Set of improvements and refinements to visualizations after React migration (#4382)

This commit is contained in:
Levko Kravets
2019-12-04 16:23:29 +02:00
committed by GitHub
parent 041d05d18b
commit 94bd03dc42
109 changed files with 2007 additions and 2190 deletions

View File

@@ -1,42 +1,12 @@
import { isNil, isString, extend, each, includes, map, sortBy } from 'lodash';
import { cleanNumber, normalizeValue, getSeriesAxis } from './utils';
import { isNil, extend, each, includes, map, sortBy } from 'lodash';
import chooseTextColorForBackground from '@/lib/chooseTextColorForBackground';
import { ColorPaletteArray } from '@/visualizations/ColorPalette';
import { cleanNumber, normalizeValue, getSeriesAxis } from './utils';
function getSeriesColor(seriesOptions, seriesIndex) {
return seriesOptions.color || ColorPaletteArray[seriesIndex % ColorPaletteArray.length];
}
function getFontColor(backgroundColor) {
let result = '#333333';
if (isString(backgroundColor)) {
let matches = /#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(backgroundColor);
let r;
let g;
let b;
if (matches) {
r = parseInt(matches[1], 16);
g = parseInt(matches[2], 16);
b = parseInt(matches[3], 16);
} else {
matches = /#?([0-9a-f])([0-9a-f])([0-9a-f])/i.exec(backgroundColor);
if (matches) {
r = parseInt(matches[1] + matches[1], 16);
g = parseInt(matches[2] + matches[2], 16);
b = parseInt(matches[3] + matches[3], 16);
} else {
return result;
}
}
const lightness = r * 0.299 + g * 0.587 + b * 0.114;
if (lightness < 170) {
result = '#ffffff';
}
}
return result;
}
function getHoverInfoPattern(options) {
const hasX = /{{\s*@@x\s*}}/.test(options.textFormat);
const hasName = /{{\s*@@name\s*}}/.test(options.textFormat);
@@ -152,7 +122,7 @@ function prepareSeries(series, options, additionalOptions) {
name: seriesOptions.name || series.name,
marker: { color: seriesColor },
insidetextfont: {
color: getFontColor(seriesColor),
color: chooseTextColorForBackground(seriesColor),
},
yaxis: seriesYAxis,
sourceData,