Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit f313206

Browse files
committed
Simpler loop syntax using forEach, Prettier cleanup.
1 parent a905b18 commit f313206

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/superset-ui-legacy-preset-chart-big-number/src/BigNumber/transformProps.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,31 @@ export default function transformProps(chartProps) {
5555
let percentChange = 0;
5656
let formattedSubheader = subheader;
5757
if (supportTrendLine) {
58-
const sortedData = [...data].sort((a, b) => a[TIME_COLUMN] - b[TIME_COLUMN]);
58+
const sortedData = [...data].sort(
59+
(a, b) => a[TIME_COLUMN] - b[TIME_COLUMN],
60+
);
5961
bigNumber = sortedData[sortedData.length - 1][metricName];
6062
if (compareLag > 0) {
6163
const compareIndex = sortedData.length - (compareLag + 1);
6264
if (compareIndex >= 0) {
6365
const compareValue = sortedData[compareIndex][metricName];
6466
percentChange =
65-
compareValue === 0 ? 0 : (bigNumber - compareValue) / Math.abs(compareValue);
66-
const formatPercentChange = getNumberFormatter(NumberFormats.PERCENT_SIGNED_1_POINT);
67-
formattedSubheader = `${formatPercentChange(percentChange)} ${compareSuffix}`;
67+
compareValue === 0
68+
? 0
69+
: (bigNumber - compareValue) / Math.abs(compareValue);
70+
const formatPercentChange = getNumberFormatter(
71+
NumberFormats.PERCENT_SIGNED_1_POINT,
72+
);
73+
formattedSubheader = `${formatPercentChange(
74+
percentChange,
75+
)} ${compareSuffix}`;
6876
}
6977
}
7078
trendLineData = supportAndShowTrendLine
71-
? sortedData.map(point => ({ x: point[TIME_COLUMN], y: point[metricName] }))
79+
? sortedData.map(point => ({
80+
x: point[TIME_COLUMN],
81+
y: point[metricName],
82+
}))
7283
: null;
7384
} else {
7485
bigNumber = data[0][metricName];
@@ -83,11 +94,11 @@ export default function transformProps(chartProps) {
8394
}
8495
let metricFormat = yAxisFormat;
8596
if (!yAxisFormat && chartProps.datasource && chartProps.datasource.metrics) {
86-
for (let x = 0; x < chartProps.datasource.metrics.length; x++) {
87-
if (chartProps.datasource.metrics[x].metric_name == metric && chartProps.datasource.metrics[x].d3format) {
88-
metricFormat = chartProps.datasource.metrics[x].d3format;
97+
chartProps.datasource.metrics.forEach(metric => {
98+
if (metric.metric_name == metric && metric.d3format) {
99+
metricFormat = metric.d3format;
89100
}
90-
}
101+
});
91102
}
92103

93104
const formatValue = getNumberFormatter(metricFormat);

0 commit comments

Comments
 (0)