Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 1 | // 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 Golton | 5038846 | 2023-04-05 16:14:38 +0100 | [diff] [blame] | 15 | import m from 'mithril'; |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 16 | |
Steve Golton | 278b7f0 | 2023-09-06 16:26:23 +0100 | [diff] [blame] | 17 | import {Time} from '../base/time'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 18 | |
Isabelle Taylor | a16dec2 | 2019-12-03 16:34:13 +0000 | [diff] [blame] | 19 | import {TRACK_SHELL_WIDTH} from './css_constants'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 20 | import {globals} from './globals'; |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 21 | import { |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 22 | getMaxMajorTicks, |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 23 | TickGenerator, |
| 24 | TickType, |
| 25 | timeScaleForVisibleWindow, |
| 26 | } from './gridline_helper'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 27 | import {Panel, PanelSize} from './panel'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 28 | |
| 29 | // This is used to display the summary of search results. |
| 30 | export class TickmarkPanel extends Panel { |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 31 | view() { |
| 32 | return m('.tickbar'); |
| 33 | } |
| 34 | |
| 35 | renderCanvas(ctx: CanvasRenderingContext2D, size: PanelSize) { |
Steve Golton | 640b81c | 2023-05-22 15:27:46 +0100 | [diff] [blame] | 36 | const {visibleTimeScale} = globals.frontendLocalState; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 37 | |
| 38 | ctx.fillStyle = '#999'; |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 39 | ctx.fillRect(TRACK_SHELL_WIDTH - 2, 0, 2, size.height); |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 40 | |
| 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 Golton | ab88091 | 2023-06-28 15:47:23 +0100 | [diff] [blame] | 46 | const visibleSpan = globals.frontendLocalState.visibleTimeSpan; |
Steve Golton | 640b81c | 2023-05-22 15:27:46 +0100 | [diff] [blame] | 47 | if (size.width > TRACK_SHELL_WIDTH && visibleSpan.duration > 0n) { |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 48 | const maxMajorTicks = getMaxMajorTicks(size.width - TRACK_SHELL_WIDTH); |
| 49 | const map = timeScaleForVisibleWindow(TRACK_SHELL_WIDTH, size.width); |
Steve Golton | 3738d9f | 2023-06-22 20:22:39 +0100 | [diff] [blame] | 50 | |
Steve Golton | 21a2fc2 | 2023-07-12 07:07:58 +0100 | [diff] [blame] | 51 | const offset = globals.timestampOffset(); |
Steve Golton | 3738d9f | 2023-06-22 20:22:39 +0100 | [diff] [blame] | 52 | const tickGen = new TickGenerator(visibleSpan, maxMajorTicks, offset); |
| 53 | for (const {type, time} of tickGen) { |
Steve Golton | b3a389d | 2023-07-10 11:03:17 +0100 | [diff] [blame] | 54 | const px = Math.floor(map.timeToPx(time)); |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 55 | if (type === TickType.MAJOR) { |
| 56 | ctx.fillRect(px, 0, 1, size.height); |
| 57 | } |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 58 | } |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 61 | const data = globals.searchSummary; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 62 | for (let i = 0; i < data.tsStarts.length; i++) { |
Steve Golton | b3a389d | 2023-07-10 11:03:17 +0100 | [diff] [blame] | 63 | const tStart = Time.fromRaw(data.tsStarts[i]); |
| 64 | const tEnd = Time.fromRaw(data.tsEnds[i]); |
Steve Golton | ab88091 | 2023-06-28 15:47:23 +0100 | [diff] [blame] | 65 | if (!visibleSpan.intersects(tStart, tEnd)) { |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 66 | continue; |
| 67 | } |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 68 | const rectStart = |
Steve Golton | b3a389d | 2023-07-10 11:03:17 +0100 | [diff] [blame] | 69 | Math.max(visibleTimeScale.timeToPx(tStart), 0) + TRACK_SHELL_WIDTH; |
| 70 | const rectEnd = visibleTimeScale.timeToPx(tEnd) + TRACK_SHELL_WIDTH; |
Neda Topoljanac | b889e39 | 2019-09-05 11:32:38 +0100 | [diff] [blame] | 71 | ctx.fillStyle = '#ffe263'; |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 72 | ctx.fillRect( |
| 73 | Math.floor(rectStart), |
| 74 | 0, |
| 75 | Math.ceil(rectEnd - rectStart), |
| 76 | size.height); |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 77 | } |
Hector Dearman | 301ce39 | 2021-07-16 13:51:33 +0100 | [diff] [blame] | 78 | const index = globals.state.searchIndex; |
Steve Golton | 7bf2fe7 | 2023-06-01 09:52:29 +0100 | [diff] [blame] | 79 | if (index !== -1 && index < globals.currentSearchResults.tsStarts.length) { |
Steve Golton | 640b81c | 2023-05-22 15:27:46 +0100 | [diff] [blame] | 80 | const start = globals.currentSearchResults.tsStarts[index]; |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 81 | const triangleStart = |
Steve Golton | b3a389d | 2023-07-10 11:03:17 +0100 | [diff] [blame] | 82 | Math.max(visibleTimeScale.timeToPx(Time.fromRaw(start)), 0) + |
| 83 | TRACK_SHELL_WIDTH; |
Steve Golton | f3897e2 | 2023-05-11 14:18:30 +0100 | [diff] [blame] | 84 | 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 Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 95 | } |
| 96 | } |