@equinor/esv-intersection 3.0.9 → 3.0.10
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/dist/components/axis.d.ts +1 -2
- package/dist/components/axis.d.ts.map +1 -1
- package/dist/control/ExtendedCurveInterpolator.d.ts.map +1 -1
- package/dist/control/IntersectionReferenceSystem.d.ts +2 -6
- package/dist/control/IntersectionReferenceSystem.d.ts.map +1 -1
- package/dist/control/LayerManager.d.ts +2 -2
- package/dist/control/LayerManager.d.ts.map +1 -1
- package/dist/control/MainController.d.ts +3 -3
- package/dist/control/MainController.d.ts.map +1 -1
- package/dist/control/ZoomPanHandler.d.ts +5 -4
- package/dist/control/ZoomPanHandler.d.ts.map +1 -1
- package/dist/control/interfaces.d.ts +3 -4
- package/dist/control/interfaces.d.ts.map +1 -1
- package/dist/control/overlay.d.ts +3 -3
- package/dist/control/overlay.d.ts.map +1 -1
- package/dist/datautils/colortable.d.ts +1 -1
- package/dist/datautils/colortable.d.ts.map +1 -1
- package/dist/datautils/findsample.d.ts.map +1 -1
- package/dist/datautils/schematicShapeGenerator.d.ts +3 -3
- package/dist/datautils/schematicShapeGenerator.d.ts.map +1 -1
- package/dist/datautils/seismicimage.d.ts.map +1 -1
- package/dist/datautils/trajectory.d.ts +1 -1
- package/dist/datautils/trajectory.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1373 -1272
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces.d.ts +1 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/layers/CalloutCanvasLayer.d.ts +2 -2
- package/dist/layers/CalloutCanvasLayer.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/ComplexRopeGeometry.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.d.ts.map +1 -1
- package/dist/layers/GeomodelCanvasLayer.d.ts +1 -1
- package/dist/layers/GeomodelCanvasLayer.d.ts.map +1 -1
- package/dist/layers/GeomodelLabelsLayer.d.ts +4 -4
- package/dist/layers/GeomodelLabelsLayer.d.ts.map +1 -1
- package/dist/layers/GeomodelLayerV2.d.ts.map +1 -1
- package/dist/layers/GridLayer.d.ts.map +1 -1
- package/dist/layers/ImageCanvasLayer.d.ts +1 -1
- package/dist/layers/ImageCanvasLayer.d.ts.map +1 -1
- package/dist/layers/ReferenceLineLayer.d.ts +1 -2
- package/dist/layers/ReferenceLineLayer.d.ts.map +1 -1
- package/dist/layers/SchematicLayer.d.ts.map +1 -1
- package/dist/layers/WellborePathLayer.d.ts +1 -1
- package/dist/layers/WellborePathLayer.d.ts.map +1 -1
- package/dist/layers/base/CanvasLayer.d.ts +3 -3
- package/dist/layers/base/CanvasLayer.d.ts.map +1 -1
- package/dist/layers/base/HTMLLayer.d.ts +1 -1
- package/dist/layers/base/HTMLLayer.d.ts.map +1 -1
- package/dist/layers/base/Layer.d.ts +10 -10
- package/dist/layers/base/Layer.d.ts.map +1 -1
- package/dist/layers/base/PixiLayer.d.ts +4 -4
- package/dist/layers/base/PixiLayer.d.ts.map +1 -1
- package/dist/layers/base/SVGLayer.d.ts +1 -1
- package/dist/layers/base/SVGLayer.d.ts.map +1 -1
- package/dist/utils/arc-length.d.ts.map +1 -1
- package/dist/utils/color.d.ts.map +1 -1
- package/dist/utils/root-finder.d.ts +1 -1
- package/dist/utils/root-finder.d.ts.map +1 -1
- package/dist/utils/text.d.ts +2 -2
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/vectorUtils.d.ts.map +1 -1
- package/dist/vendor/pixi-dashed-line/index.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/components/axis.ts +23 -30
- package/src/control/ExtendedCurveInterpolator.ts +7 -7
- package/src/control/IntersectionReferenceSystem.ts +33 -41
- package/src/control/LayerManager.ts +33 -31
- package/src/control/MainController.ts +5 -7
- package/src/control/ZoomPanHandler.ts +50 -45
- package/src/control/interfaces.ts +3 -3
- package/src/control/overlay.ts +20 -16
- package/src/datautils/colortable.ts +4 -4
- package/src/datautils/findsample.ts +8 -7
- package/src/datautils/picks.ts +13 -13
- package/src/datautils/schematicShapeGenerator.ts +47 -17
- package/src/datautils/seismicimage.ts +12 -13
- package/src/datautils/surfacedata.ts +27 -26
- package/src/datautils/trajectory.ts +34 -32
- package/src/interfaces.ts +1 -1
- package/src/layers/CalloutCanvasLayer.ts +55 -58
- package/src/layers/CustomDisplayObjects/ComplexRopeGeometry.ts +23 -20
- package/src/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.ts +9 -10
- package/src/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.ts +13 -13
- package/src/layers/GeomodelCanvasLayer.ts +43 -36
- package/src/layers/GeomodelLabelsLayer.ts +99 -96
- package/src/layers/GeomodelLayerV2.ts +11 -11
- package/src/layers/GridLayer.ts +25 -21
- package/src/layers/ImageCanvasLayer.ts +17 -11
- package/src/layers/ReferenceLineLayer.ts +53 -45
- package/src/layers/SchematicLayer.ts +78 -75
- package/src/layers/WellborePathLayer.ts +48 -46
- package/src/layers/base/CanvasLayer.ts +18 -18
- package/src/layers/base/HTMLLayer.ts +5 -5
- package/src/layers/base/Layer.ts +18 -18
- package/src/layers/base/PixiLayer.ts +24 -20
- package/src/layers/base/SVGLayer.ts +5 -5
- package/src/utils/arc-length.ts +3 -10
- package/src/utils/binary-search.ts +2 -2
- package/src/utils/color.ts +9 -5
- package/src/utils/root-finder.ts +4 -4
- package/src/utils/text.ts +5 -5
- package/src/utils/vectorUtils.ts +13 -6
- package/src/vendor/pixi-dashed-line/index.ts +3 -2
|
@@ -33,11 +33,11 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
33
33
|
defaultTextColor: string = DEFAULT_TEXT_COLOR;
|
|
34
34
|
defaultFont: string = DEFAULT_FONT;
|
|
35
35
|
|
|
36
|
-
rescaleEvent: OnRescaleEvent;
|
|
37
|
-
isLabelsOnLeftSide
|
|
36
|
+
rescaleEvent: OnRescaleEvent | undefined;
|
|
37
|
+
isLabelsOnLeftSide = true;
|
|
38
38
|
maxFontSizeInWorldCoordinates: number = MAX_FONT_SIZE_IN_WORLD_COORDINATES;
|
|
39
|
-
isXFlipped
|
|
40
|
-
areasWithAvgTopDepth: SurfaceAreaWithAvgTopDepth[] =
|
|
39
|
+
isXFlipped = false;
|
|
40
|
+
areasWithAvgTopDepth: SurfaceAreaWithAvgTopDepth[] = [];
|
|
41
41
|
|
|
42
42
|
constructor(id?: string, options?: GeomodelLayerLabelsOptions<T>) {
|
|
43
43
|
super(id, options);
|
|
@@ -54,11 +54,11 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
54
54
|
|
|
55
55
|
override setData(data: T): void {
|
|
56
56
|
super.setData(data);
|
|
57
|
-
this.areasWithAvgTopDepth =
|
|
57
|
+
this.areasWithAvgTopDepth = [];
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
generateSurfacesWithAvgDepth(): void {
|
|
61
|
-
const
|
|
61
|
+
const areas = this.data?.areas ?? [];
|
|
62
62
|
this.areasWithAvgTopDepth = areas.reduce((acc: SurfaceAreaWithAvgTopDepth[], area: SurfaceArea) => {
|
|
63
63
|
// Filter surfaces without label
|
|
64
64
|
if (!area.label) {
|
|
@@ -118,7 +118,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
if (
|
|
121
|
+
if (this.areasWithAvgTopDepth.length <= 0) {
|
|
122
122
|
this.generateSurfacesWithAvgDepth();
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -147,13 +147,15 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
drawLineLabels(): void {
|
|
150
|
-
this.data
|
|
150
|
+
this.data?.lines.filter((surfaceLine: SurfaceLine) => surfaceLine.label).forEach((surfaceLine: SurfaceLine) => this.drawLineLabel(surfaceLine));
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
drawAreaLabel = (surfaceArea: SurfaceArea, nextSurfaceArea: SurfaceArea | null, surfaces: SurfaceArea[], i: number): void => {
|
|
154
154
|
const { data } = surfaceArea;
|
|
155
155
|
const { ctx, maxFontSizeInWorldCoordinates, isXFlipped } = this;
|
|
156
|
-
const { xScale, yScale, xRatio, yRatio, zFactor } = this.rescaleEvent
|
|
156
|
+
const { xScale, yScale, xRatio, yRatio, zFactor } = this.rescaleEvent!;
|
|
157
|
+
if (ctx == null) return;
|
|
158
|
+
|
|
157
159
|
let isLabelsOnLeftSide = this.checkDrawLabelsOnLeftSide();
|
|
158
160
|
const margins = (this.options.margins || this.defaultMargins) * (isXFlipped ? -1 : 1);
|
|
159
161
|
const marginsInWorldCoords = margins / xRatio;
|
|
@@ -168,14 +170,14 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
const leftEdge = xScale.invert(xScale.range()[0]) + marginsInWorldCoords;
|
|
172
|
-
const rightEdge = xScale.invert(xScale.range()[1]) - marginsInWorldCoords;
|
|
173
|
-
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges();
|
|
173
|
+
const leftEdge = xScale.invert(xScale.range()[0]!) + marginsInWorldCoords;
|
|
174
|
+
const rightEdge = xScale.invert(xScale.range()[1]!) - marginsInWorldCoords;
|
|
175
|
+
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges() as [number, number];
|
|
174
176
|
|
|
175
177
|
// Get label metrics
|
|
176
178
|
ctx.save();
|
|
177
179
|
ctx.font = `${fontSizeInWorldCoords * yRatio}px ${this.options.font || this.defaultFont}`;
|
|
178
|
-
let labelMetrics = ctx.measureText(surfaceArea.label);
|
|
180
|
+
let labelMetrics = ctx.measureText(surfaceArea.label ?? '');
|
|
179
181
|
let labelLengthInWorldCoords = labelMetrics.width / xRatio;
|
|
180
182
|
|
|
181
183
|
// Check if label will fit horizontally
|
|
@@ -200,8 +202,8 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
200
202
|
startPos = isXFlipped ? Math.max(surfaceAreaRightEdge, rightEdge) : Math.min(surfaceAreaRightEdge, rightEdge);
|
|
201
203
|
}
|
|
202
204
|
|
|
203
|
-
const topEdge = yScale.invert(yScale.range()[0]);
|
|
204
|
-
const bottomEdge = yScale.invert(yScale.range()[1]);
|
|
205
|
+
const topEdge = yScale.invert(yScale.range()[0]!);
|
|
206
|
+
const bottomEdge = yScale.invert(yScale.range()[1]!);
|
|
205
207
|
|
|
206
208
|
// Calculate where to sample points
|
|
207
209
|
const dirSteps = 5;
|
|
@@ -211,14 +213,14 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
211
213
|
const dirStep = (labelLengthInWorldCoords / dirSteps) * (isLabelsOnLeftSide ? 1 : -1) * (isXFlipped ? -1 : 1);
|
|
212
214
|
|
|
213
215
|
// Sample points from top and calculate position
|
|
214
|
-
const topData = data.map((d) => [d[0]
|
|
216
|
+
const topData = data.map((d) => [d[0]!, d[1]!]);
|
|
215
217
|
const topPos = this.calcPos(topData, startPos, posSteps, posStep, topEdge, bottomEdge);
|
|
216
218
|
if (!topPos) {
|
|
217
219
|
return;
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
// Sample points from bottom and calculate position
|
|
221
|
-
const bottomData = data.map((d) => [d[0]
|
|
223
|
+
const bottomData = data.map((d) => [d[0]!, d[2]!]);
|
|
222
224
|
let bottomPos = this.calcPos(
|
|
223
225
|
bottomData,
|
|
224
226
|
startPos,
|
|
@@ -226,7 +228,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
226
228
|
posStep,
|
|
227
229
|
topEdge,
|
|
228
230
|
bottomEdge,
|
|
229
|
-
nextSurfaceArea
|
|
231
|
+
nextSurfaceArea?.data.map((d) => [d[0]!, d[1]!]) ?? [],
|
|
230
232
|
surfaces,
|
|
231
233
|
i,
|
|
232
234
|
);
|
|
@@ -244,7 +246,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
244
246
|
// Use reduced fontsize
|
|
245
247
|
fontSizeInWorldCoords = thickness;
|
|
246
248
|
ctx.font = `${fontSizeInWorldCoords * yRatio}px ${this.options.font || this.defaultFont}`;
|
|
247
|
-
labelMetrics = ctx.measureText(surfaceArea.label);
|
|
249
|
+
labelMetrics = ctx.measureText(surfaceArea.label ?? '');
|
|
248
250
|
labelLengthInWorldCoords = labelMetrics.width / xRatio;
|
|
249
251
|
}
|
|
250
252
|
// Sample points from top and bottom and calculate direction vector
|
|
@@ -261,7 +263,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
261
263
|
0,
|
|
262
264
|
Math.PI / 4,
|
|
263
265
|
4,
|
|
264
|
-
nextSurfaceArea
|
|
266
|
+
nextSurfaceArea?.data.map((d) => [d[0]!, d[1]!]) ?? [],
|
|
265
267
|
surfaces,
|
|
266
268
|
i,
|
|
267
269
|
);
|
|
@@ -271,20 +273,24 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
271
273
|
const textX = startPos;
|
|
272
274
|
const textY = (topPos.y + bottomPos.y) / 2;
|
|
273
275
|
const textAngle = isXFlipped ? -scaledAngle : scaledAngle;
|
|
274
|
-
ctx.textAlign = isLabelsOnLeftSide ? 'left' : 'right';
|
|
275
|
-
ctx.translate(xScale(textX), yScale(textY));
|
|
276
|
-
ctx.rotate(textAngle);
|
|
277
|
-
ctx.fillStyle = this.options.textColor || this.defaultTextColor;
|
|
278
|
-
ctx.font = `${fontSizeInWorldCoords * yRatio}px ${this.options.font || this.defaultFont}`;
|
|
279
|
-
ctx.textBaseline = 'middle';
|
|
280
|
-
ctx.fillText(surfaceArea.label, 0, 0);
|
|
281
276
|
|
|
282
|
-
ctx
|
|
277
|
+
if (ctx) {
|
|
278
|
+
ctx.textAlign = isLabelsOnLeftSide ? 'left' : 'right';
|
|
279
|
+
ctx.translate(xScale(textX), yScale(textY));
|
|
280
|
+
ctx.rotate(textAngle);
|
|
281
|
+
ctx.fillStyle = this.options.textColor || this.defaultTextColor;
|
|
282
|
+
ctx.font = `${fontSizeInWorldCoords * yRatio}px ${this.options.font || this.defaultFont}`;
|
|
283
|
+
ctx.textBaseline = 'middle';
|
|
284
|
+
ctx.fillText(surfaceArea.label ?? '', 0, 0);
|
|
285
|
+
|
|
286
|
+
ctx.restore();
|
|
287
|
+
}
|
|
283
288
|
};
|
|
284
289
|
|
|
285
290
|
drawLineLabel = (s: SurfaceLine): void => {
|
|
286
291
|
const { ctx, isXFlipped } = this;
|
|
287
|
-
const { xScale, yScale, xRatio, yRatio, zFactor } = this.rescaleEvent
|
|
292
|
+
const { xScale, yScale, xRatio, yRatio, zFactor } = this.rescaleEvent!;
|
|
293
|
+
if (ctx == null) return;
|
|
288
294
|
const isLabelsOnLeftSide = this.checkDrawLabelsOnLeftSide();
|
|
289
295
|
const marginsInWorldCoords = this.getMarginsInWorldCoordinates();
|
|
290
296
|
const maxFontSize = this.options.maxFontSize || this.defaultMaxFontSize;
|
|
@@ -296,9 +302,9 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
296
302
|
const labelMetrics = ctx.measureText(s.label);
|
|
297
303
|
const labelLengthInWorldCoords = labelMetrics.width / xRatio;
|
|
298
304
|
|
|
299
|
-
const leftEdge = xScale.invert(xScale.range()[0]) + marginsInWorldCoords;
|
|
300
|
-
const rightEdge = xScale.invert(xScale.range()[1]) - marginsInWorldCoords;
|
|
301
|
-
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges();
|
|
305
|
+
const leftEdge = xScale.invert(xScale.range()[0]!) + marginsInWorldCoords;
|
|
306
|
+
const rightEdge = xScale.invert(xScale.range()[1]!) - marginsInWorldCoords;
|
|
307
|
+
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges() as [number, number];
|
|
302
308
|
|
|
303
309
|
// Find edge where to draw
|
|
304
310
|
let startPos: number;
|
|
@@ -326,14 +332,16 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
326
332
|
const textDir = Vector2.angleRight(dir) - (isLabelsOnLeftSide ? Math.PI : 0);
|
|
327
333
|
|
|
328
334
|
// Draw label
|
|
329
|
-
ctx
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
if (ctx) {
|
|
336
|
+
ctx.textAlign = isLabelsOnLeftSide ? 'right' : 'left';
|
|
337
|
+
ctx.translate(xScale(textX), yScale(textY));
|
|
338
|
+
ctx.rotate(textDir);
|
|
339
|
+
ctx.fillStyle = this.colorToCSSColor(s.color);
|
|
340
|
+
ctx.textBaseline = 'middle';
|
|
341
|
+
ctx.fillText(s.label, 0, 0);
|
|
342
|
+
|
|
343
|
+
ctx.restore();
|
|
344
|
+
}
|
|
337
345
|
};
|
|
338
346
|
|
|
339
347
|
colorToCSSColor(color: number | string): string {
|
|
@@ -342,7 +350,6 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
342
350
|
}
|
|
343
351
|
|
|
344
352
|
let hexString = color.toString(16);
|
|
345
|
-
// eslint-disable-next-line no-magic-numbers
|
|
346
353
|
hexString = '000000'.substr(0, 6 - hexString.length) + hexString;
|
|
347
354
|
return `#${hexString}`;
|
|
348
355
|
}
|
|
@@ -352,12 +359,12 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
352
359
|
offset: number,
|
|
353
360
|
count: number,
|
|
354
361
|
step: number,
|
|
355
|
-
topLimit
|
|
356
|
-
bottomLimit
|
|
357
|
-
alternativeSurfaceData
|
|
362
|
+
topLimit?: number,
|
|
363
|
+
bottomLimit?: number,
|
|
364
|
+
alternativeSurfaceData?: number[][],
|
|
358
365
|
surfaces: SurfaceArea[] | null = null,
|
|
359
|
-
currentSurfaceIndex
|
|
360
|
-
): Vector2 {
|
|
366
|
+
currentSurfaceIndex?: number,
|
|
367
|
+
): Vector2 | null {
|
|
361
368
|
const pos = Vector2.zero.mutable;
|
|
362
369
|
let samples = 0;
|
|
363
370
|
for (let i = 0; i < count; i++) {
|
|
@@ -381,12 +388,12 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
381
388
|
|
|
382
389
|
getAlternativeYValueIfAvailable(
|
|
383
390
|
x: number,
|
|
384
|
-
topLimit
|
|
385
|
-
bottomLimit
|
|
386
|
-
alternativeSurfaceData
|
|
387
|
-
surfaces: SurfaceArea[] | null,
|
|
388
|
-
currentSurfaceIndex
|
|
389
|
-
): number {
|
|
391
|
+
topLimit?: number,
|
|
392
|
+
bottomLimit?: number,
|
|
393
|
+
alternativeSurfaceData?: number[][],
|
|
394
|
+
surfaces: SurfaceArea[] | null = null,
|
|
395
|
+
currentSurfaceIndex?: number,
|
|
396
|
+
): number | null {
|
|
390
397
|
if (!alternativeSurfaceData) {
|
|
391
398
|
return null;
|
|
392
399
|
}
|
|
@@ -397,12 +404,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
397
404
|
let si = currentSurfaceIndex + 1;
|
|
398
405
|
while (altY == null && si < surfaces.length) {
|
|
399
406
|
const altSurface = surfaces[si++];
|
|
400
|
-
altY = findSampleAtPos(
|
|
401
|
-
altSurface.data.map((d: number[]) => [d[0], d[1]]),
|
|
402
|
-
x,
|
|
403
|
-
topLimit,
|
|
404
|
-
bottomLimit,
|
|
405
|
-
);
|
|
407
|
+
altY = findSampleAtPos(altSurface?.data.map((d: number[]) => [d[0]!, d[1]!]) ?? [], x, topLimit, bottomLimit);
|
|
406
408
|
}
|
|
407
409
|
}
|
|
408
410
|
return altY;
|
|
@@ -415,8 +417,8 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
415
417
|
step: number,
|
|
416
418
|
zFactor: number,
|
|
417
419
|
initalVector: Vector2 = Vector2.left,
|
|
418
|
-
topLimit
|
|
419
|
-
bottomLimit
|
|
420
|
+
topLimit?: number,
|
|
421
|
+
bottomLimit?: number,
|
|
420
422
|
): Vector2 {
|
|
421
423
|
const dir = initalVector.mutable;
|
|
422
424
|
|
|
@@ -447,14 +449,14 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
447
449
|
count: number,
|
|
448
450
|
step: number,
|
|
449
451
|
initalVector: Vector2 = Vector2.left,
|
|
450
|
-
topLimit: number
|
|
451
|
-
bottomLimit: number
|
|
452
|
-
minReductionAngle
|
|
452
|
+
topLimit: number,
|
|
453
|
+
bottomLimit: number,
|
|
454
|
+
minReductionAngle = 0,
|
|
453
455
|
maxReductionAngle: number = Math.PI / 4,
|
|
454
|
-
angleReductionExponent
|
|
455
|
-
alternativeSurfaceBottomData: number[][]
|
|
456
|
+
angleReductionExponent = 4,
|
|
457
|
+
alternativeSurfaceBottomData: number[][],
|
|
456
458
|
surfaces: SurfaceArea[] | null = null,
|
|
457
|
-
currentSurfaceIndex: number
|
|
459
|
+
currentSurfaceIndex: number,
|
|
458
460
|
): number {
|
|
459
461
|
const angles: number[] = [];
|
|
460
462
|
const tmpVec = Vector2.zero.mutable;
|
|
@@ -483,7 +485,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
483
485
|
} else {
|
|
484
486
|
if (topY !== null) {
|
|
485
487
|
tmpVec.set(x, (topY + usedBottomY) / 2);
|
|
486
|
-
tmpVec.sub(vecAtEnd);
|
|
488
|
+
tmpVec.sub(vecAtEnd!);
|
|
487
489
|
|
|
488
490
|
angles.push(Vector2.angleRight(tmpVec));
|
|
489
491
|
} else {
|
|
@@ -492,7 +494,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
492
494
|
}
|
|
493
495
|
}
|
|
494
496
|
|
|
495
|
-
const refAngle = angles[0]
|
|
497
|
+
const refAngle = angles[0]!;
|
|
496
498
|
const offsetAngles = angles.map((d: number) => d - refAngle);
|
|
497
499
|
let factors = 0;
|
|
498
500
|
const offsetSum = offsetAngles.reduce((acc: number, v: number) => {
|
|
@@ -506,50 +508,51 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
506
508
|
}
|
|
507
509
|
|
|
508
510
|
updateXFlipped(): void {
|
|
509
|
-
const { xBounds } = this.rescaleEvent
|
|
511
|
+
const { xBounds } = this.rescaleEvent!;
|
|
510
512
|
this.isXFlipped = xBounds[0] > xBounds[1];
|
|
511
513
|
}
|
|
512
514
|
|
|
513
515
|
getMarginsInWorldCoordinates(): number {
|
|
514
|
-
const { xRatio } = this.rescaleEvent
|
|
516
|
+
const { xRatio } = this.rescaleEvent!;
|
|
515
517
|
const margins = (this.options.margins || this.defaultMargins) * (this.isXFlipped ? -1 : 1);
|
|
516
518
|
const marginsInWorldCoords = margins / xRatio;
|
|
517
519
|
return marginsInWorldCoords;
|
|
518
520
|
}
|
|
519
521
|
|
|
520
522
|
getSurfacesAreaEdges(): number[] {
|
|
521
|
-
const endPoints =
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
523
|
+
const endPoints =
|
|
524
|
+
this.data?.areas.reduce((acc, area) => {
|
|
525
|
+
const { data } = area;
|
|
526
|
+
const firstValidPoint = data.find((d: number[]) => d[1] != null);
|
|
527
|
+
if (firstValidPoint) {
|
|
528
|
+
acc.push(firstValidPoint[0]!);
|
|
529
|
+
}
|
|
530
|
+
// TODO: Use findLast() when TypeScript stops complaining about it
|
|
531
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
532
|
+
if (data[i]?.[1] != null) {
|
|
533
|
+
acc.push(data[i]?.[0]!);
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
532
536
|
}
|
|
533
|
-
}
|
|
534
537
|
|
|
535
|
-
|
|
536
|
-
|
|
538
|
+
return acc;
|
|
539
|
+
}, [] as number[]) ?? [];
|
|
537
540
|
endPoints.push(
|
|
538
|
-
...this.data
|
|
541
|
+
...(this.data?.lines.reduce((acc, line) => {
|
|
539
542
|
const { data } = line;
|
|
540
543
|
const firstValidPoint = data.find((d: number[]) => d[1] != null);
|
|
541
544
|
if (firstValidPoint) {
|
|
542
|
-
acc.push(firstValidPoint[0]);
|
|
545
|
+
acc.push(firstValidPoint[0]!);
|
|
543
546
|
}
|
|
544
547
|
// TODO: Use findLast() when TypeScript stops complaining about it
|
|
545
548
|
for (let i = data.length - 1; i >= 0; i--) {
|
|
546
|
-
if (data[i][1] != null) {
|
|
547
|
-
acc.push(data[i][0]);
|
|
549
|
+
if (data[i]?.[1] != null) {
|
|
550
|
+
acc.push(data[i]?.[0]!);
|
|
548
551
|
break;
|
|
549
552
|
}
|
|
550
553
|
}
|
|
551
554
|
return acc;
|
|
552
|
-
}, []),
|
|
555
|
+
}, [] as number[]) ?? []),
|
|
553
556
|
);
|
|
554
557
|
|
|
555
558
|
const minX = Math.min(...endPoints);
|
|
@@ -567,11 +570,11 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
567
570
|
return true;
|
|
568
571
|
}
|
|
569
572
|
|
|
570
|
-
const { xScale, yScale, xRatio } = this.rescaleEvent
|
|
573
|
+
const { xScale, yScale, xRatio } = this.rescaleEvent!;
|
|
571
574
|
const t = 200; // TODO: Use actual size of largest label or average size of all
|
|
572
575
|
|
|
573
|
-
const [dx1, dx2] = xScale.domain();
|
|
574
|
-
const [dy1, dy2] = yScale.domain();
|
|
576
|
+
const [dx1, dx2] = xScale.domain() as [number, number];
|
|
577
|
+
const [dy1, dy2] = yScale.domain() as [number, number];
|
|
575
578
|
|
|
576
579
|
let top = referenceSystem.interpolators.curtain.getIntersects(dy1, 1, 0) as number[][];
|
|
577
580
|
if (top.length === 0) {
|
|
@@ -582,8 +585,8 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
582
585
|
bottom = [referenceSystem.interpolators.curtain.getPointAt(1.0) as number[]];
|
|
583
586
|
}
|
|
584
587
|
|
|
585
|
-
const maxX = Math.max(top[0][0]
|
|
586
|
-
const minX = Math.min(top[0][0]
|
|
588
|
+
const maxX = Math.max(top[0]?.[0]!, bottom[0]?.[0]!);
|
|
589
|
+
const minX = Math.min(top[0]?.[0]!, bottom[0]?.[0]!);
|
|
587
590
|
|
|
588
591
|
const wbBBox = {
|
|
589
592
|
left: isXFlipped ? maxX : minX,
|
|
@@ -594,7 +597,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
594
597
|
const screenLeftEdge = dx1 + margin;
|
|
595
598
|
const screenRightEdge = dx2 - margin;
|
|
596
599
|
|
|
597
|
-
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges();
|
|
600
|
+
const [surfaceAreaLeftEdge, surfaceAreaRightEdge] = this.getSurfacesAreaEdges() as [number, number];
|
|
598
601
|
|
|
599
602
|
const leftLimit = isXFlipped ? Math.min(screenLeftEdge, surfaceAreaLeftEdge) : Math.max(screenLeftEdge, surfaceAreaLeftEdge);
|
|
600
603
|
const rightLimit = isXFlipped ? Math.max(screenRightEdge, surfaceAreaRightEdge) : Math.min(screenRightEdge, surfaceAreaRightEdge);
|
|
@@ -608,7 +611,7 @@ export class GeomodelLabelsLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
|
608
611
|
spaceOnLeftSide > spaceOnRightSide ||
|
|
609
612
|
spaceOnLeftSideInScreenCoordinates > t ||
|
|
610
613
|
(spaceOnLeftSideInScreenCoordinates < t && spaceOnRightSideInScreenCoordinates < t && isXFlipped) ||
|
|
611
|
-
bottom[0][1] < dy1;
|
|
614
|
+
bottom[0]?.[1]! < dy1;
|
|
612
615
|
|
|
613
616
|
return isLabelsOnLeftSide;
|
|
614
617
|
}
|
|
@@ -7,7 +7,7 @@ import { SURFACE_LINE_WIDTH } from '../constants';
|
|
|
7
7
|
const DEFAULT_Y_BOTTOM = 10000;
|
|
8
8
|
|
|
9
9
|
export class GeomodelLayerV2<T extends SurfaceData> extends PixiLayer<T> {
|
|
10
|
-
private isPreRendered
|
|
10
|
+
private isPreRendered = false;
|
|
11
11
|
|
|
12
12
|
override onRescale(event: OnRescaleEvent): void {
|
|
13
13
|
super.onRescale(event);
|
|
@@ -30,31 +30,31 @@ export class GeomodelLayerV2<T extends SurfaceData> extends PixiLayer<T> {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
preRender(): void {
|
|
33
|
-
const { data }
|
|
33
|
+
const { data } = this;
|
|
34
34
|
|
|
35
35
|
if (!data) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
data.areas.forEach((a
|
|
40
|
-
data.lines.forEach((l
|
|
39
|
+
data.areas.forEach((a) => this.generateAreaPolygon(a));
|
|
40
|
+
data.lines.forEach((l) => this.generateSurfaceLine(l));
|
|
41
41
|
|
|
42
42
|
this.isPreRendered = true;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
createPolygons = (data: number[][]): number[][] => {
|
|
46
46
|
const polygons: number[][] = [];
|
|
47
|
-
let polygon: number[]
|
|
47
|
+
let polygon: number[] | undefined;
|
|
48
48
|
|
|
49
49
|
// Start generating polygons
|
|
50
50
|
for (let i = 0; i < data.length; i++) {
|
|
51
51
|
// Generate top of polygon as long as we have valid values
|
|
52
|
-
const topIsValid = !!data[i][1];
|
|
52
|
+
const topIsValid = !!data[i]?.[1];
|
|
53
53
|
if (topIsValid) {
|
|
54
|
-
if (polygon
|
|
54
|
+
if (polygon == null) {
|
|
55
55
|
polygon = [];
|
|
56
56
|
}
|
|
57
|
-
polygon.push(data[i][0]
|
|
57
|
+
polygon.push(data[i]?.[0]!, data[i]?.[1]!);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const endIsReached = i === data.length - 1;
|
|
@@ -62,13 +62,13 @@ export class GeomodelLayerV2<T extends SurfaceData> extends PixiLayer<T> {
|
|
|
62
62
|
if (polygon) {
|
|
63
63
|
// Generate bottom of polygon
|
|
64
64
|
for (let j: number = !topIsValid ? i - 1 : i; j >= 0; j--) {
|
|
65
|
-
if (!data[j][1]) {
|
|
65
|
+
if (!data[j]?.[1]) {
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
|
-
polygon.push(data[j][0]
|
|
68
|
+
polygon.push(data[j]?.[0]!, data[j]?.[2] || DEFAULT_Y_BOTTOM);
|
|
69
69
|
}
|
|
70
70
|
polygons.push(polygon);
|
|
71
|
-
polygon =
|
|
71
|
+
polygon = undefined;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/layers/GridLayer.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { ScaleLinear } from 'd3-scale';
|
|
|
4
4
|
import { LayerOptions } from './base/Layer';
|
|
5
5
|
|
|
6
6
|
// constants
|
|
7
|
-
const MINORCOLOR
|
|
8
|
-
const MAJORCOLOR
|
|
9
|
-
const MINORWIDTH
|
|
10
|
-
const MAJORWIDTH
|
|
7
|
+
const MINORCOLOR = 'lightgray';
|
|
8
|
+
const MAJORCOLOR = 'gray';
|
|
9
|
+
const MINORWIDTH = 0.25;
|
|
10
|
+
const MAJORWIDTH = 0.75;
|
|
11
11
|
|
|
12
12
|
const defaultOptions = {
|
|
13
13
|
minorColor: MINORCOLOR,
|
|
@@ -29,8 +29,8 @@ export interface OnGridLayerUpdateEvent<T> extends OnUpdateEvent<T> {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export class GridLayer<T> extends CanvasLayer<T> {
|
|
32
|
-
private _offsetX
|
|
33
|
-
private _offsetY
|
|
32
|
+
private _offsetX = 0;
|
|
33
|
+
private _offsetY = 0;
|
|
34
34
|
|
|
35
35
|
constructor(id?: string, options?: GridLayerOptions<T>) {
|
|
36
36
|
super(id, options);
|
|
@@ -65,11 +65,11 @@ export class GridLayer<T> extends CanvasLayer<T> {
|
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const xScale = event.xScale
|
|
69
|
-
const yScale = event.yScale
|
|
68
|
+
const xScale = event.xScale!.copy();
|
|
69
|
+
const yScale = event.yScale!.copy();
|
|
70
70
|
|
|
71
|
-
const xDomain = xScale.domain();
|
|
72
|
-
const yDomain = yScale.domain();
|
|
71
|
+
const xDomain = xScale.domain() as [number, number];
|
|
72
|
+
const yDomain = yScale.domain() as [number, number];
|
|
73
73
|
|
|
74
74
|
const offsetX = this.offsetX;
|
|
75
75
|
const offsetY = this.offsetY;
|
|
@@ -77,8 +77,8 @@ export class GridLayer<T> extends CanvasLayer<T> {
|
|
|
77
77
|
xScale.domain([xDomain[0] - offsetX, xDomain[1] - offsetX]);
|
|
78
78
|
yScale.domain([yDomain[0] - offsetY, yDomain[1] - offsetY]);
|
|
79
79
|
|
|
80
|
-
const [rx1, rx2] = xScale.range();
|
|
81
|
-
const [ry1, ry2] = yScale.range();
|
|
80
|
+
const [rx1, rx2] = xScale.range() as [number, number];
|
|
81
|
+
const [ry1, ry2] = yScale.range() as [number, number];
|
|
82
82
|
|
|
83
83
|
ctx.lineWidth = minorWidth || MINORWIDTH;
|
|
84
84
|
ctx.strokeStyle = minorColor || MINORCOLOR;
|
|
@@ -101,27 +101,31 @@ export class GridLayer<T> extends CanvasLayer<T> {
|
|
|
101
101
|
private renderTicksX(xscale: ScaleLinear<number, number, never>, xticks: number[], ry1: number, ry2: number): void {
|
|
102
102
|
xticks.forEach((tx: number) => {
|
|
103
103
|
const x = xscale(tx);
|
|
104
|
-
this.ctx
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
if (this.ctx != null) {
|
|
105
|
+
this.ctx.beginPath();
|
|
106
|
+
this.ctx.moveTo(x, ry1);
|
|
107
|
+
this.ctx.lineTo(x, ry2);
|
|
108
|
+
this.ctx.stroke();
|
|
109
|
+
}
|
|
108
110
|
});
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
private renderTicksY(yscale: ScaleLinear<number, number, never>, yticks: number[], rx1: number, rx2: number): void {
|
|
112
114
|
yticks.forEach((ty: number) => {
|
|
113
115
|
const y = yscale(ty);
|
|
114
|
-
this.ctx
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
if (this.ctx != null) {
|
|
117
|
+
this.ctx.beginPath();
|
|
118
|
+
this.ctx.moveTo(rx1, y);
|
|
119
|
+
this.ctx.lineTo(rx2, y);
|
|
120
|
+
this.ctx.stroke();
|
|
121
|
+
}
|
|
118
122
|
});
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
private mapMinorTicks(ticks: number[]): number[] {
|
|
122
126
|
let xminticks: number[] = [];
|
|
123
127
|
if (ticks.length >= 2) {
|
|
124
|
-
xminticks = ticks.map((v: number) => v + (ticks[1] - ticks[0]) / 2);
|
|
128
|
+
xminticks = ticks.map((v: number) => v + (ticks[1]! - ticks[0]!) / 2);
|
|
125
129
|
xminticks.pop();
|
|
126
130
|
}
|
|
127
131
|
return xminticks;
|
|
@@ -15,7 +15,7 @@ export interface OnImageLayerUpdateEvent<T> extends OnUpdateEvent<T> {
|
|
|
15
15
|
export type OnImageLayerRescaleEvent<T> = OnImageLayerUpdateEvent<T> & OnRescaleEvent;
|
|
16
16
|
|
|
17
17
|
export class ImageLayer<T> extends CanvasLayer<T> {
|
|
18
|
-
img: HTMLImageElement;
|
|
18
|
+
img: HTMLImageElement | undefined;
|
|
19
19
|
|
|
20
20
|
override onMount(event: OnMountEvent): void {
|
|
21
21
|
super.onMount(event);
|
|
@@ -26,7 +26,9 @@ export class ImageLayer<T> extends CanvasLayer<T> {
|
|
|
26
26
|
|
|
27
27
|
override onUpdate(event: OnImageLayerUpdateEvent<T>): void {
|
|
28
28
|
super.onUpdate(event);
|
|
29
|
-
this.img
|
|
29
|
+
if (this.img != null) {
|
|
30
|
+
this.img.src = event.url;
|
|
31
|
+
}
|
|
30
32
|
this.render(event);
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -37,19 +39,23 @@ export class ImageLayer<T> extends CanvasLayer<T> {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
render(event: OnImageLayerUpdateEvent<T>): void {
|
|
40
|
-
const width = parseInt(this.elm
|
|
41
|
-
const height = parseInt(this.elm
|
|
42
|
+
const width = parseInt(this.elm?.getAttribute('width') ?? '0', 10);
|
|
43
|
+
const height = parseInt(this.elm?.getAttribute('height') ?? '0', 10);
|
|
42
44
|
const { xScale, yScale, xRatio, yRatio, x, y } = event;
|
|
43
45
|
const calcWidth = width * (xRatio || 1);
|
|
44
46
|
const calcHeight = height * (yRatio || 1);
|
|
45
47
|
this.clearCanvas();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
|
|
49
|
+
if (this.img != null) {
|
|
50
|
+
if (this.isLoading) {
|
|
51
|
+
this.img.onload = (): void => {
|
|
52
|
+
this.isLoading = false;
|
|
53
|
+
// An extra undefined check should happen here as the execution doesn't happen synchronously
|
|
54
|
+
this.img != null && this.ctx?.drawImage(this.img, xScale(x || 0), yScale(y || 0), calcWidth, calcHeight);
|
|
55
|
+
};
|
|
56
|
+
} else {
|
|
57
|
+
this.ctx?.drawImage(this.img, xScale(x || 0), yScale(y || 0), calcWidth, calcHeight);
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
}
|