@@ -4,7 +4,7 @@ import { arraysAreEqualWithStrictOrder } from '~utils/common/equality';
44import { sentimentDefault , sentimentReversed } from './constants' ;
55import { JsMath , MapMath } from './operations' ;
66import type { IsomorphMath } from './operations' ;
7- import type { MCDAConfig , TransformationFunction } from '../types' ;
7+ import type { MCDALayer , TransformationFunction } from '../types' ;
88
99const equalSentiments = ( a : Array < string > , b : Array < string > ) =>
1010 arraysAreEqualWithStrictOrder ( a , b ) ;
@@ -178,17 +178,22 @@ export const calculateLayerPipeline =
178178 type : 'view' | 'layerStyle' ,
179179 getValue : ( axis : { num : string ; den : string } ) => { num : T ; den : T } ,
180180 ) =>
181- ( {
182- axis,
183- range,
184- coefficient,
185- sentiment,
186- transformationFunction,
187- transformation,
188- normalization,
189- outliers,
190- datasetStats,
191- } : MCDAConfig [ 'layers' ] [ 0 ] ) => {
181+ (
182+ layer : MCDALayer ,
183+ forceMinMaxInLayerStyle ?: boolean ,
184+ preventValueInversion ?: boolean ,
185+ ) => {
186+ const {
187+ axis,
188+ range,
189+ coefficient,
190+ sentiment,
191+ transformationFunction,
192+ transformation,
193+ normalization,
194+ outliers,
195+ datasetStats,
196+ } = layer ;
192197 // @ts -expect-error - IsomorphCalculations typing needs fixing. The code works though, so for now ignoring the ts error
193198 const operations : IsomorphCalculations < number > =
194199 type === 'layerStyle' ? inStyleCalculations : inViewCalculations ;
@@ -246,13 +251,16 @@ export const calculateLayerPipeline =
246251 }
247252 }
248253 let normalized = tX ;
249- if ( normalization === 'max-min' || type === 'layerStyle' ) {
250- // always apply min-max normalization for layer style,
251- // because we need to have (0..1) values in expressions for proper colors interpolation
254+ if (
255+ normalization === 'max-min' ||
256+ ( type === 'layerStyle' && forceMinMaxInLayerStyle )
257+ ) {
258+ // always apply min-max normalization for mcda style with sentiments colors,
259+ // because we need to have (0..1) values in expressions for proper colors interpolation in sentiments colors (see sentimentPaint())
252260 normalized = operations . normalize ( { x : tX , min : tMin , max : tMax } ) ;
253261 }
254262 let oriented = inverted ? operations . invert ( normalized ) : normalized ;
255- if ( type === 'view' && normalization === 'no' ) {
263+ if ( ( type === 'view' && normalization === 'no' ) || preventValueInversion ) {
256264 // don't invert non-normalized values, because applying (1-value) doesn't make sense for them
257265 oriented = normalized ;
258266 }
0 commit comments