• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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.
14
15import {time} from '../base/time';
16
17import {TRACK_SHELL_WIDTH} from './css_constants';
18import {TimeScale} from './time_scale';
19
20export function drawVerticalLineAtTime(
21  ctx: CanvasRenderingContext2D,
22  timeScale: TimeScale,
23  time: time,
24  height: number,
25  color: string,
26  lineWidth = 2,
27) {
28  const xPos = TRACK_SHELL_WIDTH + Math.floor(timeScale.timeToPx(time));
29  drawVerticalLine(ctx, xPos, height, color, lineWidth);
30}
31
32function drawVerticalLine(
33  ctx: CanvasRenderingContext2D,
34  xPos: number,
35  height: number,
36  color: string,
37  lineWidth = 2,
38) {
39  ctx.beginPath();
40  ctx.strokeStyle = color;
41  const prevLineWidth = ctx.lineWidth;
42  ctx.lineWidth = lineWidth;
43  ctx.moveTo(xPos, 0);
44  ctx.lineTo(xPos, height);
45  ctx.stroke();
46  ctx.closePath();
47  ctx.lineWidth = prevLineWidth;
48}
49