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

Fix(adjustHue): account for potential negative hue value #438

Merged
merged 4 commits into from May 18, 2019

Conversation

davidde
Copy link
Contributor

@davidde davidde commented May 12, 2019

closes #437

Due to the Javascript modulo bug
(https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers),
any negative value for hue results in a bug where the resulting color will be black. Negative hues
should cycle through to 359, so that functions like `adjustHue()` can provide consistent behavior
for all colors.

fix styled-components#437
Since the % operation is already performed inside `hslToRgb()` in `src/internalHelpers/_hslToRgb.js`
(which `adjustHue()` eventually calls through `toColorString()`), this % is completely redundant.

refactor styled-components#437
@davidde davidde requested a review from bhough as a code owner May 12, 2019 21:03
@codecov
Copy link

codecov bot commented May 12, 2019

Codecov Report

Merging #438 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #438   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          80     80           
  Lines         560    560           
  Branches      166    166           
=====================================
  Hits          560    560
Impacted Files Coverage Δ
src/color/adjustHue.js 100% <ø> (ø) ⬆️
src/internalHelpers/_hslToRgb.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update faac33f...4852d6f. Read the comment docs.

Copy link
Contributor

@bhough bhough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidDeprost The only other thing we are missing here is some tests to cover what this change should produce when it would otherwise produce a negative hue.

@@ -22,9 +22,9 @@ function hslToRgb(
}

// formular from https://en.wikipedia.org/wiki/HSL_and_HSV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here we should fix as part of this.

@@ -22,9 +22,9 @@ function hslToRgb(
}

// formular from https://en.wikipedia.org/wiki/HSL_and_HSV
const huePrime = hue % 360 / 60
const huePrime = (((hue % 360) + 360) % 360) / 60 // Corrected for potential negative hue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of an inline comment, might be worth putting a note in the docs on how we handle the potential negative hue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the typo and removed the comment. I'll try looking into the docs later, when I have a bit more time.

Test hslToRgb's ability to handle negative hues passed in through adjustHue.

tests styled-components#437
@davidde
Copy link
Contributor Author

davidde commented May 18, 2019

Just added a test to hslToRgb. I'm not familiar with jest, so I wasn't entirely sure if adjustHue requires more tests. I noticed adjustHue doesn't have a single "negative" test defined. It should be pretty straightforward to copy the existing tests but with a negative argument.
Let me know if you feel this would be useful.

@bhough bhough merged commit 446b73a into styled-components:master May 18, 2019
@bhough
Copy link
Contributor

bhough commented May 18, 2019

🎉 This PR is included in version 3.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

adjustHue bug
2 participants