gralobe 1.0.6 → 1.0.9

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/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
  *
@@ -138,6 +169,9 @@ export declare class GlobeViz implements GlobeVizAPI {
138
169
  private currentStatistic;
139
170
  private animationId;
140
171
  private isDestroyed;
172
+ /** Promise that resolves when fully initialized */
173
+ ready: Promise<void>;
174
+ private resolveReady;
141
175
  /**
142
176
  * Create a new GlobeViz instance
143
177
  * @param container CSS selector or HTMLElement
@@ -172,6 +206,8 @@ export declare class GlobeViz implements GlobeVizAPI {
172
206
  * Public API for controlling the globe
173
207
  */
174
208
  export declare interface GlobeVizAPI {
209
+ /** Promise that resolves when globe is fully initialized */
210
+ ready: Promise<void>;
175
211
  /** Animate to globe view */
176
212
  toGlobe(): void;
177
213
  /** Animate to flat map view */
@@ -282,46 +318,69 @@ export declare type LabelStyle = 'none' | 'major' | 'all' | 'capitals' | 'minima
282
318
  export declare function normalizeCountryValues(values: Record<string, number> | Map<string, number>): Record<string, number>;
283
319
 
284
320
  /**
285
- * Complete statistic data ready for visualization
321
+ * Complete statistic data ready for visualization.
322
+ * Combines the definition with actual country values.
286
323
  */
287
324
  export declare interface StatisticData {
288
325
  /** The statistic definition */
289
326
  definition: StatisticDefinition;
290
- /** Country values keyed by ISO 3166-1 numeric code */
327
+ /**
328
+ * Country values keyed by ISO 3166-1 numeric code.
329
+ * Accepts both Map and plain object for flexibility.
330
+ * @example { "840": 85, "156": 68 } // USA: 85, China: 68
331
+ */
291
332
  values: Map<string, number> | Record<string, number>;
292
333
  }
293
334
 
294
335
  /**
295
- * Definition of a statistic to visualize
336
+ * Definition of a statistic to visualize.
337
+ *
338
+ * This is the canonical type for statistic definitions.
339
+ * The `format` function is optional - if not provided, a default
340
+ * formatter will be created based on the `unit` field.
296
341
  */
297
342
  export declare interface StatisticDefinition {
298
- /** Unique identifier */
343
+ /** Unique identifier (snake_case recommended) */
299
344
  id: string;
300
- /** Display name */
345
+ /** Human-readable display name */
301
346
  name: string;
302
- /** Unit of measurement (e.g., "%", "years", "$") */
347
+ /** Unit of measurement (e.g., "%", "years", "$", "per capita") */
303
348
  unit: string;
304
- /** Description for legend/tooltip */
349
+ /** Description shown in legend/tooltip */
305
350
  description: string;
306
351
  /**
307
- * Color scale as [low, mid, high] hex colors
308
- * @example ['#fee5d9', '#fcae91', '#cb181d']
352
+ * Color scale as [low, mid, high] hex colors.
353
+ * Used for choropleth rendering.
354
+ * @example ['#fee5d9', '#fcae91', '#cb181d'] // Red scale
355
+ * @example ['#e5f5e0', '#a1d99b', '#31a354'] // Green scale
309
356
  */
310
357
  colorScale: [string, string, string];
311
358
  /**
312
- * Value domain [min, max] for color mapping
313
- * @example [0, 100] for percentages
359
+ * Value domain [min, max] for color mapping.
360
+ * Values outside this range are clamped.
361
+ * @example [0, 100] // For percentages
362
+ * @example [1000, 80000] // For GDP per capita
314
363
  */
315
364
  domain: [number, number];
316
365
  /**
317
- * Format function for displaying values
366
+ * Optional custom formatter for displaying values.
367
+ * If not provided, a default formatter is created based on `unit`.
368
+ *
369
+ * NOTE: This function cannot be serialized to JSON.
370
+ * When sending statistics over the wire, omit this field
371
+ * and the renderer will create a default formatter.
372
+ *
318
373
  * @example (v) => `${v.toFixed(1)}%`
374
+ * @example (v) => `$${(v/1000).toFixed(1)}k`
319
375
  */
320
- format: (value: number) => string;
376
+ format?: (value: number) => string;
321
377
  }
322
378
 
323
379
  /**
324
- * Type definitions for GlobeViz
380
+ * Core Type Definitions for GlobeViz
381
+ *
382
+ * This is the SINGLE SOURCE OF TRUTH for all public types.
383
+ * Internal modules should import from here.
325
384
  */
326
385
  /**
327
386
  * Available texture presets for the globe
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gralobe",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
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",