@jupytergis/base 0.9.1 → 0.9.2

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.
@@ -0,0 +1,19 @@
1
+ export interface IColorMap {
2
+ name: ColorRampName;
3
+ colors: string[];
4
+ }
5
+ export declare const COLOR_RAMP_NAMES: readonly ["jet", "hot", "cool", "spring", "summer", "autumn", "winter", "bone", "copper", "greys", "YiGnBu", "greens", "YiOrRd", "bluered", "RdBu", "rainbow", "portland", "blackbody", "earth", "electric", "viridis", "inferno", "magma", "plasma", "warm", "bathymetry", "cdom", "chlorophyll", "density", "freesurface-blue", "freesurface-red", "oxygen", "par", "phase", "salinity", "temperature", "turbidity", "velocity-blue", "velocity-green", "ice", "oxy", "matter", "amp", "tempo", "rain", "topo", "balance", "delta", "curl", "diff", "tarn"];
6
+ export type ColorRampName = (typeof COLOR_RAMP_NAMES)[number];
7
+ export declare const getColorMapList: () => IColorMap[];
8
+ /**
9
+ * Hook that loads and sets color maps.
10
+ */
11
+ export declare const useColorMapList: (setColorMaps: (maps: IColorMap[]) => void) => void;
12
+ /**
13
+ * Ensure we always get a valid hex string from either an RGB(A) array or string.
14
+ */
15
+ export declare const ensureHexColorCode: (color: number[] | string) => string;
16
+ /**
17
+ * Convert hex to [r,g,b,a] array.
18
+ */
19
+ export declare function hexToRgb(hex: string): [number, number, number, number];
@@ -0,0 +1,126 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import colormap from 'colormap';
13
+ import colorScale from 'colormap/colorScale.js';
14
+ import { useEffect } from 'react';
15
+ import rawCmocean from "./components/color_ramp/cmocean.json";
16
+ const { __license__: _ } = rawCmocean, cmocean = __rest(rawCmocean, ["__license__"]);
17
+ Object.assign(colorScale, cmocean);
18
+ export const COLOR_RAMP_NAMES = [
19
+ 'jet',
20
+ // 'hsv', 11 steps min
21
+ 'hot',
22
+ 'cool',
23
+ 'spring',
24
+ 'summer',
25
+ 'autumn',
26
+ 'winter',
27
+ 'bone',
28
+ 'copper',
29
+ 'greys',
30
+ 'YiGnBu',
31
+ 'greens',
32
+ 'YiOrRd',
33
+ 'bluered',
34
+ 'RdBu',
35
+ // 'picnic', 11 steps min
36
+ 'rainbow',
37
+ 'portland',
38
+ 'blackbody',
39
+ 'earth',
40
+ 'electric',
41
+ 'viridis',
42
+ 'inferno',
43
+ 'magma',
44
+ 'plasma',
45
+ 'warm',
46
+ // 'rainbow-soft', 11 steps min
47
+ 'bathymetry',
48
+ 'cdom',
49
+ 'chlorophyll',
50
+ 'density',
51
+ 'freesurface-blue',
52
+ 'freesurface-red',
53
+ 'oxygen',
54
+ 'par',
55
+ 'phase',
56
+ 'salinity',
57
+ 'temperature',
58
+ 'turbidity',
59
+ 'velocity-blue',
60
+ 'velocity-green',
61
+ // 'cubehelix' 16 steps min
62
+ 'ice',
63
+ 'oxy',
64
+ 'matter',
65
+ 'amp',
66
+ 'tempo',
67
+ 'rain',
68
+ 'topo',
69
+ 'balance',
70
+ 'delta',
71
+ 'curl',
72
+ 'diff',
73
+ 'tarn',
74
+ ];
75
+ export const getColorMapList = () => {
76
+ const colorMapList = [];
77
+ COLOR_RAMP_NAMES.forEach(name => {
78
+ const colorRamp = colormap({
79
+ colormap: name,
80
+ nshades: 255,
81
+ format: 'rgbaString',
82
+ });
83
+ colorMapList.push({ name, colors: colorRamp });
84
+ });
85
+ return colorMapList;
86
+ };
87
+ /**
88
+ * Hook that loads and sets color maps.
89
+ */
90
+ export const useColorMapList = (setColorMaps) => {
91
+ useEffect(() => {
92
+ setColorMaps(getColorMapList());
93
+ }, [setColorMaps]);
94
+ };
95
+ /**
96
+ * Ensure we always get a valid hex string from either an RGB(A) array or string.
97
+ */
98
+ export const ensureHexColorCode = (color) => {
99
+ if (typeof color === 'string') {
100
+ return color;
101
+ }
102
+ // color must be an RGBA array
103
+ const hex = color
104
+ .slice(0, -1) // Color input doesn't support hex alpha values so cut that out
105
+ .map((val) => {
106
+ return val.toString(16).padStart(2, '0');
107
+ })
108
+ .join('');
109
+ return '#' + hex;
110
+ };
111
+ /**
112
+ * Convert hex to [r,g,b,a] array.
113
+ */
114
+ export function hexToRgb(hex) {
115
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
116
+ if (!result) {
117
+ console.warn('Unable to parse hex value, defaulting to black');
118
+ return [0, 0, 0, 255];
119
+ }
120
+ return [
121
+ parseInt(result[1], 16),
122
+ parseInt(result[2], 16),
123
+ parseInt(result[3], 16),
124
+ 255, // TODO: Make alpha customizable?
125
+ ];
126
+ }
@@ -1,69 +1,12 @@
1
1
  import { Button } from '@jupyterlab/ui-components';
2
- import colormap from 'colormap';
3
2
  import React, { useEffect, useRef, useState } from 'react';
3
+ import { useColorMapList } from "../../colorRampUtils";
4
4
  import ColorRampEntry from './ColorRampEntry';
5
5
  const CanvasSelectComponent = ({ selectedRamp, setSelected, }) => {
6
- const colorRampNames = [
7
- 'jet',
8
- // 'hsv', 11 steps min
9
- 'hot',
10
- 'cool',
11
- 'spring',
12
- 'summer',
13
- 'autumn',
14
- 'winter',
15
- 'bone',
16
- 'copper',
17
- 'greys',
18
- 'YiGnBu',
19
- 'greens',
20
- 'YiOrRd',
21
- 'bluered',
22
- 'RdBu',
23
- // 'picnic', 11 steps min
24
- 'rainbow',
25
- 'portland',
26
- 'blackbody',
27
- 'earth',
28
- 'electric',
29
- 'viridis',
30
- 'inferno',
31
- 'magma',
32
- 'plasma',
33
- 'warm',
34
- // 'rainbow-soft', 11 steps min
35
- 'bathymetry',
36
- 'cdom',
37
- 'chlorophyll',
38
- 'density',
39
- 'freesurface-blue',
40
- 'freesurface-red',
41
- 'oxygen',
42
- 'par',
43
- 'phase',
44
- 'salinity',
45
- 'temperature',
46
- 'turbidity',
47
- 'velocity-blue',
48
- 'velocity-green',
49
- // 'cubehelix' 16 steps min
50
- ];
51
6
  const containerRef = useRef(null);
52
7
  const [isOpen, setIsOpen] = useState(false);
53
8
  const [colorMaps, setColorMaps] = useState([]);
54
- useEffect(() => {
55
- const colorMapList = [];
56
- colorRampNames.forEach(name => {
57
- const colorRamp = colormap({
58
- colormap: name,
59
- nshades: 255,
60
- format: 'rgbaString',
61
- });
62
- const colorMap = { name: name, colors: colorRamp };
63
- colorMapList.push(colorMap);
64
- setColorMaps(colorMapList);
65
- });
66
- }, []);
9
+ useColorMapList(setColorMaps);
67
10
  useEffect(() => {
68
11
  if (colorMaps.length > 0) {
69
12
  updateCanvas(selectedRamp);
@@ -9,9 +9,11 @@ const ColorRamp = ({ layerParams, modeOptions, classifyFunc, showModeRow, showRa
9
9
  const [numberOfShades, setNumberOfShades] = useState('');
10
10
  const [isLoading, setIsLoading] = useState(false);
11
11
  useEffect(() => {
12
- populateOptions();
12
+ if (selectedRamp === '' && selectedMode === '' && numberOfShades === '') {
13
+ populateOptions();
14
+ }
13
15
  }, [layerParams]);
14
- const populateOptions = async () => {
16
+ const populateOptions = () => {
15
17
  let nClasses, singleBandMode, colorRamp;
16
18
  if (layerParams.symbologyState) {
17
19
  nClasses = layerParams.symbologyState.nClasses;
@@ -0,0 +1,459 @@
1
+ {
2
+ "__license__": "The MIT License (MIT) Copyright (c) 2015 Kristen M. Thyng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in alL copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
3
+ "ice": [
4
+ {
5
+ "index": 0.0,
6
+ "rgb": [3, 5, 18]
7
+ },
8
+ {
9
+ "index": 0.125,
10
+ "rgb": [33, 32, 65]
11
+ },
12
+ {
13
+ "index": 0.25,
14
+ "rgb": [56, 56, 116]
15
+ },
16
+ {
17
+ "index": 0.375,
18
+ "rgb": [62, 87, 163]
19
+ },
20
+ {
21
+ "index": 0.5,
22
+ "rgb": [66, 122, 183]
23
+ },
24
+ {
25
+ "index": 0.625,
26
+ "rgb": [88, 157, 195]
27
+ },
28
+ {
29
+ "index": 0.75,
30
+ "rgb": [122, 190, 208]
31
+ },
32
+ {
33
+ "index": 0.875,
34
+ "rgb": [176, 221, 225]
35
+ },
36
+ {
37
+ "index": 1.0,
38
+ "rgb": [234, 252, 253]
39
+ }
40
+ ],
41
+ "oxy": [
42
+ {
43
+ "index": 0.0,
44
+ "rgb": [63, 5, 5]
45
+ },
46
+ {
47
+ "index": 0.125,
48
+ "rgb": [118, 5, 15]
49
+ },
50
+ {
51
+ "index": 0.25,
52
+ "rgb": [91, 91, 90]
53
+ },
54
+ {
55
+ "index": 0.375,
56
+ "rgb": [122, 121, 121]
57
+ },
58
+ {
59
+ "index": 0.5,
60
+ "rgb": [154, 154, 153]
61
+ },
62
+ {
63
+ "index": 0.625,
64
+ "rgb": [190, 189, 188]
65
+ },
66
+ {
67
+ "index": 0.75,
68
+ "rgb": [229, 229, 228]
69
+ },
70
+ {
71
+ "index": 0.875,
72
+ "rgb": [232, 224, 50]
73
+ },
74
+ {
75
+ "index": 1.0,
76
+ "rgb": [220, 174, 25]
77
+ }
78
+ ],
79
+ "matter": [
80
+ {
81
+ "index": 0.0,
82
+ "rgb": [253, 237, 176]
83
+ },
84
+ {
85
+ "index": 0.125,
86
+ "rgb": [249, 192, 135]
87
+ },
88
+ {
89
+ "index": 0.25,
90
+ "rgb": [241, 148, 102]
91
+ },
92
+ {
93
+ "index": 0.375,
94
+ "rgb": [229, 105, 83]
95
+ },
96
+ {
97
+ "index": 0.5,
98
+ "rgb": [206, 67, 86]
99
+ },
100
+ {
101
+ "index": 0.625,
102
+ "rgb": [171, 41, 96]
103
+ },
104
+ {
105
+ "index": 0.75,
106
+ "rgb": [130, 27, 98]
107
+ },
108
+ {
109
+ "index": 0.875,
110
+ "rgb": [87, 22, 86]
111
+ },
112
+ {
113
+ "index": 1.0,
114
+ "rgb": [47, 15, 61]
115
+ }
116
+ ],
117
+ "amp": [
118
+ {
119
+ "index": 0.0,
120
+ "rgb": [241, 236, 236]
121
+ },
122
+ {
123
+ "index": 0.125,
124
+ "rgb": [226, 199, 190]
125
+ },
126
+ {
127
+ "index": 0.25,
128
+ "rgb": [215, 162, 144]
129
+ },
130
+ {
131
+ "index": 0.375,
132
+ "rgb": [204, 125, 99]
133
+ },
134
+ {
135
+ "index": 0.5,
136
+ "rgb": [191, 88, 58]
137
+ },
138
+ {
139
+ "index": 0.625,
140
+ "rgb": [174, 46, 36]
141
+ },
142
+ {
143
+ "index": 0.75,
144
+ "rgb": [142, 16, 40]
145
+ },
146
+ {
147
+ "index": 0.875,
148
+ "rgb": [100, 14, 35]
149
+ },
150
+ {
151
+ "index": 1.0,
152
+ "rgb": [60, 9, 17]
153
+ }
154
+ ],
155
+ "tempo": [
156
+ {
157
+ "index": 0.0,
158
+ "rgb": [254, 245, 244]
159
+ },
160
+ {
161
+ "index": 0.125,
162
+ "rgb": [210, 217, 198]
163
+ },
164
+ {
165
+ "index": 0.25,
166
+ "rgb": [161, 193, 161]
167
+ },
168
+ {
169
+ "index": 0.375,
170
+ "rgb": [105, 171, 137]
171
+ },
172
+ {
173
+ "index": 0.5,
174
+ "rgb": [42, 147, 127]
175
+ },
176
+ {
177
+ "index": 0.625,
178
+ "rgb": [17, 118, 118]
179
+ },
180
+ {
181
+ "index": 0.75,
182
+ "rgb": [26, 88, 103]
183
+ },
184
+ {
185
+ "index": 0.875,
186
+ "rgb": [26, 59, 84]
187
+ },
188
+ {
189
+ "index": 1.0,
190
+ "rgb": [20, 29, 67]
191
+ }
192
+ ],
193
+ "rain": [
194
+ {
195
+ "index": 0.0,
196
+ "rgb": [238, 237, 242]
197
+ },
198
+ {
199
+ "index": 0.125,
200
+ "rgb": [218, 203, 187]
201
+ },
202
+ {
203
+ "index": 0.25,
204
+ "rgb": [181, 178, 138]
205
+ },
206
+ {
207
+ "index": 0.375,
208
+ "rgb": [125, 160, 119]
209
+ },
210
+ {
211
+ "index": 0.5,
212
+ "rgb": [60, 142, 109]
213
+ },
214
+ {
215
+ "index": 0.625,
216
+ "rgb": [5, 116, 109]
217
+ },
218
+ {
219
+ "index": 0.75,
220
+ "rgb": [20, 86, 102]
221
+ },
222
+ {
223
+ "index": 0.875,
224
+ "rgb": [36, 56, 79]
225
+ },
226
+ {
227
+ "index": 1.0,
228
+ "rgb": [33, 26, 56]
229
+ }
230
+ ],
231
+ "topo": [
232
+ {
233
+ "index": 0.0,
234
+ "rgb": [39, 26, 44]
235
+ },
236
+ {
237
+ "index": 0.125,
238
+ "rgb": [64, 77, 139]
239
+ },
240
+ {
241
+ "index": 0.25,
242
+ "rgb": [72, 142, 157]
243
+ },
244
+ {
245
+ "index": 0.375,
246
+ "rgb": [121, 206, 162]
247
+ },
248
+ {
249
+ "index": 0.5,
250
+ "rgb": [13, 37, 19]
251
+ },
252
+ {
253
+ "index": 0.625,
254
+ "rgb": [59, 89, 38]
255
+ },
256
+ {
257
+ "index": 0.75,
258
+ "rgb": [144, 129, 63]
259
+ },
260
+ {
261
+ "index": 0.875,
262
+ "rgb": [210, 182, 118]
263
+ },
264
+ {
265
+ "index": 1.0,
266
+ "rgb": [248, 253, 228]
267
+ }
268
+ ],
269
+ "balance": [
270
+ {
271
+ "index": 0.0,
272
+ "rgb": [23, 28, 66]
273
+ },
274
+ {
275
+ "index": 0.125,
276
+ "rgb": [36, 72, 175]
277
+ },
278
+ {
279
+ "index": 0.25,
280
+ "rgb": [56, 135, 185]
281
+ },
282
+ {
283
+ "index": 0.375,
284
+ "rgb": [151, 185, 197]
285
+ },
286
+ {
287
+ "index": 0.5,
288
+ "rgb": [240, 236, 235]
289
+ },
290
+ {
291
+ "index": 0.625,
292
+ "rgb": [214, 161, 143]
293
+ },
294
+ {
295
+ "index": 0.75,
296
+ "rgb": [191, 87, 58]
297
+ },
298
+ {
299
+ "index": 0.875,
300
+ "rgb": [141, 15, 40]
301
+ },
302
+ {
303
+ "index": 1.0,
304
+ "rgb": [60, 9, 17]
305
+ }
306
+ ],
307
+ "delta": [
308
+ {
309
+ "index": 0.0,
310
+ "rgb": [16, 31, 63]
311
+ },
312
+ {
313
+ "index": 0.125,
314
+ "rgb": [28, 81, 156]
315
+ },
316
+ {
317
+ "index": 0.25,
318
+ "rgb": [51, 144, 169]
319
+ },
320
+ {
321
+ "index": 0.375,
322
+ "rgb": [151, 197, 190]
323
+ },
324
+ {
325
+ "index": 0.5,
326
+ "rgb": [254, 252, 203]
327
+ },
328
+ {
329
+ "index": 0.625,
330
+ "rgb": [200, 185, 67]
331
+ },
332
+ {
333
+ "index": 0.75,
334
+ "rgb": [93, 145, 12]
335
+ },
336
+ {
337
+ "index": 0.875,
338
+ "rgb": [11, 94, 44]
339
+ },
340
+ {
341
+ "index": 1.0,
342
+ "rgb": [23, 35, 18]
343
+ }
344
+ ],
345
+ "curl": [
346
+ {
347
+ "index": 0.0,
348
+ "rgb": [20, 29, 67]
349
+ },
350
+ {
351
+ "index": 0.125,
352
+ "rgb": [26, 89, 103]
353
+ },
354
+ {
355
+ "index": 0.25,
356
+ "rgb": [44, 148, 127]
357
+ },
358
+ {
359
+ "index": 0.375,
360
+ "rgb": [163, 194, 162]
361
+ },
362
+ {
363
+ "index": 0.5,
364
+ "rgb": [253, 245, 243]
365
+ },
366
+ {
367
+ "index": 0.625,
368
+ "rgb": [225, 166, 142]
369
+ },
370
+ {
371
+ "index": 0.75,
372
+ "rgb": [194, 88, 96]
373
+ },
374
+ {
375
+ "index": 0.875,
376
+ "rgb": [131, 31, 95]
377
+ },
378
+ {
379
+ "index": 1.0,
380
+ "rgb": [51, 13, 53]
381
+ }
382
+ ],
383
+ "diff": [
384
+ {
385
+ "index": 0.0,
386
+ "rgb": [7, 34, 63]
387
+ },
388
+ {
389
+ "index": 0.125,
390
+ "rgb": [49, 87, 113]
391
+ },
392
+ {
393
+ "index": 0.25,
394
+ "rgb": [116, 136, 151]
395
+ },
396
+ {
397
+ "index": 0.375,
398
+ "rgb": [184, 191, 197]
399
+ },
400
+ {
401
+ "index": 0.5,
402
+ "rgb": [245, 241, 239]
403
+ },
404
+ {
405
+ "index": 0.625,
406
+ "rgb": [193, 185, 166]
407
+ },
408
+ {
409
+ "index": 0.75,
410
+ "rgb": [140, 128, 91]
411
+ },
412
+ {
413
+ "index": 0.875,
414
+ "rgb": [86, 79, 32]
415
+ },
416
+ {
417
+ "index": 1.0,
418
+ "rgb": [28, 34, 6]
419
+ }
420
+ ],
421
+ "tarn": [
422
+ {
423
+ "index": 0.0,
424
+ "rgb": [22, 35, 13]
425
+ },
426
+ {
427
+ "index": 0.125,
428
+ "rgb": [79, 84, 19]
429
+ },
430
+ {
431
+ "index": 0.25,
432
+ "rgb": [169, 118, 49]
433
+ },
434
+ {
435
+ "index": 0.375,
436
+ "rgb": [221, 177, 141]
437
+ },
438
+ {
439
+ "index": 0.5,
440
+ "rgb": [252, 247, 245]
441
+ },
442
+ {
443
+ "index": 0.625,
444
+ "rgb": [180, 193, 161]
445
+ },
446
+ {
447
+ "index": 0.75,
448
+ "rgb": [84, 144, 132]
449
+ },
450
+ {
451
+ "index": 0.875,
452
+ "rgb": [25, 89, 110]
453
+ },
454
+ {
455
+ "index": 1.0,
456
+ "rgb": [15, 30, 79]
457
+ }
458
+ ]
459
+ }
@@ -21,7 +21,7 @@ const StopContainer = ({ selectedMethod, stopRows, setStopRows, }) => {
21
21
  React.createElement("div", { className: "jp-gis-stop-labels", style: { display: 'flex', gap: 6 } },
22
22
  React.createElement("span", { style: { flex: '0 0 18%' } }, "Value"),
23
23
  React.createElement("span", null, "Output Value")),
24
- stopRows.map((stop, index) => (React.createElement(StopRow, { key: `${index}-${stop.output}`, index: index, value: stop.stop, outputValue: stop.output, stopRows: stopRows, setStopRows: setStopRows, deleteRow: () => deleteStopRow(index), useNumber: selectedMethod === 'radius' ? true : false })))),
24
+ stopRows.map((stop, index) => (React.createElement(StopRow, { key: `${index}-${stop.output}`, index: index, dataValue: stop.stop, symbologyValue: stop.output, stopRows: stopRows, setStopRows: setStopRows, deleteRow: () => deleteStopRow(index), useNumber: selectedMethod === 'radius' ? true : false })))),
25
25
  React.createElement("div", { className: "jp-gis-symbology-button-container" },
26
26
  React.createElement(Button, { className: "jp-Dialog-button jp-mod-accept jp-mod-styled", onClick: addStopRow }, "Add Stop"))));
27
27
  };
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { IStopRow } from "../../symbologyDialog";
3
+ import { SymbologyValue } from "../../../../types";
3
4
  declare const StopRow: React.FC<{
4
5
  index: number;
5
- value: number;
6
- outputValue: number | number[];
6
+ dataValue: number;
7
+ symbologyValue: SymbologyValue;
7
8
  stopRows: IStopRow[];
8
9
  setStopRows: (stopRows: IStopRow[]) => void;
9
10
  deleteRow: () => void;
@@ -2,7 +2,8 @@ import { faTrash } from '@fortawesome/free-solid-svg-icons';
2
2
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3
3
  import { Button } from '@jupyterlab/ui-components';
4
4
  import React, { useEffect, useRef } from 'react';
5
- const StopRow = ({ index, value, outputValue, stopRows, setStopRows, deleteRow, useNumber, }) => {
5
+ import { ensureHexColorCode, hexToRgb, } from "../../colorRampUtils";
6
+ const StopRow = ({ index, dataValue, symbologyValue, stopRows, setStopRows, deleteRow, useNumber, }) => {
6
7
  const inputRef = useRef(null);
7
8
  useEffect(() => {
8
9
  var _a;
@@ -10,32 +11,6 @@ const StopRow = ({ index, value, outputValue, stopRows, setStopRows, deleteRow,
10
11
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
11
12
  }
12
13
  }, [stopRows]);
13
- const rgbArrToHex = (rgbArr) => {
14
- if (!Array.isArray(rgbArr)) {
15
- return;
16
- }
17
- const hex = rgbArr
18
- .slice(0, -1) // Color input doesn't support hex alpha values so cut that out
19
- .map((val) => {
20
- return val.toString(16).padStart(2, '0');
21
- })
22
- .join('');
23
- return '#' + hex;
24
- };
25
- const hexToRgb = (hex) => {
26
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
27
- if (!result) {
28
- console.warn('Unable to parse hex value, defaulting to black');
29
- return [parseInt('0', 16), parseInt('0', 16), parseInt('0', 16)];
30
- }
31
- const rgbValues = [
32
- parseInt(result[1], 16),
33
- parseInt(result[2], 16),
34
- parseInt(result[3], 16),
35
- 1, // TODO: Make alpha customizable?
36
- ];
37
- return rgbValues;
38
- };
39
14
  const handleStopChange = (event) => {
40
15
  const newRows = [...stopRows];
41
16
  newRows[index].stop = +event.target.value;
@@ -62,8 +37,8 @@ const StopRow = ({ index, value, outputValue, stopRows, setStopRows, deleteRow,
62
37
  setStopRows(newRows);
63
38
  };
64
39
  return (React.createElement("div", { className: "jp-gis-color-row" },
65
- React.createElement("input", { id: `jp-gis-color-value-${index}`, type: "number", value: value, onChange: handleStopChange, onBlur: handleBlur, className: "jp-mod-styled jp-gis-color-row-value-input" }),
66
- useNumber ? (React.createElement("input", { type: "number", ref: inputRef, value: outputValue, onChange: handleOutputChange, className: "jp-mod-styled jp-gis-color-row-output-input" })) : (React.createElement("input", { id: `jp-gis-color-color-${index}`, ref: inputRef, value: rgbArrToHex(outputValue), type: "color", onChange: handleOutputChange, className: "jp-mod-styled jp-gis-color-row-output-input" })),
40
+ React.createElement("input", { id: `jp-gis-color-value-${index}`, type: "number", value: dataValue, onChange: handleStopChange, onBlur: handleBlur, className: "jp-mod-styled jp-gis-color-row-value-input" }),
41
+ useNumber ? (React.createElement("input", { type: "number", ref: inputRef, value: symbologyValue, onChange: handleOutputChange, className: "jp-mod-styled jp-gis-color-row-output-input" })) : (React.createElement("input", { id: `jp-gis-color-color-${index}`, ref: inputRef, value: ensureHexColorCode(symbologyValue), type: "color", onChange: handleOutputChange, className: "jp-mod-styled jp-gis-color-row-output-input" })),
67
42
  React.createElement(Button, { id: `jp-gis-remove-color-${index}`, className: "jp-Button jp-gis-filter-icon" },
68
43
  React.createElement(FontAwesomeIcon, { icon: faTrash, onClick: deleteRow }))));
69
44
  };
@@ -3,7 +3,7 @@ import { Dialog } from '@jupyterlab/apputils';
3
3
  import { IStateDB } from '@jupyterlab/statedb';
4
4
  import { PromiseDelegate } from '@lumino/coreutils';
5
5
  import { Signal } from '@lumino/signaling';
6
- import { SymbologyTab } from "../../types";
6
+ import { SymbologyTab, SymbologyValue } from "../../types";
7
7
  export interface ISymbologyDialogProps {
8
8
  model: IJupyterGISModel;
9
9
  state: IStateDB;
@@ -24,7 +24,7 @@ export interface ISymbologyWidgetOptions {
24
24
  }
25
25
  export interface IStopRow {
26
26
  stop: number;
27
- output: number | number[];
27
+ output: SymbologyValue;
28
28
  }
29
29
  export declare class SymbologyWidget extends Dialog<boolean> {
30
30
  private okSignal;
@@ -1,4 +1,5 @@
1
1
  import colormap from 'colormap';
2
+ const COLOR_EXPR_STOPS_START = 3;
2
3
  export var VectorUtils;
3
4
  (function (VectorUtils) {
4
5
  VectorUtils.buildColorInfo = (layer) => {
@@ -25,7 +26,7 @@ export var VectorUtils;
25
26
  // Second element is type of interpolation (ie linear)
26
27
  // Third is input value that stop values are compared with
27
28
  // Fourth and on is value:color pairs
28
- for (let i = 3; i < color[key].length; i += 2) {
29
+ for (let i = COLOR_EXPR_STOPS_START; i < color[key].length; i += 2) {
29
30
  const pairKey = `${color[key][i]}-${color[key][i + 1]}`;
30
31
  if (!seenPairs.has(pairKey)) {
31
32
  valueColorPairs.push({
@@ -63,10 +64,15 @@ export var VectorUtils;
63
64
  return [];
64
65
  }
65
66
  const stopOutputPairs = [];
66
- for (let i = 3; i < color['circle-radius'].length; i += 2) {
67
+ const circleRadius = color['circle-radius'];
68
+ if (!Array.isArray(circleRadius) ||
69
+ circleRadius.length <= COLOR_EXPR_STOPS_START) {
70
+ return [];
71
+ }
72
+ for (let i = COLOR_EXPR_STOPS_START; i < circleRadius.length; i += 2) {
67
73
  const obj = {
68
- stop: color['circle-radius'][i],
69
- output: color['circle-radius'][i + 1],
74
+ stop: circleRadius[i],
75
+ output: circleRadius[i + 1],
70
76
  };
71
77
  stopOutputPairs.push(obj);
72
78
  }
@@ -282,7 +282,7 @@ const SingleBandPseudoColor = ({ model, okSignalPromise, cancel, layerId, }) =>
282
282
  ? '='
283
283
  : ''),
284
284
  React.createElement("span", null, "Output Value")),
285
- stopRows.map((stop, index) => (React.createElement(StopRow, { key: `${index}-${stop.output}`, index: index, value: stop.stop, outputValue: stop.output, stopRows: stopRows, setStopRows: setStopRows, deleteRow: () => deleteStopRow(index) })))),
285
+ stopRows.map((stop, index) => (React.createElement(StopRow, { key: `${index}-${stop.output}`, index: index, dataValue: stop.stop, symbologyValue: stop.output, stopRows: stopRows, setStopRows: setStopRows, deleteRow: () => deleteStopRow(index) })))),
286
286
  React.createElement("div", { className: "jp-gis-symbology-button-container" },
287
287
  React.createElement(Button, { className: "jp-Dialog-button jp-mod-accept jp-mod-styled", onClick: addStopRow }, "Add Stop"))));
288
288
  };
package/lib/types.d.ts CHANGED
@@ -5,6 +5,12 @@ export { IDict };
5
5
  export type ValueOf<T> = T[keyof T];
6
6
  export type JupyterGISTracker = WidgetTracker<IJupyterGISWidget>;
7
7
  export type SymbologyTab = 'color' | 'radius';
8
+ type RgbColorValue = [number, number, number] | [number, number, number, number];
9
+ type HexColorValue = string;
10
+ type InternalRgbArray = number[];
11
+ export type ColorValue = RgbColorValue | HexColorValue;
12
+ export type SizeValue = number;
13
+ export type SymbologyValue = SizeValue | ColorValue | InternalRgbArray;
8
14
  export type VectorRenderType = 'Single Symbol' | 'Canonical' | 'Graduated' | 'Categorized' | 'Heatmap';
9
15
  /**
10
16
  * Add jupytergisMaps object to the global variables.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupytergis/base",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "A JupyterLab extension for 3D modelling.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -44,7 +44,7 @@
44
44
  "@jupyter/collaboration": "^3.1.0",
45
45
  "@jupyter/react-components": "^0.16.6",
46
46
  "@jupyter/ydoc": "^2.0.0 || ^3.0.0",
47
- "@jupytergis/schema": "^0.9.1",
47
+ "@jupytergis/schema": "^0.9.2",
48
48
  "@jupyterlab/application": "^4.3.0",
49
49
  "@jupyterlab/apputils": "^4.3.0",
50
50
  "@jupyterlab/completer": "^4.3.0",