mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-12 19:26:49 +01:00
Move color helpers to helpers.color (#7130)
Move color helpers to helpers.color
This commit is contained in:
24
src/helpers/helpers.color.js
Normal file
24
src/helpers/helpers.color.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import colorLib from '@kurkle/color';
|
||||
|
||||
/**
|
||||
* @param {string | CanvasGradient | CanvasPattern} value
|
||||
*/
|
||||
const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
|
||||
|
||||
/**
|
||||
* @param {string|CanvasGradient|CanvasPattern} value
|
||||
* @return {CanvasGradient|CanvasPattern|colorLib}
|
||||
*/
|
||||
export function color(value) {
|
||||
return isPatternOrGradient(value) ? value : colorLib(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|CanvasGradient|CanvasPattern} value
|
||||
* @return {string|CanvasGradient|CanvasPattern}
|
||||
*/
|
||||
export function getHoverColor(value) {
|
||||
return isPatternOrGradient(value)
|
||||
? value
|
||||
: colorLib(value).saturate(0.5).darken(0.1).hexString();
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
/* eslint-disable import/no-namespace */
|
||||
|
||||
import color from '@kurkle/color';
|
||||
|
||||
import * as coreHelpers from './helpers.core';
|
||||
import * as canvas from './helpers.canvas';
|
||||
import * as curve from './helpers.curve';
|
||||
@@ -11,16 +9,7 @@ import * as options from './helpers.options';
|
||||
import * as math from './helpers.math';
|
||||
import * as rtl from './helpers.rtl';
|
||||
|
||||
const colorHelper =
|
||||
function(value) {
|
||||
if (value instanceof CanvasGradient || value instanceof CanvasPattern) {
|
||||
// TODO: figure out what this should be. Previously returned
|
||||
// the default color
|
||||
return value;
|
||||
}
|
||||
|
||||
return color(value);
|
||||
};
|
||||
import {color, getHoverColor} from './helpers.color';
|
||||
|
||||
export default {
|
||||
...coreHelpers,
|
||||
@@ -45,10 +34,6 @@ export default {
|
||||
fontString(pixelSize, fontStyle, fontFamily) {
|
||||
return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
|
||||
},
|
||||
color: colorHelper,
|
||||
getHoverColor(colorValue) {
|
||||
return (colorValue instanceof CanvasPattern || colorValue instanceof CanvasGradient) ?
|
||||
colorValue :
|
||||
colorHelper(colorValue).saturate(0.5).darken(0.1).hexString();
|
||||
}
|
||||
color,
|
||||
getHoverColor
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user