Skip to content

Commit

Permalink
Retain the row and state selection after call to states API
Browse files Browse the repository at this point in the history
Signed-off-by: muddana-satish <satish.muddana@ericsson.com>
  • Loading branch information
muddana-satish authored and MatthewKhouzam committed Oct 19, 2020
1 parent 9dc78bb commit a0e2dfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
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 @@ -89,15 +89,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 @@ -153,17 +144,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 @@ -286,18 +286,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

0 comments on commit a0e2dfb

Please sign in to comment.