@keneth80/k-chart 1.3.0 → 1.5.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/CHANGELOG.md +19 -0
- package/README.md +139 -0
- package/docs/code-graph-handoff.md +244 -0
- package/docs/functional-api.md +104 -1
- package/docs/release.md +74 -0
- package/examples/canvas-candlestick-series.ts +106 -0
- package/examples/svg-globe-map-series.ts +51 -0
- package/lib/kchart.d.ts +96 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +727 -16
- package/lib/kchart.js.map +1 -1
- package/package.json +7 -2
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.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,
|
|
@@ -48,6 +55,66 @@ var isZoomEnabled = function (state) {
|
|
|
48
55
|
return ((_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.enabled) === true
|
|
49
56
|
&& state.axes.some(function (axis) { return isZoomScaleSupported(axis); });
|
|
50
57
|
};
|
|
58
|
+
var isTouchLikeZoomEvent = function (event) {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
return ((_b = (_a = event === null || event === void 0 ? void 0 : event.type) === null || _a === void 0 ? void 0 : _a.startsWith) === null || _b === void 0 ? void 0 : _b.call(_a, 'touch')) === true
|
|
61
|
+
|| (event === null || event === void 0 ? void 0 : event.pointerType) === 'touch'
|
|
62
|
+
|| typeof ((_c = event === null || event === void 0 ? void 0 : event.touches) === null || _c === void 0 ? void 0 : _c.length) === 'number';
|
|
63
|
+
};
|
|
64
|
+
var isMobileLikeInput = function () { return typeof window !== 'undefined'
|
|
65
|
+
&& typeof window.matchMedia === 'function'
|
|
66
|
+
&& (window.matchMedia('(pointer: coarse)').matches || window.matchMedia('(hover: none)').matches); };
|
|
67
|
+
var matchesZoomInputDevice = function (devices, event) {
|
|
68
|
+
if (devices === 'all') {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
var touchLikeEvent = isTouchLikeZoomEvent(event);
|
|
72
|
+
var mobileLikeInput = isMobileLikeInput();
|
|
73
|
+
return devices === 'mobile'
|
|
74
|
+
? touchLikeEvent && mobileLikeInput
|
|
75
|
+
: !touchLikeEvent && !mobileLikeInput;
|
|
76
|
+
};
|
|
77
|
+
var isZoomOptionEnabled = function (option, fallback) {
|
|
78
|
+
if (typeof option === 'boolean') {
|
|
79
|
+
return option;
|
|
80
|
+
}
|
|
81
|
+
if ((option === null || option === void 0 ? void 0 : option.enabled) !== undefined) {
|
|
82
|
+
return option.enabled;
|
|
83
|
+
}
|
|
84
|
+
return fallback;
|
|
85
|
+
};
|
|
86
|
+
var getZoomWheelSensitivity = function (config) {
|
|
87
|
+
var option = config === null || config === void 0 ? void 0 : config.wheelZoom;
|
|
88
|
+
return typeof option === 'object' && typeof option.sensitivity === 'number' && option.sensitivity > 0
|
|
89
|
+
? option.sensitivity
|
|
90
|
+
: 1;
|
|
91
|
+
};
|
|
92
|
+
var getZoomWheelDevice = function (config) {
|
|
93
|
+
var option = config === null || config === void 0 ? void 0 : config.wheelZoom;
|
|
94
|
+
return typeof option === 'object' && option.devices ? option.devices : 'pc';
|
|
95
|
+
};
|
|
96
|
+
var getZoomGestureDevice = function (config) {
|
|
97
|
+
var option = config === null || config === void 0 ? void 0 : config.gestureZoom;
|
|
98
|
+
return typeof option === 'object' && option.devices ? option.devices : 'mobile';
|
|
99
|
+
};
|
|
100
|
+
var getZoomGestureMinTouches = function (config) {
|
|
101
|
+
var option = config === null || config === void 0 ? void 0 : config.gestureZoom;
|
|
102
|
+
return typeof option === 'object' && typeof option.minTouches === 'number'
|
|
103
|
+
? Math.max(1, option.minTouches)
|
|
104
|
+
: 1;
|
|
105
|
+
};
|
|
106
|
+
var hasZoomInputOptions = function (config) { return (config === null || config === void 0 ? void 0 : config.wheelZoom) !== undefined
|
|
107
|
+
|| (config === null || config === void 0 ? void 0 : config.gestureZoom) !== undefined; };
|
|
108
|
+
var getEventTouchCount = function (event) {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
if (typeof ((_a = event === null || event === void 0 ? void 0 : event.touches) === null || _a === void 0 ? void 0 : _a.length) === 'number') {
|
|
111
|
+
return event.touches.length;
|
|
112
|
+
}
|
|
113
|
+
if (typeof ((_c = (_b = event === null || event === void 0 ? void 0 : event.sourceEvent) === null || _b === void 0 ? void 0 : _b.touches) === null || _c === void 0 ? void 0 : _c.length) === 'number') {
|
|
114
|
+
return event.sourceEvent.touches.length;
|
|
115
|
+
}
|
|
116
|
+
return 0;
|
|
117
|
+
};
|
|
51
118
|
var hasTitleText = function (config) { var _a, _b; return Boolean((_b = (_a = config.title) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.trim()); };
|
|
52
119
|
var hasTopOptionLabels = function (config) {
|
|
53
120
|
var _a, _b, _c, _d, _e;
|
|
@@ -188,23 +255,49 @@ var ensureCanvas = function (container, name, size, margin, renderer) {
|
|
|
188
255
|
return canvas;
|
|
189
256
|
};
|
|
190
257
|
var resolveAxisDomain = function (axis, data) {
|
|
191
|
-
var _a, _b, _c, _d;
|
|
258
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
192
259
|
if (axis.domain) {
|
|
193
260
|
return axis.domain;
|
|
194
261
|
}
|
|
195
262
|
if (axis.type === 'string' || axis.type === 'point') {
|
|
196
263
|
return data.map(function (item) { return item[axis.field]; });
|
|
197
264
|
}
|
|
198
|
-
var
|
|
199
|
-
|
|
265
|
+
var domainFields = ((_a = axis.domainFields) === null || _a === void 0 ? void 0 : _a.length) ? axis.domainFields : [axis.field];
|
|
266
|
+
var values = data.flatMap(function (item) { return domainFields.map(function (field) {
|
|
267
|
+
var value = item[field];
|
|
200
268
|
return axis.type === 'time'
|
|
201
269
|
? new Date(value)
|
|
202
270
|
: Number(value);
|
|
203
|
-
});
|
|
204
|
-
|
|
271
|
+
}); }).filter(function (value) { return axis.type === 'time'
|
|
272
|
+
? value instanceof Date && Number.isFinite(value.getTime())
|
|
273
|
+
: Number.isFinite(value); });
|
|
274
|
+
var _h = (0, d3_array_1.extent)(values), minValue = _h[0], maxValue = _h[1];
|
|
275
|
+
var resolvedMin = (_c = (_b = axis.min) !== null && _b !== void 0 ? _b : minValue) !== null && _c !== void 0 ? _c : 0;
|
|
276
|
+
var resolvedMax = (_e = (_d = axis.max) !== null && _d !== void 0 ? _d : maxValue) !== null && _e !== void 0 ? _e : 1;
|
|
277
|
+
var canApplyPadding = axis.padding !== undefined && axis.min === undefined && axis.max === undefined;
|
|
278
|
+
if (canApplyPadding && axis.type === 'time') {
|
|
279
|
+
var minTime = resolvedMin instanceof Date ? resolvedMin.getTime() : new Date(resolvedMin).getTime();
|
|
280
|
+
var maxTime = resolvedMax instanceof Date ? resolvedMax.getTime() : new Date(resolvedMax).getTime();
|
|
281
|
+
var span = Math.max(maxTime - minTime, 24 * 60 * 60 * 1000);
|
|
282
|
+
var padding = span * Math.max((_f = axis.padding) !== null && _f !== void 0 ? _f : 0, 0);
|
|
283
|
+
return [
|
|
284
|
+
new Date(minTime - padding),
|
|
285
|
+
new Date(maxTime + padding)
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
if (canApplyPadding && axis.type === 'number') {
|
|
289
|
+
var minNumber = Number(resolvedMin);
|
|
290
|
+
var maxNumber = Number(resolvedMax);
|
|
291
|
+
var span = Math.max(maxNumber - minNumber, 1);
|
|
292
|
+
var padding = span * Math.max((_g = axis.padding) !== null && _g !== void 0 ? _g : 0, 0);
|
|
293
|
+
return [
|
|
294
|
+
minNumber - padding,
|
|
295
|
+
maxNumber + padding
|
|
296
|
+
];
|
|
297
|
+
}
|
|
205
298
|
return [
|
|
206
|
-
|
|
207
|
-
|
|
299
|
+
resolvedMin,
|
|
300
|
+
resolvedMax
|
|
208
301
|
];
|
|
209
302
|
};
|
|
210
303
|
var resolveScales = function (data, axes, plotSize) { return axes.map(function (axis) {
|
|
@@ -301,11 +394,165 @@ var resolveAxisTransform = function (placement, plotSize) {
|
|
|
301
394
|
return 'translate(0, 0)';
|
|
302
395
|
};
|
|
303
396
|
var resolveScalePosition = function (scale, value) {
|
|
304
|
-
var
|
|
397
|
+
var scaleValue = scale.type === 'time' && !(value instanceof Date)
|
|
398
|
+
? new Date(value)
|
|
399
|
+
: value;
|
|
400
|
+
var position = scale.scale(scaleValue);
|
|
305
401
|
return typeof scale.scale.bandwidth === 'function'
|
|
306
402
|
? position + scale.scale.bandwidth() / 2
|
|
307
403
|
: position;
|
|
308
404
|
};
|
|
405
|
+
var clampNumber = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
406
|
+
var resolveCanvasCandlestickWidth = function (data, xScale, xField, plotSize, configuration) {
|
|
407
|
+
var _a, _b;
|
|
408
|
+
if (typeof configuration.candleWidth === 'number') {
|
|
409
|
+
return configuration.candleWidth;
|
|
410
|
+
}
|
|
411
|
+
if (typeof configuration.candleWidth === 'function') {
|
|
412
|
+
return configuration.candleWidth({ data: data, xScale: xScale, plotSize: plotSize });
|
|
413
|
+
}
|
|
414
|
+
var minWidth = (_a = configuration.minCandleWidth) !== null && _a !== void 0 ? _a : 3;
|
|
415
|
+
var maxWidth = (_b = configuration.maxCandleWidth) !== null && _b !== void 0 ? _b : 18;
|
|
416
|
+
if (typeof xScale.scale.bandwidth === 'function') {
|
|
417
|
+
return clampNumber(xScale.scale.bandwidth() * 0.72, minWidth, maxWidth);
|
|
418
|
+
}
|
|
419
|
+
var positions = data
|
|
420
|
+
.map(function (point) { return resolveScalePosition(xScale, point[xField]); })
|
|
421
|
+
.filter(Number.isFinite)
|
|
422
|
+
.sort(function (a, b) { return a - b; });
|
|
423
|
+
var minDistance = Number.POSITIVE_INFINITY;
|
|
424
|
+
for (var index = 1; index < positions.length; index += 1) {
|
|
425
|
+
var distance = positions[index] - positions[index - 1];
|
|
426
|
+
if (distance > 0 && distance < minDistance) {
|
|
427
|
+
minDistance = distance;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (!Number.isFinite(minDistance)) {
|
|
431
|
+
return clampNumber(plotSize.width / Math.max(data.length, 1) * 0.72, minWidth, maxWidth);
|
|
432
|
+
}
|
|
433
|
+
return clampNumber(minDistance * 0.72, minWidth, maxWidth);
|
|
434
|
+
};
|
|
435
|
+
var resolveCandlestickColor = function (point, previousPoint, configuration, fallbackColor) {
|
|
436
|
+
var _a, _b, _c, _d;
|
|
437
|
+
var previousCloseFromField = configuration.previousCloseField
|
|
438
|
+
? Number(point[configuration.previousCloseField])
|
|
439
|
+
: undefined;
|
|
440
|
+
var previousCloseFromPoint = previousPoint
|
|
441
|
+
? Number(previousPoint[configuration.closeField])
|
|
442
|
+
: undefined;
|
|
443
|
+
var open = configuration.colorMode === 'previous-close'
|
|
444
|
+
? (Number.isFinite(previousCloseFromField) ? previousCloseFromField : previousCloseFromPoint)
|
|
445
|
+
: Number(point[configuration.openField]);
|
|
446
|
+
var close = Number(point[configuration.closeField]);
|
|
447
|
+
if (!Number.isFinite(open) || !Number.isFinite(close)) {
|
|
448
|
+
return (_a = configuration.neutralColor) !== null && _a !== void 0 ? _a : fallbackColor;
|
|
449
|
+
}
|
|
450
|
+
if (close > open) {
|
|
451
|
+
return (_b = configuration.upColor) !== null && _b !== void 0 ? _b : '#22c55e';
|
|
452
|
+
}
|
|
453
|
+
if (close < open) {
|
|
454
|
+
return (_c = configuration.downColor) !== null && _c !== void 0 ? _c : '#ef4444';
|
|
455
|
+
}
|
|
456
|
+
return (_d = configuration.neutralColor) !== null && _d !== void 0 ? _d : fallbackColor;
|
|
457
|
+
};
|
|
458
|
+
var formatCandlestickTooltipValue = function (value) {
|
|
459
|
+
var numberValue = Number(value);
|
|
460
|
+
return Number.isFinite(numberValue) ? numberValue.toLocaleString(undefined, { maximumFractionDigits: 4 }) : String(value);
|
|
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 WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
|
|
547
|
+
var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
|
|
548
|
+
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; });
|
|
549
|
+
var isGlobePointVisible = function (lon, lat, rotation) {
|
|
550
|
+
if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
var center = [-rotation[0], -rotation[1]];
|
|
554
|
+
return (0, d3_geo_1.geoDistance)([lon, lat], center) <= Math.PI / 2;
|
|
555
|
+
};
|
|
309
556
|
var downsampleLTTB = function (data, threshold, xAccessor, yAccessor) {
|
|
310
557
|
var dataLength = data.length;
|
|
311
558
|
var targetLength = Math.floor(threshold);
|
|
@@ -1218,9 +1465,16 @@ var renderZoom = function (state) {
|
|
|
1218
1465
|
return;
|
|
1219
1466
|
}
|
|
1220
1467
|
var mode = (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.mode) !== null && _b !== void 0 ? _b : 'wheel';
|
|
1468
|
+
var zoomConfig = state.config.zoom;
|
|
1469
|
+
var inputOptionsConfigured = hasZoomInputOptions(zoomConfig);
|
|
1221
1470
|
var selectionEnabled = isZoomEnabled(state) && (mode === 'select' || mode === 'both');
|
|
1222
|
-
var wheelEnabled = isZoomEnabled(state)
|
|
1471
|
+
var wheelEnabled = isZoomEnabled(state)
|
|
1472
|
+
&& (mode === 'wheel' || mode === 'both')
|
|
1473
|
+
&& isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.wheelZoom, true);
|
|
1223
1474
|
var panEnabled = isZoomEnabled(state) && mode === 'wheel';
|
|
1475
|
+
var desktopPanEnabled = panEnabled && isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.wheelZoom, true);
|
|
1476
|
+
var gestureEnabled = isZoomEnabled(state)
|
|
1477
|
+
&& isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.gestureZoom, !inputOptionsConfigured && panEnabled);
|
|
1224
1478
|
overlay
|
|
1225
1479
|
.style('cursor', selectionEnabled ? 'crosshair' : isZoomEnabled(state) ? 'grab' : null)
|
|
1226
1480
|
.on('dblclick.kchart-zoom-reset', null)
|
|
@@ -1233,16 +1487,35 @@ var renderZoom = function (state) {
|
|
|
1233
1487
|
state.layers.overlayGroup.selectAll('rect.kchart-zoom-selection').remove();
|
|
1234
1488
|
return;
|
|
1235
1489
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1490
|
+
if (wheelEnabled || desktopPanEnabled || gestureEnabled) {
|
|
1491
|
+
var wheelSensitivity_1 = getZoomWheelSensitivity(zoomConfig);
|
|
1238
1492
|
var zoomBehavior = (0, d3_zoom_1.zoom)()
|
|
1239
1493
|
.scaleExtent((_c = zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.scaleExtent) !== null && _c !== void 0 ? _c : [1, 40])
|
|
1240
1494
|
.extent([[0, 0], [state.plotSize.width, state.plotSize.height]])
|
|
1241
1495
|
.translateExtent([[0, 0], [state.plotSize.width, state.plotSize.height]])
|
|
1242
|
-
.
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1496
|
+
.touchable(function () { return gestureEnabled; })
|
|
1497
|
+
.wheelDelta(function (event) { return -event.deltaY
|
|
1498
|
+
* (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002)
|
|
1499
|
+
* (event.ctrlKey ? 10 : 1)
|
|
1500
|
+
* wheelSensitivity_1; })
|
|
1501
|
+
.filter(function (event) {
|
|
1502
|
+
if (event.type === 'wheel') {
|
|
1503
|
+
return wheelEnabled && (!inputOptionsConfigured
|
|
1504
|
+
|| matchesZoomInputDevice(getZoomWheelDevice(zoomConfig), event));
|
|
1505
|
+
}
|
|
1506
|
+
if (event.type === 'mousedown') {
|
|
1507
|
+
return desktopPanEnabled && (!inputOptionsConfigured
|
|
1508
|
+
|| matchesZoomInputDevice(getZoomWheelDevice(zoomConfig), event));
|
|
1509
|
+
}
|
|
1510
|
+
if (event.type === 'touchstart' || event.type === 'touchmove') {
|
|
1511
|
+
var touchCount = getEventTouchCount(event);
|
|
1512
|
+
return gestureEnabled
|
|
1513
|
+
&& touchCount >= getZoomGestureMinTouches(zoomConfig)
|
|
1514
|
+
&& (!inputOptionsConfigured
|
|
1515
|
+
|| matchesZoomInputDevice(getZoomGestureDevice(zoomConfig), event));
|
|
1516
|
+
}
|
|
1517
|
+
return false;
|
|
1518
|
+
})
|
|
1246
1519
|
.on('zoom', function (event) {
|
|
1247
1520
|
var _a;
|
|
1248
1521
|
state.zoomTransform = event.transform;
|
|
@@ -1762,6 +2035,444 @@ var createCanvasPointSeries = function (configuration) { return (0, exports.crea
|
|
|
1762
2035
|
}
|
|
1763
2036
|
}); };
|
|
1764
2037
|
exports.createCanvasPointSeries = createCanvasPointSeries;
|
|
2038
|
+
var createCanvasCandlestickSeries = function (configuration) { return (0, exports.createCustomSeries)({
|
|
2039
|
+
selector: configuration.selector,
|
|
2040
|
+
displayName: configuration.displayName,
|
|
2041
|
+
xField: configuration.xField,
|
|
2042
|
+
yField: configuration.closeField,
|
|
2043
|
+
color: configuration.neutralColor,
|
|
2044
|
+
render: function (_a) {
|
|
2045
|
+
var _b, _c;
|
|
2046
|
+
var getCanvas = _a.getCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color, plotSize = _a.plotSize;
|
|
2047
|
+
if (!xScale || !yScale) {
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
var canvas = getCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
|
|
2051
|
+
var context = canvas.getContext('2d');
|
|
2052
|
+
if (!context) {
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
var candleWidth = resolveCanvasCandlestickWidth(data, xScale, configuration.xField, plotSize, configuration);
|
|
2056
|
+
var halfWidth = candleWidth / 2;
|
|
2057
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
2058
|
+
context.lineCap = 'round';
|
|
2059
|
+
context.lineJoin = 'round';
|
|
2060
|
+
context.lineWidth = (_c = configuration.strokeWidth) !== null && _c !== void 0 ? _c : 1.4;
|
|
2061
|
+
data.forEach(function (point, index) {
|
|
2062
|
+
var _a, _b;
|
|
2063
|
+
var open = Number(point[configuration.openField]);
|
|
2064
|
+
var high = Number(point[configuration.highField]);
|
|
2065
|
+
var low = Number(point[configuration.lowField]);
|
|
2066
|
+
var close = Number(point[configuration.closeField]);
|
|
2067
|
+
if (![open, high, low, close].every(Number.isFinite) || point[configuration.xField] === undefined) {
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
var x = resolveScalePosition(xScale, point[configuration.xField]);
|
|
2071
|
+
var openY = resolveScalePosition(yScale, open);
|
|
2072
|
+
var highY = resolveScalePosition(yScale, high);
|
|
2073
|
+
var lowY = resolveScalePosition(yScale, low);
|
|
2074
|
+
var closeY = resolveScalePosition(yScale, close);
|
|
2075
|
+
if (![x, openY, highY, lowY, closeY].every(Number.isFinite)) {
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
var candleColor = resolveCandlestickColor(point, data[index - 1], configuration, color);
|
|
2079
|
+
var bodyTop = Math.min(openY, closeY);
|
|
2080
|
+
var bodyHeight = Math.max(Math.abs(closeY - openY), 1);
|
|
2081
|
+
context.strokeStyle = (_a = configuration.wickColor) !== null && _a !== void 0 ? _a : candleColor;
|
|
2082
|
+
context.beginPath();
|
|
2083
|
+
context.moveTo(x, highY);
|
|
2084
|
+
context.lineTo(x, lowY);
|
|
2085
|
+
context.stroke();
|
|
2086
|
+
context.fillStyle = candleColor;
|
|
2087
|
+
context.strokeStyle = (_b = configuration.borderColor) !== null && _b !== void 0 ? _b : candleColor;
|
|
2088
|
+
context.beginPath();
|
|
2089
|
+
context.rect(x - halfWidth, bodyTop, candleWidth, bodyHeight);
|
|
2090
|
+
context.fill();
|
|
2091
|
+
context.stroke();
|
|
2092
|
+
});
|
|
2093
|
+
},
|
|
2094
|
+
tooltip: function (_a) {
|
|
2095
|
+
var _b, _c, _d;
|
|
2096
|
+
var data = _a.data, scales = _a.scales, mouseX = _a.mouseX, mouseY = _a.mouseY, color = _a.color, plotSize = _a.plotSize;
|
|
2097
|
+
var xScale = scales.find(function (scale) { return scale.field === configuration.xField; });
|
|
2098
|
+
var yScale = (_b = scales.find(function (scale) { return scale.field === configuration.closeField; })) !== null && _b !== void 0 ? _b : scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; });
|
|
2099
|
+
if (!xScale || !yScale) {
|
|
2100
|
+
return null;
|
|
2101
|
+
}
|
|
2102
|
+
var candleWidth = resolveCanvasCandlestickWidth(data, xScale, configuration.xField, plotSize, configuration);
|
|
2103
|
+
var hitRadius = Math.max(candleWidth * 0.7, 14);
|
|
2104
|
+
var nearest = null;
|
|
2105
|
+
data.forEach(function (point, index) {
|
|
2106
|
+
if (point[configuration.xField] === undefined || point[configuration.closeField] === undefined) {
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
var x = resolveScalePosition(xScale, point[configuration.xField]);
|
|
2110
|
+
var y = resolveScalePosition(yScale, point[configuration.closeField]);
|
|
2111
|
+
var distance = Math.abs(mouseX - x);
|
|
2112
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || distance > hitRadius) {
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
var verticalDistance = Math.abs(mouseY - y);
|
|
2116
|
+
var totalDistance = distance + verticalDistance * 0.08;
|
|
2117
|
+
if (!nearest || totalDistance < nearest.distance) {
|
|
2118
|
+
nearest = {
|
|
2119
|
+
data: point,
|
|
2120
|
+
previousData: data[index - 1],
|
|
2121
|
+
x: x,
|
|
2122
|
+
y: y,
|
|
2123
|
+
distance: totalDistance
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
if (!nearest) {
|
|
2128
|
+
return null;
|
|
2129
|
+
}
|
|
2130
|
+
var point = nearest.data;
|
|
2131
|
+
var candleColor = resolveCandlestickColor(point, nearest.previousData, configuration, color);
|
|
2132
|
+
var label = (_c = configuration.displayName) !== null && _c !== void 0 ? _c : configuration.selector;
|
|
2133
|
+
var xValue = String(point[configuration.xField]);
|
|
2134
|
+
var previousClose = configuration.previousCloseField
|
|
2135
|
+
? point[configuration.previousCloseField]
|
|
2136
|
+
: (_d = nearest.previousData) === null || _d === void 0 ? void 0 : _d[configuration.closeField];
|
|
2137
|
+
return {
|
|
2138
|
+
data: point,
|
|
2139
|
+
x: nearest.x,
|
|
2140
|
+
y: nearest.y,
|
|
2141
|
+
color: candleColor,
|
|
2142
|
+
distance: nearest.distance,
|
|
2143
|
+
html: [
|
|
2144
|
+
"<strong style=\"color:".concat(candleColor, "\">").concat(label, "</strong>"),
|
|
2145
|
+
"x: ".concat(xValue),
|
|
2146
|
+
configuration.colorMode === 'previous-close'
|
|
2147
|
+
? "previous close: ".concat(formatCandlestickTooltipValue(previousClose))
|
|
2148
|
+
: '',
|
|
2149
|
+
"open: ".concat(formatCandlestickTooltipValue(point[configuration.openField])),
|
|
2150
|
+
"high: ".concat(formatCandlestickTooltipValue(point[configuration.highField])),
|
|
2151
|
+
"low: ".concat(formatCandlestickTooltipValue(point[configuration.lowField])),
|
|
2152
|
+
"close: ".concat(formatCandlestickTooltipValue(point[configuration.closeField]))
|
|
2153
|
+
].filter(Boolean).join('<br/>')
|
|
2154
|
+
};
|
|
2155
|
+
},
|
|
2156
|
+
destroy: function (_a) {
|
|
2157
|
+
var _b;
|
|
2158
|
+
var svg = _a.svg;
|
|
2159
|
+
destroyCanvasByClass(svg, "kchart-2d-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
|
|
2160
|
+
}
|
|
2161
|
+
}); };
|
|
2162
|
+
exports.createCanvasCandlestickSeries = createCanvasCandlestickSeries;
|
|
2163
|
+
var createSvgGlobeSeries = function (configuration) {
|
|
2164
|
+
var rotation = normalizeGlobeRotation(configuration.initialRotate);
|
|
2165
|
+
var zoomLevel = 1;
|
|
2166
|
+
var dragging = false;
|
|
2167
|
+
var dragStart = [0, 0];
|
|
2168
|
+
var rotationStart = __spreadArray([], rotation, true);
|
|
2169
|
+
var activePointers = new Map();
|
|
2170
|
+
var pinchStartDistance = 0;
|
|
2171
|
+
var pinchStartZoom = 1;
|
|
2172
|
+
return (0, exports.createCustomSeries)({
|
|
2173
|
+
selector: configuration.selector,
|
|
2174
|
+
displayName: configuration.displayName,
|
|
2175
|
+
xField: configuration.lonField,
|
|
2176
|
+
yField: configuration.latField,
|
|
2177
|
+
color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
|
|
2178
|
+
render: function (_a) {
|
|
2179
|
+
var _b;
|
|
2180
|
+
var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
|
|
2181
|
+
var width = plotSize.width;
|
|
2182
|
+
var height = plotSize.height;
|
|
2183
|
+
var centerX = width / 2;
|
|
2184
|
+
var centerY = height / 2;
|
|
2185
|
+
var zoomConfiguration = resolveGlobeZoomConfiguration(configuration.zoom);
|
|
2186
|
+
var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
|
|
2187
|
+
var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
|
|
2188
|
+
var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
|
|
2189
|
+
zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
|
|
2190
|
+
var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
|
|
2191
|
+
var projection = (0, d3_geo_1.geoOrthographic)()
|
|
2192
|
+
.translate([centerX, centerY])
|
|
2193
|
+
.scale(baseScale * zoomLevel)
|
|
2194
|
+
.rotate(rotation)
|
|
2195
|
+
.clipAngle(90);
|
|
2196
|
+
var path = (0, d3_geo_1.geoPath)(projection);
|
|
2197
|
+
var getFirstTwoPointerDistance = function () {
|
|
2198
|
+
var points = Array.from(activePointers.values());
|
|
2199
|
+
if (points.length < 2) {
|
|
2200
|
+
return 0;
|
|
2201
|
+
}
|
|
2202
|
+
var dx = points[0][0] - points[1][0];
|
|
2203
|
+
var dy = points[0][1] - points[1][1];
|
|
2204
|
+
return Math.hypot(dx, dy);
|
|
2205
|
+
};
|
|
2206
|
+
var applyGlobeZoom = function (nextZoom) {
|
|
2207
|
+
zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
|
|
2208
|
+
draw();
|
|
2209
|
+
};
|
|
2210
|
+
var draw = function () {
|
|
2211
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2212
|
+
projection.rotate(rotation);
|
|
2213
|
+
projection.scale(baseScale * zoomLevel);
|
|
2214
|
+
var globeGroup = group.selectAll('g.kchart-globe-layer')
|
|
2215
|
+
.data([undefined])
|
|
2216
|
+
.join('g')
|
|
2217
|
+
.attr('class', 'kchart-globe-layer')
|
|
2218
|
+
.style('cursor', configuration.draggable === false ? 'default' : dragging ? 'grabbing' : 'grab')
|
|
2219
|
+
.style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
|
|
2220
|
+
globeGroup.selectAll('path.kchart-globe-sphere')
|
|
2221
|
+
.data([{ type: 'Sphere' }])
|
|
2222
|
+
.join('path')
|
|
2223
|
+
.attr('class', 'kchart-globe-sphere')
|
|
2224
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2225
|
+
.style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : 'rgba(15, 23, 42, 0.92)')
|
|
2226
|
+
.style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(148, 163, 184, 0.62)')
|
|
2227
|
+
.style('stroke-width', 1.2)
|
|
2228
|
+
.style('pointer-events', 'all');
|
|
2229
|
+
var defaultLandGeoJson = configuration.landMode === 'countries'
|
|
2230
|
+
? WORLD_COUNTRY_GEOJSON
|
|
2231
|
+
: WORLD_LAND_GEOJSON;
|
|
2232
|
+
var landData = configuration.landVisible === false
|
|
2233
|
+
? []
|
|
2234
|
+
: normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
|
|
2235
|
+
globeGroup.selectAll('path.kchart-globe-land')
|
|
2236
|
+
.data(landData)
|
|
2237
|
+
.join('path')
|
|
2238
|
+
.attr('class', 'kchart-globe-land')
|
|
2239
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2240
|
+
.style('fill', function (datum, index) { return resolveGlobeLandStyle(configuration.landFill, datum, index, '#2dd4bf'); })
|
|
2241
|
+
.style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(configuration.landOpacity, datum, index); })
|
|
2242
|
+
.style('stroke', function (datum, index) { return resolveGlobeLandStyle(configuration.landStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
|
|
2243
|
+
.style('stroke-width', 1)
|
|
2244
|
+
.style('pointer-events', 'none');
|
|
2245
|
+
globeGroup.selectAll('path.kchart-globe-country-borders')
|
|
2246
|
+
.data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
|
|
2247
|
+
.join('path')
|
|
2248
|
+
.attr('class', 'kchart-globe-country-borders')
|
|
2249
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2250
|
+
.style('fill', 'none')
|
|
2251
|
+
.style('stroke', (_d = configuration.countryBordersStroke) !== null && _d !== void 0 ? _d : 'rgba(236, 253, 245, 0.26)')
|
|
2252
|
+
.style('stroke-width', (_e = configuration.countryBordersStrokeWidth) !== null && _e !== void 0 ? _e : 0.55)
|
|
2253
|
+
.style('pointer-events', 'none');
|
|
2254
|
+
globeGroup.selectAll('path.kchart-globe-graticule')
|
|
2255
|
+
.data(configuration.graticuleVisible === false ? [] : [(0, d3_geo_1.geoGraticule10)()])
|
|
2256
|
+
.join('path')
|
|
2257
|
+
.attr('class', 'kchart-globe-graticule')
|
|
2258
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2259
|
+
.style('fill', 'none')
|
|
2260
|
+
.style('stroke', (_f = configuration.graticuleStroke) !== null && _f !== void 0 ? _f : 'rgba(148, 163, 184, 0.22)')
|
|
2261
|
+
.style('stroke-width', 0.8)
|
|
2262
|
+
.style('pointer-events', 'none');
|
|
2263
|
+
var markerData = data.map(function (point) {
|
|
2264
|
+
var lat = resolveGlobePointValue(point, configuration.latField);
|
|
2265
|
+
var lon = resolveGlobePointValue(point, configuration.lonField);
|
|
2266
|
+
var projected = projection([lon, lat]);
|
|
2267
|
+
return {
|
|
2268
|
+
data: point,
|
|
2269
|
+
lat: lat,
|
|
2270
|
+
lon: lon,
|
|
2271
|
+
projected: projected,
|
|
2272
|
+
visible: Boolean(projected) && isGlobePointVisible(lon, lat, rotation)
|
|
2273
|
+
};
|
|
2274
|
+
}).filter(function (point) { return point.visible && point.projected; });
|
|
2275
|
+
var markers = globeGroup.selectAll('circle.kchart-globe-marker')
|
|
2276
|
+
.data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
|
|
2277
|
+
markers.exit().remove();
|
|
2278
|
+
markers.enter()
|
|
2279
|
+
.append('circle')
|
|
2280
|
+
.attr('class', 'kchart-globe-marker')
|
|
2281
|
+
.style('cursor', configuration.onMarkerClick ? 'pointer' : 'default')
|
|
2282
|
+
.style('pointer-events', 'all')
|
|
2283
|
+
.merge(markers)
|
|
2284
|
+
.attr('cx', function (datum) { return datum.projected[0]; })
|
|
2285
|
+
.attr('cy', function (datum) { return datum.projected[1]; })
|
|
2286
|
+
.attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
|
|
2287
|
+
.style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
|
|
2288
|
+
.style('stroke', (_g = configuration.markerStroke) !== null && _g !== void 0 ? _g : 'rgba(248, 251, 255, 0.92)')
|
|
2289
|
+
.style('stroke-width', (_h = configuration.markerStrokeWidth) !== null && _h !== void 0 ? _h : 1.4)
|
|
2290
|
+
.style('opacity', (_j = configuration.markerOpacity) !== null && _j !== void 0 ? _j : 0.95)
|
|
2291
|
+
.on('click', function (event, datum) {
|
|
2292
|
+
if (!configuration.onMarkerClick) {
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
event.preventDefault();
|
|
2296
|
+
event.stopPropagation();
|
|
2297
|
+
configuration.onMarkerClick({
|
|
2298
|
+
data: datum.data,
|
|
2299
|
+
event: event,
|
|
2300
|
+
lat: datum.lat,
|
|
2301
|
+
lon: datum.lon,
|
|
2302
|
+
x: datum.projected[0],
|
|
2303
|
+
y: datum.projected[1]
|
|
2304
|
+
});
|
|
2305
|
+
});
|
|
2306
|
+
var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
|
|
2307
|
+
.data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
|
|
2308
|
+
labels.exit().remove();
|
|
2309
|
+
labels.enter()
|
|
2310
|
+
.append('text')
|
|
2311
|
+
.attr('class', 'kchart-globe-marker-label')
|
|
2312
|
+
.style('pointer-events', 'none')
|
|
2313
|
+
.merge(labels)
|
|
2314
|
+
.attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
|
|
2315
|
+
.attr('y', function (datum) { return datum.projected[1] + 4; })
|
|
2316
|
+
.style('fill', 'rgba(248, 251, 255, 0.82)')
|
|
2317
|
+
.style('font-size', '11px')
|
|
2318
|
+
.style('font-weight', 700)
|
|
2319
|
+
.text(function (datum) { return String(datum.data[configuration.labelField]); });
|
|
2320
|
+
var controlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
|
|
2321
|
+
var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
|
|
2322
|
+
var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
|
|
2323
|
+
var controlItems = [
|
|
2324
|
+
{ key: 'in', label: '+', title: 'Zoom in', y: 0 },
|
|
2325
|
+
{ key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom', y: 31 },
|
|
2326
|
+
{ key: 'out', label: '-', title: 'Zoom out', y: 62 }
|
|
2327
|
+
];
|
|
2328
|
+
var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
|
|
2329
|
+
.data(controlsVisible ? [undefined] : []);
|
|
2330
|
+
zoomControls.exit().remove();
|
|
2331
|
+
var zoomControlsEnter = zoomControls.enter()
|
|
2332
|
+
.append('g')
|
|
2333
|
+
.attr('class', 'kchart-globe-zoom-controls')
|
|
2334
|
+
.style('pointer-events', 'all');
|
|
2335
|
+
var zoomControlsMerged = zoomControlsEnter
|
|
2336
|
+
.merge(zoomControls)
|
|
2337
|
+
.attr('transform', "translate(".concat(controlsX, ",").concat(controlsY, ")"));
|
|
2338
|
+
var controlButtons = zoomControlsMerged.selectAll('g.kchart-globe-zoom-control')
|
|
2339
|
+
.data(controlItems, function (datum) { return datum.key; });
|
|
2340
|
+
controlButtons.exit().remove();
|
|
2341
|
+
var controlButtonsEnter = controlButtons.enter()
|
|
2342
|
+
.append('g')
|
|
2343
|
+
.attr('class', 'kchart-globe-zoom-control')
|
|
2344
|
+
.style('cursor', 'pointer')
|
|
2345
|
+
.on('pointerdown', function (event) {
|
|
2346
|
+
event.preventDefault();
|
|
2347
|
+
event.stopPropagation();
|
|
2348
|
+
})
|
|
2349
|
+
.on('click', function (event, datum) {
|
|
2350
|
+
event.preventDefault();
|
|
2351
|
+
event.stopPropagation();
|
|
2352
|
+
if (datum.key === 'in') {
|
|
2353
|
+
applyGlobeZoom(zoomLevel * (1 + zoomControlsConfiguration.step));
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
if (datum.key === 'out') {
|
|
2357
|
+
applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
applyGlobeZoom(1);
|
|
2361
|
+
});
|
|
2362
|
+
controlButtonsEnter.append('rect')
|
|
2363
|
+
.attr('class', 'kchart-globe-zoom-control-bg')
|
|
2364
|
+
.attr('width', 34)
|
|
2365
|
+
.attr('height', 27)
|
|
2366
|
+
.attr('rx', 6);
|
|
2367
|
+
controlButtonsEnter.append('text')
|
|
2368
|
+
.attr('class', 'kchart-globe-zoom-control-label')
|
|
2369
|
+
.attr('x', 17)
|
|
2370
|
+
.attr('y', 18)
|
|
2371
|
+
.attr('text-anchor', 'middle');
|
|
2372
|
+
controlButtonsEnter.append('title');
|
|
2373
|
+
var controlButtonsMerged = controlButtonsEnter.merge(controlButtons)
|
|
2374
|
+
.attr('transform', function (datum) { return "translate(0,".concat(datum.y, ")"); })
|
|
2375
|
+
.style('opacity', function (datum) {
|
|
2376
|
+
if (datum.key === 'in' && zoomLevel >= maxZoom)
|
|
2377
|
+
return 0.48;
|
|
2378
|
+
if (datum.key === 'out' && zoomLevel <= minZoom)
|
|
2379
|
+
return 0.48;
|
|
2380
|
+
return 1;
|
|
2381
|
+
});
|
|
2382
|
+
controlButtonsMerged.select('rect.kchart-globe-zoom-control-bg')
|
|
2383
|
+
.style('fill', 'rgba(15, 23, 42, 0.72)')
|
|
2384
|
+
.style('stroke', 'rgba(226, 232, 240, 0.42)')
|
|
2385
|
+
.style('stroke-width', 1);
|
|
2386
|
+
controlButtonsMerged.select('text.kchart-globe-zoom-control-label')
|
|
2387
|
+
.style('fill', 'rgba(248, 251, 255, 0.92)')
|
|
2388
|
+
.style('font-size', function (datum) { return datum.key === 'reset' ? '10px' : '17px'; })
|
|
2389
|
+
.style('font-weight', 800)
|
|
2390
|
+
.text(function (datum) { return datum.label; });
|
|
2391
|
+
controlButtonsMerged.select('title')
|
|
2392
|
+
.text(function (datum) { return datum.title; });
|
|
2393
|
+
};
|
|
2394
|
+
draw();
|
|
2395
|
+
var globeLayer = group.select('g.kchart-globe-layer');
|
|
2396
|
+
globeLayer.on('.kchart-globe-drag', null);
|
|
2397
|
+
globeLayer.on('.kchart-globe-zoom', null);
|
|
2398
|
+
if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
|
|
2399
|
+
globeLayer.on('wheel.kchart-globe-zoom', function (event) {
|
|
2400
|
+
event.preventDefault();
|
|
2401
|
+
var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
|
|
2402
|
+
zoomLevel = clampNumber(zoomLevel * zoomDelta, minZoom, maxZoom);
|
|
2403
|
+
draw();
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
|
|
2407
|
+
globeLayer
|
|
2408
|
+
.on('pointerdown.kchart-globe-drag', function (event) {
|
|
2409
|
+
var _a, _b;
|
|
2410
|
+
var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
|
|
2411
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
|
|
2412
|
+
activePointers.set(event.pointerId, currentPoint);
|
|
2413
|
+
}
|
|
2414
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
|
|
2415
|
+
dragging = false;
|
|
2416
|
+
pinchStartDistance = getFirstTwoPointerDistance();
|
|
2417
|
+
pinchStartZoom = zoomLevel;
|
|
2418
|
+
}
|
|
2419
|
+
else if (configuration.draggable !== false) {
|
|
2420
|
+
dragging = true;
|
|
2421
|
+
dragStart = currentPoint;
|
|
2422
|
+
rotationStart = __spreadArray([], rotation, true);
|
|
2423
|
+
}
|
|
2424
|
+
(_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
|
|
2425
|
+
event.preventDefault();
|
|
2426
|
+
draw();
|
|
2427
|
+
})
|
|
2428
|
+
.on('pointermove.kchart-globe-drag', function (event) {
|
|
2429
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.has(event.pointerId)) {
|
|
2430
|
+
activePointers.set(event.pointerId, (0, d3_selection_1.pointer)(event, group.node()));
|
|
2431
|
+
}
|
|
2432
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
|
|
2433
|
+
var distance = getFirstTwoPointerDistance();
|
|
2434
|
+
if (pinchStartDistance > 0 && distance > 0) {
|
|
2435
|
+
zoomLevel = clampNumber(pinchStartZoom * distance / pinchStartDistance, minZoom, maxZoom);
|
|
2436
|
+
draw();
|
|
2437
|
+
}
|
|
2438
|
+
event.preventDefault();
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
if (!dragging) {
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
var _a = (0, d3_selection_1.pointer)(event, group.node()), mouseX = _a[0], mouseY = _a[1];
|
|
2445
|
+
var dx = mouseX - dragStart[0];
|
|
2446
|
+
var dy = mouseY - dragStart[1];
|
|
2447
|
+
rotation = [
|
|
2448
|
+
rotationStart[0] + dx / Math.max(width, 1) * 360,
|
|
2449
|
+
clampNumber(rotationStart[1] - dy / Math.max(height, 1) * 180, -89, 89),
|
|
2450
|
+
rotationStart[2]
|
|
2451
|
+
];
|
|
2452
|
+
event.preventDefault();
|
|
2453
|
+
draw();
|
|
2454
|
+
})
|
|
2455
|
+
.on('pointerup.kchart-globe-drag pointercancel.kchart-globe-drag', function (event) {
|
|
2456
|
+
var _a, _b;
|
|
2457
|
+
activePointers.delete(event.pointerId);
|
|
2458
|
+
if (activePointers.size < 2) {
|
|
2459
|
+
pinchStartDistance = 0;
|
|
2460
|
+
pinchStartZoom = zoomLevel;
|
|
2461
|
+
}
|
|
2462
|
+
dragging = false;
|
|
2463
|
+
(_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
|
|
2464
|
+
draw();
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
},
|
|
2468
|
+
destroy: function (_a) {
|
|
2469
|
+
var plotGroup = _a.plotGroup;
|
|
2470
|
+
plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
|
|
2471
|
+
plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
};
|
|
2475
|
+
exports.createSvgGlobeSeries = createSvgGlobeSeries;
|
|
1765
2476
|
var createWebglPointSeries = function (configuration) { return (0, exports.createCustomSeries)({
|
|
1766
2477
|
selector: configuration.selector,
|
|
1767
2478
|
displayName: configuration.displayName,
|