Skip to content

Better text color selection for a given background#820

Merged
RomRider merged 1 commit intoRomRider:devfrom
kosumosu:just-fix-text-color
Aug 20, 2025
Merged

Better text color selection for a given background#820
RomRider merged 1 commit intoRomRider:devfrom
kosumosu:just-fix-text-color

Conversation

@kosumosu
Copy link
Copy Markdown
Contributor

Currently, apexcharts selects text color inadequately. It can select white text for quiet bright background.
The problem is that computeTextColor() function uses linear colorObj.getLuminance(), which is not how human percepts color.
TinyColor has isLight()/isDark() methods, which work in gamma space, and my experiments indicate it works better for this purpose.
Here is the comparison (before/after):
apex-charts-bg-color-BAACC7-is-unreadable-big
apex-charts-bg-color-BAACC7-is-unreadable-big-fixed

The color of the graph is #BAACC7 which has linear luminance of about 0.44. This is less than 0.5, thus master version of apex-charts selects white text color. However, as you can probably see, black text color is much more readable.

@vingerha
Copy link
Copy Markdown
Contributor

vingerha commented Aug 7, 2025

I am updating old request onto a copy of this repo, as this repo seems abandoned. I like the idea/layout but your suggested changes have no effect with my repo. I am using the ootb/default HA theme
https://github.com/vingerha/apexcharts-card

@RomRider RomRider changed the base branch from master to dev August 20, 2025 12:51
@RomRider RomRider merged commit f09756f into RomRider:dev Aug 20, 2025
@RomRider
Copy link
Copy Markdown
Owner

Thanks !

github-actions Bot pushed a commit that referenced this pull request Aug 20, 2025
## 2.2.0-dev.2 (2025-08-20)

* docs: Fix typos and improve grammar in README.md (#698) ([6655949](6655949)), closes [#698](#698)
* docs: Updated install instructions ([37f3fa2](37f3fa2))
* feat(series): Extend `stroke_dash` to support an array for more complex dashing patterns (#902) ([cafbcec](cafbcec)), closes [#902](#902)
* Fix: Text color selection for given background now takes into account human perception. (#820) ([f09756f](f09756f)), closes [#820](#820)
* chore(deps): Update release dependencies and some outdated packages ([07b901a](07b901a))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.2.0-dev.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

github-actions Bot pushed a commit that referenced this pull request Aug 20, 2025
## [2.2.0](v2.1.2...v2.2.0) (2025-08-20)

### Features

* Display the card version on the card (useful for debugging) ([ac800c5](ac800c5))
* **series:** Add option to hide null or zero values in the header ([#544](#544)) ([baf2066](baf2066)), closes [#543](#543)
* **series:** Extend `stroke_dash` to support an array for more complex dashing patterns ([#902](#902)) ([cafbcec](cafbcec))
* Support for sections views using `section_mode` ([fe85144](fe85144)), closes [#927](#927) [#837](#837) [#904](#904) [#736](#736)

### Bug Fixes

* graph rendering too wide when heading title is too long ([#812](#812)) ([094280d](094280d))
* Text color selection for given background now takes into account human perception. ([#820](#820)) ([f09756f](f09756f))

### Documentation

* Fix typos and improve grammar in README.md ([#698](#698)) ([6655949](6655949))
* Updated install instructions ([37f3fa2](37f3fa2))
github-actions Bot pushed a commit that referenced this pull request Aug 20, 2025
## [2.2.0](v2.1.2...v2.2.0) (2025-08-20)

### Features

* Display the card version on the card (useful for debugging) ([ac800c5](ac800c5))
* **series:** Add option to hide null or zero values in the header ([#544](#544)) ([baf2066](baf2066)), closes [#543](#543)
* **series:** Extend `stroke_dash` to support an array for more complex dashing patterns ([#902](#902)) ([cafbcec](cafbcec))
* Support for sections views using `section_mode` ([fe85144](fe85144)), closes [#927](#927) [#837](#837) [#904](#904) [#736](#736)

### Bug Fixes

* graph rendering too wide when heading title is too long ([#812](#812)) ([094280d](094280d))
* Text color selection for given background now takes into account human perception. ([#820](#820)) ([f09756f](f09756f))

### Documentation

* Fix typos and improve grammar in README.md ([#698](#698)) ([6655949](6655949))
* Updated install instructions ([37f3fa2](37f3fa2))
github-actions Bot pushed a commit that referenced this pull request Aug 20, 2025
## [2.2.0](v2.1.2...v2.2.0) (2025-08-20)

### Features

* Display the card version on the card (useful for debugging) ([ac800c5](ac800c5))
* **series:** Add option to hide null or zero values in the header ([#544](#544)) ([baf2066](baf2066)), closes [#543](#543)
* **series:** Extend `stroke_dash` to support an array for more complex dashing patterns ([#902](#902)) ([cafbcec](cafbcec))
* Support for sections views using `section_mode` ([fe85144](fe85144)), closes [#927](#927) [#837](#837) [#904](#904) [#736](#736)

### Bug Fixes

* graph rendering too wide when heading title is too long ([#812](#812)) ([094280d](094280d))
* Text color selection for given background now takes into account human perception. ([#820](#820)) ([f09756f](f09756f))

### Documentation

* Fix typos and improve grammar in README.md ([#698](#698)) ([6655949](6655949))
* Updated install instructions ([37f3fa2](37f3fa2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants