perfetto-ui: Fix gridlines
The step size is calculated to be as close as possible to the desired
number of steps while meeting some contrainsts.
This means the actual number of steps != the desired steps.
Iterate through the actual number of steps instead.
Bug:146557077
Change-Id: Iee4baa31c6ffbb0205df4620ba354bc39c8d06b8
diff --git a/ui/src/frontend/gridline_helper.ts b/ui/src/frontend/gridline_helper.ts
index b61729e..a7c3c27 100644
--- a/ui/src/frontend/gridline_helper.ts
+++ b/ui/src/frontend/gridline_helper.ts
@@ -70,13 +70,14 @@
Array<[number, number]> {
const desiredSteps = width / DESIRED_PX_PER_STEP;
const step = getGridStepSize(span.duration, desiredSteps);
+ const actualSteps = Math.floor(span.duration / step);
const start = Math.round(span.start / step) * step;
const lines: Array<[number, number]> = [];
let previousTimestamp = Number.NEGATIVE_INFINITY;
// Iterating over the number of steps instead of
// for (let s = start; s < span.end; s += step) because if start is very large
// number and step very small, s will never reach end.
- for (let i = 0; i < desiredSteps; i++) {
+ for (let i = 0; i <= actualSteps; i++) {
let xPos = TRACK_SHELL_WIDTH;
const timestamp = start + i * step;
xPos += Math.floor(timescale.timeToPx(timestamp));