Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix y axis auto scaling #1112

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utilities/timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test('getYAxisBounds', () => {
[layer1.id]: [resourceWithNoValues],
}),
).toEqual([0, 10]);
expect(getYAxisBounds(yAxis, layers, resourcesByViewLayerId, { end: 4, start: 3 })).toEqual([12, 13]);
expect(getYAxisBounds(yAxis, layers, resourcesByViewLayerId, { end: 4, start: 3 })).toEqual([11, 14]);
expect(
getYAxisBounds({ ...yAxis, domainFitMode: 'fitPlan' }, layers, resourcesByViewLayerId, { end: 4, start: 3 }),
).toEqual([10, 15]);
Expand Down
24 changes: 13 additions & 11 deletions src/utilities/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export function getYAxisBounds(
}
}
// Identify the first value to the right of the viewTimeRange
if (viewTimeRange && value.x > viewTimeRange.start) {
if (viewTimeRange && value.x > viewTimeRange.end) {
if (value.is_gap) {
rightValue = undefined;
} else {
Expand Down Expand Up @@ -580,16 +580,18 @@ export function getYAxisBounds(
}
}
});
// If viewTimeRange is supplied and the minY and maxY are still undefined,
// look for the first numerical value to the left and to the right of the time window
if (
viewTimeRange &&
(minY === undefined || maxY === undefined) &&
leftValue !== undefined &&
rightValue !== undefined
) {
minY = Math.min(leftValue.y as number, rightValue.y as number);
maxY = Math.max(leftValue.y as number, rightValue.y as number);
// Account for the neighboring left and right values as these values are connected to in line drawing
if (viewTimeRange) {
minY = Math.min(
minY ?? Number.MAX_SAFE_INTEGER,
leftValue !== undefined && leftValue.y ? (leftValue.y as number) : Number.MAX_SAFE_INTEGER,
rightValue !== undefined && rightValue.y ? (rightValue.y as number) : Number.MAX_SAFE_INTEGER,
);
maxY = Math.max(
maxY ?? Number.MIN_SAFE_INTEGER,
leftValue !== undefined && leftValue.y ? (leftValue.y as number) : Number.MIN_SAFE_INTEGER,
rightValue !== undefined && rightValue.y ? (rightValue.y as number) : Number.MIN_SAFE_INTEGER,
);
}
});
}
Expand Down
Loading