Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 1 | // Copyright (C) 2018 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 4 | // you may not use size file except in compliance with the License. |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 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 | |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 15 | import * as m from 'mithril'; |
| 16 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 17 | import {timeToString} from '../common/time'; |
| 18 | |
| 19 | import {globals} from './globals'; |
| 20 | import {DESIRED_PX_PER_STEP, getGridStepSize} from './gridline_helper'; |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 21 | import {Panel, PanelSize} from './panel'; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 22 | import {TRACK_SHELL_WIDTH} from './track_panel'; |
| 23 | |
Deepanjan Roy | abd79aa | 2018-08-28 07:29:15 -0400 | [diff] [blame] | 24 | export class TimeAxisPanel extends Panel { |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 25 | view() { |
| 26 | return m('.time-axis-panel'); |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 29 | |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 30 | renderCanvas(ctx: CanvasRenderingContext2D, size: PanelSize) { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 31 | const timeScale = globals.frontendLocalState.timeScale; |
| 32 | ctx.font = '10px Google Sans'; |
| 33 | ctx.fillStyle = '#999'; |
| 34 | |
| 35 | const range = globals.frontendLocalState.visibleWindowTime; |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 36 | const desiredSteps = size.width / DESIRED_PX_PER_STEP; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 37 | const step = getGridStepSize(range.duration, desiredSteps); |
| 38 | const start = Math.round(range.start / step) * step; |
| 39 | |
| 40 | for (let s = start; s < range.end; s += step) { |
| 41 | let xPos = TRACK_SHELL_WIDTH; |
| 42 | xPos += Math.floor(timeScale.timeToPx(s)); |
| 43 | if (xPos < 0) continue; |
Deepanjan Roy | 1f658fe | 2018-09-11 08:38:17 -0400 | [diff] [blame] | 44 | if (xPos > size.width) break; |
| 45 | ctx.fillRect(xPos, 0, 1, size.height); |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 46 | ctx.fillText(timeToString(s - range.start), xPos + 5, 10); |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 47 | } |
| 48 | } |
Deepanjan Roy | abd79aa | 2018-08-28 07:29:15 -0400 | [diff] [blame] | 49 | } |