blob: ddddd7c31f584233203462140a59f0cc100bc737 [file] [log] [blame]
Isabelle Taylorb91f8342019-08-13 10:56:07 +01001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use size file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import * as m from 'mithril';
Neda Topoljanacb889e392019-09-05 11:32:38 +010016import {fromNs} from '../common/time';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010017
Isabelle Taylorb91f8342019-08-13 10:56:07 +010018import {globals} from './globals';
19import {gridlines} from './gridline_helper';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010020import {Panel, PanelSize} from './panel';
21import {TRACK_SHELL_WIDTH} from './track_constants';
22
23// This is used to display the summary of search results.
24export class TickmarkPanel extends Panel {
Isabelle Taylorb91f8342019-08-13 10:56:07 +010025 view() {
26 return m('.tickbar');
27 }
28
29 renderCanvas(ctx: CanvasRenderingContext2D, size: PanelSize) {
30 const {timeScale, visibleWindowTime} = globals.frontendLocalState;
31
32 ctx.fillStyle = '#999';
Hector Dearman372ec602019-09-03 12:12:02 +010033 ctx.fillRect(TRACK_SHELL_WIDTH - 2, 0, 2, size.height);
Isabelle Taylorb91f8342019-08-13 10:56:07 +010034 for (const xAndTime of gridlines(
35 size.width, visibleWindowTime, timeScale)) {
36 ctx.fillRect(xAndTime[0], 0, 1, size.height);
37 }
38
Hector Dearman372ec602019-09-03 12:12:02 +010039 const data = globals.searchSummary;
Isabelle Taylorb91f8342019-08-13 10:56:07 +010040 for (let i = 0; i < data.tsStarts.length; i++) {
41 const tStart = data.tsStarts[i];
42 const tEnd = data.tsEnds[i];
Isabelle Taylorb91f8342019-08-13 10:56:07 +010043 if (tEnd <= visibleWindowTime.start || tStart >= visibleWindowTime.end) {
44 continue;
45 }
Hector Dearman372ec602019-09-03 12:12:02 +010046 const rectStart =
47 Math.max(timeScale.timeToPx(tStart), 0) + TRACK_SHELL_WIDTH;
Isabelle Taylorb91f8342019-08-13 10:56:07 +010048 const rectEnd = timeScale.timeToPx(tEnd) + TRACK_SHELL_WIDTH;
Neda Topoljanacb889e392019-09-05 11:32:38 +010049 ctx.fillStyle = '#ffe263';
Hector Dearman372ec602019-09-03 12:12:02 +010050 ctx.fillRect(
51 Math.floor(rectStart),
52 0,
53 Math.ceil(rectEnd - rectStart),
54 size.height);
Isabelle Taylorb91f8342019-08-13 10:56:07 +010055 }
Neda Topoljanacb889e392019-09-05 11:32:38 +010056 const index = globals.frontendLocalState.searchIndex;
57 const startSec = fromNs(globals.currentSearchResults.tsStarts[index]);
58 const triangleStart =
59 Math.max(timeScale.timeToPx(startSec), 0) + TRACK_SHELL_WIDTH;
60 ctx.fillStyle = '#000';
61 ctx.beginPath();
62 ctx.moveTo(triangleStart, size.height);
63 ctx.lineTo(triangleStart - 3, 0);
64 ctx.lineTo(triangleStart + 3, 0);
65 ctx.lineTo(triangleStart, size.height);
66 ctx.fill();
67 ctx.closePath();
Isabelle Taylorb91f8342019-08-13 10:56:07 +010068 }
69}