gralobe 1.0.6 → 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/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
  *
@@ -282,46 +313,69 @@ export declare type LabelStyle = 'none' | 'major' | 'all' | 'capitals' | 'minima
282
313
  export declare function normalizeCountryValues(values: Record<string, number> | Map<string, number>): Record<string, number>;
283
314
 
284
315
  /**
285
- * Complete statistic data ready for visualization
316
+ * Complete statistic data ready for visualization.
317
+ * Combines the definition with actual country values.
286
318
  */
287
319
  export declare interface StatisticData {
288
320
  /** The statistic definition */
289
321
  definition: StatisticDefinition;
290
- /** Country values keyed by ISO 3166-1 numeric code */
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
+ */
291
327
  values: Map<string, number> | Record<string, number>;
292
328
  }
293
329
 
294
330
  /**
295
- * 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.
296
336
  */
297
337
  export declare interface StatisticDefinition {
298
- /** Unique identifier */
338
+ /** Unique identifier (snake_case recommended) */
299
339
  id: string;
300
- /** Display name */
340
+ /** Human-readable display name */
301
341
  name: string;
302
- /** Unit of measurement (e.g., "%", "years", "$") */
342
+ /** Unit of measurement (e.g., "%", "years", "$", "per capita") */
303
343
  unit: string;
304
- /** Description for legend/tooltip */
344
+ /** Description shown in legend/tooltip */
305
345
  description: string;
306
346
  /**
307
- * Color scale as [low, mid, high] hex colors
308
- * @example ['#fee5d9', '#fcae91', '#cb181d']
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
309
351
  */
310
352
  colorScale: [string, string, string];
311
353
  /**
312
- * Value domain [min, max] for color mapping
313
- * @example [0, 100] for percentages
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
314
358
  */
315
359
  domain: [number, number];
316
360
  /**
317
- * Format function for displaying values
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
+ *
318
368
  * @example (v) => `${v.toFixed(1)}%`
369
+ * @example (v) => `$${(v/1000).toFixed(1)}k`
319
370
  */
320
- format: (value: number) => string;
371
+ format?: (value: number) => string;
321
372
  }
322
373
 
323
374
  /**
324
- * Type definitions for GlobeViz
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.
325
379
  */
326
380
  /**
327
381
  * 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.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",