Skip to content

Commit

Permalink
fix: 0 indicator on radar viz (apache#1282)
Browse files Browse the repository at this point in the history
* fix: 0 indicator on radar viz

* fix lint
  • Loading branch information
zhaoyongjie committed Nov 17, 2021
1 parent 0b7a214 commit 19b795d
Showing 1 changed file with 31 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@
import {
CategoricalColorNamespace,
DataRecordValue,
ensureIsInt,
getMetricLabel,
getNumberFormatter,
getTimeFormatter,
Expand Down Expand Up @@ -100,6 +101,7 @@ export default function transformProps(

const metricsLabel = metrics.map(metric => getMetricLabel(metric));

const metricLabelAndMaxValueMap = new Map<string, number>();
const columnsLabelMap = new Map<string, DataRecordValue[]>();
const transformedData: RadarSeriesDataItemOption[] = [];
data.forEach(datum => {
Expand All @@ -115,6 +117,22 @@ export default function transformProps(
groupby.map(col => datum[col]),
);

// put max value of series into metricLabelAndMaxValueMap
// eslint-disable-next-line no-restricted-syntax
for (const [metricLabel, value] of Object.entries(datum)) {
if (metricLabelAndMaxValueMap.has(metricLabel)) {
metricLabelAndMaxValueMap.set(
metricLabel,
Math.max(
value as number,
ensureIsInt(metricLabelAndMaxValueMap.get(metricLabel), Number.MIN_SAFE_INTEGER),
),
);
} else {
metricLabelAndMaxValueMap.set(metricLabel, value as number);
}
}

const isFiltered =
filterState.selectedValues && !filterState.selectedValues.includes(joinedName);

Expand Down Expand Up @@ -148,10 +166,19 @@ export default function transformProps(
{},
);

const indicator = metricsLabel.map(metricLabel => ({
name: metricLabel,
max: columnConfig?.[metricLabel]?.radarMetricMaxValue,
}));
const indicator = metricsLabel.map(metricLabel => {
const maxValueInControl = columnConfig?.[metricLabel]?.radarMetricMaxValue;
// Ensure that 0 is at the center of the polar coordinates
const metricValueAsMax =
metricLabelAndMaxValueMap.get(metricLabel) === 0
? Number.MAX_SAFE_INTEGER
: metricLabelAndMaxValueMap.get(metricLabel);
const max = maxValueInControl === null ? metricValueAsMax : maxValueInControl;
return {
name: metricLabel,
max,
};
});

const series: RadarSeriesOption[] = [
{
Expand Down

0 comments on commit 19b795d

Please sign in to comment.