@mark1russell7/visuals 0.3.0 → 0.3.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.
- package/README.md +56 -1
- package/build/extent-D2SsHJnP.js +154 -0
- package/build/extent-D2SsHJnP.js.map +1 -0
- package/build/globe.d.ts +8 -1
- package/build/globe.d.ts.map +1 -1
- package/build/globe.js +135 -8
- package/build/globe.js.map +1 -1
- package/build/index.js +3 -2
- package/build/index.js.map +1 -1
- package/build/labels.d.ts +1 -1
- package/build/mark-AZ5AuAIJ.js +98 -0
- package/build/mark-AZ5AuAIJ.js.map +1 -0
- package/build/mark-D8AdQYAS.d.ts +154 -0
- package/build/mark-D8AdQYAS.d.ts.map +1 -0
- package/build/markers.d.ts +67 -0
- package/build/markers.d.ts.map +1 -0
- package/build/markers.js +687 -0
- package/build/markers.js.map +1 -0
- package/build/marks.d.ts +2 -153
- package/build/marks.d.ts.map +1 -1
- package/build/marks.js +2 -95
- package/build/marks.js.map +1 -1
- package/build/{motion-dvvkaDwv.js → motion-BvRKIWAC.js} +2 -2
- package/build/{motion-dvvkaDwv.js.map → motion-BvRKIWAC.js.map} +1 -1
- package/build/{stage-Bhu1f7Dw.d.ts → stage-DmFfah2e.d.ts} +6 -1
- package/build/stage-DmFfah2e.d.ts.map +1 -0
- package/build/three.d.ts +4 -2
- package/build/three.d.ts.map +1 -1
- package/build/three.js +11 -4
- package/build/three.js.map +1 -1
- package/build/{extent-DC0qrxC5.js → view-BB_EQx3I.js} +2 -152
- package/build/view-BB_EQx3I.js.map +1 -0
- package/package.json +6 -1
- package/build/extent-DC0qrxC5.js.map +0 -1
- package/build/stage-Bhu1f7Dw.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
3D stages for data. A stage is one canvas of three.js with a camera that a person moves. The content of the stage is your data.
|
|
4
4
|
|
|
5
|
-
The package has
|
|
5
|
+
The package has seven entries and two style sheets:
|
|
6
6
|
|
|
7
7
|
- The entry `.` has the camera maths and the model of a replay. It needs no browser, and it does not need `three`.
|
|
8
8
|
- The entry `/marks` has the marks that a viewer draws, as plain data. It needs no browser, and it does not need `three`.
|
|
9
9
|
- The entry `/three` has the stage. It needs the package `three`, version 0.187.0 or later.
|
|
10
10
|
- The entry `/globe` has a content that shows the Earth as a globe, with areas and points on it. It also needs `three`.
|
|
11
|
+
- The entry `/markers` has a content that draws the marks on a stage. It also needs `three`.
|
|
11
12
|
- The entry `/scrubber` has a control that sets the time of a picture. It needs a browser, and it does not need `three`.
|
|
12
13
|
- The file `/scrubber.css` is the style sheet of the scrubber.
|
|
13
14
|
- The entry `/labels` has the labels of a stage: a short text next to a point, as an element of the page. It needs a browser.
|
|
@@ -86,6 +87,8 @@ A stage knows nothing about the data. The content gives it these parts:
|
|
|
86
87
|
|
|
87
88
|
`stackContents` makes one content from a list of contents. The first content gives the extent, and a pick asks the last content first.
|
|
88
89
|
|
|
90
|
+
A pick can have a `distance` from the start of the ray. The stack then also asks the earlier contents, and the nearest pick is the record. A pick with no distance is above each record of the earlier contents.
|
|
91
|
+
|
|
89
92
|
A record has a name. The highlight of a record is 0, 1 or 2: no highlight, a record under the pointer, the selected record. `highlight` and `select` set the highlights from the page.
|
|
90
93
|
|
|
91
94
|
## Views
|
|
@@ -185,6 +188,7 @@ const stage = createStage(document.body, {
|
|
|
185
188
|
- An area is a region of `@mark1russell7/geo`: a `Polygon` or a `MultiPolygon` of GeoJSON. A point is a place with a latitude and a longitude.
|
|
186
189
|
- The surface of an area follows the curve of the Earth. The option `step` sets the largest step of an edge, in degrees.
|
|
187
190
|
- A kind names the style of an area or a point in the theme. A new theme changes each color, and the geometry stays.
|
|
191
|
+
- A style with `dash` draws the edge of its areas as a dashed line. `dash` has the length of a dash and of a gap, in CSS pixels. The edge of a highlight keeps the dash.
|
|
188
192
|
- The pointer finds a point first, then the last area of the list. The pointer ignores a part with `pick: false`.
|
|
189
193
|
- `show` hides each part that a test refuses, for example the records that are not active at a time.
|
|
190
194
|
- `placeAt` gives the place on the Earth under the pointer.
|
|
@@ -404,6 +408,57 @@ shapeRing("triangle").length; // => 3: the corners of the sign, counter-clockwis
|
|
|
404
408
|
|
|
405
409
|
Use it as a gate in the tests of a producer. A viewer uses it on a list that it did not make. It does not examine the form of a mark, so read a list from JSON through a schema first.
|
|
406
410
|
|
|
411
|
+
## The marks on a stage
|
|
412
|
+
|
|
413
|
+
The entry `/markers` has a content that draws a list of marks. Put it after the content of the solids in `stackContents`.
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
import { fitView } from "@mark1russell7/visuals";
|
|
417
|
+
import { createMarkers, type MarkersTheme } from "@mark1russell7/visuals/markers";
|
|
418
|
+
import { createStage, stackContents } from "@mark1russell7/visuals/three";
|
|
419
|
+
|
|
420
|
+
const theme: MarkersTheme = {
|
|
421
|
+
sky: "#ffffff",
|
|
422
|
+
ground: "#ffffff",
|
|
423
|
+
levels: { unknown: "#55677a", ok: "#1f5fa8", near: "#c9740a", over: "#b81d3a" },
|
|
424
|
+
halo: "#ffffff",
|
|
425
|
+
accent: "#111111",
|
|
426
|
+
field: ["#eef4f1", "#8fcab7", "#1d7f69"],
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const markers = createMarkers(marks);
|
|
430
|
+
const stage = createStage(box, {
|
|
431
|
+
// The content `room` has the solids. The marks are on top of them.
|
|
432
|
+
content: stackContents([room, markers]),
|
|
433
|
+
theme,
|
|
434
|
+
label: "A room with its marks",
|
|
435
|
+
views: { corner: fitView({ polar: 1, azimuth: 0.7 }) },
|
|
436
|
+
home: "corner",
|
|
437
|
+
onHover: (mark) => console.log(mark?.label),
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
// The legend of a page shows only the marks of some kinds.
|
|
441
|
+
markers.show((mark) => mark.kind !== "cable");
|
|
442
|
+
stage?.refresh();
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
| Mark | Picture |
|
|
446
|
+
| --- | --- |
|
|
447
|
+
| `point` | A sign with the shape and the color of its level. The sign looks at the camera. |
|
|
448
|
+
| `run` | A round line with its width in the space, and a thin line of the color `halo` around it. |
|
|
449
|
+
| `link` | A dashed line. It is in the picture while its record, or the record of one of its ends, has a highlight. |
|
|
450
|
+
| `field` | A grid of colors on its plane. A cell with no value is clear. |
|
|
451
|
+
| `meter` | No picture, because a meter has no place. |
|
|
452
|
+
|
|
453
|
+
- A point with no `size` has a sign with a radius of `SIGN_RADIUS` pixels at each distance. A size is in the unit of the space.
|
|
454
|
+
- A mark behind a solid stays in the picture with less color. A mark with a highlight stays solid.
|
|
455
|
+
- A sign gets the pick before each solid, also behind a solid. Thus the pointer finds an outlet behind a desk.
|
|
456
|
+
- A run and a field give the distance of their pick, so a solid in front of them gets the pick. A run gets the pick before a field.
|
|
457
|
+
- The theme gives the color of each level, the colors of a field from `min` to `max`, and the color `halo` around a mark.
|
|
458
|
+
- A record with a highlight gets a larger sign, and a line of the color `accent` around it.
|
|
459
|
+
- `signReach` gives the radius of a sign with its line. Give it to the field `clear` of a label.
|
|
460
|
+
- The pick of a field gives the mark. `fieldValue` reads the value of a cell.
|
|
461
|
+
|
|
407
462
|
## The camera maths
|
|
408
463
|
|
|
409
464
|
The entry `.` has pure functions. A page with no WebGL 2 and a test in Node.js use the same functions as the stage.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { a as fitDistance, d as viewOf, r as capDistance } from "./view-BB_EQx3I.js";
|
|
2
|
+
// src/extent.ts
|
|
3
|
+
/** The space around the content in a view that shows all of it, as a factor of the distance. */
|
|
4
|
+
const FIT_MARGIN = 1.06;
|
|
5
|
+
/** This function gives the radius of the ball around the center of an extent, or 0 for no ball. */
|
|
6
|
+
function surfaceOf(extent) {
|
|
7
|
+
const surface = extent.surface ?? 0;
|
|
8
|
+
return surface > 0 ? surface : 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* This function makes a view that shows each corner of the content from one direction.
|
|
12
|
+
* `margin` is the space around the content, as a factor of the distance. An extent with no corners gives the distance 1.
|
|
13
|
+
*/
|
|
14
|
+
function fitView(angles, margin = FIT_MARGIN) {
|
|
15
|
+
return ({ extent, fieldOfView, aspect }) => {
|
|
16
|
+
const distance = fitDistance(extent.corners, extent.center, angles, fieldOfView, aspect) * margin;
|
|
17
|
+
return {
|
|
18
|
+
target: extent.center,
|
|
19
|
+
polar: angles.polar,
|
|
20
|
+
azimuth: angles.azimuth,
|
|
21
|
+
distance: distance > 0 ? distance : 1
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This function makes a view of a part of the ball of the content: a cap around the point of the ball below the camera.
|
|
27
|
+
*
|
|
28
|
+
* `angles` is the direction from the center of the ball to the camera. `angle` is the angle of the cap at the center of the ball, in radians.
|
|
29
|
+
* `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.
|
|
30
|
+
*/
|
|
31
|
+
function capView(angles, angle, margin = FIT_MARGIN) {
|
|
32
|
+
return ({ extent, fieldOfView, aspect }) => {
|
|
33
|
+
const surface = surfaceOf(extent);
|
|
34
|
+
const height = Math.max(capDistance(surface, angle, fieldOfView, aspect) - surface, 0);
|
|
35
|
+
return {
|
|
36
|
+
target: extent.center,
|
|
37
|
+
polar: angles.polar,
|
|
38
|
+
azimuth: angles.azimuth,
|
|
39
|
+
distance: surface > 0 ? surface + height * margin : 1
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.
|
|
45
|
+
*
|
|
46
|
+
* The middle is the center of the box of the points. The camera is at the smallest distance that shows each point in the width and in the height of the picture.
|
|
47
|
+
* Thus wide points fill a wide picture. `margin` is the space around the points, as a factor of the height above the ball.
|
|
48
|
+
* A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.
|
|
49
|
+
*/
|
|
50
|
+
function ballView(points, margin = FIT_MARGIN) {
|
|
51
|
+
let found;
|
|
52
|
+
return (frame) => {
|
|
53
|
+
const { extent } = frame;
|
|
54
|
+
const { center } = extent;
|
|
55
|
+
if (found === void 0 || found.center.x !== center.x || found.center.y !== center.y || found.center.z !== center.z) found = {
|
|
56
|
+
center,
|
|
57
|
+
angles: middleOf(points, center)
|
|
58
|
+
};
|
|
59
|
+
const { angles } = found;
|
|
60
|
+
if (angles === void 0) return capView({
|
|
61
|
+
polar: Math.PI / 2,
|
|
62
|
+
azimuth: 0
|
|
63
|
+
}, Math.PI / 2, margin)(frame);
|
|
64
|
+
const surface = surfaceOf(extent);
|
|
65
|
+
const height = Math.max(fitDistance(points, center, angles, frame.fieldOfView, frame.aspect) - surface, 0);
|
|
66
|
+
return {
|
|
67
|
+
target: center,
|
|
68
|
+
polar: angles.polar,
|
|
69
|
+
azimuth: angles.azimuth,
|
|
70
|
+
distance: surface > 0 ? surface + height * margin : 1
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** This function gives the direction from `center` to the middle of the box of the points. It gives `undefined` when the middle has no direction. */
|
|
75
|
+
function middleOf(points, center) {
|
|
76
|
+
const low = {
|
|
77
|
+
x: 1e400,
|
|
78
|
+
y: 1e400,
|
|
79
|
+
z: 1e400
|
|
80
|
+
};
|
|
81
|
+
const high = {
|
|
82
|
+
x: -1e400,
|
|
83
|
+
y: -1e400,
|
|
84
|
+
z: -1e400
|
|
85
|
+
};
|
|
86
|
+
for (const point of points) {
|
|
87
|
+
low.x = Math.min(low.x, point.x);
|
|
88
|
+
low.y = Math.min(low.y, point.y);
|
|
89
|
+
low.z = Math.min(low.z, point.z);
|
|
90
|
+
high.x = Math.max(high.x, point.x);
|
|
91
|
+
high.y = Math.max(high.y, point.y);
|
|
92
|
+
high.z = Math.max(high.z, point.z);
|
|
93
|
+
}
|
|
94
|
+
const middle = {
|
|
95
|
+
x: (low.x + high.x) / 2 - center.x,
|
|
96
|
+
y: (low.y + high.y) / 2 - center.y,
|
|
97
|
+
z: (low.z + high.z) / 2 - center.z
|
|
98
|
+
};
|
|
99
|
+
const length = Math.hypot(middle.x, middle.y, middle.z);
|
|
100
|
+
if (!(length > 0) || !Number.isFinite(length)) return void 0;
|
|
101
|
+
const { polar, azimuth } = viewOf(middle, {
|
|
102
|
+
x: 0,
|
|
103
|
+
y: 0,
|
|
104
|
+
z: 0
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
polar,
|
|
108
|
+
azimuth
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */
|
|
112
|
+
function reachOf(extent) {
|
|
113
|
+
let reach = surfaceOf(extent);
|
|
114
|
+
for (const corner of extent.corners) reach = Math.max(reach, Math.hypot(corner.x - extent.center.x, corner.y - extent.center.y, corner.z - extent.center.z));
|
|
115
|
+
return reach;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.
|
|
119
|
+
*
|
|
120
|
+
* A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.
|
|
121
|
+
* The result is not less than the nearest depth of the limits, and it is in front of all the content.
|
|
122
|
+
*/
|
|
123
|
+
function nearDepth(limits, extent, distance) {
|
|
124
|
+
const free = (distance - reachOf(extent)) / 8;
|
|
125
|
+
return free > limits.near ? Math.min(free, limits.far / 4) : limits.near;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* This function gives the limits of the camera of a stage for a picture.
|
|
129
|
+
*
|
|
130
|
+
* The largest distance of the views is the base. The camera goes out to 3 times this distance, and in to 3 % of the height of that view.
|
|
131
|
+
* The extent can give each distance. The nearest depth is small against the height of the nearest camera, and the farthest depth is behind all the content.
|
|
132
|
+
*/
|
|
133
|
+
function stageLimits(frame, views, polar) {
|
|
134
|
+
const { extent } = frame;
|
|
135
|
+
const surface = surfaceOf(extent);
|
|
136
|
+
let widest = 0;
|
|
137
|
+
for (const view of views) widest = Math.max(widest, view(frame).distance);
|
|
138
|
+
if (!(widest > surface)) widest = surface + 1;
|
|
139
|
+
const reach = reachOf(extent);
|
|
140
|
+
const minDistance = extent.minDistance ?? surface + (widest - surface) * .03;
|
|
141
|
+
const maxDistance = Math.max(extent.maxDistance ?? surface + (widest - surface) * 3, minDistance);
|
|
142
|
+
const height = Math.max(minDistance - surface, 1e-6);
|
|
143
|
+
return {
|
|
144
|
+
minPolar: polar.min,
|
|
145
|
+
maxPolar: polar.max,
|
|
146
|
+
minDistance,
|
|
147
|
+
maxDistance,
|
|
148
|
+
near: height / 8,
|
|
149
|
+
far: (maxDistance + reach) * 1.5
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export { nearDepth as a, surfaceOf as c, fitView as i, ballView as n, reachOf as o, capView as r, stageLimits as s, FIT_MARGIN as t };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=extent-D2SsHJnP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extent-D2SsHJnP.js","names":[],"sources":["../src/extent.ts"],"sourcesContent":["import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { capDistance, fitDistance, viewOf, type Place, type PlaceLimits, type ViewAngles } from \"./view.ts\";\n\n/** The space that the content of a stage fills. A view and the limits of the camera come from it. */\nexport interface StageExtent {\n /** The points that a view of all the content shows, for example each corner of each solid. */\n readonly corners: readonly Point3[];\n /** The point that the camera looks at. */\n readonly center: Point3;\n /**\n * The radius of the ball around the center that the camera stays out of, for example the radius of a globe.\n * The default is 0: the content has no ball.\n */\n readonly surface?: number | undefined;\n /** The smallest distance of the camera from the center. The default comes from the views of the stage. */\n readonly minDistance?: number | undefined;\n /** The largest distance of the camera from the center. The default comes from the views of the stage. */\n readonly maxDistance?: number | undefined;\n}\n\n/** The picture that a view is for: the content, and the angle and the shape of the picture. */\nexport interface ViewFrame {\n readonly extent: StageExtent;\n /** The vertical angle of the picture, in degrees. */\n readonly fieldOfView: number;\n /** The width of the picture divided by its height. */\n readonly aspect: number;\n}\n\n/** A view of a stage: a function that gives the place of the camera for a picture. A new size of the picture gives a new place. */\nexport type StageView = (frame: ViewFrame) => Place;\n\n/** The limits of the camera of a stage: the limits of its place, and the nearest and the farthest depth that it draws. */\nexport interface StageLimits extends PlaceLimits {\n readonly near: number;\n readonly far: number;\n}\n\n/** The space around the content in a view that shows all of it, as a factor of the distance. */\nexport const FIT_MARGIN = 1.06;\n\n/** This function gives the radius of the ball around the center of an extent, or 0 for no ball. */\nexport function surfaceOf(extent: StageExtent): number {\n const surface = extent.surface ?? 0;\n return surface > 0 ? surface : 0;\n}\n\n/**\n * This function makes a view that shows each corner of the content from one direction.\n * `margin` is the space around the content, as a factor of the distance. An extent with no corners gives the distance 1.\n */\nexport function fitView(angles: ViewAngles, margin: number = FIT_MARGIN): StageView {\n return ({ extent, fieldOfView, aspect }) => {\n const distance = fitDistance(extent.corners, extent.center, angles, fieldOfView, aspect) * margin;\n return { target: extent.center, polar: angles.polar, azimuth: angles.azimuth, distance: distance > 0 ? distance : 1 };\n };\n}\n\n/**\n * This function makes a view of a part of the ball of the content: a cap around the point of the ball below the camera.\n *\n * `angles` is the direction from the center of the ball to the camera. `angle` is the angle of the cap at the center of the ball, in radians.\n * `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.\n */\nexport function capView(angles: ViewAngles, angle: number, margin: number = FIT_MARGIN): StageView {\n return ({ extent, fieldOfView, aspect }) => {\n const surface = surfaceOf(extent);\n const height = Math.max(capDistance(surface, angle, fieldOfView, aspect) - surface, 0);\n return { target: extent.center, polar: angles.polar, azimuth: angles.azimuth, distance: surface > 0 ? surface + height * margin : 1 };\n };\n}\n\n/**\n * This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.\n *\n * The middle is the center of the box of the points. The camera is at the smallest distance that shows each point in the width and in the height of the picture.\n * Thus wide points fill a wide picture. `margin` is the space around the points, as a factor of the height above the ball.\n * A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.\n */\nexport function ballView(points: readonly Point3[], margin: number = FIT_MARGIN): StageView {\n let found: { readonly center: Point3; readonly angles: ViewAngles | undefined } | undefined;\n return (frame) => {\n const { extent } = frame;\n const { center } = extent;\n // The middle is the same for each picture of one content. So the function calculates it one time for each center.\n if (found === undefined || found.center.x !== center.x || found.center.y !== center.y || found.center.z !== center.z) {\n found = { center, angles: middleOf(points, center) };\n }\n const { angles } = found;\n if (angles === undefined) return capView({ polar: Math.PI / 2, azimuth: 0 }, Math.PI / 2, margin)(frame);\n const surface = surfaceOf(extent);\n // A point of the ball needs no more distance than the outline of the ball. Thus the camera is not farther than a view of all of the ball.\n const height = Math.max(fitDistance(points, center, angles, frame.fieldOfView, frame.aspect) - surface, 0);\n return { target: center, polar: angles.polar, azimuth: angles.azimuth, distance: surface > 0 ? surface + height * margin : 1 };\n };\n}\n\n/** This function gives the direction from `center` to the middle of the box of the points. It gives `undefined` when the middle has no direction. */\nfunction middleOf(points: readonly Point3[], center: Point3): ViewAngles | undefined {\n const low = { x: Infinity, y: Infinity, z: Infinity };\n const high = { x: -Infinity, y: -Infinity, z: -Infinity };\n for (const point of points) {\n low.x = Math.min(low.x, point.x);\n low.y = Math.min(low.y, point.y);\n low.z = Math.min(low.z, point.z);\n high.x = Math.max(high.x, point.x);\n high.y = Math.max(high.y, point.y);\n high.z = Math.max(high.z, point.z);\n }\n const middle = { x: (low.x + high.x) / 2 - center.x, y: (low.y + high.y) / 2 - center.y, z: (low.z + high.z) / 2 - center.z };\n const length = Math.hypot(middle.x, middle.y, middle.z);\n if (!(length > 0) || !Number.isFinite(length)) return undefined;\n const { polar, azimuth } = viewOf(middle, { x: 0, y: 0, z: 0 });\n return { polar, azimuth };\n}\n\n/** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */\nexport function reachOf(extent: StageExtent): number {\n let reach = surfaceOf(extent);\n for (const corner of extent.corners) reach = Math.max(reach, Math.hypot(corner.x - extent.center.x, corner.y - extent.center.y, corner.z - extent.center.z));\n return reach;\n}\n\n/**\n * This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.\n *\n * A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.\n * The result is not less than the nearest depth of the limits, and it is in front of all the content.\n */\nexport function nearDepth(limits: StageLimits, extent: StageExtent, distance: number): number {\n const free = (distance - reachOf(extent)) / 8;\n return free > limits.near ? Math.min(free, limits.far / 4) : limits.near;\n}\n\n/**\n * This function gives the limits of the camera of a stage for a picture.\n *\n * The largest distance of the views is the base. The camera goes out to 3 times this distance, and in to 3 % of the height of that view.\n * The extent can give each distance. The nearest depth is small against the height of the nearest camera, and the farthest depth is behind all the content.\n */\nexport function stageLimits(frame: ViewFrame, views: readonly StageView[], polar: { readonly min: number; readonly max: number }): StageLimits {\n const { extent } = frame;\n const surface = surfaceOf(extent);\n let widest = 0;\n for (const view of views) widest = Math.max(widest, view(frame).distance);\n if (!(widest > surface)) widest = surface + 1;\n const reach = reachOf(extent);\n const minDistance = extent.minDistance ?? surface + (widest - surface) * 0.03;\n const maxDistance = Math.max(extent.maxDistance ?? surface + (widest - surface) * 3, minDistance);\n const height = Math.max(minDistance - surface, 1e-6);\n return { minPolar: polar.min, maxPolar: polar.max, minDistance, maxDistance, near: height / 8, far: (maxDistance + reach) * 1.5 };\n}\n"],"mappings":"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"}
|
package/build/globe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as StageContent } from "./stage-
|
|
1
|
+
import { r as StageContent } from "./stage-DmFfah2e.js";
|
|
2
2
|
import { C as ViewAngles, d as StageView, t as StageTheme } from "./theme-3EGbXXoP.js";
|
|
3
3
|
import { Raycaster } from "three";
|
|
4
4
|
import { LatLon, Region } from "@mark1russell7/geo";
|
|
@@ -11,6 +11,13 @@ interface GlobeStyle {
|
|
|
11
11
|
readonly opacity?: number | undefined;
|
|
12
12
|
/** The color of the edge of an area, or of the ring around a point. An area with no color has no edge. */
|
|
13
13
|
readonly line?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The lengths of a dash and of a gap of the edge of an area, in CSS pixels. An edge with no `dash` is a solid line.
|
|
16
|
+
* The lengths are correct on the surface below the camera, at each distance of the camera. Near the rim of the Earth, a dash is shorter in the picture.
|
|
17
|
+
* A length that is not more than 0 gives a solid line.
|
|
18
|
+
* The edge of a record with a highlight keeps the dash, and the ring of a point has no dash.
|
|
19
|
+
*/
|
|
20
|
+
readonly dash?: readonly [dash: number, gap: number] | undefined;
|
|
14
21
|
}
|
|
15
22
|
/** The colors of a globe. Each color is a CSS hex color. */
|
|
16
23
|
interface GlobeTheme extends StageTheme {
|
package/build/globe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globe.d.ts","names":[],"sources":["../src/globe/content.ts","../src/globe/mesh.ts","../src/globe/space.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"globe.d.ts","names":[],"sources":["../src/globe/content.ts","../src/globe/mesh.ts","../src/globe/space.ts"],"mappings":";;;;;;UA8BiB;;WAEN;;WAEA;;WAEA;;;;;;;WAOA,iBAAiB,cAAc;;;UAIzB,mBAAmB;;WAEzB;;WAEA;;WAEA;;WAEA,QAAQ,SAAS,eAAe;;WAEhC,OAAO;;WAEP;;WAEA;;;UAIM,UAAU;;WAEhB;;WAEA,QAAQ;;WAER;;WAEA,OAAO;;WAEP;;;UAIM,WAAW;;WAEjB;WACA,OAAO;;WAEP;;WAEA,OAAO;;WAEP;;WAEA;;;UAIM,aAAa;;WAEnB,iBAAiB,UAAU;;WAE3B,kBAAkB,WAAW;;WAE7B;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM,aAAa,WAAW,aAAa,GAAG;;;;;EAKvD,KAAK,OAAO,MAAM,UAAU,KAAK,WAAW;;EAE5C,QAAQ,KAAK,YAAY;;;;;;wBAmBX,YAAY;;;;;;;wBAyKZ,YAAY,GAAG,UAAS,aAAa,KAAU,aAAa;;;;;UCpT3D;;WAEN,SAAS;;WAET,WAAW;;;qBAIT;;;;;wBA0CG,WAAW;;;;;;;;;;;;;wBAyOX,cAAc,QAAQ,QAAQ,cAAc,sBAA2C;;;;;;;;wBA6GvF,YAAY,QAAQ,QAAQ,eAAe;;;;;;;wBA4E3C,UAAU,iBAAiB,eAAe;;;;;qBCld7C;WAAwB;WAAsB;;;;;;;;wBAU3C,WAAW,OAAO,QAAQ,kBAAqB;;;;;wBAS/C,WAAW,OAAO,SAAS;;wBAO3B,YAAY,OAAO,SAAS;;;;;;;wBAU5B,UAAU,OAAO,QAAQ,kBAAsB,kBAA8B;;;;;;wBAS7E,WAAW,kBAAkB,UAAU,kBAA8B;;;;;;wBAiBrE,QAAQ,QAAQ,QAAQ,WAAW,QAAQ,iBAAiB;;;;;wBAe5D,QAAQ,OAAO,QAAQ,KAAK,QAAQ"}
|
package/build/globe.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as ballView, r as capView, t as FIT_MARGIN } from "./extent-
|
|
2
|
-
import { BufferAttribute, BufferGeometry, Color, FrontSide, InstancedInterleavedBuffer, InterleavedBufferAttribute, Mesh, MeshBasicMaterial, Points, ShaderMaterial, ShapeUtils, Sphere, SphereGeometry, Vector2, Vector3 } from "three";
|
|
1
|
+
import { n as ballView, r as capView, t as FIT_MARGIN } from "./extent-D2SsHJnP.js";
|
|
2
|
+
import { BufferAttribute, BufferGeometry, Color, FrontSide, Group, InstancedInterleavedBuffer, InterleavedBufferAttribute, Mesh, MeshBasicMaterial, Points, ShaderMaterial, ShapeUtils, Sphere, SphereGeometry, Vector2, Vector3 } from "three";
|
|
3
3
|
import { densify, fromUnitVector, pointLocator, toUnitVector } from "@mark1russell7/geo";
|
|
4
4
|
import { LineMaterial } from "three/addons/lines/LineMaterial.js";
|
|
5
5
|
import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
|
|
@@ -633,15 +633,31 @@ void main() {
|
|
|
633
633
|
if (gl_FragColor.a <= 0.0) discard;
|
|
634
634
|
#include <colorspace_fragment>
|
|
635
635
|
}`;
|
|
636
|
+
/** This function gives the dash of a style. A style with no dash gives `undefined`, and so does a length that is not more than 0. */
|
|
637
|
+
function dashOf(style) {
|
|
638
|
+
const [dash, gap] = style.dash ?? [0, 0];
|
|
639
|
+
return Number.isFinite(dash) && Number.isFinite(gap) && dash > 0 && gap > 0 ? [dash, gap] : void 0;
|
|
640
|
+
}
|
|
641
|
+
/** This function adds an area to the areas with the same pattern of a dash. */
|
|
642
|
+
function addPattern(patterns, dash, part) {
|
|
643
|
+
const pattern = dash.join(" ");
|
|
644
|
+
const same = patterns.get(pattern);
|
|
645
|
+
if (same === void 0) patterns.set(pattern, [part]);
|
|
646
|
+
else same.push(part);
|
|
647
|
+
}
|
|
636
648
|
/** This function gives the text of a thrown value. */
|
|
637
649
|
function messageOf(error) {
|
|
638
650
|
return error instanceof Error ? error.message : String(error);
|
|
639
651
|
}
|
|
640
|
-
/**
|
|
641
|
-
function
|
|
652
|
+
/**
|
|
653
|
+
* This function writes the points of lines into a list of segments on a ball: six numbers for each segment. It gives the count of the segments.
|
|
654
|
+
* With `lengths`, it also writes two numbers for each segment: the length of the line to the start of the segment, and to its end.
|
|
655
|
+
*/
|
|
656
|
+
function addSegments(lines, radius, to, lengths) {
|
|
642
657
|
let count = 0;
|
|
643
658
|
for (const line of lines) {
|
|
644
659
|
let from;
|
|
660
|
+
let length = 0;
|
|
645
661
|
for (let index = 0; index + 1 < line.length; index += 2) {
|
|
646
662
|
const next = globePoint({
|
|
647
663
|
lat: line[index + 1] ?? 0,
|
|
@@ -649,6 +665,11 @@ function addSegments(lines, radius, to) {
|
|
|
649
665
|
}, radius);
|
|
650
666
|
if (from !== void 0) {
|
|
651
667
|
to.push(from.x, from.y, from.z, next.x, next.y, next.z);
|
|
668
|
+
if (lengths !== void 0) {
|
|
669
|
+
const end = length + Math.hypot(next.x - from.x, next.y - from.y, next.z - from.z);
|
|
670
|
+
lengths.push(length, end);
|
|
671
|
+
length = end;
|
|
672
|
+
}
|
|
652
673
|
count += 1;
|
|
653
674
|
}
|
|
654
675
|
from = next;
|
|
@@ -713,13 +734,14 @@ function createGlobe(options = {}) {
|
|
|
713
734
|
grid.frustumCulled = false;
|
|
714
735
|
const surfaces = [];
|
|
715
736
|
const segmentList = [];
|
|
737
|
+
const lengthList = [];
|
|
716
738
|
const areaParts = [];
|
|
717
739
|
let cornerTotal = 0;
|
|
718
740
|
let indexTotal = 0;
|
|
719
741
|
let segmentTotal = 0;
|
|
720
742
|
for (const area of options.areas ?? []) try {
|
|
721
743
|
const surface = regionSurface(area.region, step);
|
|
722
|
-
const segmentCount = addSegments(regionEdges(area.region, step), layer, segmentList);
|
|
744
|
+
const segmentCount = addSegments(regionEdges(area.region, step), layer, segmentList, lengthList);
|
|
723
745
|
areaParts.push({
|
|
724
746
|
area,
|
|
725
747
|
locate: area.pick === false ? void 0 : pointLocator(area.region),
|
|
@@ -732,6 +754,7 @@ function createGlobe(options = {}) {
|
|
|
732
754
|
shown: true,
|
|
733
755
|
filled: false,
|
|
734
756
|
lined: false,
|
|
757
|
+
dash: void 0,
|
|
735
758
|
highlight: 0
|
|
736
759
|
});
|
|
737
760
|
surfaces.push(surface);
|
|
@@ -789,6 +812,14 @@ function createGlobe(options = {}) {
|
|
|
789
812
|
const edges = new LineSegments2(edgeGeometry, edgeMaterial);
|
|
790
813
|
edges.renderOrder = 3;
|
|
791
814
|
edges.frustumCulled = false;
|
|
815
|
+
const allLengths = Float32Array.from(lengthList);
|
|
816
|
+
const dashed = new Group();
|
|
817
|
+
let dashedLines = [];
|
|
818
|
+
let litLines = [];
|
|
819
|
+
/** The text of the dashed edges of the last picture. The globe makes the objects again only for a different text. */
|
|
820
|
+
let dashedText = "[]";
|
|
821
|
+
/** The count of CSS pixels of one unit of the stage, on the surface below the camera. */
|
|
822
|
+
let dashScale = 1;
|
|
792
823
|
const highlightMaterial = new LineMaterial({
|
|
793
824
|
linewidth: options.highlightWidth ?? 2.5,
|
|
794
825
|
vertexColors: true,
|
|
@@ -853,6 +884,7 @@ function createGlobe(options = {}) {
|
|
|
853
884
|
const style = styleOf(theme, part.area.kind);
|
|
854
885
|
part.filled = style.fill !== void 0;
|
|
855
886
|
part.lined = style.line !== void 0;
|
|
887
|
+
part.dash = dashOf(style);
|
|
856
888
|
if (style.fill !== void 0) {
|
|
857
889
|
color.set(style.fill);
|
|
858
890
|
const opacity = Math.min(Math.max(style.opacity ?? 1, 0), 1);
|
|
@@ -879,25 +911,109 @@ function createGlobe(options = {}) {
|
|
|
879
911
|
for (let segment = 0; segment < part.segmentCount; segment++) allSegmentColors.set(values, (part.firstSegment + segment) * 6);
|
|
880
912
|
}
|
|
881
913
|
};
|
|
914
|
+
/** This function releases objects of the edges with dashes, and removes them from the picture. */
|
|
915
|
+
const release = (lines) => {
|
|
916
|
+
for (const line of lines) {
|
|
917
|
+
line.geometry.dispose();
|
|
918
|
+
line.material.dispose();
|
|
919
|
+
dashed.remove(line);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
/**
|
|
923
|
+
* This function makes one object of edges with dashes for each pattern, from the segments of the areas of the pattern.
|
|
924
|
+
* `paint` writes the colors of the segments of an area into a list, from a position of the list.
|
|
925
|
+
*/
|
|
926
|
+
const dashedObjects = (patterns, width, order, paint) => {
|
|
927
|
+
const lines = [];
|
|
928
|
+
for (const parts of patterns.values()) {
|
|
929
|
+
const dash = parts[0]?.dash;
|
|
930
|
+
if (dash === void 0) continue;
|
|
931
|
+
const count = parts.reduce((sum, part) => sum + part.segmentCount, 0);
|
|
932
|
+
const positions = new Float32Array(count * 6);
|
|
933
|
+
const colors = new Float32Array(count * 6);
|
|
934
|
+
const lengths = new Float32Array(count * 2);
|
|
935
|
+
let at = 0;
|
|
936
|
+
for (const part of parts) {
|
|
937
|
+
const to = part.firstSegment + part.segmentCount;
|
|
938
|
+
positions.set(allSegments.subarray(part.firstSegment * 6, to * 6), at * 6);
|
|
939
|
+
paint(part, colors, at * 6);
|
|
940
|
+
lengths.set(allLengths.subarray(part.firstSegment * 2, to * 2), at * 2);
|
|
941
|
+
at += part.segmentCount;
|
|
942
|
+
}
|
|
943
|
+
const geometry = segmentGeometry(new InstancedInterleavedBuffer(positions, 6, 1), new InstancedInterleavedBuffer(colors, 6, 1), count, bounds);
|
|
944
|
+
const distances = new InstancedInterleavedBuffer(lengths, 2, 1);
|
|
945
|
+
geometry.setAttribute("instanceDistanceStart", new InterleavedBufferAttribute(distances, 1, 0));
|
|
946
|
+
geometry.setAttribute("instanceDistanceEnd", new InterleavedBufferAttribute(distances, 1, 1));
|
|
947
|
+
const material = new LineMaterial({
|
|
948
|
+
linewidth: width,
|
|
949
|
+
vertexColors: true,
|
|
950
|
+
transparent: true,
|
|
951
|
+
depthWrite: false,
|
|
952
|
+
dashed: true,
|
|
953
|
+
dashSize: dash[0],
|
|
954
|
+
gapSize: dash[1],
|
|
955
|
+
dashScale
|
|
956
|
+
});
|
|
957
|
+
const line = new LineSegments2(geometry, material);
|
|
958
|
+
line.renderOrder = order;
|
|
959
|
+
line.frustumCulled = false;
|
|
960
|
+
dashed.add(line);
|
|
961
|
+
lines.push(line);
|
|
962
|
+
}
|
|
963
|
+
return lines;
|
|
964
|
+
};
|
|
965
|
+
/** This function makes the objects of the edges with dashes: one object for each pattern, with the segments of its areas. */
|
|
966
|
+
const syncDashed = (patterns, theme) => {
|
|
967
|
+
const text = JSON.stringify([...patterns].map(([pattern, parts]) => [pattern, parts.map((part) => [part.firstSegment, styleOf(theme, part.area.kind).line])]));
|
|
968
|
+
if (text === dashedText) return;
|
|
969
|
+
dashedText = text;
|
|
970
|
+
release(dashedLines);
|
|
971
|
+
dashedLines = dashedObjects(patterns, options.lineWidth ?? 1.25, 3, (part, colors, at) => {
|
|
972
|
+
colors.set(allSegmentColors.subarray(part.firstSegment * 6, (part.firstSegment + part.segmentCount) * 6), at);
|
|
973
|
+
});
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* This function makes the dashed edges of the records with a highlight: one object for each pattern, above the other edges.
|
|
977
|
+
* They are few, and a record changes its highlight only on an act of a person. So the globe makes them again at each change.
|
|
978
|
+
*/
|
|
979
|
+
const syncLit = (patterns, theme) => {
|
|
980
|
+
release(litLines);
|
|
981
|
+
litLines = dashedObjects(patterns, options.highlightWidth ?? 2.5, 5, (part, colors, at) => {
|
|
982
|
+
color.set(highlightColor(theme, part.highlight));
|
|
983
|
+
const values = [
|
|
984
|
+
color.r,
|
|
985
|
+
color.g,
|
|
986
|
+
color.b,
|
|
987
|
+
color.r,
|
|
988
|
+
color.g,
|
|
989
|
+
color.b
|
|
990
|
+
];
|
|
991
|
+
for (let segment = 0; segment < part.segmentCount; segment++) colors.set(values, at + segment * 6);
|
|
992
|
+
});
|
|
993
|
+
};
|
|
882
994
|
/** This function puts the data of the shown parts at the start of the buffers that the picture draws. */
|
|
883
995
|
const sync = (theme) => {
|
|
884
996
|
let indexCount = 0;
|
|
885
997
|
let segmentCount = 0;
|
|
886
998
|
let highlightCount = 0;
|
|
999
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
1000
|
+
const lit = /* @__PURE__ */ new Map();
|
|
887
1001
|
for (const part of areaParts) {
|
|
888
1002
|
if (!part.shown) continue;
|
|
889
1003
|
if (part.filled) {
|
|
890
1004
|
fillIndices.array.set(allIndices.subarray(part.firstIndex, part.firstIndex + part.indexCount), indexCount);
|
|
891
1005
|
indexCount += part.indexCount;
|
|
892
1006
|
}
|
|
893
|
-
if (part.lined)
|
|
1007
|
+
if (part.lined && part.dash !== void 0) addPattern(patterns, part.dash, part);
|
|
1008
|
+
else if (part.lined) {
|
|
894
1009
|
const from = part.firstSegment * 6;
|
|
895
1010
|
const to = from + part.segmentCount * 6;
|
|
896
1011
|
edgePositions.array.set(allSegments.subarray(from, to), segmentCount * 6);
|
|
897
1012
|
edgeColors.array.set(allSegmentColors.subarray(from, to), segmentCount * 6);
|
|
898
1013
|
segmentCount += part.segmentCount;
|
|
899
1014
|
}
|
|
900
|
-
if (part.highlight !== 0)
|
|
1015
|
+
if (part.highlight !== 0 && part.dash !== void 0) addPattern(lit, part.dash, part);
|
|
1016
|
+
else if (part.highlight !== 0) highlightCount += part.segmentCount;
|
|
901
1017
|
}
|
|
902
1018
|
fillIndices.needsUpdate = true;
|
|
903
1019
|
fillGeometry.setDrawRange(0, indexCount);
|
|
@@ -906,11 +1022,13 @@ function createGlobe(options = {}) {
|
|
|
906
1022
|
edgeColors.needsUpdate = true;
|
|
907
1023
|
edgeGeometry.instanceCount = segmentCount;
|
|
908
1024
|
edges.visible = segmentCount > 0;
|
|
1025
|
+
syncDashed(patterns, theme);
|
|
1026
|
+
syncLit(lit, theme);
|
|
909
1027
|
const highlightPositions = new Float32Array(highlightCount * 6);
|
|
910
1028
|
const highlightColors = new Float32Array(highlightCount * 6);
|
|
911
1029
|
let at = 0;
|
|
912
1030
|
for (const part of areaParts) {
|
|
913
|
-
if (!part.shown || part.highlight === 0) continue;
|
|
1031
|
+
if (!part.shown || part.highlight === 0 || part.dash !== void 0) continue;
|
|
914
1032
|
color.set(highlightColor(theme, part.highlight));
|
|
915
1033
|
const values = [
|
|
916
1034
|
color.r,
|
|
@@ -956,6 +1074,7 @@ function createGlobe(options = {}) {
|
|
|
956
1074
|
grid,
|
|
957
1075
|
fills,
|
|
958
1076
|
edges,
|
|
1077
|
+
dashed,
|
|
959
1078
|
shade,
|
|
960
1079
|
highlighted,
|
|
961
1080
|
dots
|
|
@@ -1021,6 +1140,10 @@ function createGlobe(options = {}) {
|
|
|
1021
1140
|
},
|
|
1022
1141
|
step(frame) {
|
|
1023
1142
|
pixelAngle = 2 * Math.tan(frame.fieldOfView * Math.PI / 360) / Math.max(frame.height, 1);
|
|
1143
|
+
const height = Math.max(frame.camera.position.length() - radius, radius * 1e-6);
|
|
1144
|
+
dashScale = 1 / (pixelAngle * height);
|
|
1145
|
+
for (const line of dashedLines) line.material.dashScale = dashScale;
|
|
1146
|
+
for (const line of litLines) line.material.dashScale = dashScale;
|
|
1024
1147
|
return false;
|
|
1025
1148
|
},
|
|
1026
1149
|
show(test) {
|
|
@@ -1042,6 +1165,10 @@ function createGlobe(options = {}) {
|
|
|
1042
1165
|
fillMaterial.dispose();
|
|
1043
1166
|
edgeGeometry.dispose();
|
|
1044
1167
|
edgeMaterial.dispose();
|
|
1168
|
+
release(dashedLines);
|
|
1169
|
+
release(litLines);
|
|
1170
|
+
dashedLines = [];
|
|
1171
|
+
litLines = [];
|
|
1045
1172
|
highlighted.geometry.dispose();
|
|
1046
1173
|
highlightMaterial.dispose();
|
|
1047
1174
|
pointGeometry.dispose();
|