Skip to content

Commit 7114559

Browse files
committed
fix(chart): fix multi reference line missing issue
1 parent 1a79e13 commit 7114559

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class BasicBarChart extends Chart {
198198
if (!colorConfigs.length) {
199199
const flatSeries = aggregateConfigs.map(aggConfig => {
200200
return {
201-
...this.getBarSeiesImpl(
201+
...this.getBarSeriesImpl(
202202
styleConfigs,
203203
settingConfigs,
204204
chartDataSet,
@@ -230,7 +230,7 @@ class BasicBarChart extends Chart {
230230
);
231231

232232
return {
233-
...this.getBarSeiesImpl(
233+
...this.getBarSeriesImpl(
234234
styleConfigs,
235235
settingConfigs,
236236
chartDataSet,
@@ -246,7 +246,7 @@ class BasicBarChart extends Chart {
246246
value: row?.getCell(aggConfig) || 0,
247247
};
248248
}),
249-
itemStyle: this.getSerieItemStyle(styleConfigs, {
249+
itemStyle: this.getSeriesItemStyle(styleConfigs, {
250250
color: itemStyleColor?.value,
251251
}),
252252
};
@@ -255,7 +255,7 @@ class BasicBarChart extends Chart {
255255
return colorizeGroupedSeries;
256256
}
257257

258-
private getBarSeiesImpl(
258+
private getBarSeriesImpl(
259259
styleConfigs,
260260
settingConfigs,
261261
chartDataSet: IChartDataSet<string>,
@@ -264,9 +264,9 @@ class BasicBarChart extends Chart {
264264
return {
265265
type: 'bar',
266266
sampling: 'average',
267-
barGap: this.getSerieBarGap(styleConfigs),
268-
barWidth: this.getSerieBarWidth(styleConfigs),
269-
itemStyle: this.getSerieItemStyle(styleConfigs, {
267+
barGap: this.getSeriesBarGap(styleConfigs),
268+
barWidth: this.getSeriesBarWidth(styleConfigs),
269+
itemStyle: this.getSeriesItemStyle(styleConfigs, {
270270
color: dataConfig?.color?.start,
271271
}),
272272
...this.getLabelStyle(styleConfigs),
@@ -307,7 +307,7 @@ class BasicBarChart extends Chart {
307307
});
308308
};
309309

310-
const _sereisTotalArrayByDataIndex = (series?.[0]?.data || []).map(
310+
const _seriesTotalArrayByDataIndex = (series?.[0]?.data || []).map(
311311
(_, index) => {
312312
const sum = series.reduce((acc, cur) => {
313313
const value = +_getAbsValue(cur.data?.[index] || 0);
@@ -318,12 +318,12 @@ class BasicBarChart extends Chart {
318318
},
319319
);
320320
(series || []).forEach(s => {
321-
s.data = _convertToPercentage(s.data, _sereisTotalArrayByDataIndex);
321+
s.data = _convertToPercentage(s.data, _seriesTotalArrayByDataIndex);
322322
});
323323
return series;
324324
}
325325

326-
private getSerieItemStyle(styles, itemStyle?) {
326+
private getSeriesItemStyle(styles, itemStyle?) {
327327
const [borderStyle, borderRadius] = getStyles(
328328
styles,
329329
['bar'],
@@ -339,12 +339,12 @@ class BasicBarChart extends Chart {
339339
};
340340
}
341341

342-
private getSerieBarGap(styles) {
342+
private getSeriesBarGap(styles) {
343343
const [gap] = getStyles(styles, ['bar'], ['gap']);
344344
return gap;
345345
}
346346

347-
private getSerieBarWidth(styles) {
347+
private getSeriesBarWidth(styles) {
348348
const [width] = getStyles(styles, ['bar'], ['width']);
349349
return width;
350350
}

frontend/src/app/utils/chartHelper.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,29 @@ export function getReference2(
493493
'rows',
494494
);
495495

496+
console.log(
497+
`getMarkArea2(
498+
referenceTabs,
499+
dataSetRows,
500+
dataConfig,
501+
isHorizonDisplay,
502+
), ---> `,
503+
getMarkArea2(referenceTabs, dataSetRows, dataConfig, isHorizonDisplay),
504+
);
505+
496506
return {
497507
markLine: getMarkLine2(
498508
referenceTabs,
499509
dataSetRows,
500510
dataConfig,
501511
isHorizonDisplay,
502512
),
503-
markArea: getMarkArea2(referenceTabs, dataSetRows, isHorizonDisplay),
513+
markArea: getMarkArea2(
514+
referenceTabs,
515+
dataSetRows,
516+
dataConfig,
517+
isHorizonDisplay,
518+
),
504519
};
505520
}
506521

@@ -676,8 +691,10 @@ function getMarkAreaData2(
676691
valueTypeKey,
677692
constantValueKey,
678693
metricKey,
694+
dataConfig,
679695
isHorizonDisplay,
680696
) {
697+
const metric = getSettingValue(mark.rows, metricKey, 'value');
681698
const valueKey = isHorizonDisplay ? 'xAxis' : 'yAxis';
682699
const show = getSettingValue(mark.rows, 'showLabel', 'value');
683700
const enableMarkArea = getSettingValue(mark.rows, 'enableMarkArea', 'value');
@@ -692,8 +709,10 @@ function getMarkAreaData2(
692709
);
693710
const name = mark.value;
694711
const valueType = getSettingValue(mark.rows, valueTypeKey, 'value');
695-
const metric = getSettingValue(mark.rows, metricKey, 'value');
696-
const metricDatas = dataSetRows.map(d => +d.getCellByKey(metric));
712+
const metricDatas =
713+
dataConfig.uid === metric
714+
? dataSetRows.map(d => +d.getCell(dataConfig))
715+
: [];
697716
const constantValue = getSettingValue(mark.rows, constantValueKey, 'value');
698717
let yAxis = 0;
699718
switch (valueType) {
@@ -711,8 +730,8 @@ function getMarkAreaData2(
711730
break;
712731
}
713732

714-
if (!enableMarkArea) {
715-
return null;
733+
if (!enableMarkArea || !Number.isFinite(yAxis) || Number.isNaN(yAxis)) {
734+
return;
716735
}
717736

718737
return {
@@ -826,12 +845,12 @@ function getMarkArea(refTabs, dataColumns, isHorizonDisplay) {
826845
function getMarkArea2(
827846
refTabs,
828847
dataSetRows: IChartDataSetRow<string>[],
848+
dataConfig,
829849
isHorizonDisplay,
830850
) {
831851
const refAreas = refTabs?.reduce((acc, cur) => {
832852
const markLineConfigs = cur?.rows?.filter(r => r.key === 'markArea');
833-
acc.push(...markLineConfigs);
834-
return acc;
853+
return acc.concat(markLineConfigs);
835854
}, []);
836855
return {
837856
data: refAreas
@@ -844,13 +863,14 @@ function getMarkArea2(
844863
`${prefix}ValueType`,
845864
`${prefix}ConstantValue`,
846865
`${prefix}Metric`,
866+
dataConfig,
847867
isHorizonDisplay,
848868
);
849869
})
850870
.filter(Boolean);
851871
return markAreaData;
852872
})
853-
.filter(m => Boolean(m?.length)),
873+
.filter(m => m?.length === 2),
854874
};
855875
}
856876

0 commit comments

Comments
 (0)