@@ -161,9 +161,14 @@ function getUpdateSizeMethod(graph, sizeSettings) {
161161 }
162162}
163163
164- function getDirectVariableColorUpdateMethod ( source ) {
165- return attributes =>
166- ( attributes . color = tinycolor ( attributes . data [ source ] ) . toHexString ( ) )
164+ function getDirectVariableColorUpdateMethod ( source , opacity = 100 ) {
165+ return attributes => {
166+ const color = tinycolor ( attributes . data [ source ] )
167+ const colorOpacity = color . getAlpha ( )
168+ attributes . color = color
169+ . setAlpha ( ( opacity / 100 ) * colorOpacity )
170+ . toHex8String ( )
171+ }
167172}
168173
169174function getUpdateNodeColorMethod ( graph , colorSettings ) {
@@ -175,10 +180,16 @@ function getUpdateNodeColorMethod(graph, colorSettings) {
175180 colorscale,
176181 colorscaleDirection,
177182 mode,
178- method
183+ method,
184+ opacity
179185 } = colorSettings
180186 if ( type === 'constant' ) {
181- return attributes => ( attributes . color = value )
187+ const color = tinycolor ( value )
188+ const colorOpacity = color . getAlpha ( )
189+ return attributes =>
190+ ( attributes . color = color
191+ . setAlpha ( ( opacity / 100 ) * colorOpacity )
192+ . toHex8String ( ) )
182193 } else if ( type === 'variable' ) {
183194 return sourceUsage === 'map_to'
184195 ? getColorMethod (
@@ -187,17 +198,19 @@ function getUpdateNodeColorMethod(graph, colorSettings) {
187198 ( nodeId , attributes ) => attributes . data [ source ] ,
188199 colorscale ,
189200 colorscaleDirection ,
190- getNodeValueScale
201+ getNodeValueScale ,
202+ opacity
191203 )
192- : getDirectVariableColorUpdateMethod ( source )
204+ : getDirectVariableColorUpdateMethod ( source , opacity )
193205 } else {
194206 return getColorMethod (
195207 graph ,
196208 mode ,
197209 nodeId => graph [ method ] ( nodeId ) ,
198210 colorscale ,
199211 colorscaleDirection ,
200- getNodeValueScale
212+ getNodeValueScale ,
213+ opacity
201214 )
202215 }
203216}
@@ -244,8 +257,10 @@ function getColorMethod(
244257 sourceGetter ,
245258 selectedColorscale ,
246259 colorscaleDirection ,
247- valueScaleGetter
260+ valueScaleGetter ,
261+ opacity = 100
248262) {
263+ const opacityFactor = opacity / 100
249264 const valueScale = valueScaleGetter ( graph , sourceGetter )
250265 let colorscale = selectedColorscale || DEFAULT_SCALE
251266 if ( colorscaleDirection === 'reversed' ) {
@@ -261,7 +276,9 @@ function getColorMethod(
261276 )
262277 return ( attributes , nodeId ) => {
263278 const category = sourceGetter ( nodeId , attributes )
264- attributes . color = colorMap [ category ]
279+ attributes . color = tinycolor ( colorMap [ category ] )
280+ . setAlpha ( opacityFactor )
281+ . toHex8String ( )
265282 }
266283 } else {
267284 const min = valueScale [ 0 ]
@@ -274,14 +291,18 @@ function getColorMethod(
274291 const value = sourceGetter ( nodeId , attributes )
275292 const normalizedValue = ( value - min ) / ( max - min )
276293 if ( isNaN ( normalizedValue ) ) {
277- attributes . color = '#000000'
294+ attributes . color = tinycolor ( '#000000' )
295+ . setAlpha ( opacityFactor )
296+ . toHex8String ( )
278297 return
279298 }
280299 const exactMatch = normalizedColorscale . find (
281300 ( [ value ] ) => value === normalizedValue
282301 )
283302 if ( exactMatch ) {
284- attributes . color = tinycolor ( exactMatch [ 1 ] ) . toHexString ( )
303+ attributes . color = tinycolor ( exactMatch [ 1 ] )
304+ . setAlpha ( opacityFactor )
305+ . toHex8String ( )
285306 return
286307 }
287308
@@ -305,7 +326,9 @@ function getColorMethod(
305326 r : r0 + interpolationFactor * ( r1 - r0 ) ,
306327 g : g0 + interpolationFactor * ( g1 - g0 ) ,
307328 b : b0 + interpolationFactor * ( b1 - b0 )
308- } ) . toHexString ( )
329+ } )
330+ . setAlpha ( opacityFactor )
331+ . toHex8String ( )
309332 }
310333 }
311334}
0 commit comments