Skip to content
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
51 changes: 4 additions & 47 deletions src/screen-name/graph/ConfigurableGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,8 @@ export default class ConfigurableGraph extends Node {
});
this.graphContentNode.addChild(this.xAxisInteractionRegion);

// Create line plot
const linePlot = new LinePlot(this.chartTransform, [], {
stroke: TrackLabColors.plot1Property,
lineWidth: PLOT_LINE_WIDTH,
});

// Wrap line plot in a clipped container to prevent overflow beyond the grid
// Clipped container for all track line plots; prevents overflow beyond the grid.
this.clippedDataContainer = new Node({
children: [linePlot],
clipArea: Shape.rect(0, 0, width, height),
});
this.graphContentNode.addChild(this.clippedDataContainer);
Expand Down Expand Up @@ -308,8 +301,9 @@ export default class ConfigurableGraph extends Node {
yTickLabelSet,
};

// Initialize data manager
this.dataManager = new GraphDataManager(this.chartTransform, linePlot, maxDataPoints, this.gridConfig);
// Coordinator for tick spacing, axis reset, and zoom-flag state shared by
// gesture handlers. No LinePlot: track plots are managed via setTrackData().
this.dataManager = new GraphDataManager(this.chartTransform, null, maxDataPoints, this.gridConfig);

// Create controls panel helper
this.controlsPanel = new GraphControlsPanel(
Expand Down Expand Up @@ -586,43 +580,6 @@ export default class ConfigurableGraph extends Node {
this.dataManager.clearData();
}

/**
* Add data points from a record array, mapping each record to the selected axes.
*/
public addDataPoints(dataPoints: Array<Record<string, number>>): void {
if (dataPoints.length === 0) {
return;
}

const xProperty = this.xPropertyProperty.value;
const yProperty = this.yPropertyProperty.value;

const mappedPoints: Array<{ x: number; y: number }> = [];
for (const point of dataPoints) {
const x = this.getValueForAxis(xProperty, point);
const y = this.getValueForAxis(yProperty, point);
if (x !== null && y !== null && Number.isFinite(x) && Number.isFinite(y)) {
mappedPoints.push({ x, y });
}
}

if (mappedPoints.length > 0) {
this.dataManager.addDataPoints(mappedPoints);
}
}

/**
* Get the value for a specific axis from a data point record.
* Dispatches on the PlottableProperty variant: RecordPlottable uses an
* accessor function; LivePlottable reads from a reactive property.
*/
private getValueForAxis(axisProperty: PlottableProperty, point: Record<string, number>): number | null {
if ("accessor" in axisProperty) {
return axisProperty.accessor(point);
}
return axisProperty.property.value;
}

/**
* Update the axis labels (call when units change)
*/
Expand Down
10 changes: 5 additions & 5 deletions src/screen-name/graph/GraphDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class GraphDataManager {

private readonly maxDataPoints: number;
private readonly chartTransform: ChartTransform;
private readonly linePlot: LinePlot;
private readonly linePlot: LinePlot | null;
private isManuallyZoomed = false;

// Grid and tick components
Expand All @@ -52,7 +52,7 @@ export default class GraphDataManager {

public constructor(
chartTransform: ChartTransform,
linePlot: LinePlot,
linePlot: LinePlot | null,
maxDataPoints: number,
gridConfig: GridVisualizationConfig,
) {
Expand Down Expand Up @@ -186,7 +186,7 @@ export default class GraphDataManager {
const evicted = this.writePoint(xValue, yValue);
this.updateMinMaxIncremental(xValue, yValue, evicted);

this.linePlot.setDataSet(this.getOrderedPoints());
this.linePlot?.setDataSet(this.getOrderedPoints());

if (this.dataSize > 1 && !this.isManuallyZoomed) {
this.applyAxisRangesFromExtremes();
Expand Down Expand Up @@ -233,7 +233,7 @@ export default class GraphDataManager {
this.recomputeMinMax();
}

this.linePlot.setDataSet(this.getOrderedPoints());
this.linePlot?.setDataSet(this.getOrderedPoints());

if (this.dataSize > 1 && !this.isManuallyZoomed) {
this.applyAxisRangesFromExtremes();
Expand All @@ -250,7 +250,7 @@ export default class GraphDataManager {
this.xMax = -Infinity;
this.yMin = Infinity;
this.yMax = -Infinity;
this.linePlot.setDataSet([]);
this.linePlot?.setDataSet([]);

const defaultRange = new Range(-10, 10);
this.chartTransform.setModelXRange(defaultRange);
Expand Down