@keneth80/k-chart 1.7.0 → 1.8.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.
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
50
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
51
  if (ar || !(i in from)) {
@@ -52,6 +88,9 @@ var resolveGlobeLandStyle = function (value, feature, index, fallback) { return
52
88
  var resolveGlobeLandOpacity = function (value, feature, index) { return typeof value === 'function'
53
89
  ? value(feature, index)
54
90
  : value !== null && value !== void 0 ? value : 0.88; };
91
+ var safeSvgId = function (value) {
92
+ return value.replace(/[^a-zA-Z0-9_-]/g, '-');
93
+ };
55
94
  var normalizeGlobeLandFeatures = function (geoJson) {
56
95
  var values = Array.isArray(geoJson) ? geoJson : [geoJson];
57
96
  return values.flatMap(function (value) {
@@ -110,9 +149,36 @@ var resolveGlobeZoomControlsConfiguration = function (controls) {
110
149
  y: (_d = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _d !== void 0 ? _d : 8
111
150
  };
112
151
  };
152
+ var resolveGlobeTransitionConfiguration = function (transition, duration) {
153
+ var _a, _b, _c, _d, _e, _f, _g, _h;
154
+ if (typeof transition === 'string') {
155
+ return {
156
+ type: transition,
157
+ duration: duration,
158
+ coverDuration: duration * 0.62,
159
+ revealDuration: duration * 0.38,
160
+ respectReducedMotion: true,
161
+ color: '#f5f7fa',
162
+ density: 0.82,
163
+ blur: 18
164
+ };
165
+ }
166
+ var transitionDuration = Math.max(240, (_a = transition === null || transition === void 0 ? void 0 : transition.duration) !== null && _a !== void 0 ? _a : duration);
167
+ return {
168
+ type: (_b = transition === null || transition === void 0 ? void 0 : transition.type) !== null && _b !== void 0 ? _b : 'warp',
169
+ duration: transitionDuration,
170
+ coverDuration: Math.max(120, (_c = transition === null || transition === void 0 ? void 0 : transition.coverDuration) !== null && _c !== void 0 ? _c : transitionDuration * 0.62),
171
+ revealDuration: Math.max(120, (_d = transition === null || transition === void 0 ? void 0 : transition.revealDuration) !== null && _d !== void 0 ? _d : transitionDuration * 0.38),
172
+ respectReducedMotion: (_e = transition === null || transition === void 0 ? void 0 : transition.respectReducedMotion) !== null && _e !== void 0 ? _e : true,
173
+ color: (_f = transition === null || transition === void 0 ? void 0 : transition.color) !== null && _f !== void 0 ? _f : '#f5f7fa',
174
+ density: clampNumber((_g = transition === null || transition === void 0 ? void 0 : transition.density) !== null && _g !== void 0 ? _g : 0.82, 0.2, 1),
175
+ blur: Math.max(0, (_h = transition === null || transition === void 0 ? void 0 : transition.blur) !== null && _h !== void 0 ? _h : 18)
176
+ };
177
+ };
113
178
  var resolveGlobeDrilldownConfiguration = function (drilldown) {
114
179
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
115
180
  if (typeof drilldown === 'boolean') {
181
+ var duration_1 = 720;
116
182
  return {
117
183
  enabled: drilldown,
118
184
  mode: 'map',
@@ -121,19 +187,22 @@ var resolveGlobeDrilldownConfiguration = function (drilldown) {
121
187
  globeZoomThreshold: 1.8,
122
188
  focusZoom: 2.6,
123
189
  zoomScale: 6,
124
- duration: 720,
190
+ duration: duration_1,
191
+ transition: resolveGlobeTransitionConfiguration(undefined, duration_1),
125
192
  resetControl: true
126
193
  };
127
194
  }
195
+ var duration = (_a = drilldown === null || drilldown === void 0 ? void 0 : drilldown.duration) !== null && _a !== void 0 ? _a : 720;
128
196
  return {
129
- enabled: (_a = drilldown === null || drilldown === void 0 ? void 0 : drilldown.enabled) !== null && _a !== void 0 ? _a : false,
130
- mode: (_b = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mode) !== null && _b !== void 0 ? _b : 'map',
131
- autoMapOnZoom: (_c = drilldown === null || drilldown === void 0 ? void 0 : drilldown.autoMapOnZoom) !== null && _c !== void 0 ? _c : false,
132
- mapZoomThreshold: (_d = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mapZoomThreshold) !== null && _d !== void 0 ? _d : 2.4,
133
- globeZoomThreshold: (_e = drilldown === null || drilldown === void 0 ? void 0 : drilldown.globeZoomThreshold) !== null && _e !== void 0 ? _e : 1.8,
134
- focusZoom: (_f = drilldown === null || drilldown === void 0 ? void 0 : drilldown.focusZoom) !== null && _f !== void 0 ? _f : 2.6,
135
- zoomScale: (_g = drilldown === null || drilldown === void 0 ? void 0 : drilldown.zoomScale) !== null && _g !== void 0 ? _g : 6,
136
- duration: (_h = drilldown === null || drilldown === void 0 ? void 0 : drilldown.duration) !== null && _h !== void 0 ? _h : 720,
197
+ enabled: (_b = drilldown === null || drilldown === void 0 ? void 0 : drilldown.enabled) !== null && _b !== void 0 ? _b : false,
198
+ mode: (_c = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mode) !== null && _c !== void 0 ? _c : 'map',
199
+ autoMapOnZoom: (_d = drilldown === null || drilldown === void 0 ? void 0 : drilldown.autoMapOnZoom) !== null && _d !== void 0 ? _d : false,
200
+ mapZoomThreshold: (_e = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mapZoomThreshold) !== null && _e !== void 0 ? _e : 2.4,
201
+ globeZoomThreshold: (_f = drilldown === null || drilldown === void 0 ? void 0 : drilldown.globeZoomThreshold) !== null && _f !== void 0 ? _f : 1.8,
202
+ focusZoom: (_g = drilldown === null || drilldown === void 0 ? void 0 : drilldown.focusZoom) !== null && _g !== void 0 ? _g : 2.6,
203
+ zoomScale: (_h = drilldown === null || drilldown === void 0 ? void 0 : drilldown.zoomScale) !== null && _h !== void 0 ? _h : 6,
204
+ duration: duration,
205
+ transition: resolveGlobeTransitionConfiguration(drilldown === null || drilldown === void 0 ? void 0 : drilldown.transition, duration),
137
206
  resetControl: (_j = drilldown === null || drilldown === void 0 ? void 0 : drilldown.resetControl) !== null && _j !== void 0 ? _j : true,
138
207
  landFill: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landFill,
139
208
  landStroke: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landStroke,
@@ -151,6 +220,64 @@ var isGlobePointVisible = function (lon, lat, rotation) {
151
220
  }
152
221
  return (0, d3_geo_1.geoDistance)([lon, lat], [-rotation[0], -rotation[1]]) <= Math.PI / 2;
153
222
  };
223
+ var seededUnit = function (index, salt) {
224
+ var value = Math.sin(index * 12.9898 + salt * 78.233) * 43758.5453;
225
+ return value - Math.floor(value);
226
+ };
227
+ var drawCloudTransitionFrame = function (canvas, width, height, coverage, configuration) {
228
+ var _a;
229
+ var pixelRatio = Math.max(1, (_a = globalThis.devicePixelRatio) !== null && _a !== void 0 ? _a : 1);
230
+ var targetWidth = Math.max(1, Math.round(width * pixelRatio));
231
+ var targetHeight = Math.max(1, Math.round(height * pixelRatio));
232
+ if (canvas.width !== targetWidth || canvas.height !== targetHeight) {
233
+ canvas.width = targetWidth;
234
+ canvas.height = targetHeight;
235
+ }
236
+ canvas.style.width = "".concat(width, "px");
237
+ canvas.style.height = "".concat(height, "px");
238
+ var context = canvas.getContext('2d');
239
+ if (!context) {
240
+ return;
241
+ }
242
+ context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
243
+ context.clearRect(0, 0, width, height);
244
+ if (coverage <= 0) {
245
+ return;
246
+ }
247
+ var normalizedCoverage = clampNumber(coverage, 0, 1);
248
+ var easedCoverage = normalizedCoverage < 0.5
249
+ ? 2 * normalizedCoverage * normalizedCoverage
250
+ : 1 - Math.pow(-2 * normalizedCoverage + 2, 2) / 2;
251
+ var diagonal = Math.hypot(width, height);
252
+ var cloudCount = Math.max(18, Math.round(52 * configuration.density));
253
+ context.save();
254
+ context.filter = configuration.blur > 0 ? "blur(".concat(configuration.blur, "px)") : 'none';
255
+ for (var index = 0; index < cloudCount; index += 1) {
256
+ var angle = seededUnit(index, 1) * Math.PI * 2;
257
+ var edgeDistance = diagonal * (0.6 - easedCoverage * 0.58);
258
+ var scatter = seededUnit(index, 2) * diagonal * 0.24;
259
+ var x = width / 2 + Math.cos(angle) * (edgeDistance + scatter);
260
+ var y = height / 2 + Math.sin(angle) * (edgeDistance + scatter) * 0.62;
261
+ var radius = diagonal * (0.08 + seededUnit(index, 3) * 0.11) * (0.38 + easedCoverage);
262
+ var gradient = context.createRadialGradient(x, y, radius * 0.08, x, y, radius);
263
+ gradient.addColorStop(0, configuration.color);
264
+ gradient.addColorStop(0.46, configuration.color);
265
+ gradient.addColorStop(1, 'rgba(245, 247, 250, 0)');
266
+ context.globalAlpha = clampNumber((0.25 + easedCoverage * 0.72) * configuration.density, 0, 1);
267
+ context.fillStyle = gradient;
268
+ context.beginPath();
269
+ context.arc(x, y, radius, 0, Math.PI * 2);
270
+ context.fill();
271
+ }
272
+ context.restore();
273
+ if (easedCoverage > 0.82) {
274
+ context.save();
275
+ context.globalAlpha = Math.pow((easedCoverage - 0.82) / 0.18, 1.45) * 0.96;
276
+ context.fillStyle = configuration.color;
277
+ context.fillRect(0, 0, width, height);
278
+ context.restore();
279
+ }
280
+ };
154
281
  var createSvgGlobeSeries = function (configuration) {
155
282
  var rotation = normalizeGlobeRotation(configuration.initialRotate);
156
283
  var zoomLevel = 1;
@@ -166,6 +293,10 @@ var createSvgGlobeSeries = function (configuration) {
166
293
  var warpEffect;
167
294
  var warpTimer;
168
295
  var warpFrame;
296
+ var cloudFrame;
297
+ var cloudCanvas;
298
+ var cloudHost;
299
+ var cloudTransitionToken = 0;
169
300
  var wheelZoomReference;
170
301
  var wheelZoomReferenceTimer;
171
302
  var hoveredMarkerTarget;
@@ -179,8 +310,10 @@ var createSvgGlobeSeries = function (configuration) {
179
310
  yField: configuration.latField,
180
311
  color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
181
312
  render: function (_a) {
182
- var _b;
313
+ var _this = this;
314
+ var _b, _c, _d, _e;
183
315
  var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
316
+ cloudHost = (_d = (_c = (_b = group.node()) === null || _b === void 0 ? void 0 : _b.ownerSVGElement) === null || _c === void 0 ? void 0 : _c.parentElement) !== null && _d !== void 0 ? _d : cloudHost;
184
317
  var width = plotSize.width;
185
318
  var height = plotSize.height;
186
319
  var centerX = width / 2;
@@ -191,7 +324,7 @@ var createSvgGlobeSeries = function (configuration) {
191
324
  var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
192
325
  var drilldownConfiguration = resolveGlobeDrilldownConfiguration(configuration.drilldown);
193
326
  zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
194
- var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
327
+ var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_e = configuration.globeScale) !== null && _e !== void 0 ? _e : 0.88));
195
328
  var globeProjection = (0, d3_geo_1.geoOrthographic)()
196
329
  .translate([centerX, centerY])
197
330
  .scale(baseScale * zoomLevel)
@@ -203,6 +336,8 @@ var createSvgGlobeSeries = function (configuration) {
203
336
  .center(focusedPoint ? [focusedPoint.lon, focusedPoint.lat] : [0, 0]);
204
337
  var path = (0, d3_geo_1.geoPath)(globeProjection);
205
338
  var mapPath = (0, d3_geo_1.geoPath)(mapProjection);
339
+ var gradientId = "kchart-globe-ocean-".concat(safeSvgId(configuration.selector));
340
+ var atmosphereId = "kchart-globe-atmosphere-".concat(safeSvgId(configuration.selector));
206
341
  var resolveGlobeCenter = function () {
207
342
  var _a;
208
343
  var inverted = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, [centerX, centerY]);
@@ -225,6 +360,97 @@ var createSvgGlobeSeries = function (configuration) {
225
360
  warpFrame = undefined;
226
361
  }
227
362
  };
363
+ var removeCloudCanvas = function () {
364
+ if (cloudFrame !== undefined) {
365
+ globalThis.cancelAnimationFrame(cloudFrame);
366
+ cloudFrame = undefined;
367
+ }
368
+ cloudCanvas === null || cloudCanvas === void 0 ? void 0 : cloudCanvas.remove();
369
+ cloudCanvas = undefined;
370
+ };
371
+ var ensureCloudCanvas = function () {
372
+ var _a, _b;
373
+ var host = cloudHost !== null && cloudHost !== void 0 ? cloudHost : (_b = (_a = group.node()) === null || _a === void 0 ? void 0 : _a.ownerSVGElement) === null || _b === void 0 ? void 0 : _b.parentElement;
374
+ if (!host) {
375
+ return undefined;
376
+ }
377
+ if (!cloudCanvas || cloudCanvas.parentElement !== host) {
378
+ cloudCanvas === null || cloudCanvas === void 0 ? void 0 : cloudCanvas.remove();
379
+ cloudCanvas = document.createElement('canvas');
380
+ cloudCanvas.className = 'kchart-globe-cloud-transition';
381
+ cloudCanvas.setAttribute('aria-hidden', 'true');
382
+ Object.assign(cloudCanvas.style, {
383
+ position: 'absolute',
384
+ inset: '0',
385
+ zIndex: '20',
386
+ pointerEvents: 'none'
387
+ });
388
+ host.appendChild(cloudCanvas);
389
+ }
390
+ return cloudCanvas;
391
+ };
392
+ var runCloudTransition = function (onCovered, onFinished) {
393
+ var _a, _b;
394
+ var invokeCovered = function () {
395
+ return Promise.resolve().then(onCovered);
396
+ };
397
+ var canvas = ensureCloudCanvas();
398
+ if (!canvas) {
399
+ void invokeCovered().finally(onFinished);
400
+ return;
401
+ }
402
+ if (cloudFrame !== undefined) {
403
+ globalThis.cancelAnimationFrame(cloudFrame);
404
+ cloudFrame = undefined;
405
+ }
406
+ var transitionToken = ++cloudTransitionToken;
407
+ var reducedMotion = (_b = (_a = globalThis.matchMedia) === null || _a === void 0 ? void 0 : _a.call(globalThis, '(prefers-reduced-motion: reduce)').matches) !== null && _b !== void 0 ? _b : false;
408
+ var configuredDuration = drilldownConfiguration.transition.coverDuration
409
+ + drilldownConfiguration.transition.revealDuration;
410
+ var reducedDuration = reducedMotion && drilldownConfiguration.transition.respectReducedMotion
411
+ ? Math.min(1200, configuredDuration)
412
+ : configuredDuration;
413
+ var durationScale = reducedDuration / configuredDuration;
414
+ var coverDuration = drilldownConfiguration.transition.coverDuration * durationScale;
415
+ var revealDuration = drilldownConfiguration.transition.revealDuration * durationScale;
416
+ var startedAt = globalThis.performance.now();
417
+ var reveal = function () {
418
+ var revealStartedAt = globalThis.performance.now();
419
+ var animateReveal = function (now) {
420
+ if (transitionToken !== cloudTransitionToken || !cloudCanvas) {
421
+ return;
422
+ }
423
+ var progress = clampNumber((now - revealStartedAt) / revealDuration, 0, 1);
424
+ drawCloudTransitionFrame(cloudCanvas, size.width, size.height, 1 - easeInOutCubic(progress), drilldownConfiguration.transition);
425
+ if (progress < 1) {
426
+ cloudFrame = globalThis.requestAnimationFrame(animateReveal);
427
+ return;
428
+ }
429
+ cloudFrame = undefined;
430
+ removeCloudCanvas();
431
+ onFinished === null || onFinished === void 0 ? void 0 : onFinished();
432
+ };
433
+ cloudFrame = globalThis.requestAnimationFrame(animateReveal);
434
+ };
435
+ var animateCover = function (now) {
436
+ if (transitionToken !== cloudTransitionToken || !cloudCanvas) {
437
+ return;
438
+ }
439
+ var progress = clampNumber((now - startedAt) / coverDuration, 0, 1);
440
+ drawCloudTransitionFrame(cloudCanvas, size.width, size.height, easeInOutCubic(progress), drilldownConfiguration.transition);
441
+ if (progress < 1) {
442
+ cloudFrame = globalThis.requestAnimationFrame(animateCover);
443
+ return;
444
+ }
445
+ cloudFrame = undefined;
446
+ invokeCovered()
447
+ .catch(function (error) {
448
+ console.error('[KChart Globe] Cloud transition callback failed.', error);
449
+ })
450
+ .finally(reveal);
451
+ };
452
+ cloudFrame = globalThis.requestAnimationFrame(animateCover);
453
+ };
228
454
  var clearWheelZoomReference = function () {
229
455
  wheelZoomReference = undefined;
230
456
  if (wheelZoomReferenceTimer !== undefined) {
@@ -258,6 +484,104 @@ var createSvgGlobeSeries = function (configuration) {
258
484
  };
259
485
  }
260
486
  focusedPoint = datum;
487
+ var notifyEnter = function () { return __awaiter(_this, void 0, void 0, function () {
488
+ var _a;
489
+ return __generator(this, function (_b) {
490
+ switch (_b.label) {
491
+ case 0: return [4 /*yield*/, ((_a = drilldownConfiguration.onEnter) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration, {
492
+ data: datum.data,
493
+ lat: datum.lat,
494
+ lon: datum.lon,
495
+ exit: function () { return exitDrilldown(); }
496
+ }))];
497
+ case 1:
498
+ _b.sent();
499
+ return [2 /*return*/];
500
+ }
501
+ });
502
+ }); };
503
+ if (drilldownConfiguration.transition.type === 'cloud') {
504
+ externalMapTransitioning = true;
505
+ viewMode = 'globe';
506
+ var applyCoveredView_1 = function () { return __awaiter(_this, void 0, void 0, function () {
507
+ return __generator(this, function (_a) {
508
+ switch (_a.label) {
509
+ case 0:
510
+ if (mode === 'zoom') {
511
+ rotation = [-datum.lon, -datum.lat, rotation[2]];
512
+ zoomLevel = clampNumber(drilldownConfiguration.focusZoom, minZoom, maxZoom);
513
+ viewMode = 'globe';
514
+ }
515
+ else if (mode === 'external-map') {
516
+ viewMode = 'external-map';
517
+ }
518
+ else {
519
+ viewMode = mode;
520
+ }
521
+ draw();
522
+ return [4 /*yield*/, notifyEnter()];
523
+ case 1:
524
+ _a.sent();
525
+ externalMapTransitioning = false;
526
+ return [2 /*return*/];
527
+ }
528
+ });
529
+ }); };
530
+ var startCloud_1 = function () {
531
+ runCloudTransition(applyCoveredView_1, draw);
532
+ };
533
+ if (mode === 'external-map' && moveCamera) {
534
+ var cameraDuration_1 = Math.min(460, Math.max(280, drilldownConfiguration.transition.duration * 0.28));
535
+ var startRotation_1 = __spreadArray([], rotation, true);
536
+ var targetRotation_1 = [
537
+ -datum.lon,
538
+ -datum.lat,
539
+ rotation[2]
540
+ ];
541
+ var longitudeDelta_1 = shortestAngleDelta(startRotation_1[0], targetRotation_1[0]);
542
+ var startedAt_1 = globalThis.performance.now();
543
+ var animateCamera_1 = function (now) {
544
+ var progress = clampNumber((now - startedAt_1) / cameraDuration_1, 0, 1);
545
+ var easedProgress = easeInOutCubic(progress);
546
+ rotation = [
547
+ startRotation_1[0] + longitudeDelta_1 * easedProgress,
548
+ startRotation_1[1] + (targetRotation_1[1] - startRotation_1[1]) * easedProgress,
549
+ startRotation_1[2]
550
+ ];
551
+ draw();
552
+ if (progress < 1) {
553
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
554
+ return;
555
+ }
556
+ warpFrame = undefined;
557
+ rotation = targetRotation_1;
558
+ startCloud_1();
559
+ };
560
+ draw();
561
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
562
+ }
563
+ else {
564
+ startCloud_1();
565
+ }
566
+ return;
567
+ }
568
+ if (drilldownConfiguration.transition.type === 'none') {
569
+ if (mode === 'zoom') {
570
+ rotation = [-datum.lon, -datum.lat, rotation[2]];
571
+ zoomLevel = clampNumber(drilldownConfiguration.focusZoom, minZoom, maxZoom);
572
+ viewMode = 'globe';
573
+ }
574
+ else {
575
+ viewMode = mode;
576
+ }
577
+ externalMapTransitioning = mode === 'external-map';
578
+ draw();
579
+ void notifyEnter().finally(function () {
580
+ externalMapTransitioning = false;
581
+ draw();
582
+ });
583
+ return;
584
+ }
261
585
  if (mode === 'zoom') {
262
586
  viewMode = 'globe';
263
587
  rotation = [
@@ -280,37 +604,28 @@ var createSvgGlobeSeries = function (configuration) {
280
604
  x: datum.projected[0],
281
605
  y: datum.projected[1],
282
606
  startedAt: Date.now(),
283
- duration: drilldownConfiguration.duration
607
+ duration: drilldownConfiguration.transition.duration
284
608
  };
285
- var notifyEnter = function () {
286
- var _a;
287
- (_a = drilldownConfiguration.onEnter) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration, {
288
- data: datum.data,
289
- lat: datum.lat,
290
- lon: datum.lon,
291
- exit: function () { return exitDrilldown(); }
292
- });
293
- };
294
609
  if (mode === 'external-map') {
295
- var cameraDuration_1 = moveCamera
296
- ? Math.min(460, Math.max(280, drilldownConfiguration.duration * 0.34))
610
+ var cameraDuration_2 = moveCamera
611
+ ? Math.min(460, Math.max(280, drilldownConfiguration.transition.duration * 0.34))
297
612
  : 0;
298
- var warpDuration_1 = Math.max(600, drilldownConfiguration.duration - cameraDuration_1);
299
- var startRotation_1 = __spreadArray([], rotation, true);
300
- var targetRotation_1 = [
613
+ var warpDuration_1 = Math.max(600, drilldownConfiguration.transition.duration - cameraDuration_2);
614
+ var startRotation_2 = __spreadArray([], rotation, true);
615
+ var targetRotation_2 = [
301
616
  -datum.lon,
302
617
  -datum.lat,
303
618
  rotation[2]
304
619
  ];
305
- var longitudeDelta_1 = shortestAngleDelta(startRotation_1[0], targetRotation_1[0]);
306
- var startedAt_1 = globalThis.performance.now();
620
+ var longitudeDelta_2 = shortestAngleDelta(startRotation_2[0], targetRotation_2[0]);
621
+ var startedAt_2 = globalThis.performance.now();
307
622
  var revealExternalMap_1 = function () {
308
623
  warpTimer = globalThis.setTimeout(function () {
309
624
  warpTimer = undefined;
310
625
  externalMapTransitioning = false;
311
626
  viewMode = 'external-map';
312
627
  warpEffect = undefined;
313
- notifyEnter();
628
+ void notifyEnter();
314
629
  draw();
315
630
  }, warpDuration_1);
316
631
  };
@@ -329,37 +644,36 @@ var createSvgGlobeSeries = function (configuration) {
329
644
  startWarp_1();
330
645
  return;
331
646
  }
332
- var animateCamera_1 = function (now) {
333
- var progress = clampNumber((now - startedAt_1) / cameraDuration_1, 0, 1);
647
+ var animateCamera_2 = function (now) {
648
+ var progress = clampNumber((now - startedAt_2) / cameraDuration_2, 0, 1);
334
649
  var easedProgress = easeInOutCubic(progress);
335
650
  rotation = [
336
- startRotation_1[0] + longitudeDelta_1 * easedProgress,
337
- startRotation_1[1] + (targetRotation_1[1] - startRotation_1[1]) * easedProgress,
338
- startRotation_1[2]
651
+ startRotation_2[0] + longitudeDelta_2 * easedProgress,
652
+ startRotation_2[1] + (targetRotation_2[1] - startRotation_2[1]) * easedProgress,
653
+ startRotation_2[2]
339
654
  ];
340
655
  draw();
341
656
  if (progress < 1) {
342
- warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
657
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_2);
343
658
  return;
344
659
  }
345
660
  warpFrame = undefined;
346
- rotation = targetRotation_1;
661
+ rotation = targetRotation_2;
347
662
  startWarp_1();
348
663
  };
349
664
  draw();
350
- warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
665
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_2);
351
666
  return;
352
667
  }
353
- notifyEnter();
668
+ void notifyEnter();
354
669
  warpTimer = globalThis.setTimeout(function () {
355
670
  warpTimer = undefined;
356
671
  warpEffect = undefined;
357
672
  draw();
358
- }, drilldownConfiguration.duration);
673
+ }, drilldownConfiguration.transition.duration);
359
674
  draw();
360
675
  };
361
676
  var exitDrilldown = function (restoreState) {
362
- var _a;
363
677
  if (restoreState === void 0) { restoreState = true; }
364
678
  if (viewMode === 'globe' && !focusedPoint) {
365
679
  return;
@@ -370,17 +684,37 @@ var createSvgGlobeSeries = function (configuration) {
370
684
  }
371
685
  cancelWarpFrame();
372
686
  hoveredMarkerTarget = undefined;
373
- externalMapTransitioning = false;
374
- viewMode = 'globe';
375
- focusedPoint = undefined;
376
- if (restoreState && drilldownRestoreState) {
377
- rotation = __spreadArray([], drilldownRestoreState.rotation, true);
378
- zoomLevel = clampNumber(drilldownRestoreState.zoomLevel, minZoom, maxZoom);
687
+ var completeExit = function () { return __awaiter(_this, void 0, void 0, function () {
688
+ var _a;
689
+ return __generator(this, function (_b) {
690
+ switch (_b.label) {
691
+ case 0:
692
+ viewMode = 'globe';
693
+ focusedPoint = undefined;
694
+ if (restoreState && drilldownRestoreState) {
695
+ rotation = __spreadArray([], drilldownRestoreState.rotation, true);
696
+ zoomLevel = clampNumber(drilldownRestoreState.zoomLevel, minZoom, maxZoom);
697
+ }
698
+ drilldownRestoreState = undefined;
699
+ warpEffect = undefined;
700
+ return [4 /*yield*/, ((_a = drilldownConfiguration.onExit) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration))];
701
+ case 1:
702
+ _b.sent();
703
+ draw();
704
+ return [2 /*return*/];
705
+ }
706
+ });
707
+ }); };
708
+ if (drilldownConfiguration.transition.type === 'cloud') {
709
+ externalMapTransitioning = true;
710
+ runCloudTransition(completeExit, function () {
711
+ externalMapTransitioning = false;
712
+ draw();
713
+ });
714
+ return;
379
715
  }
380
- drilldownRestoreState = undefined;
381
- warpEffect = undefined;
382
- (_a = drilldownConfiguration.onExit) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration);
383
- draw();
716
+ externalMapTransitioning = false;
717
+ void completeExit();
384
718
  };
385
719
  var resolveAutoMapTarget = function (reference) {
386
720
  var nearest;
@@ -415,10 +749,10 @@ var createSvgGlobeSeries = function (configuration) {
415
749
  var enterThreshold = Math.max(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
416
750
  var exitThreshold = Math.min(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
417
751
  if (viewMode === 'globe' && zoomLevel >= enterThreshold) {
418
- var target = preferredTarget !== null && preferredTarget !== void 0 ? preferredTarget : resolveAutoMapTarget(settledCenter);
752
+ var viewportCenter = reference !== null && reference !== void 0 ? reference : settledCenter;
753
+ var target = preferredTarget !== null && preferredTarget !== void 0 ? preferredTarget : resolveAutoMapTarget(viewportCenter);
419
754
  if (target) {
420
- var automaticTarget = __assign(__assign({}, target), { lon: settledCenter[0], lat: settledCenter[1], projected: [centerX, centerY] });
421
- enterDrilldown(automaticTarget, drilldownConfiguration.mode, Math.min(zoomLevel, exitThreshold), false);
755
+ enterDrilldown(target, drilldownConfiguration.mode, Math.min(zoomLevel, exitThreshold), false);
422
756
  return true;
423
757
  }
424
758
  }
@@ -451,15 +785,66 @@ var createSvgGlobeSeries = function (configuration) {
451
785
  .attr('class', 'kchart-globe-layer')
452
786
  .style('cursor', configuration.draggable === false || viewMode === 'map' ? 'default' : dragging ? 'grabbing' : 'grab')
453
787
  .style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
788
+ var defs = group.selectAll('defs.kchart-globe-defs')
789
+ .data([undefined])
790
+ .join('defs')
791
+ .attr('class', 'kchart-globe-defs');
792
+ var oceanGradient = defs.selectAll("radialGradient#".concat(gradientId))
793
+ .data([undefined])
794
+ .join('radialGradient')
795
+ .attr('id', gradientId)
796
+ .attr('cx', '35%')
797
+ .attr('cy', '28%')
798
+ .attr('r', '74%');
799
+ oceanGradient.selectAll('stop')
800
+ .data([
801
+ { offset: '0%', color: '#62c7f7' },
802
+ { offset: '34%', color: '#2077b8' },
803
+ { offset: '72%', color: '#0b3e73' },
804
+ { offset: '100%', color: '#061a38' }
805
+ ])
806
+ .join('stop')
807
+ .attr('offset', function (datum) { return datum.offset; })
808
+ .attr('stop-color', function (datum) { return datum.color; });
809
+ var atmosphereGradient = defs.selectAll("radialGradient#".concat(atmosphereId))
810
+ .data([undefined])
811
+ .join('radialGradient')
812
+ .attr('id', atmosphereId)
813
+ .attr('cx', '50%')
814
+ .attr('cy', '50%')
815
+ .attr('r', '54%');
816
+ atmosphereGradient.selectAll('stop')
817
+ .data([
818
+ { offset: '70%', color: '#ffffff', opacity: 0 },
819
+ { offset: '88%', color: '#7dd3fc', opacity: 0.16 },
820
+ { offset: '100%', color: '#dff6ff', opacity: 0.42 }
821
+ ])
822
+ .join('stop')
823
+ .attr('offset', function (datum) { return datum.offset; })
824
+ .attr('stop-color', function (datum) { return datum.color; })
825
+ .attr('stop-opacity', function (datum) { return datum.opacity; });
454
826
  globeGroup.selectAll('path.kchart-globe-sphere')
455
827
  .data(viewMode === 'globe' ? [{ type: 'Sphere' }] : [])
456
828
  .join('path')
457
829
  .attr('class', 'kchart-globe-sphere')
458
830
  .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
459
- .style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : 'rgba(15, 23, 42, 0.92)')
460
- .style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(148, 163, 184, 0.62)')
831
+ .style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : "url(#".concat(gradientId, ")"))
832
+ .style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(186, 230, 253, 0.72)')
461
833
  .style('stroke-width', 1.2)
462
- .style('pointer-events', 'all');
834
+ .style('pointer-events', 'all')
835
+ .lower();
836
+ globeGroup.selectAll('circle.kchart-globe-atmosphere')
837
+ .data(viewMode === 'globe' ? [undefined] : [])
838
+ .join('circle')
839
+ .attr('class', 'kchart-globe-atmosphere')
840
+ .attr('cx', centerX)
841
+ .attr('cy', centerY)
842
+ .attr('r', baseScale * zoomLevel)
843
+ .style('fill', "url(#".concat(atmosphereId, ")"))
844
+ .style('stroke', 'rgba(186, 230, 253, 0.34)')
845
+ .style('stroke-width', 3)
846
+ .style('filter', 'drop-shadow(0 0 18px rgba(56, 189, 248, 0.2))')
847
+ .style('pointer-events', 'none');
463
848
  var defaultLandGeoJson = configuration.landMode === 'countries'
464
849
  ? WORLD_COUNTRY_GEOJSON
465
850
  : WORLD_LAND_GEOJSON;
@@ -486,7 +871,7 @@ var createSvgGlobeSeries = function (configuration) {
486
871
  .attr('y', 0)
487
872
  .attr('width', width)
488
873
  .attr('height', height)
489
- .style('fill', (_g = configuration.sphereFill) !== null && _g !== void 0 ? _g : 'rgba(15, 23, 42, 0.92)')
874
+ .style('fill', (_g = configuration.sphereFill) !== null && _g !== void 0 ? _g : '#10233f')
490
875
  .style('pointer-events', 'all')
491
876
  .lower();
492
877
  globeGroup.selectAll('path.kchart-globe-land')
@@ -494,9 +879,9 @@ var createSvgGlobeSeries = function (configuration) {
494
879
  .join('path')
495
880
  .attr('class', 'kchart-globe-land')
496
881
  .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
497
- .style('fill', function (datum, index) { return resolveGlobeLandStyle(activeLandFill, datum, index, '#2dd4bf'); })
882
+ .style('fill', function (datum, index) { return resolveGlobeLandStyle(activeLandFill, datum, index, '#5fa96b'); })
498
883
  .style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(activeLandOpacity, datum, index); })
499
- .style('stroke', function (datum, index) { return resolveGlobeLandStyle(activeLandStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
884
+ .style('stroke', function (datum, index) { return resolveGlobeLandStyle(activeLandStroke, datum, index, 'rgba(220, 252, 231, 0.54)'); })
500
885
  .style('stroke-width', 1)
501
886
  .style('pointer-events', 'none');
502
887
  globeGroup.selectAll('path.kchart-globe-country-borders')
@@ -505,7 +890,7 @@ var createSvgGlobeSeries = function (configuration) {
505
890
  .attr('class', 'kchart-globe-country-borders')
506
891
  .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
507
892
  .style('fill', 'none')
508
- .style('stroke', (_h = configuration.countryBordersStroke) !== null && _h !== void 0 ? _h : 'rgba(236, 253, 245, 0.26)')
893
+ .style('stroke', (_h = configuration.countryBordersStroke) !== null && _h !== void 0 ? _h : 'rgba(240, 253, 244, 0.2)')
509
894
  .style('stroke-width', (_j = configuration.countryBordersStrokeWidth) !== null && _j !== void 0 ? _j : 0.55)
510
895
  .style('pointer-events', 'none');
511
896
  globeGroup.selectAll('path.kchart-globe-graticule')
@@ -514,9 +899,11 @@ var createSvgGlobeSeries = function (configuration) {
514
899
  .attr('class', 'kchart-globe-graticule')
515
900
  .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
516
901
  .style('fill', 'none')
517
- .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(148, 163, 184, 0.22)')
902
+ .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(186, 230, 253, 0.14)')
518
903
  .style('stroke-width', 0.8)
519
904
  .style('pointer-events', 'none');
905
+ globeGroup.select('circle.kchart-globe-atmosphere')
906
+ .raise();
520
907
  var markerData = (viewMode === 'external-map' ? [] : data).map(function (point) {
521
908
  var lat = resolveGlobePointValue(point, configuration.latField);
522
909
  var lon = resolveGlobePointValue(point, configuration.lonField);
@@ -672,7 +1059,7 @@ var createSvgGlobeSeries = function (configuration) {
672
1059
  .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
673
1060
  .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
674
1061
  .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
675
- var activeWarpDuration = Math.max(480, (_p = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.duration) !== null && _p !== void 0 ? _p : drilldownConfiguration.duration);
1062
+ var activeWarpDuration = Math.max(480, (_p = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.duration) !== null && _p !== void 0 ? _p : drilldownConfiguration.transition.duration);
676
1063
  var warpData = warpEffect
677
1064
  ? [0, 1, 2].map(function (index) { return (__assign(__assign({}, warpEffect), { index: index })); })
678
1065
  : [];
@@ -947,6 +1334,14 @@ var createSvgGlobeSeries = function (configuration) {
947
1334
  globalThis.cancelAnimationFrame(warpFrame);
948
1335
  warpFrame = undefined;
949
1336
  }
1337
+ cloudTransitionToken += 1;
1338
+ if (cloudFrame !== undefined) {
1339
+ globalThis.cancelAnimationFrame(cloudFrame);
1340
+ cloudFrame = undefined;
1341
+ }
1342
+ cloudCanvas === null || cloudCanvas === void 0 ? void 0 : cloudCanvas.remove();
1343
+ cloudCanvas = undefined;
1344
+ cloudHost = undefined;
950
1345
  wheelZoomReference = undefined;
951
1346
  hoveredMarkerTarget = undefined;
952
1347
  markerPress = undefined;