vasturiano / react-globe.gl

React component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/react-globe.gl/example/world-population/
MIT License
904 stars 156 forks source link

colorInterpolator with params #117

Open PaulieScanlon opened 1 year ago

PaulieScanlon commented 1 year ago

I'd like to use ringColor={() => colorInterpolator} with multiple colors.

I have multiple ringData points and whilst i can show a ring for each with the correct color.

E.g

{
    lat: latitude,
    lng: longitude,
    color:  '255,51,51' 
},
{
    lat: latitude,
    lng: longitude,
    color: '51,153,255,
}

i can't apply the colorInterpolator since it only passes t:number which is used by the Interpolation function. I'd like the rings to fade out as they do when the colorInterpolator is used, but without the hardcoded rgba value as part of the function

Describe the solution you'd like

Could the colorInterpolator function accept a color parameter from the ringData object perhaps?

ringColor={(c, t) => colorInterpolator(c.color, t)}
//
const colorInterpolator = (c,t) => `rgba(c,${Math.sqrt(1-t)})`;
vasturiano commented 1 year ago

@PaulieScanlon thanks for reaching out.

I'm not sure I understand fully what you're intending, but would something along these lines not work?

ringColor(ring => t => `rgba(${ring.color}, ${Math.sqrt(1-t)})`)

(assuming each of your ring objects has a color string attribute like you've shown above)

PaulieScanlon commented 1 year ago

Hey! Thanks so much for the reply. Yes, I think this will do the trick. I'll have a play and see what's what!

Thank you again!!