Skip to content

Commit 0f8768c

Browse files
authored
Merge pull request #1213 from qxqzx13/dev
chart add drillbale
2 parents 4f170c4 + c8afdd6 commit 0f8768c

File tree

8 files changed

+82
-29
lines changed

8 files changed

+82
-29
lines changed

frontend/src/app/components/ChartGraph/BasicFunnelChart/BasicFunnelChart.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import ChartDataSetDTO, {
3131
import {
3232
getAutoFunnelTopPosition,
3333
getColumnRenderName,
34+
getDrillableRows,
3435
getExtraSeriesDataFormat,
3536
getExtraSeriesRowData,
3637
getGridStyle,
@@ -42,6 +43,7 @@ import {
4243
import { init } from 'echarts';
4344
import isEmpty from 'lodash/isEmpty';
4445
import Chart from '../../../models/Chart';
46+
import { ChartDrillOption } from '../../../models/ChartDrillOption';
4547
import Config from './config';
4648
import { Series, SeriesData } from './types';
4749

@@ -86,7 +88,11 @@ class BasicFunnelChart extends Chart {
8688
if (!this.isMatchRequirement(props.config)) {
8789
return;
8890
}
89-
const newOptions = this.getOptions(props.dataset, props.config);
91+
const newOptions = this.getOptions(
92+
props.dataset,
93+
props.config,
94+
props.drillOption,
95+
);
9096
this.chart?.setOption(Object.assign({}, newOptions), true);
9197
}
9298

@@ -98,12 +104,17 @@ class BasicFunnelChart extends Chart {
98104
this.chart?.resize({ width: context?.width, height: context?.height });
99105
}
100106

101-
private getOptions(dataset: ChartDataSetDTO, config: ChartConfig) {
107+
private getOptions(
108+
dataset: ChartDataSetDTO,
109+
config: ChartConfig,
110+
drillOption: ChartDrillOption,
111+
) {
102112
const styleConfigs = config.styles || [];
103113
const dataConfigs = config.datas || [];
104-
const groupConfigs = dataConfigs
105-
.filter(c => c.type === ChartDataSectionType.GROUP)
106-
.flatMap(config => config.rows || []);
114+
const groupConfigs: ChartDataSectionField[] = getDrillableRows(
115+
dataConfigs,
116+
drillOption,
117+
);
107118
const aggregateConfigs = dataConfigs
108119
.filter(c => c.type === ChartDataSectionType.AGGREGATE)
109120
.flatMap(config => config.rows || []);

frontend/src/app/components/ChartGraph/BasicFunnelChart/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const config: ChartConfig = {
3131
STRING: ['alias', 'colorize', 'sortable'],
3232
DATE: ['alias', 'colorize', 'sortable'],
3333
},
34+
drillable: true,
3435
},
3536
{
3637
label: 'metrics',

frontend/src/app/components/ChartGraph/BasicLineChart/BasicLineChart.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
getAxisTick,
3636
getColorizeGroupSeriesColumns,
3737
getColumnRenderName,
38+
getDrillableRows,
3839
getExtraSeriesDataFormat,
3940
getExtraSeriesRowData,
4041
getGridStyle,
@@ -51,6 +52,7 @@ import {
5152
import { init } from 'echarts';
5253
import { UniqArray } from 'utils/object';
5354
import Chart from '../../../models/Chart';
55+
import { ChartDrillOption } from '../../../models/ChartDrillOption';
5456
import Config from './config';
5557
import { Series } from './types';
5658

@@ -97,7 +99,11 @@ class BasicLineChart extends Chart {
9799
this.chart?.clear();
98100
return;
99101
}
100-
const newOptions = this.getOptions(props.dataset, props.config);
102+
const newOptions = this.getOptions(
103+
props.dataset,
104+
props.config,
105+
props.drillOption,
106+
);
101107
this.chart?.setOption(Object.assign({}, newOptions), true);
102108
}
103109

@@ -110,13 +116,18 @@ class BasicLineChart extends Chart {
110116
this.chart?.dispose();
111117
}
112118

113-
private getOptions(dataset: ChartDataSetDTO, config: ChartConfig) {
119+
private getOptions(
120+
dataset: ChartDataSetDTO,
121+
config: ChartConfig,
122+
drillOption: ChartDrillOption,
123+
) {
114124
const styleConfigs = config.styles || [];
115125
const dataConfigs = config.datas || [];
116126
const settingConfigs = config.settings || [];
117-
const groupConfigs = dataConfigs
118-
.filter(c => c.type === ChartDataSectionType.GROUP)
119-
.flatMap(config => config.rows || []);
127+
const groupConfigs: ChartDataSectionField[] = getDrillableRows(
128+
dataConfigs,
129+
drillOption,
130+
);
120131
const aggregateConfigs = dataConfigs
121132
.filter(c => c.type === ChartDataSectionType.AGGREGATE)
122133
.flatMap(config => config.rows || []);
@@ -133,13 +144,17 @@ class BasicLineChart extends Chart {
133144
dataConfigs,
134145
);
135146

136-
const xAxisColumns: XAxisColumns[] = (groupConfigs || []).map(config => {
137-
return {
147+
const xAxisColumns: XAxisColumns[] = [
148+
{
138149
type: 'category',
139150
tooltip: { show: true },
140-
data: UniqArray(chartDataSet.map(dc => dc.getCell(config))),
141-
};
142-
});
151+
data: UniqArray(
152+
chartDataSet?.map(row => {
153+
return groupConfigs.map(g => row.getCell(g)).join('-');
154+
}),
155+
),
156+
},
157+
];
143158
const series = this.getSeries(
144159
settingConfigs,
145160
styleConfigs,
@@ -215,7 +230,6 @@ class BasicLineChart extends Chart {
215230
});
216231
}
217232

218-
const xAxisConfig = groupConfigs?.[0];
219233
const secondGroupInfos = getColorizeGroupSeriesColumns(
220234
chartDataSet,
221235
colorConfigs[0],
@@ -239,7 +253,9 @@ class BasicLineChart extends Chart {
239253
normal: { color: itemStyleColor?.value },
240254
},
241255
data: xAxisColumns[0].data.map(d => {
242-
const row = dataSet.find(r => r.getCell(xAxisConfig) === d)!;
256+
const row = dataSet.find(
257+
r => r.getMultiCell(...groupConfigs) === d,
258+
)!;
243259
return {
244260
...getExtraSeriesRowData(row),
245261
...getExtraSeriesDataFormat(aggConfig?.format),

frontend/src/app/components/ChartGraph/BasicLineChart/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const config: ChartConfig = {
2525
key: 'dimension',
2626
required: true,
2727
type: 'group',
28-
limit: 1,
28+
limit: [1, 999],
29+
drillable: true,
2930
},
3031
{
3132
label: 'metrics',

frontend/src/app/components/ChartGraph/BasicPieChart/BasicPieChart.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import ChartDataSetDTO, {
3030
} from 'app/types/ChartDataSet';
3131
import {
3232
getColumnRenderName,
33+
getDrillableRows,
3334
getExtraSeriesDataFormat,
3435
getExtraSeriesRowData,
3536
getGridStyle,
@@ -40,6 +41,7 @@ import {
4041
} from 'app/utils/chartHelper';
4142
import { init } from 'echarts';
4243
import Chart from '../../../models/Chart';
44+
import { ChartDrillOption } from '../../../models/ChartDrillOption';
4345
import Config from './config';
4446
import { PieSeries, PieSeriesImpl, PieSeriesStyle } from './types';
4547

@@ -83,7 +85,11 @@ class BasicPieChart extends Chart {
8385
this.chart?.clear();
8486
return;
8587
}
86-
const newOptions = this.getOptions(props.dataset, props.config);
88+
const newOptions = this.getOptions(
89+
props.dataset,
90+
props.config,
91+
props.drillOption,
92+
);
8793
this.chart?.setOption(Object.assign({}, newOptions), true);
8894
}
8995

@@ -95,12 +101,17 @@ class BasicPieChart extends Chart {
95101
this.chart?.resize(context);
96102
}
97103

98-
private getOptions(dataset: ChartDataSetDTO, config: ChartConfig) {
104+
private getOptions(
105+
dataset: ChartDataSetDTO,
106+
config: ChartConfig,
107+
drillOption: ChartDrillOption,
108+
) {
99109
const styleConfigs = config.styles || [];
100110
const dataConfigs = config.datas || [];
101-
const groupConfigs = dataConfigs
102-
.filter(c => c.type === ChartDataSectionType.GROUP)
103-
.flatMap(config => config.rows || []);
111+
const groupConfigs: ChartDataSectionField[] = getDrillableRows(
112+
dataConfigs,
113+
drillOption,
114+
);
104115
const aggregateConfigs = dataConfigs
105116
.filter(c => c.type === ChartDataSectionType.AGGREGATE)
106117
.flatMap(config => config.rows || []);

frontend/src/app/components/ChartGraph/BasicPieChart/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ const config: ChartConfig = {
2525
key: 'dimension',
2626
required: true,
2727
type: 'group',
28-
limit: [0, 1],
28+
limit: [0, 999],
2929
actions: {
3030
NUMERIC: ['alias', 'colorize', 'sortable'],
3131
STRING: ['alias', 'colorize', 'sortable'],
3232
DATE: ['alias', 'colorize', 'sortable'],
3333
},
34+
drillable: true,
3435
},
3536
{
3637
label: 'metrics',

frontend/src/app/components/ChartGraph/BasicScatterChart/BasicScatterChart.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ChartDataSetDTO, { IChartDataSet } from 'app/types/ChartDataSet';
2929
import {
3030
getColumnRenderName,
3131
getDataColumnMaxAndMin2,
32+
getDrillableRows,
3233
getExtraSeriesRowData,
3334
getGridStyle,
3435
getReference2,
@@ -39,6 +40,7 @@ import {
3940
} from 'app/utils/chartHelper';
4041
import { init } from 'echarts';
4142
import Chart from '../../../models/Chart';
43+
import { ChartDrillOption } from '../../../models/ChartDrillOption';
4244
import Config from './config';
4345
import { ScatterMetricAndSizeSerie } from './types';
4446

@@ -80,7 +82,11 @@ class BasicScatterChart extends Chart {
8082
this.chart?.clear();
8183
return;
8284
}
83-
const newOptions = this.getOptions(props.dataset, props.config);
85+
const newOptions = this.getOptions(
86+
props.dataset,
87+
props.config,
88+
props.drillOption,
89+
);
8490
this.chart?.setOption(Object.assign({}, newOptions), true);
8591
}
8692

@@ -92,13 +98,18 @@ class BasicScatterChart extends Chart {
9298
this.chart?.resize(opt, context);
9399
}
94100

95-
private getOptions(dataset: ChartDataSetDTO, config: ChartConfig) {
101+
private getOptions(
102+
dataset: ChartDataSetDTO,
103+
config: ChartConfig,
104+
drillOption: ChartDrillOption,
105+
) {
96106
const styleConfigs = config.styles || [];
97107
const dataConfigs = config.datas || [];
98108
const settingConfigs = config.settings || [];
99-
const groupConfigs = dataConfigs
100-
.filter(c => c.type === ChartDataSectionType.GROUP)
101-
.flatMap(config => config.rows || []);
109+
const groupConfigs: ChartDataSectionField[] = getDrillableRows(
110+
dataConfigs,
111+
drillOption,
112+
);
102113
const aggregateConfigs = dataConfigs
103114
.filter(c => c.type === ChartDataSectionType.AGGREGATE)
104115
.flatMap(config => config.rows || []);

frontend/src/app/components/ChartGraph/BasicScatterChart/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const config: ChartConfig = {
2525
key: 'dimension',
2626
type: 'group',
2727
required: true,
28+
drillable: true,
2829
},
2930
{
3031
label: 'metrics',

0 commit comments

Comments
 (0)