diff --git a/package.json b/package.json index dcf75ccafc4de..e45f87c51a123 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ }, "dependencies": { "@elastic/datemath": "4.0.2", - "@elastic/eui": "0.0.13", + "@elastic/eui": "0.0.14", "@elastic/filesaver": "1.1.2", "@elastic/numeral": "2.3.0", "@elastic/test-subj-selector": "0.2.1", diff --git a/src/core_plugins/metric_vis/public/metric_vis.less b/src/core_plugins/metric_vis/public/metric_vis.less index e98e1b5d8d995..f63fb29e29b39 100644 --- a/src/core_plugins/metric_vis/public/metric_vis.less +++ b/src/core_plugins/metric_vis/public/metric_vis.less @@ -16,4 +16,8 @@ margin: auto; padding: 16px; } + + .metric-container--light { + color: white; + } } diff --git a/src/core_plugins/metric_vis/public/metric_vis_controller.js b/src/core_plugins/metric_vis/public/metric_vis_controller.js index d0aa5d4e08d85..5190690c1e91a 100644 --- a/src/core_plugins/metric_vis/public/metric_vis_controller.js +++ b/src/core_plugins/metric_vis/public/metric_vis_controller.js @@ -1,6 +1,8 @@ import _ from 'lodash'; import React, { Component } from 'react'; import { getHeatmapColors } from 'ui/vislib/components/color/heatmap_color'; +import { isColorDark } from '@elastic/eui'; +import classNames from 'classnames'; export class MetricVisComponent extends Component { @@ -54,6 +56,14 @@ export class MetricVisComponent extends Component { return colors[label]; } + _needsLightText(bgColor) { + const color = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/.exec(bgColor); + if (!color) { + return false; + } + return isColorDark(parseInt(color[1]), parseInt(color[2]), parseInt(color[3])); + } + _processTableGroups(tableGroups) { const config = this.props.vis.params.metric; const isPercentageMode = config.percentageMode; @@ -101,7 +111,8 @@ export class MetricVisComponent extends Component { label: title, value: value, color: shouldColor && config.style.labelColor ? color : null, - bgColor: shouldColor && config.style.bgColor ? color : null + bgColor: shouldColor && config.style.bgColor ? color : null, + lightText: shouldColor && config.style.bgColor && this._needsLightText(color), }); }); }); @@ -116,10 +127,14 @@ export class MetricVisComponent extends Component { color: metric.color }; + const containerClassName = classNames('metric-container', { + 'metric-container--light': metric.lightText + }); + return (