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

Retain row and state selection after refresh #49

Merged
merged 1 commit into from Oct 19, 2020
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
22 changes: 1 addition & 21 deletions example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TimeGraphChartSelectionRange } from "timeline-chart/lib/layer/time-grap
import { TimeGraphAxisCursors } from "timeline-chart/lib/layer/time-graph-axis-cursors";
// import { timeGraph } from "timeline-chart/lib/test-data";
import { TimelineChart } from "timeline-chart/lib/time-graph-model";
import { TimeGraphRowElement, TimeGraphRowElementStyle } from "timeline-chart/lib/components/time-graph-row-element";
import { TimeGraphRowElementStyle } from "timeline-chart/lib/components/time-graph-row-element";
import { TestDataProvider } from "./test-data-provider";
import { TimeGraphChartGrid } from "timeline-chart/lib/layer/time-graph-chart-grid";
import { TimeGraphVerticalScrollbar } from "timeline-chart/lib/layer/time-graph-vertical-scrollbar";
Expand Down Expand Up @@ -86,15 +86,6 @@ const timeGraphChart = new TimeGraphChart('timeGraphChart', {
const newRange: TimelineChart.TimeGraphRange = { start, end };
const newResolution: number = resolution * 0.1;
timeGraph = testDataProvider.getData({ range: newRange, resolution: newResolution });
if (selectedElement) {
for (const row of timeGraph.rows) {
const selEl = row.states.find(el => !!selectedElement && el.id === selectedElement.id);
if (selEl) {
selEl.selected = true;
break;
}
}
}
return {
rows: timeGraph.rows,
range: newRange,
Expand Down Expand Up @@ -149,17 +140,6 @@ timeGraphChart.registerRowElementMouseInteractions({
}
}
});
let selectedElement: TimeGraphRowElement | undefined;
timeGraphChart.onSelectedRowElementChanged((model) => {
if (model) {
const el = timeGraphChart.getElementById(model.id);
if (el) {
selectedElement = el;
}
} else {
selectedElement = undefined;
}
})

const timeGraphChartArrows = new TimeGraphChartArrows('timeGraphChartArrows', rowController);
timeGraphChartContainer.addLayer(timeGraphChartArrows);
Expand Down
16 changes: 10 additions & 6 deletions timeline-chart/src/layer/time-graph-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,22 @@ export class TimeGraphChart extends TimeGraphChartLayer {
}).bind(this));
this.addChild(rowComponent);
this.rowComponents.set(row, rowComponent);
let selectedElement: TimeGraphRowElement | undefined;
if (this.rowController.selectedRow && this.rowController.selectedRow.id === row.id) {
this.selectRow(row);
}
row.states.forEach((rowElementModel: TimelineChart.TimeGraphRowElementModel) => {
const el = this.createNewRowElement(rowElementModel, rowComponent);
if (el) {
el.model.selected && (this.selectedElementModel = el.model) && (selectedElement = el);
this.addElementInteractions(el);
!el.model.selected && this.addChild(el);
this.addChild(el);
if (this.selectedElementModel && this.rowController.selectedRow
&& this.rowController.selectedRow.id === row.id
&& this.selectedElementModel.range.start === el.model.range.start
&& this.selectedElementModel.range.end === el.model.range.end) {
this.selectRowElement(el.model);
}
}
});
if (selectedElement) {
this.addChild(selectedElement);
}
}

protected createNewRowElement(rowElementModel: TimelineChart.TimeGraphRowElementModel, rowComponent: TimeGraphRow): TimeGraphRowElement | undefined {
Expand Down