@metoceanapi/wxtiles-common 0.0.8 → 0.0.11
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.txt +1 -1
- package/biome.json +12 -0
- package/controls/WxAPIControl/WxAPIControl-busy.ts +16 -0
- package/controls/WxAPIControl/WxAPIControl-datasets.ts +102 -0
- package/controls/WxAPIControl/WxAPIControl-filter.ts +66 -0
- package/controls/WxAPIControl/WxAPIControl-variables.ts +73 -0
- package/controls/WxAPIControl.ts +91 -120
- package/controls/WxInfoControl.ts +87 -2
- package/controls/WxLegendControl.ts +28 -2
- package/controls/WxStyleEditorControl.ts +123 -6
- package/controls/WxTimeControl.ts +132 -4
- package/docs/docs/.nojekyll +1 -0
- package/docs/docs/assets/highlight.css +92 -0
- package/docs/docs/assets/icons.svg +1 -0
- package/docs/docs/assets/style.css +1610 -0
- package/docs/docs/classes/controls_WxAPIControl.WxAPIControl.html +28 -0
- package/docs/docs/classes/controls_WxInfoControl.WxInfoControl.html +20 -0
- package/docs/docs/classes/controls_WxLegendControl.WxLegendControl.html +19 -0
- package/docs/docs/classes/controls_WxStyleEditorControl.WxStyleEditorControl.html +111 -0
- package/docs/docs/classes/controls_WxTimeControl.WxTimeControl.html +28 -0
- package/docs/docs/classes/managers_BaseDatasetManager.BaseDatasetManager.html +104 -0
- package/docs/docs/classes/managers_WxAllDatasetsManager.WxAllDatasetsManager.html +24 -0
- package/docs/docs/classes/types.WxRasterDataCache.html +27 -0
- package/docs/docs/classes/utils_RawCLUT.RawCLUT.html +18 -0
- package/docs/docs/classes/utils_qtree.QTree.html +22 -0
- package/docs/docs/classes/utils_wxtools.DataIntegral.html +10 -0
- package/docs/docs/classes/wxapi.WxAPI.html +45 -0
- package/docs/docs/classes/wxlayer_loader.Loader.html +31 -0
- package/docs/docs/classes/wxlayer_painter.Painter.html +20 -0
- package/docs/docs/classes/wxlayer_wxlayer.WxLayer.html +57 -0
- package/docs/docs/enums/utils_qtree.TileType.html +5 -0
- package/docs/docs/functions/utils_RawCLUT.WxCreateLegend.html +5 -0
- package/docs/docs/functions/utils_mercator.LatLonToPixels.html +6 -0
- package/docs/docs/functions/utils_mercator.PixelsToLatLon.html +6 -0
- package/docs/docs/functions/utils_mercator.PixelsToLonLat.html +6 -0
- package/docs/docs/functions/utils_mercator.coordToPixel.html +5 -0
- package/docs/docs/functions/utils_tests_wxtools.tests.html +1 -0
- package/docs/docs/functions/utils_wxtools.HEXtoRGBA.html +3 -0
- package/docs/docs/functions/utils_wxtools.HashXYZ.html +4 -0
- package/docs/docs/functions/utils_wxtools.RGBAtoHEX.html +3 -0
- package/docs/docs/functions/utils_wxtools.RGBtoHEX.html +3 -0
- package/docs/docs/functions/utils_wxtools.WXLOG.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxGetColorSchemes.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxGetColorStyles.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxTilesLibSetup.html +3 -0
- package/docs/docs/functions/utils_wxtools.WxTilesLogging.html +5 -0
- package/docs/docs/functions/utils_wxtools.blurData.html +7 -0
- package/docs/docs/functions/utils_wxtools.buildIntegralPare.html +6 -0
- package/docs/docs/functions/utils_wxtools.cacheUriPromise.html +2 -0
- package/docs/docs/functions/utils_wxtools.create2DContext.html +6 -0
- package/docs/docs/functions/utils_wxtools.createEl.html +5 -0
- package/docs/docs/functions/utils_wxtools.createLevels.html +6 -0
- package/docs/docs/functions/utils_wxtools.fetchJson.html +6 -0
- package/docs/docs/functions/utils_wxtools.getClosestTimeString.html +5 -0
- package/docs/docs/functions/utils_wxtools.loadDataIntegral.html +5 -0
- package/docs/docs/functions/utils_wxtools.loadImage.html +4 -0
- package/docs/docs/functions/utils_wxtools.loadImageData.html +5 -0
- package/docs/docs/functions/utils_wxtools.makeConverter.html +9 -0
- package/docs/docs/functions/utils_wxtools.mixColor.html +3 -0
- package/docs/docs/functions/utils_wxtools.refineColor.html +3 -0
- package/docs/docs/functions/utils_wxtools.uriXYZ.html +5 -0
- package/docs/docs/functions/wxlayer_WxImplementation.WxLayerBaseImplementationMixin.html +4 -0
- package/docs/docs/functions/wxlayer_loadertools.applyMask.html +10 -0
- package/docs/docs/functions/wxlayer_loadertools.makeBox.html +4 -0
- package/docs/docs/functions/wxlayer_loadertools.splitCoords.html +6 -0
- package/docs/docs/functions/wxlayer_loadertools.subData.html +5 -0
- package/docs/docs/functions/wxlayer_loadertools.subDataDegree.html +5 -0
- package/docs/docs/functions/wxlayer_loadertools.subMask.html +5 -0
- package/docs/docs/hierarchy.html +1 -0
- package/docs/docs/index.html +7 -0
- package/docs/docs/interfaces/types.IsoInfo.html +8 -0
- package/docs/docs/interfaces/types.SLinePoint.html +4 -0
- package/docs/docs/interfaces/types.WxAPIOptions.html +37 -0
- package/docs/docs/interfaces/types.WxAllBoundariesMeta.html +8 -0
- package/docs/docs/interfaces/types.WxAllDatasetsShortMetas.html +4 -0
- package/docs/docs/interfaces/types.WxBoundaryMeta.html +10 -0
- package/docs/docs/interfaces/types.WxData.html +10 -0
- package/docs/docs/interfaces/types.WxDataSetManagerOptions.html +14 -0
- package/docs/docs/interfaces/types.WxDatasetMeta.html +20 -0
- package/docs/docs/interfaces/types.WxDatasetShortMeta.html +9 -0
- package/docs/docs/interfaces/types.WxLayerAPI.html +24 -0
- package/docs/docs/interfaces/types.WxLayerBaseAPI.html +16 -0
- package/docs/docs/interfaces/types.WxLayerOptions.html +12 -0
- package/docs/docs/interfaces/types.WxLngLat.html +6 -0
- package/docs/docs/interfaces/types.WxRasterData.html +13 -0
- package/docs/docs/interfaces/types.WxRequestInit.html +3 -0
- package/docs/docs/interfaces/types.WxTileInfo.html +18 -0
- package/docs/docs/interfaces/types.WxVariableMeta.html +13 -0
- package/docs/docs/interfaces/types.WxVariablesMetas.html +4 -0
- package/docs/docs/interfaces/utils_RawCLUT.WxLegend.html +14 -0
- package/docs/docs/interfaces/utils_RawCLUT.WxTick.html +10 -0
- package/docs/docs/interfaces/utils_qtree.Tree.html +7 -0
- package/docs/docs/interfaces/utils_wxtools.CachedUriLoaderPromiseFunc.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.ColorStylesIncomplete.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.Converter.html +5 -0
- package/docs/docs/interfaces/utils_wxtools.DataPicture.html +6 -0
- package/docs/docs/interfaces/utils_wxtools.IntegralPare.html +6 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorSchemes.html +3 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStyleStrict.html +95 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStyleWeak.html +95 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStylesStrict.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStylesWeakMixed.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.WxTilesLibOptions.html +8 -0
- package/docs/docs/interfaces/utils_wxtools.WxUnits.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.XYZ.html +5 -0
- package/docs/docs/modules/controls_WxAPIControl.html +1 -0
- package/docs/docs/modules/controls_WxInfoControl.html +1 -0
- package/docs/docs/modules/controls_WxLegendControl.html +1 -0
- package/docs/docs/modules/controls_WxStyleEditorControl.html +1 -0
- package/docs/docs/modules/controls_WxTimeControl.html +1 -0
- package/docs/docs/modules/defaults_colorschemes.html +1 -0
- package/docs/docs/modules/defaults_styles.html +1 -0
- package/docs/docs/modules/defaults_uconv.html +1 -0
- package/docs/docs/modules/managers_BaseDatasetManager.html +1 -0
- package/docs/docs/modules/managers_WxAllDatasetsManager.html +1 -0
- package/docs/docs/modules/types.html +1 -0
- package/docs/docs/modules/utils_RawCLUT.html +1 -0
- package/docs/docs/modules/utils_mercator.html +1 -0
- package/docs/docs/modules/utils_qtree.html +1 -0
- package/docs/docs/modules/utils_tests_wxtools.html +1 -0
- package/docs/docs/modules/utils_wxtools.html +1 -0
- package/docs/docs/modules/wxapi.html +1 -0
- package/docs/docs/modules/wxlayer_WxImplementation.html +1 -0
- package/docs/docs/modules/wxlayer_loader.html +1 -0
- package/docs/docs/modules/wxlayer_loadertools.html +1 -0
- package/docs/docs/modules/wxlayer_painter.html +1 -0
- package/docs/docs/modules/wxlayer_wxlayer.html +1 -0
- package/docs/docs/modules.html +1 -0
- package/docs/docs/types/types.ListenerMethod.html +1 -0
- package/docs/docs/types/types.SLine.html +2 -0
- package/docs/docs/types/types.WxDate.html +9 -0
- package/docs/docs/types/types.WxEventType.html +1 -0
- package/docs/docs/types/types.WxInstances.html +2 -0
- package/docs/docs/types/types.WxLayerVarsNames.html +2 -0
- package/docs/docs/types/types.WxURIs.html +2 -0
- package/docs/docs/types/utils_qtree.SubTrees.html +2 -0
- package/docs/docs/types/utils_qtree.SubTreesN.html +2 -0
- package/docs/docs/types/utils_qtree.TreeN.html +2 -0
- package/docs/docs/types/utils_wxtools.DataIntegrals.html +2 -0
- package/docs/docs/types/utils_wxtools.DataPictures.html +2 -0
- package/docs/docs/types/utils_wxtools.WxUnitTuple.html +2 -0
- package/docs/docs/types/utils_wxtools.colorMapTuple.html +2 -0
- package/docs/docs/variables/defaults_colorschemes.__colorSchemes_default_preset.html +1 -0
- package/docs/docs/variables/defaults_styles.__colorStyles_default_preset.html +1 -0
- package/docs/docs/variables/defaults_uconv.__units_default_preset.html +1 -0
- package/managers/BaseDatasetManager.ts +274 -0
- package/managers/WxAllDatasetsManager.ts +60 -0
- package/package.json +6 -3
- package/tsconfig.json +19 -0
- package/typedoc.json +4 -0
- package/types.ts +471 -0
- package/wxapi.ts +223 -0
- package/wxlayer/WxImplementation.ts +372 -0
- package/wxlayer/loader.ts +305 -0
- package/wxlayer/loadertools.ts +380 -0
- package/wxlayer/painter.ts +451 -0
- package/wxlayer/wxlayer.ts +379 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DataPicture,
|
|
3
|
+
type DataPictures,
|
|
4
|
+
HEXtoRGBA,
|
|
5
|
+
RGBtoHEX,
|
|
6
|
+
refineColor,
|
|
7
|
+
} from "../utils/wxtools";
|
|
8
|
+
import type { WxData, IsoInfo, WxRasterData } from "../types";
|
|
9
|
+
import type { WxLayer } from "./wxlayer";
|
|
10
|
+
import type { BaseDatasetManager } from "../managers/BaseDatasetManager";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Class for rendering a single tile.
|
|
14
|
+
* Do not create manually
|
|
15
|
+
* */
|
|
16
|
+
export class Painter<WxDatasetManagerT extends BaseDatasetManager> {
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
* {@link WxLayer} - parent layer
|
|
20
|
+
* */
|
|
21
|
+
protected _layer: WxLayer<WxDatasetManagerT>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
* Do not use constructor directly
|
|
26
|
+
* */
|
|
27
|
+
constructor(layer: WxLayer<WxDatasetManagerT>) {
|
|
28
|
+
this._layer = layer;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Renders the tile using the provided data into the specified contexts.
|
|
33
|
+
*
|
|
34
|
+
* @param data - WxRasterData object containing the necessary contexts and data.
|
|
35
|
+
*/
|
|
36
|
+
paint({ data, ctxFill, ctxText, ctxStreamLines }: WxRasterData): void {
|
|
37
|
+
const { _layer: layer } = this;
|
|
38
|
+
const { units } = layer.currentVariableMeta;
|
|
39
|
+
const imageData = new ImageData(256, 256); //new ImageData(256, 256);
|
|
40
|
+
const imageBuffer = new Uint32Array(imageData.data.buffer); // a usefull representation of image's bytes (same memory)
|
|
41
|
+
ctxFill.clearRect(0, 0, 256, 256);
|
|
42
|
+
ctxText.clearRect(0, 0, 256, 256);
|
|
43
|
+
ctxStreamLines.clearRect(0, 0, 256, 256);
|
|
44
|
+
|
|
45
|
+
_fill(data.data[0], imageBuffer, layer);
|
|
46
|
+
const isoInfo = _drawIsolines(imageBuffer, data.data[0], layer);
|
|
47
|
+
ctxFill.putImageData(imageData, 0, 0);
|
|
48
|
+
_printIsolineText(isoInfo, ctxText, layer);
|
|
49
|
+
_printVectorsStatic(data.data, ctxText, layer);
|
|
50
|
+
_printDegreesStatic(data.data[0], ctxText, units, layer);
|
|
51
|
+
_drawStreamLinesStatic(data, ctxText, layer);
|
|
52
|
+
} // paint
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns the canvas corresponding to the rendered tile.
|
|
56
|
+
* If animation is enabled, the streamlines context is used.
|
|
57
|
+
*
|
|
58
|
+
* @param data - WxRasterData object containing the contexts.
|
|
59
|
+
* @param animation - Boolean flag to enable animation.
|
|
60
|
+
* @param seed - Time seed for animation frames.
|
|
61
|
+
*/
|
|
62
|
+
getPaintedCanvas(
|
|
63
|
+
data: WxRasterData,
|
|
64
|
+
animation: boolean,
|
|
65
|
+
seed: number,
|
|
66
|
+
): HTMLCanvasElement {
|
|
67
|
+
if (animation) {
|
|
68
|
+
this.imprintVectorAnimationLinesStep(data, seed);
|
|
69
|
+
return data.ctxStreamLines.canvas;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return data.ctxFill.canvas;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Renders animated streamlines for a single tile with the provided time seed.
|
|
77
|
+
*
|
|
78
|
+
* @param data - WxRasterData object containing the contexts.
|
|
79
|
+
* @param seed - Time seed for animation frames.
|
|
80
|
+
*/
|
|
81
|
+
imprintVectorAnimationLinesStep(
|
|
82
|
+
{ data, ctxFill, ctxStreamLines }: WxRasterData,
|
|
83
|
+
seed: number,
|
|
84
|
+
): void {
|
|
85
|
+
const { _layer: layer } = this;
|
|
86
|
+
ctxStreamLines.clearRect(0, 0, 256, 256);
|
|
87
|
+
ctxStreamLines.drawImage(ctxFill.canvas, 0, 0);
|
|
88
|
+
if (
|
|
89
|
+
data.slines.length === 0 ||
|
|
90
|
+
layer.style.streamLineStatic ||
|
|
91
|
+
layer.style.streamLineColor === "none"
|
|
92
|
+
)
|
|
93
|
+
return;
|
|
94
|
+
_drawVectorAnimationLinesStep(data, ctxStreamLines, layer, seed);
|
|
95
|
+
} // imprintVectorAnimationLinesStep
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Fills the background with colors from the CLUT (Color Look-Up Table) */
|
|
99
|
+
function _fill<WxDatasetManagerT extends BaseDatasetManager>(
|
|
100
|
+
data: DataPicture,
|
|
101
|
+
imageBuffer: Uint32Array,
|
|
102
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
103
|
+
) {
|
|
104
|
+
const { raw } = data; // scalar data
|
|
105
|
+
const { colorsI } = CLUT;
|
|
106
|
+
// fill: none, gradient, solid
|
|
107
|
+
if (style.fill !== "none") {
|
|
108
|
+
for (let y = 0, i = 0, di = 259; y < 256; ++y, di += 2) {
|
|
109
|
+
for (let x = 0; x < 256; ++x, ++i, ++di) {
|
|
110
|
+
imageBuffer[i] = colorsI[raw[di]];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
imageBuffer.fill(0);
|
|
115
|
+
}
|
|
116
|
+
} // _fill
|
|
117
|
+
|
|
118
|
+
/** Draws isolines and returns related information. */
|
|
119
|
+
function _drawIsolines<WxDatasetManagerT extends BaseDatasetManager>(
|
|
120
|
+
imageBuffer: Uint32Array,
|
|
121
|
+
data: DataPicture,
|
|
122
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
123
|
+
): IsoInfo[] {
|
|
124
|
+
const { raw } = data; // scalar data
|
|
125
|
+
const { levelIndex, colorsI } = CLUT;
|
|
126
|
+
const info: IsoInfo[] = []; // numbers on isolines
|
|
127
|
+
if (style.isolineColor !== "none") {
|
|
128
|
+
const flatColor =
|
|
129
|
+
style.isolineColor[0] === "#" ? HEXtoRGBA(style.isolineColor) : 0;
|
|
130
|
+
for (let y = 0, t = 0; y < 256; y += 1) {
|
|
131
|
+
for (let x = 0; x < 256; x += 1) {
|
|
132
|
+
const i = (y + 1) * 258 + (x + 1);
|
|
133
|
+
const d = raw[i]; // central data
|
|
134
|
+
const dr = raw[i + 1]; // right
|
|
135
|
+
const db = raw[i + 258]; // bottom
|
|
136
|
+
if (!d || !dr || !db) continue; // do not check isoline for NaN pixels (0)
|
|
137
|
+
|
|
138
|
+
const lic = levelIndex[d]; // check level index aroud the current pixel
|
|
139
|
+
const lir = levelIndex[dr]; // check level index aroud the current pixel
|
|
140
|
+
const lib = levelIndex[db]; // check level index aroud the current pixel
|
|
141
|
+
if (lic !== lir || lic !== lib) {
|
|
142
|
+
const mli = Math.max(lic, lir, lib); // max level index out of three possible
|
|
143
|
+
const md = Math.max(d, dr, db); // max data index out of three possible
|
|
144
|
+
const ii = y * 256 + x;
|
|
145
|
+
switch (style.isolineColor) {
|
|
146
|
+
case "inverted":
|
|
147
|
+
imageBuffer[ii] = ~colorsI[md] | 0xff000000; // invert color and make alfa = 255
|
|
148
|
+
break;
|
|
149
|
+
case "fill":
|
|
150
|
+
imageBuffer[ii] = colorsI[md] | 0xff000000; // make alfa = 255
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
imageBuffer[ii] = flatColor;
|
|
154
|
+
break;
|
|
155
|
+
} // switch isoline_style
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
style.isolineText &&
|
|
159
|
+
!(++t % 255) &&
|
|
160
|
+
x > 20 &&
|
|
161
|
+
x < 235 &&
|
|
162
|
+
y > 20 &&
|
|
163
|
+
y < 235
|
|
164
|
+
) {
|
|
165
|
+
info.push({ x, y, d, dr, db, mli });
|
|
166
|
+
}
|
|
167
|
+
} // if isoline
|
|
168
|
+
} // for x
|
|
169
|
+
} // for y
|
|
170
|
+
} // if (style.isolineColor != 'none')
|
|
171
|
+
|
|
172
|
+
return info;
|
|
173
|
+
} // _drawIsolines
|
|
174
|
+
|
|
175
|
+
/** Prints isoline text annotations on the canvas. */
|
|
176
|
+
function _printIsolineText<WxDatasetManagerT extends BaseDatasetManager>(
|
|
177
|
+
info: IsoInfo[],
|
|
178
|
+
ctx: CanvasRenderingContext2D,
|
|
179
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
180
|
+
): void {
|
|
181
|
+
// drawing Info
|
|
182
|
+
if (info.length) {
|
|
183
|
+
const ems = style.isolineTextSizeEm || 1.1;
|
|
184
|
+
ctx.font = `${ems.toString()}em Sans-serif`;
|
|
185
|
+
ctx.lineWidth = 2;
|
|
186
|
+
ctx.strokeStyle = "white"; // RGBtoHEX(p.c); // alfa = 255
|
|
187
|
+
ctx.fillStyle = "black";
|
|
188
|
+
ctx.textAlign = "center";
|
|
189
|
+
ctx.textBaseline = "middle";
|
|
190
|
+
|
|
191
|
+
const baseMetrics = ctx.measureText("-.0123456789");
|
|
192
|
+
const textHeight =
|
|
193
|
+
baseMetrics.actualBoundingBoxAscent +
|
|
194
|
+
baseMetrics.actualBoundingBoxDescent;
|
|
195
|
+
const hScale = 1.5;
|
|
196
|
+
const height = hScale * textHeight;
|
|
197
|
+
const hOffset =
|
|
198
|
+
baseMetrics.actualBoundingBoxAscent + (height - textHeight) / 2;
|
|
199
|
+
const wScale = 1.1;
|
|
200
|
+
const radii = ems * 2.5;
|
|
201
|
+
const printIsolineTextSurround =
|
|
202
|
+
style.isolineTextBackground || false
|
|
203
|
+
? _printIsolineTextWithStroke
|
|
204
|
+
: _printIsolineTextBackground;
|
|
205
|
+
|
|
206
|
+
for (const { x, y, d, dr, db, mli } of info) {
|
|
207
|
+
const angle = Math.atan2(d - dr, db - d); // rotate angle: we can use RAW d, dd, and dr for atan2!
|
|
208
|
+
ctx.save();
|
|
209
|
+
ctx.translate(x, y);
|
|
210
|
+
ctx.rotate(angle < -1.57 || angle > 1.57 ? angle + 3.14 : angle); // so text is always up side up
|
|
211
|
+
const val = CLUT.ticks[mli].dataString; // select value from levels/colorMap
|
|
212
|
+
printIsolineTextSurround(val, ctx, { height, hOffset, wScale, radii });
|
|
213
|
+
ctx.fillText(val, 0, 0);
|
|
214
|
+
ctx.restore();
|
|
215
|
+
}
|
|
216
|
+
} // if info.length
|
|
217
|
+
} // _printIsolineText
|
|
218
|
+
|
|
219
|
+
/** Draws isoline text background with rounded rectangles. */
|
|
220
|
+
function _printIsolineTextWithStroke(
|
|
221
|
+
val: string,
|
|
222
|
+
ctx: CanvasRenderingContext2D,
|
|
223
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
224
|
+
z: any,
|
|
225
|
+
): void {
|
|
226
|
+
ctx.strokeText(val, 0, 0);
|
|
227
|
+
} // _printIsolineTextWithStroke
|
|
228
|
+
|
|
229
|
+
/** Draws isoline text background with rounded rectangles. */
|
|
230
|
+
function _printIsolineTextBackground(
|
|
231
|
+
val: string,
|
|
232
|
+
ctx: CanvasRenderingContext2D,
|
|
233
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
234
|
+
{ height, hOffset, wScale, radii }: any,
|
|
235
|
+
): void {
|
|
236
|
+
const prevFill = ctx.fillStyle;
|
|
237
|
+
ctx.fillStyle = ctx.strokeStyle;
|
|
238
|
+
const width = wScale * ctx.measureText(val).width;
|
|
239
|
+
ctx.beginPath();
|
|
240
|
+
ctx.roundRect(-width / 2, -hOffset, width, height, radii);
|
|
241
|
+
ctx.closePath();
|
|
242
|
+
ctx.fill();
|
|
243
|
+
ctx.fillStyle = prevFill;
|
|
244
|
+
} // _printIsolineTextBackground
|
|
245
|
+
|
|
246
|
+
/** Prints vector field representations on the canvas. */
|
|
247
|
+
function _printVectorsStatic<WxDatasetManagerT extends BaseDatasetManager>(
|
|
248
|
+
data: DataPictures,
|
|
249
|
+
ctx: CanvasRenderingContext2D,
|
|
250
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
251
|
+
): void {
|
|
252
|
+
if (
|
|
253
|
+
!CLUT.DataToKnots ||
|
|
254
|
+
style.vectorColor === "none" ||
|
|
255
|
+
style.vectorType === "none"
|
|
256
|
+
)
|
|
257
|
+
return;
|
|
258
|
+
if (data.length !== 3) throw new Error("data.length !== 3");
|
|
259
|
+
const [l, u, v] = data;
|
|
260
|
+
|
|
261
|
+
switch (style.vectorType) {
|
|
262
|
+
case "barbs":
|
|
263
|
+
ctx.font = "40px barbs";
|
|
264
|
+
break;
|
|
265
|
+
case "arrows":
|
|
266
|
+
ctx.font = "50px arrows";
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
ctx.font = style.vectorType;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
ctx.textAlign = "center";
|
|
273
|
+
ctx.textBaseline = "middle";
|
|
274
|
+
ctx.fillStyle = style.vectorColor;
|
|
275
|
+
|
|
276
|
+
const addDegrees = style.addDegrees
|
|
277
|
+
? 0.017453292519943 * style.addDegrees
|
|
278
|
+
: 0;
|
|
279
|
+
|
|
280
|
+
const gridStep = 32; //Math.min(2 ** (zdif + 5), 128);
|
|
281
|
+
for (let y = gridStep / 2; y < 256; y += gridStep) {
|
|
282
|
+
for (let x = gridStep / 2; x < 256; x += gridStep) {
|
|
283
|
+
const di = x + 1 + (y + 1) * 258;
|
|
284
|
+
if (!l.raw[di]) continue; // NODATA
|
|
285
|
+
|
|
286
|
+
const ang = Math.atan2(
|
|
287
|
+
u.dmin + u.raw[di] * u.dmul,
|
|
288
|
+
v.dmin + v.raw[di] * v.dmul,
|
|
289
|
+
);
|
|
290
|
+
const vecLen = l.dmin + l.raw[di] * l.dmul;
|
|
291
|
+
const sm =
|
|
292
|
+
style.vectorType !== "barbs"
|
|
293
|
+
? style.vectorFactor * 0.5
|
|
294
|
+
: 0.2; /*0.2 to fit font*/
|
|
295
|
+
const vecCode =
|
|
296
|
+
Math.min(~~(CLUT.DataToKnots(vecLen) * sm), 25 /* to fit .ttf */) +
|
|
297
|
+
65; /* A */
|
|
298
|
+
const vecChar = String.fromCharCode(vecCode);
|
|
299
|
+
switch (style.vectorColor) {
|
|
300
|
+
case "inverted":
|
|
301
|
+
ctx.fillStyle = RGBtoHEX(~CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
302
|
+
break;
|
|
303
|
+
case "fill":
|
|
304
|
+
ctx.fillStyle = RGBtoHEX(CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
305
|
+
break;
|
|
306
|
+
} // switch isoline_style
|
|
307
|
+
|
|
308
|
+
ctx.save();
|
|
309
|
+
ctx.translate(x, y);
|
|
310
|
+
ctx.rotate(ang + addDegrees);
|
|
311
|
+
ctx.fillText(vecChar, 0, 0);
|
|
312
|
+
ctx.restore();
|
|
313
|
+
} // for x
|
|
314
|
+
} // for y
|
|
315
|
+
} // _printVectorsStatic
|
|
316
|
+
|
|
317
|
+
/** Prints degrees with static text annotations on the canvas. */
|
|
318
|
+
function _printDegreesStatic<WxDatasetManagerT extends BaseDatasetManager>(
|
|
319
|
+
data: DataPicture,
|
|
320
|
+
ctx: CanvasRenderingContext2D,
|
|
321
|
+
units: string,
|
|
322
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
323
|
+
): void {
|
|
324
|
+
if (units !== "degree") return;
|
|
325
|
+
const addDegrees = 0.017453292519943 * style.addDegrees;
|
|
326
|
+
|
|
327
|
+
ctx.font = "50px arrows";
|
|
328
|
+
ctx.textAlign = "center";
|
|
329
|
+
ctx.textBaseline = "middle";
|
|
330
|
+
ctx.fillStyle = style.vectorColor;
|
|
331
|
+
const vecChar = "L";
|
|
332
|
+
|
|
333
|
+
const gridStep = 32; //Math.min(2 ** (zdif + 5), 128);
|
|
334
|
+
for (let y = gridStep / 2; y < 256; y += gridStep) {
|
|
335
|
+
for (let x = gridStep / 2; x < 256; x += gridStep) {
|
|
336
|
+
const di = x + 1 + (y + 1) * 258;
|
|
337
|
+
if (!data.raw[di]) continue; // NODATA
|
|
338
|
+
const angDeg = data.dmin + data.raw[di] * data.dmul + 180;
|
|
339
|
+
const ang = angDeg * 0.01745329251; // pi/180
|
|
340
|
+
switch (style.vectorColor) {
|
|
341
|
+
case "inverted":
|
|
342
|
+
ctx.fillStyle = RGBtoHEX(~CLUT.colorsI[data.raw[di]]); // alfa = 255
|
|
343
|
+
break;
|
|
344
|
+
case "fill":
|
|
345
|
+
ctx.fillStyle = RGBtoHEX(CLUT.colorsI[data.raw[di]]); // alfa = 255
|
|
346
|
+
break;
|
|
347
|
+
} // switch isoline_style
|
|
348
|
+
|
|
349
|
+
ctx.save();
|
|
350
|
+
ctx.translate(x, y);
|
|
351
|
+
ctx.rotate(ang + addDegrees);
|
|
352
|
+
ctx.fillText(vecChar, 0, 0);
|
|
353
|
+
ctx.restore();
|
|
354
|
+
} // for x
|
|
355
|
+
} // for y
|
|
356
|
+
} // _printDegreesStatic
|
|
357
|
+
|
|
358
|
+
/** Draws streamlines with static representations on the canvas. */
|
|
359
|
+
function _drawStreamLinesStatic<WxDatasetManagerT extends BaseDatasetManager>(
|
|
360
|
+
wxdata: WxData,
|
|
361
|
+
ctx: CanvasRenderingContext2D,
|
|
362
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
363
|
+
): void {
|
|
364
|
+
const { data, slines } = wxdata;
|
|
365
|
+
if (
|
|
366
|
+
!slines.length ||
|
|
367
|
+
!style.streamLineStatic ||
|
|
368
|
+
style.streamLineColor === "none"
|
|
369
|
+
)
|
|
370
|
+
return;
|
|
371
|
+
|
|
372
|
+
const l = data[0];
|
|
373
|
+
ctx.lineWidth = 1;
|
|
374
|
+
if (style.streamLineColor[0] === "#") {
|
|
375
|
+
ctx.strokeStyle = refineColor(style.streamLineColor);
|
|
376
|
+
}
|
|
377
|
+
for (let i = slines.length; i--; ) {
|
|
378
|
+
const sLine = slines[i];
|
|
379
|
+
for (let k = 0; k < sLine.length - 1; ++k) {
|
|
380
|
+
const p0 = sLine[k];
|
|
381
|
+
const p1 = sLine[k + 1];
|
|
382
|
+
const di = p0.x + 1 + (p0.y + 1) * 258;
|
|
383
|
+
|
|
384
|
+
switch (style.streamLineColor) {
|
|
385
|
+
case "inverted":
|
|
386
|
+
ctx.strokeStyle = RGBtoHEX(~CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
387
|
+
break;
|
|
388
|
+
case "fill":
|
|
389
|
+
ctx.strokeStyle = RGBtoHEX(CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
390
|
+
break;
|
|
391
|
+
} // switch isoline_style
|
|
392
|
+
|
|
393
|
+
ctx.beginPath();
|
|
394
|
+
ctx.moveTo(p0.x, p0.y);
|
|
395
|
+
ctx.lineTo(p1.x, p1.y);
|
|
396
|
+
ctx.stroke();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} // _drawStreamLinesStatic
|
|
400
|
+
|
|
401
|
+
/** Draws vector animation lines step by step based on time seed. */
|
|
402
|
+
function _drawVectorAnimationLinesStep<WxDatasetManagerT extends BaseDatasetManager>(
|
|
403
|
+
wxdata: WxData,
|
|
404
|
+
ctx: CanvasRenderingContext2D,
|
|
405
|
+
{ CLUT, style }: WxLayer<WxDatasetManagerT>,
|
|
406
|
+
seed_: number,
|
|
407
|
+
): void {
|
|
408
|
+
// 'seed_' is a time tick given by the browser's scheduller
|
|
409
|
+
const { data, slines } = wxdata;
|
|
410
|
+
// if (!slines.length || !style.streamLineStatic || style.streamLineColor === 'none') return; // done by the caller!!!
|
|
411
|
+
const l = data[0];
|
|
412
|
+
|
|
413
|
+
let baseColor =
|
|
414
|
+
style.streamLineColor[0] === "#"
|
|
415
|
+
? refineColor(style.streamLineColor).substring(0, 7)
|
|
416
|
+
: "#000000";
|
|
417
|
+
|
|
418
|
+
const seed = seed_ >> 5;
|
|
419
|
+
for (let i = 0; i < slines.length; ++i) {
|
|
420
|
+
const sLine = slines[i];
|
|
421
|
+
const sSize = sLine.length - 1;
|
|
422
|
+
// pseed - is the most opaque piece
|
|
423
|
+
const pseed = (seed + (1 + sLine[0].x) * (1 + sLine[0].y)) % 30;
|
|
424
|
+
for (let k = 0; k < sSize; ++k) {
|
|
425
|
+
const p0 = sLine[k];
|
|
426
|
+
const p1 = sLine[k + 1];
|
|
427
|
+
let t = 1 - (pseed - k) / sSize;
|
|
428
|
+
if (t < 0 || t > 1) t = 0;
|
|
429
|
+
const col = (~~(t * 255)).toString(16).padStart(2, "0");
|
|
430
|
+
const w = 1 + ~~((1.2 - t) * 5);
|
|
431
|
+
ctx.lineWidth = w;
|
|
432
|
+
|
|
433
|
+
const di = p0.x + 1 + (p0.y + 1) * 258;
|
|
434
|
+
switch (style.streamLineColor) {
|
|
435
|
+
case "inverted":
|
|
436
|
+
baseColor = RGBtoHEX(~CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
437
|
+
break;
|
|
438
|
+
case "fill":
|
|
439
|
+
baseColor = RGBtoHEX(CLUT.colorsI[l.raw[di]]); // alfa = 255
|
|
440
|
+
break;
|
|
441
|
+
} // switch isoline_style
|
|
442
|
+
|
|
443
|
+
ctx.strokeStyle = baseColor + col; //(col.length < 2 ? '0' + col : col);
|
|
444
|
+
|
|
445
|
+
ctx.beginPath();
|
|
446
|
+
ctx.moveTo(p0.x, p0.y);
|
|
447
|
+
ctx.lineTo(p1.x, p1.y);
|
|
448
|
+
ctx.stroke();
|
|
449
|
+
} // for k
|
|
450
|
+
} // for i
|
|
451
|
+
} // _drawVectorAnimationLinesStep
|