From: Jukka Kurkela Date: Wed, 19 Feb 2020 23:14:22 +0000 (+0200) Subject: Move color helpers to helpers.color (#7130) X-Git-Tag: v3.0.0-alpha~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a737729d5ca1718510796d1391b8a8991968efd;p=thirdparty%2FChart.js.git Move color helpers to helpers.color (#7130) Move color helpers to helpers.color --- diff --git a/src/helpers/helpers.color.js b/src/helpers/helpers.color.js new file mode 100644 index 000000000..1049dc236 --- /dev/null +++ b/src/helpers/helpers.color.js @@ -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(); +} diff --git a/src/helpers/index.js b/src/helpers/index.js index 7a18ff4bf..91b7721cf 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -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 };