@keneth80/k-chart 1.4.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
@@ -19,15 +19,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
19
  }
20
20
  return to.concat(ar || Array.prototype.slice.call(from));
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.createKChart = exports.createWebglLineSeries = exports.createWebglPointSeries = exports.createCanvasCandlestickSeries = exports.createCanvasPointSeries = exports.createCanvasLineSeries = exports.createLineSeries = exports.createCursorLineOption = exports.createGuideLineOption = exports.createSpecAreaOption = exports.createCustomSeries = exports.startKChartRenderWorker = exports.downsampleLTTB = void 0;
26
+ exports.createKChart = exports.createWebglLineSeries = exports.createWebglPointSeries = exports.createSvgGlobeSeries = exports.createCanvasCandlestickSeries = exports.createCanvasPointSeries = exports.createCanvasLineSeries = exports.createLineSeries = exports.createCursorLineOption = exports.createGuideLineOption = exports.createSpecAreaOption = exports.createCustomSeries = exports.startKChartRenderWorker = exports.downsampleLTTB = void 0;
24
27
  var d3_array_1 = require("d3-array");
25
28
  var d3_axis_1 = require("d3-axis");
29
+ var d3_geo_1 = require("d3-geo");
26
30
  var d3_scale_1 = require("d3-scale");
27
31
  var d3_scale_chromatic_1 = require("d3-scale-chromatic");
28
32
  var d3_selection_1 = require("d3-selection");
29
33
  var d3_shape_1 = require("d3-shape");
30
34
  var d3_zoom_1 = require("d3-zoom");
35
+ var topojson_client_1 = require("topojson-client");
36
+ var countries_110m_json_1 = __importDefault(require("world-atlas/countries-110m.json"));
37
+ var land_110m_json_1 = __importDefault(require("world-atlas/land-110m.json"));
31
38
  var defaultMargin = {
32
39
  top: 24,
33
40
  right: 24,
@@ -452,6 +459,132 @@ var formatCandlestickTooltipValue = function (value) {
452
459
  var numberValue = Number(value);
453
460
  return Number.isFinite(numberValue) ? numberValue.toLocaleString(undefined, { maximumFractionDigits: 4 }) : String(value);
454
461
  };
462
+ var resolveGlobePointValue = function (point, field) { return Number(point[field]); };
463
+ var resolveGlobeMarkerRadius = function (point, configuration) {
464
+ var _a;
465
+ if (typeof configuration.markerRadius === 'function') {
466
+ return configuration.markerRadius(point);
467
+ }
468
+ return (_a = configuration.markerRadius) !== null && _a !== void 0 ? _a : 5;
469
+ };
470
+ var resolveGlobeMarkerColor = function (point, configuration, fallbackColor) {
471
+ var _a;
472
+ if (typeof configuration.markerColor === 'function') {
473
+ return configuration.markerColor(point);
474
+ }
475
+ return (_a = configuration.markerColor) !== null && _a !== void 0 ? _a : fallbackColor;
476
+ };
477
+ var resolveGlobeLandStyle = function (value, feature, index, fallback) {
478
+ if (typeof value === 'function') {
479
+ return value(feature, index);
480
+ }
481
+ return value !== null && value !== void 0 ? value : fallback;
482
+ };
483
+ var resolveGlobeLandOpacity = function (value, feature, index) {
484
+ if (typeof value === 'function') {
485
+ return value(feature, index);
486
+ }
487
+ return value !== null && value !== void 0 ? value : 0.88;
488
+ };
489
+ var normalizeGlobeLandFeatures = function (geoJson) {
490
+ var values = Array.isArray(geoJson) ? geoJson : [geoJson];
491
+ return values.flatMap(function (value) {
492
+ if ((value === null || value === void 0 ? void 0 : value.type) === 'FeatureCollection' && Array.isArray(value.features)) {
493
+ return value.features;
494
+ }
495
+ return value ? [value] : [];
496
+ });
497
+ };
498
+ var normalizeGlobeRotation = function (rotation) {
499
+ var _a, _b, _c;
500
+ return [
501
+ (_a = rotation === null || rotation === void 0 ? void 0 : rotation[0]) !== null && _a !== void 0 ? _a : 0,
502
+ (_b = rotation === null || rotation === void 0 ? void 0 : rotation[1]) !== null && _b !== void 0 ? _b : -12,
503
+ (_c = rotation === null || rotation === void 0 ? void 0 : rotation[2]) !== null && _c !== void 0 ? _c : 0
504
+ ];
505
+ };
506
+ var resolveGlobeZoomConfiguration = function (zoom) {
507
+ var _a, _b, _c, _d, _e, _f, _g;
508
+ if (typeof zoom === 'boolean') {
509
+ return {
510
+ enabled: zoom,
511
+ wheel: true,
512
+ pinch: true,
513
+ controls: false,
514
+ min: 0.55,
515
+ max: 3,
516
+ wheelSensitivity: 0.0012
517
+ };
518
+ }
519
+ return {
520
+ enabled: (_a = zoom === null || zoom === void 0 ? void 0 : zoom.enabled) !== null && _a !== void 0 ? _a : false,
521
+ wheel: (_b = zoom === null || zoom === void 0 ? void 0 : zoom.wheel) !== null && _b !== void 0 ? _b : true,
522
+ pinch: (_c = zoom === null || zoom === void 0 ? void 0 : zoom.pinch) !== null && _c !== void 0 ? _c : true,
523
+ controls: (_d = zoom === null || zoom === void 0 ? void 0 : zoom.controls) !== null && _d !== void 0 ? _d : false,
524
+ min: (_e = zoom === null || zoom === void 0 ? void 0 : zoom.min) !== null && _e !== void 0 ? _e : 0.55,
525
+ max: (_f = zoom === null || zoom === void 0 ? void 0 : zoom.max) !== null && _f !== void 0 ? _f : 3,
526
+ wheelSensitivity: (_g = zoom === null || zoom === void 0 ? void 0 : zoom.wheelSensitivity) !== null && _g !== void 0 ? _g : 0.0012
527
+ };
528
+ };
529
+ var resolveGlobeZoomControlsConfiguration = function (controls) {
530
+ var _a, _b, _c, _d;
531
+ if (typeof controls === 'boolean') {
532
+ return {
533
+ visible: controls,
534
+ step: 0.22,
535
+ x: 8,
536
+ y: 8
537
+ };
538
+ }
539
+ return {
540
+ visible: (_a = controls === null || controls === void 0 ? void 0 : controls.visible) !== null && _a !== void 0 ? _a : false,
541
+ step: (_b = controls === null || controls === void 0 ? void 0 : controls.step) !== null && _b !== void 0 ? _b : 0.22,
542
+ x: (_c = controls === null || controls === void 0 ? void 0 : controls.x) !== null && _c !== void 0 ? _c : 8,
543
+ y: (_d = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _d !== void 0 ? _d : 8
544
+ };
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
+ };
578
+ var WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
579
+ var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
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; });
581
+ var isGlobePointVisible = function (lon, lat, rotation) {
582
+ if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
583
+ return false;
584
+ }
585
+ var center = [-rotation[0], -rotation[1]];
586
+ return (0, d3_geo_1.geoDistance)([lon, lat], center) <= Math.PI / 2;
587
+ };
455
588
  var downsampleLTTB = function (data, threshold, xAccessor, yAccessor) {
456
589
  var dataLength = data.length;
457
590
  var targetLength = Math.floor(threshold);
@@ -2059,6 +2192,816 @@ var createCanvasCandlestickSeries = function (configuration) { return (0, export
2059
2192
  }
2060
2193
  }); };
2061
2194
  exports.createCanvasCandlestickSeries = createCanvasCandlestickSeries;
2195
+ var createSvgGlobeSeries = function (configuration) {
2196
+ var rotation = normalizeGlobeRotation(configuration.initialRotate);
2197
+ var zoomLevel = 1;
2198
+ var dragging = false;
2199
+ var dragStart = [0, 0];
2200
+ var rotationStart = __spreadArray([], rotation, true);
2201
+ var activePointers = new Map();
2202
+ var pinchStartDistance = 0;
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;
2216
+ return (0, exports.createCustomSeries)({
2217
+ selector: configuration.selector,
2218
+ displayName: configuration.displayName,
2219
+ xField: configuration.lonField,
2220
+ yField: configuration.latField,
2221
+ color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
2222
+ render: function (_a) {
2223
+ var _b;
2224
+ var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
2225
+ var width = plotSize.width;
2226
+ var height = plotSize.height;
2227
+ var centerX = width / 2;
2228
+ var centerY = height / 2;
2229
+ var zoomConfiguration = resolveGlobeZoomConfiguration(configuration.zoom);
2230
+ var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
2231
+ var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
2232
+ var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
2233
+ var drilldownConfiguration = resolveGlobeDrilldownConfiguration(configuration.drilldown);
2234
+ zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
2235
+ var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
2236
+ var globeProjection = (0, d3_geo_1.geoOrthographic)()
2237
+ .translate([centerX, centerY])
2238
+ .scale(baseScale * zoomLevel)
2239
+ .rotate(rotation)
2240
+ .clipAngle(90);
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
+ };
2254
+ var getFirstTwoPointerDistance = function () {
2255
+ var points = Array.from(activePointers.values());
2256
+ if (points.length < 2) {
2257
+ return 0;
2258
+ }
2259
+ var dx = points[0][0] - points[1][0];
2260
+ var dy = points[0][1] - points[1][1];
2261
+ return Math.hypot(dx, dy);
2262
+ };
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);
2400
+ draw();
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
+ };
2481
+ var draw = function () {
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));
2489
+ var globeGroup = group.selectAll('g.kchart-globe-layer')
2490
+ .data([undefined])
2491
+ .join('g')
2492
+ .attr('class', 'kchart-globe-layer')
2493
+ .style('cursor', configuration.draggable === false || viewMode === 'map' ? 'default' : dragging ? 'grabbing' : 'grab')
2494
+ .style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
2495
+ globeGroup.selectAll('path.kchart-globe-sphere')
2496
+ .data(viewMode === 'globe' ? [{ type: 'Sphere' }] : [])
2497
+ .join('path')
2498
+ .attr('class', 'kchart-globe-sphere')
2499
+ .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
2500
+ .style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : 'rgba(15, 23, 42, 0.92)')
2501
+ .style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(148, 163, 184, 0.62)')
2502
+ .style('stroke-width', 1.2)
2503
+ .style('pointer-events', 'all');
2504
+ var defaultLandGeoJson = configuration.landMode === 'countries'
2505
+ ? WORLD_COUNTRY_GEOJSON
2506
+ : WORLD_LAND_GEOJSON;
2507
+ var landData = configuration.landVisible === false
2508
+ ? []
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();
2533
+ globeGroup.selectAll('path.kchart-globe-land')
2534
+ .data(landData)
2535
+ .join('path')
2536
+ .attr('class', 'kchart-globe-land')
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)'); })
2541
+ .style('stroke-width', 1)
2542
+ .style('pointer-events', 'none');
2543
+ globeGroup.selectAll('path.kchart-globe-country-borders')
2544
+ .data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
2545
+ .join('path')
2546
+ .attr('class', 'kchart-globe-country-borders')
2547
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2548
+ .style('fill', 'none')
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)
2551
+ .style('pointer-events', 'none');
2552
+ globeGroup.selectAll('path.kchart-globe-graticule')
2553
+ .data(configuration.graticuleVisible === false || viewMode === 'external-map' ? [] : [(0, d3_geo_1.geoGraticule10)()])
2554
+ .join('path')
2555
+ .attr('class', 'kchart-globe-graticule')
2556
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2557
+ .style('fill', 'none')
2558
+ .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(148, 163, 184, 0.22)')
2559
+ .style('stroke-width', 0.8)
2560
+ .style('pointer-events', 'none');
2561
+ var markerData = (viewMode === 'external-map' ? [] : data).map(function (point) {
2562
+ var lat = resolveGlobePointValue(point, configuration.latField);
2563
+ var lon = resolveGlobePointValue(point, configuration.lonField);
2564
+ var projected = viewMode === 'map'
2565
+ ? mapProjection([lon, lat])
2566
+ : globeProjection([lon, lat]);
2567
+ return {
2568
+ data: point,
2569
+ lat: lat,
2570
+ lon: lon,
2571
+ projected: projected,
2572
+ visible: Boolean(projected) && (viewMode === 'map'
2573
+ ? true
2574
+ : isGlobePointVisible(lon, lat, rotation))
2575
+ };
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);
2663
+ var markers = globeGroup.selectAll('circle.kchart-globe-marker')
2664
+ .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
2665
+ markers.exit().remove();
2666
+ markers.enter()
2667
+ .append('circle')
2668
+ .attr('class', 'kchart-globe-marker')
2669
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
2670
+ .style('pointer-events', 'all')
2671
+ .merge(markers)
2672
+ .attr('cx', function (datum) { return datum.projected[0]; })
2673
+ .attr('cy', function (datum) { return datum.projected[1]; })
2674
+ .attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
2675
+ .style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
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);
2690
+ var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
2691
+ .data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
2692
+ labels.exit().remove();
2693
+ labels.enter()
2694
+ .append('text')
2695
+ .attr('class', 'kchart-globe-marker-label')
2696
+ .merge(labels)
2697
+ .attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
2698
+ .attr('y', function (datum) { return datum.projected[1] + 4; })
2699
+ .style('fill', 'rgba(248, 251, 255, 0.82)')
2700
+ .style('font-size', '11px')
2701
+ .style('font-weight', 700)
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;
2810
+ var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
2811
+ var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
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 })); });
2819
+ var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
2820
+ .data(controlsVisible ? [undefined] : []);
2821
+ zoomControls.exit().remove();
2822
+ var zoomControlsEnter = zoomControls.enter()
2823
+ .append('g')
2824
+ .attr('class', 'kchart-globe-zoom-controls')
2825
+ .style('pointer-events', 'all');
2826
+ var zoomControlsMerged = zoomControlsEnter
2827
+ .merge(zoomControls)
2828
+ .attr('transform', "translate(".concat(controlsX, ",").concat(controlsY, ")"));
2829
+ var controlButtons = zoomControlsMerged.selectAll('g.kchart-globe-zoom-control')
2830
+ .data(controlItems, function (datum) { return datum.key; });
2831
+ controlButtons.exit().remove();
2832
+ var controlButtonsEnter = controlButtons.enter()
2833
+ .append('g')
2834
+ .attr('class', 'kchart-globe-zoom-control')
2835
+ .style('cursor', 'pointer')
2836
+ .on('pointerdown', function (event) {
2837
+ event.preventDefault();
2838
+ event.stopPropagation();
2839
+ })
2840
+ .on('click', function (event, datum) {
2841
+ event.preventDefault();
2842
+ event.stopPropagation();
2843
+ if (datum.key === 'in') {
2844
+ applyGlobeZoom(zoomLevel * (1 + zoomControlsConfiguration.step));
2845
+ return;
2846
+ }
2847
+ if (datum.key === 'out') {
2848
+ applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
2849
+ return;
2850
+ }
2851
+ if (datum.key === 'globe') {
2852
+ exitDrilldown();
2853
+ return;
2854
+ }
2855
+ applyGlobeZoom(1);
2856
+ });
2857
+ controlButtonsEnter.append('rect')
2858
+ .attr('class', 'kchart-globe-zoom-control-bg')
2859
+ .attr('width', 34)
2860
+ .attr('height', 27)
2861
+ .attr('rx', 6);
2862
+ controlButtonsEnter.append('text')
2863
+ .attr('class', 'kchart-globe-zoom-control-label')
2864
+ .attr('x', 17)
2865
+ .attr('y', 18)
2866
+ .attr('text-anchor', 'middle');
2867
+ controlButtonsEnter.append('title');
2868
+ var controlButtonsMerged = controlButtonsEnter.merge(controlButtons)
2869
+ .attr('transform', function (datum) { return "translate(0,".concat(datum.y, ")"); })
2870
+ .style('opacity', function (datum) {
2871
+ if (datum.key === 'in' && zoomLevel >= maxZoom)
2872
+ return 0.48;
2873
+ if (datum.key === 'out' && zoomLevel <= minZoom)
2874
+ return 0.48;
2875
+ return 1;
2876
+ });
2877
+ controlButtonsMerged.select('rect.kchart-globe-zoom-control-bg')
2878
+ .style('fill', 'rgba(15, 23, 42, 0.72)')
2879
+ .style('stroke', 'rgba(226, 232, 240, 0.42)')
2880
+ .style('stroke-width', 1);
2881
+ controlButtonsMerged.select('text.kchart-globe-zoom-control-label')
2882
+ .style('fill', 'rgba(248, 251, 255, 0.92)')
2883
+ .style('font-size', function (datum) { return datum.key === 'reset' ? '10px' : '17px'; })
2884
+ .style('font-weight', 800)
2885
+ .text(function (datum) { return datum.label; });
2886
+ controlButtonsMerged.select('title')
2887
+ .text(function (datum) { return datum.title; });
2888
+ };
2889
+ draw();
2890
+ var globeLayer = group.select('g.kchart-globe-layer');
2891
+ globeLayer.on('.kchart-globe-drag', null);
2892
+ globeLayer.on('.kchart-globe-zoom', null);
2893
+ if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
2894
+ globeLayer.on('wheel.kchart-globe-zoom', function (event) {
2895
+ var _a;
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);
2911
+ var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
2912
+ applyGlobeZoom(zoomLevel * zoomDelta, wheelZoomReference, hoveredMarkerTarget);
2913
+ });
2914
+ }
2915
+ if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
2916
+ globeLayer
2917
+ .on('pointerdown.kchart-globe-drag', function (event) {
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
+ }
2923
+ var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
2924
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
2925
+ activePointers.set(event.pointerId, currentPoint);
2926
+ }
2927
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
2928
+ dragging = false;
2929
+ pinchStartDistance = getFirstTwoPointerDistance();
2930
+ pinchStartZoom = zoomLevel;
2931
+ }
2932
+ else if (configuration.draggable !== false && viewMode === 'globe') {
2933
+ dragging = true;
2934
+ dragStart = currentPoint;
2935
+ rotationStart = __spreadArray([], rotation, true);
2936
+ }
2937
+ (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2938
+ event.preventDefault();
2939
+ draw();
2940
+ })
2941
+ .on('pointermove.kchart-globe-drag', function (event) {
2942
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.has(event.pointerId)) {
2943
+ activePointers.set(event.pointerId, (0, d3_selection_1.pointer)(event, group.node()));
2944
+ }
2945
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
2946
+ var distance = getFirstTwoPointerDistance();
2947
+ if (pinchStartDistance > 0 && distance > 0) {
2948
+ applyGlobeZoom(pinchStartZoom * distance / pinchStartDistance);
2949
+ }
2950
+ event.preventDefault();
2951
+ return;
2952
+ }
2953
+ if (!dragging) {
2954
+ return;
2955
+ }
2956
+ var _a = (0, d3_selection_1.pointer)(event, group.node()), mouseX = _a[0], mouseY = _a[1];
2957
+ var dx = mouseX - dragStart[0];
2958
+ var dy = mouseY - dragStart[1];
2959
+ rotation = [
2960
+ rotationStart[0] + dx / Math.max(width, 1) * 360,
2961
+ clampNumber(rotationStart[1] - dy / Math.max(height, 1) * 180, -89, 89),
2962
+ rotationStart[2]
2963
+ ];
2964
+ event.preventDefault();
2965
+ draw();
2966
+ })
2967
+ .on('pointerup.kchart-globe-drag pointercancel.kchart-globe-drag', function (event) {
2968
+ var _a, _b;
2969
+ activePointers.delete(event.pointerId);
2970
+ if (activePointers.size < 2) {
2971
+ pinchStartDistance = 0;
2972
+ pinchStartZoom = zoomLevel;
2973
+ }
2974
+ dragging = false;
2975
+ settledCenter = resolveGlobeCenter();
2976
+ (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2977
+ draw();
2978
+ });
2979
+ }
2980
+ },
2981
+ destroy: function (_a) {
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;
2999
+ plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
3000
+ plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
3001
+ }
3002
+ });
3003
+ };
3004
+ exports.createSvgGlobeSeries = createSvgGlobeSeries;
2062
3005
  var createWebglPointSeries = function (configuration) { return (0, exports.createCustomSeries)({
2063
3006
  selector: configuration.selector,
2064
3007
  displayName: configuration.displayName,