GithubHelp home page GithubHelp logo

Add formatHex8() to include opacity about d3-color HOT 7 CLOSED

d3 avatar d3 commented on April 19, 2024 4
Add formatHex8() to include opacity

from d3-color.

Comments (7)

mootari avatar mootari commented on April 19, 2024 3
  • What happens if opacity is outside [0..1]? Should the hex value be clamped to [0..255]?
  • How should the float value be coerced? Via round() or floor()?

Edit: The answers are "yes" and "round".

d3-color/src/color.js

Lines 279 to 282 in 7d61bbe

function hex(value) {
value = Math.max(0, Math.min(255, Math.round(value) || 0));
return (value < 16 ? "0" : "") + value.toString(16);
}

from d3-color.

danburzo avatar danburzo commented on April 19, 2024 1

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?

from d3-color.

curran avatar curran commented on April 19, 2024

Nice catch!

from d3-color.

Fil avatar Fil commented on April 19, 2024

Agree with @danburzo that we should add formatHex8 and not change formatHex which is documented as "in RGB space".

from d3-color.

jasonwilliams avatar jasonwilliams commented on April 19, 2024

shameless bump

from d3-color.

danburzo avatar danburzo commented on April 19, 2024

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.

from d3-color.

jasonwilliams avatar jasonwilliams commented on April 19, 2024

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?

from d3-color.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.