Closed rben01 closed 2 years ago
Nice catch!
I believe formatHex()
is supposed to be a widely-compatible string representation of the color. 8-char hex notation does not benefit from the same support (e.g. Edge only gained it after switching to Chromium), so maybe a formatHex8()
is more suitable?
Agree with @danburzo that we should add formatHex8 and not change formatHex which is documented as "in RGB space".
shameless bump
Another usecase for formatHex()
to maintain its current implementation is that the HTML <input type='color'>
only accepts 6-digit hex as a color format.
Another usecase for
formatHex()
to maintain its current implementation is that the HTML<input type='color'>
only accepts 6-digit hex as a color format.
That’s fine, but an API that can do alpha would be useful, formatHex8
or something. I’m not too bothered if it can’t be this API as long as it’s supported somewhere.
maybe this issue should be changed to a feature request for that instead?
Edit: The answers are "yes" and "round". https://github.com/d3/d3-color/blob/7d61bbe6e426a7f3d3f4520a8b31cfc92dc69ee7/src/color.js#L279-L282
To reproduce:
I'd expect that
formatHex
would preserve opacity just asformatRgb
does; however, opacity is clearly ignored in the function definition https://github.com/d3/d3-color/blob/e87dc62c4bd4641534e81d8b0a42e472ab88156d/src/color.js#L266