@keneth80/k-chart 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +66 -0
- package/docs/code-graph-handoff.md +2 -0
- package/docs/functional-api.md +48 -0
- package/examples/svg-globe-map-series.ts +51 -0
- package/lib/kchart.d.ts +55 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +415 -1
- package/lib/kchart.js.map +1 -1
- package/package.json +7 -2
package/lib/kchart.js
CHANGED
|
@@ -19,15 +19,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
19
19
|
}
|
|
20
20
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
21
|
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
22
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.createKChart = exports.createWebglLineSeries = exports.createWebglPointSeries = exports.createCanvasCandlestickSeries = exports.createCanvasPointSeries = exports.createCanvasLineSeries = exports.createLineSeries = exports.createCursorLineOption = exports.createGuideLineOption = exports.createSpecAreaOption = exports.createCustomSeries = exports.startKChartRenderWorker = exports.downsampleLTTB = void 0;
|
|
26
|
+
exports.createKChart = exports.createWebglLineSeries = exports.createWebglPointSeries = exports.createSvgGlobeSeries = exports.createCanvasCandlestickSeries = exports.createCanvasPointSeries = exports.createCanvasLineSeries = exports.createLineSeries = exports.createCursorLineOption = exports.createGuideLineOption = exports.createSpecAreaOption = exports.createCustomSeries = exports.startKChartRenderWorker = exports.downsampleLTTB = void 0;
|
|
24
27
|
var d3_array_1 = require("d3-array");
|
|
25
28
|
var d3_axis_1 = require("d3-axis");
|
|
29
|
+
var d3_geo_1 = require("d3-geo");
|
|
26
30
|
var d3_scale_1 = require("d3-scale");
|
|
27
31
|
var d3_scale_chromatic_1 = require("d3-scale-chromatic");
|
|
28
32
|
var d3_selection_1 = require("d3-selection");
|
|
29
33
|
var d3_shape_1 = require("d3-shape");
|
|
30
34
|
var d3_zoom_1 = require("d3-zoom");
|
|
35
|
+
var topojson_client_1 = require("topojson-client");
|
|
36
|
+
var countries_110m_json_1 = __importDefault(require("world-atlas/countries-110m.json"));
|
|
37
|
+
var land_110m_json_1 = __importDefault(require("world-atlas/land-110m.json"));
|
|
31
38
|
var defaultMargin = {
|
|
32
39
|
top: 24,
|
|
33
40
|
right: 24,
|
|
@@ -452,6 +459,100 @@ var formatCandlestickTooltipValue = function (value) {
|
|
|
452
459
|
var numberValue = Number(value);
|
|
453
460
|
return Number.isFinite(numberValue) ? numberValue.toLocaleString(undefined, { maximumFractionDigits: 4 }) : String(value);
|
|
454
461
|
};
|
|
462
|
+
var resolveGlobePointValue = function (point, field) { return Number(point[field]); };
|
|
463
|
+
var resolveGlobeMarkerRadius = function (point, configuration) {
|
|
464
|
+
var _a;
|
|
465
|
+
if (typeof configuration.markerRadius === 'function') {
|
|
466
|
+
return configuration.markerRadius(point);
|
|
467
|
+
}
|
|
468
|
+
return (_a = configuration.markerRadius) !== null && _a !== void 0 ? _a : 5;
|
|
469
|
+
};
|
|
470
|
+
var resolveGlobeMarkerColor = function (point, configuration, fallbackColor) {
|
|
471
|
+
var _a;
|
|
472
|
+
if (typeof configuration.markerColor === 'function') {
|
|
473
|
+
return configuration.markerColor(point);
|
|
474
|
+
}
|
|
475
|
+
return (_a = configuration.markerColor) !== null && _a !== void 0 ? _a : fallbackColor;
|
|
476
|
+
};
|
|
477
|
+
var resolveGlobeLandStyle = function (value, feature, index, fallback) {
|
|
478
|
+
if (typeof value === 'function') {
|
|
479
|
+
return value(feature, index);
|
|
480
|
+
}
|
|
481
|
+
return value !== null && value !== void 0 ? value : fallback;
|
|
482
|
+
};
|
|
483
|
+
var resolveGlobeLandOpacity = function (value, feature, index) {
|
|
484
|
+
if (typeof value === 'function') {
|
|
485
|
+
return value(feature, index);
|
|
486
|
+
}
|
|
487
|
+
return value !== null && value !== void 0 ? value : 0.88;
|
|
488
|
+
};
|
|
489
|
+
var normalizeGlobeLandFeatures = function (geoJson) {
|
|
490
|
+
var values = Array.isArray(geoJson) ? geoJson : [geoJson];
|
|
491
|
+
return values.flatMap(function (value) {
|
|
492
|
+
if ((value === null || value === void 0 ? void 0 : value.type) === 'FeatureCollection' && Array.isArray(value.features)) {
|
|
493
|
+
return value.features;
|
|
494
|
+
}
|
|
495
|
+
return value ? [value] : [];
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
var normalizeGlobeRotation = function (rotation) {
|
|
499
|
+
var _a, _b, _c;
|
|
500
|
+
return [
|
|
501
|
+
(_a = rotation === null || rotation === void 0 ? void 0 : rotation[0]) !== null && _a !== void 0 ? _a : 0,
|
|
502
|
+
(_b = rotation === null || rotation === void 0 ? void 0 : rotation[1]) !== null && _b !== void 0 ? _b : -12,
|
|
503
|
+
(_c = rotation === null || rotation === void 0 ? void 0 : rotation[2]) !== null && _c !== void 0 ? _c : 0
|
|
504
|
+
];
|
|
505
|
+
};
|
|
506
|
+
var resolveGlobeZoomConfiguration = function (zoom) {
|
|
507
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
508
|
+
if (typeof zoom === 'boolean') {
|
|
509
|
+
return {
|
|
510
|
+
enabled: zoom,
|
|
511
|
+
wheel: true,
|
|
512
|
+
pinch: true,
|
|
513
|
+
controls: false,
|
|
514
|
+
min: 0.55,
|
|
515
|
+
max: 3,
|
|
516
|
+
wheelSensitivity: 0.0012
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
enabled: (_a = zoom === null || zoom === void 0 ? void 0 : zoom.enabled) !== null && _a !== void 0 ? _a : false,
|
|
521
|
+
wheel: (_b = zoom === null || zoom === void 0 ? void 0 : zoom.wheel) !== null && _b !== void 0 ? _b : true,
|
|
522
|
+
pinch: (_c = zoom === null || zoom === void 0 ? void 0 : zoom.pinch) !== null && _c !== void 0 ? _c : true,
|
|
523
|
+
controls: (_d = zoom === null || zoom === void 0 ? void 0 : zoom.controls) !== null && _d !== void 0 ? _d : false,
|
|
524
|
+
min: (_e = zoom === null || zoom === void 0 ? void 0 : zoom.min) !== null && _e !== void 0 ? _e : 0.55,
|
|
525
|
+
max: (_f = zoom === null || zoom === void 0 ? void 0 : zoom.max) !== null && _f !== void 0 ? _f : 3,
|
|
526
|
+
wheelSensitivity: (_g = zoom === null || zoom === void 0 ? void 0 : zoom.wheelSensitivity) !== null && _g !== void 0 ? _g : 0.0012
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
var resolveGlobeZoomControlsConfiguration = function (controls) {
|
|
530
|
+
var _a, _b, _c, _d;
|
|
531
|
+
if (typeof controls === 'boolean') {
|
|
532
|
+
return {
|
|
533
|
+
visible: controls,
|
|
534
|
+
step: 0.22,
|
|
535
|
+
x: 8,
|
|
536
|
+
y: 8
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
visible: (_a = controls === null || controls === void 0 ? void 0 : controls.visible) !== null && _a !== void 0 ? _a : false,
|
|
541
|
+
step: (_b = controls === null || controls === void 0 ? void 0 : controls.step) !== null && _b !== void 0 ? _b : 0.22,
|
|
542
|
+
x: (_c = controls === null || controls === void 0 ? void 0 : controls.x) !== null && _c !== void 0 ? _c : 8,
|
|
543
|
+
y: (_d = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _d !== void 0 ? _d : 8
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
var WORLD_COUNTRY_GEOJSON = (0, topojson_client_1.feature)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries);
|
|
547
|
+
var WORLD_LAND_GEOJSON = (0, topojson_client_1.feature)(land_110m_json_1.default, land_110m_json_1.default.objects.land);
|
|
548
|
+
var WORLD_COUNTRY_BORDERS_GEOJSON = (0, topojson_client_1.mesh)(countries_110m_json_1.default, countries_110m_json_1.default.objects.countries, function (a, b) { return a !== b; });
|
|
549
|
+
var isGlobePointVisible = function (lon, lat, rotation) {
|
|
550
|
+
if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
var center = [-rotation[0], -rotation[1]];
|
|
554
|
+
return (0, d3_geo_1.geoDistance)([lon, lat], center) <= Math.PI / 2;
|
|
555
|
+
};
|
|
455
556
|
var downsampleLTTB = function (data, threshold, xAccessor, yAccessor) {
|
|
456
557
|
var dataLength = data.length;
|
|
457
558
|
var targetLength = Math.floor(threshold);
|
|
@@ -2059,6 +2160,319 @@ var createCanvasCandlestickSeries = function (configuration) { return (0, export
|
|
|
2059
2160
|
}
|
|
2060
2161
|
}); };
|
|
2061
2162
|
exports.createCanvasCandlestickSeries = createCanvasCandlestickSeries;
|
|
2163
|
+
var createSvgGlobeSeries = function (configuration) {
|
|
2164
|
+
var rotation = normalizeGlobeRotation(configuration.initialRotate);
|
|
2165
|
+
var zoomLevel = 1;
|
|
2166
|
+
var dragging = false;
|
|
2167
|
+
var dragStart = [0, 0];
|
|
2168
|
+
var rotationStart = __spreadArray([], rotation, true);
|
|
2169
|
+
var activePointers = new Map();
|
|
2170
|
+
var pinchStartDistance = 0;
|
|
2171
|
+
var pinchStartZoom = 1;
|
|
2172
|
+
return (0, exports.createCustomSeries)({
|
|
2173
|
+
selector: configuration.selector,
|
|
2174
|
+
displayName: configuration.displayName,
|
|
2175
|
+
xField: configuration.lonField,
|
|
2176
|
+
yField: configuration.latField,
|
|
2177
|
+
color: typeof configuration.markerColor === 'string' ? configuration.markerColor : undefined,
|
|
2178
|
+
render: function (_a) {
|
|
2179
|
+
var _b;
|
|
2180
|
+
var group = _a.group, data = _a.data, size = _a.size, plotSize = _a.plotSize, margin = _a.margin, color = _a.color;
|
|
2181
|
+
var width = plotSize.width;
|
|
2182
|
+
var height = plotSize.height;
|
|
2183
|
+
var centerX = width / 2;
|
|
2184
|
+
var centerY = height / 2;
|
|
2185
|
+
var zoomConfiguration = resolveGlobeZoomConfiguration(configuration.zoom);
|
|
2186
|
+
var minZoom = Math.min(zoomConfiguration.min, zoomConfiguration.max);
|
|
2187
|
+
var maxZoom = Math.max(zoomConfiguration.min, zoomConfiguration.max);
|
|
2188
|
+
var zoomControlsConfiguration = resolveGlobeZoomControlsConfiguration(zoomConfiguration.controls);
|
|
2189
|
+
zoomLevel = clampNumber(zoomLevel, minZoom, maxZoom);
|
|
2190
|
+
var baseScale = Math.max(1, Math.min(width, height) / 2 * ((_b = configuration.globeScale) !== null && _b !== void 0 ? _b : 0.88));
|
|
2191
|
+
var projection = (0, d3_geo_1.geoOrthographic)()
|
|
2192
|
+
.translate([centerX, centerY])
|
|
2193
|
+
.scale(baseScale * zoomLevel)
|
|
2194
|
+
.rotate(rotation)
|
|
2195
|
+
.clipAngle(90);
|
|
2196
|
+
var path = (0, d3_geo_1.geoPath)(projection);
|
|
2197
|
+
var getFirstTwoPointerDistance = function () {
|
|
2198
|
+
var points = Array.from(activePointers.values());
|
|
2199
|
+
if (points.length < 2) {
|
|
2200
|
+
return 0;
|
|
2201
|
+
}
|
|
2202
|
+
var dx = points[0][0] - points[1][0];
|
|
2203
|
+
var dy = points[0][1] - points[1][1];
|
|
2204
|
+
return Math.hypot(dx, dy);
|
|
2205
|
+
};
|
|
2206
|
+
var applyGlobeZoom = function (nextZoom) {
|
|
2207
|
+
zoomLevel = clampNumber(nextZoom, minZoom, maxZoom);
|
|
2208
|
+
draw();
|
|
2209
|
+
};
|
|
2210
|
+
var draw = function () {
|
|
2211
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2212
|
+
projection.rotate(rotation);
|
|
2213
|
+
projection.scale(baseScale * zoomLevel);
|
|
2214
|
+
var globeGroup = group.selectAll('g.kchart-globe-layer')
|
|
2215
|
+
.data([undefined])
|
|
2216
|
+
.join('g')
|
|
2217
|
+
.attr('class', 'kchart-globe-layer')
|
|
2218
|
+
.style('cursor', configuration.draggable === false ? 'default' : dragging ? 'grabbing' : 'grab')
|
|
2219
|
+
.style('touch-action', configuration.draggable === false && !zoomConfiguration.enabled ? null : 'none');
|
|
2220
|
+
globeGroup.selectAll('path.kchart-globe-sphere')
|
|
2221
|
+
.data([{ type: 'Sphere' }])
|
|
2222
|
+
.join('path')
|
|
2223
|
+
.attr('class', 'kchart-globe-sphere')
|
|
2224
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2225
|
+
.style('fill', (_a = configuration.sphereFill) !== null && _a !== void 0 ? _a : 'rgba(15, 23, 42, 0.92)')
|
|
2226
|
+
.style('stroke', (_b = configuration.sphereStroke) !== null && _b !== void 0 ? _b : 'rgba(148, 163, 184, 0.62)')
|
|
2227
|
+
.style('stroke-width', 1.2)
|
|
2228
|
+
.style('pointer-events', 'all');
|
|
2229
|
+
var defaultLandGeoJson = configuration.landMode === 'countries'
|
|
2230
|
+
? WORLD_COUNTRY_GEOJSON
|
|
2231
|
+
: WORLD_LAND_GEOJSON;
|
|
2232
|
+
var landData = configuration.landVisible === false
|
|
2233
|
+
? []
|
|
2234
|
+
: normalizeGlobeLandFeatures((_c = configuration.landGeoJson) !== null && _c !== void 0 ? _c : defaultLandGeoJson);
|
|
2235
|
+
globeGroup.selectAll('path.kchart-globe-land')
|
|
2236
|
+
.data(landData)
|
|
2237
|
+
.join('path')
|
|
2238
|
+
.attr('class', 'kchart-globe-land')
|
|
2239
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2240
|
+
.style('fill', function (datum, index) { return resolveGlobeLandStyle(configuration.landFill, datum, index, '#2dd4bf'); })
|
|
2241
|
+
.style('fill-opacity', function (datum, index) { return resolveGlobeLandOpacity(configuration.landOpacity, datum, index); })
|
|
2242
|
+
.style('stroke', function (datum, index) { return resolveGlobeLandStyle(configuration.landStroke, datum, index, 'rgba(236, 253, 245, 0.9)'); })
|
|
2243
|
+
.style('stroke-width', 1)
|
|
2244
|
+
.style('pointer-events', 'none');
|
|
2245
|
+
globeGroup.selectAll('path.kchart-globe-country-borders')
|
|
2246
|
+
.data(configuration.countryBordersVisible === false || configuration.landVisible === false ? [] : [WORLD_COUNTRY_BORDERS_GEOJSON])
|
|
2247
|
+
.join('path')
|
|
2248
|
+
.attr('class', 'kchart-globe-country-borders')
|
|
2249
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2250
|
+
.style('fill', 'none')
|
|
2251
|
+
.style('stroke', (_d = configuration.countryBordersStroke) !== null && _d !== void 0 ? _d : 'rgba(236, 253, 245, 0.26)')
|
|
2252
|
+
.style('stroke-width', (_e = configuration.countryBordersStrokeWidth) !== null && _e !== void 0 ? _e : 0.55)
|
|
2253
|
+
.style('pointer-events', 'none');
|
|
2254
|
+
globeGroup.selectAll('path.kchart-globe-graticule')
|
|
2255
|
+
.data(configuration.graticuleVisible === false ? [] : [(0, d3_geo_1.geoGraticule10)()])
|
|
2256
|
+
.join('path')
|
|
2257
|
+
.attr('class', 'kchart-globe-graticule')
|
|
2258
|
+
.attr('d', function (datum) { var _a; return (_a = path(datum)) !== null && _a !== void 0 ? _a : ''; })
|
|
2259
|
+
.style('fill', 'none')
|
|
2260
|
+
.style('stroke', (_f = configuration.graticuleStroke) !== null && _f !== void 0 ? _f : 'rgba(148, 163, 184, 0.22)')
|
|
2261
|
+
.style('stroke-width', 0.8)
|
|
2262
|
+
.style('pointer-events', 'none');
|
|
2263
|
+
var markerData = data.map(function (point) {
|
|
2264
|
+
var lat = resolveGlobePointValue(point, configuration.latField);
|
|
2265
|
+
var lon = resolveGlobePointValue(point, configuration.lonField);
|
|
2266
|
+
var projected = projection([lon, lat]);
|
|
2267
|
+
return {
|
|
2268
|
+
data: point,
|
|
2269
|
+
lat: lat,
|
|
2270
|
+
lon: lon,
|
|
2271
|
+
projected: projected,
|
|
2272
|
+
visible: Boolean(projected) && isGlobePointVisible(lon, lat, rotation)
|
|
2273
|
+
};
|
|
2274
|
+
}).filter(function (point) { return point.visible && point.projected; });
|
|
2275
|
+
var markers = globeGroup.selectAll('circle.kchart-globe-marker')
|
|
2276
|
+
.data(markerData, function (datum) { return String(configuration.labelField ? datum.data[configuration.labelField] : "".concat(datum.lat, ",").concat(datum.lon)); });
|
|
2277
|
+
markers.exit().remove();
|
|
2278
|
+
markers.enter()
|
|
2279
|
+
.append('circle')
|
|
2280
|
+
.attr('class', 'kchart-globe-marker')
|
|
2281
|
+
.style('cursor', configuration.onMarkerClick ? 'pointer' : 'default')
|
|
2282
|
+
.style('pointer-events', 'all')
|
|
2283
|
+
.merge(markers)
|
|
2284
|
+
.attr('cx', function (datum) { return datum.projected[0]; })
|
|
2285
|
+
.attr('cy', function (datum) { return datum.projected[1]; })
|
|
2286
|
+
.attr('r', function (datum) { return resolveGlobeMarkerRadius(datum.data, configuration); })
|
|
2287
|
+
.style('fill', function (datum) { return resolveGlobeMarkerColor(datum.data, configuration, color); })
|
|
2288
|
+
.style('stroke', (_g = configuration.markerStroke) !== null && _g !== void 0 ? _g : 'rgba(248, 251, 255, 0.92)')
|
|
2289
|
+
.style('stroke-width', (_h = configuration.markerStrokeWidth) !== null && _h !== void 0 ? _h : 1.4)
|
|
2290
|
+
.style('opacity', (_j = configuration.markerOpacity) !== null && _j !== void 0 ? _j : 0.95)
|
|
2291
|
+
.on('click', function (event, datum) {
|
|
2292
|
+
if (!configuration.onMarkerClick) {
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
event.preventDefault();
|
|
2296
|
+
event.stopPropagation();
|
|
2297
|
+
configuration.onMarkerClick({
|
|
2298
|
+
data: datum.data,
|
|
2299
|
+
event: event,
|
|
2300
|
+
lat: datum.lat,
|
|
2301
|
+
lon: datum.lon,
|
|
2302
|
+
x: datum.projected[0],
|
|
2303
|
+
y: datum.projected[1]
|
|
2304
|
+
});
|
|
2305
|
+
});
|
|
2306
|
+
var labels = globeGroup.selectAll('text.kchart-globe-marker-label')
|
|
2307
|
+
.data(configuration.labelField ? markerData : [], function (datum) { return String(datum.data[configuration.labelField]); });
|
|
2308
|
+
labels.exit().remove();
|
|
2309
|
+
labels.enter()
|
|
2310
|
+
.append('text')
|
|
2311
|
+
.attr('class', 'kchart-globe-marker-label')
|
|
2312
|
+
.style('pointer-events', 'none')
|
|
2313
|
+
.merge(labels)
|
|
2314
|
+
.attr('x', function (datum) { return datum.projected[0] + resolveGlobeMarkerRadius(datum.data, configuration) + 5; })
|
|
2315
|
+
.attr('y', function (datum) { return datum.projected[1] + 4; })
|
|
2316
|
+
.style('fill', 'rgba(248, 251, 255, 0.82)')
|
|
2317
|
+
.style('font-size', '11px')
|
|
2318
|
+
.style('font-weight', 700)
|
|
2319
|
+
.text(function (datum) { return String(datum.data[configuration.labelField]); });
|
|
2320
|
+
var controlsVisible = zoomConfiguration.enabled && zoomControlsConfiguration.visible;
|
|
2321
|
+
var controlsX = Math.max(-margin.left, size.width - margin.left - zoomControlsConfiguration.x - 34);
|
|
2322
|
+
var controlsY = Math.max(-margin.top, zoomControlsConfiguration.y - margin.top);
|
|
2323
|
+
var controlItems = [
|
|
2324
|
+
{ key: 'in', label: '+', title: 'Zoom in', y: 0 },
|
|
2325
|
+
{ key: 'reset', label: "".concat(Math.round(zoomLevel * 100), "%"), title: 'Reset zoom', y: 31 },
|
|
2326
|
+
{ key: 'out', label: '-', title: 'Zoom out', y: 62 }
|
|
2327
|
+
];
|
|
2328
|
+
var zoomControls = globeGroup.selectAll('g.kchart-globe-zoom-controls')
|
|
2329
|
+
.data(controlsVisible ? [undefined] : []);
|
|
2330
|
+
zoomControls.exit().remove();
|
|
2331
|
+
var zoomControlsEnter = zoomControls.enter()
|
|
2332
|
+
.append('g')
|
|
2333
|
+
.attr('class', 'kchart-globe-zoom-controls')
|
|
2334
|
+
.style('pointer-events', 'all');
|
|
2335
|
+
var zoomControlsMerged = zoomControlsEnter
|
|
2336
|
+
.merge(zoomControls)
|
|
2337
|
+
.attr('transform', "translate(".concat(controlsX, ",").concat(controlsY, ")"));
|
|
2338
|
+
var controlButtons = zoomControlsMerged.selectAll('g.kchart-globe-zoom-control')
|
|
2339
|
+
.data(controlItems, function (datum) { return datum.key; });
|
|
2340
|
+
controlButtons.exit().remove();
|
|
2341
|
+
var controlButtonsEnter = controlButtons.enter()
|
|
2342
|
+
.append('g')
|
|
2343
|
+
.attr('class', 'kchart-globe-zoom-control')
|
|
2344
|
+
.style('cursor', 'pointer')
|
|
2345
|
+
.on('pointerdown', function (event) {
|
|
2346
|
+
event.preventDefault();
|
|
2347
|
+
event.stopPropagation();
|
|
2348
|
+
})
|
|
2349
|
+
.on('click', function (event, datum) {
|
|
2350
|
+
event.preventDefault();
|
|
2351
|
+
event.stopPropagation();
|
|
2352
|
+
if (datum.key === 'in') {
|
|
2353
|
+
applyGlobeZoom(zoomLevel * (1 + zoomControlsConfiguration.step));
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
if (datum.key === 'out') {
|
|
2357
|
+
applyGlobeZoom(zoomLevel / (1 + zoomControlsConfiguration.step));
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
applyGlobeZoom(1);
|
|
2361
|
+
});
|
|
2362
|
+
controlButtonsEnter.append('rect')
|
|
2363
|
+
.attr('class', 'kchart-globe-zoom-control-bg')
|
|
2364
|
+
.attr('width', 34)
|
|
2365
|
+
.attr('height', 27)
|
|
2366
|
+
.attr('rx', 6);
|
|
2367
|
+
controlButtonsEnter.append('text')
|
|
2368
|
+
.attr('class', 'kchart-globe-zoom-control-label')
|
|
2369
|
+
.attr('x', 17)
|
|
2370
|
+
.attr('y', 18)
|
|
2371
|
+
.attr('text-anchor', 'middle');
|
|
2372
|
+
controlButtonsEnter.append('title');
|
|
2373
|
+
var controlButtonsMerged = controlButtonsEnter.merge(controlButtons)
|
|
2374
|
+
.attr('transform', function (datum) { return "translate(0,".concat(datum.y, ")"); })
|
|
2375
|
+
.style('opacity', function (datum) {
|
|
2376
|
+
if (datum.key === 'in' && zoomLevel >= maxZoom)
|
|
2377
|
+
return 0.48;
|
|
2378
|
+
if (datum.key === 'out' && zoomLevel <= minZoom)
|
|
2379
|
+
return 0.48;
|
|
2380
|
+
return 1;
|
|
2381
|
+
});
|
|
2382
|
+
controlButtonsMerged.select('rect.kchart-globe-zoom-control-bg')
|
|
2383
|
+
.style('fill', 'rgba(15, 23, 42, 0.72)')
|
|
2384
|
+
.style('stroke', 'rgba(226, 232, 240, 0.42)')
|
|
2385
|
+
.style('stroke-width', 1);
|
|
2386
|
+
controlButtonsMerged.select('text.kchart-globe-zoom-control-label')
|
|
2387
|
+
.style('fill', 'rgba(248, 251, 255, 0.92)')
|
|
2388
|
+
.style('font-size', function (datum) { return datum.key === 'reset' ? '10px' : '17px'; })
|
|
2389
|
+
.style('font-weight', 800)
|
|
2390
|
+
.text(function (datum) { return datum.label; });
|
|
2391
|
+
controlButtonsMerged.select('title')
|
|
2392
|
+
.text(function (datum) { return datum.title; });
|
|
2393
|
+
};
|
|
2394
|
+
draw();
|
|
2395
|
+
var globeLayer = group.select('g.kchart-globe-layer');
|
|
2396
|
+
globeLayer.on('.kchart-globe-drag', null);
|
|
2397
|
+
globeLayer.on('.kchart-globe-zoom', null);
|
|
2398
|
+
if (zoomConfiguration.enabled && zoomConfiguration.wheel) {
|
|
2399
|
+
globeLayer.on('wheel.kchart-globe-zoom', function (event) {
|
|
2400
|
+
event.preventDefault();
|
|
2401
|
+
var zoomDelta = Math.exp(-event.deltaY * zoomConfiguration.wheelSensitivity);
|
|
2402
|
+
zoomLevel = clampNumber(zoomLevel * zoomDelta, minZoom, maxZoom);
|
|
2403
|
+
draw();
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
if (configuration.draggable !== false || (zoomConfiguration.enabled && zoomConfiguration.pinch)) {
|
|
2407
|
+
globeLayer
|
|
2408
|
+
.on('pointerdown.kchart-globe-drag', function (event) {
|
|
2409
|
+
var _a, _b;
|
|
2410
|
+
var currentPoint = (0, d3_selection_1.pointer)(event, group.node());
|
|
2411
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch) {
|
|
2412
|
+
activePointers.set(event.pointerId, currentPoint);
|
|
2413
|
+
}
|
|
2414
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
|
|
2415
|
+
dragging = false;
|
|
2416
|
+
pinchStartDistance = getFirstTwoPointerDistance();
|
|
2417
|
+
pinchStartZoom = zoomLevel;
|
|
2418
|
+
}
|
|
2419
|
+
else if (configuration.draggable !== false) {
|
|
2420
|
+
dragging = true;
|
|
2421
|
+
dragStart = currentPoint;
|
|
2422
|
+
rotationStart = __spreadArray([], rotation, true);
|
|
2423
|
+
}
|
|
2424
|
+
(_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
|
|
2425
|
+
event.preventDefault();
|
|
2426
|
+
draw();
|
|
2427
|
+
})
|
|
2428
|
+
.on('pointermove.kchart-globe-drag', function (event) {
|
|
2429
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.has(event.pointerId)) {
|
|
2430
|
+
activePointers.set(event.pointerId, (0, d3_selection_1.pointer)(event, group.node()));
|
|
2431
|
+
}
|
|
2432
|
+
if (zoomConfiguration.enabled && zoomConfiguration.pinch && activePointers.size >= 2) {
|
|
2433
|
+
var distance = getFirstTwoPointerDistance();
|
|
2434
|
+
if (pinchStartDistance > 0 && distance > 0) {
|
|
2435
|
+
zoomLevel = clampNumber(pinchStartZoom * distance / pinchStartDistance, minZoom, maxZoom);
|
|
2436
|
+
draw();
|
|
2437
|
+
}
|
|
2438
|
+
event.preventDefault();
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
if (!dragging) {
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
var _a = (0, d3_selection_1.pointer)(event, group.node()), mouseX = _a[0], mouseY = _a[1];
|
|
2445
|
+
var dx = mouseX - dragStart[0];
|
|
2446
|
+
var dy = mouseY - dragStart[1];
|
|
2447
|
+
rotation = [
|
|
2448
|
+
rotationStart[0] + dx / Math.max(width, 1) * 360,
|
|
2449
|
+
clampNumber(rotationStart[1] - dy / Math.max(height, 1) * 180, -89, 89),
|
|
2450
|
+
rotationStart[2]
|
|
2451
|
+
];
|
|
2452
|
+
event.preventDefault();
|
|
2453
|
+
draw();
|
|
2454
|
+
})
|
|
2455
|
+
.on('pointerup.kchart-globe-drag pointercancel.kchart-globe-drag', function (event) {
|
|
2456
|
+
var _a, _b;
|
|
2457
|
+
activePointers.delete(event.pointerId);
|
|
2458
|
+
if (activePointers.size < 2) {
|
|
2459
|
+
pinchStartDistance = 0;
|
|
2460
|
+
pinchStartZoom = zoomLevel;
|
|
2461
|
+
}
|
|
2462
|
+
dragging = false;
|
|
2463
|
+
(_b = (_a = event.currentTarget).releasePointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
|
|
2464
|
+
draw();
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
},
|
|
2468
|
+
destroy: function (_a) {
|
|
2469
|
+
var plotGroup = _a.plotGroup;
|
|
2470
|
+
plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-drag', null);
|
|
2471
|
+
plotGroup.selectAll("g.series-".concat(configuration.selector, " g.kchart-globe-layer")).on('.kchart-globe-zoom', null);
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
};
|
|
2475
|
+
exports.createSvgGlobeSeries = createSvgGlobeSeries;
|
|
2062
2476
|
var createWebglPointSeries = function (configuration) { return (0, exports.createCustomSeries)({
|
|
2063
2477
|
selector: configuration.selector,
|
|
2064
2478
|
displayName: configuration.displayName,
|