Skip to content

Commit

Permalink
Add additional checks to prevent freezing for invalid timeline ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Jan 31, 2025
1 parent fe89655 commit 7cd9891
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/hub/SelectionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ export default class SelectionImpl implements Selection {
/** Returns the visible range for the timeline. */
getTimelineRange(): [number, number] {
this.applyTimelineScroll(0, 0, 0);
return [...this.timelineRange];
let safeTimelineRange = [...this.timelineRange] as [number, number];
safeTimelineRange[1] = Math.max(safeTimelineRange[1], safeTimelineRange[0] + 1e-3);
return safeTimelineRange;
}

/** Returns whether the timeline is locked to max zoom. */
Expand Down
3 changes: 2 additions & 1 deletion src/hub/Timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ export default class Timeline {
context.textBaseline = "middle";
context.globalAlpha = 0.5;
let stepPos = Math.ceil(cleanFloat(timeRange[0] / stepSize)) * stepSize;
while (true) {
let iterCount = 0;
while (iterCount++ < 100) {
let x = scaleValue(stepPos, timeRange, [0, width]);
if (x > width + 1) {
break;
Expand Down
12 changes: 8 additions & 4 deletions src/shared/renderers/LineGraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ export default class LineGraphRenderer implements TabRenderer {
context.beginPath();
context.moveTo(graphLeft + graphWidth, yScaler.calculate(field.values[field.values.length - 1]));
let i = field.values.length - 1;
while (true) {
let iterCount = 0;
while (iterCount++ < 100) {
let x = xScaler.calculate(field.timestamps[i]);

// Render start of current data point
Expand Down Expand Up @@ -529,7 +530,8 @@ export default class LineGraphRenderer implements TabRenderer {
if (command.showLeftAxis) {
context.textAlign = "right";
let stepPos = Math.floor(command.leftRange[1] / leftStepSize) * leftStepSize;
while (true) {
let iterCount = 0;
while (iterCount++ < 100) {
let y = scaleValue(stepPos, command.leftRange, [graphTop + graphHeightOpen, graphTop]);
if (y > graphTop + graphHeight) break;

Expand Down Expand Up @@ -558,7 +560,8 @@ export default class LineGraphRenderer implements TabRenderer {
if (command.showRightAxis) {
context.textAlign = "left";
let stepPos = Math.floor(command.rightRange[1] / rightStepSize) * rightStepSize;
while (true) {
let iterCount = 0;
while (iterCount++ < 100) {
let y = scaleValue(stepPos, command.rightRange, [graphTop + graphHeightOpen, graphTop]);
if (y > graphTop + graphHeight) break;

Expand Down Expand Up @@ -587,7 +590,8 @@ export default class LineGraphRenderer implements TabRenderer {
// Render x axis
context.textAlign = "center";
let stepPos = Math.ceil(cleanFloat(timeRange[0] / timeStepSize)) * timeStepSize;
while (true) {
let iterCount = 0;
while (iterCount++ < 100) {
let x = scaleValue(stepPos, timeRange, [graphLeft, graphLeft + graphWidth]);

// Clean up final x (scroll can cause rounding problems)
Expand Down

0 comments on commit 7cd9891

Please sign in to comment.