@keneth80/k-chart 1.6.0 → 1.7.1

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +104 -0
  3. package/docs/code-graph-handoff.md +35 -12
  4. package/docs/functional-api.md +97 -1
  5. package/examples/three-constellation-series.ts +375 -0
  6. package/lib/core/contracts.d.ts +452 -0
  7. package/lib/core/contracts.d.ts.map +1 -0
  8. package/lib/core/contracts.js +3 -0
  9. package/lib/core/contracts.js.map +1 -0
  10. package/lib/core/create-kchart.d.ts +4 -0
  11. package/lib/core/create-kchart.d.ts.map +1 -0
  12. package/lib/core/create-kchart.js +1344 -0
  13. package/lib/core/create-kchart.js.map +1 -0
  14. package/lib/core/index.d.ts +3 -0
  15. package/lib/core/index.d.ts.map +1 -0
  16. package/lib/core/index.js +19 -0
  17. package/lib/core/index.js.map +1 -0
  18. package/lib/index.d.ts +5 -1
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js +5 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib/kchart.d.ts +11 -438
  23. package/lib/kchart.d.ts.map +1 -1
  24. package/lib/kchart.js +24 -3189
  25. package/lib/kchart.js.map +1 -1
  26. package/lib/options/cursor-line.d.ts +4 -0
  27. package/lib/options/cursor-line.d.ts.map +1 -0
  28. package/lib/options/cursor-line.js +36 -0
  29. package/lib/options/cursor-line.js.map +1 -0
  30. package/lib/options/guide-line.d.ts +5 -0
  31. package/lib/options/guide-line.d.ts.map +1 -0
  32. package/lib/options/guide-line.js +129 -0
  33. package/lib/options/guide-line.js.map +1 -0
  34. package/lib/options/index.d.ts +5 -0
  35. package/lib/options/index.d.ts.map +1 -0
  36. package/lib/options/index.js +21 -0
  37. package/lib/options/index.js.map +1 -0
  38. package/lib/options/spec-area.d.ts +5 -0
  39. package/lib/options/spec-area.d.ts.map +1 -0
  40. package/lib/options/spec-area.js +112 -0
  41. package/lib/options/spec-area.js.map +1 -0
  42. package/lib/options/tooltip-note.d.ts +15 -0
  43. package/lib/options/tooltip-note.d.ts.map +1 -0
  44. package/lib/options/tooltip-note.js +265 -0
  45. package/lib/options/tooltip-note.js.map +1 -0
  46. package/lib/series/canvas-candlestick.d.ts +3 -0
  47. package/lib/series/canvas-candlestick.d.ts.map +1 -0
  48. package/lib/series/canvas-candlestick.js +204 -0
  49. package/lib/series/canvas-candlestick.js.map +1 -0
  50. package/lib/series/canvas-line.d.ts +3 -0
  51. package/lib/series/canvas-line.d.ts.map +1 -0
  52. package/lib/series/canvas-line.js +67 -0
  53. package/lib/series/canvas-line.js.map +1 -0
  54. package/lib/series/canvas-point.d.ts +3 -0
  55. package/lib/series/canvas-point.d.ts.map +1 -0
  56. package/lib/series/canvas-point.js +52 -0
  57. package/lib/series/canvas-point.js.map +1 -0
  58. package/lib/series/custom.d.ts +3 -0
  59. package/lib/series/custom.d.ts.map +1 -0
  60. package/lib/series/custom.js +6 -0
  61. package/lib/series/custom.js.map +1 -0
  62. package/lib/series/index.d.ts +9 -0
  63. package/lib/series/index.d.ts.map +1 -0
  64. package/lib/series/index.js +25 -0
  65. package/lib/series/index.js.map +1 -0
  66. package/lib/series/support/canvas.d.ts +19 -0
  67. package/lib/series/support/canvas.d.ts.map +1 -0
  68. package/lib/series/support/canvas.js +130 -0
  69. package/lib/series/support/canvas.js.map +1 -0
  70. package/lib/series/support/scale.d.ts +3 -0
  71. package/lib/series/support/scale.d.ts.map +1 -0
  72. package/lib/series/support/scale.js +14 -0
  73. package/lib/series/support/scale.js.map +1 -0
  74. package/lib/series/support/webgl.d.ts +9 -0
  75. package/lib/series/support/webgl.d.ts.map +1 -0
  76. package/lib/series/support/webgl.js +92 -0
  77. package/lib/series/support/webgl.js.map +1 -0
  78. package/lib/series/svg-globe.d.ts +3 -0
  79. package/lib/series/svg-globe.d.ts.map +1 -0
  80. package/lib/series/svg-globe.js +964 -0
  81. package/lib/series/svg-globe.js.map +1 -0
  82. package/lib/series/svg-line.d.ts +3 -0
  83. package/lib/series/svg-line.d.ts.map +1 -0
  84. package/lib/series/svg-line.js +66 -0
  85. package/lib/series/svg-line.js.map +1 -0
  86. package/lib/series/webgl-line.d.ts +3 -0
  87. package/lib/series/webgl-line.d.ts.map +1 -0
  88. package/lib/series/webgl-line.js +67 -0
  89. package/lib/series/webgl-line.js.map +1 -0
  90. package/lib/series/webgl-point.d.ts +3 -0
  91. package/lib/series/webgl-point.d.ts.map +1 -0
  92. package/lib/series/webgl-point.js +63 -0
  93. package/lib/series/webgl-point.js.map +1 -0
  94. package/lib/utils/downsample-lttb.d.ts +2 -0
  95. package/lib/utils/downsample-lttb.d.ts.map +1 -0
  96. package/lib/utils/downsample-lttb.js +60 -0
  97. package/lib/utils/downsample-lttb.js.map +1 -0
  98. package/lib/utils/index.d.ts +2 -0
  99. package/lib/utils/index.d.ts.map +1 -0
  100. package/lib/utils/index.js +18 -0
  101. package/lib/utils/index.js.map +1 -0
  102. package/lib/worker/index.d.ts +2 -0
  103. package/lib/worker/index.d.ts.map +1 -0
  104. package/lib/worker/index.js +18 -0
  105. package/lib/worker/index.js.map +1 -0
  106. package/lib/worker/render-worker.d.ts +2 -0
  107. package/lib/worker/render-worker.d.ts.map +1 -0
  108. package/lib/worker/render-worker.js +116 -0
  109. package/lib/worker/render-worker.js.map +1 -0
  110. package/package.json +23 -9
@@ -0,0 +1,964 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createSvgGlobeSeries = void 0;
27
+ var d3_geo_1 = require("d3-geo");
28
+ var d3_selection_1 = require("d3-selection");
29
+ var topojson_client_1 = require("topojson-client");
30
+ var countries_110m_json_1 = __importDefault(require("world-atlas/countries-110m.json"));
31
+ var land_110m_json_1 = __importDefault(require("world-atlas/land-110m.json"));
32
+ var custom_1 = require("./custom");
33
+ var clampNumber = function (value, min, max) {
34
+ return Math.max(min, Math.min(max, value));
35
+ };
36
+ var resolveGlobePointValue = function (point, field) { return Number(point[field]); };
37
+ var resolveGlobeMarkerRadius = function (point, configuration) {
38
+ var _a;
39
+ return typeof configuration.markerRadius === 'function'
40
+ ? configuration.markerRadius(point)
41
+ : (_a = configuration.markerRadius) !== null && _a !== void 0 ? _a : 5;
42
+ };
43
+ var resolveGlobeMarkerColor = function (point, configuration, fallbackColor) {
44
+ var _a;
45
+ return typeof configuration.markerColor === 'function'
46
+ ? configuration.markerColor(point)
47
+ : (_a = configuration.markerColor) !== null && _a !== void 0 ? _a : fallbackColor;
48
+ };
49
+ var resolveGlobeLandStyle = function (value, feature, index, fallback) { return typeof value === 'function'
50
+ ? value(feature, index)
51
+ : value !== null && value !== void 0 ? value : fallback; };
52
+ var resolveGlobeLandOpacity = function (value, feature, index) { return typeof value === 'function'
53
+ ? value(feature, index)
54
+ : value !== null && value !== void 0 ? value : 0.88; };
55
+ var normalizeGlobeLandFeatures = function (geoJson) {
56
+ var values = Array.isArray(geoJson) ? geoJson : [geoJson];
57
+ return values.flatMap(function (value) {
58
+ if ((value === null || value === void 0 ? void 0 : value.type) === 'FeatureCollection' &&
59
+ Array.isArray(value.features)) {
60
+ return value.features;
61
+ }
62
+ return value ? [value] : [];
63
+ });
64
+ };
65
+ var normalizeGlobeRotation = function (rotation) {
66
+ var _a, _b, _c;
67
+ return [
68
+ (_a = rotation === null || rotation === void 0 ? void 0 : rotation[0]) !== null && _a !== void 0 ? _a : 0,
69
+ (_b = rotation === null || rotation === void 0 ? void 0 : rotation[1]) !== null && _b !== void 0 ? _b : -12,
70
+ (_c = rotation === null || rotation === void 0 ? void 0 : rotation[2]) !== null && _c !== void 0 ? _c : 0
71
+ ];
72
+ };
73
+ var resolveGlobeZoomConfiguration = function (zoom) {
74
+ var _a, _b, _c, _d, _e, _f, _g;
75
+ if (typeof zoom === 'boolean') {
76
+ return {
77
+ enabled: zoom,
78
+ wheel: true,
79
+ pinch: true,
80
+ controls: false,
81
+ min: 0.55,
82
+ max: 3,
83
+ wheelSensitivity: 0.0012
84
+ };
85
+ }
86
+ return {
87
+ enabled: (_a = zoom === null || zoom === void 0 ? void 0 : zoom.enabled) !== null && _a !== void 0 ? _a : false,
88
+ wheel: (_b = zoom === null || zoom === void 0 ? void 0 : zoom.wheel) !== null && _b !== void 0 ? _b : true,
89
+ pinch: (_c = zoom === null || zoom === void 0 ? void 0 : zoom.pinch) !== null && _c !== void 0 ? _c : true,
90
+ controls: (_d = zoom === null || zoom === void 0 ? void 0 : zoom.controls) !== null && _d !== void 0 ? _d : false,
91
+ min: (_e = zoom === null || zoom === void 0 ? void 0 : zoom.min) !== null && _e !== void 0 ? _e : 0.55,
92
+ max: (_f = zoom === null || zoom === void 0 ? void 0 : zoom.max) !== null && _f !== void 0 ? _f : 3,
93
+ wheelSensitivity: (_g = zoom === null || zoom === void 0 ? void 0 : zoom.wheelSensitivity) !== null && _g !== void 0 ? _g : 0.0012
94
+ };
95
+ };
96
+ var resolveGlobeZoomControlsConfiguration = function (controls) {
97
+ var _a, _b, _c, _d;
98
+ if (typeof controls === 'boolean') {
99
+ return {
100
+ visible: controls,
101
+ step: 0.22,
102
+ x: 8,
103
+ y: 8
104
+ };
105
+ }
106
+ return {
107
+ visible: (_a = controls === null || controls === void 0 ? void 0 : controls.visible) !== null && _a !== void 0 ? _a : false,
108
+ step: (_b = controls === null || controls === void 0 ? void 0 : controls.step) !== null && _b !== void 0 ? _b : 0.22,
109
+ x: (_c = controls === null || controls === void 0 ? void 0 : controls.x) !== null && _c !== void 0 ? _c : 8,
110
+ y: (_d = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _d !== void 0 ? _d : 8
111
+ };
112
+ };
113
+ var resolveGlobeDrilldownConfiguration = function (drilldown) {
114
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
115
+ if (typeof drilldown === 'boolean') {
116
+ return {
117
+ enabled: drilldown,
118
+ mode: 'map',
119
+ autoMapOnZoom: false,
120
+ mapZoomThreshold: 2.4,
121
+ globeZoomThreshold: 1.8,
122
+ focusZoom: 2.6,
123
+ zoomScale: 6,
124
+ duration: 720,
125
+ resetControl: true
126
+ };
127
+ }
128
+ 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,
137
+ resetControl: (_j = drilldown === null || drilldown === void 0 ? void 0 : drilldown.resetControl) !== null && _j !== void 0 ? _j : true,
138
+ landFill: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landFill,
139
+ landStroke: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landStroke,
140
+ landOpacity: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landOpacity,
141
+ onEnter: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onEnter,
142
+ onExit: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onExit
143
+ };
144
+ };
145
+ var WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
146
+ var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
147
+ var WORLD_COUNTRY_BORDERS_GEOJSON = (0, topojson_client_1.mesh)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries, function (left, right) { return left !== right; });
148
+ var isGlobePointVisible = function (lon, lat, rotation) {
149
+ if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
150
+ return false;
151
+ }
152
+ return (0, d3_geo_1.geoDistance)([lon, lat], [-rotation[0], -rotation[1]]) <= Math.PI / 2;
153
+ };
154
+ var createSvgGlobeSeries = function (configuration) {
155
+ var rotation = normalizeGlobeRotation(configuration.initialRotate);
156
+ var zoomLevel = 1;
157
+ var dragging = false;
158
+ var dragStart = [0, 0];
159
+ var rotationStart = __spreadArray([], rotation, true);
160
+ var activePointers = new Map();
161
+ var pinchStartDistance = 0;
162
+ var pinchStartZoom = 1;
163
+ var viewMode = 'globe';
164
+ var focusedPoint;
165
+ var drilldownRestoreState;
166
+ var warpEffect;
167
+ var warpTimer;
168
+ var warpFrame;
169
+ var wheelZoomReference;
170
+ var wheelZoomReferenceTimer;
171
+ var hoveredMarkerTarget;
172
+ var markerPress;
173
+ var settledCenter = [-rotation[0], -rotation[1]];
174
+ var externalMapTransitioning = false;
175
+ return (0, custom_1.createCustomSeries)({
176
+ selector: configuration.selector,
177
+ displayName: configuration.displayName,
178
+ xField: configuration.lonField,
179
+ yField: configuration.latField,
180
+ color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
181
+ render: function (_a) {
182
+ var _b;
183
+ var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
184
+ var width = plotSize.width;
185
+ var height = plotSize.height;
186
+ var centerX = width / 2;
187
+ var centerY = height / 2;
188
+ var zoomConfiguration = resolveGlobeZoomConfiguration(configuration.zoom);
189
+ var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
190
+ var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
191
+ var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
192
+ var drilldownConfiguration = resolveGlobeDrilldownConfiguration(configuration.drilldown);
193
+ 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));
195
+ var globeProjection = (0, d3_geo_1.geoOrthographic)()
196
+ .translate([centerX, centerY])
197
+ .scale(baseScale * zoomLevel)
198
+ .rotate(rotation)
199
+ .clipAngle(90);
200
+ var mapProjection = (0, d3_geo_1.geoMercator)()
201
+ .translate([centerX, centerY])
202
+ .scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel))
203
+ .center(focusedPoint ? [focusedPoint.lon, focusedPoint.lat] : [0, 0]);
204
+ var path = (0, d3_geo_1.geoPath)(globeProjection);
205
+ var mapPath = (0, d3_geo_1.geoPath)(mapProjection);
206
+ var resolveGlobeCenter = function () {
207
+ var _a;
208
+ var inverted = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, [centerX, centerY]);
209
+ return inverted && Number.isFinite(inverted[0]) && Number.isFinite(inverted[1])
210
+ ? inverted
211
+ : [-rotation[0], -rotation[1]];
212
+ };
213
+ var getFirstTwoPointerDistance = function () {
214
+ var points = Array.from(activePointers.values());
215
+ if (points.length < 2) {
216
+ return 0;
217
+ }
218
+ var dx = points[0][0] - points[1][0];
219
+ var dy = points[0][1] - points[1][1];
220
+ return Math.hypot(dx, dy);
221
+ };
222
+ var cancelWarpFrame = function () {
223
+ if (warpFrame !== undefined) {
224
+ globalThis.cancelAnimationFrame(warpFrame);
225
+ warpFrame = undefined;
226
+ }
227
+ };
228
+ var clearWheelZoomReference = function () {
229
+ wheelZoomReference = undefined;
230
+ if (wheelZoomReferenceTimer !== undefined) {
231
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
232
+ wheelZoomReferenceTimer = undefined;
233
+ }
234
+ };
235
+ var easeInOutCubic = function (progress) { return progress < 0.5
236
+ ? 4 * progress * progress * progress
237
+ : 1 - Math.pow(-2 * progress + 2, 3) / 2; };
238
+ var shortestAngleDelta = function (from, to) {
239
+ return (to - from + 540) % 360 - 180;
240
+ };
241
+ var enterDrilldown = function (datum, mode, restoreZoomLevel, moveCamera) {
242
+ if (mode === void 0) { mode = drilldownConfiguration.mode; }
243
+ if (moveCamera === void 0) { moveCamera = true; }
244
+ if (!drilldownConfiguration.enabled || externalMapTransitioning) {
245
+ return;
246
+ }
247
+ clearWheelZoomReference();
248
+ hoveredMarkerTarget = undefined;
249
+ if (warpTimer !== undefined) {
250
+ globalThis.clearTimeout(warpTimer);
251
+ warpTimer = undefined;
252
+ }
253
+ cancelWarpFrame();
254
+ if (!focusedPoint) {
255
+ drilldownRestoreState = {
256
+ rotation: __spreadArray([], rotation, true),
257
+ zoomLevel: clampNumber(restoreZoomLevel !== null && restoreZoomLevel !== void 0 ? restoreZoomLevel : zoomLevel, minZoom, maxZoom)
258
+ };
259
+ }
260
+ focusedPoint = datum;
261
+ if (mode === 'zoom') {
262
+ viewMode = 'globe';
263
+ rotation = [
264
+ -datum.lon,
265
+ -datum.lat,
266
+ rotation[2]
267
+ ];
268
+ zoomLevel = clampNumber(drilldownConfiguration.focusZoom, minZoom, maxZoom);
269
+ }
270
+ else if (mode === 'external-map') {
271
+ externalMapTransitioning = true;
272
+ viewMode = 'globe';
273
+ }
274
+ else {
275
+ viewMode = mode;
276
+ }
277
+ warpEffect = mode === 'external-map'
278
+ ? undefined
279
+ : {
280
+ x: datum.projected[0],
281
+ y: datum.projected[1],
282
+ startedAt: Date.now(),
283
+ duration: drilldownConfiguration.duration
284
+ };
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
+ if (mode === 'external-map') {
295
+ var cameraDuration_1 = moveCamera
296
+ ? Math.min(460, Math.max(280, drilldownConfiguration.duration * 0.34))
297
+ : 0;
298
+ var warpDuration_1 = Math.max(600, drilldownConfiguration.duration - cameraDuration_1);
299
+ var startRotation_1 = __spreadArray([], rotation, true);
300
+ var targetRotation_1 = [
301
+ -datum.lon,
302
+ -datum.lat,
303
+ rotation[2]
304
+ ];
305
+ var longitudeDelta_1 = shortestAngleDelta(startRotation_1[0], targetRotation_1[0]);
306
+ var startedAt_1 = globalThis.performance.now();
307
+ var revealExternalMap_1 = function () {
308
+ warpTimer = globalThis.setTimeout(function () {
309
+ warpTimer = undefined;
310
+ externalMapTransitioning = false;
311
+ viewMode = 'external-map';
312
+ warpEffect = undefined;
313
+ notifyEnter();
314
+ draw();
315
+ }, warpDuration_1);
316
+ };
317
+ var startWarp_1 = function () {
318
+ warpEffect = {
319
+ x: centerX,
320
+ y: centerY,
321
+ startedAt: Date.now(),
322
+ duration: warpDuration_1
323
+ };
324
+ draw();
325
+ revealExternalMap_1();
326
+ };
327
+ if (!moveCamera) {
328
+ draw();
329
+ startWarp_1();
330
+ return;
331
+ }
332
+ var animateCamera_1 = function (now) {
333
+ var progress = clampNumber((now - startedAt_1) / cameraDuration_1, 0, 1);
334
+ var easedProgress = easeInOutCubic(progress);
335
+ rotation = [
336
+ startRotation_1[0] + longitudeDelta_1 * easedProgress,
337
+ startRotation_1[1] + (targetRotation_1[1] - startRotation_1[1]) * easedProgress,
338
+ startRotation_1[2]
339
+ ];
340
+ draw();
341
+ if (progress < 1) {
342
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
343
+ return;
344
+ }
345
+ warpFrame = undefined;
346
+ rotation = targetRotation_1;
347
+ startWarp_1();
348
+ };
349
+ draw();
350
+ warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
351
+ return;
352
+ }
353
+ notifyEnter();
354
+ warpTimer = globalThis.setTimeout(function () {
355
+ warpTimer = undefined;
356
+ warpEffect = undefined;
357
+ draw();
358
+ }, drilldownConfiguration.duration);
359
+ draw();
360
+ };
361
+ var exitDrilldown = function (restoreState) {
362
+ var _a;
363
+ if (restoreState === void 0) { restoreState = true; }
364
+ if (viewMode === 'globe' && !focusedPoint) {
365
+ return;
366
+ }
367
+ if (warpTimer !== undefined) {
368
+ globalThis.clearTimeout(warpTimer);
369
+ warpTimer = undefined;
370
+ }
371
+ cancelWarpFrame();
372
+ 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);
379
+ }
380
+ drilldownRestoreState = undefined;
381
+ warpEffect = undefined;
382
+ (_a = drilldownConfiguration.onExit) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration);
383
+ draw();
384
+ };
385
+ var resolveAutoMapTarget = function (reference) {
386
+ var nearest;
387
+ var center = reference !== null && reference !== void 0 ? reference : settledCenter;
388
+ data.forEach(function (point) {
389
+ var lat = resolveGlobePointValue(point, configuration.latField);
390
+ var lon = resolveGlobePointValue(point, configuration.lonField);
391
+ if (!Number.isFinite(lat) || !Number.isFinite(lon) || !isGlobePointVisible(lon, lat, rotation)) {
392
+ return;
393
+ }
394
+ var projected = globeProjection([lon, lat]);
395
+ if (!projected) {
396
+ return;
397
+ }
398
+ var distance = (0, d3_geo_1.geoDistance)(center, [lon, lat]);
399
+ if (!nearest || distance < nearest.distance) {
400
+ nearest = {
401
+ data: point,
402
+ lat: lat,
403
+ lon: lon,
404
+ projected: projected,
405
+ distance: distance
406
+ };
407
+ }
408
+ });
409
+ return nearest;
410
+ };
411
+ var syncZoomViewMode = function (reference, preferredTarget) {
412
+ if (!drilldownConfiguration.enabled || !drilldownConfiguration.autoMapOnZoom || externalMapTransitioning) {
413
+ return false;
414
+ }
415
+ var enterThreshold = Math.max(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
416
+ var exitThreshold = Math.min(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
417
+ if (viewMode === 'globe' && zoomLevel >= enterThreshold) {
418
+ var viewportCenter = reference !== null && reference !== void 0 ? reference : settledCenter;
419
+ var target = preferredTarget !== null && preferredTarget !== void 0 ? preferredTarget : resolveAutoMapTarget(viewportCenter);
420
+ if (target) {
421
+ enterDrilldown(target, drilldownConfiguration.mode, Math.min(zoomLevel, exitThreshold), false);
422
+ return true;
423
+ }
424
+ }
425
+ if (viewMode === 'map' && zoomLevel <= exitThreshold) {
426
+ exitDrilldown(false);
427
+ return true;
428
+ }
429
+ return false;
430
+ };
431
+ var applyGlobeZoom = function (nextZoom, reference, preferredTarget) {
432
+ if (externalMapTransitioning) {
433
+ return;
434
+ }
435
+ zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
436
+ if (!syncZoomViewMode(reference, preferredTarget)) {
437
+ draw();
438
+ }
439
+ };
440
+ var draw = function () {
441
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
442
+ globeProjection.rotate(rotation);
443
+ globeProjection.scale(baseScale * zoomLevel);
444
+ if (focusedPoint) {
445
+ mapProjection.center([focusedPoint.lon, focusedPoint.lat]);
446
+ }
447
+ mapProjection.scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel));
448
+ var globeGroup = group.selectAll('g.kchart-globe-layer')
449
+ .data([undefined])
450
+ .join('g')
451
+ .attr('class', 'kchart-globe-layer')
452
+ .style('cursor', configuration.draggable === false || viewMode === 'map' ? 'default' : dragging ? 'grabbing' : 'grab')
453
+ .style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
454
+ globeGroup.selectAll('path.kchart-globe-sphere')
455
+ .data(viewMode === 'globe' ? [{ type: 'Sphere' }] : [])
456
+ .join('path')
457
+ .attr('class', 'kchart-globe-sphere')
458
+ .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)')
461
+ .style('stroke-width', 1.2)
462
+ .style('pointer-events', 'all');
463
+ var defaultLandGeoJson = configuration.landMode === 'countries'
464
+ ? WORLD_COUNTRY_GEOJSON
465
+ : WORLD_LAND_GEOJSON;
466
+ var landData = configuration.landVisible === false
467
+ ? []
468
+ : viewMode === 'external-map'
469
+ ? []
470
+ : normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
471
+ var activePath = viewMode === 'map' ? mapPath : path;
472
+ var activeLandFill = viewMode === 'map'
473
+ ? (_d = drilldownConfiguration.landFill) !== null && _d !== void 0 ? _d : configuration.landFill
474
+ : configuration.landFill;
475
+ var activeLandStroke = viewMode === 'map'
476
+ ? (_e = drilldownConfiguration.landStroke) !== null && _e !== void 0 ? _e : configuration.landStroke
477
+ : configuration.landStroke;
478
+ var activeLandOpacity = viewMode === 'map'
479
+ ? (_f = drilldownConfiguration.landOpacity) !== null && _f !== void 0 ? _f : configuration.landOpacity
480
+ : configuration.landOpacity;
481
+ globeGroup.selectAll('rect.kchart-globe-map-background')
482
+ .data(viewMode === 'map' ? [undefined] : [])
483
+ .join('rect')
484
+ .attr('class', 'kchart-globe-map-background')
485
+ .attr('x', 0)
486
+ .attr('y', 0)
487
+ .attr('width', width)
488
+ .attr('height', height)
489
+ .style('fill', (_g = configuration.sphereFill) !== null && _g !== void 0 ? _g : 'rgba(15, 23, 42, 0.92)')
490
+ .style('pointer-events', 'all')
491
+ .lower();
492
+ globeGroup.selectAll('path.kchart-globe-land')
493
+ .data(landData)
494
+ .join('path')
495
+ .attr('class', 'kchart-globe-land')
496
+ .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'); })
498
+ .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)'); })
500
+ .style('stroke-width', 1)
501
+ .style('pointer-events', 'none');
502
+ globeGroup.selectAll('path.kchart-globe-country-borders')
503
+ .data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
504
+ .join('path')
505
+ .attr('class', 'kchart-globe-country-borders')
506
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
507
+ .style('fill', 'none')
508
+ .style('stroke', (_h = configuration.countryBordersStroke) !== null && _h !== void 0 ? _h : 'rgba(236, 253, 245, 0.26)')
509
+ .style('stroke-width', (_j = configuration.countryBordersStrokeWidth) !== null && _j !== void 0 ? _j : 0.55)
510
+ .style('pointer-events', 'none');
511
+ globeGroup.selectAll('path.kchart-globe-graticule')
512
+ .data(configuration.graticuleVisible === false || viewMode === 'external-map' ? [] : [(0, d3_geo_1.geoGraticule10)()])
513
+ .join('path')
514
+ .attr('class', 'kchart-globe-graticule')
515
+ .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
516
+ .style('fill', 'none')
517
+ .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(148, 163, 184, 0.22)')
518
+ .style('stroke-width', 0.8)
519
+ .style('pointer-events', 'none');
520
+ var markerData = (viewMode === 'external-map' ? [] : data).map(function (point) {
521
+ var lat = resolveGlobePointValue(point, configuration.latField);
522
+ var lon = resolveGlobePointValue(point, configuration.lonField);
523
+ var projected = viewMode === 'map'
524
+ ? mapProjection([lon, lat])
525
+ : globeProjection([lon, lat]);
526
+ return {
527
+ data: point,
528
+ lat: lat,
529
+ lon: lon,
530
+ projected: projected,
531
+ visible: Boolean(projected) && (viewMode === 'map'
532
+ ? true
533
+ : isGlobePointVisible(lon, lat, rotation))
534
+ };
535
+ }).filter(function (point) { return point.visible && point.projected; });
536
+ var markerSelectable = Boolean(configuration.onMarkerClick || drilldownConfiguration.enabled);
537
+ var activateMarker = function (event, datum) {
538
+ var _a;
539
+ if (!markerSelectable) {
540
+ return;
541
+ }
542
+ event.preventDefault();
543
+ event.stopPropagation();
544
+ enterDrilldown(datum);
545
+ (_a = configuration.onMarkerClick) === null || _a === void 0 ? void 0 : _a.call(configuration, {
546
+ data: datum.data,
547
+ event: event,
548
+ lat: datum.lat,
549
+ lon: datum.lon,
550
+ x: datum.projected[0],
551
+ y: datum.projected[1]
552
+ });
553
+ };
554
+ var handleMarkerPointerDown = function (event, datum) {
555
+ var _a, _b;
556
+ if (!markerSelectable || event.button !== 0) {
557
+ return;
558
+ }
559
+ event.preventDefault();
560
+ event.stopPropagation();
561
+ markerPress = {
562
+ pointerId: event.pointerId,
563
+ startX: event.clientX,
564
+ startY: event.clientY,
565
+ moved: false,
566
+ datum: datum
567
+ };
568
+ (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
569
+ };
570
+ var handleMarkerPointerMove = function (event) {
571
+ if (!markerPress || markerPress.pointerId !== event.pointerId) {
572
+ return;
573
+ }
574
+ if (Math.hypot(event.clientX - markerPress.startX, event.clientY - markerPress.startY) > 5) {
575
+ markerPress.moved = true;
576
+ }
577
+ };
578
+ var handleMarkerPointerUp = function (event) {
579
+ var _a, _b;
580
+ if (!markerPress || markerPress.pointerId !== event.pointerId) {
581
+ return;
582
+ }
583
+ event.preventDefault();
584
+ event.stopPropagation();
585
+ var pressed = markerPress;
586
+ markerPress = undefined;
587
+ (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
588
+ if (!pressed.moved) {
589
+ activateMarker(event, pressed.datum);
590
+ }
591
+ };
592
+ var handleMarkerPointerCancel = function (event) {
593
+ if ((markerPress === null || markerPress === void 0 ? void 0 : markerPress.pointerId) === event.pointerId) {
594
+ markerPress = undefined;
595
+ }
596
+ };
597
+ var markerHitAreas = globeGroup.selectAll('circle.kchart-globe-marker-hit-area')
598
+ .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
599
+ markerHitAreas.exit().remove();
600
+ markerHitAreas.enter()
601
+ .append('circle')
602
+ .attr('class', 'kchart-globe-marker-hit-area')
603
+ .merge(markerHitAreas)
604
+ .attr('cx', function (datum) { return datum.projected[0]; })
605
+ .attr('cy', function (datum) { return datum.projected[1]; })
606
+ .attr('r', function (datum) { return Math.max(resolveGlobeMarkerRadius(datum.data, configuration) + 10, 16); })
607
+ .style('fill', 'transparent')
608
+ .style('stroke', 'transparent')
609
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
610
+ .style('pointer-events', markerSelectable ? 'all' : 'none')
611
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
612
+ hoveredMarkerTarget = datum;
613
+ })
614
+ .on('mouseleave.kchart-globe-zoom-target', function () {
615
+ hoveredMarkerTarget = undefined;
616
+ })
617
+ .on('click', null)
618
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
619
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
620
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
621
+ .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
622
+ var markers = globeGroup.selectAll('circle.kchart-globe-marker')
623
+ .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
624
+ markers.exit().remove();
625
+ markers.enter()
626
+ .append('circle')
627
+ .attr('class', 'kchart-globe-marker')
628
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
629
+ .style('pointer-events', 'all')
630
+ .merge(markers)
631
+ .attr('cx', function (datum) { return datum.projected[0]; })
632
+ .attr('cy', function (datum) { return datum.projected[1]; })
633
+ .attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
634
+ .style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
635
+ .style('stroke', (_l = configuration.markerStroke) !== null && _l !== void 0 ? _l : 'rgba(248, 251, 255, 0.92)')
636
+ .style('stroke-width', (_m = configuration.markerStrokeWidth) !== null && _m !== void 0 ? _m : 1.4)
637
+ .style('opacity', (_o = configuration.markerOpacity) !== null && _o !== void 0 ? _o : 0.95)
638
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
639
+ hoveredMarkerTarget = datum;
640
+ })
641
+ .on('mouseleave.kchart-globe-zoom-target', function () {
642
+ hoveredMarkerTarget = undefined;
643
+ })
644
+ .on('click', null)
645
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
646
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
647
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
648
+ .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
649
+ var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
650
+ .data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
651
+ labels.exit().remove();
652
+ labels.enter()
653
+ .append('text')
654
+ .attr('class', 'kchart-globe-marker-label')
655
+ .merge(labels)
656
+ .attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
657
+ .attr('y', function (datum) { return datum.projected[1] + 4; })
658
+ .style('fill', 'rgba(248, 251, 255, 0.82)')
659
+ .style('font-size', '11px')
660
+ .style('font-weight', 700)
661
+ .style('cursor', markerSelectable ? 'pointer' : 'default')
662
+ .style('pointer-events', markerSelectable ? 'all' : 'none')
663
+ .text(function (datum) { return String(datum.data[configuration.labelField]); })
664
+ .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
665
+ hoveredMarkerTarget = datum;
666
+ })
667
+ .on('mouseleave.kchart-globe-zoom-target', function () {
668
+ hoveredMarkerTarget = undefined;
669
+ })
670
+ .on('click', null)
671
+ .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
672
+ .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
673
+ .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
674
+ .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);
676
+ var warpData = warpEffect
677
+ ? [0, 1, 2].map(function (index) { return (__assign(__assign({}, warpEffect), { index: index })); })
678
+ : [];
679
+ var warpRings = globeGroup.selectAll('circle.kchart-globe-warp-ring')
680
+ .data(warpData, function (datum) { return datum.index; });
681
+ warpRings.exit().remove();
682
+ var warpRingsEnter = warpRings.enter()
683
+ .append('circle')
684
+ .attr('class', 'kchart-globe-warp-ring')
685
+ .style('fill', 'none')
686
+ .style('pointer-events', 'none');
687
+ warpRingsEnter.append('animate')
688
+ .attr('attributeName', 'r')
689
+ .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
690
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
691
+ .attr('values', "12;".concat(Math.max(width, height) * 0.78))
692
+ .attr('keyTimes', '0;1')
693
+ .attr('calcMode', 'spline')
694
+ .attr('keySplines', '0.18 0.72 0.2 1')
695
+ .attr('fill', 'freeze');
696
+ warpRingsEnter.append('animate')
697
+ .attr('attributeName', 'opacity')
698
+ .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
699
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
700
+ .attr('values', '0;1;0')
701
+ .attr('keyTimes', '0;0.16;1')
702
+ .attr('fill', 'freeze');
703
+ warpRingsEnter.merge(warpRings)
704
+ .attr('cx', function (datum) { return datum.x; })
705
+ .attr('cy', function (datum) { return datum.y; })
706
+ .attr('r', 12)
707
+ .style('stroke', function (datum) { return datum.index === 0 ? 'rgba(255, 255, 255, 0.9)' : 'rgba(93, 184, 255, 0.62)'; })
708
+ .style('stroke-width', function (datum) { return 3 - datum.index * 0.55; })
709
+ .style('stroke-dasharray', function (datum) { return datum.index === 0 ? 'none' : '6 10'; })
710
+ .style('filter', 'drop-shadow(0 0 8px rgba(93, 184, 255, 0.9))');
711
+ var warpFlash = globeGroup.selectAll('circle.kchart-globe-warp-flash')
712
+ .data(warpEffect ? [warpEffect] : []);
713
+ warpFlash.exit().remove();
714
+ var warpFlashEnter = warpFlash.enter()
715
+ .append('circle')
716
+ .attr('class', 'kchart-globe-warp-flash')
717
+ .style('fill', 'rgba(248, 251, 255, 0.96)')
718
+ .style('pointer-events', 'none')
719
+ .style('filter', 'drop-shadow(0 0 18px rgba(93, 184, 255, 1))');
720
+ warpFlashEnter.append('animate')
721
+ .attr('attributeName', 'r')
722
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
723
+ .attr('values', "5;".concat(Math.max(width, height) * 0.42))
724
+ .attr('keyTimes', '0;1')
725
+ .attr('fill', 'freeze');
726
+ warpFlashEnter.append('animate')
727
+ .attr('attributeName', 'opacity')
728
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
729
+ .attr('values', '1;0.72;0')
730
+ .attr('keyTimes', '0;0.18;1')
731
+ .attr('fill', 'freeze');
732
+ warpFlashEnter.merge(warpFlash)
733
+ .attr('cx', function (datum) { return datum.x; })
734
+ .attr('cy', function (datum) { return datum.y; })
735
+ .attr('r', 5);
736
+ var warpLines = globeGroup.selectAll('line.kchart-globe-warp-line')
737
+ .data(warpEffect ? Array.from({ length: 18 }, function (_, index) { return index; }) : []);
738
+ warpLines.exit().remove();
739
+ var warpLinesEnter = warpLines.enter()
740
+ .append('line')
741
+ .attr('class', 'kchart-globe-warp-line')
742
+ .style('stroke', 'rgba(248, 251, 255, 0.5)')
743
+ .style('stroke-width', 1.4)
744
+ .style('stroke-dasharray', '18 12')
745
+ .style('pointer-events', 'none');
746
+ warpLinesEnter.append('animate')
747
+ .attr('attributeName', 'opacity')
748
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
749
+ .attr('values', '0;0.85;0')
750
+ .attr('keyTimes', '0;0.22;1')
751
+ .attr('fill', 'freeze');
752
+ warpLinesEnter.append('animate')
753
+ .attr('attributeName', 'stroke-dashoffset')
754
+ .attr('dur', "".concat(activeWarpDuration, "ms"))
755
+ .attr('from', '180')
756
+ .attr('to', '0')
757
+ .attr('fill', 'freeze');
758
+ warpLinesEnter.merge(warpLines)
759
+ .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; })
760
+ .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; })
761
+ .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); })
762
+ .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); })
763
+ .style('filter', 'drop-shadow(0 0 5px rgba(93, 184, 255, 0.82))');
764
+ var zoomControlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
765
+ var drilldownResetVisible = Boolean(focusedPoint)
766
+ && drilldownConfiguration.resetControl
767
+ && !externalMapTransitioning;
768
+ var controlsVisible = zoomControlsVisible || drilldownResetVisible;
769
+ var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
770
+ var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
771
+ var controlItems = __spreadArray(__spreadArray([], (zoomControlsVisible ? [
772
+ { key: 'in', label: '+', title: 'Zoom in' },
773
+ { key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom' },
774
+ { key: 'out', label: '-', title: 'Zoom out' }
775
+ ] : []), true), (drilldownResetVisible ? [
776
+ { key: 'globe', label: 'G', title: 'Back to globe' }
777
+ ] : []), true).map(function (item, index) { return (__assign(__assign({}, item), { y: index * 31 })); });
778
+ var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
779
+ .data(controlsVisible ? [undefined] : []);
780
+ zoomControls.exit().remove();
781
+ var zoomControlsEnter = zoomControls.enter()
782
+ .append('g')
783
+ .attr('class', 'kchart-globe-zoom-controls')
784
+ .style('pointer-events', 'all');
785
+ var zoomControlsMerged = zoomControlsEnter
786
+ .merge(zoomControls)
787
+ .attr('transform', "translate(".concat(controlsX, ",").concat(controlsY, ")"));
788
+ var controlButtons = zoomControlsMerged.selectAll('g.kchart-globe-zoom-control')
789
+ .data(controlItems, function (datum) { return datum.key; });
790
+ controlButtons.exit().remove();
791
+ var controlButtonsEnter = controlButtons.enter()
792
+ .append('g')
793
+ .attr('class', 'kchart-globe-zoom-control')
794
+ .style('cursor', 'pointer')
795
+ .on('pointerdown', function (event) {
796
+ event.preventDefault();
797
+ event.stopPropagation();
798
+ })
799
+ .on('click', function (event, datum) {
800
+ event.preventDefault();
801
+ event.stopPropagation();
802
+ if (datum.key === 'in') {
803
+ applyGlobeZoom(zoomLevel * (1 + zoomControlsConfiguration.step));
804
+ return;
805
+ }
806
+ if (datum.key === 'out') {
807
+ applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
808
+ return;
809
+ }
810
+ if (datum.key === 'globe') {
811
+ exitDrilldown();
812
+ return;
813
+ }
814
+ applyGlobeZoom(1);
815
+ });
816
+ controlButtonsEnter.append('rect')
817
+ .attr('class', 'kchart-globe-zoom-control-bg')
818
+ .attr('width', 34)
819
+ .attr('height', 27)
820
+ .attr('rx', 6);
821
+ controlButtonsEnter.append('text')
822
+ .attr('class', 'kchart-globe-zoom-control-label')
823
+ .attr('x', 17)
824
+ .attr('y', 18)
825
+ .attr('text-anchor', 'middle');
826
+ controlButtonsEnter.append('title');
827
+ var controlButtonsMerged = controlButtonsEnter.merge(controlButtons)
828
+ .attr('transform', function (datum) { return "translate(0,".concat(datum.y, ")"); })
829
+ .style('opacity', function (datum) {
830
+ if (datum.key === 'in' && zoomLevel >= maxZoom)
831
+ return 0.48;
832
+ if (datum.key === 'out' && zoomLevel <= minZoom)
833
+ return 0.48;
834
+ return 1;
835
+ });
836
+ controlButtonsMerged.select('rect.kchart-globe-zoom-control-bg')
837
+ .style('fill', 'rgba(15, 23, 42, 0.72)')
838
+ .style('stroke', 'rgba(226, 232, 240, 0.42)')
839
+ .style('stroke-width', 1);
840
+ controlButtonsMerged.select('text.kchart-globe-zoom-control-label')
841
+ .style('fill', 'rgba(248, 251, 255, 0.92)')
842
+ .style('font-size', function (datum) { return datum.key === 'reset' ? '10px' : '17px'; })
843
+ .style('font-weight', 800)
844
+ .text(function (datum) { return datum.label; });
845
+ controlButtonsMerged.select('title')
846
+ .text(function (datum) { return datum.title; });
847
+ };
848
+ draw();
849
+ var globeLayer = group.select('g.kchart-globe-layer');
850
+ globeLayer.on('.kchart-globe-drag', null);
851
+ globeLayer.on('.kchart-globe-zoom', null);
852
+ if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
853
+ globeLayer.on('wheel.kchart-globe-zoom', function (event) {
854
+ var _a;
855
+ event.preventDefault();
856
+ if (!wheelZoomReference) {
857
+ var currentPoint = (0, d3_selection_1.pointer)(event, globeLayer.node());
858
+ var reference = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, currentPoint);
859
+ if (reference && Number.isFinite(reference[0]) && Number.isFinite(reference[1])) {
860
+ wheelZoomReference = reference;
861
+ }
862
+ }
863
+ if (wheelZoomReferenceTimer !== undefined) {
864
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
865
+ }
866
+ wheelZoomReferenceTimer = globalThis.setTimeout(function () {
867
+ wheelZoomReference = undefined;
868
+ wheelZoomReferenceTimer = undefined;
869
+ }, 180);
870
+ var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
871
+ applyGlobeZoom(zoomLevel * zoomDelta, wheelZoomReference, hoveredMarkerTarget);
872
+ });
873
+ }
874
+ if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
875
+ globeLayer
876
+ .on('pointerdown.kchart-globe-drag', function (event) {
877
+ var _a, _b;
878
+ var eventTarget = event.target;
879
+ if (eventTarget === null || eventTarget === void 0 ? void 0 : eventTarget.closest('.kchart-globe-marker-hit-area, .kchart-globe-marker, .kchart-globe-marker-label')) {
880
+ return;
881
+ }
882
+ var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
883
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
884
+ activePointers.set(event.pointerId, currentPoint);
885
+ }
886
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
887
+ dragging = false;
888
+ pinchStartDistance = getFirstTwoPointerDistance();
889
+ pinchStartZoom = zoomLevel;
890
+ }
891
+ else if (configuration.draggable !== false && viewMode === 'globe') {
892
+ dragging = true;
893
+ dragStart = currentPoint;
894
+ rotationStart = __spreadArray([], rotation, true);
895
+ }
896
+ (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
897
+ event.preventDefault();
898
+ draw();
899
+ })
900
+ .on('pointermove.kchart-globe-drag', function (event) {
901
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.has(event.pointerId)) {
902
+ activePointers.set(event.pointerId, (0, d3_selection_1.pointer)(event, group.node()));
903
+ }
904
+ if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
905
+ var distance = getFirstTwoPointerDistance();
906
+ if (pinchStartDistance > 0 && distance > 0) {
907
+ applyGlobeZoom(pinchStartZoom * distance / pinchStartDistance);
908
+ }
909
+ event.preventDefault();
910
+ return;
911
+ }
912
+ if (!dragging) {
913
+ return;
914
+ }
915
+ var _a = (0, d3_selection_1.pointer)(event, group.node()), mouseX = _a[0], mouseY = _a[1];
916
+ var dx = mouseX - dragStart[0];
917
+ var dy = mouseY - dragStart[1];
918
+ rotation = [
919
+ rotationStart[0] + dx / Math.max(width, 1) * 360,
920
+ clampNumber(rotationStart[1] - dy / Math.max(height, 1) * 180, -89, 89),
921
+ rotationStart[2]
922
+ ];
923
+ event.preventDefault();
924
+ draw();
925
+ })
926
+ .on('pointerup.kchart-globe-drag pointercancel.kchart-globe-drag', function (event) {
927
+ var _a, _b;
928
+ activePointers.delete(event.pointerId);
929
+ if (activePointers.size < 2) {
930
+ pinchStartDistance = 0;
931
+ pinchStartZoom = zoomLevel;
932
+ }
933
+ dragging = false;
934
+ settledCenter = resolveGlobeCenter();
935
+ (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
936
+ draw();
937
+ });
938
+ }
939
+ },
940
+ destroy: function (_a) {
941
+ var plotGroup = _a.plotGroup;
942
+ if (warpTimer !== undefined) {
943
+ globalThis.clearTimeout(warpTimer);
944
+ warpTimer = undefined;
945
+ }
946
+ if (warpFrame !== undefined) {
947
+ globalThis.cancelAnimationFrame(warpFrame);
948
+ warpFrame = undefined;
949
+ }
950
+ wheelZoomReference = undefined;
951
+ hoveredMarkerTarget = undefined;
952
+ markerPress = undefined;
953
+ if (wheelZoomReferenceTimer !== undefined) {
954
+ globalThis.clearTimeout(wheelZoomReferenceTimer);
955
+ wheelZoomReferenceTimer = undefined;
956
+ }
957
+ externalMapTransitioning = false;
958
+ plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
959
+ plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
960
+ }
961
+ });
962
+ };
963
+ exports.createSvgGlobeSeries = createSvgGlobeSeries;
964
+ //# sourceMappingURL=svg-globe.js.map