Skip to content

Commit

Permalink
feat: add supplementIndicatorNodes config #1644
Browse files Browse the repository at this point in the history
  • Loading branch information
fangsmile committed May 14, 2024
1 parent 88d5692 commit fcd864c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/vtable/src/PivotChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type { ITreeLayoutHeadNode } from './layout/tree-helper';
import { DimensionTree, type LayouTreeNode } from './layout/tree-helper';
import { IndicatorDimensionKeyPlaceholder } from './tools/global';
import { checkHasCartesianChart } from './layout/chart-helper/get-chart-spec';
import { supplementIndicatorNodesForCustomTree } from './layout/layout-helper';
export class PivotChart extends BaseTable implements PivotChartAPI {
layoutNodeId: { seqId: number } = { seqId: 0 };
declare internalProps: PivotChartProtected;
Expand Down Expand Up @@ -97,12 +98,18 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
let columnDimensionTree;
let rowDimensionTree;
if (options.columnTree) {
if (options.indicatorsAsCol !== false) {
supplementIndicatorNodesForCustomTree(this.internalProps.columnTree, options.indicators);
}
columnDimensionTree = new DimensionTree(
(this.internalProps.columnTree as ITreeLayoutHeadNode[]) ?? [],
this.layoutNodeId
);
}
if (options.rowTree) {
if (options.indicatorsAsCol === false) {
supplementIndicatorNodesForCustomTree(this.internalProps.rowTree, options.indicators);
}
rowDimensionTree = new DimensionTree(
(this.internalProps.rowTree as ITreeLayoutHeadNode[]) ?? [],
this.layoutNodeId
Expand Down Expand Up @@ -267,12 +274,18 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
let columnDimensionTree;
let rowDimensionTree;
if (options.columnTree) {
if (options.indicatorsAsCol !== false) {
supplementIndicatorNodesForCustomTree(this.internalProps.columnTree, options.indicators);
}
columnDimensionTree = new DimensionTree(
(this.internalProps.columnTree as ITreeLayoutHeadNode[]) ?? [],
this.layoutNodeId
);
}
if (options.rowTree) {
if (options.indicatorsAsCol === false) {
supplementIndicatorNodesForCustomTree(this.internalProps.rowTree, options.indicators);
}
rowDimensionTree = new DimensionTree(
(this.internalProps.rowTree as ITreeLayoutHeadNode[]) ?? [],
this.layoutNodeId
Expand Down
5 changes: 4 additions & 1 deletion packages/vtable/src/layout/layout-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ export function parseColKeyRowKeyForPivotTable(table: PivotTable, options: Pivot
};
}

function supplementIndicatorNodesForCustomTree(customTree: IHeaderTreeDefine[], indicators: (string | IIndicator)[]) {
export function supplementIndicatorNodesForCustomTree(
customTree: IHeaderTreeDefine[],
indicators: (string | IIndicator)[]
) {
const checkNode = (nodes: IHeaderTreeDefine[], isHasIndicator: boolean) => {
nodes.forEach((node: IHeaderTreeDefine) => {
if (
Expand Down
7 changes: 7 additions & 0 deletions packages/vtable/src/tools/get-data-path/create-dataset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dataset } from '../../dataset/dataset';
import { supplementIndicatorNodesForCustomTree } from '../../layout/layout-helper';
import type { ITreeLayoutHeadNode } from '../../layout/tree-helper';
import { DimensionTree } from '../../layout/tree-helper';
import type {
Expand All @@ -18,9 +19,15 @@ export function createDataset(options: PivotChartConstructorOptions) {
let columnDimensionTree;
let rowDimensionTree;
if (options.columnTree) {
if (options.indicatorsAsCol !== false) {
supplementIndicatorNodesForCustomTree(options.columnTree, options.indicators);
}
columnDimensionTree = new DimensionTree((options.columnTree as ITreeLayoutHeadNode[]) ?? [], layoutNodeId);
}
if (options.rowTree) {
if (options.indicatorsAsCol === false) {
supplementIndicatorNodesForCustomTree(options.rowTree, options.indicators);
}
rowDimensionTree = new DimensionTree((options.rowTree as ITreeLayoutHeadNode[]) ?? [], layoutNodeId);
}
const rowKeys = rowDimensionTree.dimensionKeys?.count
Expand Down

0 comments on commit fcd864c

Please sign in to comment.