Closed antoinetissier closed 5 years ago
This is the expected behavior of d3.interpolateString, which finds numbers embedded in strings. You’ll need a different interpolator if you want to apply a different strategy for parsing strings. For example:
circle.transition().attrTween("style", () => {
const i = d3.interpolate(
{fill: "#00aeef", opacity: 0.5},
{fill: "#61c1e6", opacity: 0.5}
);
return t => {
const styles = Object.entries(i(t));
return styles.map(([name, value]) => `${name}: ${value};`).join("");
};
});
Hi,
Consider the following snippet:
Instead of having circles of the blue color defined by HEX string
#61c1e6
, I get black circles. I look at the HTML of a circle, and in the style I see that there is an unrecognized entry 'fill:#61c1000000' which is obviously not recognized.It took me some time to figure out that actually substring
1e6
in#61c1e6
is interpreted as a number in scientific notation. This occurs because of the interpolator created during the call to.transition()
:In my use case I need to use
.attr('style', ...)
as the css is passed programatically (I do not know the style attributes beforehand). This transition issue makes it impossible to use. Is there any way I can work around this issue ?Many thanks, Antoine