jupyter-ijavascript-utils 1.52.0 → 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 CHANGED
@@ -74,6 +74,7 @@ Give it a try here:
74
74
  [![Binder:what can I do with this](https://mybinder.org/badge_logo.svg)](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
@@ -1,3 +1,3 @@
1
1
  # syntax=docker/dockerfile:1
2
2
 
3
- FROM darkbluestudios/jupyter-ijavascript-utils:binder_1.52.0
3
+ FROM darkbluestudios/jupyter-ijavascript-utils:binder_1.53.0
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
  ![Screenshot of example notebook](docResources/img/mainExampleNotebook.png)
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.52.0",
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.1.2",
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
+ * ![Example SVG](img/interpolationExample.svg)
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
- * * Hex - 6-8 character hexadecimal colors as RRGGBB or RRGGBBAA, like red for #ff0000 or #ff000080 for semi-transparency
72
- * * Hex3 - 3-4 character hexadecimal colors: RGB or RGBA, like red for #F00 or #F008 for semi-transparency
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
+ * ![example](img/interpolationStrategies.svg)
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
- * Which interpolation strategy to use when interpolating between colors
168
+ * Default interpolation strategy used when interpolating
169
+ * from one color to another.
118
170
  *
119
171
  * (Defaults to linear)
120
172
  *
173
+ * ![example](img/interpolationStrategies.svg)
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
- return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`;
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
package/src/date.js CHANGED
@@ -311,9 +311,10 @@ module.exports.epochShift = function epochShift(date, timeZoneStr) {
311
311
  * Consider this as an alternative to epochShifting.
312
312
  *
313
313
  * ```
314
- * d = new Date(Date.toISO(2024, 12, 26, 12, 30, 0));
314
+ * d = Date.parse('2024-12-27 13:30:00');
315
315
  *
316
- * utils.date.toLocalISO(d, 'america/Chicago'); // '2024-12-16T06:30:00.000+05:30Z'
316
+ * utils.date.toLocalISO(d, 'america/Chicago'); // '2024-12-27T07:30:00.000-06:00'
317
+ * utils.date.toLocalISO(d, 'europe/paris'); // '2024-12-27T14:30:00.000+01:00'
317
318
  * ```
318
319
  *
319
320
  * @param {Date} date - date to print
@@ -461,10 +462,10 @@ class DateRange {
461
462
  * @param {DateRange} targetDateRange - dateRange to compare
462
463
  * @returns {Boolean}
463
464
  * @example
464
- * overlapA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
465
- * overlapB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
466
- * overlapC = new Date(Date.UTC(2024, 12, 26, 14, 0, 0));
467
- * overlapD = new Date(Date.UTC(2024, 12, 26, 15, 0, 0));
465
+ * overlapA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
466
+ * overlapB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
467
+ * overlapC = new Date(Date.UTC(2024, 11, 26, 14, 0, 0));
468
+ * overlapD = new Date(Date.UTC(2024, 11, 26, 15, 0, 0));
468
469
  *
469
470
  * rangeBefore = new utils.DateRange(overlapA, overlapB);
470
471
  * rangeAfter = new utils.DateRange(overlapC, overlapD);
@@ -490,10 +491,10 @@ class DateRange {
490
491
  * @returns {Boolean} - if the value is within the range (true) or not (false)
491
492
  *
492
493
  * @example
493
- * withinA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
494
- * withinB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
495
- * withinC = new Date(Date.UTC(2024, 12, 26, 14, 0, 0));
496
- * withinD = new Date(Date.UTC(2024, 12, 26, 15, 0, 0));
494
+ * withinA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
495
+ * withinB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
496
+ * withinC = new Date(Date.UTC(2024, 11, 26, 14, 0, 0));
497
+ * withinD = new Date(Date.UTC(2024, 11, 26, 15, 0, 0));
497
498
  *
498
499
  * range = new utils.DateRange(withinB, withinD);
499
500
  * range.contains(withinA); // false - it was before the range
@@ -512,8 +513,8 @@ class DateRange {
512
513
  * Determines the millisecond duration between the end and start time.
513
514
  *
514
515
  * ```
515
- * durationA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
516
- * durationB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
516
+ * durationA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
517
+ * durationB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
517
518
  * range = new utils.DateRange(durationA, durationB);
518
519
  *
519
520
  * range.durationString(); // 1 hour in milliseconds; 1000 * 60 * 60;
@@ -529,8 +530,8 @@ class DateRange {
529
530
  * Determines the duration in a clear and understandable string;
530
531
  *
531
532
  * ```
532
- * durationA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
533
- * durationB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
533
+ * durationA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
534
+ * durationB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
534
535
  * range = new utils.DateRange(durationA, durationB);
535
536
  *
536
537
  * range.durationString(); // '0 days, 1 hours, 0 minutes, 0.0 seconds';
@@ -547,8 +548,8 @@ class DateRange {
547
548
  * Determines the duration in days:hours:minutes:seconds.milliseconds
548
549
  *
549
550
  * ```
550
- * durationA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
551
- * durationB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
551
+ * durationA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
552
+ * durationB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
552
553
  * range = new utils.DateRange(durationA, durationB);
553
554
  *
554
555
  * range.durationString(); // '0:01:00:00.0000';
@@ -574,8 +575,8 @@ class DateRange {
574
575
  * Converts the daterange to a string value
575
576
  *
576
577
  * ```
577
- * durationA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
578
- * durationB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
578
+ * durationA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
579
+ * durationB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
579
580
  * range = new utils.DateRange(durationA, durationB);
580
581
  *
581
582
  * range.toString(); // '2025-01-26T12:00:00.000Z to 2025-01-26T13:00:00.000Z';
@@ -591,8 +592,8 @@ class DateRange {
591
592
  * Converts the daterange to a local string value
592
593
  *
593
594
  * ```
594
- * durationA = new Date(Date.UTC(2024, 12, 26, 12, 0, 0));
595
- * durationB = new Date(Date.UTC(2024, 12, 26, 13, 0, 0));
595
+ * durationA = new Date(Date.UTC(2024, 11, 26, 12, 0, 0));
596
+ * durationB = new Date(Date.UTC(2024, 11, 26, 13, 0, 0));
596
597
  * range = new utils.DateRange(durationA, durationB);
597
598
  *
598
599
  * range.toLocaleString(); // '1/26/2025, 12:00:00 PM to 1/26/2025, 1:00:00 PM'