-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide some color and spectrum creating functions #293
Labels
Comments
So this was my attempt at using Chroma.js It does seem to work a little better in terms of finding the right interpolation. Though I think it can be expanded on/cleaned up. I'm going to leave it just on the docs side EUI for now. import chroma from 'chroma-js';
export function createSpectrum(
colors,
steps = 5,
diverging = false,
correctLightness = true,
bezier = true
) {
if (colors.length < 2) {
console.warn(
'createSpectrum expects the colors array to have at least 2 colors'
);
return;
}
diverging = diverging || colors.length > 2;
const even = steps % 2 === 0;
const numStepsLeft = diverging
? Math.ceil(steps / 2) + (even ? 1 : 0)
: steps;
const numStepsRight = diverging ? Math.ceil(steps / 2) + (even ? 1 : 0) : 0;
const numColorsHalf =
Math.ceil(colors.length / 2) + (colors.length % 2 === 0 ? 1 : 0);
const colorsLeft = colors.filter(function(item, index) {
if (index < numColorsHalf) {
return true; // keep it
}
});
const colorsRight = colors
.reverse()
.filter(function(item, index) {
if (index < numColorsHalf) {
return true; // keep it
}
})
.reverse();
function createSteps(colors, steps) {
return colors.length
? chroma
.scale(bezier && colors.length > 1 ? chroma.bezier(colors) : colors)
.correctLightness(correctLightness)
.colors(steps)
: [];
}
const stepsLeft = createSteps(colorsLeft, numStepsLeft);
const stepsRight = createSteps(colorsRight, numStepsRight);
const spectrum = (even && diverging
? stepsLeft.slice(0, stepsLeft.length - 1)
: stepsLeft
).concat(stepsRight.slice(1));
return spectrum;
} |
6 tasks
Open
Closing as this is not a priority right now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Is your feature request related to a problem? Please describe.
Right now, when you provide an array of colors, the chart simply iterates consecutively through the array, stopping when it's reached the last series. This works great for categorical style charts, but not for quantitative or tend-like charts.
Describe the solution you'd like
Provide some color functions that allow consumers to pass 1+ colors, and the number of stops, then returns an array of colors interpolated based on those parameters.
Something like:
You might even want to consider using Chroma.js as is used by the tool in the screenshots above.
Describe alternatives you've considered
Providing this in EUI instead. But it makes more sense for this library to provide it.
This was my hacky way of creating these functions:
Additional context

Checklist
[ ] every related Kibana issue is listed underKibana Cross Issues
list[ ]kibana cross issue
tag is associated to the issue if any kibana cross issue is presentThe text was updated successfully, but these errors were encountered: