jupyter-ijavascript-utils 1.52.1 → 1.53.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/DOCS.md +1 -0
- package/Dockerfile +1 -1
- package/README.md +1 -0
- package/package.json +2 -2
- package/src/color.js +81 -5
package/DOCS.md
CHANGED
|
@@ -74,6 +74,7 @@ Give it a try here:
|
|
|
74
74
|
[](https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main?labpath=example.ipynb)
|
|
75
75
|
|
|
76
76
|
## What's New
|
|
77
|
+
* 1.53 - additional docs and examples for {@link module:color|color/colour} package.
|
|
77
78
|
* 1.52 - print a date to ISO in local time with {@link module:date.toLocalISO|date.toLocalISO}
|
|
78
79
|
* 1.51 - added in {@link module:date|date} - and addressed issue #69, #68, #67, #66
|
|
79
80
|
* 1.50 - added in {@link module:color|color/colour} - and addressed issue #65
|
package/Dockerfile
CHANGED
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ This is not intended to be the only way to accomplish many of these tasks, and a
|
|
|
54
54
|

|
|
55
55
|
|
|
56
56
|
# What's New
|
|
57
|
+
* 1.53 - additional docs and examples for color/colour package.
|
|
57
58
|
* 1.52 - print a date to ISO in local time with date.toLocalISO
|
|
58
59
|
* 1.51 - added in date - and addressed issues #69, #68, #67, #66
|
|
59
60
|
* 1.50 - added in color/colour - and addressed issue #65
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jupyter-ijavascript-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.53.0",
|
|
4
4
|
"description": "Utilities for working with iJavaScript - a Jupyter Kernel",
|
|
5
5
|
"homepage": "https://jupyter-ijavascript-utils.onrender.com/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"sinon": "^11.1.1"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@svgdotjs/svg.js": "^3.
|
|
49
|
+
"@svgdotjs/svg.js": "^3.2.4",
|
|
50
50
|
"fs-extra": "^10.0.1",
|
|
51
51
|
"generate-schema": "^2.6.0",
|
|
52
52
|
"node-fetch": "^2.6.5",
|
package/src/color.js
CHANGED
|
@@ -49,6 +49,33 @@
|
|
|
49
49
|
* a function of signature (fromColor:Number[0-255], toColor:Number[0-255], percentage:Number[0-1]):Number[0-255]
|
|
50
50
|
* * {@link module:color.INTERPOLATION_STRATEGIES|color.INTERPOLATION_STRATEGIES} - a list of strategies for interpolation you can choose from
|
|
51
51
|
*
|
|
52
|
+
* ```
|
|
53
|
+
* utils.svg.render({ width: 800, height: 100,
|
|
54
|
+
* onReady: ({el, width, height, SVG }) => {
|
|
55
|
+
* const fromColor = '#ff0000';
|
|
56
|
+
* const toColor = 'rgb(0, 255, 0)';
|
|
57
|
+
*
|
|
58
|
+
* const numBoxes = 5;
|
|
59
|
+
* const boxWidth = width / numBoxes;
|
|
60
|
+
* const boxHeight = 100;
|
|
61
|
+
*
|
|
62
|
+
* // utils.color.interpolationStrategy = utils.color.INTERPOLATION_STRATEGIES.linear;
|
|
63
|
+
* // utils.color.defaultFormat = utils.color.FORMATS.hex;
|
|
64
|
+
*
|
|
65
|
+
* const colorSequence = utils.color.generateSequence(fromColor, toColor, numBoxes);
|
|
66
|
+
* // [ '#ff0000', '#9d6200', '#4bb400', '#13ec00', '#00ff00' ]
|
|
67
|
+
*
|
|
68
|
+
* colorSequence.forEach((boxColor, boxIndex) => {
|
|
69
|
+
* el.rect(boxWidth, boxHeight)
|
|
70
|
+
* .fill(boxColor)
|
|
71
|
+
* .translate(boxIndex * boxWidth);
|
|
72
|
+
* });
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* 
|
|
78
|
+
*
|
|
52
79
|
* @module color
|
|
53
80
|
* @exports color
|
|
54
81
|
*/
|
|
@@ -68,13 +95,28 @@ module.exports.COLOR_VALIDATION = {
|
|
|
68
95
|
* Enum strings of types expected
|
|
69
96
|
*
|
|
70
97
|
* There are 6 types of formats supported:
|
|
71
|
-
* *
|
|
72
|
-
*
|
|
98
|
+
* * HEX - 6 character hexadecimal colors as RRGGBB, like red for #ff0000
|
|
99
|
+
* * alternatively - 3 character hexadecimal colors #RGB are supported: like red for #F00
|
|
100
|
+
* * HEXA - 8 character hexadecimal colors as RRGGBBAA, like red for #ff000080 with semi-transparency
|
|
101
|
+
* * alternatively - 4 character hexadecimal colors #RGBA are supported: #F008
|
|
73
102
|
* * RGB - color with format `rgb(RR,GG,BB)` - like red for `rgb(255,0,0)`
|
|
74
103
|
* * RGBA - RGB format with alpha: `rgba(RR,GG,BB,AA)` - like red for `rgba(255,0,0,0.5)` for semi-transparency
|
|
75
104
|
* * ARRAY - 3 to 4 length array, with format: `[r,g,b]` or `[r,g,b,a]` - like red for [255,0,0] or [255,0,0,0.5] for semi-transparency
|
|
76
105
|
* * OBJECT - objects with properties: r, g, b and optionally: a (the object is not modified and only those properties are checked)
|
|
77
106
|
*
|
|
107
|
+
* For example:
|
|
108
|
+
*
|
|
109
|
+
* ```
|
|
110
|
+
* baseColor = '#b1d1f3';
|
|
111
|
+
*
|
|
112
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.HEX); // '#b1d1f3'
|
|
113
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.HEXA); // #b1d1f3ff
|
|
114
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.RGB); // rgb( 177, 209, 243)
|
|
115
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.RGBA); // rgba(177, 209, 243, 1)
|
|
116
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.ARRAY); // [ 177, 209, 243, 1 ]
|
|
117
|
+
* utils.color.convert(baseColor, utils.color.FORMATS.OBJECT); // { r: 177, g: 209, b: 243, a: 1 }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
78
120
|
* @see {@link module:color.defaultFormat|color.defaultFormat}
|
|
79
121
|
*/
|
|
80
122
|
module.exports.FORMATS = {
|
|
@@ -90,6 +132,13 @@ module.exports.FORMATS = {
|
|
|
90
132
|
* Default format used when converting to types
|
|
91
133
|
* (allowing the conversion type to be optional)
|
|
92
134
|
*
|
|
135
|
+
* ```
|
|
136
|
+
* baseColor = '#b1d1f3';
|
|
137
|
+
* utils.color.defaultFormat = utils.color.FORMATS.RGBA;
|
|
138
|
+
*
|
|
139
|
+
* utils.color.convert(baseColor); // rgba(177, 209, 243, 1)
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
93
142
|
* @see {@link module:color.FORMATS|color.FORMATS}
|
|
94
143
|
*/
|
|
95
144
|
module.exports.defaultFormat = ColorUtils.FORMATS.HEX;
|
|
@@ -99,6 +148,8 @@ const PI2 = Math.PI * 0.5;
|
|
|
99
148
|
/**
|
|
100
149
|
* Different types of interpolation strategies:
|
|
101
150
|
*
|
|
151
|
+
* 
|
|
152
|
+
*
|
|
102
153
|
* * linear - linear interpolation between one value to another (straight line)
|
|
103
154
|
* * easeInOut - slows in to the change and slows out near the end
|
|
104
155
|
* * easeIn - slow then fast
|
|
@@ -114,10 +165,34 @@ module.exports.INTERPOLATION_STRATEGIES = {
|
|
|
114
165
|
};
|
|
115
166
|
|
|
116
167
|
/**
|
|
117
|
-
*
|
|
168
|
+
* Default interpolation strategy used when interpolating
|
|
169
|
+
* from one color to another.
|
|
118
170
|
*
|
|
119
171
|
* (Defaults to linear)
|
|
120
172
|
*
|
|
173
|
+
* 
|
|
174
|
+
*
|
|
175
|
+
* For example, you can specify how you would like to interpolate
|
|
176
|
+
* and even which format you'd like to receive the results in.
|
|
177
|
+
*
|
|
178
|
+
* ```
|
|
179
|
+
* //-- same as utils.color.INTERPOLATION_STRATEGIES.linear;
|
|
180
|
+
* linear = (a, b, pct) => a + (b - a) * pct;
|
|
181
|
+
* format = utils.color.FORMATS.ARRAY;
|
|
182
|
+
* utils.color.interpolate(red, green, 0, linear, format); // [255, 0, 0, 1]
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* or instead, you can set this property and set the default
|
|
186
|
+
*
|
|
187
|
+
* ```
|
|
188
|
+
* // or set the default
|
|
189
|
+
* utils.color.interpolationStrategy = linear;
|
|
190
|
+
* utils.color.defaultFormat = utils.color.FORMATS.ARRAY;
|
|
191
|
+
*
|
|
192
|
+
* //-- note that the interpolation strategy or format isn't passed
|
|
193
|
+
* utils.color.interpolate(red, green, 0.5); // [127.5, 127.5, 0, 1]
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
121
196
|
* @see {@link module:color.INTERPOLATION_STRATEGIES}
|
|
122
197
|
*/
|
|
123
198
|
module.exports.interpolationStrategy = ColorUtils.INTERPOLATION_STRATEGIES.linear;
|
|
@@ -211,7 +286,8 @@ module.exports.parseHex = function parseHex(hexStr, optionalAlpha = 1) {
|
|
|
211
286
|
*/
|
|
212
287
|
module.exports.toHex = function toHex(target) {
|
|
213
288
|
const [r, g, b] = ColorUtils.parse(target);
|
|
214
|
-
|
|
289
|
+
const hexOut = (num) => num.toString(16).padStart(2, '0');
|
|
290
|
+
return `#${hexOut(r)}${hexOut(g)}${hexOut(b)}`;
|
|
215
291
|
};
|
|
216
292
|
|
|
217
293
|
/**
|
|
@@ -511,6 +587,7 @@ module.exports.parse = function parse(target, optionalAlpha = 1) {
|
|
|
511
587
|
* ```
|
|
512
588
|
*
|
|
513
589
|
* @param {string|array|object} target - any of the Formats provided
|
|
590
|
+
* @param {string} [formatType = color.defaultFormat] - optional format to convert to, if not using the default
|
|
514
591
|
* @returns {string|array|object} - any of the format types provided
|
|
515
592
|
*
|
|
516
593
|
* @see {@link module:color.defaultFormat|color.defaultFormat} - to set the default format
|
|
@@ -621,7 +698,6 @@ module.exports.interpolate = function interpolate(
|
|
|
621
698
|
*
|
|
622
699
|
* @param {string|array|object} fromColor -the color to interpolate from
|
|
623
700
|
* @param {string|array|object} toColor - the color to interpolate to
|
|
624
|
-
* @param {Number} percent - value from 0-1 on where we should be on the sliding scale
|
|
625
701
|
* @param {Function} [interpolationFn = ColorUtils.interpolationStrategy] - function of
|
|
626
702
|
* signature (fromVal:Number[0-255], toVal:Number[0-255], pct:Number[0-1]):Number[0-255]
|
|
627
703
|
* @param {String} [formatType = ColorUtils.defaultFormat] - the format to convert the result to
|