]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Move color helpers to helpers.color (#7130)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 19 Feb 2020 23:14:22 +0000 (01:14 +0200)
committerGitHub <noreply@github.com>
Wed, 19 Feb 2020 23:14:22 +0000 (18:14 -0500)
Move color helpers to helpers.color

src/helpers/helpers.color.js [new file with mode: 0644]
src/helpers/index.js

diff --git a/src/helpers/helpers.color.js b/src/helpers/helpers.color.js
new file mode 100644 (file)
index 0000000..1049dc2
--- /dev/null
@@ -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();
+}
index 7a18ff4bf70f901aa75e747a8a063d6bad2147ce..91b7721cfb981ed43a9b63e48c8be9833c71c3f2 100644 (file)
@@ -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
 };