Skip to content

Commit

Permalink
Merge pull request #1820 from VisActor/1817-bug-indicatorkey-sameWith…
Browse files Browse the repository at this point in the history
…DimensionValue

1817 bug indicatorkey same with dimension value
  • Loading branch information
fangsmile authored May 30, 2024
2 parents c28f210 + 1b9faa4 commit 26adafc
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "refactor: dimension value same with indicator key cell value error #1817\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
63 changes: 54 additions & 9 deletions packages/vtable/src/PivotChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,19 +590,34 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
return typeof fieldFormat === 'function' ? fieldFormat(title, col, row, this as BaseTableAPI) : title;
}
if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
return aggregator.value ? aggregator.value() : undefined;
}
Expand Down Expand Up @@ -641,19 +656,34 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
return typeof title === 'function' ? title() : title;
}
if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
return aggregator.value ? aggregator.value() : undefined;
// return ''
Expand All @@ -677,19 +707,34 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
return undefined;
}
if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
return aggregator.records;
// return ''
Expand Down
125 changes: 107 additions & 18 deletions packages/vtable/src/PivotTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,18 +557,33 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
} else if (this.dataset) {
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
if (cellDimensionPath) {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
if (aggregator.records && aggregator.records.length >= 1) {
return aggregator.records[0][field];
Expand Down Expand Up @@ -626,26 +641,41 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
return dataValue;
} else if (this.dataset) {
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const colKeys = cellDimensionPath.colHeaderPaths
?.filter((path: any) => {
return !path.virtual;
})
?.map((colPath: any) => {
?.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths
?.filter((path: any) => {
return !path.virtual;
})
?.map((rowPath: any) => {
?.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
const { fieldFormat } = this.internalProps.layoutMap.getBody(col, row) as IndicatorData;
// return typeof fieldFormat === 'function'
Expand Down Expand Up @@ -690,19 +720,34 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
const dataValue = this.records[rowIndex]?.[colIndex];
return dataValue;
} else if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
return aggregator.value ? aggregator.value() : undefined;
// return ''
Expand Down Expand Up @@ -740,11 +785,24 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
const dataValue = this.records[rowIndex]?.[colIndex];
return dataValue;
} else if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
Expand All @@ -753,7 +811,8 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
false
false,
indicatorPosition
);
return aggregator.value ? aggregator.value() : undefined;
} else if (this.flatDataToObjects) {
Expand Down Expand Up @@ -787,19 +846,34 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
const dataValue = this.records[rowIndex]?.[colIndex];
return dataValue;
} else if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
true,
indicatorPosition
);
return aggregator.records;
// return ''
Expand Down Expand Up @@ -832,19 +906,34 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
const dataValue = this.records[rowIndex]?.[colIndex];
return dataValue;
} else if (this.dataset) {
let indicatorPosition: { position: 'col' | 'row'; index?: number };
const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row);
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any) => {
const colKeys = cellDimensionPath.colHeaderPaths.map((colPath: any, index: number) => {
if (colPath.indicatorKey) {
indicatorPosition = {
position: 'col',
index
};
}
return colPath.indicatorKey ?? colPath.value;
});
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any) => {
const rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath: any, index: number) => {
if (rowPath.indicatorKey) {
indicatorPosition = {
position: 'row',
index
};
}
return rowPath.indicatorKey ?? rowPath.value;
});
const aggregator = this.dataset.getAggregator(
// !this.internalProps.layoutMap.indicatorsAsCol ? rowKeys.slice(0, -1) : rowKeys,
// this.internalProps.layoutMap.indicatorsAsCol ? colKeys.slice(0, -1) : colKeys,
rowKeys,
colKeys,
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row)
(this.internalProps.layoutMap as PivotHeaderLayoutMap).getIndicatorKey(col, row),
false,
indicatorPosition
);
return aggregator.records;
// return ''
Expand Down
Loading

0 comments on commit 26adafc

Please sign in to comment.