Skip to content

Conversation

@MLDimitry
Copy link
Contributor

@MLDimitry MLDimitry commented Nov 16, 2020

WHY are these changes introduced?

Fixes https://github.com/Shopify/shopify/issues/265949

I originally solved part of this problem by increasing the precision of brightness to 4 decimal places in #3621

What I realized testing my solution in production was I had missed the fact that other colour values would also lose precision in their hue, saturation, lightness, and alpha. This PR increases the precision of the other fields and also adds a function for more accurate rounding to decimals.

Before - Note color gets replaced after pasting
Color-Before

After - Note color doesn't get replaced
Color-After

WHAT is this pull request doing?

This PR improves the fix for color-transformers by also increasing precision of other HSBLA values.

@MLDimitry MLDimitry added the Bug Something is broken and not working as intended in the system. label Nov 16, 2020
@MLDimitry MLDimitry self-assigned this Nov 16, 2020
@MLDimitry MLDimitry changed the title [color-transformers > rgbToHsbl] Increase precision of hue, saturation, lightness, and alpha [color-transformers > Hsbl] Increase precision of hue, saturation, lightness, and alpha Nov 16, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 16, 2020

🟡 This pull request modifies 6 files and might impact 69 other files. This is an average splash zone for a change, remember to tophat areas that could be affected.

Details:
All files potentially affected (total: 69)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

🧩 src/components/ThemeProvider/tests/ThemeProvider.test.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/utilities/color-transformers.ts (total: 68)

Files potentially affected (total: 68)

🧩 src/utilities/roundNumberToDecimalPlaces.ts (total: 69)

Files potentially affected (total: 69)

🧩 src/utilities/tests/color-transformers.test.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/utilities/tests/roundNumberToDecimals.test.ts (total: 0)

Files potentially affected (total: 0)

export function roundNumberToDecimalPlaces(value: number, decimals: number) {
// @ts-ignore - string concatenation represents exponential number notation
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
Copy link
Contributor Author

@MLDimitry MLDimitry Nov 16, 2020

Choose a reason for hiding this comment

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

On my continued exploration of floating point fun, I found that toFixed(2) (which uses Math.round for it's rounding) does not accurately round all floating point numbers. i.e. 1.005 in floating point is really 1.004999995, or a value very close but below 1.005 which causes it to be rounded to 1.00 instead of 1.01. (I have a test for this case)

Here's an interesting blog post on rounding which led me to this solution which converts the numbers to exponential notation for more accurate rounding.

@MLDimitry MLDimitry force-pushed the color-transformer-moar-precision branch from 6a297f7 to 0a2a175 Compare November 17, 2020 13:58
@MLDimitry
Copy link
Contributor Author

The 2 Percy snapshot failures look like an improvement, since video thumbnails now load, when previously they didn't? Could someone more familiar take a look?

@MLDimitry
Copy link
Contributor Author

MLDimitry commented Nov 17, 2020

Noticing this still is losing precision for #A76850 so investigating that. False alarm, was in the online-store-web project but was testing a depdendency built into web

@kyledurand kyledurand requested review from BPScott and kaelig and removed request for alex-page November 17, 2020 14:42
@kyledurand kyledurand requested review from AndrewMusgrave and danrosenthal and removed request for danrosenthal November 17, 2020 14:53
@MLDimitry
Copy link
Contributor Author

I was pushing updates to get failing tests/linting/TypeScript issues fixed and they look like they all are now.

This is ready for review, and if someone could also take a look at the two failing Percy screenshots (I think they can be approved but hoping for 2nd more contextful opinion), that'd be great.

@MLDimitry
Copy link
Contributor Author

Bumping this for a review, hopefully y'all have some time around the Alpha Polaris launch. Thanks!

cc @kyledurand @BPScott @kaelig @AndrewMusgrave

Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

Thanks for the articles! Makes sense to me, nice job 💯 You'll want someone from the new design language to take a look as well though

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Great sleuthing!

Two little requests for comment adjusting, then we're good to go.

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>
@MLDimitry
Copy link
Contributor Author

Thanks for the comments, reviews, and suggestions. I've applied them and resolved new conflicts. This is ready for another review when folks can.

@MLDimitry MLDimitry requested a review from BPScott November 26, 2020 20:58
Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Thanks! :shipit:

@MLDimitry MLDimitry merged commit 3e304b3 into master Nov 27, 2020
@MLDimitry MLDimitry deleted the color-transformer-moar-precision branch November 27, 2020 19:34
MLDimitry added a commit that referenced this pull request Dec 1, 2020
…ghtness, and alpha (#3640)

* update float precision of hue, saturation, lightness, and alpha

* add UNRELEASED.md entry

* add roundNumberToDecimalPlaces for accurate rounding

* improved hsbla rounding in color-transformers

* push eslint ignore

* make rounding function more readable/fix eslint + ts

* remove trivially inferred type annotations

* more rounding of values before being stringified

* update failing tests

* Update UNRELEASED.md

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>

* Update comment in src/utilities/roundNumberToDecimalPlaces.ts

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>
sylvhama pushed a commit that referenced this pull request Mar 26, 2021
…ghtness, and alpha (#3640)

* update float precision of hue, saturation, lightness, and alpha

* add UNRELEASED.md entry

* add roundNumberToDecimalPlaces for accurate rounding

* improved hsbla rounding in color-transformers

* push eslint ignore

* make rounding function more readable/fix eslint + ts

* remove trivially inferred type annotations

* more rounding of values before being stringified

* update failing tests

* Update UNRELEASED.md

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>

* Update comment in src/utilities/roundNumberToDecimalPlaces.ts

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>

Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is broken and not working as intended in the system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants