blob: 9390c7fc5e65ec7801498485411a97b5ba629685 [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
Steve Golton50388462023-04-05 16:14:38 +010015import m from 'mithril';
Steve Golton9ae75582023-01-26 18:48:16 +000016
Steve Golton278b7f02023-09-06 16:26:23 +010017import {Time} from '../base/time';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010018
Isabelle Taylora16dec22019-12-03 16:34:13 +000019import {TRACK_SHELL_WIDTH} from './css_constants';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010020import {globals} from './globals';
Steve Golton9ae75582023-01-26 18:48:16 +000021import {
Steve Goltonf3897e22023-05-11 14:18:30 +010022 getMaxMajorTicks,
Steve Golton9ae75582023-01-26 18:48:16 +000023 TickGenerator,
24 TickType,
25 timeScaleForVisibleWindow,
26} from './gridline_helper';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010027import {Panel, PanelSize} from './panel';
Isabelle Taylorb91f8342019-08-13 10:56:07 +010028
29// This is used to display the summary of search results.
30export class TickmarkPanel extends Panel {
Isabelle Taylorb91f8342019-08-13 10:56:07 +010031 view() {
32 return m('.tickbar');
33 }
34
35 renderCanvas(ctx: CanvasRenderingContext2D, size: PanelSize) {
Steve Golton640b81c2023-05-22 15:27:46 +010036 const {visibleTimeScale} = globals.frontendLocalState;
Isabelle Taylorb91f8342019-08-13 10:56:07 +010037
38 ctx.fillStyle = '#999';
Hector Dearman372ec602019-09-03 12:12:02 +010039 ctx.fillRect(TRACK_SHELL_WIDTH - 2, 0, 2, size.height);
Steve Goltonf3897e22023-05-11 14:18:30 +010040
41 ctx.save();
42 ctx.beginPath();
43 ctx.rect(TRACK_SHELL_WIDTH, 0, size.width - TRACK_SHELL_WIDTH, size.height);
44 ctx.clip();
45
Steve Goltonab880912023-06-28 15:47:23 +010046 const visibleSpan = globals.frontendLocalState.visibleTimeSpan;
Steve Golton640b81c2023-05-22 15:27:46 +010047 if (size.width > TRACK_SHELL_WIDTH && visibleSpan.duration > 0n) {
Steve Goltonf3897e22023-05-11 14:18:30 +010048 const maxMajorTicks = getMaxMajorTicks(size.width - TRACK_SHELL_WIDTH);
49 const map = timeScaleForVisibleWindow(TRACK_SHELL_WIDTH, size.width);
Steve Golton3738d9f2023-06-22 20:22:39 +010050
Steve Golton21a2fc22023-07-12 07:07:58 +010051 const offset = globals.timestampOffset();
Steve Golton3738d9f2023-06-22 20:22:39 +010052 const tickGen = new TickGenerator(visibleSpan, maxMajorTicks, offset);
53 for (const {type, time} of tickGen) {
Steve Goltonb3a389d2023-07-10 11:03:17 +010054 const px = Math.floor(map.timeToPx(time));
Steve Goltonf3897e22023-05-11 14:18:30 +010055 if (type === TickType.MAJOR) {
56 ctx.fillRect(px, 0, 1, size.height);
57 }
Steve Golton9ae75582023-01-26 18:48:16 +000058 }
Isabelle Taylorb91f8342019-08-13 10:56:07 +010059 }
60
Hector Dearman372ec602019-09-03 12:12:02 +010061 const data = globals.searchSummary;
Isabelle Taylorb91f8342019-08-13 10:56:07 +010062 for (let i = 0; i < data.tsStarts.length; i++) {
Steve Goltonb3a389d2023-07-10 11:03:17 +010063 const tStart = Time.fromRaw(data.tsStarts[i]);
64 const tEnd = Time.fromRaw(data.tsEnds[i]);
Steve Goltonab880912023-06-28 15:47:23 +010065 if (!visibleSpan.intersects(tStart, tEnd)) {
Isabelle Taylorb91f8342019-08-13 10:56:07 +010066 continue;
67 }
Hector Dearman372ec602019-09-03 12:12:02 +010068 const rectStart =
Steve Goltonb3a389d2023-07-10 11:03:17 +010069 Math.max(visibleTimeScale.timeToPx(tStart), 0) + TRACK_SHELL_WIDTH;
70 const rectEnd = visibleTimeScale.timeToPx(tEnd) + TRACK_SHELL_WIDTH;
Neda Topoljanacb889e392019-09-05 11:32:38 +010071 ctx.fillStyle = '#ffe263';
Hector Dearman372ec602019-09-03 12:12:02 +010072 ctx.fillRect(
73 Math.floor(rectStart),
74 0,
75 Math.ceil(rectEnd - rectStart),
76 size.height);
Isabelle Taylorb91f8342019-08-13 10:56:07 +010077 }
Hector Dearman301ce392021-07-16 13:51:33 +010078 const index = globals.state.searchIndex;
Steve Golton7bf2fe72023-06-01 09:52:29 +010079 if (index !== -1 && index < globals.currentSearchResults.tsStarts.length) {
Steve Golton640b81c2023-05-22 15:27:46 +010080 const start = globals.currentSearchResults.tsStarts[index];
Steve Goltonf3897e22023-05-11 14:18:30 +010081 const triangleStart =
Steve Goltonb3a389d2023-07-10 11:03:17 +010082 Math.max(visibleTimeScale.timeToPx(Time.fromRaw(start)), 0) +
83 TRACK_SHELL_WIDTH;
Steve Goltonf3897e22023-05-11 14:18:30 +010084 ctx.fillStyle = '#000';
85 ctx.beginPath();
86 ctx.moveTo(triangleStart, size.height);
87 ctx.lineTo(triangleStart - 3, 0);
88 ctx.lineTo(triangleStart + 3, 0);
89 ctx.lineTo(triangleStart, size.height);
90 ctx.fill();
91 ctx.closePath();
92 }
93
94 ctx.restore();
Isabelle Taylorb91f8342019-08-13 10:56:07 +010095 }
96}