@d3plus/color 3.0.15 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -42
- package/es/src/add.js +10 -14
- package/es/src/assign.js +14 -14
- package/es/src/contrast.js +7 -9
- package/es/src/defaults.js +22 -11
- package/es/src/legible.js +7 -9
- package/es/src/lighter.js +8 -10
- package/es/src/subtract.js +10 -12
- package/package.json +18 -10
- package/types/index.d.ts +8 -0
- package/types/src/add.d.ts +8 -0
- package/types/src/assign.d.ts +7 -0
- package/types/src/contrast.d.ts +7 -0
- package/types/src/defaults.d.ts +33 -0
- package/types/src/legible.d.ts +5 -0
- package/types/src/lighter.d.ts +6 -0
- package/types/src/subtract.d.ts +8 -0
- package/umd/d3plus-color.full.js +76 -181
- package/umd/d3plus-color.full.js.map +1 -1
- package/umd/d3plus-color.full.min.js +56 -58
- package/umd/d3plus-color.js +76 -181
- package/umd/d3plus-color.js.map +1 -1
- package/umd/d3plus-color.min.js +54 -56
package/umd/d3plus-color.min.js
CHANGED
|
@@ -1,74 +1,72 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/color v3.0.
|
|
2
|
+
@d3plus/color v3.0.16
|
|
3
3
|
Color functions that extent the ability of d3-color.
|
|
4
4
|
Copyright (c) 2026 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
!function(o,l){"object"==typeof exports&&"undefined"!=typeof module?l(exports,require("d3-color"),require("d3-scale"),require("open-color/open-color.js")):"function"==typeof define&&define.amd?define("@d3plus/color",["exports","d3-color","d3-scale","open-color/open-color.js"],l):l((o="undefined"!=typeof globalThis?globalThis:o||self).d3plus={},o.d3Color,o.d3Scale,o.pkg)}(this,function(o,l,r,s){"use strict";
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
@
|
|
11
|
-
|
|
9
|
+
Adds two colors together.
|
|
10
|
+
@param c1 The first color, a valid CSS color string.
|
|
11
|
+
@param c2 The second color, also a valid CSS color string.
|
|
12
|
+
@param o1 Value from 0 to 1 of the first color's opacity.
|
|
13
|
+
@param o2 Value from 0 to 1 of the first color's opacity.
|
|
14
|
+
*/const{theme:e}=s,n={dark:e.colors.gray[700],light:e.colors.gray[50],missing:e.colors.gray[400],off:e.colors.red[900],on:e.colors.green[900],scale:r.scaleOrdinal().range([e.colors.indigo[900],e.colors.yellow[600],e.colors.red[900],e.colors.green[900],e.colors.orange[600],e.colors.grape[900],e.colors.cyan[600],e.colors.pink[600],e.colors.lime[600],e.colors.blue[300],e.colors.pink[300],e.colors.lime[300],e.colors.violet[300],e.colors.cyan[100],e.colors.orange[100],e.colors.green[100],e.colors.grape[100],e.colors.red[100]])};
|
|
12
15
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
* A set of default color values used when assigning colors based on data.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue
|
|
19
|
+
* ```
|
|
20
|
+
* {
|
|
21
|
+
* dark: "#495057",
|
|
22
|
+
* light: "#f8f9fa",
|
|
23
|
+
* missing: "#ced4da",
|
|
24
|
+
* off: "#c92a2a",
|
|
25
|
+
* on: "#2b8a3e",
|
|
26
|
+
* scale: d3.scaleOrdinal().range([
|
|
27
|
+
* "#364fc7", "#fab005", "#c92a2a",
|
|
28
|
+
* "#2b8a3e", "#fd7e14", "#862e9c",
|
|
29
|
+
* "#15aabf", "#e64980", "#82c91e",
|
|
30
|
+
* "#74c0fc", "#faa2c1", "#c0eb75",
|
|
31
|
+
* "#b197fc", "#c5f6fa", "#ffe8cc",
|
|
32
|
+
* "#d3f9d8", "#f3d9fa", "#ffe3e3"
|
|
33
|
+
* ])
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/o.colorAdd=function(o,r,s=1,e=1){const n=l.hsl(o),c=l.hsl(r);let t=Math.abs(c.h*e-n.h*s);t>180&&(t-=360);let i=(Math.min(n.h,c.h)+t/2)%360;const a=n.l+(c.l*e-n.l*s)/2,g=n.s+(c.s*e-n.s*s)/2;return i<0&&(i+=360),l.hsl(`hsl(${i},${100*g}%,${100*a}%)`).toString()},o.colorAssign=
|
|
17
37
|
/**
|
|
18
|
-
|
|
19
|
-
@
|
|
20
|
-
@param
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/o.colorAdd=
|
|
24
|
-
/**
|
|
25
|
-
@function colorAdd
|
|
26
|
-
@desc Adds two colors together.
|
|
27
|
-
@param {String} c1 The first color, a valid CSS color string.
|
|
28
|
-
@param {String} c2 The second color, also a valid CSS color string.
|
|
29
|
-
@param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
|
|
30
|
-
@param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
|
|
31
|
-
@returns {String}
|
|
32
|
-
*/function(o,e,r=1,n=1){o=i.hsl(o),e=i.hsl(e);let t=Math.abs(e.h*n-o.h*r),l=(180<t&&(t-=360),(Math.min(o.h,e.h)+t/2)%360);var s=o.l+(e.l*n-o.l*r)/2,e=o.s+(e.s*n-o.s*r)/2;
|
|
33
|
-
// a = o1 + (o2 - o1) / 2;
|
|
34
|
-
return l<0&&(l+=360),i.hsl(`hsl(${l},${100*e}%,${100*s}%)`).toString();
|
|
35
|
-
// return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
|
|
36
|
-
},o.colorAssign=function(o,e={}){
|
|
38
|
+
Assigns a color to a value using a predefined set of defaults.
|
|
39
|
+
@param c A valid CSS color string.
|
|
40
|
+
@param u An object containing overrides of the default colors.
|
|
41
|
+
*/
|
|
42
|
+
function(o,r={}){
|
|
37
43
|
// If the value is null or undefined, set to grey.
|
|
38
|
-
return
|
|
44
|
+
return[null,void 0].indexOf(o)>=0?r.missing||n.missing:!0===o?r.on||n.on:!1===o?r.off||n.off:
|
|
39
45
|
// If the value is not a valid color string, use the color scale.
|
|
40
|
-
|
|
46
|
+
l.color(o)?o:(r.scale||n.scale)(o)}
|
|
41
47
|
/**
|
|
42
|
-
|
|
43
|
-
@
|
|
44
|
-
@param
|
|
45
|
-
|
|
46
|
-
@returns {String}
|
|
47
|
-
*/,o.colorContrast=function(o,e={}){return t(128<=(299*(o=i.rgb(o)).r+587*o.g+114*o.b)/1e3?"dark":"light",e)}
|
|
48
|
+
A set of default color values used when assigning colors based on data.
|
|
49
|
+
@param c A valid CSS color string.
|
|
50
|
+
@param u An object containing overrides of the default colors.
|
|
51
|
+
*/,o.colorContrast=function(o,r={}){const s=l.rgb(o);return(299*s.r+587*s.g+114*s.b)/1e3>=128?r.dark||n.dark:r.light||n.light}
|
|
48
52
|
/**
|
|
49
|
-
|
|
50
|
-
@
|
|
51
|
-
|
|
52
|
-
@returns {String}
|
|
53
|
-
*/,o.colorDefaults=n,o.colorLegible=function(o){return.45<(o=i.hsl(o)).l&&(.8<o.s&&(o.s=.8),o.l=.45),o.toString()}
|
|
53
|
+
Darkens a color so that it will appear legible on a white background.
|
|
54
|
+
@param c A valid CSS color string.
|
|
55
|
+
*/,o.colorDefaults=n,o.colorLegible=function(o){const r=l.hsl(o);return r.l>.45&&(r.s>.8&&(r.s=.8),r.l=.45),r.toString()}
|
|
54
56
|
/**
|
|
55
|
-
|
|
56
|
-
@
|
|
57
|
-
@param
|
|
58
|
-
|
|
59
|
-
@returns {String}
|
|
60
|
-
*/,o.colorLighter=function(o,e=.5){return e*=1-(o=i.hsl(o)).l,o.l+=e,o.s-=e,o.toString()}
|
|
57
|
+
Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
|
|
58
|
+
@param c A valid CSS color string.
|
|
59
|
+
@param i Strength of the lightening effect, from 0 to 1.
|
|
60
|
+
*/,o.colorLighter=function(o,r=.5){const s=l.hsl(o);return r*=1-s.l,s.l+=r,s.s-=r,s.toString()}
|
|
61
61
|
/**
|
|
62
|
-
|
|
63
|
-
@
|
|
64
|
-
@param
|
|
65
|
-
@param
|
|
66
|
-
@param
|
|
67
|
-
|
|
68
|
-
@returns {String}
|
|
69
|
-
*/,o.colorSubtract=function(o,e,r=1,n=1){o=i.hsl(o);let t=(e=i.hsl(e)).h*n-o.h*r,l=(180<Math.abs(t)&&(t-=360),(o.h-t)%360);var s=o.l-(e.l*n-o.l*r)/2,e=o.s-(e.s*n-o.s*r)/2;
|
|
62
|
+
Subtracts one color from another.
|
|
63
|
+
@param c1 The base color, a valid CSS color string.
|
|
64
|
+
@param c2 The color to remove from the base color, also a valid CSS color string.
|
|
65
|
+
@param o1 Value from 0 to 1 of the first color's opacity.
|
|
66
|
+
@param o2 Value from 0 to 1 of the first color's opacity.
|
|
67
|
+
*/,o.colorSubtract=function(o,r,s=1,e=1){const n=l.hsl(o),c=l.hsl(r);let t=c.h*e-n.h*s;Math.abs(t)>180&&(t-=360);let i=(n.h-t)%360;const a=n.l-(c.l*e-n.l*s)/2,g=n.s-(c.s*e-n.s*s)/2;
|
|
70
68
|
// a = o1 - (o2 - o1) / 2;
|
|
71
|
-
return
|
|
69
|
+
return i<0&&(i+=360),l.hsl(`hsl(${i},${100*g}%,${100*a}%)`).toString();
|
|
72
70
|
// return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
|
|
73
71
|
}});
|
|
74
72
|
//# sourceMappingURL=d3plus-color.js.map
|