autumnplot-gl 3.1.0 → 3.2.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/README.md +6 -11
- package/dist/110.autumnplot-gl.js +1 -1
- package/dist/110.autumnplot-gl.js.map +1 -1
- package/dist/autumnplot-gl.js +1 -1
- package/dist/autumnplot-gl.js.map +1 -1
- package/dist/marchingsquares.wasm +0 -0
- package/lib/Barbs.d.ts +17 -1
- package/lib/Barbs.js +20 -18
- package/lib/BillboardCollection.d.ts +9 -2
- package/lib/BillboardCollection.js +46 -9
- package/lib/Color.d.ts +56 -0
- package/lib/Color.js +160 -0
- package/lib/ColorBar.d.ts +2 -1
- package/lib/ColorBar.js +5 -5
- package/lib/Colormap.d.ts +19 -18
- package/lib/Colormap.js +81 -20
- package/lib/Contour.d.ts +24 -3
- package/lib/Contour.js +56 -10
- package/lib/Fill.d.ts +1 -2
- package/lib/Fill.js +19 -44
- package/lib/Grid.d.ts +1 -0
- package/lib/Grid.js +6 -1
- package/lib/Hodographs.d.ts +18 -1
- package/lib/Hodographs.js +17 -16
- package/lib/Paintball.js +3 -2
- package/lib/PlotComponent.js +9 -4
- package/lib/PlotLayer.d.ts +1 -1
- package/lib/PlotLayer.worker.js +7 -7
- package/lib/PolylineCollection.d.ts +13 -6
- package/lib/PolylineCollection.js +76 -64
- package/lib/StationPlot.d.ts +34 -0
- package/lib/StationPlot.js +73 -0
- package/lib/TextCollection.d.ts +3 -2
- package/lib/TextCollection.js +21 -11
- package/lib/cpp/marchingsquares.wasm +0 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +2 -1
- package/lib/utils.d.ts +2 -8
- package/lib/utils.js +1 -83
- package/package.json +2 -2
package/lib/TextCollection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isWebGL2Ctx } from "./AutumnTypes";
|
|
2
|
+
import { Color } from "./Color";
|
|
2
3
|
import { LngLat } from "./Map";
|
|
3
4
|
import { Cache, normalizeOptions } from "./utils";
|
|
4
5
|
import { WGLBuffer, WGLProgram, WGLTexture } from "autumn-wgl";
|
|
@@ -45,8 +46,8 @@ varying highp vec2 v_tex_coord;
|
|
|
45
46
|
uniform sampler2D u_sdf_sampler;
|
|
46
47
|
uniform int u_is_halo;
|
|
47
48
|
|
|
48
|
-
uniform lowp
|
|
49
|
-
uniform lowp
|
|
49
|
+
uniform lowp vec4 u_text_color;
|
|
50
|
+
uniform lowp vec4 u_halo_color;
|
|
50
51
|
|
|
51
52
|
#define SDF_FILL 0.75
|
|
52
53
|
#define SDF_HALO 0.45
|
|
@@ -57,18 +58,21 @@ void main() {
|
|
|
57
58
|
lowp float step_width = 0.08;
|
|
58
59
|
lowp float alpha = smoothstep(SDF_FILL - step_width, SDF_FILL + step_width, sdf_val);
|
|
59
60
|
|
|
60
|
-
lowp
|
|
61
|
+
lowp vec4 color = u_is_halo == 1 ? u_halo_color : u_text_color;
|
|
61
62
|
|
|
62
63
|
if (u_is_halo == 1) {
|
|
63
64
|
alpha = min(smoothstep(SDF_HALO - step_width, SDF_HALO + step_width, sdf_val), 1.0 - alpha);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
color.a *= alpha;
|
|
68
|
+
gl_FragColor = color;
|
|
67
69
|
}`
|
|
68
70
|
const program_cache = new Cache((gl) => new WGLProgram(gl, text_vertex_shader_src, text_fragment_shader_src));
|
|
69
71
|
const PADDING = 3;
|
|
70
72
|
function parseFontPBF(data) {
|
|
71
73
|
const readGlyph = (tag, glyph, pbf) => {
|
|
74
|
+
if (pbf === undefined)
|
|
75
|
+
return;
|
|
72
76
|
switch (tag) {
|
|
73
77
|
case 1:
|
|
74
78
|
glyph.id = pbf.readVarint();
|
|
@@ -94,12 +98,16 @@ function parseFontPBF(data) {
|
|
|
94
98
|
}
|
|
95
99
|
};
|
|
96
100
|
const readFontStack = (tag, glyphs, pbf) => {
|
|
101
|
+
if (glyphs === undefined || pbf === undefined)
|
|
102
|
+
return;
|
|
97
103
|
if (tag == 3) {
|
|
98
104
|
const glyph = pbf.readMessage(readGlyph, {});
|
|
99
105
|
glyphs.push(glyph);
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
108
|
const readFontStacks = (tag, glyphs, pbf) => {
|
|
109
|
+
if (pbf === undefined)
|
|
110
|
+
return;
|
|
103
111
|
if (tag == 1) {
|
|
104
112
|
pbf.readMessage(readFontStack, glyphs);
|
|
105
113
|
}
|
|
@@ -119,6 +127,8 @@ function createAtlas(pbf_glyphs) {
|
|
|
119
127
|
const glyphs = {};
|
|
120
128
|
glyph_bins.forEach(glyph_bin => {
|
|
121
129
|
const { bin, glyph } = glyph_bin;
|
|
130
|
+
if (bin.x === undefined || bin.y === undefined)
|
|
131
|
+
throw `Potpack couldn't pack this pot, I guess?`;
|
|
122
132
|
glyphs[glyph.id] = {
|
|
123
133
|
id: glyph.id, width: glyph.width, height: glyph.height, left: glyph.left, top: glyph.top,
|
|
124
134
|
atlas_i: bin.x, atlas_j: bin.y, advance: glyph.advance
|
|
@@ -149,8 +159,8 @@ const text_collection_opt_defaults = {
|
|
|
149
159
|
horizontal_align: 'left',
|
|
150
160
|
vertical_align: 'baseline',
|
|
151
161
|
font_size: 12,
|
|
152
|
-
text_color: [0, 0, 0],
|
|
153
|
-
halo_color: [0, 0, 0],
|
|
162
|
+
text_color: new Color([0, 0, 0, 1]),
|
|
163
|
+
halo_color: new Color([0, 0, 0, 1]),
|
|
154
164
|
halo: false
|
|
155
165
|
};
|
|
156
166
|
class TextCollection {
|
|
@@ -229,22 +239,22 @@ class TextCollection {
|
|
|
229
239
|
tc_data[i_tc++] = glyph_info.atlas_j / font_atlas.atlas_height;
|
|
230
240
|
x_offset += glyph_info.advance - glyph_info.left;
|
|
231
241
|
}
|
|
232
|
-
if (opts.horizontal_align == 'center') {
|
|
242
|
+
if (this.opts.horizontal_align == 'center') {
|
|
233
243
|
for (let i = init_i_off; i < init_i_off + text.length * 12; i += 2) {
|
|
234
244
|
offset_data[i] -= x_offset / 2;
|
|
235
245
|
}
|
|
236
246
|
}
|
|
237
|
-
else if (opts.horizontal_align == 'right') {
|
|
247
|
+
else if (this.opts.horizontal_align == 'right') {
|
|
238
248
|
for (let i = init_i_off; i < init_i_off + text.length * 12; i += 2) {
|
|
239
249
|
offset_data[i] -= x_offset;
|
|
240
250
|
}
|
|
241
251
|
}
|
|
242
|
-
if (opts.vertical_align == 'top') {
|
|
252
|
+
if (this.opts.vertical_align == 'top') {
|
|
243
253
|
for (let i = init_i_off + 1; i < init_i_off + text.length * 12; i += 2) {
|
|
244
254
|
offset_data[i] -= (font_atlas.baseline - font_atlas.top);
|
|
245
255
|
}
|
|
246
256
|
}
|
|
247
|
-
else if (opts.vertical_align == 'middle') {
|
|
257
|
+
else if (this.opts.vertical_align == 'middle') {
|
|
248
258
|
for (let i = init_i_off + 1; i < init_i_off + text.length * 12; i += 2) {
|
|
249
259
|
offset_data[i] -= (font_atlas.baseline - font_atlas.top) / 2;
|
|
250
260
|
}
|
|
@@ -261,7 +271,7 @@ class TextCollection {
|
|
|
261
271
|
render(gl, matrix, [map_width, map_height], map_zoom) {
|
|
262
272
|
const uniforms = {
|
|
263
273
|
'u_matrix': matrix, 'u_map_width': map_width, 'u_map_height': map_height, 'u_map_zoom': map_zoom, 'u_font_size': this.opts.font_size,
|
|
264
|
-
'u_text_color': this.opts.text_color, 'u_halo_color': this.opts.halo_color, 'u_offset': 0
|
|
274
|
+
'u_text_color': this.opts.text_color.toRGBATuple(), 'u_halo_color': this.opts.halo_color.toRGBATuple(), 'u_offset': 0
|
|
265
275
|
};
|
|
266
276
|
uniforms['u_is_halo'] = this.opts.halo ? 1 : 0;
|
|
267
277
|
this.program.use({ 'a_pos': this.anchors, 'a_offset': this.offsets, 'a_tex_coord': this.texcoords }, uniforms, { 'u_sdf_sampler': this.texture });
|
|
Binary file
|
package/lib/index.d.ts
CHANGED
|
@@ -7,8 +7,10 @@ import Hodographs, { HodographOptions } from './Hodographs';
|
|
|
7
7
|
import { PlotLayer, MultiPlotLayer } from './PlotLayer';
|
|
8
8
|
import { WindProfile, WebGLAnyRenderingContext, TypedArray, ContourData } from "./AutumnTypes";
|
|
9
9
|
import { MapLikeType } from "./Map";
|
|
10
|
-
import { ColorMap, ColorMapOptions
|
|
10
|
+
import { ColorMap, ColorMapOptions } from './Colormap';
|
|
11
|
+
import { Color } from "./Color";
|
|
11
12
|
import { makeColorBar, makePaintballKey, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions } from "./ColorBar";
|
|
13
|
+
import { LineStyle } from "./PolylineCollection";
|
|
12
14
|
import { RawScalarField, RawVectorField, RawProfileField, VectorRelativeTo, RawVectorFieldOptions } from "./RawField";
|
|
13
15
|
import { Grid, GridType, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid } from './Grid';
|
|
14
16
|
import { FieldContourOpts } from './ContourCreator';
|
|
@@ -27,4 +29,4 @@ declare const colormaps: {
|
|
|
27
29
|
* first, you can prevent races when you contour a bunch of fields at once.
|
|
28
30
|
*/
|
|
29
31
|
declare function initAutumnPlot(): void;
|
|
30
|
-
export { PlotComponent, Barbs, BarbsOptions, Contour, ContourOptions, ContourLabels, ContourLabelOptions, ContourFill, Raster, ContourFillOptions, RasterOptions, Paintball, PaintballOptions, Hodographs, HodographOptions, WindProfile, PlotLayer, MultiPlotLayer, MapLikeType, ColorMap, ColorMapOptions, colormaps, makeColorBar, makePaintballKey, Color, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions, RawScalarField, RawVectorField, RawProfileField, Grid, GridType, VectorRelativeTo, RawVectorFieldOptions, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, WebGLAnyRenderingContext, TypedArray, ContourData, initAutumnPlot, FieldContourOpts };
|
|
32
|
+
export { PlotComponent, Barbs, BarbsOptions, Contour, ContourOptions, ContourLabels, ContourLabelOptions, ContourFill, Raster, ContourFillOptions, RasterOptions, Paintball, PaintballOptions, Hodographs, HodographOptions, WindProfile, PlotLayer, MultiPlotLayer, MapLikeType, LineStyle, ColorMap, ColorMapOptions, colormaps, makeColorBar, makePaintballKey, Color, ColorbarOrientation, ColorbarTickDirection, ColorBarOptions, PaintballKeyOptions, RawScalarField, RawVectorField, RawProfileField, Grid, GridType, VectorRelativeTo, RawVectorFieldOptions, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, WebGLAnyRenderingContext, TypedArray, ContourData, initAutumnPlot, FieldContourOpts };
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import Paintball from "./Paintball";
|
|
|
6
6
|
import Hodographs from './Hodographs';
|
|
7
7
|
import { PlotLayer, MultiPlotLayer } from './PlotLayer';
|
|
8
8
|
import { ColorMap, bluered, redblue, pw_speed500mb, pw_speed850mb, pw_cape, pw_t2m, pw_td2m, nws_storm_clear_refl } from './Colormap';
|
|
9
|
+
import { Color } from "./Color";
|
|
9
10
|
import { makeColorBar, makePaintballKey } from "./ColorBar";
|
|
10
11
|
import { RawScalarField, RawVectorField, RawProfileField } from "./RawField";
|
|
11
12
|
import { Grid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid } from './Grid';
|
|
@@ -27,4 +28,4 @@ const colormaps = {
|
|
|
27
28
|
function initAutumnPlot() {
|
|
28
29
|
initMSModule();
|
|
29
30
|
}
|
|
30
|
-
export { PlotComponent, Barbs, Contour, ContourLabels, ContourFill, Raster, Paintball, Hodographs, PlotLayer, MultiPlotLayer, ColorMap, colormaps, makeColorBar, makePaintballKey, RawScalarField, RawVectorField, RawProfileField, Grid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, initAutumnPlot };
|
|
31
|
+
export { PlotComponent, Barbs, Contour, ContourLabels, ContourFill, Raster, Paintball, Hodographs, PlotLayer, MultiPlotLayer, ColorMap, colormaps, makeColorBar, makePaintballKey, Color, RawScalarField, RawVectorField, RawProfileField, Grid, PlateCarreeGrid, PlateCarreeRotatedGrid, LambertGrid, initAutumnPlot };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
declare const hex2rgba: (hexstr: string, out_type?: string) => [number, number, number, number];
|
|
2
|
-
declare const rgba2hex: (rgba: [number, number, number, number], in_type?: string) => string;
|
|
3
|
-
declare const hex2rgb: (hexstr: string, out_type?: string) => [number, number, number];
|
|
4
|
-
declare const rgb2hex: (rgb: [number, number, number], in_type?: string) => string;
|
|
5
|
-
declare const rgb2hsv: (rgb: [number, number, number]) => [number, number, number];
|
|
6
|
-
declare const hsv2rgb: (hsv: [number, number, number]) => [number, number, number];
|
|
7
1
|
declare function getMinZoom(jlat: number, ilon: number, thin_fac_base: number): number;
|
|
8
2
|
declare function zip(...args: any[]): Generator<any[], void, unknown>;
|
|
9
|
-
declare function getOS(): string;
|
|
3
|
+
declare function getOS(): string | null;
|
|
10
4
|
declare class Cache<A extends unknown[], R> {
|
|
11
5
|
private cached_values;
|
|
12
6
|
private readonly compute_value;
|
|
@@ -15,4 +9,4 @@ declare class Cache<A extends unknown[], R> {
|
|
|
15
9
|
getValue(...args: A): R;
|
|
16
10
|
}
|
|
17
11
|
declare function normalizeOptions<Type extends Record<string, any>>(opts: Type | undefined, defaults: Required<Type>): Required<Type>;
|
|
18
|
-
export {
|
|
12
|
+
export { zip, getMinZoom, getOS, Cache, normalizeOptions };
|
package/lib/utils.js
CHANGED
|
@@ -1,85 +1,3 @@
|
|
|
1
|
-
const hex2rgba = (hexstr, out_type) => {
|
|
2
|
-
out_type = out_type === undefined ? 'float' : out_type;
|
|
3
|
-
const match = hexstr.match(/#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?/i);
|
|
4
|
-
if (match === null) {
|
|
5
|
-
throw `Got '${hexstr}' in hex2rgba, which does not look like a hex color`;
|
|
6
|
-
}
|
|
7
|
-
let rgba = match.slice(1).filter(c => c !== undefined).map(c => parseInt(c, 16));
|
|
8
|
-
if (out_type == 'float') {
|
|
9
|
-
rgba = rgba.map(c => c / 255);
|
|
10
|
-
}
|
|
11
|
-
return rgba[3] === undefined ? [rgba[0], rgba[1], rgba[2], 1] : [rgba[0], rgba[1], rgba[2], rgba[3]];
|
|
12
|
-
};
|
|
13
|
-
const rgba2hex = (rgba, in_type) => {
|
|
14
|
-
in_type = in_type === undefined ? 'float' : in_type;
|
|
15
|
-
let rgba_ = rgba;
|
|
16
|
-
if (in_type == 'float') {
|
|
17
|
-
rgba_ = rgba_.map(c => Math.round(c * 255));
|
|
18
|
-
}
|
|
19
|
-
return '#' + rgba_.map(c => c.toString(16).padStart(2, '0').toUpperCase()).join('');
|
|
20
|
-
};
|
|
21
|
-
const hex2rgb = (hexstr, out_type) => {
|
|
22
|
-
const [r, g, b, a] = hex2rgba(hexstr, out_type);
|
|
23
|
-
return [r, g, b];
|
|
24
|
-
};
|
|
25
|
-
const rgb2hex = (rgb, in_type) => {
|
|
26
|
-
const [r, g, b] = rgb;
|
|
27
|
-
return rgba2hex([r, g, b, 0], in_type).slice(0, -2);
|
|
28
|
-
};
|
|
29
|
-
const rgb2hsv = (rgb) => {
|
|
30
|
-
const [r, g, b] = rgb;
|
|
31
|
-
const Cmax = Math.max(r, g, b);
|
|
32
|
-
const Cmin = Math.min(r, g, b);
|
|
33
|
-
const Delta = Cmax - Cmin;
|
|
34
|
-
let H;
|
|
35
|
-
if (Delta == 0) {
|
|
36
|
-
H = 0;
|
|
37
|
-
}
|
|
38
|
-
else if (Cmax == r) {
|
|
39
|
-
H = 60 * ((g - b) / Delta) % 6;
|
|
40
|
-
}
|
|
41
|
-
else if (Cmax == g) {
|
|
42
|
-
H = 60 * ((b - r) / Delta + 2);
|
|
43
|
-
}
|
|
44
|
-
else if (Cmax == b) {
|
|
45
|
-
H = 60 * ((r - g) / Delta + 4);
|
|
46
|
-
}
|
|
47
|
-
let S = Cmax == 0 ? 0 : Delta / Cmax;
|
|
48
|
-
let V = Cmax;
|
|
49
|
-
return [H, S, V];
|
|
50
|
-
};
|
|
51
|
-
const hsv2rgb = (hsv) => {
|
|
52
|
-
const [H, S, V] = hsv;
|
|
53
|
-
const C = V * S;
|
|
54
|
-
const X = C * (1 - Math.abs(H / 60 % 2 - 1));
|
|
55
|
-
const m = V - C;
|
|
56
|
-
let r_prime, g_prime, b_prime;
|
|
57
|
-
if (0 <= H && H < 60) {
|
|
58
|
-
r_prime = C;
|
|
59
|
-
g_prime = X, b_prime = 0;
|
|
60
|
-
}
|
|
61
|
-
else if (60 <= H && H < 120) {
|
|
62
|
-
r_prime = X;
|
|
63
|
-
g_prime = C, b_prime = 0;
|
|
64
|
-
}
|
|
65
|
-
else if (120 <= H && H < 180) {
|
|
66
|
-
r_prime = 0;
|
|
67
|
-
g_prime = C, b_prime = X;
|
|
68
|
-
}
|
|
69
|
-
else if (180 <= H && H < 240) {
|
|
70
|
-
r_prime = 0;
|
|
71
|
-
g_prime = X, b_prime = C;
|
|
72
|
-
}
|
|
73
|
-
else if (240 <= H && H < 300) {
|
|
74
|
-
r_prime = X;
|
|
75
|
-
g_prime = 0, b_prime = C;
|
|
76
|
-
}
|
|
77
|
-
else if (300 <= H && H < 360) {
|
|
78
|
-
r_prime = C;
|
|
79
|
-
g_prime = 0, b_prime = X;
|
|
80
|
-
}
|
|
81
|
-
return [r_prime + m, g_prime + m, b_prime + m];
|
|
82
|
-
};
|
|
83
1
|
function getMinZoom(jlat, ilon, thin_fac_base) {
|
|
84
2
|
const zoom_base = 1;
|
|
85
3
|
let zoom = zoom_base;
|
|
@@ -143,4 +61,4 @@ function normalizeOptions(opts, defaults) {
|
|
|
143
61
|
}
|
|
144
62
|
return ret;
|
|
145
63
|
}
|
|
146
|
-
export {
|
|
64
|
+
export { zip, getMinZoom, getOS, Cache, normalizeOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autumnplot-gl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@petamoriken/float16": "^3.8.4",
|
|
37
|
-
"autumn-wgl": "^1.4.
|
|
37
|
+
"autumn-wgl": "^1.4.1",
|
|
38
38
|
"comlink": "^4.3.1",
|
|
39
39
|
"kd-tree-javascript": "^1.0.3",
|
|
40
40
|
"pbf": "^3.2.1",
|