Hector Dearman | 3d26fdb | 2018-07-09 13:54:06 +0100 | [diff] [blame] | 1 | // 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 Schwab | 01b3568 | 2018-06-28 13:56:49 +0100 | [diff] [blame] | 14 | |
| 15 | import * as m from 'mithril'; |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 16 | |
| 17 | import {Milliseconds, TimeScale} from './time_scale'; |
Hector Dearman | 44869b1 | 2018-07-09 09:54:31 +0100 | [diff] [blame] | 18 | import {TrackShell} from './track_shell'; |
Michail Schwab | bbdd983 | 2018-07-12 12:02:53 -0400 | [diff] [blame] | 19 | import {VirtualCanvasContext} from './virtual_canvas_context'; |
Micha Schwab | 01b3568 | 2018-06-28 13:56:49 +0100 | [diff] [blame] | 20 | |
Hector Dearman | 44869b1 | 2018-07-09 09:54:31 +0100 | [diff] [blame] | 21 | export const Track = { |
Micha Schwab | da32244 | 2018-06-28 20:19:59 +0100 | [diff] [blame] | 22 | view({attrs}) { |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 23 | 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 Schwab | bbdd983 | 2018-07-12 12:02:53 -0400 | [diff] [blame] | 33 | if (attrs.trackContext.isOnCanvas()) { |
| 34 | attrs.trackContext.fillStyle = '#ccc'; |
michaschwab | 3e47c90 | 2018-07-16 14:58:51 -0400 | [diff] [blame] | 35 | attrs.trackContext.fillRect(0, 0, attrs.width, 73); |
Michail Schwab | 8049055 | 2018-07-10 15:45:57 -0400 | [diff] [blame] | 36 | |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 37 | attrs.trackContext.fillStyle = '#c00'; |
| 38 | attrs.trackContext.fillRect(shownStart, 40, shownWidth, 30); |
| 39 | |
Michail Schwab | bbdd983 | 2018-07-12 12:02:53 -0400 | [diff] [blame] | 40 | attrs.trackContext.font = '16px Arial'; |
| 41 | attrs.trackContext.fillStyle = '#000'; |
michaschwab | 3e47c90 | 2018-07-16 14:58:51 -0400 | [diff] [blame] | 42 | attrs.trackContext.fillText( |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 43 | attrs.name + ' rendered by canvas', shownStart, 60); |
Michail Schwab | bbdd983 | 2018-07-12 12:02:53 -0400 | [diff] [blame] | 44 | } |
Michail Schwab | 8049055 | 2018-07-10 15:45:57 -0400 | [diff] [blame] | 45 | |
Deepanjan Roy | a752b46 | 2018-07-04 01:24:31 +0100 | [diff] [blame] | 46 | return m( |
| 47 | '.track', |
Michail Schwab | 8049055 | 2018-07-10 15:45:57 -0400 | [diff] [blame] | 48 | { |
| 49 | style: { |
| 50 | position: 'absolute', |
| 51 | top: attrs.top.toString() + 'px', |
| 52 | left: 0, |
| 53 | width: '100%' |
| 54 | } |
| 55 | }, |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 56 | 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 Schwab | 01b3568 | 2018-06-28 13:56:49 +0100 | [diff] [blame] | 69 | } |
michaschwab | 3e47c90 | 2018-07-16 14:58:51 -0400 | [diff] [blame] | 70 | } as m.Component<{ |
| 71 | name: string, |
| 72 | trackContext: VirtualCanvasContext, |
| 73 | top: number, |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame^] | 74 | width: number, |
| 75 | timeScale: TimeScale |
| 76 | }>; |