blob: 10df5d680157a0fa46193f41a05638327d108371 [file] [log] [blame]
Hector Dearman3d26fdb2018-07-09 13:54:06 +01001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this 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.
Micha Schwab01b35682018-06-28 13:56:49 +010014
15import * as m from 'mithril';
Michail Schwabbeb34522018-07-20 08:15:17 -040016
17import {Milliseconds, TimeScale} from './time_scale';
Hector Dearman44869b12018-07-09 09:54:31 +010018import {TrackShell} from './track_shell';
Michail Schwabbbdd9832018-07-12 12:02:53 -040019import {VirtualCanvasContext} from './virtual_canvas_context';
Micha Schwab01b35682018-06-28 13:56:49 +010020
Hector Dearman44869b12018-07-09 09:54:31 +010021export const Track = {
Micha Schwabda322442018-06-28 20:19:59 +010022 view({attrs}) {
Michail Schwabbeb34522018-07-20 08:15:17 -040023 const sliceStart: Milliseconds = 100000;
24 const sliceEnd: Milliseconds = 400000;
25
26 const rectStart = attrs.timeScale.msToPx(sliceStart);
27 const rectWidth = attrs.timeScale.msToPx(sliceEnd) - rectStart;
28 const shownStart = rectStart > attrs.width ? attrs.width : rectStart;
29 const shownWidth = rectWidth + (rectStart as number) > attrs.width ?
30 attrs.width :
31 rectWidth;
32
Michail Schwabbbdd9832018-07-12 12:02:53 -040033 if (attrs.trackContext.isOnCanvas()) {
34 attrs.trackContext.fillStyle = '#ccc';
michaschwab3e47c902018-07-16 14:58:51 -040035 attrs.trackContext.fillRect(0, 0, attrs.width, 73);
Michail Schwab80490552018-07-10 15:45:57 -040036
Michail Schwabbeb34522018-07-20 08:15:17 -040037 attrs.trackContext.fillStyle = '#c00';
38 attrs.trackContext.fillRect(shownStart, 40, shownWidth, 30);
39
Michail Schwabbbdd9832018-07-12 12:02:53 -040040 attrs.trackContext.font = '16px Arial';
41 attrs.trackContext.fillStyle = '#000';
michaschwab3e47c902018-07-16 14:58:51 -040042 attrs.trackContext.fillText(
Michail Schwabbeb34522018-07-20 08:15:17 -040043 attrs.name + ' rendered by canvas', shownStart, 60);
Michail Schwabbbdd9832018-07-12 12:02:53 -040044 }
Michail Schwab80490552018-07-10 15:45:57 -040045
Deepanjan Roya752b462018-07-04 01:24:31 +010046 return m(
47 '.track',
Michail Schwab80490552018-07-10 15:45:57 -040048 {
49 style: {
50 position: 'absolute',
51 top: attrs.top.toString() + 'px',
52 left: 0,
53 width: '100%'
54 }
55 },
Michail Schwabbeb34522018-07-20 08:15:17 -040056 m(TrackShell,
57 attrs,
58 m('.marker',
59 {
60 style: {
61 'font-size': '1.5em',
62 position: 'absolute',
63 left: rectStart.toString() + 'px',
64 width: rectWidth.toString() + 'px',
65 background: '#aca'
66 }
67 },
68 attrs.name + ' DOM Content')));
Micha Schwab01b35682018-06-28 13:56:49 +010069 }
michaschwab3e47c902018-07-16 14:58:51 -040070} as m.Component<{
71 name: string,
72 trackContext: VirtualCanvasContext,
73 top: number,
Michail Schwabbeb34522018-07-20 08:15:17 -040074 width: number,
75 timeScale: TimeScale
76}>;