@keneth80/k-chart 1.6.0 → 1.7.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +21 -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
package/lib/kchart.js CHANGED
@@ -1,3193 +1,28 @@
1
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 };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
15
  };
25
16
  Object.defineProperty(exports, "__esModule", { value: true });
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;
27
- var d3_array_1 = require("d3-array");
28
- var d3_axis_1 = require("d3-axis");
29
- var d3_geo_1 = require("d3-geo");
30
- var d3_scale_1 = require("d3-scale");
31
- var d3_scale_chromatic_1 = require("d3-scale-chromatic");
32
- var d3_selection_1 = require("d3-selection");
33
- var d3_shape_1 = require("d3-shape");
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"));
38
- var defaultMargin = {
39
- top: 24,
40
- right: 24,
41
- bottom: 36,
42
- left: 44
43
- };
44
- var transferredCanvases = new WeakSet();
45
- var asyncCanvasEntries = new WeakMap();
46
- var asyncCanvasId = 0;
47
- var cloneAxisDomain = function (domain) { return domain
48
- ? domain.map(function (value) { return value instanceof Date ? new Date(value) : value; })
49
- : undefined; };
50
- var cloneAxes = function (axes) { return axes.map(function (axis) { return (__assign(__assign({}, axis), { min: axis.min instanceof Date ? new Date(axis.min) : axis.min, max: axis.max instanceof Date ? new Date(axis.max) : axis.max, domain: cloneAxisDomain(axis.domain) })); }); };
51
- var isZoomScaleSupported = function (axis) { return axis.type === 'number' || axis.type === 'time'; };
52
- var isHorizontalAxis = function (axis) { return axis.placement === 'bottom' || axis.placement === 'top'; };
53
- var isZoomEnabled = function (state) {
54
- var _a;
55
- return ((_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.enabled) === true
56
- && state.axes.some(function (axis) { return isZoomScaleSupported(axis); });
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
- };
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()); };
119
- var hasTopOptionLabels = function (config) {
120
- var _a, _b, _c, _d, _e;
121
- var hasSpecAreaLabels = Boolean((_a = config.specAreas) === null || _a === void 0 ? void 0 : _a.some(function (area) { return area.visible !== false && area.label; }))
122
- || Boolean((_b = config.options) === null || _b === void 0 ? void 0 : _b.some(function (option) { return option.type === 'spec-area'
123
- && option.visible !== false
124
- && option.areas.some(function (area) { return area.visible !== false && area.label; }); }));
125
- var hasGuideLineLabels = Boolean((_d = (_c = config.guideLines) === null || _c === void 0 ? void 0 : _c.x) === null || _d === void 0 ? void 0 : _d.some(function (line) { return line.visible !== false && line.label; }))
126
- || Boolean((_e = config.options) === null || _e === void 0 ? void 0 : _e.some(function (option) {
127
- var _a;
128
- return option.type === 'guide-line'
129
- && option.visible !== false
130
- && ((_a = option.x) === null || _a === void 0 ? void 0 : _a.some(function (line) { return line.visible !== false && line.label; }));
131
- }));
132
- return hasSpecAreaLabels || hasGuideLineLabels;
133
- };
134
- var resolveEffectiveMargin = function (config, size, baseMargin) {
135
- var legend = config.legend;
136
- var hasTopLegend = (legend === null || legend === void 0 ? void 0 : legend.visible) !== false && (legend === null || legend === void 0 ? void 0 : legend.placement) !== 'right' && (legend === null || legend === void 0 ? void 0 : legend.placement) !== 'bottom' && config.series.length > 0;
137
- var titleVisible = hasTitleText(config);
138
- var topOptionLabelsVisible = hasTopOptionLabels(config);
139
- if (!hasTopLegend && titleVisible) {
140
- return baseMargin;
141
- }
142
- var itemWidth = 148;
143
- var itemHeight = 22;
144
- var availableLegendWidth = Math.max(itemWidth, size.width - baseMargin.left - baseMargin.right);
145
- var legendColumns = Math.max(1, Math.floor(availableLegendWidth / itemWidth));
146
- var legendRows = hasTopLegend ? Math.ceil(config.series.length / legendColumns) : 0;
147
- var legendY = titleVisible
148
- ? topOptionLabelsVisible ? 58 : 54
149
- : 16;
150
- var legendHeight = legendRows > 0 ? legendRows * itemHeight : 0;
151
- var optionLabelLift = topOptionLabelsVisible ? 18 : 0;
152
- var gap = topOptionLabelsVisible ? 12 : 18;
153
- var requiredTop = Math.ceil(legendY + legendHeight + optionLabelLift + gap);
154
- if (!titleVisible || topOptionLabelsVisible) {
155
- return __assign(__assign({}, baseMargin), { top: Math.max(defaultMargin.top, requiredTop) });
156
- }
157
- return baseMargin;
158
- };
159
- var resolveContainer = function (selector) {
160
- var container = typeof selector === 'string'
161
- ? (0, d3_selection_1.select)(selector)
162
- : (0, d3_selection_1.select)(selector);
163
- if (!container.node()) {
164
- throw new Error('KChart container not found.');
165
- }
166
- return container;
167
- };
168
- var resolveSize = function (container, config, margin) {
169
- var _a, _b;
170
- var rect = container.node().getBoundingClientRect();
171
- var size = {
172
- width: (_a = config.width) !== null && _a !== void 0 ? _a : Math.max(rect.width, 320),
173
- height: (_b = config.height) !== null && _b !== void 0 ? _b : Math.max(rect.height, 240)
174
- };
175
- var effectiveMargin = resolveEffectiveMargin(config, size, margin);
176
- return {
177
- size: size,
178
- plotSize: {
179
- width: Math.max(size.width - effectiveMargin.left - effectiveMargin.right, 0),
180
- height: Math.max(size.height - effectiveMargin.top - effectiveMargin.bottom, 0)
181
- },
182
- margin: effectiveMargin
183
- };
184
- };
185
- var createLayers = function (container, config, getSize, getMargin) {
186
- container
187
- .classed('kchart', true)
188
- .style('position', 'relative');
189
- if (config.className) {
190
- container.classed(config.className, true);
191
- }
192
- var svg = container.selectAll('svg.kchart-svg')
193
- .data([undefined])
194
- .join('svg')
195
- .attr('class', 'kchart-svg')
196
- .style('position', 'relative')
197
- .style('z-index', 3)
198
- .style('pointer-events', 'all');
199
- var rootGroup = svg.selectAll('g.kchart-root')
200
- .data([undefined])
201
- .join('g')
202
- .attr('class', 'kchart-root');
203
- var plotGroup = rootGroup.selectAll('g.kchart-plot')
204
- .data([undefined])
205
- .join('g')
206
- .attr('class', 'kchart-plot');
207
- var seriesGroup = plotGroup.selectAll('g.kchart-series')
208
- .data([undefined])
209
- .join('g')
210
- .attr('class', 'kchart-series');
211
- var overlayGroup = plotGroup.selectAll('g.kchart-overlay')
212
- .data([undefined])
213
- .join('g')
214
- .attr('class', 'kchart-overlay');
215
- var getCanvas = function (name) {
216
- if (name === void 0) { name = 'default'; }
217
- return ensureCanvas(container, name, getSize(), getMargin(), '2d');
218
- };
219
- var getWebglCanvas = function (name) {
220
- if (name === void 0) { name = 'webgl'; }
221
- return ensureCanvas(container, name, getSize(), getMargin(), 'webgl');
222
- };
223
- return {
224
- svg: svg,
225
- rootGroup: rootGroup,
226
- plotGroup: plotGroup,
227
- seriesGroup: seriesGroup,
228
- overlayGroup: overlayGroup,
229
- getCanvas: getCanvas,
230
- getWebglCanvas: getWebglCanvas
231
- };
232
- };
233
- var ensureCanvas = function (container, name, size, margin, renderer) {
234
- var className = "kchart-".concat(renderer, "-canvas-").concat(name);
235
- var width = Math.max(size.width - margin.left - margin.right, 0);
236
- var height = Math.max(size.height - margin.top - margin.bottom, 0);
237
- var canvas = container.selectAll("canvas.".concat(className))
238
- .data([undefined])
239
- .join('canvas')
240
- .attr('class', className)
241
- .style('position', 'absolute')
242
- .style('z-index', 1)
243
- .style('pointer-events', 'none')
244
- .style('left', "".concat(margin.left, "px"))
245
- .style('top', "".concat(margin.top, "px"))
246
- .style('width', "".concat(width, "px"))
247
- .style('height', "".concat(height, "px"))
248
- .attr('data-kchart-width', String(width))
249
- .attr('data-kchart-height', String(height))
250
- .node();
251
- if (!transferredCanvases.has(canvas)) {
252
- canvas.width = width;
253
- canvas.height = height;
254
- }
255
- return canvas;
256
- };
257
- var resolveAxisDomain = function (axis, data) {
258
- var _a, _b, _c, _d, _e, _f, _g;
259
- if (axis.domain) {
260
- return axis.domain;
261
- }
262
- if (axis.type === 'string' || axis.type === 'point') {
263
- return data.map(function (item) { return item[axis.field]; });
264
- }
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];
268
- return axis.type === 'time'
269
- ? new Date(value)
270
- : Number(value);
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
- }
298
- return [
299
- resolvedMin,
300
- resolvedMax
301
- ];
302
- };
303
- var resolveScales = function (data, axes, plotSize) { return axes.map(function (axis) {
304
- var _a, _b;
305
- var isHorizontal = axis.placement === 'bottom' || axis.placement === 'top';
306
- var range = isHorizontal ? [0, plotSize.width] : [plotSize.height, 0];
307
- var domain = resolveAxisDomain(axis, data);
308
- var scale;
309
- if (axis.type === 'string') {
310
- scale = (0, d3_scale_1.scaleBand)()
311
- .domain(domain.map(String))
312
- .range(range)
313
- .padding((_a = axis.padding) !== null && _a !== void 0 ? _a : 0.1);
314
- }
315
- else if (axis.type === 'point') {
316
- scale = (0, d3_scale_1.scalePoint)()
317
- .domain(domain.map(String))
318
- .range(range)
319
- .padding((_b = axis.padding) !== null && _b !== void 0 ? _b : 0.1);
320
- }
321
- else if (axis.type === 'time') {
322
- scale = (0, d3_scale_1.scaleTime)()
323
- .domain(domain.map(function (value) { return value instanceof Date ? value : new Date(value); }))
324
- .range(range);
325
- }
326
- else {
327
- scale = (0, d3_scale_1.scaleLinear)()
328
- .domain(domain.map(Number))
329
- .range(range)
330
- .nice();
331
- }
332
- return __assign(__assign({}, axis), { scale: scale });
333
- }); };
334
- var renderAxes = function (state) {
335
- var axisLayer = state.layers.rootGroup.selectAll('g.kchart-axes')
336
- .data([undefined])
337
- .join('g')
338
- .attr('class', 'kchart-axes')
339
- .attr('transform', "translate(".concat(state.margin.left, ", ").concat(state.margin.top, ")"));
340
- state.scales.forEach(function (scale) {
341
- var axisGroup = axisLayer.selectAll("g.kchart-axis-".concat(scale.placement))
342
- .data(scale.visible === false ? [] : [scale])
343
- .join('g')
344
- .attr('class', "kchart-axis kchart-axis-".concat(scale.placement));
345
- var axisFactory = {
346
- top: d3_axis_1.axisTop,
347
- right: d3_axis_1.axisRight,
348
- bottom: d3_axis_1.axisBottom,
349
- left: d3_axis_1.axisLeft
350
- }[scale.placement](scale.scale);
351
- if (scale.tickCount && typeof axisFactory.ticks === 'function') {
352
- axisFactory.ticks(scale.tickCount);
353
- }
354
- if (scale.tickFormat) {
355
- axisFactory.tickFormat(scale.tickFormat);
356
- }
357
- axisGroup
358
- .attr('transform', resolveAxisTransform(scale.placement, state.plotSize))
359
- .call(axisFactory);
360
- renderAxisTitle(axisGroup, scale, state.plotSize);
361
- });
362
- };
363
- var renderAxisTitle = function (axisGroup, scale, plotSize) {
364
- var _a;
365
- var title = axisGroup.selectAll('text.kchart-axis-title')
366
- .data(scale.title ? [scale] : [])
367
- .join('text')
368
- .attr('class', 'kchart-axis-title')
369
- .style('fill', '#9fb1bf')
370
- .style('font-size', '12px')
371
- .style('font-weight', 600)
372
- .style('text-anchor', 'middle')
373
- .text((_a = scale.title) !== null && _a !== void 0 ? _a : '');
374
- if (scale.placement === 'bottom') {
375
- title.attr('x', plotSize.width / 2).attr('y', 34).attr('transform', null);
376
- }
377
- else if (scale.placement === 'top') {
378
- title.attr('x', plotSize.width / 2).attr('y', -24).attr('transform', null);
379
- }
380
- else if (scale.placement === 'left') {
381
- title.attr('x', -plotSize.height / 2).attr('y', -36).attr('transform', 'rotate(-90)');
382
- }
383
- else {
384
- title.attr('x', plotSize.height / 2).attr('y', -36).attr('transform', 'rotate(90)');
385
- }
386
- };
387
- var resolveAxisTransform = function (placement, plotSize) {
388
- if (placement === 'bottom') {
389
- return "translate(0, ".concat(plotSize.height, ")");
390
- }
391
- if (placement === 'right') {
392
- return "translate(".concat(plotSize.width, ", 0)");
393
- }
394
- return 'translate(0, 0)';
395
- };
396
- var resolveScalePosition = function (scale, value) {
397
- var scaleValue = scale.type === 'time' && !(value instanceof Date)
398
- ? new Date(value)
399
- : value;
400
- var position = scale.scale(scaleValue);
401
- return typeof scale.scale.bandwidth === 'function'
402
- ? position + scale.scale.bandwidth() / 2
403
- : position;
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 resolveGlobeDrilldownConfiguration = function (drilldown) {
547
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
548
- if (typeof drilldown === 'boolean') {
549
- return {
550
- enabled: drilldown,
551
- mode: 'map',
552
- autoMapOnZoom: false,
553
- mapZoomThreshold: 2.4,
554
- globeZoomThreshold: 1.8,
555
- focusZoom: 2.6,
556
- zoomScale: 6,
557
- duration: 720,
558
- resetControl: true
559
- };
560
- }
561
- return {
562
- enabled: (_a = drilldown === null || drilldown === void 0 ? void 0 : drilldown.enabled) !== null && _a !== void 0 ? _a : false,
563
- mode: (_b = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mode) !== null && _b !== void 0 ? _b : 'map',
564
- autoMapOnZoom: (_c = drilldown === null || drilldown === void 0 ? void 0 : drilldown.autoMapOnZoom) !== null && _c !== void 0 ? _c : false,
565
- mapZoomThreshold: (_d = drilldown === null || drilldown === void 0 ? void 0 : drilldown.mapZoomThreshold) !== null && _d !== void 0 ? _d : 2.4,
566
- globeZoomThreshold: (_e = drilldown === null || drilldown === void 0 ? void 0 : drilldown.globeZoomThreshold) !== null && _e !== void 0 ? _e : 1.8,
567
- focusZoom: (_f = drilldown === null || drilldown === void 0 ? void 0 : drilldown.focusZoom) !== null && _f !== void 0 ? _f : 2.6,
568
- zoomScale: (_g = drilldown === null || drilldown === void 0 ? void 0 : drilldown.zoomScale) !== null && _g !== void 0 ? _g : 6,
569
- duration: (_h = drilldown === null || drilldown === void 0 ? void 0 : drilldown.duration) !== null && _h !== void 0 ? _h : 720,
570
- resetControl: (_j = drilldown === null || drilldown === void 0 ? void 0 : drilldown.resetControl) !== null && _j !== void 0 ? _j : true,
571
- landFill: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landFill,
572
- landStroke: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landStroke,
573
- landOpacity: drilldown === null || drilldown === void 0 ? void 0 : drilldown.landOpacity,
574
- onEnter: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onEnter,
575
- onExit: drilldown === null || drilldown === void 0 ? void 0 : drilldown.onExit
576
- };
577
- };
578
- var WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
579
- var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
580
- var WORLD_COUNTRY_BORDERS_GEOJSON = (0, topojson_client_1.mesh)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries, function (a, b) { return a !== b; });
581
- var isGlobePointVisible = function (lon, lat, rotation) {
582
- if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
583
- return false;
584
- }
585
- var center = [-rotation[0], -rotation[1]];
586
- return (0, d3_geo_1.geoDistance)([lon, lat], center) <= Math.PI / 2;
587
- };
588
- var downsampleLTTB = function (data, threshold, xAccessor, yAccessor) {
589
- var dataLength = data.length;
590
- var targetLength = Math.floor(threshold);
591
- if (dataLength <= 2 || !Number.isFinite(targetLength) || targetLength <= 0 || targetLength >= dataLength) {
592
- return data;
593
- }
594
- if (targetLength === 1) {
595
- return [data[0]];
596
- }
597
- if (targetLength === 2) {
598
- return [data[0], data[dataLength - 1]];
599
- }
600
- var sampled = [data[0]];
601
- var bucketSize = (dataLength - 2) / (targetLength - 2);
602
- var previousSelectedIndex = 0;
603
- for (var bucketIndex = 0; bucketIndex < targetLength - 2; bucketIndex += 1) {
604
- var averageStart = Math.floor((bucketIndex + 1) * bucketSize) + 1;
605
- var averageEnd = Math.min(Math.floor((bucketIndex + 2) * bucketSize) + 1, dataLength);
606
- var averageLength = Math.max(averageEnd - averageStart, 1);
607
- var averageX = 0;
608
- var averageY = 0;
609
- for (var index = averageStart; index < averageEnd; index += 1) {
610
- averageX += xAccessor(data[index]);
611
- averageY += yAccessor(data[index]);
612
- }
613
- if (averageEnd <= averageStart) {
614
- averageX = xAccessor(data[dataLength - 1]);
615
- averageY = yAccessor(data[dataLength - 1]);
616
- }
617
- else {
618
- averageX /= averageLength;
619
- averageY /= averageLength;
620
- }
621
- var rangeStart = Math.floor(bucketIndex * bucketSize) + 1;
622
- var rangeEnd = Math.min(Math.floor((bucketIndex + 1) * bucketSize) + 1, dataLength - 1);
623
- var pointAX = xAccessor(data[previousSelectedIndex]);
624
- var pointAY = yAccessor(data[previousSelectedIndex]);
625
- var maxArea = -1;
626
- var maxAreaIndex = rangeStart;
627
- for (var index = rangeStart; index < rangeEnd; index += 1) {
628
- var pointBX = xAccessor(data[index]);
629
- var pointBY = yAccessor(data[index]);
630
- var area = Math.abs((pointAX - averageX) * (pointBY - pointAY)
631
- - (pointAX - pointBX) * (averageY - pointAY)) * 0.5;
632
- if (Number.isFinite(area) && area > maxArea) {
633
- maxArea = area;
634
- maxAreaIndex = index;
635
- }
636
- }
637
- sampled.push(data[maxAreaIndex]);
638
- previousSelectedIndex = maxAreaIndex;
639
- }
640
- sampled.push(data[dataLength - 1]);
641
- return sampled;
642
- };
643
- exports.downsampleLTTB = downsampleLTTB;
644
- var resolveDownsampleValue = function (value, scale) {
645
- if (value instanceof Date) {
646
- return value.getTime();
647
- }
648
- if ((scale === null || scale === void 0 ? void 0 : scale.type) === 'time' && typeof value === 'string') {
649
- return new Date(value).getTime();
650
- }
651
- return Number(value);
652
- };
653
- var resolveDownsampleAccessor = function (field, scale) {
654
- if (!field) {
655
- return undefined;
656
- }
657
- return function (point) { return resolveDownsampleValue(point[field], scale); };
658
- };
659
- var resolveDownsampleThreshold = function (downsample, context) {
660
- var _a;
661
- if (typeof downsample === 'boolean') {
662
- return Math.max(3, Math.floor(context.plotSize.width));
663
- }
664
- if (typeof downsample.threshold === 'function') {
665
- return downsample.threshold(context);
666
- }
667
- return (_a = downsample.threshold) !== null && _a !== void 0 ? _a : Math.max(3, Math.floor(context.plotSize.width));
668
- };
669
- var resolveSeriesRenderData = function (state, series, xScale, yScale) {
670
- var _a, _b;
671
- var downsample = series.downsample;
672
- if (!downsample || (typeof downsample !== 'boolean' && downsample.enabled === false)) {
673
- return state.data;
674
- }
675
- var xAccessor = typeof downsample === 'boolean'
676
- ? resolveDownsampleAccessor(series.xField, xScale)
677
- : (_a = downsample.xAccessor) !== null && _a !== void 0 ? _a : resolveDownsampleAccessor(series.xField, xScale);
678
- var yAccessor = typeof downsample === 'boolean'
679
- ? resolveDownsampleAccessor(series.yField, yScale)
680
- : (_b = downsample.yAccessor) !== null && _b !== void 0 ? _b : resolveDownsampleAccessor(series.yField, yScale);
681
- if (!xAccessor || !yAccessor) {
682
- return state.data;
683
- }
684
- var context = {
685
- data: state.data,
686
- plotSize: state.plotSize,
687
- series: series,
688
- xField: series.xField,
689
- yField: series.yField
690
- };
691
- var threshold = resolveDownsampleThreshold(downsample, context);
692
- return (0, exports.downsampleLTTB)(state.data, threshold, xAccessor, yAccessor);
693
- };
694
- var getAsyncCanvasEntry = function (canvas, renderer, asyncRender) {
695
- if (!(asyncRender === null || asyncRender === void 0 ? void 0 : asyncRender.enabled) || !asyncRender.workerFactory || typeof canvas.transferControlToOffscreen !== 'function') {
696
- return null;
697
- }
698
- var existing = asyncCanvasEntries.get(canvas);
699
- if (existing) {
700
- return existing.failed || existing.renderer !== renderer ? null : existing;
701
- }
702
- try {
703
- var worker = asyncRender.workerFactory();
704
- var canvasId = "kchart-offscreen-".concat(asyncCanvasId += 1);
705
- var offscreenCanvas = canvas.transferControlToOffscreen();
706
- var entry_1 = {
707
- worker: worker,
708
- renderer: renderer,
709
- canvasId: canvasId,
710
- failed: false
711
- };
712
- worker.onerror = function () {
713
- entry_1.failed = true;
714
- };
715
- worker.postMessage({
716
- type: 'kchart:init-canvas',
717
- canvasId: canvasId,
718
- renderer: renderer,
719
- canvas: offscreenCanvas
720
- }, [offscreenCanvas]);
721
- transferredCanvases.add(canvas);
722
- asyncCanvasEntries.set(canvas, entry_1);
723
- return entry_1;
724
- }
725
- catch (_error) {
726
- return null;
727
- }
728
- };
729
- var destroyAsyncCanvas = function (canvas) {
730
- var entry = asyncCanvasEntries.get(canvas);
731
- if (!entry) {
732
- return;
733
- }
734
- try {
735
- entry.worker.postMessage({
736
- type: 'kchart:destroy-canvas',
737
- canvasId: entry.canvasId
738
- });
739
- entry.worker.terminate();
740
- }
741
- catch (_error) {
742
- entry.worker.terminate();
743
- }
744
- asyncCanvasEntries.delete(canvas);
745
- };
746
- var destroyCanvasByClass = function (svg, className) {
747
- var _a;
748
- var parent = (_a = svg.node()) === null || _a === void 0 ? void 0 : _a.parentElement;
749
- if (!parent) {
750
- return;
751
- }
752
- (0, d3_selection_1.select)(parent).selectAll("canvas.".concat(className))
753
- .each(function destroyCanvas() {
754
- destroyAsyncCanvas(this);
755
- })
756
- .remove();
757
- };
758
- var resolveLinePoints = function (data, xScale, yScale, xField, yField) {
759
- var points = new Float32Array(data.length * 2);
760
- var pointIndex = 0;
761
- data.forEach(function (point) {
762
- if (point[xField] === undefined || point[yField] === undefined) {
763
- return;
764
- }
765
- var x = resolveScalePosition(xScale, point[xField]);
766
- var y = resolveScalePosition(yScale, point[yField]);
767
- if (Number.isFinite(x) && Number.isFinite(y)) {
768
- points[pointIndex] = x;
769
- points[pointIndex + 1] = y;
770
- pointIndex += 2;
771
- }
772
- });
773
- return pointIndex === points.length
774
- ? points
775
- : points.slice(0, pointIndex);
776
- };
777
- var resolveWebglLineVertices = function (points, width, height) {
778
- var vertices = new Float32Array(points.length);
779
- for (var index = 0; index < points.length; index += 2) {
780
- vertices[index] = (points[index] / width) * 2 - 1;
781
- vertices[index + 1] = 1 - (points[index + 1] / height) * 2;
782
- }
783
- return vertices;
784
- };
785
- var resolveWebglPointInterleavedData = function (data, xScale, yScale, xField, yField, width, height, resolveSize) {
786
- var buffer = new Float32Array(data.length * 3);
787
- var pointCount = 0;
788
- data.forEach(function (point) {
789
- if (point[xField] === undefined || point[yField] === undefined) {
790
- return;
791
- }
792
- var x = resolveScalePosition(xScale, point[xField]);
793
- var y = resolveScalePosition(yScale, point[yField]);
794
- if (!Number.isFinite(x) || !Number.isFinite(y)) {
795
- return;
796
- }
797
- var offset = pointCount * 3;
798
- buffer[offset] = (x / width) * 2 - 1;
799
- buffer[offset + 1] = 1 - (y / height) * 2;
800
- buffer[offset + 2] = resolveSize(point);
801
- pointCount += 1;
802
- });
803
- return {
804
- buffer: pointCount * 3 === buffer.length
805
- ? buffer
806
- : buffer.subarray(0, pointCount * 3),
807
- count: pointCount
808
- };
809
- };
810
- var resolveCanvasPixelSize = function (canvas) { return ({
811
- width: Number(canvas.dataset.kchartWidth) || canvas.width,
812
- height: Number(canvas.dataset.kchartHeight) || canvas.height
813
- }); };
814
- var renderLineWithWorker = function (canvas, renderer, asyncRender, payload) {
815
- var entry = getAsyncCanvasEntry(canvas, renderer, asyncRender);
816
- if (!entry) {
817
- return false;
818
- }
819
- var message = __assign({ type: 'kchart:render-line', canvasId: entry.canvasId, renderer: renderer }, payload);
820
- entry.worker.postMessage(message, [message.points.buffer]);
821
- return true;
822
- };
823
- var parseColor = function (color) {
824
- if (color.startsWith('#')) {
825
- var value = color.slice(1);
826
- var normalized = value.length === 3
827
- ? value.split('').map(function (item) { return item + item; }).join('')
828
- : value;
829
- var numberValue = parseInt(normalized, 16);
830
- return [
831
- ((numberValue >> 16) & 255) / 255,
832
- ((numberValue >> 8) & 255) / 255,
833
- (numberValue & 255) / 255,
834
- 1
835
- ];
836
- }
837
- return [0.35, 0.72, 1, 1];
838
- };
839
- var createShader = function (gl, type, source) {
840
- var shader = gl.createShader(type);
841
- if (!shader) {
842
- return null;
843
- }
844
- gl.shaderSource(shader, source);
845
- gl.compileShader(shader);
846
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
847
- gl.deleteShader(shader);
848
- return null;
849
- }
850
- return shader;
851
- };
852
- var createProgram = function (gl, vertexSource, fragmentSource) {
853
- var vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
854
- var fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
855
- if (!vertexShader || !fragmentShader) {
856
- return null;
857
- }
858
- var program = gl.createProgram();
859
- if (!program) {
860
- return null;
861
- }
862
- gl.attachShader(program, vertexShader);
863
- gl.attachShader(program, fragmentShader);
864
- gl.linkProgram(program);
865
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
866
- gl.deleteProgram(program);
867
- return null;
868
- }
869
- return program;
870
- };
871
- var startKChartRenderWorker = function (workerScope) {
872
- if (workerScope === void 0) { workerScope = self; }
873
- var canvases = new Map();
874
- var resolveWorkerProgram = function (entry) {
875
- var _a, _b;
876
- if (entry.program) {
877
- return entry.program;
878
- }
879
- if (!entry.gl) {
880
- return null;
881
- }
882
- var vertexSource = "\n attribute vec2 a_position;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }\n ";
883
- var fragmentSource = "\n precision mediump float;\n uniform vec4 u_color;\n\n void main() {\n gl_FragColor = u_color;\n }\n ";
884
- entry.program = (_a = createProgram(entry.gl, vertexSource, fragmentSource)) !== null && _a !== void 0 ? _a : undefined;
885
- return (_b = entry.program) !== null && _b !== void 0 ? _b : null;
886
- };
887
- var drawCanvasLine = function (entry, message) {
888
- var context = entry.context2d;
889
- if (!context) {
890
- return;
891
- }
892
- entry.canvas.width = message.width;
893
- entry.canvas.height = message.height;
894
- context.clearRect(0, 0, message.width, message.height);
895
- context.beginPath();
896
- context.lineCap = 'round';
897
- context.lineJoin = 'round';
898
- context.lineWidth = message.lineWidth;
899
- context.strokeStyle = message.color;
900
- for (var index = 0; index < message.points.length; index += 2) {
901
- var x = message.points[index];
902
- var y = message.points[index + 1];
903
- if (index === 0) {
904
- context.moveTo(x, y);
905
- }
906
- else {
907
- context.lineTo(x, y);
908
- }
909
- }
910
- context.stroke();
911
- };
912
- var drawWebglLine = function (entry, message) {
913
- var gl = entry.gl;
914
- if (!gl) {
915
- return;
916
- }
917
- entry.canvas.width = message.width;
918
- entry.canvas.height = message.height;
919
- var vertices = new Float32Array(message.points.length);
920
- for (var index = 0; index < message.points.length; index += 2) {
921
- vertices[index] = (message.points[index] / message.width) * 2 - 1;
922
- vertices[index + 1] = 1 - (message.points[index + 1] / message.height) * 2;
923
- }
924
- var program = resolveWorkerProgram(entry);
925
- if (!program) {
926
- return;
927
- }
928
- gl.viewport(0, 0, message.width, message.height);
929
- gl.clearColor(0, 0, 0, 0);
930
- gl.clear(gl.COLOR_BUFFER_BIT);
931
- gl.useProgram(program);
932
- gl.enable(gl.BLEND);
933
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
934
- gl.lineWidth(message.lineWidth);
935
- var positionBuffer = gl.createBuffer();
936
- gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
937
- gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
938
- var positionLocation = gl.getAttribLocation(program, 'a_position');
939
- gl.enableVertexAttribArray(positionLocation);
940
- gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
941
- var colorLocation = gl.getUniformLocation(program, 'u_color');
942
- gl.uniform4fv(colorLocation, new Float32Array(parseColor(message.color)));
943
- gl.drawArrays(gl.LINE_STRIP, 0, vertices.length / 2);
944
- gl.deleteBuffer(positionBuffer);
945
- };
946
- workerScope.onmessage = function (event) {
947
- var _a, _b;
948
- var message = event.data;
949
- if (message.type === 'kchart:init-canvas') {
950
- var canvas = message.canvas;
951
- var renderer = message.renderer;
952
- var entry = {
953
- canvas: canvas,
954
- renderer: renderer
955
- };
956
- if (renderer === '2d') {
957
- entry.context2d = (_a = canvas.getContext('2d')) !== null && _a !== void 0 ? _a : undefined;
958
- }
959
- else {
960
- entry.gl = (_b = canvas.getContext('webgl', { alpha: true })) !== null && _b !== void 0 ? _b : undefined;
961
- }
962
- canvases.set(message.canvasId, entry);
963
- return;
964
- }
965
- if (message.type === 'kchart:destroy-canvas') {
966
- canvases.delete(message.canvasId);
967
- return;
968
- }
969
- if (message.type === 'kchart:render-line') {
970
- var entry = canvases.get(message.canvasId);
971
- if (!entry) {
972
- return;
973
- }
974
- if (message.renderer === '2d') {
975
- drawCanvasLine(entry, message);
976
- }
977
- else {
978
- drawWebglLine(entry, message);
979
- }
980
- }
981
- };
982
- };
983
- exports.startKChartRenderWorker = startKChartRenderWorker;
984
- var renderTitle = function (state) {
985
- var _a, _b, _c, _d, _e;
986
- var title = state.config.title;
987
- var hasTitle = Boolean((_a = title === null || title === void 0 ? void 0 : title.text) === null || _a === void 0 ? void 0 : _a.trim());
988
- var titleY = Math.max(Math.min(state.margin.top - 42, 28), 20);
989
- var titleGroup = state.layers.rootGroup.selectAll('text.kchart-title')
990
- .data(hasTitle ? [undefined] : [])
991
- .join('text')
992
- .attr('class', 'kchart-title')
993
- .attr('y', titleY)
994
- .style('fill', (_b = title === null || title === void 0 ? void 0 : title.color) !== null && _b !== void 0 ? _b : '#edf3f8')
995
- .style('font-size', "".concat((_c = title === null || title === void 0 ? void 0 : title.fontSize) !== null && _c !== void 0 ? _c : 14, "px"))
996
- .style('font-weight', (_d = title === null || title === void 0 ? void 0 : title.fontWeight) !== null && _d !== void 0 ? _d : 700)
997
- .text((_e = title === null || title === void 0 ? void 0 : title.text) !== null && _e !== void 0 ? _e : '');
998
- if (!title || !hasTitle) {
999
- return;
1000
- }
1001
- if (title.align === 'left') {
1002
- titleGroup.attr('x', state.margin.left).style('text-anchor', 'start');
1003
- }
1004
- else if (title.align === 'right') {
1005
- titleGroup.attr('x', state.size.width - state.margin.right).style('text-anchor', 'end');
1006
- }
1007
- else {
1008
- titleGroup.attr('x', state.size.width / 2).style('text-anchor', 'middle');
1009
- }
1010
- };
1011
- var renderGrid = function (state) {
1012
- var _a;
1013
- var grid = state.config.grid;
1014
- var isVisible = (grid === null || grid === void 0 ? void 0 : grid.visible) !== false;
1015
- var gridGroup = state.layers.plotGroup.selectAll('g.kchart-grid')
1016
- .data(isVisible ? [undefined] : [])
1017
- .join('g')
1018
- .attr('class', 'kchart-grid');
1019
- if (!isVisible) {
1020
- return;
1021
- }
1022
- var xScale = state.scales.find(function (scale) { return scale.placement === 'bottom' || scale.placement === 'top'; });
1023
- var yScale = state.scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; });
1024
- var color = (_a = grid === null || grid === void 0 ? void 0 : grid.color) !== null && _a !== void 0 ? _a : 'rgba(188, 206, 218, 0.18)';
1025
- var styleLine = function (selection) {
1026
- var _a;
1027
- return selection
1028
- .style('stroke', color)
1029
- .style('stroke-width', 1)
1030
- .style('stroke-dasharray', (_a = grid === null || grid === void 0 ? void 0 : grid.dasharray) !== null && _a !== void 0 ? _a : '2 6')
1031
- .style('shape-rendering', 'crispEdges');
1032
- };
1033
- if ((grid === null || grid === void 0 ? void 0 : grid.x) !== false && xScale && typeof xScale.scale.ticks === 'function') {
1034
- gridGroup.selectAll('line.kchart-grid-x')
1035
- .data(xScale.scale.ticks())
1036
- .join('line')
1037
- .attr('class', 'kchart-grid-x')
1038
- .attr('x1', function (value) { return resolveScalePosition(xScale, value); })
1039
- .attr('x2', function (value) { return resolveScalePosition(xScale, value); })
1040
- .attr('y1', 0)
1041
- .attr('y2', state.plotSize.height)
1042
- .call(styleLine);
1043
- }
1044
- else {
1045
- gridGroup.selectAll('line.kchart-grid-x').remove();
1046
- }
1047
- if ((grid === null || grid === void 0 ? void 0 : grid.y) !== false && yScale && typeof yScale.scale.ticks === 'function') {
1048
- gridGroup.selectAll('line.kchart-grid-y')
1049
- .data(yScale.scale.ticks())
1050
- .join('line')
1051
- .attr('class', 'kchart-grid-y')
1052
- .attr('x1', 0)
1053
- .attr('x2', state.plotSize.width)
1054
- .attr('y1', function (value) { return resolveScalePosition(yScale, value); })
1055
- .attr('y2', function (value) { return resolveScalePosition(yScale, value); })
1056
- .call(styleLine);
1057
- }
1058
- else {
1059
- gridGroup.selectAll('line.kchart-grid-y').remove();
1060
- }
1061
- };
1062
- var getSpecAreas = function (state) {
1063
- var _a, _b;
1064
- return __spreadArray(__spreadArray([], ((_a = state.config.specAreas) !== null && _a !== void 0 ? _a : []), true), ((_b = state.config.options) !== null && _b !== void 0 ? _b : [])
1065
- .filter(function (option) { return option.type === 'spec-area' && option.visible !== false; })
1066
- .flatMap(function (option) { return option.areas; }), true).filter(function (area) { return area.visible !== false; });
1067
- };
1068
- var renderSpecAreas = function (state) {
1069
- var areas = getSpecAreas(state);
1070
- var areaGroup = state.layers.plotGroup.selectAll('g.kchart-spec-areas')
1071
- .data(areas.length ? [undefined] : [])
1072
- .join('g')
1073
- .attr('class', 'kchart-spec-areas');
1074
- var labelGroup = state.layers.plotGroup.selectAll('g.kchart-spec-area-labels')
1075
- .data(areas.length ? [undefined] : [])
1076
- .join('g')
1077
- .attr('class', 'kchart-spec-area-labels');
1078
- if (!areas.length) {
1079
- return;
1080
- }
1081
- var xScale = state.scales.find(function (scale) { return scale.placement === 'bottom' || scale.placement === 'top'; });
1082
- if (!xScale) {
1083
- return;
1084
- }
1085
- var clamp = function (value) { return Math.max(0, Math.min(state.plotSize.width, value)); };
1086
- var area = areaGroup.selectAll('g.kchart-spec-area')
1087
- .data(areas)
1088
- .join('g')
1089
- .attr('class', 'kchart-spec-area');
1090
- area.selectAll('rect')
1091
- .data(function (item) { return [item]; })
1092
- .join('rect')
1093
- .attr('x', function (item) { return clamp(resolveScalePosition(xScale, item.start)); })
1094
- .attr('y', 0)
1095
- .attr('width', function (item) { return Math.max(0, clamp(resolveScalePosition(xScale, item.end)) - clamp(resolveScalePosition(xScale, item.start))); })
1096
- .attr('height', state.plotSize.height)
1097
- .style('fill', function (item) { var _a; return (_a = item.color) !== null && _a !== void 0 ? _a : 'rgba(249, 225, 250, 0.22)'; })
1098
- .style('pointer-events', 'none');
1099
- var labels = labelGroup.selectAll('g.kchart-spec-area-label')
1100
- .data(areas.filter(function (item) { return item.label; }))
1101
- .join('g')
1102
- .attr('class', 'kchart-spec-area-label')
1103
- .attr('transform', function (item) {
1104
- var start = clamp(resolveScalePosition(xScale, item.start));
1105
- var end = clamp(resolveScalePosition(xScale, item.end));
1106
- return "translate(".concat(start + Math.max(0, end - start) / 2, ", -14)");
1107
- })
1108
- .style('pointer-events', 'none');
1109
- labels.selectAll('rect')
1110
- .data(function (item) { return [item]; })
1111
- .join('rect')
1112
- .attr('x', function (item) { var _a, _b; return -Math.max(46, ((_b = (_a = item.label) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) * 6.5) / 2; })
1113
- .attr('y', -11)
1114
- .attr('width', function (item) { var _a, _b; return Math.max(46, ((_b = (_a = item.label) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) * 6.5); })
1115
- .attr('height', 18)
1116
- .attr('rx', 5)
1117
- .style('fill', 'rgba(10, 14, 20, 0.82)')
1118
- .style('stroke', 'rgba(248, 251, 255, 0.22)')
1119
- .style('stroke-width', 1);
1120
- labels.selectAll('text')
1121
- .data(function (item) { return [item]; })
1122
- .join('text')
1123
- .attr('x', 0)
1124
- .attr('y', 2)
1125
- .style('fill', '#b6c4cf')
1126
- .style('font-size', '11px')
1127
- .style('font-weight', 700)
1128
- .style('text-anchor', 'middle')
1129
- .text(function (item) { var _a; return (_a = item.label) !== null && _a !== void 0 ? _a : ''; });
1130
- };
1131
- var getFixedGuideLines = function (state) {
1132
- var _a, _b, _c;
1133
- var config = state.config.guideLines;
1134
- if ((config === null || config === void 0 ? void 0 : config.visible) === false) {
1135
- return [];
1136
- }
1137
- return __spreadArray(__spreadArray(__spreadArray([], ((_a = config === null || config === void 0 ? void 0 : config.x) !== null && _a !== void 0 ? _a : []).map(function (item) { return (__assign(__assign({}, item), { axis: 'x' })); }), true), ((_b = config === null || config === void 0 ? void 0 : config.y) !== null && _b !== void 0 ? _b : []).map(function (item) { return (__assign(__assign({}, item), { axis: 'y' })); }), true), ((_c = state.config.options) !== null && _c !== void 0 ? _c : [])
1138
- .filter(function (option) { return option.type === 'guide-line' && option.visible !== false; })
1139
- .flatMap(function (option) {
1140
- var _a, _b;
1141
- return __spreadArray(__spreadArray([], ((_a = option.x) !== null && _a !== void 0 ? _a : []).map(function (item) { return (__assign(__assign({}, item), { axis: 'x' })); }), true), ((_b = option.y) !== null && _b !== void 0 ? _b : []).map(function (item) { return (__assign(__assign({}, item), { axis: 'y' })); }), true);
1142
- }), true).filter(function (item) { return item.visible !== false; });
1143
- };
1144
- var renderGuideLines = function (state) {
1145
- var guideLines = getFixedGuideLines(state);
1146
- var guideGroup = state.layers.plotGroup.selectAll('g.kchart-fixed-guide-lines')
1147
- .data(guideLines.length ? [undefined] : [])
1148
- .join('g')
1149
- .attr('class', 'kchart-fixed-guide-lines');
1150
- if (!guideLines.length) {
1151
- return;
1152
- }
1153
- var xScale = state.scales.find(function (scale) { return scale.placement === 'bottom' || scale.placement === 'top'; });
1154
- var yScale = state.scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; });
1155
- var positioned = guideLines
1156
- .map(function (item) {
1157
- var scale = item.axis === 'y' ? yScale : xScale;
1158
- if (!scale) {
1159
- return null;
1160
- }
1161
- var position = resolveScalePosition(scale, item.value);
1162
- if (!Number.isFinite(position)) {
1163
- return null;
1164
- }
1165
- return __assign(__assign({}, item), { position: position });
1166
- })
1167
- .filter(function (item) { return Boolean(item); });
1168
- var guide = guideGroup.selectAll('g.kchart-fixed-guide-line')
1169
- .data(positioned, function (item) { var _a; return "".concat(item.axis, "-").concat(String(item.value), "-").concat((_a = item.label) !== null && _a !== void 0 ? _a : ''); })
1170
- .join('g')
1171
- .attr('class', function (item) { return "kchart-fixed-guide-line kchart-fixed-guide-line-".concat(item.axis); });
1172
- guide.selectAll('line')
1173
- .data(function (item) { return [item]; })
1174
- .join('line')
1175
- .attr('x1', function (item) { return item.axis === 'x' ? item.position : 0; })
1176
- .attr('x2', function (item) { return item.axis === 'x' ? item.position : state.plotSize.width; })
1177
- .attr('y1', function (item) { return item.axis === 'x' ? 0 : item.position; })
1178
- .attr('y2', function (item) { return item.axis === 'x' ? state.plotSize.height : item.position; })
1179
- .style('stroke', function (item) { var _a; return (_a = item.color) !== null && _a !== void 0 ? _a : 'rgba(248, 251, 255, 0.46)'; })
1180
- .style('stroke-width', function (item) { var _a; return (_a = item.width) !== null && _a !== void 0 ? _a : 1; })
1181
- .style('stroke-dasharray', function (item) { var _a; return (_a = item.dasharray) !== null && _a !== void 0 ? _a : '4 6'; })
1182
- .style('shape-rendering', 'crispEdges')
1183
- .style('pointer-events', 'none');
1184
- var labels = guide.selectAll('g.kchart-fixed-guide-line-label')
1185
- .data(function (item) { return item.label ? [item] : []; })
1186
- .join('g')
1187
- .attr('class', 'kchart-fixed-guide-line-label')
1188
- .attr('transform', function (item) { return item.axis === 'x'
1189
- ? "translate(".concat(item.position, ", -20)")
1190
- : "translate(-12, ".concat(item.position, ")"); });
1191
- labels.selectAll('rect')
1192
- .data(function (item) { return [item]; })
1193
- .join('rect')
1194
- .attr('x', function (item) { return item.axis === 'x' ? -Math.max(28, String(item.label).length * 7 + 14) / 2 : -Math.max(28, String(item.label).length * 7 + 14); })
1195
- .attr('y', -12)
1196
- .attr('width', function (item) { return Math.max(28, String(item.label).length * 7 + 14); })
1197
- .attr('height', 18)
1198
- .attr('rx', 5)
1199
- .style('fill', function (item) { var _a; return (_a = item.labelBackground) !== null && _a !== void 0 ? _a : 'rgba(10, 14, 20, 0.84)'; })
1200
- .style('stroke', function (item) { var _a; return (_a = item.color) !== null && _a !== void 0 ? _a : 'rgba(248, 251, 255, 0.46)'; })
1201
- .style('stroke-width', 1);
1202
- labels.selectAll('text')
1203
- .data(function (item) { return [item]; })
1204
- .join('text')
1205
- .attr('x', function (item) { return item.axis === 'x' ? 0 : -Math.max(28, String(item.label).length * 7 + 14) / 2; })
1206
- .attr('y', 1)
1207
- .style('fill', function (item) { var _a; return (_a = item.labelColor) !== null && _a !== void 0 ? _a : '#edf3f8'; })
1208
- .style('font-size', '11px')
1209
- .style('font-weight', 700)
1210
- .style('text-anchor', 'middle')
1211
- .style('pointer-events', 'none')
1212
- .text(function (item) { var _a; return (_a = item.label) !== null && _a !== void 0 ? _a : ''; });
1213
- };
1214
- var renderLegend = function (state) {
1215
- var _a, _b, _c;
1216
- var legend = state.config.legend;
1217
- var isVisible = (legend === null || legend === void 0 ? void 0 : legend.visible) !== false && state.series.length > 0;
1218
- var legendGroup = state.layers.rootGroup.selectAll('g.kchart-legend')
1219
- .data(isVisible ? [undefined] : [])
1220
- .join('g')
1221
- .attr('class', 'kchart-legend');
1222
- if (!isVisible) {
1223
- return;
1224
- }
1225
- var itemGap = (_a = legend === null || legend === void 0 ? void 0 : legend.itemGap) !== null && _a !== void 0 ? _a : 14;
1226
- var itemWidth = 148;
1227
- var itemHeight = 22;
1228
- var availableLegendWidth = Math.max(itemWidth, state.size.width - state.margin.left - state.margin.right);
1229
- var legendColumns = Math.max(1, Math.floor(availableLegendWidth / itemWidth));
1230
- var items = state.series.map(function (series, index) {
1231
- var _a, _b;
1232
- return ({
1233
- selector: series.selector,
1234
- name: (_a = series.displayName) !== null && _a !== void 0 ? _a : series.selector,
1235
- color: (_b = series.color) !== null && _b !== void 0 ? _b : state.colors[index % state.colors.length],
1236
- hidden: state.hiddenSeries.has(series.selector)
1237
- });
1238
- });
1239
- var selectable = (legend === null || legend === void 0 ? void 0 : legend.selectable) !== false;
1240
- var item = legendGroup.selectAll('g.kchart-legend-item')
1241
- .data(items)
1242
- .join('g')
1243
- .attr('class', 'kchart-legend-item')
1244
- .style('cursor', selectable ? 'pointer' : 'default')
1245
- .style('opacity', function (itemData) { return itemData.hidden ? 0.48 : 1; })
1246
- .attr('transform', function (_item, index) {
1247
- if ((legend === null || legend === void 0 ? void 0 : legend.placement) === 'right') {
1248
- return "translate(0, ".concat(index * 20, ")");
1249
- }
1250
- return "translate(".concat((index % legendColumns) * itemWidth, ", ").concat(Math.floor(index / legendColumns) * itemHeight, ")");
1251
- })
1252
- .on('click', function (_event, itemData) {
1253
- if (!selectable) {
1254
- return;
1255
- }
1256
- if (state.hiddenSeries.has(itemData.selector)) {
1257
- state.hiddenSeries.delete(itemData.selector);
1258
- }
1259
- else {
1260
- state.hiddenSeries.add(itemData.selector);
1261
- }
1262
- render(state);
1263
- });
1264
- item.selectAll('rect.kchart-legend-check')
1265
- .data(function (itemData) { return [itemData]; })
1266
- .join('rect')
1267
- .attr('class', 'kchart-legend-check')
1268
- .attr('x', -6)
1269
- .attr('y', -8)
1270
- .attr('width', 14)
1271
- .attr('height', 14)
1272
- .attr('rx', 3)
1273
- .style('fill', function (itemData) { return itemData.hidden ? 'transparent' : itemData.color; })
1274
- .style('stroke', '#f8fbff')
1275
- .style('stroke-width', 1.4);
1276
- item.selectAll('path.kchart-legend-checkmark')
1277
- .data(function (itemData) { return [itemData]; })
1278
- .join('path')
1279
- .attr('class', 'kchart-legend-checkmark')
1280
- .attr('d', 'M -2 -1 L 0 3 L 5 -5')
1281
- .style('fill', 'none')
1282
- .style('stroke', '#ffffff')
1283
- .style('stroke-width', 1.6)
1284
- .style('stroke-linecap', 'round')
1285
- .style('stroke-linejoin', 'round')
1286
- .style('opacity', function (itemData) { return itemData.hidden ? 0 : 1; });
1287
- item.selectAll('text')
1288
- .data(function (itemData) { return [itemData]; })
1289
- .join('text')
1290
- .attr('x', 16)
1291
- .attr('y', 4)
1292
- .style('fill', '#b6c4cf')
1293
- .style('font-size', '12px')
1294
- .style('text-decoration', function (itemData) { return itemData.hidden ? 'line-through' : 'none'; })
1295
- .text(function (itemData) { return itemData.name; });
1296
- if ((legend === null || legend === void 0 ? void 0 : legend.placement) === 'right') {
1297
- legendGroup.attr('transform', "translate(".concat(state.size.width - state.margin.right + itemGap, ", ").concat(state.margin.top, ")"));
1298
- }
1299
- else if ((legend === null || legend === void 0 ? void 0 : legend.placement) === 'bottom') {
1300
- legendGroup.attr('transform', "translate(".concat(state.margin.left, ", ").concat(state.size.height - 10, ")"));
1301
- }
1302
- else {
1303
- var hasSpecAreas = getSpecAreas(state).length > 0;
1304
- var hasTitle = Boolean((_c = (_b = state.config.title) === null || _b === void 0 ? void 0 : _b.text) === null || _c === void 0 ? void 0 : _c.trim());
1305
- var legendY = hasSpecAreas
1306
- ? (hasTitle ? Math.max(Math.min(state.margin.top - 38, 58), 44) : 20)
1307
- : hasTitle
1308
- ? Math.max(Math.min(state.margin.top - 30, 64), 54)
1309
- : 16;
1310
- legendGroup.attr('transform', "translate(".concat(state.margin.left, ", ").concat(legendY, ")"));
1311
- }
1312
- };
1313
- var getTooltipElement = function (state) { return state.container
1314
- .selectAll('div.kchart-tooltip')
1315
- .data([undefined])
1316
- .join('div')
1317
- .attr('class', 'kchart-tooltip')
1318
- .style('position', 'absolute')
1319
- .style('z-index', 6)
1320
- .style('pointer-events', 'none')
1321
- .style('opacity', 0)
1322
- .style('padding', '8px 10px')
1323
- .style('border', '1px solid rgba(233, 242, 247, 0.18)')
1324
- .style('border-radius', '8px')
1325
- .style('background', 'rgba(10, 14, 20, 0.95)')
1326
- .style('box-shadow', '0 14px 30px rgba(0, 0, 0, 0.32)')
1327
- .style('color', '#edf3f8')
1328
- .style('font-size', '12px')
1329
- .style('line-height', '1.45'); };
1330
- var formatTooltip = function (state, data, series, color) {
1331
- var _a, _b;
1332
- if ((_a = state.config.tooltip) === null || _a === void 0 ? void 0 : _a.formatter) {
1333
- return state.config.tooltip.formatter({
1334
- data: data,
1335
- series: series,
1336
- x: series.xField ? data[series.xField] : undefined,
1337
- y: series.yField ? data[series.yField] : undefined,
1338
- color: color
1339
- });
1340
- }
1341
- var label = (_b = series.displayName) !== null && _b !== void 0 ? _b : series.selector;
1342
- var xValue = series.xField ? data[series.xField] : '';
1343
- var yValue = series.yField ? data[series.yField] : '';
1344
- return "<strong style=\"color:".concat(color, "\">").concat(label, "</strong><br/>x: ").concat(xValue, "<br/>y: ").concat(yValue);
1345
- };
1346
- var getCursorGuide = function (state) {
1347
- var _a, _b, _c;
1348
- var option = (_a = state.config.options) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.type === 'cursor-line' && item.visible !== false; });
1349
- if (option) {
1350
- return __assign({ visible: (_b = option.visible) !== null && _b !== void 0 ? _b : true }, option.config);
1351
- }
1352
- return (_c = state.config.cursorGuide) !== null && _c !== void 0 ? _c : state.config.guideLine;
1353
- };
1354
- var resolveZoomedAxes = function (state, transform) {
1355
- var _a, _b;
1356
- var direction = (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.direction) !== null && _b !== void 0 ? _b : 'x';
1357
- var baseScales = resolveScales(state.data, state.baseAxes, state.plotSize);
1358
- var xDomain;
1359
- var yDomain;
1360
- var axes = state.baseAxes.map(function (axis) {
1361
- var horizontal = isHorizontalAxis(axis);
1362
- var shouldZoom = isZoomScaleSupported(axis)
1363
- && ((horizontal && (direction === 'x' || direction === 'xy'))
1364
- || (!horizontal && (direction === 'y' || direction === 'xy')));
1365
- if (!shouldZoom) {
1366
- return __assign(__assign({}, axis), { domain: cloneAxisDomain(axis.domain) });
1367
- }
1368
- var scale = baseScales.find(function (item) { return item.field === axis.field && item.placement === axis.placement; });
1369
- if (!scale) {
1370
- return __assign(__assign({}, axis), { domain: cloneAxisDomain(axis.domain) });
1371
- }
1372
- var zoomedScale = horizontal
1373
- ? transform.rescaleX(scale.scale)
1374
- : transform.rescaleY(scale.scale);
1375
- var domain = zoomedScale.domain().map(function (value) { return axis.type === 'time'
1376
- ? value instanceof Date ? value : new Date(value)
1377
- : Number(value); });
1378
- if (horizontal) {
1379
- xDomain = domain;
1380
- }
1381
- else {
1382
- yDomain = domain;
1383
- }
1384
- return __assign(__assign({}, axis), { domain: domain });
1385
- });
1386
- return {
1387
- axes: axes,
1388
- xDomain: xDomain,
1389
- yDomain: yDomain,
1390
- transform: transform
1391
- };
1392
- };
1393
- var resetZoom = function (state) {
1394
- var _a, _b;
1395
- state.zoomTransform = d3_zoom_1.zoomIdentity;
1396
- state.axes = cloneAxes(state.initialAxes);
1397
- state.baseAxes = cloneAxes(state.initialAxes);
1398
- state.config = __assign(__assign({}, state.config), { axes: state.axes });
1399
- (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.onZoom) === null || _b === void 0 ? void 0 : _b.call(_a, {
1400
- axes: state.axes,
1401
- transform: state.zoomTransform
1402
- });
1403
- render(state);
1404
- };
1405
- var drawZoomSelection = function (state) {
1406
- var selection = state.zoomSelection;
1407
- var rect = state.layers.overlayGroup.selectAll('rect.kchart-zoom-selection')
1408
- .data((selection === null || selection === void 0 ? void 0 : selection.active) ? [undefined] : [])
1409
- .join('rect')
1410
- .attr('class', 'kchart-zoom-selection')
1411
- .style('fill', 'rgba(93, 184, 255, 0.16)')
1412
- .style('stroke', 'rgba(148, 214, 255, 0.9)')
1413
- .style('stroke-width', 1)
1414
- .style('stroke-dasharray', '4 4')
1415
- .style('pointer-events', 'none');
1416
- if (!(selection === null || selection === void 0 ? void 0 : selection.active)) {
1417
- return;
1418
- }
1419
- rect
1420
- .attr('x', Math.min(selection.startX, selection.currentX))
1421
- .attr('y', Math.min(selection.startY, selection.currentY))
1422
- .attr('width', Math.abs(selection.currentX - selection.startX))
1423
- .attr('height', Math.abs(selection.currentY - selection.startY));
1424
- };
1425
- var resolveSelectionZoomAxes = function (state, selection) {
1426
- var _a, _b;
1427
- var direction = (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.direction) !== null && _b !== void 0 ? _b : 'x';
1428
- var minX = Math.max(0, Math.min(selection.startX, selection.currentX));
1429
- var maxX = Math.min(state.plotSize.width, Math.max(selection.startX, selection.currentX));
1430
- var minY = Math.max(0, Math.min(selection.startY, selection.currentY));
1431
- var maxY = Math.min(state.plotSize.height, Math.max(selection.startY, selection.currentY));
1432
- var width = maxX - minX;
1433
- var height = maxY - minY;
1434
- var shouldZoomX = direction === 'x' || direction === 'xy';
1435
- var shouldZoomY = direction === 'y' || direction === 'xy';
1436
- if ((shouldZoomX && width < 8) || (shouldZoomY && height < 8)) {
1437
- return null;
1438
- }
1439
- var xDomain;
1440
- var yDomain;
1441
- var axes = state.axes.map(function (axis) {
1442
- var horizontal = isHorizontalAxis(axis);
1443
- var shouldZoom = isZoomScaleSupported(axis)
1444
- && ((horizontal && shouldZoomX) || (!horizontal && shouldZoomY));
1445
- if (!shouldZoom) {
1446
- return __assign(__assign({}, axis), { domain: cloneAxisDomain(axis.domain) });
1447
- }
1448
- var scale = state.scales.find(function (item) { return item.field === axis.field && item.placement === axis.placement; });
1449
- if (!scale || typeof scale.scale.invert !== 'function') {
1450
- return __assign(__assign({}, axis), { domain: cloneAxisDomain(axis.domain) });
1451
- }
1452
- var rawDomain = horizontal
1453
- ? [scale.scale.invert(minX), scale.scale.invert(maxX)]
1454
- : [scale.scale.invert(maxY), scale.scale.invert(minY)];
1455
- var domain = rawDomain.map(function (value) { return axis.type === 'time'
1456
- ? value instanceof Date ? value : new Date(value)
1457
- : Number(value); });
1458
- if (horizontal) {
1459
- xDomain = domain;
1460
- }
1461
- else {
1462
- yDomain = domain;
1463
- }
1464
- return __assign(__assign({}, axis), { domain: domain });
1465
- });
1466
- return {
1467
- axes: axes,
1468
- xDomain: xDomain,
1469
- yDomain: yDomain,
1470
- transform: d3_zoom_1.zoomIdentity
1471
- };
1472
- };
1473
- var applySelectionZoom = function (state) {
1474
- var _a, _b;
1475
- var selection = state.zoomSelection;
1476
- if (!(selection === null || selection === void 0 ? void 0 : selection.active)) {
1477
- return;
1478
- }
1479
- var nextZoom = resolveSelectionZoomAxes(state, selection);
1480
- state.zoomSelection = undefined;
1481
- drawZoomSelection(state);
1482
- if (!nextZoom) {
1483
- return;
1484
- }
1485
- state.zoomTransform = d3_zoom_1.zoomIdentity;
1486
- state.axes = nextZoom.axes;
1487
- state.baseAxes = cloneAxes(nextZoom.axes);
1488
- state.config = __assign(__assign({}, state.config), { axes: state.axes });
1489
- (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.onZoom) === null || _b === void 0 ? void 0 : _b.call(_a, nextZoom);
1490
- render(state);
1491
- };
1492
- var renderZoom = function (state) {
1493
- var _a, _b, _c;
1494
- var overlay = state.layers.overlayGroup.select('rect.kchart-tooltip-overlay');
1495
- var overlayNode = overlay.node();
1496
- if (!overlayNode) {
1497
- return;
1498
- }
1499
- var mode = (_b = (_a = state.config.zoom) === null || _a === void 0 ? void 0 : _a.mode) !== null && _b !== void 0 ? _b : 'wheel';
1500
- var zoomConfig = state.config.zoom;
1501
- var inputOptionsConfigured = hasZoomInputOptions(zoomConfig);
1502
- var selectionEnabled = isZoomEnabled(state) && (mode === 'select' || mode === 'both');
1503
- var wheelEnabled = isZoomEnabled(state)
1504
- && (mode === 'wheel' || mode === 'both')
1505
- && isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.wheelZoom, true);
1506
- var panEnabled = isZoomEnabled(state) && mode === 'wheel';
1507
- var desktopPanEnabled = panEnabled && isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.wheelZoom, true);
1508
- var gestureEnabled = isZoomEnabled(state)
1509
- && isZoomOptionEnabled(zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.gestureZoom, !inputOptionsConfigured && panEnabled);
1510
- overlay
1511
- .style('cursor', selectionEnabled ? 'crosshair' : isZoomEnabled(state) ? 'grab' : null)
1512
- .on('dblclick.kchart-zoom-reset', null)
1513
- .on('mousedown.kchart-select-zoom', null)
1514
- .on('mousemove.kchart-select-zoom', null)
1515
- .on('mouseup.kchart-select-zoom', null)
1516
- .on('mouseleave.kchart-select-zoom', null);
1517
- if (!isZoomEnabled(state)) {
1518
- overlay.on('.zoom', null);
1519
- state.layers.overlayGroup.selectAll('rect.kchart-zoom-selection').remove();
1520
- return;
1521
- }
1522
- if (wheelEnabled || desktopPanEnabled || gestureEnabled) {
1523
- var wheelSensitivity_1 = getZoomWheelSensitivity(zoomConfig);
1524
- var zoomBehavior = (0, d3_zoom_1.zoom)()
1525
- .scaleExtent((_c = zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.scaleExtent) !== null && _c !== void 0 ? _c : [1, 40])
1526
- .extent([[0, 0], [state.plotSize.width, state.plotSize.height]])
1527
- .translateExtent([[0, 0], [state.plotSize.width, state.plotSize.height]])
1528
- .touchable(function () { return gestureEnabled; })
1529
- .wheelDelta(function (event) { return -event.deltaY
1530
- * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002)
1531
- * (event.ctrlKey ? 10 : 1)
1532
- * wheelSensitivity_1; })
1533
- .filter(function (event) {
1534
- if (event.type === 'wheel') {
1535
- return wheelEnabled && (!inputOptionsConfigured
1536
- || matchesZoomInputDevice(getZoomWheelDevice(zoomConfig), event));
1537
- }
1538
- if (event.type === 'mousedown') {
1539
- return desktopPanEnabled && (!inputOptionsConfigured
1540
- || matchesZoomInputDevice(getZoomWheelDevice(zoomConfig), event));
1541
- }
1542
- if (event.type === 'touchstart' || event.type === 'touchmove') {
1543
- var touchCount = getEventTouchCount(event);
1544
- return gestureEnabled
1545
- && touchCount >= getZoomGestureMinTouches(zoomConfig)
1546
- && (!inputOptionsConfigured
1547
- || matchesZoomInputDevice(getZoomGestureDevice(zoomConfig), event));
1548
- }
1549
- return false;
1550
- })
1551
- .on('zoom', function (event) {
1552
- var _a;
1553
- state.zoomTransform = event.transform;
1554
- var nextZoom = resolveZoomedAxes(state, event.transform);
1555
- state.axes = nextZoom.axes;
1556
- state.config = __assign(__assign({}, state.config), { axes: state.axes });
1557
- (_a = zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.onZoom) === null || _a === void 0 ? void 0 : _a.call(zoomConfig, nextZoom);
1558
- render(state);
1559
- });
1560
- overlay.call(zoomBehavior);
1561
- overlayNode.__zoom = state.zoomTransform;
1562
- }
1563
- else {
1564
- overlay.on('.zoom', null);
1565
- }
1566
- if (selectionEnabled) {
1567
- overlay
1568
- .on('mousedown.kchart-select-zoom', function (event) {
1569
- if (event.button !== 0) {
1570
- return;
1571
- }
1572
- event.preventDefault();
1573
- event.stopPropagation();
1574
- var _a = (0, d3_selection_1.pointer)(event, overlayNode), mouseX = _a[0], mouseY = _a[1];
1575
- state.zoomSelection = {
1576
- active: true,
1577
- startX: mouseX,
1578
- startY: mouseY,
1579
- currentX: mouseX,
1580
- currentY: mouseY
1581
- };
1582
- drawZoomSelection(state);
1583
- })
1584
- .on('mousemove.kchart-select-zoom', function (event) {
1585
- var _a;
1586
- if (!((_a = state.zoomSelection) === null || _a === void 0 ? void 0 : _a.active)) {
1587
- return;
1588
- }
1589
- var _b = (0, d3_selection_1.pointer)(event, overlayNode), mouseX = _b[0], mouseY = _b[1];
1590
- state.zoomSelection.currentX = mouseX;
1591
- state.zoomSelection.currentY = mouseY;
1592
- drawZoomSelection(state);
1593
- })
1594
- .on('mouseup.kchart-select-zoom', function (event) {
1595
- var _a;
1596
- if (!((_a = state.zoomSelection) === null || _a === void 0 ? void 0 : _a.active)) {
1597
- return;
1598
- }
1599
- var _b = (0, d3_selection_1.pointer)(event, overlayNode), mouseX = _b[0], mouseY = _b[1];
1600
- state.zoomSelection.currentX = mouseX;
1601
- state.zoomSelection.currentY = mouseY;
1602
- applySelectionZoom(state);
1603
- })
1604
- .on('mouseleave.kchart-select-zoom', function () {
1605
- var _a;
1606
- if (!((_a = state.zoomSelection) === null || _a === void 0 ? void 0 : _a.active)) {
1607
- return;
1608
- }
1609
- state.zoomSelection = undefined;
1610
- drawZoomSelection(state);
1611
- });
1612
- }
1613
- if ((zoomConfig === null || zoomConfig === void 0 ? void 0 : zoomConfig.resetOnDoubleClick) !== false) {
1614
- overlay.on('dblclick.kchart-zoom-reset', function () { return resetZoom(state); });
1615
- }
1616
- };
1617
- var renderTooltip = function (state) {
1618
- var _a, _b;
1619
- var tooltipEnabled = ((_a = state.config.tooltip) === null || _a === void 0 ? void 0 : _a.visible) === true;
1620
- var cursorGuide = getCursorGuide(state);
1621
- var guideEnabled = (cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.visible) === true;
1622
- var enabled = tooltipEnabled || guideEnabled || isZoomEnabled(state);
1623
- var overlay = state.layers.overlayGroup.selectAll('rect.kchart-tooltip-overlay')
1624
- .data(enabled ? [undefined] : [])
1625
- .join('rect')
1626
- .attr('class', 'kchart-tooltip-overlay')
1627
- .attr('width', state.plotSize.width)
1628
- .attr('height', state.plotSize.height)
1629
- .style('fill', 'transparent')
1630
- .style('pointer-events', 'all');
1631
- var guideLine = state.layers.overlayGroup.selectAll('line.kchart-guide-line')
1632
- .data(guideEnabled ? [undefined] : [])
1633
- .join('line')
1634
- .attr('class', 'kchart-guide-line')
1635
- .attr('y1', 0)
1636
- .attr('y2', state.plotSize.height)
1637
- .style('stroke', (_b = cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.color) !== null && _b !== void 0 ? _b : 'rgba(248, 251, 255, 0.72)')
1638
- .style('stroke-width', 1)
1639
- .style('stroke-dasharray', '3 5')
1640
- .style('opacity', 0)
1641
- .style('pointer-events', 'none');
1642
- var guideMarkerGroup = state.layers.overlayGroup.selectAll('g.kchart-guide-markers')
1643
- .data(guideEnabled ? [undefined] : [])
1644
- .join('g')
1645
- .attr('class', 'kchart-guide-markers')
1646
- .style('opacity', 0)
1647
- .style('pointer-events', 'none');
1648
- var guideAxisLabel = state.layers.overlayGroup.selectAll('g.kchart-guide-axis-label')
1649
- .data(guideEnabled ? [undefined] : [])
1650
- .join('g')
1651
- .attr('class', 'kchart-guide-axis-label')
1652
- .style('opacity', 0)
1653
- .style('pointer-events', 'none');
1654
- var tooltip = getTooltipElement(state);
1655
- if (!enabled) {
1656
- tooltip.style('opacity', 0);
1657
- return;
1658
- }
1659
- overlay
1660
- .on('mousemove', function (event) {
1661
- var _a, _b;
1662
- var target = overlay.node();
1663
- if (!target) {
1664
- return;
1665
- }
1666
- var _c = (0, d3_selection_1.pointer)(event, target), mouseX = _c[0], mouseY = _c[1];
1667
- var nearest = null;
1668
- var guideMarkers = [];
1669
- state.series.forEach(function (series, index) {
1670
- var _a, _b, _c, _d, _e;
1671
- if (state.hiddenSeries.has(series.selector)) {
1672
- return;
1673
- }
1674
- var color = (_a = series.color) !== null && _a !== void 0 ? _a : state.colors[index % state.colors.length];
1675
- var customTooltip = (_b = series.tooltip) === null || _b === void 0 ? void 0 : _b.call(series, __assign(__assign({}, state.layers), { data: state.data, scales: state.scales, size: state.size, plotSize: state.plotSize, margin: state.margin, color: color, seriesIndex: index, mouseX: mouseX, mouseY: mouseY }));
1676
- if (customTooltip) {
1677
- var distance = (_c = customTooltip.distance) !== null && _c !== void 0 ? _c : Math.hypot(mouseX - customTooltip.x, mouseY - customTooltip.y);
1678
- if (!nearest || distance < nearest.distance) {
1679
- nearest = {
1680
- data: customTooltip.data,
1681
- series: series,
1682
- color: (_d = customTooltip.color) !== null && _d !== void 0 ? _d : color,
1683
- distance: distance,
1684
- x: customTooltip.x,
1685
- y: customTooltip.y,
1686
- html: customTooltip.html
1687
- };
1688
- }
1689
- }
1690
- if (series.tooltip) {
1691
- return;
1692
- }
1693
- if (!series.xField || !series.yField) {
1694
- return;
1695
- }
1696
- var xScale = state.scales.find(function (scale) { return scale.field === series.xField; });
1697
- var yScale = (_e = state.scales.find(function (scale) { return scale.field === series.yField; })) !== null && _e !== void 0 ? _e : state.scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; });
1698
- if (!xScale || !yScale) {
1699
- return;
1700
- }
1701
- state.data.forEach(function (datum) {
1702
- var _a;
1703
- var x = resolveScalePosition(xScale, datum[series.xField]);
1704
- var y = resolveScalePosition(yScale, datum[series.yField]);
1705
- var distance = Math.hypot(mouseX - x, mouseY - y);
1706
- var guideDistance = Math.abs(mouseX - x);
1707
- if (!nearest || distance < nearest.distance) {
1708
- nearest = {
1709
- data: datum,
1710
- series: series,
1711
- color: color,
1712
- distance: distance,
1713
- x: x,
1714
- y: y
1715
- };
1716
- }
1717
- if (guideEnabled) {
1718
- var label_1 = (_a = series.displayName) !== null && _a !== void 0 ? _a : series.selector;
1719
- var currentMarker = guideMarkers.find(function (marker) { return marker.label === label_1; });
1720
- if (!currentMarker || guideDistance < Math.abs(mouseX - currentMarker.x)) {
1721
- if (currentMarker) {
1722
- currentMarker.x = x;
1723
- currentMarker.y = y;
1724
- currentMarker.value = datum[series.yField];
1725
- currentMarker.xValue = datum[series.xField];
1726
- }
1727
- else {
1728
- guideMarkers.push({
1729
- x: x,
1730
- y: y,
1731
- color: color,
1732
- label: label_1,
1733
- value: datum[series.yField],
1734
- xValue: datum[series.xField]
1735
- });
1736
- }
1737
- }
1738
- }
1739
- });
1740
- });
1741
- if (guideEnabled && guideMarkers.length) {
1742
- var guideX = guideMarkers[0].x;
1743
- var arrangedGuideMarkers = guideMarkers
1744
- .slice()
1745
- .sort(function (a, b) { return a.y - b.y; })
1746
- .map(function (item, index, sorted) {
1747
- var previous = index > 0 ? sorted[index - 1] : undefined;
1748
- var labelY = Math.max(item.y, (previous === null || previous === void 0 ? void 0 : previous.labelY) !== undefined ? previous.labelY + 20 : item.y);
1749
- return __assign(__assign({}, item), { labelY: Math.min(labelY, state.plotSize.height - 12) });
1750
- });
1751
- guideLine
1752
- .attr('x1', guideX)
1753
- .attr('x2', guideX)
1754
- .style('opacity', 1);
1755
- var xFormat = cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.xFormat;
1756
- var xLabel = xFormat
1757
- ? xFormat(guideMarkers[0].xValue)
1758
- : String(guideMarkers[0].xValue);
1759
- var xLabelWidth = Math.max(44, xLabel.length * 7 + 16);
1760
- guideAxisLabel
1761
- .attr('transform', "translate(".concat(guideX, ", ").concat(state.plotSize.height + 18, ")"))
1762
- .style('opacity', 1);
1763
- guideAxisLabel.selectAll('rect')
1764
- .data([xLabel])
1765
- .join('rect')
1766
- .attr('x', -xLabelWidth / 2)
1767
- .attr('y', -12)
1768
- .attr('width', xLabelWidth)
1769
- .attr('height', 18)
1770
- .attr('rx', 5)
1771
- .style('fill', 'rgba(10, 14, 20, 0.9)')
1772
- .style('stroke', 'rgba(248, 251, 255, 0.24)')
1773
- .style('stroke-width', 1);
1774
- guideAxisLabel.selectAll('text')
1775
- .data([xLabel])
1776
- .join('text')
1777
- .attr('x', 0)
1778
- .attr('y', 1)
1779
- .style('fill', '#edf3f8')
1780
- .style('font-size', '11px')
1781
- .style('font-weight', 700)
1782
- .style('text-anchor', 'middle')
1783
- .text(function (item) { return item; });
1784
- var marker = guideMarkerGroup.selectAll('g.kchart-guide-marker')
1785
- .data(arrangedGuideMarkers)
1786
- .join('g')
1787
- .attr('class', 'kchart-guide-marker')
1788
- .attr('transform', function (item) { return "translate(".concat(item.x, ", ").concat(item.y, ")"); });
1789
- marker.selectAll('circle')
1790
- .data(function (item) { return [item]; })
1791
- .join('circle')
1792
- .attr('r', (_a = cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.markerRadius) !== null && _a !== void 0 ? _a : 4)
1793
- .style('fill', function (item) { return item.color; })
1794
- .style('stroke', '#ffffff')
1795
- .style('stroke-width', 1.5);
1796
- marker.selectAll('rect')
1797
- .data(function (item) { return [item]; })
1798
- .join('rect')
1799
- .attr('x', 8)
1800
- .attr('y', function (item) { return item.labelY - item.y - 10; })
1801
- .attr('width', function (item) {
1802
- var valueFormat = cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.valueFormat;
1803
- var value = valueFormat ? valueFormat(item.value) : Number(item.value).toFixed(1);
1804
- return Math.max(54, "".concat(item.label, ": ").concat(value).length * 6.3 + 12);
1805
- })
1806
- .attr('height', 18)
1807
- .attr('rx', 5)
1808
- .style('fill', 'rgba(10, 14, 20, 0.86)')
1809
- .style('stroke', function (item) { return item.color; })
1810
- .style('stroke-width', 1);
1811
- marker.selectAll('text')
1812
- .data(function (item) { return [item]; })
1813
- .join('text')
1814
- .attr('x', 14)
1815
- .attr('y', function (item) { return item.labelY - item.y + 4; })
1816
- .style('fill', '#edf3f8')
1817
- .style('font-size', '11px')
1818
- .style('font-weight', 700)
1819
- .text(function (item) {
1820
- var valueFormat = cursorGuide === null || cursorGuide === void 0 ? void 0 : cursorGuide.valueFormat;
1821
- var value = valueFormat ? valueFormat(item.value) : Number(item.value).toFixed(1);
1822
- return "".concat(item.label, ": ").concat(value);
1823
- });
1824
- guideMarkerGroup.style('opacity', 1);
1825
- }
1826
- else {
1827
- guideLine.style('opacity', 0);
1828
- guideMarkerGroup.style('opacity', 0);
1829
- guideAxisLabel.style('opacity', 0);
1830
- }
1831
- if (!tooltipEnabled) {
1832
- tooltip.style('opacity', 0);
1833
- return;
1834
- }
1835
- if (!nearest || nearest.distance > 36) {
1836
- tooltip.style('opacity', 0);
1837
- return;
1838
- }
1839
- tooltip
1840
- .html((_b = nearest.html) !== null && _b !== void 0 ? _b : formatTooltip(state, nearest.data, nearest.series, nearest.color))
1841
- .style('left', "".concat(state.margin.left + nearest.x + 12, "px"))
1842
- .style('top', "".concat(state.margin.top + nearest.y + 12, "px"))
1843
- .style('opacity', 1);
1844
- })
1845
- .on('mouseleave', function () {
1846
- state.series.forEach(function (series) {
1847
- var _a;
1848
- if (!state.hiddenSeries.has(series.selector)) {
1849
- (_a = series.clearTooltip) === null || _a === void 0 ? void 0 : _a.call(series, state.layers);
1850
- }
1851
- });
1852
- tooltip.style('opacity', 0);
1853
- guideLine.style('opacity', 0);
1854
- guideMarkerGroup.style('opacity', 0);
1855
- guideAxisLabel.style('opacity', 0);
1856
- });
1857
- };
1858
- var renderSeries = function (state) {
1859
- state.layers.svg
1860
- .attr('width', state.size.width)
1861
- .attr('height', state.size.height);
1862
- state.layers.plotGroup.attr('transform', "translate(".concat(state.margin.left, ", ").concat(state.margin.top, ")"));
1863
- state.layers.seriesGroup.selectAll('*').remove();
1864
- state.series.forEach(function (series, index) {
1865
- var _a, _b, _c;
1866
- if (state.hiddenSeries.has(series.selector)) {
1867
- (_a = series.destroy) === null || _a === void 0 ? void 0 : _a.call(series, state.layers);
1868
- return;
1869
- }
1870
- var xScale = series.xField
1871
- ? state.scales.find(function (scale) { return scale.field === series.xField; })
1872
- : state.scales.find(function (scale) { return scale.placement === 'bottom' || scale.placement === 'top'; });
1873
- var yScale = series.yField
1874
- ? (_b = state.scales.find(function (scale) { return scale.field === series.yField; })) !== null && _b !== void 0 ? _b : state.scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; })
1875
- : state.scales.find(function (scale) { return scale.placement === 'left' || scale.placement === 'right'; });
1876
- var seriesGroup = state.layers.seriesGroup.selectAll("g.".concat(series.selector, "-group"))
1877
- .data([series])
1878
- .join('g')
1879
- .attr('class', "".concat(series.selector, "-group"));
1880
- var renderData = resolveSeriesRenderData(state, series, xScale, yScale);
1881
- series.render(__assign(__assign({}, state.layers), { group: seriesGroup, seriesGroup: seriesGroup, data: renderData, scales: state.scales, xScale: xScale, yScale: yScale, size: state.size, plotSize: state.plotSize, margin: state.margin, color: (_c = series.color) !== null && _c !== void 0 ? _c : state.colors[index % state.colors.length], seriesIndex: index }));
1882
- });
1883
- };
1884
- var render = function (state) {
1885
- var baseMargin = __assign(__assign({}, defaultMargin), state.config.margin);
1886
- var sizes = resolveSize(state.container, state.config, baseMargin);
1887
- state.size = sizes.size;
1888
- state.margin = sizes.margin;
1889
- state.plotSize = sizes.plotSize;
1890
- state.scales = resolveScales(state.data, state.axes, state.plotSize);
1891
- renderTitle(state);
1892
- renderAxes(state);
1893
- renderGrid(state);
1894
- renderSpecAreas(state);
1895
- renderGuideLines(state);
1896
- renderSeries(state);
1897
- renderLegend(state);
1898
- renderTooltip(state);
1899
- renderZoom(state);
1900
- };
1901
- var createCustomSeries = function (series) { return series; };
1902
- exports.createCustomSeries = createCustomSeries;
1903
- var createSpecAreaOption = function (areas, config) {
1904
- if (config === void 0) { config = {}; }
1905
- return (__assign(__assign({ type: 'spec-area' }, config), { areas: areas }));
1906
- };
1907
- exports.createSpecAreaOption = createSpecAreaOption;
1908
- var createGuideLineOption = function (config) { return (__assign({ type: 'guide-line' }, config)); };
1909
- exports.createGuideLineOption = createGuideLineOption;
1910
- var createCursorLineOption = function (config) {
1911
- var _a;
1912
- if (config === void 0) { config = {}; }
1913
- return ({
1914
- type: 'cursor-line',
1915
- visible: (_a = config.visible) !== null && _a !== void 0 ? _a : true,
1916
- config: config
1917
- });
1918
- };
1919
- exports.createCursorLineOption = createCursorLineOption;
1920
- var createLineSeries = function (configuration) { return (0, exports.createCustomSeries)({
1921
- selector: configuration.selector,
1922
- displayName: configuration.displayName,
1923
- xField: configuration.xField,
1924
- yField: configuration.yField,
1925
- color: configuration.color,
1926
- downsample: configuration.downsample,
1927
- render: function (_a) {
1928
- var _b, _c, _d, _e, _f, _g;
1929
- var group = _a.group, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color;
1930
- if (!xScale || !yScale) {
1931
- return;
1932
- }
1933
- var resolveX = function (point) { return resolveScalePosition(xScale, point[configuration.xField]); };
1934
- var resolveY = function (point) { return resolveScalePosition(yScale, point[configuration.yField]); };
1935
- var line = (0, d3_shape_1.line)()
1936
- .defined(function (point) { return point[configuration.xField] !== undefined && point[configuration.yField] !== undefined; })
1937
- .x(resolveX)
1938
- .y(resolveY);
1939
- if (configuration.curve) {
1940
- line.curve(d3_shape_1.curveMonotoneX);
1941
- }
1942
- group.selectAll(".".concat(configuration.selector))
1943
- .data([data])
1944
- .join('path')
1945
- .attr('class', configuration.selector)
1946
- .attr('d', line)
1947
- .style('fill', 'none')
1948
- .style('stroke', (_b = configuration.color) !== null && _b !== void 0 ? _b : color)
1949
- .style('stroke-width', (_c = configuration.strokeWidth) !== null && _c !== void 0 ? _c : 2)
1950
- .style('stroke-linecap', 'round')
1951
- .style('stroke-linejoin', 'round');
1952
- if (!configuration.dot) {
1953
- group.selectAll(".".concat(configuration.selector, "-dot")).remove();
1954
- return;
1955
- }
1956
- var dotOption = typeof configuration.dot === 'object' ? configuration.dot : {};
1957
- group.selectAll(".".concat(configuration.selector, "-dot"))
1958
- .data(data)
1959
- .join('circle')
1960
- .attr('class', "".concat(configuration.selector, "-dot"))
1961
- .attr('cx', resolveX)
1962
- .attr('cy', resolveY)
1963
- .attr('r', (_d = dotOption.radius) !== null && _d !== void 0 ? _d : 3)
1964
- .style('fill', (_f = (_e = dotOption.fill) !== null && _e !== void 0 ? _e : configuration.color) !== null && _f !== void 0 ? _f : color)
1965
- .style('stroke', (_g = dotOption.stroke) !== null && _g !== void 0 ? _g : '#ffffff')
1966
- .style('stroke-width', 1);
1967
- }
1968
- }); };
1969
- exports.createLineSeries = createLineSeries;
1970
- var createCanvasLineSeries = function (configuration) { return (0, exports.createCustomSeries)({
1971
- selector: configuration.selector,
1972
- displayName: configuration.displayName,
1973
- xField: configuration.xField,
1974
- yField: configuration.yField,
1975
- color: configuration.color,
1976
- downsample: configuration.downsample,
1977
- render: function (_a) {
1978
- var _b, _c, _d, _e, _f;
1979
- var getCanvas = _a.getCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color;
1980
- if (!xScale || !yScale) {
1981
- return;
1982
- }
1983
- var canvas = getCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
1984
- var canvasSize = resolveCanvasPixelSize(canvas);
1985
- var points = resolveLinePoints(data, xScale, yScale, configuration.xField, configuration.yField);
1986
- if (renderLineWithWorker(canvas, '2d', configuration.asyncRender, {
1987
- width: canvasSize.width,
1988
- height: canvasSize.height,
1989
- color: (_c = configuration.color) !== null && _c !== void 0 ? _c : color,
1990
- lineWidth: (_d = configuration.lineWidth) !== null && _d !== void 0 ? _d : 2,
1991
- points: points
1992
- })) {
1993
- return;
1994
- }
1995
- var context = canvas.getContext('2d');
1996
- if (!context) {
1997
- return;
1998
- }
1999
- var hasPoint = false;
2000
- context.clearRect(0, 0, canvas.width, canvas.height);
2001
- context.beginPath();
2002
- context.lineCap = 'round';
2003
- context.lineJoin = 'round';
2004
- context.lineWidth = (_e = configuration.lineWidth) !== null && _e !== void 0 ? _e : 2;
2005
- context.strokeStyle = (_f = configuration.color) !== null && _f !== void 0 ? _f : color;
2006
- data.forEach(function (point) {
2007
- if (point[configuration.xField] === undefined || point[configuration.yField] === undefined) {
2008
- return;
2009
- }
2010
- var x = resolveScalePosition(xScale, point[configuration.xField]);
2011
- var y = resolveScalePosition(yScale, point[configuration.yField]);
2012
- if (!hasPoint) {
2013
- context.moveTo(x, y);
2014
- hasPoint = true;
2015
- return;
2016
- }
2017
- context.lineTo(x, y);
2018
- });
2019
- context.stroke();
2020
- },
2021
- destroy: function (_a) {
2022
- var _b;
2023
- var svg = _a.svg;
2024
- destroyCanvasByClass(svg, "kchart-2d-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
2025
- }
2026
- }); };
2027
- exports.createCanvasLineSeries = createCanvasLineSeries;
2028
- var createCanvasPointSeries = function (configuration) { return (0, exports.createCustomSeries)({
2029
- selector: configuration.selector,
2030
- displayName: configuration.displayName,
2031
- xField: configuration.xField,
2032
- yField: configuration.yField,
2033
- color: configuration.color,
2034
- render: function (_a) {
2035
- var _b, _c, _d, _e, _f;
2036
- var getCanvas = _a.getCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color;
2037
- if (!xScale || !yScale) {
2038
- return;
2039
- }
2040
- var canvas = getCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
2041
- var context = canvas.getContext('2d');
2042
- if (!context) {
2043
- return;
2044
- }
2045
- context.clearRect(0, 0, canvas.width, canvas.height);
2046
- context.fillStyle = (_d = (_c = configuration.fill) !== null && _c !== void 0 ? _c : configuration.color) !== null && _d !== void 0 ? _d : color;
2047
- context.strokeStyle = (_e = configuration.stroke) !== null && _e !== void 0 ? _e : 'rgba(255, 255, 255, 0.78)';
2048
- context.lineWidth = (_f = configuration.strokeWidth) !== null && _f !== void 0 ? _f : 1.5;
2049
- data.forEach(function (point) {
2050
- var _a;
2051
- if (point[configuration.xField] === undefined || point[configuration.yField] === undefined) {
2052
- return;
2053
- }
2054
- var radius = typeof configuration.radius === 'function'
2055
- ? configuration.radius(point)
2056
- : (_a = configuration.radius) !== null && _a !== void 0 ? _a : 3;
2057
- context.beginPath();
2058
- context.arc(resolveScalePosition(xScale, point[configuration.xField]), resolveScalePosition(yScale, point[configuration.yField]), radius, 0, Math.PI * 2);
2059
- context.fill();
2060
- context.stroke();
2061
- });
2062
- },
2063
- destroy: function (_a) {
2064
- var _b;
2065
- var svg = _a.svg;
2066
- destroyCanvasByClass(svg, "kchart-2d-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
2067
- }
2068
- }); };
2069
- exports.createCanvasPointSeries = createCanvasPointSeries;
2070
- var createCanvasCandlestickSeries = function (configuration) { return (0, exports.createCustomSeries)({
2071
- selector: configuration.selector,
2072
- displayName: configuration.displayName,
2073
- xField: configuration.xField,
2074
- yField: configuration.closeField,
2075
- color: configuration.neutralColor,
2076
- render: function (_a) {
2077
- var _b, _c;
2078
- var getCanvas = _a.getCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color, plotSize = _a.plotSize;
2079
- if (!xScale || !yScale) {
2080
- return;
2081
- }
2082
- var canvas = getCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
2083
- var context = canvas.getContext('2d');
2084
- if (!context) {
2085
- return;
2086
- }
2087
- var candleWidth = resolveCanvasCandlestickWidth(data, xScale, configuration.xField, plotSize, configuration);
2088
- var halfWidth = candleWidth / 2;
2089
- context.clearRect(0, 0, canvas.width, canvas.height);
2090
- context.lineCap = 'round';
2091
- context.lineJoin = 'round';
2092
- context.lineWidth = (_c = configuration.strokeWidth) !== null && _c !== void 0 ? _c : 1.4;
2093
- data.forEach(function (point, index) {
2094
- var _a, _b;
2095
- var open = Number(point[configuration.openField]);
2096
- var high = Number(point[configuration.highField]);
2097
- var low = Number(point[configuration.lowField]);
2098
- var close = Number(point[configuration.closeField]);
2099
- if (![open, high, low, close].every(Number.isFinite) || point[configuration.xField] === undefined) {
2100
- return;
2101
- }
2102
- var x = resolveScalePosition(xScale, point[configuration.xField]);
2103
- var openY = resolveScalePosition(yScale, open);
2104
- var highY = resolveScalePosition(yScale, high);
2105
- var lowY = resolveScalePosition(yScale, low);
2106
- var closeY = resolveScalePosition(yScale, close);
2107
- if (![x, openY, highY, lowY, closeY].every(Number.isFinite)) {
2108
- return;
2109
- }
2110
- var candleColor = resolveCandlestickColor(point, data[index - 1], configuration, color);
2111
- var bodyTop = Math.min(openY, closeY);
2112
- var bodyHeight = Math.max(Math.abs(closeY - openY), 1);
2113
- context.strokeStyle = (_a = configuration.wickColor) !== null && _a !== void 0 ? _a : candleColor;
2114
- context.beginPath();
2115
- context.moveTo(x, highY);
2116
- context.lineTo(x, lowY);
2117
- context.stroke();
2118
- context.fillStyle = candleColor;
2119
- context.strokeStyle = (_b = configuration.borderColor) !== null && _b !== void 0 ? _b : candleColor;
2120
- context.beginPath();
2121
- context.rect(x - halfWidth, bodyTop, candleWidth, bodyHeight);
2122
- context.fill();
2123
- context.stroke();
2124
- });
2125
- },
2126
- tooltip: function (_a) {
2127
- var _b, _c, _d;
2128
- var data = _a.data, scales = _a.scales, mouseX = _a.mouseX, mouseY = _a.mouseY, color = _a.color, plotSize = _a.plotSize;
2129
- var xScale = scales.find(function (scale) { return scale.field === configuration.xField; });
2130
- 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'; });
2131
- if (!xScale || !yScale) {
2132
- return null;
2133
- }
2134
- var candleWidth = resolveCanvasCandlestickWidth(data, xScale, configuration.xField, plotSize, configuration);
2135
- var hitRadius = Math.max(candleWidth * 0.7, 14);
2136
- var nearest = null;
2137
- data.forEach(function (point, index) {
2138
- if (point[configuration.xField] === undefined || point[configuration.closeField] === undefined) {
2139
- return;
2140
- }
2141
- var x = resolveScalePosition(xScale, point[configuration.xField]);
2142
- var y = resolveScalePosition(yScale, point[configuration.closeField]);
2143
- var distance = Math.abs(mouseX - x);
2144
- if (!Number.isFinite(x) || !Number.isFinite(y) || distance > hitRadius) {
2145
- return;
2146
- }
2147
- var verticalDistance = Math.abs(mouseY - y);
2148
- var totalDistance = distance + verticalDistance * 0.08;
2149
- if (!nearest || totalDistance < nearest.distance) {
2150
- nearest = {
2151
- data: point,
2152
- previousData: data[index - 1],
2153
- x: x,
2154
- y: y,
2155
- distance: totalDistance
2156
- };
2157
- }
2158
- });
2159
- if (!nearest) {
2160
- return null;
2161
- }
2162
- var point = nearest.data;
2163
- var candleColor = resolveCandlestickColor(point, nearest.previousData, configuration, color);
2164
- var label = (_c = configuration.displayName) !== null && _c !== void 0 ? _c : configuration.selector;
2165
- var xValue = String(point[configuration.xField]);
2166
- var previousClose = configuration.previousCloseField
2167
- ? point[configuration.previousCloseField]
2168
- : (_d = nearest.previousData) === null || _d === void 0 ? void 0 : _d[configuration.closeField];
2169
- return {
2170
- data: point,
2171
- x: nearest.x,
2172
- y: nearest.y,
2173
- color: candleColor,
2174
- distance: nearest.distance,
2175
- html: [
2176
- "<strong style=\"color:".concat(candleColor, "\">").concat(label, "</strong>"),
2177
- "x: ".concat(xValue),
2178
- configuration.colorMode === 'previous-close'
2179
- ? "previous close: ".concat(formatCandlestickTooltipValue(previousClose))
2180
- : '',
2181
- "open: ".concat(formatCandlestickTooltipValue(point[configuration.openField])),
2182
- "high: ".concat(formatCandlestickTooltipValue(point[configuration.highField])),
2183
- "low: ".concat(formatCandlestickTooltipValue(point[configuration.lowField])),
2184
- "close: ".concat(formatCandlestickTooltipValue(point[configuration.closeField]))
2185
- ].filter(Boolean).join('<br/>')
2186
- };
2187
- },
2188
- destroy: function (_a) {
2189
- var _b;
2190
- var svg = _a.svg;
2191
- destroyCanvasByClass(svg, "kchart-2d-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
2192
- }
2193
- }); };
2194
- exports.createCanvasCandlestickSeries = createCanvasCandlestickSeries;
2195
- var createSvgGlobeSeries = function (configuration) {
2196
- var rotation = normalizeGlobeRotation(configuration.initialRotate);
2197
- var zoomLevel = 1;
2198
- var dragging = false;
2199
- var dragStart = [0, 0];
2200
- var rotationStart = __spreadArray([], rotation, true);
2201
- var activePointers = new Map();
2202
- var pinchStartDistance = 0;
2203
- var pinchStartZoom = 1;
2204
- var viewMode = 'globe';
2205
- var focusedPoint;
2206
- var drilldownRestoreState;
2207
- var warpEffect;
2208
- var warpTimer;
2209
- var warpFrame;
2210
- var wheelZoomReference;
2211
- var wheelZoomReferenceTimer;
2212
- var hoveredMarkerTarget;
2213
- var markerPress;
2214
- var settledCenter = [-rotation[0], -rotation[1]];
2215
- var externalMapTransitioning = false;
2216
- return (0, exports.createCustomSeries)({
2217
- selector: configuration.selector,
2218
- displayName: configuration.displayName,
2219
- xField: configuration.lonField,
2220
- yField: configuration.latField,
2221
- color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
2222
- render: function (_a) {
2223
- var _b;
2224
- var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
2225
- var width = plotSize.width;
2226
- var height = plotSize.height;
2227
- var centerX = width / 2;
2228
- var centerY = height / 2;
2229
- var zoomConfiguration = resolveGlobeZoomConfiguration(configuration.zoom);
2230
- var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
2231
- var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
2232
- var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
2233
- var drilldownConfiguration = resolveGlobeDrilldownConfiguration(configuration.drilldown);
2234
- zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
2235
- var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
2236
- var globeProjection = (0, d3_geo_1.geoOrthographic)()
2237
- .translate([centerX, centerY])
2238
- .scale(baseScale * zoomLevel)
2239
- .rotate(rotation)
2240
- .clipAngle(90);
2241
- var mapProjection = (0, d3_geo_1.geoMercator)()
2242
- .translate([centerX, centerY])
2243
- .scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel))
2244
- .center(focusedPoint ? [focusedPoint.lon, focusedPoint.lat] : [0, 0]);
2245
- var path = (0, d3_geo_1.geoPath)(globeProjection);
2246
- var mapPath = (0, d3_geo_1.geoPath)(mapProjection);
2247
- var resolveGlobeCenter = function () {
2248
- var _a;
2249
- var inverted = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, [centerX, centerY]);
2250
- return inverted && Number.isFinite(inverted[0]) && Number.isFinite(inverted[1])
2251
- ? inverted
2252
- : [-rotation[0], -rotation[1]];
2253
- };
2254
- var getFirstTwoPointerDistance = function () {
2255
- var points = Array.from(activePointers.values());
2256
- if (points.length < 2) {
2257
- return 0;
2258
- }
2259
- var dx = points[0][0] - points[1][0];
2260
- var dy = points[0][1] - points[1][1];
2261
- return Math.hypot(dx, dy);
2262
- };
2263
- var cancelWarpFrame = function () {
2264
- if (warpFrame !== undefined) {
2265
- globalThis.cancelAnimationFrame(warpFrame);
2266
- warpFrame = undefined;
2267
- }
2268
- };
2269
- var clearWheelZoomReference = function () {
2270
- wheelZoomReference = undefined;
2271
- if (wheelZoomReferenceTimer !== undefined) {
2272
- globalThis.clearTimeout(wheelZoomReferenceTimer);
2273
- wheelZoomReferenceTimer = undefined;
2274
- }
2275
- };
2276
- var easeInOutCubic = function (progress) { return progress < 0.5
2277
- ? 4 * progress * progress * progress
2278
- : 1 - Math.pow(-2 * progress + 2, 3) / 2; };
2279
- var shortestAngleDelta = function (from, to) {
2280
- return (to - from + 540) % 360 - 180;
2281
- };
2282
- var enterDrilldown = function (datum, mode, restoreZoomLevel, moveCamera) {
2283
- if (mode === void 0) { mode = drilldownConfiguration.mode; }
2284
- if (moveCamera === void 0) { moveCamera = true; }
2285
- if (!drilldownConfiguration.enabled || externalMapTransitioning) {
2286
- return;
2287
- }
2288
- clearWheelZoomReference();
2289
- hoveredMarkerTarget = undefined;
2290
- if (warpTimer !== undefined) {
2291
- globalThis.clearTimeout(warpTimer);
2292
- warpTimer = undefined;
2293
- }
2294
- cancelWarpFrame();
2295
- if (!focusedPoint) {
2296
- drilldownRestoreState = {
2297
- rotation: __spreadArray([], rotation, true),
2298
- zoomLevel: clampNumber(restoreZoomLevel !== null && restoreZoomLevel !== void 0 ? restoreZoomLevel : zoomLevel, minZoom, maxZoom)
2299
- };
2300
- }
2301
- focusedPoint = datum;
2302
- if (mode === 'zoom') {
2303
- viewMode = 'globe';
2304
- rotation = [
2305
- -datum.lon,
2306
- -datum.lat,
2307
- rotation[2]
2308
- ];
2309
- zoomLevel = clampNumber(drilldownConfiguration.focusZoom, minZoom, maxZoom);
2310
- }
2311
- else if (mode === 'external-map') {
2312
- externalMapTransitioning = true;
2313
- viewMode = 'globe';
2314
- }
2315
- else {
2316
- viewMode = mode;
2317
- }
2318
- warpEffect = mode === 'external-map'
2319
- ? undefined
2320
- : {
2321
- x: datum.projected[0],
2322
- y: datum.projected[1],
2323
- startedAt: Date.now(),
2324
- duration: drilldownConfiguration.duration
2325
- };
2326
- var notifyEnter = function () {
2327
- var _a;
2328
- (_a = drilldownConfiguration.onEnter) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration, {
2329
- data: datum.data,
2330
- lat: datum.lat,
2331
- lon: datum.lon,
2332
- exit: function () { return exitDrilldown(); }
2333
- });
2334
- };
2335
- if (mode === 'external-map') {
2336
- var cameraDuration_1 = moveCamera
2337
- ? Math.min(460, Math.max(280, drilldownConfiguration.duration * 0.34))
2338
- : 0;
2339
- var warpDuration_1 = Math.max(600, drilldownConfiguration.duration - cameraDuration_1);
2340
- var startRotation_1 = __spreadArray([], rotation, true);
2341
- var targetRotation_1 = [
2342
- -datum.lon,
2343
- -datum.lat,
2344
- rotation[2]
2345
- ];
2346
- var longitudeDelta_1 = shortestAngleDelta(startRotation_1[0], targetRotation_1[0]);
2347
- var startedAt_1 = globalThis.performance.now();
2348
- var revealExternalMap_1 = function () {
2349
- warpTimer = globalThis.setTimeout(function () {
2350
- warpTimer = undefined;
2351
- externalMapTransitioning = false;
2352
- viewMode = 'external-map';
2353
- warpEffect = undefined;
2354
- notifyEnter();
2355
- draw();
2356
- }, warpDuration_1);
2357
- };
2358
- var startWarp_1 = function () {
2359
- warpEffect = {
2360
- x: centerX,
2361
- y: centerY,
2362
- startedAt: Date.now(),
2363
- duration: warpDuration_1
2364
- };
2365
- draw();
2366
- revealExternalMap_1();
2367
- };
2368
- if (!moveCamera) {
2369
- draw();
2370
- startWarp_1();
2371
- return;
2372
- }
2373
- var animateCamera_1 = function (now) {
2374
- var progress = clampNumber((now - startedAt_1) / cameraDuration_1, 0, 1);
2375
- var easedProgress = easeInOutCubic(progress);
2376
- rotation = [
2377
- startRotation_1[0] + longitudeDelta_1 * easedProgress,
2378
- startRotation_1[1] + (targetRotation_1[1] - startRotation_1[1]) * easedProgress,
2379
- startRotation_1[2]
2380
- ];
2381
- draw();
2382
- if (progress < 1) {
2383
- warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
2384
- return;
2385
- }
2386
- warpFrame = undefined;
2387
- rotation = targetRotation_1;
2388
- startWarp_1();
2389
- };
2390
- draw();
2391
- warpFrame = globalThis.requestAnimationFrame(animateCamera_1);
2392
- return;
2393
- }
2394
- notifyEnter();
2395
- warpTimer = globalThis.setTimeout(function () {
2396
- warpTimer = undefined;
2397
- warpEffect = undefined;
2398
- draw();
2399
- }, drilldownConfiguration.duration);
2400
- draw();
2401
- };
2402
- var exitDrilldown = function (restoreState) {
2403
- var _a;
2404
- if (restoreState === void 0) { restoreState = true; }
2405
- if (viewMode === 'globe' && !focusedPoint) {
2406
- return;
2407
- }
2408
- if (warpTimer !== undefined) {
2409
- globalThis.clearTimeout(warpTimer);
2410
- warpTimer = undefined;
2411
- }
2412
- cancelWarpFrame();
2413
- hoveredMarkerTarget = undefined;
2414
- externalMapTransitioning = false;
2415
- viewMode = 'globe';
2416
- focusedPoint = undefined;
2417
- if (restoreState && drilldownRestoreState) {
2418
- rotation = __spreadArray([], drilldownRestoreState.rotation, true);
2419
- zoomLevel = clampNumber(drilldownRestoreState.zoomLevel, minZoom, maxZoom);
2420
- }
2421
- drilldownRestoreState = undefined;
2422
- warpEffect = undefined;
2423
- (_a = drilldownConfiguration.onExit) === null || _a === void 0 ? void 0 : _a.call(drilldownConfiguration);
2424
- draw();
2425
- };
2426
- var resolveAutoMapTarget = function (reference) {
2427
- var nearest;
2428
- var center = reference !== null && reference !== void 0 ? reference : settledCenter;
2429
- data.forEach(function (point) {
2430
- var lat = resolveGlobePointValue(point, configuration.latField);
2431
- var lon = resolveGlobePointValue(point, configuration.lonField);
2432
- if (!Number.isFinite(lat) || !Number.isFinite(lon) || !isGlobePointVisible(lon, lat, rotation)) {
2433
- return;
2434
- }
2435
- var projected = globeProjection([lon, lat]);
2436
- if (!projected) {
2437
- return;
2438
- }
2439
- var distance = (0, d3_geo_1.geoDistance)(center, [lon, lat]);
2440
- if (!nearest || distance < nearest.distance) {
2441
- nearest = {
2442
- data: point,
2443
- lat: lat,
2444
- lon: lon,
2445
- projected: projected,
2446
- distance: distance
2447
- };
2448
- }
2449
- });
2450
- return nearest;
2451
- };
2452
- var syncZoomViewMode = function (reference, preferredTarget) {
2453
- if (!drilldownConfiguration.enabled || !drilldownConfiguration.autoMapOnZoom || externalMapTransitioning) {
2454
- return false;
2455
- }
2456
- var enterThreshold = Math.max(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
2457
- var exitThreshold = Math.min(drilldownConfiguration.mapZoomThreshold, drilldownConfiguration.globeZoomThreshold);
2458
- if (viewMode === 'globe' && zoomLevel >= enterThreshold) {
2459
- var target = preferredTarget !== null && preferredTarget !== void 0 ? preferredTarget : resolveAutoMapTarget(settledCenter);
2460
- if (target) {
2461
- var automaticTarget = __assign(__assign({}, target), { lon: settledCenter[0], lat: settledCenter[1], projected: [centerX, centerY] });
2462
- enterDrilldown(automaticTarget, drilldownConfiguration.mode, Math.min(zoomLevel, exitThreshold), false);
2463
- return true;
2464
- }
2465
- }
2466
- if (viewMode === 'map' && zoomLevel <= exitThreshold) {
2467
- exitDrilldown(false);
2468
- return true;
2469
- }
2470
- return false;
2471
- };
2472
- var applyGlobeZoom = function (nextZoom, reference, preferredTarget) {
2473
- if (externalMapTransitioning) {
2474
- return;
2475
- }
2476
- zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
2477
- if (!syncZoomViewMode(reference, preferredTarget)) {
2478
- draw();
2479
- }
2480
- };
2481
- var draw = function () {
2482
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
2483
- globeProjection.rotate(rotation);
2484
- globeProjection.scale(baseScale * zoomLevel);
2485
- if (focusedPoint) {
2486
- mapProjection.center([focusedPoint.lon, focusedPoint.lat]);
2487
- }
2488
- mapProjection.scale(Math.max(1, Math.min(width, height) / Math.PI * drilldownConfiguration.zoomScale * zoomLevel));
2489
- var globeGroup = group.selectAll('g.kchart-globe-layer')
2490
- .data([undefined])
2491
- .join('g')
2492
- .attr('class', 'kchart-globe-layer')
2493
- .style('cursor', configuration.draggable === false || viewMode === 'map' ? 'default' : dragging ? 'grabbing' : 'grab')
2494
- .style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
2495
- globeGroup.selectAll('path.kchart-globe-sphere')
2496
- .data(viewMode === 'globe' ? [{ type: 'Sphere' }] : [])
2497
- .join('path')
2498
- .attr('class', 'kchart-globe-sphere')
2499
- .attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
2500
- .style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : 'rgba(15, 23, 42, 0.92)')
2501
- .style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(148, 163, 184, 0.62)')
2502
- .style('stroke-width', 1.2)
2503
- .style('pointer-events', 'all');
2504
- var defaultLandGeoJson = configuration.landMode === 'countries'
2505
- ? WORLD_COUNTRY_GEOJSON
2506
- : WORLD_LAND_GEOJSON;
2507
- var landData = configuration.landVisible === false
2508
- ? []
2509
- : viewMode === 'external-map'
2510
- ? []
2511
- : normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
2512
- var activePath = viewMode === 'map' ? mapPath : path;
2513
- var activeLandFill = viewMode === 'map'
2514
- ? (_d = drilldownConfiguration.landFill) !== null && _d !== void 0 ? _d : configuration.landFill
2515
- : configuration.landFill;
2516
- var activeLandStroke = viewMode === 'map'
2517
- ? (_e = drilldownConfiguration.landStroke) !== null && _e !== void 0 ? _e : configuration.landStroke
2518
- : configuration.landStroke;
2519
- var activeLandOpacity = viewMode === 'map'
2520
- ? (_f = drilldownConfiguration.landOpacity) !== null && _f !== void 0 ? _f : configuration.landOpacity
2521
- : configuration.landOpacity;
2522
- globeGroup.selectAll('rect.kchart-globe-map-background')
2523
- .data(viewMode === 'map' ? [undefined] : [])
2524
- .join('rect')
2525
- .attr('class', 'kchart-globe-map-background')
2526
- .attr('x', 0)
2527
- .attr('y', 0)
2528
- .attr('width', width)
2529
- .attr('height', height)
2530
- .style('fill', (_g = configuration.sphereFill) !== null && _g !== void 0 ? _g : 'rgba(15, 23, 42, 0.92)')
2531
- .style('pointer-events', 'all')
2532
- .lower();
2533
- globeGroup.selectAll('path.kchart-globe-land')
2534
- .data(landData)
2535
- .join('path')
2536
- .attr('class', 'kchart-globe-land')
2537
- .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2538
- .style('fill', function (datum, index) { return resolveGlobeLandStyle(activeLandFill, datum, index, '#2dd4bf'); })
2539
- .style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(activeLandOpacity, datum, index); })
2540
- .style('stroke', function (datum, index) { return resolveGlobeLandStyle(activeLandStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
2541
- .style('stroke-width', 1)
2542
- .style('pointer-events', 'none');
2543
- globeGroup.selectAll('path.kchart-globe-country-borders')
2544
- .data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
2545
- .join('path')
2546
- .attr('class', 'kchart-globe-country-borders')
2547
- .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2548
- .style('fill', 'none')
2549
- .style('stroke', (_h = configuration.countryBordersStroke) !== null && _h !== void 0 ? _h : 'rgba(236, 253, 245, 0.26)')
2550
- .style('stroke-width', (_j = configuration.countryBordersStrokeWidth) !== null && _j !== void 0 ? _j : 0.55)
2551
- .style('pointer-events', 'none');
2552
- globeGroup.selectAll('path.kchart-globe-graticule')
2553
- .data(configuration.graticuleVisible === false || viewMode === 'external-map' ? [] : [(0, d3_geo_1.geoGraticule10)()])
2554
- .join('path')
2555
- .attr('class', 'kchart-globe-graticule')
2556
- .attr('d', function (datum) { var _a; return (_a = activePath(datum)) !== null && _a !== void 0 ? _a : ''; })
2557
- .style('fill', 'none')
2558
- .style('stroke', (_k = configuration.graticuleStroke) !== null && _k !== void 0 ? _k : 'rgba(148, 163, 184, 0.22)')
2559
- .style('stroke-width', 0.8)
2560
- .style('pointer-events', 'none');
2561
- var markerData = (viewMode === 'external-map' ? [] : data).map(function (point) {
2562
- var lat = resolveGlobePointValue(point, configuration.latField);
2563
- var lon = resolveGlobePointValue(point, configuration.lonField);
2564
- var projected = viewMode === 'map'
2565
- ? mapProjection([lon, lat])
2566
- : globeProjection([lon, lat]);
2567
- return {
2568
- data: point,
2569
- lat: lat,
2570
- lon: lon,
2571
- projected: projected,
2572
- visible: Boolean(projected) && (viewMode === 'map'
2573
- ? true
2574
- : isGlobePointVisible(lon, lat, rotation))
2575
- };
2576
- }).filter(function (point) { return point.visible && point.projected; });
2577
- var markerSelectable = Boolean(configuration.onMarkerClick || drilldownConfiguration.enabled);
2578
- var activateMarker = function (event, datum) {
2579
- var _a;
2580
- if (!markerSelectable) {
2581
- return;
2582
- }
2583
- event.preventDefault();
2584
- event.stopPropagation();
2585
- enterDrilldown(datum);
2586
- (_a = configuration.onMarkerClick) === null || _a === void 0 ? void 0 : _a.call(configuration, {
2587
- data: datum.data,
2588
- event: event,
2589
- lat: datum.lat,
2590
- lon: datum.lon,
2591
- x: datum.projected[0],
2592
- y: datum.projected[1]
2593
- });
2594
- };
2595
- var handleMarkerPointerDown = function (event, datum) {
2596
- var _a, _b;
2597
- if (!markerSelectable || event.button !== 0) {
2598
- return;
2599
- }
2600
- event.preventDefault();
2601
- event.stopPropagation();
2602
- markerPress = {
2603
- pointerId: event.pointerId,
2604
- startX: event.clientX,
2605
- startY: event.clientY,
2606
- moved: false,
2607
- datum: datum
2608
- };
2609
- (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2610
- };
2611
- var handleMarkerPointerMove = function (event) {
2612
- if (!markerPress || markerPress.pointerId !== event.pointerId) {
2613
- return;
2614
- }
2615
- if (Math.hypot(event.clientX - markerPress.startX, event.clientY - markerPress.startY) > 5) {
2616
- markerPress.moved = true;
2617
- }
2618
- };
2619
- var handleMarkerPointerUp = function (event) {
2620
- var _a, _b;
2621
- if (!markerPress || markerPress.pointerId !== event.pointerId) {
2622
- return;
2623
- }
2624
- event.preventDefault();
2625
- event.stopPropagation();
2626
- var pressed = markerPress;
2627
- markerPress = undefined;
2628
- (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2629
- if (!pressed.moved) {
2630
- activateMarker(event, pressed.datum);
2631
- }
2632
- };
2633
- var handleMarkerPointerCancel = function (event) {
2634
- if ((markerPress === null || markerPress === void 0 ? void 0 : markerPress.pointerId) === event.pointerId) {
2635
- markerPress = undefined;
2636
- }
2637
- };
2638
- var markerHitAreas = globeGroup.selectAll('circle.kchart-globe-marker-hit-area')
2639
- .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
2640
- markerHitAreas.exit().remove();
2641
- markerHitAreas.enter()
2642
- .append('circle')
2643
- .attr('class', 'kchart-globe-marker-hit-area')
2644
- .merge(markerHitAreas)
2645
- .attr('cx', function (datum) { return datum.projected[0]; })
2646
- .attr('cy', function (datum) { return datum.projected[1]; })
2647
- .attr('r', function (datum) { return Math.max(resolveGlobeMarkerRadius(datum.data, configuration) + 10, 16); })
2648
- .style('fill', 'transparent')
2649
- .style('stroke', 'transparent')
2650
- .style('cursor', markerSelectable ? 'pointer' : 'default')
2651
- .style('pointer-events', markerSelectable ? 'all' : 'none')
2652
- .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2653
- hoveredMarkerTarget = datum;
2654
- })
2655
- .on('mouseleave.kchart-globe-zoom-target', function () {
2656
- hoveredMarkerTarget = undefined;
2657
- })
2658
- .on('click', null)
2659
- .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2660
- .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2661
- .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2662
- .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2663
- var markers = globeGroup.selectAll('circle.kchart-globe-marker')
2664
- .data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
2665
- markers.exit().remove();
2666
- markers.enter()
2667
- .append('circle')
2668
- .attr('class', 'kchart-globe-marker')
2669
- .style('cursor', markerSelectable ? 'pointer' : 'default')
2670
- .style('pointer-events', 'all')
2671
- .merge(markers)
2672
- .attr('cx', function (datum) { return datum.projected[0]; })
2673
- .attr('cy', function (datum) { return datum.projected[1]; })
2674
- .attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
2675
- .style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
2676
- .style('stroke', (_l = configuration.markerStroke) !== null && _l !== void 0 ? _l : 'rgba(248, 251, 255, 0.92)')
2677
- .style('stroke-width', (_m = configuration.markerStrokeWidth) !== null && _m !== void 0 ? _m : 1.4)
2678
- .style('opacity', (_o = configuration.markerOpacity) !== null && _o !== void 0 ? _o : 0.95)
2679
- .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2680
- hoveredMarkerTarget = datum;
2681
- })
2682
- .on('mouseleave.kchart-globe-zoom-target', function () {
2683
- hoveredMarkerTarget = undefined;
2684
- })
2685
- .on('click', null)
2686
- .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2687
- .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2688
- .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2689
- .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2690
- var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
2691
- .data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
2692
- labels.exit().remove();
2693
- labels.enter()
2694
- .append('text')
2695
- .attr('class', 'kchart-globe-marker-label')
2696
- .merge(labels)
2697
- .attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
2698
- .attr('y', function (datum) { return datum.projected[1] + 4; })
2699
- .style('fill', 'rgba(248, 251, 255, 0.82)')
2700
- .style('font-size', '11px')
2701
- .style('font-weight', 700)
2702
- .style('cursor', markerSelectable ? 'pointer' : 'default')
2703
- .style('pointer-events', markerSelectable ? 'all' : 'none')
2704
- .text(function (datum) { return String(datum.data[configuration.labelField]); })
2705
- .on('mouseenter.kchart-globe-zoom-target', function (_event, datum) {
2706
- hoveredMarkerTarget = datum;
2707
- })
2708
- .on('mouseleave.kchart-globe-zoom-target', function () {
2709
- hoveredMarkerTarget = undefined;
2710
- })
2711
- .on('click', null)
2712
- .on('pointerdown.kchart-globe-marker-press', handleMarkerPointerDown)
2713
- .on('pointermove.kchart-globe-marker-press', handleMarkerPointerMove)
2714
- .on('pointerup.kchart-globe-marker-press', handleMarkerPointerUp)
2715
- .on('pointercancel.kchart-globe-marker-press', handleMarkerPointerCancel);
2716
- var activeWarpDuration = Math.max(480, (_p = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.duration) !== null && _p !== void 0 ? _p : drilldownConfiguration.duration);
2717
- var warpData = warpEffect
2718
- ? [0, 1, 2].map(function (index) { return (__assign(__assign({}, warpEffect), { index: index })); })
2719
- : [];
2720
- var warpRings = globeGroup.selectAll('circle.kchart-globe-warp-ring')
2721
- .data(warpData, function (datum) { return datum.index; });
2722
- warpRings.exit().remove();
2723
- var warpRingsEnter = warpRings.enter()
2724
- .append('circle')
2725
- .attr('class', 'kchart-globe-warp-ring')
2726
- .style('fill', 'none')
2727
- .style('pointer-events', 'none');
2728
- warpRingsEnter.append('animate')
2729
- .attr('attributeName', 'r')
2730
- .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
2731
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2732
- .attr('values', "12;".concat(Math.max(width, height) * 0.78))
2733
- .attr('keyTimes', '0;1')
2734
- .attr('calcMode', 'spline')
2735
- .attr('keySplines', '0.18 0.72 0.2 1')
2736
- .attr('fill', 'freeze');
2737
- warpRingsEnter.append('animate')
2738
- .attr('attributeName', 'opacity')
2739
- .attr('begin', function (datum) { return "".concat(datum.index * 80, "ms"); })
2740
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2741
- .attr('values', '0;1;0')
2742
- .attr('keyTimes', '0;0.16;1')
2743
- .attr('fill', 'freeze');
2744
- warpRingsEnter.merge(warpRings)
2745
- .attr('cx', function (datum) { return datum.x; })
2746
- .attr('cy', function (datum) { return datum.y; })
2747
- .attr('r', 12)
2748
- .style('stroke', function (datum) { return datum.index === 0 ? 'rgba(255, 255, 255, 0.9)' : 'rgba(93, 184, 255, 0.62)'; })
2749
- .style('stroke-width', function (datum) { return 3 - datum.index * 0.55; })
2750
- .style('stroke-dasharray', function (datum) { return datum.index === 0 ? 'none' : '6 10'; })
2751
- .style('filter', 'drop-shadow(0 0 8px rgba(93, 184, 255, 0.9))');
2752
- var warpFlash = globeGroup.selectAll('circle.kchart-globe-warp-flash')
2753
- .data(warpEffect ? [warpEffect] : []);
2754
- warpFlash.exit().remove();
2755
- var warpFlashEnter = warpFlash.enter()
2756
- .append('circle')
2757
- .attr('class', 'kchart-globe-warp-flash')
2758
- .style('fill', 'rgba(248, 251, 255, 0.96)')
2759
- .style('pointer-events', 'none')
2760
- .style('filter', 'drop-shadow(0 0 18px rgba(93, 184, 255, 1))');
2761
- warpFlashEnter.append('animate')
2762
- .attr('attributeName', 'r')
2763
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2764
- .attr('values', "5;".concat(Math.max(width, height) * 0.42))
2765
- .attr('keyTimes', '0;1')
2766
- .attr('fill', 'freeze');
2767
- warpFlashEnter.append('animate')
2768
- .attr('attributeName', 'opacity')
2769
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2770
- .attr('values', '1;0.72;0')
2771
- .attr('keyTimes', '0;0.18;1')
2772
- .attr('fill', 'freeze');
2773
- warpFlashEnter.merge(warpFlash)
2774
- .attr('cx', function (datum) { return datum.x; })
2775
- .attr('cy', function (datum) { return datum.y; })
2776
- .attr('r', 5);
2777
- var warpLines = globeGroup.selectAll('line.kchart-globe-warp-line')
2778
- .data(warpEffect ? Array.from({ length: 18 }, function (_, index) { return index; }) : []);
2779
- warpLines.exit().remove();
2780
- var warpLinesEnter = warpLines.enter()
2781
- .append('line')
2782
- .attr('class', 'kchart-globe-warp-line')
2783
- .style('stroke', 'rgba(248, 251, 255, 0.5)')
2784
- .style('stroke-width', 1.4)
2785
- .style('stroke-dasharray', '18 12')
2786
- .style('pointer-events', 'none');
2787
- warpLinesEnter.append('animate')
2788
- .attr('attributeName', 'opacity')
2789
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2790
- .attr('values', '0;0.85;0')
2791
- .attr('keyTimes', '0;0.22;1')
2792
- .attr('fill', 'freeze');
2793
- warpLinesEnter.append('animate')
2794
- .attr('attributeName', 'stroke-dashoffset')
2795
- .attr('dur', "".concat(activeWarpDuration, "ms"))
2796
- .attr('from', '180')
2797
- .attr('to', '0')
2798
- .attr('fill', 'freeze');
2799
- warpLinesEnter.merge(warpLines)
2800
- .attr('x1', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.x) !== null && _a !== void 0 ? _a : centerX) + Math.cos(index / 18 * Math.PI * 2) * 18; })
2801
- .attr('y1', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.y) !== null && _a !== void 0 ? _a : centerY) + Math.sin(index / 18 * Math.PI * 2) * 18; })
2802
- .attr('x2', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.x) !== null && _a !== void 0 ? _a : centerX) + Math.cos(index / 18 * Math.PI * 2) * Math.max(width, height); })
2803
- .attr('y2', function (index) { var _a; return ((_a = warpEffect === null || warpEffect === void 0 ? void 0 : warpEffect.y) !== null && _a !== void 0 ? _a : centerY) + Math.sin(index / 18 * Math.PI * 2) * Math.max(width, height); })
2804
- .style('filter', 'drop-shadow(0 0 5px rgba(93, 184, 255, 0.82))');
2805
- var zoomControlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
2806
- var drilldownResetVisible = Boolean(focusedPoint)
2807
- && drilldownConfiguration.resetControl
2808
- && !externalMapTransitioning;
2809
- var controlsVisible = zoomControlsVisible || drilldownResetVisible;
2810
- var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
2811
- var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
2812
- var controlItems = __spreadArray(__spreadArray([], (zoomControlsVisible ? [
2813
- { key: 'in', label: '+', title: 'Zoom in' },
2814
- { key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom' },
2815
- { key: 'out', label: '-', title: 'Zoom out' }
2816
- ] : []), true), (drilldownResetVisible ? [
2817
- { key: 'globe', label: 'G', title: 'Back to globe' }
2818
- ] : []), true).map(function (item, index) { return (__assign(__assign({}, item), { y: index * 31 })); });
2819
- var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
2820
- .data(controlsVisible ? [undefined] : []);
2821
- zoomControls.exit().remove();
2822
- var zoomControlsEnter = zoomControls.enter()
2823
- .append('g')
2824
- .attr('class', 'kchart-globe-zoom-controls')
2825
- .style('pointer-events', 'all');
2826
- var zoomControlsMerged = zoomControlsEnter
2827
- .merge(zoomControls)
2828
- .attr('transform', "translate(".concat(controlsX, ",").concat(controlsY, ")"));
2829
- var controlButtons = zoomControlsMerged.selectAll('g.kchart-globe-zoom-control')
2830
- .data(controlItems, function (datum) { return datum.key; });
2831
- controlButtons.exit().remove();
2832
- var controlButtonsEnter = controlButtons.enter()
2833
- .append('g')
2834
- .attr('class', 'kchart-globe-zoom-control')
2835
- .style('cursor', 'pointer')
2836
- .on('pointerdown', function (event) {
2837
- event.preventDefault();
2838
- event.stopPropagation();
2839
- })
2840
- .on('click', function (event, datum) {
2841
- event.preventDefault();
2842
- event.stopPropagation();
2843
- if (datum.key === 'in') {
2844
- applyGlobeZoom(zoomLevel * (1 + zoomControlsConfiguration.step));
2845
- return;
2846
- }
2847
- if (datum.key === 'out') {
2848
- applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
2849
- return;
2850
- }
2851
- if (datum.key === 'globe') {
2852
- exitDrilldown();
2853
- return;
2854
- }
2855
- applyGlobeZoom(1);
2856
- });
2857
- controlButtonsEnter.append('rect')
2858
- .attr('class', 'kchart-globe-zoom-control-bg')
2859
- .attr('width', 34)
2860
- .attr('height', 27)
2861
- .attr('rx', 6);
2862
- controlButtonsEnter.append('text')
2863
- .attr('class', 'kchart-globe-zoom-control-label')
2864
- .attr('x', 17)
2865
- .attr('y', 18)
2866
- .attr('text-anchor', 'middle');
2867
- controlButtonsEnter.append('title');
2868
- var controlButtonsMerged = controlButtonsEnter.merge(controlButtons)
2869
- .attr('transform', function (datum) { return "translate(0,".concat(datum.y, ")"); })
2870
- .style('opacity', function (datum) {
2871
- if (datum.key === 'in' && zoomLevel >= maxZoom)
2872
- return 0.48;
2873
- if (datum.key === 'out' && zoomLevel <= minZoom)
2874
- return 0.48;
2875
- return 1;
2876
- });
2877
- controlButtonsMerged.select('rect.kchart-globe-zoom-control-bg')
2878
- .style('fill', 'rgba(15, 23, 42, 0.72)')
2879
- .style('stroke', 'rgba(226, 232, 240, 0.42)')
2880
- .style('stroke-width', 1);
2881
- controlButtonsMerged.select('text.kchart-globe-zoom-control-label')
2882
- .style('fill', 'rgba(248, 251, 255, 0.92)')
2883
- .style('font-size', function (datum) { return datum.key === 'reset' ? '10px' : '17px'; })
2884
- .style('font-weight', 800)
2885
- .text(function (datum) { return datum.label; });
2886
- controlButtonsMerged.select('title')
2887
- .text(function (datum) { return datum.title; });
2888
- };
2889
- draw();
2890
- var globeLayer = group.select('g.kchart-globe-layer');
2891
- globeLayer.on('.kchart-globe-drag', null);
2892
- globeLayer.on('.kchart-globe-zoom', null);
2893
- if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
2894
- globeLayer.on('wheel.kchart-globe-zoom', function (event) {
2895
- var _a;
2896
- event.preventDefault();
2897
- if (!wheelZoomReference) {
2898
- var currentPoint = (0, d3_selection_1.pointer)(event, globeLayer.node());
2899
- var reference = (_a = globeProjection.invert) === null || _a === void 0 ? void 0 : _a.call(globeProjection, currentPoint);
2900
- if (reference && Number.isFinite(reference[0]) && Number.isFinite(reference[1])) {
2901
- wheelZoomReference = reference;
2902
- }
2903
- }
2904
- if (wheelZoomReferenceTimer !== undefined) {
2905
- globalThis.clearTimeout(wheelZoomReferenceTimer);
2906
- }
2907
- wheelZoomReferenceTimer = globalThis.setTimeout(function () {
2908
- wheelZoomReference = undefined;
2909
- wheelZoomReferenceTimer = undefined;
2910
- }, 180);
2911
- var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
2912
- applyGlobeZoom(zoomLevel * zoomDelta, wheelZoomReference, hoveredMarkerTarget);
2913
- });
2914
- }
2915
- if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
2916
- globeLayer
2917
- .on('pointerdown.kchart-globe-drag', function (event) {
2918
- var _a, _b;
2919
- var eventTarget = event.target;
2920
- if (eventTarget === null || eventTarget === void 0 ? void 0 : eventTarget.closest('.kchart-globe-marker-hit-area, .kchart-globe-marker, .kchart-globe-marker-label')) {
2921
- return;
2922
- }
2923
- var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
2924
- if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
2925
- activePointers.set(event.pointerId, currentPoint);
2926
- }
2927
- if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
2928
- dragging = false;
2929
- pinchStartDistance = getFirstTwoPointerDistance();
2930
- pinchStartZoom = zoomLevel;
2931
- }
2932
- else if (configuration.draggable !== false && viewMode === 'globe') {
2933
- dragging = true;
2934
- dragStart = currentPoint;
2935
- rotationStart = __spreadArray([], rotation, true);
2936
- }
2937
- (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2938
- event.preventDefault();
2939
- draw();
2940
- })
2941
- .on('pointermove.kchart-globe-drag', function (event) {
2942
- if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.has(event.pointerId)) {
2943
- activePointers.set(event.pointerId, (0, d3_selection_1.pointer)(event, group.node()));
2944
- }
2945
- if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
2946
- var distance = getFirstTwoPointerDistance();
2947
- if (pinchStartDistance > 0 && distance > 0) {
2948
- applyGlobeZoom(pinchStartZoom * distance / pinchStartDistance);
2949
- }
2950
- event.preventDefault();
2951
- return;
2952
- }
2953
- if (!dragging) {
2954
- return;
2955
- }
2956
- var _a = (0, d3_selection_1.pointer)(event, group.node()), mouseX = _a[0], mouseY = _a[1];
2957
- var dx = mouseX - dragStart[0];
2958
- var dy = mouseY - dragStart[1];
2959
- rotation = [
2960
- rotationStart[0] + dx / Math.max(width, 1) * 360,
2961
- clampNumber(rotationStart[1] - dy / Math.max(height, 1) * 180, -89, 89),
2962
- rotationStart[2]
2963
- ];
2964
- event.preventDefault();
2965
- draw();
2966
- })
2967
- .on('pointerup.kchart-globe-drag pointercancel.kchart-globe-drag', function (event) {
2968
- var _a, _b;
2969
- activePointers.delete(event.pointerId);
2970
- if (activePointers.size < 2) {
2971
- pinchStartDistance = 0;
2972
- pinchStartZoom = zoomLevel;
2973
- }
2974
- dragging = false;
2975
- settledCenter = resolveGlobeCenter();
2976
- (_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
2977
- draw();
2978
- });
2979
- }
2980
- },
2981
- destroy: function (_a) {
2982
- var plotGroup = _a.plotGroup;
2983
- if (warpTimer !== undefined) {
2984
- globalThis.clearTimeout(warpTimer);
2985
- warpTimer = undefined;
2986
- }
2987
- if (warpFrame !== undefined) {
2988
- globalThis.cancelAnimationFrame(warpFrame);
2989
- warpFrame = undefined;
2990
- }
2991
- wheelZoomReference = undefined;
2992
- hoveredMarkerTarget = undefined;
2993
- markerPress = undefined;
2994
- if (wheelZoomReferenceTimer !== undefined) {
2995
- globalThis.clearTimeout(wheelZoomReferenceTimer);
2996
- wheelZoomReferenceTimer = undefined;
2997
- }
2998
- externalMapTransitioning = false;
2999
- plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
3000
- plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
3001
- }
3002
- });
3003
- };
3004
- exports.createSvgGlobeSeries = createSvgGlobeSeries;
3005
- var createWebglPointSeries = function (configuration) { return (0, exports.createCustomSeries)({
3006
- selector: configuration.selector,
3007
- displayName: configuration.displayName,
3008
- xField: configuration.xField,
3009
- yField: configuration.yField,
3010
- color: configuration.color,
3011
- render: function (_a) {
3012
- var _b, _c;
3013
- var getWebglCanvas = _a.getWebglCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color;
3014
- if (!xScale || !yScale) {
3015
- return;
3016
- }
3017
- var canvas = getWebglCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
3018
- var gl = canvas.getContext('webgl', { alpha: true });
3019
- if (!gl) {
3020
- return;
3021
- }
3022
- var vertexSource = "\n attribute vec2 a_position;\n attribute float a_size;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n gl_PointSize = a_size;\n }\n ";
3023
- var fragmentSource = "\n precision mediump float;\n uniform vec4 u_color;\n\n void main() {\n vec2 point = gl_PointCoord - vec2(0.5);\n if (length(point) > 0.5) {\n discard;\n }\n gl_FragColor = u_color;\n }\n ";
3024
- var program = createProgram(gl, vertexSource, fragmentSource);
3025
- if (!program) {
3026
- return;
3027
- }
3028
- var _d = resolveWebglPointInterleavedData(data, xScale, yScale, configuration.xField, configuration.yField, canvas.width, canvas.height, function (point) {
3029
- var _a;
3030
- return typeof configuration.pointSize === 'function'
3031
- ? configuration.pointSize(point)
3032
- : (_a = configuration.pointSize) !== null && _a !== void 0 ? _a : 8;
3033
- }), buffer = _d.buffer, count = _d.count;
3034
- gl.viewport(0, 0, canvas.width, canvas.height);
3035
- gl.clearColor(0, 0, 0, 0);
3036
- gl.clear(gl.COLOR_BUFFER_BIT);
3037
- gl.useProgram(program);
3038
- gl.enable(gl.BLEND);
3039
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
3040
- var interleavedBuffer = gl.createBuffer();
3041
- gl.bindBuffer(gl.ARRAY_BUFFER, interleavedBuffer);
3042
- gl.bufferData(gl.ARRAY_BUFFER, buffer, gl.STATIC_DRAW);
3043
- var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
3044
- var positionLocation = gl.getAttribLocation(program, 'a_position');
3045
- gl.enableVertexAttribArray(positionLocation);
3046
- gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, stride, 0);
3047
- var sizeLocation = gl.getAttribLocation(program, 'a_size');
3048
- gl.enableVertexAttribArray(sizeLocation);
3049
- gl.vertexAttribPointer(sizeLocation, 1, gl.FLOAT, false, stride, 2 * Float32Array.BYTES_PER_ELEMENT);
3050
- var colorLocation = gl.getUniformLocation(program, 'u_color');
3051
- gl.uniform4fv(colorLocation, new Float32Array(parseColor((_c = configuration.color) !== null && _c !== void 0 ? _c : color)));
3052
- gl.drawArrays(gl.POINTS, 0, count);
3053
- },
3054
- destroy: function (_a) {
3055
- var _b;
3056
- var svg = _a.svg;
3057
- destroyCanvasByClass(svg, "kchart-webgl-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
3058
- }
3059
- }); };
3060
- exports.createWebglPointSeries = createWebglPointSeries;
3061
- var createWebglLineSeries = function (configuration) { return (0, exports.createCustomSeries)({
3062
- selector: configuration.selector,
3063
- displayName: configuration.displayName,
3064
- xField: configuration.xField,
3065
- yField: configuration.yField,
3066
- color: configuration.color,
3067
- downsample: configuration.downsample,
3068
- render: function (_a) {
3069
- var _b, _c, _d, _e, _f;
3070
- var getWebglCanvas = _a.getWebglCanvas, data = _a.data, xScale = _a.xScale, yScale = _a.yScale, color = _a.color;
3071
- if (!xScale || !yScale) {
3072
- return;
3073
- }
3074
- var canvas = getWebglCanvas((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector);
3075
- var canvasSize = resolveCanvasPixelSize(canvas);
3076
- var points = resolveLinePoints(data, xScale, yScale, configuration.xField, configuration.yField);
3077
- if (renderLineWithWorker(canvas, 'webgl', configuration.asyncRender, {
3078
- width: canvasSize.width,
3079
- height: canvasSize.height,
3080
- color: (_c = configuration.color) !== null && _c !== void 0 ? _c : color,
3081
- lineWidth: (_d = configuration.lineWidth) !== null && _d !== void 0 ? _d : 1,
3082
- points: points
3083
- })) {
3084
- return;
3085
- }
3086
- var gl = canvas.getContext('webgl', { alpha: true });
3087
- if (!gl) {
3088
- return;
3089
- }
3090
- var vertexSource = "\n attribute vec2 a_position;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }\n ";
3091
- var fragmentSource = "\n precision mediump float;\n uniform vec4 u_color;\n\n void main() {\n gl_FragColor = u_color;\n }\n ";
3092
- var program = createProgram(gl, vertexSource, fragmentSource);
3093
- if (!program) {
3094
- return;
3095
- }
3096
- var vertices = resolveWebglLineVertices(points, canvas.width, canvas.height);
3097
- gl.viewport(0, 0, canvas.width, canvas.height);
3098
- gl.clearColor(0, 0, 0, 0);
3099
- gl.clear(gl.COLOR_BUFFER_BIT);
3100
- gl.useProgram(program);
3101
- gl.enable(gl.BLEND);
3102
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
3103
- gl.lineWidth((_e = configuration.lineWidth) !== null && _e !== void 0 ? _e : 1);
3104
- var positionBuffer = gl.createBuffer();
3105
- gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
3106
- gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
3107
- var positionLocation = gl.getAttribLocation(program, 'a_position');
3108
- gl.enableVertexAttribArray(positionLocation);
3109
- gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
3110
- var colorLocation = gl.getUniformLocation(program, 'u_color');
3111
- gl.uniform4fv(colorLocation, new Float32Array(parseColor((_f = configuration.color) !== null && _f !== void 0 ? _f : color)));
3112
- gl.drawArrays(gl.LINE_STRIP, 0, vertices.length / 2);
3113
- },
3114
- destroy: function (_a) {
3115
- var _b;
3116
- var svg = _a.svg;
3117
- destroyCanvasByClass(svg, "kchart-webgl-canvas-".concat((_b = configuration.canvasName) !== null && _b !== void 0 ? _b : configuration.selector));
3118
- }
3119
- }); };
3120
- exports.createWebglLineSeries = createWebglLineSeries;
3121
- var createKChart = function (config) {
3122
- var _a;
3123
- var container = resolveContainer(config.selector);
3124
- var baseMargin = __assign(__assign({}, defaultMargin), config.margin);
3125
- var sizes = resolveSize(container, config, baseMargin);
3126
- var state = {
3127
- config: config,
3128
- container: container,
3129
- data: config.data,
3130
- axes: cloneAxes(config.axes),
3131
- initialAxes: cloneAxes(config.axes),
3132
- baseAxes: cloneAxes(config.axes),
3133
- series: config.series,
3134
- size: sizes.size,
3135
- plotSize: sizes.plotSize,
3136
- margin: sizes.margin,
3137
- colors: (_a = config.colors) !== null && _a !== void 0 ? _a : d3_scale_chromatic_1.schemeCategory10.slice(),
3138
- scales: [],
3139
- layers: undefined,
3140
- hiddenSeries: new Set(),
3141
- zoomTransform: d3_zoom_1.zoomIdentity
3142
- };
3143
- state.layers = createLayers(container, config, function () { return state.size; }, function () { return state.margin; });
3144
- var controller = {
3145
- render: function () {
3146
- render(state);
3147
- return controller;
3148
- },
3149
- updateData: function (data) {
3150
- state.data = data;
3151
- state.config = __assign(__assign({}, state.config), { data: data });
3152
- return controller.render();
3153
- },
3154
- updateAxes: function (axes) {
3155
- state.axes = cloneAxes(axes);
3156
- state.initialAxes = cloneAxes(axes);
3157
- state.baseAxes = cloneAxes(axes);
3158
- state.zoomTransform = d3_zoom_1.zoomIdentity;
3159
- state.config = __assign(__assign({}, state.config), { axes: state.axes });
3160
- return controller.render();
3161
- },
3162
- updateSeries: function (series) {
3163
- state.series = series;
3164
- return controller.render();
3165
- },
3166
- resize: function (size) {
3167
- if (size === void 0) { size = {}; }
3168
- var nextConfig = __assign(__assign({}, state.config), size);
3169
- var nextBaseMargin = __assign(__assign({}, defaultMargin), nextConfig.margin);
3170
- var nextSizes = resolveSize(state.container, nextConfig, nextBaseMargin);
3171
- state.config = nextConfig;
3172
- state.margin = nextSizes.margin;
3173
- state.size = nextSizes.size;
3174
- state.plotSize = nextSizes.plotSize;
3175
- return controller.render();
3176
- },
3177
- destroy: function () {
3178
- state.series.forEach(function (series) {
3179
- if (series.destroy) {
3180
- series.destroy(state.layers);
3181
- }
3182
- });
3183
- state.container.selectAll('.kchart-svg').remove();
3184
- state.container.selectAll('canvas[class^="kchart-"]').remove();
3185
- },
3186
- getState: function () {
3187
- return state;
3188
- }
3189
- };
3190
- return controller;
3191
- };
3192
- exports.createKChart = createKChart;
17
+ /**
18
+ * Backward-compatible public barrel.
19
+ *
20
+ * New implementation code lives under core, series, options, and utils.
21
+ */
22
+ __exportStar(require("./core/contracts"), exports);
23
+ __exportStar(require("./core/create-kchart"), exports);
24
+ __exportStar(require("./options"), exports);
25
+ __exportStar(require("./series"), exports);
26
+ __exportStar(require("./utils/downsample-lttb"), exports);
27
+ __exportStar(require("./worker/render-worker"), exports);
3193
28
  //# sourceMappingURL=kchart.js.map