-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat: add 4.5 contrast for text in partition slices #608
Conversation
Codecov Report
@@ Coverage Diff @@
## master #608 +/- ##
=======================================
Coverage 72.77% 72.77%
=======================================
Files 266 266
Lines 8716 8716
Branches 1645 1645
=======================================
Hits 6343 6343
Misses 2330 2330
Partials 43 43 Continue to review full report at Codecov.
|
@cchaos when you have the time, I'd love to hear your thoughts and make sure I'm interpreting this correctly: Currently, this PR will take into account contrast (which I believe is closely tied to luminosity) but in the Is there a different term (like transparency?) that I should be considering in calculating the text color with a certain background color? Thanks for you help in advance! |
@rshen91 Yes you are correct. That white text on the transparent sections does not have high contrast which means that your calculations don't take transparency into account. Though the only way it'd be able to do so is if you also knew the background color of the container. Opacity is a killer for trying to calculate contrast ratios. In EUI, we don't use transparency but "tint" instead which is when a color is blended with white. Or "shade" for blending with black. But as user and consumer created object, you'll never truly know the background color unless you ask for it. Also, it still doesn't look like the calculations are correct as even the inner-most slice, which I'd assume is not already transparent, fails at only 3.06 |
This PR will be relevant for PR #629 where the background color can be used for the tooltip color icon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggested change but otherwise looks great 🎉
Nice work, this makes the pie charts look that much better!
- handle transparent string as color - use optional chaining for accessing theme.background.color - verify in IE11
src/components/chart_background.tsx
Outdated
@@ -34,18 +33,19 @@ export class ChartBackgroundComponent extends React.Component<ChartBackgroundPro | |||
} | |||
|
|||
render() { | |||
return <div className="echChartBackground" style={{ background: this.props?.backgroundStyles?.color }} />; | |||
const { background } = this.props; | |||
return <div className="echChartBackground" style={{ background }} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could allow non-colors to be passed to the background
. Is this a good idea?
body {
background: lightblue url("img_tree.gif") no-repeat fixed center;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed here 9c91e74
src/components/chart_background.tsx
Outdated
} | ||
} | ||
|
||
const mapStateToProps = (state: GlobalChartState): ChartBackgroundProps => { | ||
if (!getInternalIsInitializedSelector(state)) { | ||
return { | ||
backgroundStyles: getChartThemeSelector(state).background, | ||
background: 'transparent', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
# [19.5.0](v19.4.1...v19.5.0) (2020-06-15) ### Bug Fixes * **tooltip:** show true opaque colors in tooltips ([#629](#629)) ([23290be](23290be)), closes [#628](#628) * path of stacked area series with missing values ([#703](#703)) ([2541180](2541180)) * remove double rendering ([#693](#693)) ([ebf2748](ebf2748)), closes [#690](#690) ### Features * **partition:** add 4.5 contrast for text in partition slices ([#608](#608)) ([eded2ac](eded2ac)), closes [#606](#606) * add screenshot functions to partition/goal ([#697](#697)) ([5581c3c](5581c3c))
🎉 This PR is included in version 19.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [19.5.0](elastic/elastic-charts@v19.4.1...v19.5.0) (2020-06-15) ### Bug Fixes * **tooltip:** show true opaque colors in tooltips ([opensearch-project#629](elastic/elastic-charts#629)) ([323b325](elastic/elastic-charts@323b325)), closes [opensearch-project#628](elastic/elastic-charts#628) * path of stacked area series with missing values ([opensearch-project#703](elastic/elastic-charts#703)) ([93f063f](elastic/elastic-charts@93f063f)) * remove double rendering ([#693](elastic/elastic-charts#693)) ([1a9bbb9](elastic/elastic-charts@1a9bbb9)), closes [#690](elastic/elastic-charts#690) ### Features * **partition:** add 4.5 contrast for text in partition slices ([opensearch-project#608](elastic/elastic-charts#608)) ([59d6d49](elastic/elastic-charts@59d6d49)), closes [opensearch-project#606](elastic/elastic-charts#606) * add screenshot functions to partition/goal ([opensearch-project#697](elastic/elastic-charts#697)) ([6d2ff64](elastic/elastic-charts@6d2ff64))
Summary
Closes #606
Iterated off some logic from elastic/kibana#60261 into the elastic-charts repo to calculate light or dark text for the partition and tree map charts.
textInvertible
is set true, then the contrast of the text on the slices and the container background color is taken into account.New stories added:
Stylings - Partition Background
: which has a pie chart with varying opacity values. Knobs are included to settextInvertible
andtextContrast
to true or false. Additionally you can specify a number fortextContrast
to try and achieve.Stylings - Partition Labels
: showing the link labels adjusting in color to different background colors. There is a knob provided for the background to be set to show textColor changing in the labels and the text within the pie slices.Main files with changes for reviewers:
Checklist
Delete any items that are not applicable to this PR.