@keneth80/k-chart 1.5.0 → 1.6.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.
package/lib/kchart.js CHANGED
@@ -543,6 +543,38 @@ var resolveGlobeZoomControlsConfiguration = function (controls) {
543
543
  y: (_d = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _d !== void 0 ? _d : 8
544
544
  };
545
545
  };
546
+ var resolveGlobeDrilldownConfiguration = function (drilldown) {
547
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
548
+ if (typeof drilldown === 'boolean') {
549
+ return {
550
+ enabled: drilldown,
551
+ mode: 'map',
552
+ autoMapOnZoom: false,
553
+ mapZoomThreshold: 2.4,
554
+ globeZoomThreshold: 1.8,
555
+ focusZoom: 2.6,
556
+ zoomScale: 6,
557
+ duration: 720,
558
+ resetControl: true
559
+ };
560
+ }
561
+ return {
562
+ enabled: (_a = drilldown === null || drilldown === void 0 ? void 0 : drilldown.enabled) !== null && _a !== void 0 ? _a : false,
563
+ mode: (_b = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mode) !== null && _b !== void 0 ? _b : 'map',
564
+ autoMapOnZoom: (_c = drilldown === null || drilldown === void 0 ? void 0 : drilldown.autoMapOnZoom) !== null && _c !== void 0 ? _c : false,
565
+ mapZoomThreshold: (_d = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mapZoomThreshold) !== null && _d !== void 0 ? _d : 2.4,
566
+ globeZoomThreshold: (_e = drilldown === null || drilldown === void 0 ? void 0 : drilldown.globeZoomThreshold) !== null && _e !== void 0 ? _e : 1.8,
567
+ focusZoom: (_f = drilldown === null || drilldown === void 0 ? void 0 : drilldown.focusZoom) !== null && _f !== void 0 ? _f : 2.6,
568
+ zoomScale: (_g = drilldown === null || drilldown === void 0 ? void 0 : drilldown.zoomScale) !== null && _g !== void 0 ? _g : 6,
569
+ duration: (_h = drilldown === null || drilldown === void 0 ? void 0 : drilldown.duration) !== null && _h !== void 0 ? _h : 720,
570
+ resetControl: (_j = drilldown === null || drilldown === void 0 ? void 0 : drilldown.resetControl) !== null && _j !== void 0 ? _j : true,
571
+ landFill: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landFill,
572
+ landStroke: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landStroke,
573
+ landOpacity: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landOpacity,
574
+ onEnter: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onEnter,
575
+ onExit: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onExit
576
+ };
577
+ };
546
578
  var WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
547
579
  var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
548
580
  var WORLD_COUNTRY_BORDERS_GEOJSON = (0, topojson_client_1.mesh)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries, function (a, b) { return a !== b; });
@@ -2169,6 +2201,18 @@ var createSvgGlobeSeries = function (configuration) {
2169
2201
  var activePointers = new Map();
2170
2202
  var pinchStartDistance = 0;
2171
2203
  var pinchStartZoom = 1;
2204
+ var viewMode = 'globe';
2205
+ var focusedPoint;
2206
+ var drilldownRestoreState;
2207
+ var warpEffect;
2208
+ var warpTimer;
2209
+ var warpFrame;
2210
+ var wheelZoomReference;
2211
+ var wheelZoomReferenceTimer;
2212
+ var hoveredMarkerTarget;
2213
+ var markerPress;
2214
+ var settledCenter = [-rotation[0], -rotation[1]];
2215
+ var externalMapTransitioning = false;
2172
2216
  return (0, exports.createCustomSeries)({
2173
2217
  selector: configuration.selector,
2174
2218
  displayName: configuration.displayName,
@@ -2186,14 +2230,27 @@ var createSvgGlobeSeries = function (configuration) {
2186
2230
  var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
2187
2231
  var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
2188
2232
  var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
2233
+ var drilldownConfiguration = resolveGlobeDrilldownConfiguration(configuration.drilldown);
2189
2234
  zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
2190
2235
  var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
2191
- var projection = (0, d3_geo_1.geoOrthographic)()
2236
+ var globeProjection = (0, d3_geo_1.geoOrthographic)()
2192
2237
  .translate([centerX, centerY])
2193
2238
  .scale(baseScale * zoomLevel)
2194
2239
  .rotate(rotation)
2195
2240
  .clipAngle(90);
2196
- var path = (0, d3_geo_1.geoPath)(projection);
2241
+ var mapProjection = (0, d3_geo_1.geoMercator)()
2242
+ .translate([centerX, centerY])
2243
+ .scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel))
2244
+ .center(focusedPoint ? [focusedPoint.lon, focusedPoint.lat] : [0, 0]);
2245
+ var path = (0, d3_geo_1.geoPath)(globeProjection);
2246
+ var mapPath = (0, d3_geo_1.geoPath)(mapProjection);
2247
+ var resolveGlobeCenter = function () {
2248
+ var _a;
2249
+ var inverted = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, [centerX, centerY]);
2250
+ return inverted && Number.isFinite(inverted[0]) && Number.isFinite(inverted[1])
2251
+ ? inverted
2252
+ : [-rotation[0], -rotation[1]];
2253
+ };
2197
2254
  var getFirstTwoPointerDistance = function () {
2198
2255
  var points = Array.from(activePointers.values());
2199
2256
  if (points.length < 2) {
@@ -2203,22 +2260,240 @@ var createSvgGlobeSeries = function (configuration) {
2203
2260
  var dy = points[0][1] - points[1][1];
2204
2261
  return Math.hypot(dx, dy);
2205
2262
  };
2206
- var applyGlobeZoom = function (nextZoom) {
2207
- zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
2263
+ var cancelWarpFrame = function () {
2264
+ if (warpFrame !== undefined) {
2265
+ globalThis.cancelAnimationFrame(warpFrame);
2266
+ warpFrame = undefined;
2267
+ }
2268
+ };
2269
+ var clearWheelZoomReference = function () {
2270
+ wheelZoomReference = undefined;
2271
+ if (wheelZoomReferenceTimer !== undefined) {
2272
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
2273
+ wheelZoomReferenceTimer = undefined;
2274
+ }
2275
+ };
2276
+ var easeInOutCubic = function (progress) { return progress < 0.5
2277
+ ? 4 * progress * progress * progress
2278
+ : 1 - Math.pow(-2 * progress + 2, 3) / 2; };
2279
+ var shortestAngleDelta = function (from, to) {
2280
+ return (to - from + 540) % 360 - 180;
2281
+ };
2282
+ var enterDrilldown = function (datum, mode, restoreZoomLevel, moveCamera) {
2283
+ if (mode === void 0) { mode = drilldownConfiguration.mode; }
2284
+ if (moveCamera === void 0) { moveCamera = true; }
2285
+ if (!drilldownConfiguration.enabled || externalMapTransitioning) {
2286
+ return;
2287
+ }
2288
+ clearWheelZoomReference();
2289
+ hoveredMarkerTarget = undefined;
2290
+ if (warpTimer !== undefined) {
2291
+ globalThis.clearTimeout(warpTimer);
2292
+ warpTimer = undefined;
2293
+ }
2294
+ cancelWarpFrame();
2295
+ if (!focusedPoint) {
2296
+ drilldownRestoreState = {
2297
+ rotation: __spreadArray([], rotation, true),
2298
+ zoomLevel: clampNumber(restoreZoomLevel !== null && restoreZoomLevel !== void 0 ? restoreZoomLevel : zoomLevel, minZoom, maxZoom)
2299
+ };
2300
+ }
2301
+ focusedPoint = datum;
2302
+ if (mode === 'zoom') {
2303
+ viewMode = 'globe';
2304
+ rotation = [
2305
+ -datum.lon,
2306
+ -datum.lat,
2307
+ rotation[2]
2308
+ ];
2309
+ zoomLevel = clampNumber(drilldownConfiguration.focusZoom, minZoom, maxZoom);
2310
+ }
2311
+ else if (mode === 'external-map') {
2312
+ externalMapTransitioning = true;
2313
+ viewMode = 'globe';
2314
+ }
2315
+ else {
2316
+ viewMode = mode;
2317
+ }
2318
+ warpEffect = mode === 'external-map'
2319
+ ? undefined
2320
+ : {
2321
+ x: datum.projected[0],
2322
+ y: datum.projected[1],
2323
+ startedAt: Date.now(),
2324
+ duration: drilldownConfiguration.duration
2325
+ };
2326
+ var notifyEnter = function () {
2327
+ var _a;
2328
+ (_a = drilldownConfiguration.onEnter) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration, {
2329
+ data: datum.data,
2330
+ lat: datum.lat,
2331
+ lon: datum.lon,
2332
+ exit: function () { return exitDrilldown(); }
2333
+ });
2334
+ };
2335
+ if (mode === 'external-map') {
2336
+ var cameraDuration_1 = moveCamera
2337
+ ? Math.min(460, Math.max(280, drilldownConfiguration.duration * 0.34))
2338
+ : 0;
2339
+ var warpDuration_1 = Math.max(600, drilldownConfiguration.duration - cameraDuration_1);
2340
+ var startRotation_1 = __spreadArray([], rotation, true);
2341
+ var targetRotation_1 = [
2342
+ -datum.lon,
2343
+ -datum.lat,
2344
+ rotation[2]
2345
+ ];
2346
+ var longitudeDelta_1 = shortestAngleDelta(startRotation_1[0], targetRotation_1[0]);
2347
+ var startedAt_1 = globalThis.performance.now();
2348
+ var revealExternalMap_1 = function () {
2349
+ warpTimer = globalThis.setTimeout(function () {
2350
+ warpTimer = undefined;
2351
+ externalMapTransitioning = false;
2352
+ viewMode = 'external-map';
2353
+ warpEffect = undefined;
2354
+ notifyEnter();
2355
+ draw();
2356
+ }, warpDuration_1);
2357
+ };
2358
+ var startWarp_1 = function () {
2359
+ warpEffect = {
2360
+ x: centerX,
2361
+ y: centerY,
2362
+ startedAt: Date.now(),
2363
+ duration: warpDuration_1
2364
+ };
2365
+ draw();
2366
+ revealExternalMap_1();
2367
+ };
2368
+ if (!moveCamera) {
2369
+ draw();
2370
+ startWarp_1();
2371
+ return;
2372
+ }
2373
+ var animateCamera_1 = function (now) {
2374
+ var progress = clampNumber((now - startedAt_1) / cameraDuration_1, 0, 1);
2375
+ var easedProgress = easeInOutCubic(progress);
2376
+ rotation = [
2377
+ startRotation_1[0] + longitudeDelta_1 * easedProgress,
2378
+ startRotation_1[1] + (targetRotation_1[1] - startRotation_1[1]) * easedProgress,
2379
+ startRotation_1[2]
2380
+ ];
2381
+ draw();
2382
+ if (progress < 1) {
2383
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
2384
+ return;
2385
+ }
2386
+ warpFrame = undefined;
2387
+ rotation = targetRotation_1;
2388
+ startWarp_1();
2389
+ };
2390
+ draw();
2391
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
2392
+ return;
2393
+ }
2394
+ notifyEnter();
2395
+ warpTimer = globalThis.setTimeout(function () {
2396
+ warpTimer = undefined;
2397
+ warpEffect = undefined;
2398
+ draw();
2399
+ }, drilldownConfiguration.duration);
2208
2400
  draw();
2209
2401
  };
2402
+ var exitDrilldown = function (restoreState) {
2403
+ var _a;
2404
+ if (restoreState === void 0) { restoreState = true; }
2405
+ if (viewMode === 'globe' && !focusedPoint) {
2406
+ return;
2407
+ }
2408
+ if (warpTimer !== undefined) {
2409
+ globalThis.clearTimeout(warpTimer);
2410
+ warpTimer = undefined;
2411
+ }
2412
+ cancelWarpFrame();
2413
+ hoveredMarkerTarget = undefined;
2414
+ externalMapTransitioning = false;
2415
+ viewMode = 'globe';
2416
+ focusedPoint = undefined;
2417
+ if (restoreState && drilldownRestoreState) {
2418
+ rotation = __spreadArray([], drilldownRestoreState.rotation, true);
2419
+ zoomLevel = clampNumber(drilldownRestoreState.zoomLevel, minZoom, maxZoom);
2420
+ }
2421
+ drilldownRestoreState = undefined;
2422
+ warpEffect = undefined;
2423
+ (_a = drilldownConfiguration.onExit) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration);
2424
+ draw();
2425
+ };
2426
+ var resolveAutoMapTarget = function (reference) {
2427
+ var nearest;
2428
+ var center = reference !== null && reference !== void 0 ? reference : settledCenter;
2429
+ data.forEach(function (point) {
2430
+ var lat = resolveGlobePointValue(point, configuration.latField);
2431
+ var lon = resolveGlobePointValue(point, configuration.lonField);
2432
+ if (!Number.isFinite(lat) || !Number.isFinite(lon) || !isGlobePointVisible(lon, lat, rotation)) {
2433
+ return;
2434
+ }
2435
+ var projected = globeProjection([lon, lat]);
2436
+ if (!projected) {
2437
+ return;
2438
+ }
2439
+ var distance = (0, d3_geo_1.geoDistance)(center, [lon, lat]);
2440
+ if (!nearest || distance < nearest.distance) {
2441
+ nearest = {
2442
+ data: point,
2443
+ lat: lat,
2444
+ lon: lon,
2445
+ projected: projected,
2446
+ distance: distance
2447
+ };
2448
+ }
2449
+ });
2450
+ return nearest;
2451
+ };
2452
+ var syncZoomViewMode = function (reference, preferredTarget) {
2453
+ if (!drilldownConfiguration.enabled || !drilldownConfiguration.autoMapOnZoom || externalMapTransitioning) {
2454
+ return false;
2455
+ }
2456
+ var enterThreshold = Math.max(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
2457
+ var exitThreshold = Math.min(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
2458
+ if (viewMode === 'globe' && zoomLevel >= enterThreshold) {
2459
+ var target = preferredTarget !== null && preferredTarget !== void 0 ? preferredTarget : resolveAutoMapTarget(settledCenter);
2460
+ if (target) {
2461
+ var automaticTarget = __assign(__assign({}, target), { lon: settledCenter[0], lat: settledCenter[1], projected: [centerX, centerY] });
2462
+ enterDrilldown(automaticTarget, drilldownConfiguration.mode, Math.min(zoomLevel, exitThreshold), false);
2463
+ return true;
2464
+ }
2465
+ }
2466
+ if (viewMode === 'map' && zoomLevel <= exitThreshold) {
2467
+ exitDrilldown(false);
2468
+ return true;
2469
+ }
2470
+ return false;
2471
+ };
2472
+ var applyGlobeZoom = function (nextZoom, reference, preferredTarget) {
2473
+ if (externalMapTransitioning) {
2474
+ return;
2475
+ }
2476
+ zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
2477
+ if (!syncZoomViewMode(reference, preferredTarget)) {
2478
+ draw();
2479
+ }
2480
+ };
2210
2481
  var draw = function () {
2211
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2212
- projection.rotate(rotation);
2213
- projection.scale(baseScale * zoomLevel);
2482
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
2483
+ globeProjection.rotate(rotation);
2484
+ globeProjection.scale(baseScale * zoomLevel);
2485
+ if (focusedPoint) {
2486
+ mapProjection.center([focusedPoint.lon, focusedPoint.lat]);
2487
+ }
2488
+ mapProjection.scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel));
2214
2489
  var globeGroup = group.selectAll('g.kchart-globe-layer')
2215
2490
  .data([undefined])
2216
2491
  .join('g')
2217
2492
  .attr('class', 'kchart-globe-layer')
2218
- .style('cursor', configuration.draggable === false ? 'default' : dragging ? 'grabbing' : 'grab')
2493
+ .style('cursor', configuration.draggable === false || viewMode === 'map' ? 'default' : dragging ? 'grabbing' : 'grab')
2219
2494
  .style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
2220
2495
  globeGroup.selectAll('path.kchart-globe-sphere')
2221
- .data([{ type: 'Sphere' }])
2496
+ .data(viewMode === 'globe' ? [{ type: 'Sphere' }] : [])
2222
2497
  .join('path')
2223
2498
  .attr('class', 'kchart-globe-sphere')
2224
2499
  .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
@@ -2231,100 +2506,316 @@ var createSvgGlobeSeries = function (configuration) {
2231
2506
  : WORLD_LAND_GEOJSON;
2232
2507
  var landData = configuration.landVisible === false
2233
2508
  ? []
2234
- : normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
2509
+ : viewMode === 'external-map'
2510
+ ? []
2511
+ : normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
2512
+ var activePath = viewMode === 'map' ? mapPath : path;
2513
+ var activeLandFill = viewMode === 'map'
2514
+ ? (_d = drilldownConfiguration.landFill) !== null && _d !== void 0 ? _d : configuration.landFill
2515
+ : configuration.landFill;
2516
+ var activeLandStroke = viewMode === 'map'
2517
+ ? (_e = drilldownConfiguration.landStroke) !== null && _e !== void 0 ? _e : configuration.landStroke
2518
+ : configuration.landStroke;
2519
+ var activeLandOpacity = viewMode === 'map'
2520
+ ? (_f = drilldownConfiguration.landOpacity) !== null && _f !== void 0 ? _f : configuration.landOpacity
2521
+ : configuration.landOpacity;
2522
+ globeGroup.selectAll('rect.kchart-globe-map-background')
2523
+ .data(viewMode === 'map' ? [undefined] : [])
2524
+ .join('rect')
2525
+ .attr('class', 'kchart-globe-map-background')
2526
+ .attr('x', 0)
2527
+ .attr('y', 0)
2528
+ .attr('width', width)
2529
+ .attr('height', height)
2530
+ .style('fill', (_g = configuration.sphereFill) !== null && _g !== void 0 ? _g : 'rgba(15, 23, 42, 0.92)')
2531
+ .style('pointer-events', 'all')
2532
+ .lower();
2235
2533
  globeGroup.selectAll('path.kchart-globe-land')
2236
2534
  .data(landData)
2237
2535
  .join('path')
2238
2536
  .attr('class', 'kchart-globe-land')
2239
- .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
2240
- .style('fill', function (datum, index) { return resolveGlobeLandStyle(configuration.landFill, datum, index, '#2dd4bf'); })
2241
- .style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(configuration.landOpacity, datum, index); })
2242
- .style('stroke', function (datum, index) { return resolveGlobeLandStyle(configuration.landStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
2537
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2538
+ .style('fill', function (datum, index) { return resolveGlobeLandStyle(activeLandFill, datum, index, '#2dd4bf'); })
2539
+ .style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(activeLandOpacity, datum, index); })
2540
+ .style('stroke', function (datum, index) { return resolveGlobeLandStyle(activeLandStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
2243
2541
  .style('stroke-width', 1)
2244
2542
  .style('pointer-events', 'none');
2245
2543
  globeGroup.selectAll('path.kchart-globe-country-borders')
2246
2544
  .data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
2247
2545
  .join('path')
2248
2546
  .attr('class', 'kchart-globe-country-borders')
2249
- .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
2547
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2250
2548
  .style('fill', 'none')
2251
- .style('stroke', (_d = configuration.countryBordersStroke) !== null && _d !== void 0 ? _d : 'rgba(236, 253, 245, 0.26)')
2252
- .style('stroke-width', (_e = configuration.countryBordersStrokeWidth) !== null && _e !== void 0 ? _e : 0.55)
2549
+ .style('stroke', (_h = configuration.countryBordersStroke) !== null && _h !== void 0 ? _h : 'rgba(236, 253, 245, 0.26)')
2550
+ .style('stroke-width', (_j = configuration.countryBordersStrokeWidth) !== null && _j !== void 0 ? _j : 0.55)
2253
2551
  .style('pointer-events', 'none');
2254
2552
  globeGroup.selectAll('path.kchart-globe-graticule')
2255
- .data(configuration.graticuleVisible === false ? [] : [(0, d3_geo_1.geoGraticule10)()])
2553
+ .data(configuration.graticuleVisible === false || viewMode === 'external-map' ? [] : [(0, d3_geo_1.geoGraticule10)()])
2256
2554
  .join('path')
2257
2555
  .attr('class', 'kchart-globe-graticule')
2258
- .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
2556
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2259
2557
  .style('fill', 'none')
2260
- .style('stroke', (_f = configuration.graticuleStroke) !== null && _f !== void 0 ? _f : 'rgba(148, 163, 184, 0.22)')
2558
+ .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(148, 163, 184, 0.22)')
2261
2559
  .style('stroke-width', 0.8)
2262
2560
  .style('pointer-events', 'none');
2263
- var markerData = data.map(function (point) {
2561
+ var markerData = (viewMode === 'external-map' ? [] : data).map(function (point) {
2264
2562
  var lat = resolveGlobePointValue(point, configuration.latField);
2265
2563
  var lon = resolveGlobePointValue(point, configuration.lonField);
2266
- var projected = projection([lon, lat]);
2564
+ var projected = viewMode === 'map'
2565
+ ? mapProjection([lon, lat])
2566
+ : globeProjection([lon, lat]);
2267
2567
  return {
2268
2568
  data: point,
2269
2569
  lat: lat,
2270
2570
  lon: lon,
2271
2571
  projected: projected,
2272
- visible: Boolean(projected) && isGlobePointVisible(lon, lat, rotation)
2572
+ visible: Boolean(projected) && (viewMode === 'map'
2573
+ ? true
2574
+ : isGlobePointVisible(lon, lat, rotation))
2273
2575
  };
2274
2576
  }).filter(function (point) { return point.visible && point.projected; });
2577
+ var markerSelectable = Boolean(configuration.onMarkerClick || drilldownConfiguration.enabled);
2578
+ var activateMarker = function (event, datum) {
2579
+ var _a;
2580
+ if (!markerSelectable) {
2581
+ return;
2582
+ }
2583
+ event.preventDefault();
2584
+ event.stopPropagation();
2585
+ enterDrilldown(datum);
2586
+ (_a = configuration.onMarkerClick) === null || _a === void 0 ? void 0 : _a.call(configuration, {
2587
+ data: datum.data,
2588
+ event: event,
2589
+ lat: datum.lat,
2590
+ lon: datum.lon,
2591
+ x: datum.projected[0],
2592
+ y: datum.projected[1]
2593
+ });
2594
+ };
2595
+ var handleMarkerPointerDown = function (event, datum) {
2596
+ var _a, _b;
2597
+ if (!markerSelectable || event.button !== 0) {
2598
+ return;
2599
+ }
2600
+ event.preventDefault();
2601
+ event.stopPropagation();
2602
+ markerPress = {
2603
+ pointerId: event.pointerId,
2604
+ startX: event.clientX,
2605
+ startY: event.clientY,
2606
+ moved: false,
2607
+ datum: datum
2608
+ };
2609
+ (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2610
+ };
2611
+ var handleMarkerPointerMove = function (event) {
2612
+ if (!markerPress || markerPress.pointerId !== event.pointerId) {
2613
+ return;
2614
+ }
2615
+ if (Math.hypot(event.clientX - markerPress.startX, event.clientY - markerPress.startY) > 5) {
2616
+ markerPress.moved = true;
2617
+ }
2618
+ };
2619
+ var handleMarkerPointerUp = function (event) {
2620
+ var _a, _b;
2621
+ if (!markerPress || markerPress.pointerId !== event.pointerId) {
2622
+ return;
2623
+ }
2624
+ event.preventDefault();
2625
+ event.stopPropagation();
2626
+ var pressed = markerPress;
2627
+ markerPress = undefined;
2628
+ (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2629
+ if (!pressed.moved) {
2630
+ activateMarker(event, pressed.datum);
2631
+ }
2632
+ };
2633
+ var handleMarkerPointerCancel = function (event) {
2634
+ if ((markerPress === null || markerPress === void 0 ? void 0 : markerPress.pointerId) === event.pointerId) {
2635
+ markerPress = undefined;
2636
+ }
2637
+ };
2638
+ var markerHitAreas = globeGroup.selectAll('circle.kchart-globe-marker-hit-area')
2639
+ .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
2640
+ markerHitAreas.exit().remove();
2641
+ markerHitAreas.enter()
2642
+ .append('circle')
2643
+ .attr('class', 'kchart-globe-marker-hit-area')
2644
+ .merge(markerHitAreas)
2645
+ .attr('cx', function (datum) { return datum.projected[0]; })
2646
+ .attr('cy', function (datum) { return datum.projected[1]; })
2647
+ .attr('r', function (datum) { return Math.max(resolveGlobeMarkerRadius(datum.data, configuration) + 10, 16); })
2648
+ .style('fill', 'transparent')
2649
+ .style('stroke', 'transparent')
2650
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
2651
+ .style('pointer-events', markerSelectable ? 'all' : 'none')
2652
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2653
+ hoveredMarkerTarget = datum;
2654
+ })
2655
+ .on('mouseleave.kchart-globe-zoom-target', function () {
2656
+ hoveredMarkerTarget = undefined;
2657
+ })
2658
+ .on('click', null)
2659
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2660
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2661
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2662
+ .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2275
2663
  var markers = globeGroup.selectAll('circle.kchart-globe-marker')
2276
2664
  .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
2277
2665
  markers.exit().remove();
2278
2666
  markers.enter()
2279
2667
  .append('circle')
2280
2668
  .attr('class', 'kchart-globe-marker')
2281
- .style('cursor', configuration.onMarkerClick ? 'pointer' : 'default')
2669
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
2282
2670
  .style('pointer-events', 'all')
2283
2671
  .merge(markers)
2284
2672
  .attr('cx', function (datum) { return datum.projected[0]; })
2285
2673
  .attr('cy', function (datum) { return datum.projected[1]; })
2286
2674
  .attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
2287
2675
  .style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
2288
- .style('stroke', (_g = configuration.markerStroke) !== null && _g !== void 0 ? _g : 'rgba(248, 251, 255, 0.92)')
2289
- .style('stroke-width', (_h = configuration.markerStrokeWidth) !== null && _h !== void 0 ? _h : 1.4)
2290
- .style('opacity', (_j = configuration.markerOpacity) !== null && _j !== void 0 ? _j : 0.95)
2291
- .on('click', function (event, datum) {
2292
- if (!configuration.onMarkerClick) {
2293
- return;
2294
- }
2295
- event.preventDefault();
2296
- event.stopPropagation();
2297
- configuration.onMarkerClick({
2298
- data: datum.data,
2299
- event: event,
2300
- lat: datum.lat,
2301
- lon: datum.lon,
2302
- x: datum.projected[0],
2303
- y: datum.projected[1]
2304
- });
2305
- });
2676
+ .style('stroke', (_l = configuration.markerStroke) !== null && _l !== void 0 ? _l : 'rgba(248, 251, 255, 0.92)')
2677
+ .style('stroke-width', (_m = configuration.markerStrokeWidth) !== null && _m !== void 0 ? _m : 1.4)
2678
+ .style('opacity', (_o = configuration.markerOpacity) !== null && _o !== void 0 ? _o : 0.95)
2679
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2680
+ hoveredMarkerTarget = datum;
2681
+ })
2682
+ .on('mouseleave.kchart-globe-zoom-target', function () {
2683
+ hoveredMarkerTarget = undefined;
2684
+ })
2685
+ .on('click', null)
2686
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2687
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2688
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2689
+ .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2306
2690
  var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
2307
2691
  .data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
2308
2692
  labels.exit().remove();
2309
2693
  labels.enter()
2310
2694
  .append('text')
2311
2695
  .attr('class', 'kchart-globe-marker-label')
2312
- .style('pointer-events', 'none')
2313
2696
  .merge(labels)
2314
2697
  .attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
2315
2698
  .attr('y', function (datum) { return datum.projected[1] + 4; })
2316
2699
  .style('fill', 'rgba(248, 251, 255, 0.82)')
2317
2700
  .style('font-size', '11px')
2318
2701
  .style('font-weight', 700)
2319
- .text(function (datum) { return String(datum.data[configuration.labelField]); });
2320
- var controlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
2702
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
2703
+ .style('pointer-events', markerSelectable ? 'all' : 'none')
2704
+ .text(function (datum) { return String(datum.data[configuration.labelField]); })
2705
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2706
+ hoveredMarkerTarget = datum;
2707
+ })
2708
+ .on('mouseleave.kchart-globe-zoom-target', function () {
2709
+ hoveredMarkerTarget = undefined;
2710
+ })
2711
+ .on('click', null)
2712
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2713
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2714
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2715
+ .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2716
+ var activeWarpDuration = Math.max(480, (_p = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.duration) !== null && _p !== void 0 ? _p : drilldownConfiguration.duration);
2717
+ var warpData = warpEffect
2718
+ ? [0, 1, 2].map(function (index) { return (__assign(__assign({}, warpEffect), { index: index })); })
2719
+ : [];
2720
+ var warpRings = globeGroup.selectAll('circle.kchart-globe-warp-ring')
2721
+ .data(warpData, function (datum) { return datum.index; });
2722
+ warpRings.exit().remove();
2723
+ var warpRingsEnter = warpRings.enter()
2724
+ .append('circle')
2725
+ .attr('class', 'kchart-globe-warp-ring')
2726
+ .style('fill', 'none')
2727
+ .style('pointer-events', 'none');
2728
+ warpRingsEnter.append('animate')
2729
+ .attr('attributeName', 'r')
2730
+ .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
2731
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2732
+ .attr('values', "12;".concat(Math.max(width, height) * 0.78))
2733
+ .attr('keyTimes', '0;1')
2734
+ .attr('calcMode', 'spline')
2735
+ .attr('keySplines', '0.18 0.72 0.2 1')
2736
+ .attr('fill', 'freeze');
2737
+ warpRingsEnter.append('animate')
2738
+ .attr('attributeName', 'opacity')
2739
+ .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
2740
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2741
+ .attr('values', '0;1;0')
2742
+ .attr('keyTimes', '0;0.16;1')
2743
+ .attr('fill', 'freeze');
2744
+ warpRingsEnter.merge(warpRings)
2745
+ .attr('cx', function (datum) { return datum.x; })
2746
+ .attr('cy', function (datum) { return datum.y; })
2747
+ .attr('r', 12)
2748
+ .style('stroke', function (datum) { return datum.index === 0 ? 'rgba(255, 255, 255, 0.9)' : 'rgba(93, 184, 255, 0.62)'; })
2749
+ .style('stroke-width', function (datum) { return 3 - datum.index * 0.55; })
2750
+ .style('stroke-dasharray', function (datum) { return datum.index === 0 ? 'none' : '6 10'; })
2751
+ .style('filter', 'drop-shadow(0 0 8px rgba(93, 184, 255, 0.9))');
2752
+ var warpFlash = globeGroup.selectAll('circle.kchart-globe-warp-flash')
2753
+ .data(warpEffect ? [warpEffect] : []);
2754
+ warpFlash.exit().remove();
2755
+ var warpFlashEnter = warpFlash.enter()
2756
+ .append('circle')
2757
+ .attr('class', 'kchart-globe-warp-flash')
2758
+ .style('fill', 'rgba(248, 251, 255, 0.96)')
2759
+ .style('pointer-events', 'none')
2760
+ .style('filter', 'drop-shadow(0 0 18px rgba(93, 184, 255, 1))');
2761
+ warpFlashEnter.append('animate')
2762
+ .attr('attributeName', 'r')
2763
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2764
+ .attr('values', "5;".concat(Math.max(width, height) * 0.42))
2765
+ .attr('keyTimes', '0;1')
2766
+ .attr('fill', 'freeze');
2767
+ warpFlashEnter.append('animate')
2768
+ .attr('attributeName', 'opacity')
2769
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2770
+ .attr('values', '1;0.72;0')
2771
+ .attr('keyTimes', '0;0.18;1')
2772
+ .attr('fill', 'freeze');
2773
+ warpFlashEnter.merge(warpFlash)
2774
+ .attr('cx', function (datum) { return datum.x; })
2775
+ .attr('cy', function (datum) { return datum.y; })
2776
+ .attr('r', 5);
2777
+ var warpLines = globeGroup.selectAll('line.kchart-globe-warp-line')
2778
+ .data(warpEffect ? Array.from({ length: 18 }, function (_, index) { return index; }) : []);
2779
+ warpLines.exit().remove();
2780
+ var warpLinesEnter = warpLines.enter()
2781
+ .append('line')
2782
+ .attr('class', 'kchart-globe-warp-line')
2783
+ .style('stroke', 'rgba(248, 251, 255, 0.5)')
2784
+ .style('stroke-width', 1.4)
2785
+ .style('stroke-dasharray', '18 12')
2786
+ .style('pointer-events', 'none');
2787
+ warpLinesEnter.append('animate')
2788
+ .attr('attributeName', 'opacity')
2789
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2790
+ .attr('values', '0;0.85;0')
2791
+ .attr('keyTimes', '0;0.22;1')
2792
+ .attr('fill', 'freeze');
2793
+ warpLinesEnter.append('animate')
2794
+ .attr('attributeName', 'stroke-dashoffset')
2795
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
2796
+ .attr('from', '180')
2797
+ .attr('to', '0')
2798
+ .attr('fill', 'freeze');
2799
+ warpLinesEnter.merge(warpLines)
2800
+ .attr('x1', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.x) !== null && _a !== void 0 ? _a : centerX) + Math.cos(index / 18 * Math.PI * 2) * 18; })
2801
+ .attr('y1', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.y) !== null && _a !== void 0 ? _a : centerY) + Math.sin(index / 18 * Math.PI * 2) * 18; })
2802
+ .attr('x2', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.x) !== null && _a !== void 0 ? _a : centerX) + Math.cos(index / 18 * Math.PI * 2) * Math.max(width, height); })
2803
+ .attr('y2', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.y) !== null && _a !== void 0 ? _a : centerY) + Math.sin(index / 18 * Math.PI * 2) * Math.max(width, height); })
2804
+ .style('filter', 'drop-shadow(0 0 5px rgba(93, 184, 255, 0.82))');
2805
+ var zoomControlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
2806
+ var drilldownResetVisible = Boolean(focusedPoint)
2807
+ && drilldownConfiguration.resetControl
2808
+ && !externalMapTransitioning;
2809
+ var controlsVisible = zoomControlsVisible || drilldownResetVisible;
2321
2810
  var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
2322
2811
  var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
2323
- var controlItems = [
2324
- { key: 'in', label: '+', title: 'Zoom in', y: 0 },
2325
- { key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom', y: 31 },
2326
- { key: 'out', label: '-', title: 'Zoom out', y: 62 }
2327
- ];
2812
+ var controlItems = __spreadArray(__spreadArray([], (zoomControlsVisible ? [
2813
+ { key: 'in', label: '+', title: 'Zoom in' },
2814
+ { key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom' },
2815
+ { key: 'out', label: '-', title: 'Zoom out' }
2816
+ ] : []), true), (drilldownResetVisible ? [
2817
+ { key: 'globe', label: 'G', title: 'Back to globe' }
2818
+ ] : []), true).map(function (item, index) { return (__assign(__assign({}, item), { y: index * 31 })); });
2328
2819
  var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
2329
2820
  .data(controlsVisible ? [undefined] : []);
2330
2821
  zoomControls.exit().remove();
@@ -2357,6 +2848,10 @@ var createSvgGlobeSeries = function (configuration) {
2357
2848
  applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
2358
2849
  return;
2359
2850
  }
2851
+ if (datum.key === 'globe') {
2852
+ exitDrilldown();
2853
+ return;
2854
+ }
2360
2855
  applyGlobeZoom(1);
2361
2856
  });
2362
2857
  controlButtonsEnter.append('rect')
@@ -2397,16 +2892,34 @@ var createSvgGlobeSeries = function (configuration) {
2397
2892
  globeLayer.on('.kchart-globe-zoom', null);
2398
2893
  if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
2399
2894
  globeLayer.on('wheel.kchart-globe-zoom', function (event) {
2895
+ var _a;
2400
2896
  event.preventDefault();
2897
+ if (!wheelZoomReference) {
2898
+ var currentPoint = (0, d3_selection_1.pointer)(event, globeLayer.node());
2899
+ var reference = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, currentPoint);
2900
+ if (reference && Number.isFinite(reference[0]) && Number.isFinite(reference[1])) {
2901
+ wheelZoomReference = reference;
2902
+ }
2903
+ }
2904
+ if (wheelZoomReferenceTimer !== undefined) {
2905
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
2906
+ }
2907
+ wheelZoomReferenceTimer = globalThis.setTimeout(function () {
2908
+ wheelZoomReference = undefined;
2909
+ wheelZoomReferenceTimer = undefined;
2910
+ }, 180);
2401
2911
  var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
2402
- zoomLevel = clampNumber(zoomLevel * zoomDelta, minZoom, maxZoom);
2403
- draw();
2912
+ applyGlobeZoom(zoomLevel * zoomDelta, wheelZoomReference, hoveredMarkerTarget);
2404
2913
  });
2405
2914
  }
2406
2915
  if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
2407
2916
  globeLayer
2408
2917
  .on('pointerdown.kchart-globe-drag', function (event) {
2409
2918
  var _a, _b;
2919
+ var eventTarget = event.target;
2920
+ if (eventTarget === null || eventTarget === void 0 ? void 0 : eventTarget.closest('.kchart-globe-marker-hit-area, .kchart-globe-marker, .kchart-globe-marker-label')) {
2921
+ return;
2922
+ }
2410
2923
  var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
2411
2924
  if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
2412
2925
  activePointers.set(event.pointerId, currentPoint);
@@ -2416,7 +2929,7 @@ var createSvgGlobeSeries = function (configuration) {
2416
2929
  pinchStartDistance = getFirstTwoPointerDistance();
2417
2930
  pinchStartZoom = zoomLevel;
2418
2931
  }
2419
- else if (configuration.draggable !== false) {
2932
+ else if (configuration.draggable !== false && viewMode === 'globe') {
2420
2933
  dragging = true;
2421
2934
  dragStart = currentPoint;
2422
2935
  rotationStart = __spreadArray([], rotation, true);
@@ -2432,8 +2945,7 @@ var createSvgGlobeSeries = function (configuration) {
2432
2945
  if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
2433
2946
  var distance = getFirstTwoPointerDistance();
2434
2947
  if (pinchStartDistance > 0 && distance > 0) {
2435
- zoomLevel = clampNumber(pinchStartZoom * distance / pinchStartDistance, minZoom, maxZoom);
2436
- draw();
2948
+ applyGlobeZoom(pinchStartZoom * distance / pinchStartDistance);
2437
2949
  }
2438
2950
  event.preventDefault();
2439
2951
  return;
@@ -2460,6 +2972,7 @@ var createSvgGlobeSeries = function (configuration) {
2460
2972
  pinchStartZoom = zoomLevel;
2461
2973
  }
2462
2974
  dragging = false;
2975
+ settledCenter = resolveGlobeCenter();
2463
2976
  (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2464
2977
  draw();
2465
2978
  });
@@ -2467,6 +2980,22 @@ var createSvgGlobeSeries = function (configuration) {
2467
2980
  },
2468
2981
  destroy: function (_a) {
2469
2982
  var plotGroup = _a.plotGroup;
2983
+ if (warpTimer !== undefined) {
2984
+ globalThis.clearTimeout(warpTimer);
2985
+ warpTimer = undefined;
2986
+ }
2987
+ if (warpFrame !== undefined) {
2988
+ globalThis.cancelAnimationFrame(warpFrame);
2989
+ warpFrame = undefined;
2990
+ }
2991
+ wheelZoomReference = undefined;
2992
+ hoveredMarkerTarget = undefined;
2993
+ markerPress = undefined;
2994
+ if (wheelZoomReferenceTimer !== undefined) {
2995
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
2996
+ wheelZoomReferenceTimer = undefined;
2997
+ }
2998
+ externalMapTransitioning = false;
2470
2999
  plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
2471
3000
  plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
2472
3001
  }