fix(radar-chart): metric options not available & add `min` option (#30349)
This commit is contained in:
parent
03146b21be
commit
b2fd56094f
|
|
@ -56,6 +56,22 @@ const radarMetricMaxValue: { name: string; config: ControlFormItemSpec } = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const radarMetricMinValue: { name: string; config: ControlFormItemSpec } = {
|
||||||
|
name: 'radarMetricMinValue',
|
||||||
|
config: {
|
||||||
|
controlType: 'InputNumber',
|
||||||
|
label: t('Min'),
|
||||||
|
description: t(
|
||||||
|
'The minimum value of metrics. It is an optional configuration. If not set, it will be the minimum value of the data',
|
||||||
|
),
|
||||||
|
defaultValue: '0',
|
||||||
|
width: 120,
|
||||||
|
placeholder: t('auto'),
|
||||||
|
debounceDelay: 400,
|
||||||
|
validators: [validateNumber],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const config: ControlPanelConfig = {
|
const config: ControlPanelConfig = {
|
||||||
controlPanelSections: [
|
controlPanelSections: [
|
||||||
{
|
{
|
||||||
|
|
@ -164,7 +180,9 @@ const config: ControlPanelConfig = {
|
||||||
description: t('Further customize how to display each metric'),
|
description: t('Further customize how to display each metric'),
|
||||||
renderTrigger: true,
|
renderTrigger: true,
|
||||||
configFormLayout: {
|
configFormLayout: {
|
||||||
[GenericDataType.Numeric]: [[radarMetricMaxValue]],
|
[GenericDataType.Numeric]: [
|
||||||
|
[radarMetricMinValue, radarMetricMaxValue],
|
||||||
|
],
|
||||||
},
|
},
|
||||||
shouldMapStateToProps() {
|
shouldMapStateToProps() {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -179,11 +197,17 @@ const config: ControlPanelConfig = {
|
||||||
}
|
}
|
||||||
return value.label;
|
return value.label;
|
||||||
});
|
});
|
||||||
|
const { colnames: _colnames, coltypes: _coltypes } =
|
||||||
|
chart?.queriesResponse?.[0] ?? {};
|
||||||
|
const colnames: string[] = _colnames || [];
|
||||||
|
const coltypes: GenericDataType[] = _coltypes || [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
queryResponse: chart?.queriesResponse?.[0] as
|
queryResponse: chart?.queriesResponse?.[0] as
|
||||||
| ChartDataResponseResult
|
| ChartDataResponseResult
|
||||||
| undefined,
|
| undefined,
|
||||||
appliedColumnNames: metricColumn,
|
appliedColumnNames: metricColumn,
|
||||||
|
columnsPropsObject: { colnames, coltypes },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ export default function transformProps(
|
||||||
const groupbyLabels = groupby.map(getColumnLabel);
|
const groupbyLabels = groupby.map(getColumnLabel);
|
||||||
|
|
||||||
const metricLabelAndMaxValueMap = new Map<string, number>();
|
const metricLabelAndMaxValueMap = new Map<string, number>();
|
||||||
|
const metricLabelAndMinValueMap = new Map<string, number>();
|
||||||
const columnsLabelMap = new Map<string, string[]>();
|
const columnsLabelMap = new Map<string, string[]>();
|
||||||
const transformedData: RadarSeriesDataItemOption[] = [];
|
const transformedData: RadarSeriesDataItemOption[] = [];
|
||||||
data.forEach(datum => {
|
data.forEach(datum => {
|
||||||
|
|
@ -155,6 +156,21 @@ export default function transformProps(
|
||||||
} else {
|
} else {
|
||||||
metricLabelAndMaxValueMap.set(metricLabel, value as number);
|
metricLabelAndMaxValueMap.set(metricLabel, value as number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metricLabelAndMinValueMap.has(metricLabel)) {
|
||||||
|
metricLabelAndMinValueMap.set(
|
||||||
|
metricLabel,
|
||||||
|
Math.min(
|
||||||
|
value as number,
|
||||||
|
ensureIsInt(
|
||||||
|
metricLabelAndMinValueMap.get(metricLabel),
|
||||||
|
Number.MAX_SAFE_INTEGER,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
metricLabelAndMinValueMap.set(metricLabel, value as number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isFiltered =
|
const isFiltered =
|
||||||
|
|
@ -199,6 +215,8 @@ export default function transformProps(
|
||||||
|
|
||||||
const indicator = metricLabels.map(metricLabel => {
|
const indicator = metricLabels.map(metricLabel => {
|
||||||
const maxValueInControl = columnConfig?.[metricLabel]?.radarMetricMaxValue;
|
const maxValueInControl = columnConfig?.[metricLabel]?.radarMetricMaxValue;
|
||||||
|
const minValueInControl = columnConfig?.[metricLabel]?.radarMetricMinValue;
|
||||||
|
|
||||||
// Ensure that 0 is at the center of the polar coordinates
|
// Ensure that 0 is at the center of the polar coordinates
|
||||||
const metricValueAsMax =
|
const metricValueAsMax =
|
||||||
metricLabelAndMaxValueMap.get(metricLabel) === 0
|
metricLabelAndMaxValueMap.get(metricLabel) === 0
|
||||||
|
|
@ -206,9 +224,23 @@ export default function transformProps(
|
||||||
: metricLabelAndMaxValueMap.get(metricLabel);
|
: metricLabelAndMaxValueMap.get(metricLabel);
|
||||||
const max =
|
const max =
|
||||||
maxValueInControl === null ? metricValueAsMax : maxValueInControl;
|
maxValueInControl === null ? metricValueAsMax : maxValueInControl;
|
||||||
|
|
||||||
|
let min: number;
|
||||||
|
// If the min value doesn't exist, set it to 0 (default),
|
||||||
|
// if it is null, set it to the min value of the data,
|
||||||
|
// otherwise, use the value from the control
|
||||||
|
if (minValueInControl === undefined) {
|
||||||
|
min = 0;
|
||||||
|
} else if (minValueInControl === null) {
|
||||||
|
min = metricLabelAndMinValueMap.get(metricLabel) || 0;
|
||||||
|
} else {
|
||||||
|
min = minValueInControl;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: metricLabel,
|
name: metricLabel,
|
||||||
max,
|
max,
|
||||||
|
min,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,10 @@ import {
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { DEFAULT_LEGEND_FORM_DATA } from '../constants';
|
import { DEFAULT_LEGEND_FORM_DATA } from '../constants';
|
||||||
|
|
||||||
type RadarColumnConfig = Record<string, { radarMetricMaxValue?: number }>;
|
type RadarColumnConfig = Record<
|
||||||
|
string,
|
||||||
|
{ radarMetricMaxValue?: number; radarMetricMinValue?: number }
|
||||||
|
>;
|
||||||
|
|
||||||
export type EchartsRadarFormData = QueryFormData &
|
export type EchartsRadarFormData = QueryFormData &
|
||||||
LegendFormData & {
|
LegendFormData & {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue