Skip to content

Commit

Permalink
Pull vis color utils into Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Mar 17, 2020
1 parent ccfc1ed commit be6bdd5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions x-pack/legacy/plugins/maps/public/layers/styles/color_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import React from 'react';
import tinycolor from 'tinycolor2';
import chroma from 'chroma-js';

import { euiPaletteColorBlind } from '@elastic/eui/lib/services';

import { getLegendColors, getColor } from 'ui/vis/map/color_util';

import { ColorGradient } from './components/color_gradient';
import { COLOR_PALETTE_MAX_SIZE } from '../../../common/constants';
import { vislibColorMaps } from '../../../../../../../src/plugins/charts/public';
Expand All @@ -30,6 +26,24 @@ export const DEFAULT_LINE_COLORS = [
'#FFF',
];

function getLegendColors(colorRamp, numLegendColors = 4) {
const colors = [];
colors[0] = getColor(colorRamp, 0);
for (let i = 1; i < numLegendColors - 1; i++) {
colors[i] = getColor(colorRamp, Math.floor((colorRamp.length * i) / numLegendColors));
}
colors[numLegendColors - 1] = getColor(colorRamp, colorRamp.length - 1);
return colors;
}

function getColor(colorRamp, i) {
const color = colorRamp[i][1];
const red = Math.floor(color[0] * 255);
const green = Math.floor(color[1] * 255);
const blue = Math.floor(color[2] * 255);
return `rgb(${red},${green},${blue})`;
}

function getColorRamp(colorRampName) {
const colorRamp = vislibColorMaps[colorRampName];
if (!colorRamp) {
Expand Down

0 comments on commit be6bdd5

Please sign in to comment.