Skip to content

Commit aa8ada0

Browse files
committed
AG-3245 - re-ordering columns in the grid should override re-ordering in the data panel
1 parent 2d3a47e commit aa8ada0

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

enterprise-modules/grid-charts/src/chartAdaptor/chartComp/chartController.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ChartController extends BeanStub {
4141

4242
@PostConstruct
4343
private init(): void {
44-
this.updateForGridChange();
44+
this.setChartRange();
4545

4646
this.addDestroyableEventListener(this.eventService, Events.EVENT_RANGE_SELECTION_CHANGED, event => {
4747
if (event.id && event.id === this.model.getChartId()) {
@@ -52,30 +52,33 @@ export class ChartController extends BeanStub {
5252
this.addDestroyableEventListener(this.eventService, Events.EVENT_COLUMN_MOVED, this.updateForGridChange.bind(this));
5353
this.addDestroyableEventListener(this.eventService, Events.EVENT_COLUMN_PINNED, this.updateForGridChange.bind(this));
5454
this.addDestroyableEventListener(this.eventService, Events.EVENT_COLUMN_VISIBLE, this.updateForGridChange.bind(this));
55-
this.addDestroyableEventListener(this.eventService, Events.EVENT_MODEL_UPDATED, this.updateForGridChange.bind(this));
56-
this.addDestroyableEventListener(this.eventService, Events.EVENT_CELL_VALUE_CHANGED, this.updateForGridChange.bind(this));
55+
56+
this.addDestroyableEventListener(this.eventService, Events.EVENT_MODEL_UPDATED, this.updateForDataChange.bind(this));
57+
this.addDestroyableEventListener(this.eventService, Events.EVENT_CELL_VALUE_CHANGED, this.updateForDataChange.bind(this));
5758
}
5859

5960
public updateForGridChange() {
60-
// don't update chart if chart is detached from grid data
6161
if (this.model.isDetached()) { return; }
6262

6363
this.model.updateCellRanges();
64-
6564
this.setChartRange();
6665
}
6766

67+
public updateForDataChange() {
68+
if (this.model.isDetached()) { return; }
69+
70+
this.model.updateData();
71+
this.raiseChartUpdatedEvent();
72+
}
73+
6874
public updateForRangeChange() {
6975
this.updateForGridChange();
70-
7176
this.raiseChartRangeSelectionChangedEvent();
7277
}
7378

7479
public updateForPanelChange(updatedCol: ColState): void {
7580
this.model.updateCellRanges(updatedCol);
76-
7781
this.setChartRange();
78-
7982
this.raiseChartRangeSelectionChangedEvent();
8083
}
8184

enterprise-modules/grid-charts/src/chartAdaptor/chartComp/chartDataModel.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ export class ChartDataModel extends BeanStub {
190190
}
191191

192192
private getAllColumnsFromRanges(): Set<Column> {
193+
194+
193195
let columns = this.dimensionCellRange || this.valueCellRange ? [] : this.referenceCellRange.columns;
194196

195197
if (this.dimensionCellRange) {
@@ -326,7 +328,7 @@ export class ChartDataModel extends BeanStub {
326328
return 'id-' + Math.random().toString(36).substr(2, 16);
327329
}
328330

329-
private updateData(): void {
331+
public updateData(): void {
330332
const { startRow, endRow } = this.getRowIndexes();
331333
const selectedDimension = this.getSelectedDimension();
332334
const selectedValueCols = this.getSelectedValueCols();
@@ -353,6 +355,9 @@ export class ChartDataModel extends BeanStub {
353355
private resetColumnState(): void {
354356
const { dimensionCols, valueCols } = this.getAllChartColumns();
355357
const allCols = this.pivotChart ? _.convertToSet(this.columnController.getAllDisplayedColumns()) : this.getAllColumnsFromRanges();
358+
359+
const isInitialising = this.valueColState.length < 1;
360+
356361
this.dimensionColState = [];
357362
this.valueColState = [];
358363

@@ -384,12 +389,12 @@ export class ChartDataModel extends BeanStub {
384389

385390
this.dimensionColState.unshift(defaultCategory);
386391

387-
const valueColumnsFromRange = this.valueCellRange.columns.slice();
392+
const valueColumnsFromReferenceRange = this.referenceCellRange.columns.filter(c => valueCols.has(c));
388393

389394
valueCols.forEach(column => {
390-
if (_.includes(this.valueCellRange.columns, column)) {
391-
// ensure that columns included in the specified cell range are added in the order they were specified
392-
column = valueColumnsFromRange.shift();
395+
// first time the value cell range is set, preserve the column order from the supplied range
396+
if (isInitialising && _.includes(this.referenceCellRange.columns, column)) {
397+
column = valueColumnsFromReferenceRange.shift();
393398
}
394399

395400
this.valueColState.push({

0 commit comments

Comments
 (0)