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

[TSVB] fix text color when using custom background color #60261

Merged
merged 9 commits into from
Mar 17, 2020

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Mar 16, 2020

Summary

This PR fix the foreground color of the TSVB timeseries chart when the user specify custom background color from the UI.
In particular we are applying the following steps:

  • if no background color is configured, then apply as usual the chart LIGHT_THEME or DARK_THEME themes
  • if a background color is configured, then:
    1. find the best theme between dark and light that initially satisfy the background luminosity
    2. align axis title, labels, ticks and lines to the same color computed, starting from the original colors, to have the best contrast with the current background.
    3. apply that theme
    4. apply an additional css class that is required to change the legend and no data text colors

Screenshot 2020-03-16 at 12 06 33

Screenshot 2020-03-16 at 12 06 40

Screenshot 2020-03-16 at 12 06 52

Screenshot 2020-03-16 at 12 07 05

Screenshot 2020-03-16 at 12 12 29

Screenshot 2020-03-16 at 12 12 49

Screenshot 2020-03-16 at 12 55 13

fix #60011

Checklist

Delete any items that are not applicable to this PR.

When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the choosed background color irrespective of the used dark/light theme
@markov00 markov00 requested a review from timroes March 16, 2020 13:46
@markov00 markov00 requested a review from a team as a code owner March 16, 2020 13:46
@markov00 markov00 added release_note:fix bug Fixes for quality problems that affect the customer experience Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.6.2 v8.0.0 labels Mar 16, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

bgColor: string,
lightFgColor: string,
darkFgColor: string,
ratio = 4.4
Copy link
Contributor

Choose a reason for hiding this comment

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

AA contrast is actually 4.5 not 4.4. And this contrast is expected to be attained for text. However, for graphics like axis lines and pure fill colors without text, only a 3.0 contrast level needs to be met.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, I think I've found cases where I cannot reach a 4.5 value with a grey scale foreground color, but maybe I'm completely wrong about that

Copy link
Member Author

Choose a reason for hiding this comment

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

update here f490b91

if (relLum <= 0.0031308) {
return relLum * 12.92;
} else {
return (1.0 + 0.055) * Math.pow(relLum, 1.0 / 2.4) - 0.055;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you are re-writing the WCAG's luminance and contrast calculator in this file. My thoughts are:

A. This would be good to be pulled into a service instead so it doesn't have to be re-written by other chart types or plugins.
B. EUI does export a calculateContrast color service
C. ChromaJS is a dependency and they have a .contrast method

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a good candidate for the “charts” plugin

Copy link
Member Author

Choose a reason for hiding this comment

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

@cchaos I'm not rewriting the luminance here, I'm inverting the luminance formula to get the lightness to use with the gray color.
This for sure will be part of elastic-charts, I'm currently applying this here because it needs to be released on a patch release and we can't upgrade the chart library in a patch release

Copy link
Member Author

@markov00 markov00 Mar 16, 2020

Choose a reason for hiding this comment

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

I can replace computeContrast with the contrast method of color
We don't have chromajs as a dependency in Kibana right now

Copy link
Member Author

Choose a reason for hiding this comment

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

updated here: 07f437a

Copy link
Contributor

Choose a reason for hiding this comment

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

++ for moving this to elastic-charts later on

Comment on lines +10 to +25
.tvbVisTimeSeriesDark {
.echReactiveChart_unavailable {
color: #DFE5EF;
}
.echLegendItem {
color: #DFE5EF;
}
}
.tvbVisTimeSeriesLight {
.echReactiveChart_unavailable {
color: #343741;
}
.echLegendItem {
color: #343741;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I could see this becoming an ever-growing list of overrides and we highly suggest not applying straight hex values when they come from the EUI palette/theme. We need to figure out a more extensible approach like possibly adding these to the Chart theme.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be moved to elastic-charts for sure

@timroes timroes added the v7.7.0 label Mar 16, 2020
Copy link
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

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

Tested on Chrome Linux, seems to work with different combinations of darkmode on/off and background colors. One minor nitpick about test names, otherwise this looks good to me.

import { getTheme } from './theme';
import { LIGHT_THEME, DARK_THEME } from '@elastic/charts';

describe('src/legacy/core_plugins/vis_type_timeseries/public/visualizations/views/timeseries/utils/theme.ts', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a proper test name here like "TSVB theme" (even if the rest of TSVB does that weirdly).

Copy link
Member Author

Choose a reason for hiding this comment

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

updated here 3bd5f54

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@markov00 markov00 merged commit e25430b into elastic:master Mar 17, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* master: (30 commits)
  [TSVB] fix text color when using custom background color (elastic#60261)
  Fix import to timefilter from in TSVB (elastic#60296)
  [NP] Get rid of usage redirectWhenMissing service (elastic#59777)
  [SIEM] Fix Timeline footer styling (elastic#59587)
  [ML] Fixes to error handling for analytics jobs and file data viz (elastic#60249)
  Give better stack traces for Unhandled Promise Rejection warnings (elastic#60235)
  resolves elastic#58905 (elastic#60120)
  Added variables button for text fields in Pagerduty component. (elastic#60189)
  adds test that action vars are rendered for alert action parms (elastic#60310)
  Closes 59786 by removing the update toast (elastic#60172)
  [EPM] Packages list tabs (elastic#60167)
  Added message variables button for Webhook body form field (elastic#60174)
  Revert "adds new test (elastic#60064)"
  [Maps] move MapSavedObject type out of telemetry (elastic#60127)
  [Reporting] Fix error handling for job handler in route (elastic#60161)
  [Endpoint] TEST: verify alerts page header says 'Alerts' (elastic#60206)
  EMT-248: implement ack resource to accept event payload to acknowledge agent actions (elastic#60218)
  Migrate dual validated range (elastic#59689)
  Embeddable triggers (elastic#58440)
  [Endpoint] Sample data generator CLI script (elastic#59952)
  ...
markov00 added a commit to markov00/kibana that referenced this pull request Mar 17, 2020
When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the chosen background color irrespective of the used dark/light theme
markov00 added a commit to markov00/kibana that referenced this pull request Mar 17, 2020
When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the chosen background color irrespective of the used dark/light theme
markov00 added a commit that referenced this pull request Mar 17, 2020
…0365)

When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the chosen background color irrespective of the used dark/light theme
markov00 added a commit that referenced this pull request Mar 17, 2020
…0364)

When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the chosen background color irrespective of the used dark/light theme
cnasikas pushed a commit to cnasikas/kibana that referenced this pull request Mar 17, 2020
When the user apply a background color manually from the UI,
this commit adapt the current colors to have a better contrast with
the chosen background color irrespective of the used dark/light theme
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* master: (51 commits)
  do not update cell background if is label cell (elastic#60308)
  FTR configurable test users (elastic#52431)
  [Reporting] Wholesale moves client to newest-platform (elastic#58945)
  [Ingest] Support `show_user` package registry flag (elastic#60338)
  [SIEM] Adds 'Closes one signal when more than one opened signals are selected' test again (elastic#60380)
  [SIEM][Detections Engine] - Add rule markdown field to rule create, detail, and edit flows (elastic#60108)
  [Fleet] Add config revision to fleet agents (elastic#60292)
  Allow kbn-config-schema to ignore unknown keys (elastic#59560)
  [ML] Functional tests - disable df analytics clone tests
  skip flaky suite (elastic#58643) (elastic#58991)
  [FTR] Add support for --include and --exclude files via tags (elastic#60123)
  [SIEM] Fix link on overview page (elastic#60348)
  skip flaky test (elastic#60369)
  [Endpoint] Adds take action dropdown and tests to alert details flyout (elastic#59242)
  [Lens] Simplify state management from visualization (elastic#58279)
  Changing default type to start and allowing it to be configured by the event category (elastic#60323)
  [ML] Adds the class_assignment_objective to classification (elastic#60358)
  [TSVB] fix text color when using custom background color (elastic#60261)
  Fix import to timefilter from in TSVB (elastic#60296)
  [NP] Get rid of usage redirectWhenMissing service (elastic#59777)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 17, 2020
* alerting/view-in-app: (53 commits)
  fixed typo
  handle optional alerting plugin
  do not update cell background if is label cell (elastic#60308)
  FTR configurable test users (elastic#52431)
  [Reporting] Wholesale moves client to newest-platform (elastic#58945)
  [Ingest] Support `show_user` package registry flag (elastic#60338)
  [SIEM] Adds 'Closes one signal when more than one opened signals are selected' test again (elastic#60380)
  [SIEM][Detections Engine] - Add rule markdown field to rule create, detail, and edit flows (elastic#60108)
  [Fleet] Add config revision to fleet agents (elastic#60292)
  Allow kbn-config-schema to ignore unknown keys (elastic#59560)
  [ML] Functional tests - disable df analytics clone tests
  skip flaky suite (elastic#58643) (elastic#58991)
  [FTR] Add support for --include and --exclude files via tags (elastic#60123)
  [SIEM] Fix link on overview page (elastic#60348)
  skip flaky test (elastic#60369)
  [Endpoint] Adds take action dropdown and tests to alert details flyout (elastic#59242)
  [Lens] Simplify state management from visualization (elastic#58279)
  Changing default type to start and allowing it to be configured by the event category (elastic#60323)
  [ML] Adds the class_assignment_objective to classification (elastic#60358)
  [TSVB] fix text color when using custom background color (elastic#60261)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.6.2 v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TSVB does not take into account background color for legend styling
6 participants