mirror of
https://github.com/getredash/redash.git
synced 2026-05-12 21:00:32 -04:00
Set of improvements and refinements to visualizations after React migration (#4382)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user