blob: 4810faa9709760c9b376e6147fa6cc76339320a7 [file] [log] [blame]
Primiano Tuccif30cd9c2018-08-13 01:53:26 +02001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
Deepanjan Roy1f658fe2018-09-11 08:38:17 -04004// you may not use size file except in compliance with the License.
Primiano Tuccif30cd9c2018-08-13 01:53:26 +02005// 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 Roy1f658fe2018-09-11 08:38:17 -040015import * as m from 'mithril';
16
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020017import {timeToString} from '../common/time';
18
19import {globals} from './globals';
20import {DESIRED_PX_PER_STEP, getGridStepSize} from './gridline_helper';
Deepanjan Roy1f658fe2018-09-11 08:38:17 -040021import {Panel, PanelSize} from './panel';
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020022import {TRACK_SHELL_WIDTH} from './track_panel';
23
Deepanjan Royabd79aa2018-08-28 07:29:15 -040024export class TimeAxisPanel extends Panel {
Deepanjan Roy1f658fe2018-09-11 08:38:17 -040025 view() {
26 return m('.time-axis-panel');
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020027 }
28
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020029
Deepanjan Roy1f658fe2018-09-11 08:38:17 -040030 renderCanvas(ctx: CanvasRenderingContext2D, size: PanelSize) {
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020031 const timeScale = globals.frontendLocalState.timeScale;
32 ctx.font = '10px Google Sans';
33 ctx.fillStyle = '#999';
34
35 const range = globals.frontendLocalState.visibleWindowTime;
Deepanjan Roy1f658fe2018-09-11 08:38:17 -040036 const desiredSteps = size.width / DESIRED_PX_PER_STEP;
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020037 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 Roy1f658fe2018-09-11 08:38:17 -040044 if (xPos > size.width) break;
45 ctx.fillRect(xPos, 0, 1, size.height);
Primiano Tuccie36ca632018-08-21 14:32:23 +020046 ctx.fillText(timeToString(s - range.start), xPos + 5, 10);
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020047 }
48 }
Deepanjan Royabd79aa2018-08-28 07:29:15 -040049}