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

Pass threshold as a parameters #2

Closed
franciscohanna92 opened this issue Oct 26, 2021 · 9 comments · Fixed by #5
Closed

Pass threshold as a parameters #2

franciscohanna92 opened this issue Oct 26, 2021 · 9 comments · Fixed by #5

Comments

@franciscohanna92
Copy link
Contributor

franciscohanna92 commented Oct 26, 2021

Hello there!

Where is this threshold value coming from? I mean, why 130?

if (contrast > 130) {

Would you accept a PR to receive that value as an optional parameter?

@russoedu
Copy link
Owner

russoedu commented Oct 26, 2021 via email

@franciscohanna92
Copy link
Contributor Author

After some digging around the web, I think I found the original source for this algorithm.

It's important to notice that the author recommends "a more accurate" set of value to calculates the contrast (or "perceived brightness")

brightness = sqrt( .299 R2 + .587 G2 + .114 B2 )

Should I include these changes (new values for calculation and link to the original source in README.md) in the PR?

@russoedu
Copy link
Owner

russoedu commented Oct 26, 2021 via email

@russoedu
Copy link
Owner

russoedu commented Oct 28, 2021 via email

@franciscohanna92
Copy link
Contributor Author

@russoedu I think the best will be to do it from the TS branch!

@russoedu
Copy link
Owner

russoedu commented Oct 30, 2021 via email

@franciscohanna92
Copy link
Contributor Author

@russoedu Hello there! Getting back at this after some busy days.

I see as kind of difficult (or impossible) to pass yet another optional param as the threshold. For example, if I want to use the hex number overload and use a threshold value as a second parameter, calling fontColorContrast(0XF3DC56, 0.15) will result in 0.15 being interpreted as the green value, give the function definition:

function fontColorContrast (hexColorOrRedOrArray: string | number | number[], green?: number, blue?: number, threshold?: number) { ... }

A solution could be to deprecate the overload that accepts three independent number values (there's already a number[] one which serves the same purpose). This way, each overload will accept always two params, the second one being threshold.

What do you think?

@franciscohanna92
Copy link
Contributor Author

I've created the PR to better explain myself. Let me know what you think.

Regards.

@russoedu
Copy link
Owner

russoedu commented Nov 3, 2021 via email

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

Successfully merging a pull request may close this issue.

2 participants