@@ -55,20 +55,31 @@ export default function transformProps(chartProps) {
55
55
let percentChange = 0 ;
56
56
let formattedSubheader = subheader ;
57
57
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
+ ) ;
59
61
bigNumber = sortedData [ sortedData . length - 1 ] [ metricName ] ;
60
62
if ( compareLag > 0 ) {
61
63
const compareIndex = sortedData . length - ( compareLag + 1 ) ;
62
64
if ( compareIndex >= 0 ) {
63
65
const compareValue = sortedData [ compareIndex ] [ metricName ] ;
64
66
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 } `;
68
76
}
69
77
}
70
78
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
+ } ) )
72
83
: null ;
73
84
} else {
74
85
bigNumber = data [ 0 ] [ metricName ] ;
@@ -83,11 +94,11 @@ export default function transformProps(chartProps) {
83
94
}
84
95
let metricFormat = yAxisFormat ;
85
96
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 ;
89
100
}
90
- }
101
+ } ) ;
91
102
}
92
103
93
104
const formatValue = getNumberFormatter ( metricFormat ) ;
0 commit comments