@@ -70,7 +70,7 @@ function indexCore(
70
70
71
71
// format an indicator for passing to the weighted mean function
72
72
function formatIndicator ( indicator , entity , max ) {
73
- const diverging = ! ! indicator . diverging ;
73
+ const diverging = ( indicator . diverging === true || String ( indicator . diverging ) . toLocaleLowerCase ( ) === 'true' ) ;
74
74
let value = entity . user && entity . user [ indicator . id ]
75
75
? Number ( entity . user [ indicator . id ] )
76
76
: Number ( entity [ indicator . id ] ) ;
@@ -87,7 +87,7 @@ function indexCore(
87
87
if ( indicator . max ) {
88
88
range = [ 0 , indicator . max ] ;
89
89
if ( indicator . min ) {
90
- range = [ 0 , Math . max ( Math . abs ( indicator . min ) , indicator . max ) ] ;
90
+ range = [ 0 , Math . max ( Math . abs ( indicator . min ) , Math . abs ( indicator . max ) ) ] ;
91
91
}
92
92
} else {
93
93
range = [ 0 , max ] ;
@@ -108,22 +108,23 @@ function indexCore(
108
108
109
109
function indexEntity ( entity , calculationList , overwrite = allowOverwrite ) {
110
110
const newEntity = clone ( entity ) ;
111
- calculationList . forEach ( ( indicatorID ) => {
112
- if ( ( newEntity [ indicatorID ] && overwrite === true ) || ! newEntity [ indicatorID ] ) {
111
+ calculationList . forEach ( ( parentIndicatorID ) => {
112
+ if ( ( newEntity [ parentIndicatorID ] && overwrite === true ) || ! newEntity [ parentIndicatorID ] ) {
113
113
// get the required component indicators to calculate the parent value
114
114
// this is a bit brittle maybe?
115
115
116
116
const componentIndicators = indicatorsData
117
- . filter ( ( indicator ) => ( indicator . id . indexOf ( indicatorID ) === 0
118
- && indicator . id . length === indicatorID . length + 2 ) )
117
+ . filter ( ( indicator ) => (
118
+ indicator . id . indexOf ( parentIndicatorID ) === 0 // the
119
+ && indicator . id . split ( '.' ) . length === parentIndicatorID . split ( '.' ) . length + 1 ) )
119
120
. filter ( ( indicator ) => excludeIndicator ( indicator ) === false )
120
121
. map ( ( indicator ) => formatIndicator ( indicator , newEntity , indexMax ) ) ;
121
122
// calculate the weighted mean of the component indicators on the newEntity
122
123
// assign that value to the newEntity
123
- newEntity [ indicatorID ] = calculateWeightedMean ( componentIndicators , indexMax , clamp ) ;
124
+ newEntity [ parentIndicatorID ] = calculateWeightedMean ( componentIndicators , indexMax , clamp ) ;
124
125
} else {
125
- console . warn ( `retaining existing value for ${ newEntity . name } - ${ indicatorID } : ${ Number ( entity [ indicatorID ] ) } ` ) ;
126
- newEntity [ indicatorID ] = Number ( entity [ indicatorID ] ) ;
126
+ console . warn ( `retaining existing value for ${ newEntity . name } - ${ parentIndicatorID } : ${ Number ( entity [ parentIndicatorID ] ) } ` ) ;
127
+ newEntity [ parentIndicatorID ] = Number ( entity [ parentIndicatorID ] ) ;
127
128
}
128
129
} ) ;
129
130
0 commit comments