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 | |
| 15 | import * as m from 'mithril'; |
Neda Topoljanac | b889e39 | 2019-09-05 11:32:38 +0100 | [diff] [blame^] | 16 | import {fromNs} from '../common/time'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 17 | |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 18 | import {globals} from './globals'; |
| 19 | import {gridlines} from './gridline_helper'; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 20 | import {Panel, PanelSize} from './panel'; |
| 21 | import {TRACK_SHELL_WIDTH} from './track_constants'; |
| 22 | |
| 23 | // This is used to display the summary of search results. |
| 24 | export class TickmarkPanel extends Panel { |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 25 | 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 Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 33 | ctx.fillRect(TRACK_SHELL_WIDTH - 2, 0, 2, size.height); |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 34 | for (const xAndTime of gridlines( |
| 35 | size.width, visibleWindowTime, timeScale)) { |
| 36 | ctx.fillRect(xAndTime[0], 0, 1, size.height); |
| 37 | } |
| 38 | |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 39 | const data = globals.searchSummary; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 40 | for (let i = 0; i < data.tsStarts.length; i++) { |
| 41 | const tStart = data.tsStarts[i]; |
| 42 | const tEnd = data.tsEnds[i]; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 43 | if (tEnd <= visibleWindowTime.start || tStart >= visibleWindowTime.end) { |
| 44 | continue; |
| 45 | } |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 46 | const rectStart = |
| 47 | Math.max(timeScale.timeToPx(tStart), 0) + TRACK_SHELL_WIDTH; |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 48 | const rectEnd = timeScale.timeToPx(tEnd) + TRACK_SHELL_WIDTH; |
Neda Topoljanac | b889e39 | 2019-09-05 11:32:38 +0100 | [diff] [blame^] | 49 | ctx.fillStyle = '#ffe263'; |
Hector Dearman | 372ec60 | 2019-09-03 12:12:02 +0100 | [diff] [blame] | 50 | ctx.fillRect( |
| 51 | Math.floor(rectStart), |
| 52 | 0, |
| 53 | Math.ceil(rectEnd - rectStart), |
| 54 | size.height); |
Isabelle Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 55 | } |
Neda Topoljanac | b889e39 | 2019-09-05 11:32:38 +0100 | [diff] [blame^] | 56 | 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 Taylor | b91f834 | 2019-08-13 10:56:07 +0100 | [diff] [blame] | 68 | } |
| 69 | } |