Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong color when picking from left bottom #14

Closed
unmec opened this issue Apr 13, 2018 · 3 comments
Closed

Wrong color when picking from left bottom #14

unmec opened this issue Apr 13, 2018 · 3 comments
Labels

Comments

@unmec
Copy link

unmec commented Apr 13, 2018

Thanks for this component.

I found out that the area from 5 o'clock to 9 o'clock always returns something red in console.

BTW I am using tinycolor to convert the hsv to hex. But I don't think that's related in some ways.

@jsdario
Copy link
Member

jsdario commented Apr 13, 2018

I'd really appreciate if you could attach a screenshot with some log, so I can appreciate which is your exact case.

We are using https://github.com/netbeast/colorsys to convert colors back and forward.

Highly saturated colors (whites) can be translated to red in some scenarios, since they lose their color information in (white in rgb is {255,255,255} but in hsv, hue is an independent variable, so its info is kept safe).

Don't know if that's the case of tinycolor, in colorsys there it is a test implementation:

https://github.com/netbeast/colorsys/blob/master/test/test.js#L39-L47

@unmec
Copy link
Author

unmec commented Apr 13, 2018

Thanks for your quick reply @jsdario

Actually I just found the reason and fixed it like this:

When dragging in that area, for instance at 7 o'clock blue color, picker returns a value like so:

{ h: -134.48844413341297, s: 87.99901795187165, v: 100 }

The correct range for h is [0, 360], so obviously tinycolor converting to hex will return some other colors like red (I was just logging the final result at the beginning).

All I did is a small check:

selected(color) {
  if (color.h < 0) {
    color.h = Number(color.h) + 360;
  }
  // do whatever I want with color
}

That's it. Hopefully it would be helpful for anyone else who is using this component.

@jsdario
Copy link
Member

jsdario commented Apr 13, 2018

Oh I see! Since I am collaborator here and in colorsys I considered hue as any possible valid angle in degrees.

Thanks a lot for your contribution! Will close the issue with a solved tag :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants