@dxos/react-ui-geo 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/chunk-data.mjs +7 -2
- package/dist/lib/chunk-data.mjs.map +1 -1
- package/dist/lib/index.mjs +22 -18
- package/dist/lib/index.mjs.map +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +2 -0
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/util/styles.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -17
- package/src/components/Globe/Globe.stories.tsx +77 -1
- package/src/components/Globe/Globe.tsx +4 -1
- package/src/components/Map/Map.tsx +5 -4
- package/src/components/Toolbar/Controls.tsx +2 -2
- package/src/data.ts +10 -2
- package/src/hooks/useTour.ts +1 -1
- package/src/typings.d.ts +8 -0
- package/src/util/styles.ts +21 -11
- package/data/countries-10m.ts +0 -12
- package/data/countries-50m.ts +0 -12
- package/dist/lib/chunk-countries-10m.mjs +0 -10
- package/dist/lib/chunk-countries-10m.mjs.map +0 -1
- package/dist/lib/chunk-countries-50m.mjs +0 -10
- package/dist/lib/chunk-countries-50m.mjs.map +0 -1
- package/dist/types/data/countries-10m.d.ts +0 -8
- package/dist/types/data/countries-10m.d.ts.map +0 -1
- package/dist/types/data/countries-50m.d.ts +0 -8
- package/dist/types/data/countries-50m.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-geo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Geo components.",
|
|
5
5
|
"homepage": "https://github.com/dxos",
|
|
6
6
|
"bugs": "https://github.com/dxos/issues",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"types": "./dist/types/src/data.d.ts",
|
|
31
31
|
"import": "./dist/lib/data.mjs"
|
|
32
32
|
},
|
|
33
|
+
"./data/raw/*": "./data/raw/*",
|
|
33
34
|
"./translations": {
|
|
34
35
|
"source": "./src/translations.ts",
|
|
35
36
|
"types": "./dist/types/src/translations.d.ts",
|
|
@@ -48,6 +49,11 @@
|
|
|
48
49
|
"src"
|
|
49
50
|
],
|
|
50
51
|
"dependencies": {
|
|
52
|
+
"@dxos/debug": "0.17.0",
|
|
53
|
+
"@dxos/log": "0.17.0",
|
|
54
|
+
"@dxos/node-std": "0.17.0",
|
|
55
|
+
"@dxos/react-hooks": "0.17.0",
|
|
56
|
+
"@dxos/ui-types": "0.17.0",
|
|
51
57
|
"@types/topojson-specification": "^1.0.5",
|
|
52
58
|
"d3": "^7.9.0",
|
|
53
59
|
"geojson": "^0.5.0",
|
|
@@ -56,35 +62,30 @@
|
|
|
56
62
|
"react-resize-detector": "^11.0.1",
|
|
57
63
|
"topojson-client": "^3.1.0",
|
|
58
64
|
"topojson-simplify": "^3.0.3",
|
|
59
|
-
"versor": "^0.2.0"
|
|
60
|
-
"@dxos/debug": "0.16.0",
|
|
61
|
-
"@dxos/node-std": "0.16.0",
|
|
62
|
-
"@dxos/react-hooks": "0.16.0",
|
|
63
|
-
"@dxos/ui-types": "0.16.0",
|
|
64
|
-
"@dxos/log": "0.16.0"
|
|
65
|
+
"versor": "^0.2.0"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
68
|
+
"@dxos/react-ui": "0.17.0",
|
|
69
|
+
"@dxos/ui-theme": "0.17.0",
|
|
67
70
|
"@storybook/react-vite": "^10.6.0",
|
|
68
71
|
"@types/d3": "^7.4.3",
|
|
69
72
|
"@types/geojson": "^7946.0.14",
|
|
70
73
|
"@types/leaflet": "^1.9.16",
|
|
71
|
-
"@types/react": "~19.
|
|
72
|
-
"@types/react-dom": "~19.
|
|
74
|
+
"@types/react": "~19.3.0",
|
|
75
|
+
"@types/react-dom": "~19.3.0",
|
|
73
76
|
"@types/topojson-client": "^3.1.4",
|
|
74
77
|
"@types/topojson-simplify": "^3.0.3",
|
|
75
78
|
"JSONStream": "^1.3.5",
|
|
76
79
|
"geojson2h3": "^1.2.0",
|
|
77
80
|
"leva": "^0.10.1",
|
|
78
|
-
"react": "~19.
|
|
79
|
-
"react-dom": "~19.
|
|
80
|
-
"@dxos/react-ui": "0.16.0",
|
|
81
|
-
"@dxos/ui-theme": "0.16.0"
|
|
81
|
+
"react": "~19.3.1",
|
|
82
|
+
"react-dom": "~19.3.1"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"react": "
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
85
|
+
"@dxos/react-ui": "^0.17.0",
|
|
86
|
+
"@dxos/ui-theme": "^0.17.0",
|
|
87
|
+
"react": "~19.3.1",
|
|
88
|
+
"react-dom": "~19.3.1"
|
|
88
89
|
},
|
|
89
90
|
"publishConfig": {
|
|
90
91
|
"access": "public"
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import { type FeatureCollection, type Geometry, type Position } from 'geojson';
|
|
7
7
|
import { Leva } from 'leva';
|
|
8
|
-
import React, { useMemo, useState } from 'react';
|
|
8
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
9
|
import { type Topology } from 'topojson-specification';
|
|
10
10
|
|
|
11
11
|
import * as Hooks from '@dxos/react-ui/Hooks';
|
|
@@ -449,3 +449,79 @@ export const VersorDrag: Story = {
|
|
|
449
449
|
styles: defaultStyles,
|
|
450
450
|
},
|
|
451
451
|
};
|
|
452
|
+
|
|
453
|
+
//
|
|
454
|
+
// Docs
|
|
455
|
+
//
|
|
456
|
+
|
|
457
|
+
const TRIP = [
|
|
458
|
+
{ lat: 51.5074, lng: -0.1278 },
|
|
459
|
+
{ lat: 40.7128, lng: -74.006 },
|
|
460
|
+
{ lat: 35.6762, lng: 139.6503 },
|
|
461
|
+
{ lat: -33.8688, lng: 151.2093 },
|
|
462
|
+
{ lat: -23.5505, lng: -46.6333 },
|
|
463
|
+
];
|
|
464
|
+
|
|
465
|
+
const TRIP_LEGS = TRIP.map((source, index) => ({ source, target: TRIP[(index + 1) % TRIP.length] }));
|
|
466
|
+
|
|
467
|
+
const TRIP_STYLES: Record<'light' | 'dark', StyleSet> = {
|
|
468
|
+
light: {
|
|
469
|
+
background: { fillStyle: '#EEE' },
|
|
470
|
+
water: { fillStyle: '#555' },
|
|
471
|
+
land: { fillStyle: '#999' },
|
|
472
|
+
line: { strokeStyle: '#b91c1c', lineWidth: 1, lineDash: [4, 6] },
|
|
473
|
+
point: { fillStyle: '#b91c1c', pointRadius: 3 },
|
|
474
|
+
arc: { strokeStyle: '#f97316', lineWidth: 2 },
|
|
475
|
+
cursor: { fillStyle: '#f97316', pointRadius: 3 },
|
|
476
|
+
},
|
|
477
|
+
dark: {
|
|
478
|
+
background: { fillStyle: '#111' },
|
|
479
|
+
water: { fillStyle: '#123E6A' },
|
|
480
|
+
land: { fillStyle: '#032153' },
|
|
481
|
+
line: { strokeStyle: '#fbbf24', lineWidth: 1, lineDash: [4, 6] },
|
|
482
|
+
point: { fillStyle: '#f87171', pointRadius: 3 },
|
|
483
|
+
arc: { strokeStyle: '#fbbf24', lineWidth: 2 },
|
|
484
|
+
cursor: { fillStyle: '#fbbf24', pointRadius: 3 },
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const TripStory = () => {
|
|
489
|
+
const themeMode = Hooks.useThemeMode();
|
|
490
|
+
const [topology] = Hooks.useAsyncState(() => loadTopology('110m'), []);
|
|
491
|
+
const [controller, setController] = useState<GlobeController | null>(null);
|
|
492
|
+
const [dragging, setDragging] = useState(false);
|
|
493
|
+
const handleZoom = useGlobeZoomHandler(controller);
|
|
494
|
+
const styles = TRIP_STYLES[themeMode];
|
|
495
|
+
const [running, setRunning] = useTour(controller, TRIP, { loop: true, duration: 2_000, styles });
|
|
496
|
+
useDrag(controller, {
|
|
497
|
+
onUpdate: ({ type }) => {
|
|
498
|
+
setDragging(type !== 'end');
|
|
499
|
+
if (type === 'start') {
|
|
500
|
+
setRunning(false);
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// The tour needs a mounted canvas; it resumes after a pause once a lap ends or the user lets go.
|
|
506
|
+
useEffect(() => {
|
|
507
|
+
if (running || dragging || !controller?.canvas) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const timeout = setTimeout(() => setRunning(true), 1_500);
|
|
511
|
+
return () => clearTimeout(timeout);
|
|
512
|
+
}, [controller, running, dragging]);
|
|
513
|
+
|
|
514
|
+
return (
|
|
515
|
+
<Globe.Root zoom={1} rotation={[0, -20, 0]} ref={setController}>
|
|
516
|
+
<Globe.Viewport>
|
|
517
|
+
<Globe.Canvas topology={topology} styles={styles} features={{ points: TRIP, lines: TRIP_LEGS }} />
|
|
518
|
+
<Globe.Zoom onAction={handleZoom} />
|
|
519
|
+
</Globe.Viewport>
|
|
520
|
+
</Globe.Root>
|
|
521
|
+
);
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
/** The docs' globe: flies a trip from stop to stop; drag to take over, and the tour resumes after. */
|
|
525
|
+
export const Docs: Story = {
|
|
526
|
+
render: () => <TripStory />,
|
|
527
|
+
};
|
|
@@ -120,9 +120,12 @@ const SPHERE = { type: 'Sphere' } as const;
|
|
|
120
120
|
* The scale at zoom 1. With a `fit`, the sphere's projected bounds are measured at unit scale and
|
|
121
121
|
* scaled to fit inside (`contain`) or fill (`cover`) the canvas, whatever the projection's shape.
|
|
122
122
|
*/
|
|
123
|
+
/** The unfitted globe's diameter as a fraction of the shorter side, so at rest it does not touch the edges. */
|
|
124
|
+
const GLOBE_EXTENT = 0.9;
|
|
125
|
+
|
|
123
126
|
const baseScale = (projection: GeoProjection, size: { width: number; height: number }, fit?: GlobeFit): number => {
|
|
124
127
|
if (!fit) {
|
|
125
|
-
return Math.min(size.width, size.height) / 2;
|
|
128
|
+
return (Math.min(size.width, size.height) / 2) * GLOBE_EXTENT;
|
|
126
129
|
}
|
|
127
130
|
const [[x0, y0], [x1, y1]] = geoPath(projection.scale(1).translate([0, 0]).rotate([0, 0, 0])).bounds(SPHERE);
|
|
128
131
|
const ratios = [size.width / (x1 - x0), size.height / (y1 - y0)];
|
|
@@ -389,10 +389,11 @@ const MapMarkers = ({ selected, markers, lines, onSelect }: MapMarkersProps) =>
|
|
|
389
389
|
iconUrl: 'https://media.dxos.network/marker-icon.png',
|
|
390
390
|
iconRetinaUrl: 'https://media.dxos.network/marker-icon-2x.png',
|
|
391
391
|
shadowUrl: 'https://media.dxos.network/marker-shadow.png',
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
// 60% of Leaflet's default pin, so dense clusters (a city's data centres) stay readable.
|
|
393
|
+
iconSize: [15, 25],
|
|
394
|
+
iconAnchor: [7.5, 25],
|
|
395
|
+
popupAnchor: [0.5, -20],
|
|
396
|
+
shadowSize: [25, 25],
|
|
396
397
|
})
|
|
397
398
|
}
|
|
398
399
|
>
|
|
@@ -21,7 +21,7 @@ export const ZoomControls = ({ classNames, onAction }: ControlProps) => {
|
|
|
21
21
|
const { t } = Hooks.useTranslation(translationKey);
|
|
22
22
|
|
|
23
23
|
return (
|
|
24
|
-
<Toolbar.Root classNames={['gap-
|
|
24
|
+
<Toolbar.Root classNames={['gap-1', classNames]}>
|
|
25
25
|
<Button.Root
|
|
26
26
|
icon='ph--plus--regular'
|
|
27
27
|
iconOnly
|
|
@@ -42,7 +42,7 @@ export const ActionControls = ({ classNames, onAction }: ControlProps) => {
|
|
|
42
42
|
const { t } = Hooks.useTranslation(translationKey);
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
|
-
<Toolbar.Root classNames={['gap-
|
|
45
|
+
<Toolbar.Root classNames={['gap-1', classNames]}>
|
|
46
46
|
<Button.Root
|
|
47
47
|
icon='ph--path--regular'
|
|
48
48
|
iconOnly
|
package/src/data.ts
CHANGED
|
@@ -18,11 +18,19 @@ export type CountriesResolution = '110m' | '50m' | '10m';
|
|
|
18
18
|
export const loadTopology = async (resolution: CountriesResolution = '110m'): Promise<Topology> => {
|
|
19
19
|
switch (resolution) {
|
|
20
20
|
case '10m':
|
|
21
|
-
return (await import('
|
|
21
|
+
return fetchTopologyFile((await import('@dxos/react-ui-geo/data/raw/countries-10m.json?url')).default);
|
|
22
22
|
case '50m':
|
|
23
|
-
return (await import('
|
|
23
|
+
return fetchTopologyFile((await import('@dxos/react-ui-geo/data/raw/countries-50m.json?url')).default);
|
|
24
24
|
case '110m':
|
|
25
25
|
default:
|
|
26
26
|
return (await import('../data/countries-110m.ts')).default;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
|
|
30
|
+
const fetchTopologyFile = async (url: string): Promise<Topology> => {
|
|
31
|
+
const response = await fetch(url);
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`Failed to load topology: ${url} (${response.status})`);
|
|
34
|
+
}
|
|
35
|
+
return response.json();
|
|
36
|
+
};
|
package/src/hooks/useTour.ts
CHANGED
|
@@ -70,7 +70,7 @@ export const useTour = (
|
|
|
70
70
|
context.save();
|
|
71
71
|
try {
|
|
72
72
|
context.beginPath();
|
|
73
|
-
context.strokeStyle = options.styles?.arc?.strokeStyle ?? '
|
|
73
|
+
context.strokeStyle = options.styles?.arc?.strokeStyle ?? 'rgb(220, 38, 38)';
|
|
74
74
|
context.lineWidth = (options.styles?.arc?.lineWidth ?? 1.5) * (controller.zoom ?? 1);
|
|
75
75
|
context.setLineDash(options.styles?.arc?.lineDash ?? []);
|
|
76
76
|
path({ type: 'LineString', coordinates: [ip(t1), ip(t2)] });
|
package/src/typings.d.ts
ADDED
package/src/util/styles.ts
CHANGED
|
@@ -13,11 +13,11 @@ import { type StyleSet } from './render.ts';
|
|
|
13
13
|
*/
|
|
14
14
|
// Point colour; lines pick up the same colour at reduced alpha so the route
|
|
15
15
|
// reads as belonging to the same node set without competing with the nodes.
|
|
16
|
-
const POINT_COLOR = 'rgb(
|
|
17
|
-
const LINE_COLOR = 'rgba(
|
|
16
|
+
const POINT_COLOR = 'rgb(30, 58, 138)';
|
|
17
|
+
const LINE_COLOR = 'rgba(30, 58, 138, 0.5)';
|
|
18
18
|
|
|
19
|
-
// The selected point is larger and
|
|
20
|
-
const SELECTED_COLOR = 'rgb(
|
|
19
|
+
// The selected point is larger, ringed and amber, so it reads at a glance among the blue others.
|
|
20
|
+
const SELECTED_COLOR = 'rgb(245, 158, 11)';
|
|
21
21
|
const SELECTED_RING = 'rgba(255, 255, 255, 0.9)';
|
|
22
22
|
|
|
23
23
|
export const globeStyles = (themeMode: ThemeMode): StyleSet =>
|
|
@@ -41,36 +41,46 @@ export const globeStyles = (themeMode: ThemeMode): StyleSet =>
|
|
|
41
41
|
lineDash: [4, 16],
|
|
42
42
|
strokeStyle: LINE_COLOR,
|
|
43
43
|
},
|
|
44
|
+
// Small so dense clusters (a city's data centres) stay separate dots rather than merging into a blob.
|
|
44
45
|
point: {
|
|
45
|
-
pointRadius:
|
|
46
|
+
pointRadius: 1.5,
|
|
46
47
|
fillStyle: POINT_COLOR,
|
|
47
48
|
},
|
|
48
49
|
selected: {
|
|
49
|
-
pointRadius:
|
|
50
|
+
pointRadius: 4,
|
|
50
51
|
fillStyle: SELECTED_COLOR,
|
|
51
52
|
strokeStyle: SELECTED_RING,
|
|
52
53
|
lineWidth: 2,
|
|
53
54
|
},
|
|
54
55
|
}
|
|
55
56
|
: {
|
|
57
|
+
// Outside the globe: the r0 surface's lightness with a grey-blue hue, so the sphere sits on the app's own tone.
|
|
58
|
+
background: {
|
|
59
|
+
fillStyle: 'oklch(0.966 0.012 240)',
|
|
60
|
+
},
|
|
61
|
+
// A street-map palette: sky-blue water, mint land, and borders a shade darker than the land.
|
|
56
62
|
water: {
|
|
57
|
-
fillStyle: '#
|
|
63
|
+
fillStyle: '#88CFE3',
|
|
58
64
|
},
|
|
59
65
|
land: {
|
|
60
|
-
fillStyle: '#
|
|
61
|
-
strokeStyle: '#
|
|
66
|
+
fillStyle: '#C4EBD5',
|
|
67
|
+
strokeStyle: '#A7DBBE',
|
|
68
|
+
},
|
|
69
|
+
border: {
|
|
70
|
+
strokeStyle: '#9CCFB1',
|
|
62
71
|
},
|
|
63
72
|
line: {
|
|
64
73
|
lineWidth: 1.5,
|
|
65
74
|
lineDash: [4, 16],
|
|
66
75
|
strokeStyle: LINE_COLOR,
|
|
67
76
|
},
|
|
77
|
+
// Small so dense clusters (a city's data centres) stay separate dots rather than merging into a blob.
|
|
68
78
|
point: {
|
|
69
|
-
pointRadius:
|
|
79
|
+
pointRadius: 1.5,
|
|
70
80
|
fillStyle: POINT_COLOR,
|
|
71
81
|
},
|
|
72
82
|
selected: {
|
|
73
|
-
pointRadius:
|
|
83
|
+
pointRadius: 4,
|
|
74
84
|
fillStyle: SELECTED_COLOR,
|
|
75
85
|
strokeStyle: SELECTED_RING,
|
|
76
86
|
lineWidth: 2,
|