From 1ef4e426d5a0c45f547907d6a3c16161a42ed3e7 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 13 Sep 2024 10:44:48 -0400 Subject: [PATCH] Clamp computed world range to absolute range Clamp the computed requested world range (which adds a buffer to the left and right of the view range) to the limits of the absolute range. This prevents unnecessary row updates because the row's provided model range is always clamped. Reject row data received during full search for an outdated world range. Signed-off-by: Patrick Tasse --- timeline-chart/src/layer/time-graph-chart.ts | 11 +++++------ timeline-chart/src/time-graph-state-controller.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/timeline-chart/src/layer/time-graph-chart.ts b/timeline-chart/src/layer/time-graph-chart.ts index 783a324..5b9411f 100644 --- a/timeline-chart/src/layer/time-graph-chart.ts +++ b/timeline-chart/src/layer/time-graph-chart.ts @@ -505,6 +505,7 @@ export class TimeGraphChart extends TimeGraphChartLayer { } const visibleRowIds = this.getVisibleRowIds(VISIBLE_ROW_BUFFER); const { viewRange } = this.unitController; + const worldRange = this.stateController.computeWorldRangeFromViewRange(); const resolutionFactor = fine ? FINE_RESOLUTION_FACTOR : this._coarseResolutionFactor; const resolution = (resolutionFactor * Number(this.unitController.viewRangeLength)) / this.stateController.canvasDisplayWidth; // Compute the visible rowIds to fetch. Fetch all visible rows if update flag is set, @@ -517,16 +518,11 @@ export class TimeGraphChart extends TimeGraphChartLayer { !rowComponent.providedModel || viewRange.start < rowComponent.providedModel.range.start || // This logic can be updated for pre-rendering before we reach the end. viewRange.end > rowComponent.providedModel.range.end || // This logic can be updated for pre-rendering before we reach the end. - !isEqual(this.stateController.worldRange, rowComponent.providedModel.range) || + !isEqual(worldRange, rowComponent.providedModel.range) || resolution < rowComponent.providedModel.resolution || !isEqual(rowComponent.providedModel.filterExpressionsMap, this._filterExpressionsMap) ); }); if (rowIds.length > 0) { - // When we fetch data, update the world range from the current view range. - // Only on coarse renders - // Only if we are updating all rows and not increasing vertical height. See: https://github.com/eclipse-cdt-cloud/theia-trace-extension/pull/832#issuecomment-1259902534. - const allRowsUpdated = rowIds.length === visibleRowIds.length; - const worldRange = allRowsUpdated ? this.stateController.computeWorldRangeFromViewRange() : this.stateController.worldRange; const additionalParams: { [key: string]: any } = {}; if (this._filterExpressionsMap) { additionalParams['filter_query_parameters'] = {'filter_expressions_map': this._filterExpressionsMap, 'strategy': fullSearch ? 'DEEP' : 'SAMPLED'}; @@ -606,6 +602,9 @@ export class TimeGraphChart extends TimeGraphChartLayer { this.stateController.worldRange = request.worldRange; this.stateController.worldZoomFactor = this.stateController.zoomFactor; this.stateController.resetScale(); + } else if (!isEqual(request.worldRange, this.stateController.worldRange)) { + // response discarded because world range updated + return Promise.reject(new Error("Request for outdated world range")); } this.addOrUpdateRows(rowData); if (this.isNavigating) { diff --git a/timeline-chart/src/time-graph-state-controller.ts b/timeline-chart/src/time-graph-state-controller.ts index 3b5423e..fdcaf6e 100644 --- a/timeline-chart/src/time-graph-state-controller.ts +++ b/timeline-chart/src/time-graph-state-controller.ts @@ -168,8 +168,14 @@ export class TimeGraphStateController { computeWorldRangeFromViewRange() { const deltaV = this.unitController.viewRange.end - this.unitController.viewRange.start; - const start = this.unitController.viewRange.start - BIMath.multiply(deltaV, this.unitController.worldRenderFactor); - const end = this.unitController.viewRange.end + BIMath.multiply(deltaV, this.unitController.worldRenderFactor); + let start = this.unitController.viewRange.start - BIMath.multiply(deltaV, this.unitController.worldRenderFactor); + let end = this.unitController.viewRange.end + BIMath.multiply(deltaV, this.unitController.worldRenderFactor); + if (start < 0) { + start = BigInt(0); + } + if (end > this.unitController.absoluteRange) { + end = this.unitController.absoluteRange; + } return { start, end }; }