@@ -70,7 +70,7 @@ function indexCore(
7070
7171 // format an indicator for passing to the weighted mean function
7272 function formatIndicator ( indicator , entity , max ) {
73- const diverging = ! ! indicator . diverging ;
73+ const diverging = ( indicator . diverging === true || String ( indicator . diverging ) . toLocaleLowerCase ( ) === 'true' ) ;
7474 let value = entity . user && entity . user [ indicator . id ]
7575 ? Number ( entity . user [ indicator . id ] )
7676 : Number ( entity [ indicator . id ] ) ;
@@ -87,7 +87,7 @@ function indexCore(
8787 if ( indicator . max ) {
8888 range = [ 0 , indicator . max ] ;
8989 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 ) ) ] ;
9191 }
9292 } else {
9393 range = [ 0 , max ] ;
@@ -108,22 +108,23 @@ function indexCore(
108108
109109 function indexEntity ( entity , calculationList , overwrite = allowOverwrite ) {
110110 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 ] ) {
113113 // get the required component indicators to calculate the parent value
114114 // this is a bit brittle maybe?
115115
116116 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 ) )
119120 . filter ( ( indicator ) => excludeIndicator ( indicator ) === false )
120121 . map ( ( indicator ) => formatIndicator ( indicator , newEntity , indexMax ) ) ;
121122 // calculate the weighted mean of the component indicators on the newEntity
122123 // assign that value to the newEntity
123- newEntity [ indicatorID ] = calculateWeightedMean ( componentIndicators , indexMax , clamp ) ;
124+ newEntity [ parentIndicatorID ] = calculateWeightedMean ( componentIndicators , indexMax , clamp ) ;
124125 } 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 ] ) ;
127128 }
128129 } ) ;
129130
0 commit comments