gralobe 1.0.5 → 1.0.8
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 +21 -0
- package/README.md +28 -7
- package/dist/gralobe.js +1192 -840
- package/dist/gralobe.js.map +1 -1
- package/dist/gralobe.umd.cjs +17 -17
- package/dist/gralobe.umd.cjs.map +1 -1
- package/dist/index.d.ts +87 -18
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
export declare const BUILT_IN_STATISTICS: Record<string, StatisticDefinition>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Country data with a value for visualization
|
|
8
|
-
* Uses ISO 3166-1 numeric codes for country identification
|
|
7
|
+
* Country data with a value for visualization.
|
|
8
|
+
* Uses ISO 3166-1 numeric codes for country identification.
|
|
9
9
|
*/
|
|
10
10
|
export declare interface CountryData {
|
|
11
11
|
/** ISO 3166-1 numeric code (e.g., "840" for USA, "156" for China) */
|
|
@@ -41,10 +41,31 @@ declare interface CountryStatistics {
|
|
|
41
41
|
accessElectricity: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Value Formatters
|
|
46
|
+
*
|
|
47
|
+
* Centralized formatting utilities for statistic values.
|
|
48
|
+
* Used by Legend, tooltips, and any other display components.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Create a formatter function based on the unit type.
|
|
52
|
+
*
|
|
53
|
+
* @param unit - The unit string (e.g., "%", "$", "years")
|
|
54
|
+
* @returns A function that formats numeric values with the appropriate unit
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const fmt = createFormatter('%');
|
|
58
|
+
* fmt(42.567); // "42.6%"
|
|
59
|
+
*
|
|
60
|
+
* const currencyFmt = createFormatter('$');
|
|
61
|
+
* currencyFmt(1234567); // "$1,234,567"
|
|
62
|
+
*/
|
|
63
|
+
export declare function createFormatter(unit: string): (value: number) => string;
|
|
64
|
+
|
|
44
65
|
/**
|
|
45
66
|
* Visual effects configuration
|
|
46
67
|
*/
|
|
47
|
-
declare interface EffectsConfig {
|
|
68
|
+
export declare interface EffectsConfig {
|
|
48
69
|
/** Show atmosphere glow around globe */
|
|
49
70
|
atmosphere?: boolean;
|
|
50
71
|
/** Show cloud layer */
|
|
@@ -82,7 +103,7 @@ declare interface EffectsConfig {
|
|
|
82
103
|
/**
|
|
83
104
|
* Export options for screenshots, GIFs, and videos
|
|
84
105
|
*/
|
|
85
|
-
declare interface ExportOptions {
|
|
106
|
+
export declare interface ExportOptions {
|
|
86
107
|
/** Output width in pixels */
|
|
87
108
|
width?: number;
|
|
88
109
|
/** Output height in pixels */
|
|
@@ -95,6 +116,16 @@ declare interface ExportOptions {
|
|
|
95
116
|
filename?: string;
|
|
96
117
|
}
|
|
97
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Format a value using the provided formatter or create a default one.
|
|
121
|
+
*
|
|
122
|
+
* @param value - The numeric value to format
|
|
123
|
+
* @param unit - The unit string
|
|
124
|
+
* @param customFormatter - Optional custom formatter function
|
|
125
|
+
* @returns Formatted string
|
|
126
|
+
*/
|
|
127
|
+
export declare function formatValue(value: number, unit: string, customFormatter?: (value: number) => string): string;
|
|
128
|
+
|
|
98
129
|
/**
|
|
99
130
|
* GlobeViz - Interactive 3D Globe Visualization
|
|
100
131
|
*
|
|
@@ -277,52 +308,90 @@ export declare interface GlobeVizConfig {
|
|
|
277
308
|
export declare type LabelStyle = 'none' | 'major' | 'all' | 'capitals' | 'minimal';
|
|
278
309
|
|
|
279
310
|
/**
|
|
280
|
-
*
|
|
311
|
+
* Normalize a values object/map to use numeric codes
|
|
312
|
+
*/
|
|
313
|
+
export declare function normalizeCountryValues(values: Record<string, number> | Map<string, number>): Record<string, number>;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Complete statistic data ready for visualization.
|
|
317
|
+
* Combines the definition with actual country values.
|
|
281
318
|
*/
|
|
282
319
|
export declare interface StatisticData {
|
|
283
320
|
/** The statistic definition */
|
|
284
321
|
definition: StatisticDefinition;
|
|
285
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Country values keyed by ISO 3166-1 numeric code.
|
|
324
|
+
* Accepts both Map and plain object for flexibility.
|
|
325
|
+
* @example { "840": 85, "156": 68 } // USA: 85, China: 68
|
|
326
|
+
*/
|
|
286
327
|
values: Map<string, number> | Record<string, number>;
|
|
287
328
|
}
|
|
288
329
|
|
|
289
330
|
/**
|
|
290
|
-
* Definition of a statistic to visualize
|
|
331
|
+
* Definition of a statistic to visualize.
|
|
332
|
+
*
|
|
333
|
+
* This is the canonical type for statistic definitions.
|
|
334
|
+
* The `format` function is optional - if not provided, a default
|
|
335
|
+
* formatter will be created based on the `unit` field.
|
|
291
336
|
*/
|
|
292
337
|
export declare interface StatisticDefinition {
|
|
293
|
-
/** Unique identifier */
|
|
338
|
+
/** Unique identifier (snake_case recommended) */
|
|
294
339
|
id: string;
|
|
295
|
-
/**
|
|
340
|
+
/** Human-readable display name */
|
|
296
341
|
name: string;
|
|
297
|
-
/** Unit of measurement (e.g., "%", "years", "$") */
|
|
342
|
+
/** Unit of measurement (e.g., "%", "years", "$", "per capita") */
|
|
298
343
|
unit: string;
|
|
299
|
-
/** Description
|
|
344
|
+
/** Description shown in legend/tooltip */
|
|
300
345
|
description: string;
|
|
301
346
|
/**
|
|
302
|
-
* Color scale as [low, mid, high] hex colors
|
|
303
|
-
*
|
|
347
|
+
* Color scale as [low, mid, high] hex colors.
|
|
348
|
+
* Used for choropleth rendering.
|
|
349
|
+
* @example ['#fee5d9', '#fcae91', '#cb181d'] // Red scale
|
|
350
|
+
* @example ['#e5f5e0', '#a1d99b', '#31a354'] // Green scale
|
|
304
351
|
*/
|
|
305
352
|
colorScale: [string, string, string];
|
|
306
353
|
/**
|
|
307
|
-
* Value domain [min, max] for color mapping
|
|
308
|
-
*
|
|
354
|
+
* Value domain [min, max] for color mapping.
|
|
355
|
+
* Values outside this range are clamped.
|
|
356
|
+
* @example [0, 100] // For percentages
|
|
357
|
+
* @example [1000, 80000] // For GDP per capita
|
|
309
358
|
*/
|
|
310
359
|
domain: [number, number];
|
|
311
360
|
/**
|
|
312
|
-
*
|
|
361
|
+
* Optional custom formatter for displaying values.
|
|
362
|
+
* If not provided, a default formatter is created based on `unit`.
|
|
363
|
+
*
|
|
364
|
+
* NOTE: This function cannot be serialized to JSON.
|
|
365
|
+
* When sending statistics over the wire, omit this field
|
|
366
|
+
* and the renderer will create a default formatter.
|
|
367
|
+
*
|
|
313
368
|
* @example (v) => `${v.toFixed(1)}%`
|
|
369
|
+
* @example (v) => `$${(v/1000).toFixed(1)}k`
|
|
314
370
|
*/
|
|
315
|
-
format
|
|
371
|
+
format?: (value: number) => string;
|
|
316
372
|
}
|
|
317
373
|
|
|
318
374
|
/**
|
|
319
|
-
* Type
|
|
375
|
+
* Core Type Definitions for GlobeViz
|
|
376
|
+
*
|
|
377
|
+
* This is the SINGLE SOURCE OF TRUTH for all public types.
|
|
378
|
+
* Internal modules should import from here.
|
|
320
379
|
*/
|
|
321
380
|
/**
|
|
322
381
|
* Available texture presets for the globe
|
|
323
382
|
*/
|
|
324
383
|
export declare type TexturePreset = 'satellite' | 'natural' | 'dark' | 'light' | 'night' | 'topographic';
|
|
325
384
|
|
|
385
|
+
/**
|
|
386
|
+
* ISO 3166-1 country code mappings
|
|
387
|
+
* Maps alpha-2, alpha-3, and common names to numeric codes
|
|
388
|
+
*/
|
|
389
|
+
/**
|
|
390
|
+
* Convert any country identifier to ISO 3166-1 numeric code
|
|
391
|
+
* Supports: numeric codes, alpha-2, alpha-3, and common names
|
|
392
|
+
*/
|
|
393
|
+
export declare function toNumericCode(input: string): string;
|
|
394
|
+
|
|
326
395
|
export declare const WORLD_STATISTICS: CountryStatistics[];
|
|
327
396
|
|
|
328
397
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gralobe",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Interactive 3D globe visualization with statistics, smooth flat map ↔ globe transitions, and country labels",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/gralobe.umd.cjs",
|
|
@@ -43,12 +43,15 @@
|
|
|
43
43
|
"build": "tsc && vite build",
|
|
44
44
|
"build:lib": "tsc && vite build --mode lib",
|
|
45
45
|
"preview": "vite preview",
|
|
46
|
+
"test": "playwright test",
|
|
47
|
+
"test:ui": "playwright test --ui",
|
|
46
48
|
"prepublishOnly": "npm run build:lib"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
51
|
"three": ">=0.150.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
54
|
+
"@playwright/test": "^1.57.0",
|
|
52
55
|
"@types/topojson-client": "^3.1.5",
|
|
53
56
|
"@types/topojson-specification": "^1.0.5",
|
|
54
57
|
"typescript": "~5.9.3",
|