gralobe 1.0.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.
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Built-in statistics available out of the box
3
+ */
4
+ export declare const BUILT_IN_STATISTICS: Record<string, StatisticDefinition>;
5
+
6
+ /**
7
+ * Country data with a value for visualization
8
+ * Uses ISO 3166-1 numeric codes for country identification
9
+ */
10
+ export declare interface CountryData {
11
+ /** ISO 3166-1 numeric code (e.g., "840" for USA, "156" for China) */
12
+ id: string;
13
+ /** The value to visualize */
14
+ value: number;
15
+ /** Optional: ISO 3166-1 alpha-2 code (e.g., "US", "CN") */
16
+ code?: string;
17
+ /** Optional: Country name for display */
18
+ name?: string;
19
+ }
20
+
21
+ /**
22
+ * Real World Statistics Data
23
+ * Sources: World Bank Open Data, UN Data, WHO (2022-2023 estimates)
24
+ * Country codes follow ISO 3166-1 numeric standard
25
+ */
26
+ declare interface CountryStatistics {
27
+ id: string;
28
+ code: string;
29
+ name: string;
30
+ population: number;
31
+ gdpPerCapita: number;
32
+ co2Emissions: number;
33
+ lifeExpectancy: number;
34
+ humanDevIndex: number;
35
+ internetUsers: number;
36
+ renewableEnergy: number;
37
+ urbanPopulation: number;
38
+ healthExpenditure: number;
39
+ educationExpenditure: number;
40
+ forestArea: number;
41
+ accessElectricity: number;
42
+ }
43
+
44
+ /**
45
+ * Visual effects configuration
46
+ */
47
+ declare interface EffectsConfig {
48
+ /** Show cloud layer */
49
+ clouds?: boolean;
50
+ /** Cloud animation speed (0.1-3) */
51
+ cloudSpeed?: number;
52
+ /** Cloud layer opacity (0-1) */
53
+ cloudOpacity?: number;
54
+ /** Atmosphere glow intensity (0-1) */
55
+ atmosphereIntensity?: number;
56
+ /** Show aurora effect */
57
+ aurora?: boolean;
58
+ /** Show city lights on dark side */
59
+ cityLights?: boolean;
60
+ /** Ocean specular reflection */
61
+ oceanSpecular?: boolean;
62
+ /** Show lat/lon grid lines */
63
+ gridLines?: boolean;
64
+ /** Grid line opacity (0-1) */
65
+ gridOpacity?: number;
66
+ /** Hologram visual mode */
67
+ hologramMode?: boolean;
68
+ /** Vintage/sepia mode */
69
+ vintageMode?: boolean;
70
+ /** Thermal imaging mode */
71
+ thermalMode?: boolean;
72
+ /** Blueprint wireframe mode */
73
+ blueprintMode?: boolean;
74
+ /** Pulsing glow effect */
75
+ glowPulse?: boolean;
76
+ /** Star twinkling animation */
77
+ starTwinkle?: boolean;
78
+ }
79
+
80
+ /**
81
+ * Export options for screenshots, GIFs, and videos
82
+ */
83
+ declare interface ExportOptions {
84
+ /** Output width in pixels */
85
+ width?: number;
86
+ /** Output height in pixels */
87
+ height?: number;
88
+ /** Animation duration in seconds (for GIF/video) */
89
+ duration?: number;
90
+ /** Frames per second (for GIF/video) */
91
+ fps?: number;
92
+ /** Output filename */
93
+ filename?: string;
94
+ }
95
+
96
+ /**
97
+ * GlobeViz - Interactive 3D Globe Visualization
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Basic usage
102
+ * const globe = new GlobeViz('#container');
103
+ *
104
+ * // With configuration
105
+ * const globe = new GlobeViz('#container', {
106
+ * texture: 'satellite',
107
+ * labels: 'all',
108
+ * statistic: 'lifeExpectancy',
109
+ * autoRotate: true,
110
+ * });
111
+ *
112
+ * // Control programmatically
113
+ * globe.toFlat();
114
+ * globe.setStatistic('gdpPerCapita');
115
+ * ```
116
+ */
117
+ export declare class GlobeViz implements GlobeVizAPI {
118
+ private container;
119
+ private config;
120
+ private scene;
121
+ private camera;
122
+ private renderer;
123
+ private controls;
124
+ private globe;
125
+ private material;
126
+ private atmosphere;
127
+ private stars;
128
+ private gui;
129
+ private choropleth;
130
+ private legend;
131
+ private exporter;
132
+ private countryLabels;
133
+ private textureLoader;
134
+ private dataTexture;
135
+ private morph;
136
+ private currentStatistic;
137
+ private animationId;
138
+ private isDestroyed;
139
+ /**
140
+ * Create a new GlobeViz instance
141
+ * @param container CSS selector or HTMLElement
142
+ * @param config Configuration options
143
+ */
144
+ constructor(container: string | HTMLElement, config?: GlobeVizConfig);
145
+ private init;
146
+ private createGlobe;
147
+ private createAtmosphere;
148
+ private createStars;
149
+ private createGUI;
150
+ private handleResize;
151
+ private animate;
152
+ toGlobe(): void;
153
+ toFlat(): void;
154
+ setMorph(value: number): void;
155
+ getMorph(): number;
156
+ setStatistic(id: string | StatisticData): void;
157
+ setLabels(style: LabelStyle): void;
158
+ setTexture(preset: TexturePreset): Promise<void>;
159
+ setAutoRotate(enabled: boolean): void;
160
+ screenshot(options?: ExportOptions): void;
161
+ recordGif(options?: ExportOptions): Promise<void>;
162
+ recordVideo(options?: ExportOptions): Promise<void>;
163
+ setEffects(effects: Partial<EffectsConfig>): void;
164
+ resize(width: number, height: number): void;
165
+ destroy(): void;
166
+ }
167
+
168
+ /**
169
+ * Public API for controlling the globe
170
+ */
171
+ export declare interface GlobeVizAPI {
172
+ /** Animate to globe view */
173
+ toGlobe(): void;
174
+ /** Animate to flat map view */
175
+ toFlat(): void;
176
+ /** Set morph value directly (0 = flat, 1 = globe) */
177
+ setMorph(value: number): void;
178
+ /** Get current morph value */
179
+ getMorph(): number;
180
+ /** Change the displayed statistic */
181
+ setStatistic(id: string | StatisticData): void;
182
+ /** Change label style */
183
+ setLabels(style: LabelStyle): void;
184
+ /** Change texture */
185
+ setTexture(preset: TexturePreset): void;
186
+ /** Enable/disable auto-rotation */
187
+ setAutoRotate(enabled: boolean): void;
188
+ /** Take a screenshot */
189
+ screenshot(options?: ExportOptions): void;
190
+ /** Record a GIF animation */
191
+ recordGif(options?: ExportOptions): Promise<void>;
192
+ /** Record a video */
193
+ recordVideo(options?: ExportOptions): Promise<void>;
194
+ /** Update effects configuration */
195
+ setEffects(effects: Partial<EffectsConfig>): void;
196
+ /** Resize the visualization */
197
+ resize(width: number, height: number): void;
198
+ /** Destroy the instance and clean up */
199
+ destroy(): void;
200
+ }
201
+
202
+ /**
203
+ * Configuration options for GlobeViz
204
+ */
205
+ export declare interface GlobeVizConfig {
206
+ /**
207
+ * Earth texture preset
208
+ * @default 'satellite' (NASA Blue Marble)
209
+ */
210
+ texture?: TexturePreset;
211
+ /**
212
+ * Country label display style
213
+ * @default 'all'
214
+ */
215
+ labels?: LabelStyle;
216
+ /**
217
+ * Initial statistic to display
218
+ * Can be a built-in statistic ID or a custom StatisticData object
219
+ * @default 'lifeExpectancy'
220
+ */
221
+ statistic?: string | StatisticData;
222
+ /**
223
+ * Custom statistics data (country values)
224
+ * If not provided, uses built-in world statistics
225
+ */
226
+ data?: CountryData[];
227
+ /**
228
+ * Enable auto-rotation
229
+ * @default false
230
+ */
231
+ autoRotate?: boolean;
232
+ /**
233
+ * Initial view: 'globe' or 'flat'
234
+ * @default 'globe'
235
+ */
236
+ initialView?: 'globe' | 'flat';
237
+ /**
238
+ * Show control panel (lil-gui)
239
+ * @default true
240
+ */
241
+ showControls?: boolean;
242
+ /**
243
+ * Show legend
244
+ * @default true
245
+ */
246
+ showLegend?: boolean;
247
+ /**
248
+ * Visual effects configuration
249
+ */
250
+ effects?: EffectsConfig;
251
+ /**
252
+ * Enable 3D height extrusion based on data values
253
+ * @default false
254
+ */
255
+ extrudeHeight?: boolean;
256
+ /**
257
+ * Width of the container (defaults to container's width)
258
+ */
259
+ width?: number;
260
+ /**
261
+ * Height of the container (defaults to container's height)
262
+ */
263
+ height?: number;
264
+ /**
265
+ * Callback when a country is clicked
266
+ */
267
+ onCountryClick?: (countryId: string, countryName: string, value?: number) => void;
268
+ /**
269
+ * Callback when view changes between flat and globe
270
+ */
271
+ onViewChange?: (view: 'globe' | 'flat', morph: number) => void;
272
+ }
273
+
274
+ export declare type LabelStyle = 'none' | 'major' | 'all' | 'capitals' | 'minimal';
275
+
276
+ /**
277
+ * Complete statistic data ready for visualization
278
+ */
279
+ export declare interface StatisticData {
280
+ /** The statistic definition */
281
+ definition: StatisticDefinition;
282
+ /** Country values keyed by ISO 3166-1 numeric code */
283
+ values: Map<string, number> | Record<string, number>;
284
+ }
285
+
286
+ /**
287
+ * Definition of a statistic to visualize
288
+ */
289
+ export declare interface StatisticDefinition {
290
+ /** Unique identifier */
291
+ id: string;
292
+ /** Display name */
293
+ name: string;
294
+ /** Unit of measurement (e.g., "%", "years", "$") */
295
+ unit: string;
296
+ /** Description for legend/tooltip */
297
+ description: string;
298
+ /**
299
+ * Color scale as [low, mid, high] hex colors
300
+ * @example ['#fee5d9', '#fcae91', '#cb181d']
301
+ */
302
+ colorScale: [string, string, string];
303
+ /**
304
+ * Value domain [min, max] for color mapping
305
+ * @example [0, 100] for percentages
306
+ */
307
+ domain: [number, number];
308
+ /**
309
+ * Format function for displaying values
310
+ * @example (v) => `${v.toFixed(1)}%`
311
+ */
312
+ format: (value: number) => string;
313
+ }
314
+
315
+ /**
316
+ * Type definitions for GlobeViz
317
+ */
318
+ /**
319
+ * Available texture presets for the globe
320
+ */
321
+ export declare type TexturePreset = 'satellite' | 'natural' | 'dark' | 'light' | 'night' | 'topographic';
322
+
323
+ export declare const WORLD_STATISTICS: CountryStatistics[];
324
+
325
+ export { }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "gralobe",
3
+ "version": "1.0.0",
4
+ "description": "Interactive 3D globe visualization with statistics, smooth flat map ↔ globe transitions, and country labels",
5
+ "type": "module",
6
+ "main": "./dist/gralobe.umd.cjs",
7
+ "module": "./dist/gralobe.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/gralobe.js",
13
+ "require": "./dist/gralobe.umd.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "globe",
22
+ "3d",
23
+ "visualization",
24
+ "map",
25
+ "statistics",
26
+ "three.js",
27
+ "webgl",
28
+ "choropleth",
29
+ "earth",
30
+ "world",
31
+ "geography",
32
+ "data-visualization"
33
+ ],
34
+ "author": "BATIKAN BORA ORMANCI <batikanor@gmail.com>",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/batikanor/gralobe"
39
+ },
40
+ "homepage": "https://github.com/batikanor/gralobe#readme",
41
+ "scripts": {
42
+ "dev": "vite",
43
+ "build": "tsc && vite build",
44
+ "build:lib": "tsc && vite build --mode lib",
45
+ "preview": "vite preview",
46
+ "prepublishOnly": "npm run build:lib"
47
+ },
48
+ "peerDependencies": {
49
+ "three": ">=0.150.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/topojson-client": "^3.1.5",
53
+ "@types/topojson-specification": "^1.0.5",
54
+ "typescript": "~5.9.3",
55
+ "vite": "^7.2.4",
56
+ "vite-plugin-dts": "^4.5.4"
57
+ },
58
+ "dependencies": {
59
+ "@types/three": "^0.181.0",
60
+ "gifenc": "^1.0.3",
61
+ "gsap": "^3.13.0",
62
+ "lil-gui": "^0.21.0",
63
+ "three": ">=0.150.0",
64
+ "topojson-client": "^3.1.0",
65
+ "world-atlas": "^2.0.2"
66
+ }
67
+ }