Skip to content

Commit f346455

Browse files
authored
Fix metric contrast (#16296)
* Update EUI to 0.0.14 * Make metrics text white when on dark color
1 parent 86c5597 commit f346455

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
"dependencies": {
7878
"@elastic/datemath": "4.0.2",
79-
"@elastic/eui": "0.0.13",
79+
"@elastic/eui": "0.0.14",
8080
"@elastic/filesaver": "1.1.2",
8181
"@elastic/numeral": "2.3.1",
8282
"@elastic/test-subj-selector": "0.2.1",

src/core_plugins/metric_vis/public/metric_vis.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
margin: auto;
1717
padding: 16px;
1818
}
19+
20+
.metric-container--light {
21+
color: white;
22+
}
1923
}

src/core_plugins/metric_vis/public/metric_vis_controller.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import _ from 'lodash';
22
import React, { Component } from 'react';
33
import { getHeatmapColors } from 'ui/vislib/components/color/heatmap_color';
4+
import { isColorDark } from '@elastic/eui';
5+
import classNames from 'classnames';
46

57
export class MetricVisComponent extends Component {
68

@@ -54,6 +56,14 @@ export class MetricVisComponent extends Component {
5456
return colors[label];
5557
}
5658

59+
_needsLightText(bgColor) {
60+
const color = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/.exec(bgColor);
61+
if (!color) {
62+
return false;
63+
}
64+
return isColorDark(parseInt(color[1]), parseInt(color[2]), parseInt(color[3]));
65+
}
66+
5767
_processTableGroups(tableGroups) {
5868
const config = this.props.vis.params.metric;
5969
const isPercentageMode = config.percentageMode;
@@ -101,7 +111,8 @@ export class MetricVisComponent extends Component {
101111
label: title,
102112
value: value,
103113
color: shouldColor && config.style.labelColor ? color : null,
104-
bgColor: shouldColor && config.style.bgColor ? color : null
114+
bgColor: shouldColor && config.style.bgColor ? color : null,
115+
lightText: shouldColor && config.style.bgColor && this._needsLightText(color),
105116
});
106117
});
107118
});
@@ -116,10 +127,14 @@ export class MetricVisComponent extends Component {
116127
color: metric.color
117128
};
118129

130+
const containerClassName = classNames('metric-container', {
131+
'metric-container--light': metric.lightText
132+
});
133+
119134
return (
120135
<div
121136
key={index}
122-
className="metric-container"
137+
className={containerClassName}
123138
style={{ backgroundColor: metric.bgColor }}
124139
>
125140
<div

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
version "0.0.0"
8888
uid ""
8989

90-
"@elastic/eui@0.0.13":
91-
version "0.0.13"
92-
resolved "https://registry.yarnpkg.com/@elastic/eui/-/eui-0.0.13.tgz#aa3a71c6bfc41978366c29a4254b3a8d1953108f"
90+
"@elastic/eui@0.0.14":
91+
version "0.0.14"
92+
resolved "https://registry.yarnpkg.com/@elastic/eui/-/eui-0.0.14.tgz#18842465e11ee96d1b90813e7fd38bef2c65bc8b"
9393
dependencies:
9494
brace "^0.10.0"
9595
classnames "^2.2.5"

0 commit comments

Comments
 (0)