Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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.1",
"@elastic/test-subj-selector": "0.2.1",
Expand Down
4 changes: 4 additions & 0 deletions src/core_plugins/metric_vis/public/metric_vis.less
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
margin: auto;
padding: 16px;
}

.metric-container--light {
color: white;
}
}
19 changes: 17 additions & 2 deletions src/core_plugins/metric_vis/public/metric_vis_controller.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we really need this? How does it arise that we don't know bgColor if of rgb() format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The colors are currently calculated by the getHeatmapColors function, which will always return a color in "rgb(...)" format to us.

This part will hopefully be cleaner once we build a proper palette color picker later on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay I guess I misread. We DO know that the color is in rgb() format. That's why we parse it here, into it's red, green and blue component, so we can pass three numeric values to the isDarkColor method.

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;
Expand Down Expand Up @@ -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),
});
});
});
Expand All @@ -116,10 +127,14 @@ export class MetricVisComponent extends Component {
color: metric.color
};

const containerClassName = classNames('metric-container', {
'metric-container--light': metric.lightText
});

return (
<div
key={index}
className="metric-container"
className={containerClassName}
style={{ backgroundColor: metric.bgColor }}
>
<div
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
version "0.0.0"
uid ""

"@elastic/eui@0.0.13":
version "0.0.13"
resolved "https://registry.yarnpkg.com/@elastic/eui/-/eui-0.0.13.tgz#aa3a71c6bfc41978366c29a4254b3a8d1953108f"
"@elastic/eui@0.0.14":
version "0.0.14"
resolved "https://registry.yarnpkg.com/@elastic/eui/-/eui-0.0.14.tgz#18842465e11ee96d1b90813e7fd38bef2c65bc8b"
dependencies:
brace "^0.10.0"
classnames "^2.2.5"
Expand Down