You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
While @encodable/color exposes all D3 color maps, the main library is not using the interpolator with scaleSequential. Instead scaleLinear is used with a range of the scheme colors. However, this effectively results in a linear scale between the first two colors of the scheme only. Sequential multi-hue color scales are thus not supported.
Describe the solution you'd like
My understanding is that we'd have to extend encodable's createScale():
functioncreateScale<OutputextendsDefaultOutput>(config: ScaleConfig<Output>){const{ range }=config;// Handle categorical color scales// An ordinal scale without specified range// is assumed to be a color scale.if(config.type===ScaleType.ORDINAL&&typeofrange==='undefined'){constscheme='scheme'inconfig ? config.scheme : undefined;constresolve=Encodable.getCategoricalColorScaleResolver();letcolorScale: ScaleOrdinal<StringLike,string>;if(typeofscheme==='undefined'){colorScale=resolve({});}elseif(isSchemeParams(scheme)){colorScale=resolve(scheme);}else{colorScale=resolve({name: scheme});}constcastedColorScale=(colorScaleasunknown)asScaleOrdinal<StringLike,Output>;applyDomain(config,castedColorScale);returncastedColorScale;}// Handle sequential color scalesif(config.type===ScaleType.SEQUENTIAL&&config?.scheme&&isSchemeParams(config?.scheme)){constscheme=config.scheme;letcount=isContinuousScaleConfig(config)&&domain
? domain.length
: scheme.count||2;letextent=scheme.extent
? scheme.extent
: [0,1];constschemeObject=Encodable.resolveColorScheme({name: scheme.name,type: ScaleType.SEQUENTIAL});if(typeofschemeObject!=='undefined'&&schemeObject.type===ScaleType.SEQUENTIAL){constwrappedScheme=wrapColorScheme(schemeObject);constcolors=wrappedScheme.getColors(count,extent)asOutput[];constinterpolator=piecewise(interpolateRgb,colors);constcolorScale=(scaleSequential(interpolator)asunknown)asScaleLinear<string,string>;applyDomain(config,colorScale);returncolorScale;}}constscale=createScaleFromScaleType<Output>(config.type);returnupdateScale(scale,config);}
I probably missed a few aspects here but I am happy to give this a shot if you accept PRs.
Describe alternatives you've considered
Alternatively, we could probably extend createScaleFromScaleType() to support scaleSequential via ScaleType like VegaLite. However, I don't think encodable supports applying interpolators anywhere so it might be easier to do the above route.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
While @encodable/color exposes all D3 color maps, the main library is not using the interpolator with
scaleSequential
. InsteadscaleLinear
is used with a range of the scheme colors. However, this effectively results in a linear scale between the first two colors of the scheme only. Sequential multi-hue color scales are thus not supported.Describe the solution you'd like
My understanding is that we'd have to extend encodable's
createScale()
:I probably missed a few aspects here but I am happy to give this a shot if you accept PRs.
Describe alternatives you've considered
Alternatively, we could probably extend
createScaleFromScaleType()
to supportscaleSequential
viaScaleType
like VegaLite. However, I don't think encodable supports applying interpolators anywhere so it might be easier to do the above route.The text was updated successfully, but these errors were encountered: