@keneth80/k-chart 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/docs/configuration-reference.md +22 -0
- package/docs/functional-api.md +13 -2
- package/examples/stackblitz-korea-region-map-basic/package-lock.json +1 -1
- package/examples/stackblitz-korea-region-map-basic/package.json +1 -1
- package/examples/stackblitz-korea-region-map-basic/src/data/LICENSE.md +11 -0
- package/examples/stackblitz-korea-region-map-basic/src/data/korea-provinces-2018-topo-simple.json +1 -0
- package/examples/stackblitz-korea-region-map-basic/src/main.ts +32 -40
- package/lib/core/contracts.d.ts +15 -0
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/series/svg-region-map.d.ts.map +1 -1
- package/lib/series/svg-region-map.js +362 -166
- package/lib/series/svg-region-map.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createWorldCountryMapSeries = exports.createGeoRegionMapSeries = void 0;
|
|
18
18
|
var d3_geo_1 = require("d3-geo");
|
|
19
|
+
var d3_zoom_1 = require("d3-zoom");
|
|
19
20
|
var topojson_client_1 = require("topojson-client");
|
|
20
21
|
var countries_110m_json_1 = __importDefault(require("world-atlas/countries-110m.json"));
|
|
21
22
|
var custom_1 = require("./custom");
|
|
@@ -32,12 +33,25 @@ var defaultRegionPalette = [
|
|
|
32
33
|
'#2f73b8',
|
|
33
34
|
'#9b5de5'
|
|
34
35
|
];
|
|
35
|
-
var normalizeGeoFeatures = function (geoJson) {
|
|
36
|
+
var normalizeGeoFeatures = function (geoJson, topoObjectName) {
|
|
36
37
|
var values = Array.isArray(geoJson) ? geoJson : [geoJson];
|
|
37
38
|
return values.flatMap(function (value) {
|
|
38
39
|
if (!value) {
|
|
39
40
|
return [];
|
|
40
41
|
}
|
|
42
|
+
if (value.type === 'Topology' && value.objects) {
|
|
43
|
+
var objectName = topoObjectName && value.objects[topoObjectName]
|
|
44
|
+
? topoObjectName
|
|
45
|
+
: Object.keys(value.objects)[0];
|
|
46
|
+
if (!objectName) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
var converted = (0, topojson_client_1.feature)(value, value.objects[objectName]);
|
|
50
|
+
if (converted.type === 'FeatureCollection' && Array.isArray(converted.features)) {
|
|
51
|
+
return converted.features;
|
|
52
|
+
}
|
|
53
|
+
return converted.type === 'Feature' ? [converted] : [];
|
|
54
|
+
}
|
|
41
55
|
if (value.type === 'FeatureCollection' && Array.isArray(value.features)) {
|
|
42
56
|
return value.features;
|
|
43
57
|
}
|
|
@@ -94,6 +108,43 @@ var resolveLabels = function (labels) {
|
|
|
94
108
|
offset: (_m = labels === null || labels === void 0 ? void 0 : labels.offset) !== null && _m !== void 0 ? _m : 18
|
|
95
109
|
};
|
|
96
110
|
};
|
|
111
|
+
var resolveRegionZoomControls = function (controls) {
|
|
112
|
+
var _a, _b, _c, _d;
|
|
113
|
+
if (typeof controls === 'boolean') {
|
|
114
|
+
return {
|
|
115
|
+
visible: controls,
|
|
116
|
+
x: 8,
|
|
117
|
+
y: 8,
|
|
118
|
+
step: 0.28
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
visible: (_a = controls === null || controls === void 0 ? void 0 : controls.visible) !== null && _a !== void 0 ? _a : false,
|
|
123
|
+
x: (_b = controls === null || controls === void 0 ? void 0 : controls.x) !== null && _b !== void 0 ? _b : 8,
|
|
124
|
+
y: (_c = controls === null || controls === void 0 ? void 0 : controls.y) !== null && _c !== void 0 ? _c : 8,
|
|
125
|
+
step: (_d = controls === null || controls === void 0 ? void 0 : controls.step) !== null && _d !== void 0 ? _d : 0.28
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
var resolveRegionZoom = function (zoomConfiguration) {
|
|
129
|
+
var _a, _b, _c, _d, _e;
|
|
130
|
+
if (typeof zoomConfiguration === 'boolean') {
|
|
131
|
+
return {
|
|
132
|
+
enabled: zoomConfiguration,
|
|
133
|
+
wheel: true,
|
|
134
|
+
pan: true,
|
|
135
|
+
controls: resolveRegionZoomControls(zoomConfiguration),
|
|
136
|
+
scaleExtent: [1, 8]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
enabled: (_a = zoomConfiguration === null || zoomConfiguration === void 0 ? void 0 : zoomConfiguration.enabled) !== null && _a !== void 0 ? _a : false,
|
|
141
|
+
wheel: (_b = zoomConfiguration === null || zoomConfiguration === void 0 ? void 0 : zoomConfiguration.wheel) !== null && _b !== void 0 ? _b : true,
|
|
142
|
+
pan: (_c = zoomConfiguration === null || zoomConfiguration === void 0 ? void 0 : zoomConfiguration.pan) !== null && _c !== void 0 ? _c : true,
|
|
143
|
+
controls: resolveRegionZoomControls((_d = zoomConfiguration === null || zoomConfiguration === void 0 ? void 0 : zoomConfiguration.controls) !== null && _d !== void 0 ? _d : false),
|
|
144
|
+
scaleExtent: (_e = zoomConfiguration === null || zoomConfiguration === void 0 ? void 0 : zoomConfiguration.scaleExtent) !== null && _e !== void 0 ? _e : [1, 8]
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
var clampNumber = function (value, min, max) { return Math.max(min, Math.min(max, value)); };
|
|
97
148
|
var resolveRegionFill = function (context, configuration) {
|
|
98
149
|
var _a;
|
|
99
150
|
if (context.data && configuration.colorField) {
|
|
@@ -148,176 +199,321 @@ var createTooltipHtml = function (context, configuration) {
|
|
|
148
199
|
var valueText = context.value === undefined ? '' : "<br/>value: ".concat(context.value);
|
|
149
200
|
return "<strong>".concat(context.label, "</strong>").concat(valueText);
|
|
150
201
|
};
|
|
151
|
-
var createGeoRegionMapSeries = function (configuration) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
var datum = dataByKey.get(key);
|
|
183
|
-
var value = datum && configuration.valueField ? datum[configuration.valueField] : undefined;
|
|
184
|
-
var centroid = path.centroid(featureItem);
|
|
185
|
-
return {
|
|
186
|
-
feature: featureItem,
|
|
187
|
-
data: datum,
|
|
188
|
-
index: index,
|
|
189
|
-
key: key,
|
|
190
|
-
label: label,
|
|
191
|
-
value: value,
|
|
192
|
-
centroid: centroid
|
|
202
|
+
var createGeoRegionMapSeries = function (configuration) {
|
|
203
|
+
var regionZoomTransform = d3_zoom_1.zoomIdentity;
|
|
204
|
+
var getLocalPoint = function (x, y) { return [
|
|
205
|
+
(x - regionZoomTransform.x) / regionZoomTransform.k,
|
|
206
|
+
(y - regionZoomTransform.y) / regionZoomTransform.k
|
|
207
|
+
]; };
|
|
208
|
+
var getScreenPoint = function (point) { return [
|
|
209
|
+
point[0] * regionZoomTransform.k + regionZoomTransform.x,
|
|
210
|
+
point[1] * regionZoomTransform.k + regionZoomTransform.y
|
|
211
|
+
]; };
|
|
212
|
+
return (0, custom_1.createCustomSeries)({
|
|
213
|
+
selector: configuration.selector,
|
|
214
|
+
displayName: configuration.displayName,
|
|
215
|
+
color: typeof configuration.fill === 'string' ? configuration.fill : undefined,
|
|
216
|
+
render: function (_a) {
|
|
217
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
218
|
+
var group = _a.group, data = _a.data, plotSize = _a.plotSize, overlayGroup = _a.overlayGroup;
|
|
219
|
+
var width = plotSize.width;
|
|
220
|
+
var height = plotSize.height;
|
|
221
|
+
var zoomConfiguration = resolveRegionZoom(configuration.zoom);
|
|
222
|
+
var _l = [
|
|
223
|
+
Math.min(zoomConfiguration.scaleExtent[0], zoomConfiguration.scaleExtent[1]),
|
|
224
|
+
Math.max(zoomConfiguration.scaleExtent[0], zoomConfiguration.scaleExtent[1])
|
|
225
|
+
], minZoom = _l[0], maxZoom = _l[1];
|
|
226
|
+
regionZoomTransform = d3_zoom_1.zoomIdentity
|
|
227
|
+
.translate(regionZoomTransform.x, regionZoomTransform.y)
|
|
228
|
+
.scale(clampNumber(regionZoomTransform.k, minZoom, maxZoom));
|
|
229
|
+
var features = normalizeGeoFeatures(configuration.geoJson, configuration.topoObjectName);
|
|
230
|
+
var featureCollection = {
|
|
231
|
+
type: 'FeatureCollection',
|
|
232
|
+
features: features
|
|
193
233
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
234
|
+
var projection = (0, d3_geo_1.geoMercator)()
|
|
235
|
+
.fitExtent([
|
|
236
|
+
[(_b = configuration.fitPadding) !== null && _b !== void 0 ? _b : 16, (_c = configuration.fitPadding) !== null && _c !== void 0 ? _c : 16],
|
|
237
|
+
[Math.max(1, width - ((_d = configuration.fitPadding) !== null && _d !== void 0 ? _d : 16)), Math.max(1, height - ((_e = configuration.fitPadding) !== null && _e !== void 0 ? _e : 16))]
|
|
238
|
+
], featureCollection);
|
|
239
|
+
var path = (0, d3_geo_1.geoPath)(projection);
|
|
240
|
+
var dataKey = (_f = configuration.dataKey) !== null && _f !== void 0 ? _f : 'name';
|
|
241
|
+
var featureKey = (_g = configuration.featureKey) !== null && _g !== void 0 ? _g : 'name';
|
|
242
|
+
var labelKey = (_h = configuration.labelKey) !== null && _h !== void 0 ? _h : featureKey;
|
|
243
|
+
var dataByKey = new Map();
|
|
244
|
+
data.forEach(function (point) {
|
|
245
|
+
dataByKey.set(String(point[dataKey]), point);
|
|
246
|
+
});
|
|
247
|
+
var regions = features.map(function (featureItem, index) {
|
|
248
|
+
var _a;
|
|
249
|
+
var key = getPropertyValue(featureItem, featureKey, String((_a = featureItem === null || featureItem === void 0 ? void 0 : featureItem.id) !== null && _a !== void 0 ? _a : index));
|
|
250
|
+
var label = getPropertyValue(featureItem, labelKey, key);
|
|
251
|
+
var datum = dataByKey.get(key);
|
|
252
|
+
var value = datum && configuration.valueField ? datum[configuration.valueField] : undefined;
|
|
253
|
+
var centroid = path.centroid(featureItem);
|
|
254
|
+
return {
|
|
255
|
+
feature: featureItem,
|
|
256
|
+
data: datum,
|
|
257
|
+
index: index,
|
|
258
|
+
key: key,
|
|
259
|
+
label: label,
|
|
260
|
+
value: value,
|
|
261
|
+
centroid: centroid
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
group.selectAll('rect.kchart-region-map-background')
|
|
265
|
+
.data(configuration.backgroundFill ? [[width, height]] : [])
|
|
266
|
+
.join('rect')
|
|
267
|
+
.attr('class', 'kchart-region-map-background')
|
|
268
|
+
.attr('width', width)
|
|
269
|
+
.attr('height', height)
|
|
270
|
+
.style('fill', (_j = configuration.backgroundFill) !== null && _j !== void 0 ? _j : 'transparent');
|
|
271
|
+
var mapLayer = group.selectAll('g.kchart-region-map-layer')
|
|
272
|
+
.data([undefined])
|
|
273
|
+
.join('g')
|
|
274
|
+
.attr('class', 'kchart-region-map-layer')
|
|
275
|
+
.attr('transform', regionZoomTransform.toString());
|
|
276
|
+
mapLayer.selectAll("path.".concat(configuration.selector))
|
|
277
|
+
.data(regions, function (item) { return item.key; })
|
|
278
|
+
.join('path')
|
|
279
|
+
.attr('class', configuration.selector)
|
|
280
|
+
.attr('d', function (item) { var _a; return (_a = path(item.feature)) !== null && _a !== void 0 ? _a : ''; })
|
|
281
|
+
.style('fill', function (item) { return resolveRegionFill(item, configuration); })
|
|
282
|
+
.style('fill-opacity', function (item) { return resolveRegionOpacity(item, configuration); })
|
|
283
|
+
.style('stroke', function (item) { return resolveRegionStroke(item, configuration); })
|
|
284
|
+
.style('stroke-width', (_k = configuration.strokeWidth) !== null && _k !== void 0 ? _k : 1.2)
|
|
285
|
+
.style('stroke-linejoin', 'round')
|
|
286
|
+
.style('cursor', configuration.onRegionClick ? 'pointer' : 'default')
|
|
287
|
+
.on('click', function (event, item) {
|
|
288
|
+
var _a;
|
|
289
|
+
(_a = configuration.onRegionClick) === null || _a === void 0 ? void 0 : _a.call(configuration, __assign(__assign({}, item), { event: event }));
|
|
290
|
+
});
|
|
291
|
+
var labelConfiguration = resolveLabels(configuration.labels);
|
|
292
|
+
var labelItems = labelConfiguration.visible ? regions
|
|
293
|
+
.filter(function (item) { return Number.isFinite(item.centroid[0]) && Number.isFinite(item.centroid[1]); })
|
|
294
|
+
.map(function (item) {
|
|
295
|
+
var side = labelConfiguration.side === 'auto'
|
|
296
|
+
? item.centroid[0] < width / 2 ? 'left' : 'right'
|
|
297
|
+
: labelConfiguration.side;
|
|
298
|
+
return __assign(__assign({}, item), { side: side, labelX: labelConfiguration.mode === 'callout'
|
|
299
|
+
? side === 'left' ? labelConfiguration.offset : width - labelConfiguration.offset
|
|
300
|
+
: item.centroid[0], labelY: item.centroid[1], anchor: labelConfiguration.mode === 'callout'
|
|
301
|
+
? side === 'left' ? 'end' : 'start'
|
|
302
|
+
: 'middle' });
|
|
303
|
+
}) : [];
|
|
304
|
+
if (labelConfiguration.visible && labelConfiguration.mode === 'callout') {
|
|
305
|
+
var minGap_1 = labelConfiguration.fontSize + 6;
|
|
306
|
+
['left', 'right'].forEach(function (side) {
|
|
307
|
+
var sideItems = labelItems
|
|
308
|
+
.filter(function (item) { return item.side === side; })
|
|
309
|
+
.sort(function (a, b) { return a.labelY - b.labelY; });
|
|
310
|
+
sideItems.forEach(function (item, index) {
|
|
311
|
+
var previous = sideItems[index - 1];
|
|
312
|
+
if (previous && item.labelY - previous.labelY < minGap_1) {
|
|
313
|
+
item.labelY = previous.labelY + minGap_1;
|
|
314
|
+
}
|
|
315
|
+
item.labelY = Math.max(labelConfiguration.offset, Math.min(height - labelConfiguration.offset, item.labelY));
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
mapLayer.selectAll("path.".concat(configuration.selector, "-callout"))
|
|
320
|
+
.data(labelConfiguration.mode === 'callout' ? labelItems : [], function (item) { return item.key; })
|
|
321
|
+
.join('path')
|
|
322
|
+
.attr('class', "".concat(configuration.selector, "-callout"))
|
|
323
|
+
.attr('d', function (item) { return "M".concat(item.centroid[0], ",").concat(item.centroid[1], " L").concat(item.labelX, ",").concat(item.labelY); })
|
|
324
|
+
.style('fill', 'none')
|
|
325
|
+
.style('stroke', labelConfiguration.calloutStroke)
|
|
326
|
+
.style('stroke-width', 1)
|
|
327
|
+
.style('stroke-opacity', labelConfiguration.calloutOpacity)
|
|
328
|
+
.style('pointer-events', 'none');
|
|
329
|
+
mapLayer.selectAll("text.".concat(configuration.selector, "-label"))
|
|
330
|
+
.data(labelItems, function (item) { return item.key; })
|
|
331
|
+
.join('text')
|
|
332
|
+
.attr('class', "".concat(configuration.selector, "-label"))
|
|
333
|
+
.attr('x', function (item) { return item.labelX; })
|
|
334
|
+
.attr('y', function (item) { return item.labelY; })
|
|
335
|
+
.attr('text-anchor', function (item) { return item.anchor; })
|
|
336
|
+
.attr('dominant-baseline', 'middle')
|
|
337
|
+
.style('fill', labelConfiguration.fill)
|
|
338
|
+
.style('font-size', "".concat(labelConfiguration.fontSize, "px"))
|
|
339
|
+
.style('font-weight', labelConfiguration.fontWeight)
|
|
340
|
+
.style('paint-order', 'stroke')
|
|
341
|
+
.style('stroke', labelConfiguration.stroke)
|
|
342
|
+
.style('stroke-width', labelConfiguration.strokeWidth)
|
|
343
|
+
.style('pointer-events', 'none')
|
|
344
|
+
.text(function (item) { return labelConfiguration.formatter(item); });
|
|
345
|
+
var applyZoomTransform = function (transform) {
|
|
346
|
+
regionZoomTransform = transform;
|
|
347
|
+
group.select('g.kchart-region-map-layer')
|
|
348
|
+
.attr('transform', regionZoomTransform.toString());
|
|
349
|
+
overlayGroup.selectAll("g.".concat(configuration.selector, "-zoom-controls")).raise();
|
|
350
|
+
};
|
|
351
|
+
var renderZoomControls = function () {
|
|
352
|
+
var controls = zoomConfiguration.controls;
|
|
353
|
+
var controlItems = controls.visible ? [
|
|
354
|
+
{ key: 'in', label: '+', title: 'Zoom in' },
|
|
355
|
+
{ key: 'reset', label: "".concat(Math.round(regionZoomTransform.k * 100), "%"), title: 'Reset zoom' },
|
|
356
|
+
{ key: 'out', label: '-', title: 'Zoom out' }
|
|
357
|
+
] : [];
|
|
358
|
+
var controlsGroup = overlayGroup.selectAll("g.".concat(configuration.selector, "-zoom-controls"))
|
|
359
|
+
.data(controlItems.length ? [undefined] : [])
|
|
360
|
+
.join('g')
|
|
361
|
+
.attr('class', "".concat(configuration.selector, "-zoom-controls"))
|
|
362
|
+
.attr('transform', "translate(".concat(Math.max(0, width - controls.x - 48), ", ").concat(controls.y, ")"))
|
|
363
|
+
.style('pointer-events', 'all');
|
|
364
|
+
var buttons = controlsGroup.selectAll('g.kchart-region-map-zoom-control')
|
|
365
|
+
.data(controlItems, function (item) { return item.key; })
|
|
366
|
+
.join('g')
|
|
367
|
+
.attr('class', 'kchart-region-map-zoom-control')
|
|
368
|
+
.attr('transform', function (_item, index) { return "translate(0, ".concat(index * 34, ")"); })
|
|
369
|
+
.style('cursor', 'pointer')
|
|
370
|
+
.style('opacity', function (item) {
|
|
371
|
+
if (item.key === 'in' && regionZoomTransform.k >= maxZoom)
|
|
372
|
+
return 0.45;
|
|
373
|
+
if (item.key === 'out' && regionZoomTransform.k <= minZoom)
|
|
374
|
+
return 0.45;
|
|
375
|
+
return 1;
|
|
376
|
+
})
|
|
377
|
+
.on('click', function (event, item) {
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
event.stopPropagation();
|
|
380
|
+
var nextScale = item.key === 'in'
|
|
381
|
+
? regionZoomTransform.k * (1 + controls.step)
|
|
382
|
+
: item.key === 'out'
|
|
383
|
+
? regionZoomTransform.k / (1 + controls.step)
|
|
384
|
+
: 1;
|
|
385
|
+
var centerX = width / 2;
|
|
386
|
+
var centerY = height / 2;
|
|
387
|
+
var scale = clampNumber(nextScale, minZoom, maxZoom);
|
|
388
|
+
var nextTransform = item.key === 'reset'
|
|
389
|
+
? d3_zoom_1.zoomIdentity
|
|
390
|
+
: d3_zoom_1.zoomIdentity
|
|
391
|
+
.translate(centerX, centerY)
|
|
392
|
+
.scale(scale)
|
|
393
|
+
.translate(-(centerX - regionZoomTransform.x) / regionZoomTransform.k, -(centerY - regionZoomTransform.y) / regionZoomTransform.k);
|
|
394
|
+
applyZoomTransform(nextTransform);
|
|
395
|
+
renderZoomControls();
|
|
396
|
+
});
|
|
397
|
+
buttons.selectAll('rect')
|
|
398
|
+
.data([undefined])
|
|
399
|
+
.join('rect')
|
|
400
|
+
.attr('width', 48)
|
|
401
|
+
.attr('height', 30)
|
|
402
|
+
.attr('rx', 7)
|
|
403
|
+
.style('fill', 'rgba(16, 23, 33, 0.86)')
|
|
404
|
+
.style('stroke', 'rgba(226, 236, 249, 0.55)')
|
|
405
|
+
.style('stroke-width', 1);
|
|
406
|
+
buttons.selectAll('text')
|
|
407
|
+
.data(function (item) { return [item]; })
|
|
408
|
+
.join('text')
|
|
409
|
+
.attr('x', 24)
|
|
410
|
+
.attr('y', 16)
|
|
411
|
+
.attr('text-anchor', 'middle')
|
|
412
|
+
.attr('dominant-baseline', 'middle')
|
|
413
|
+
.style('fill', '#f8fbff')
|
|
414
|
+
.style('font-size', function (item) { return item.key === 'reset' ? '10px' : '18px'; })
|
|
415
|
+
.style('font-weight', 800)
|
|
416
|
+
.style('pointer-events', 'none')
|
|
417
|
+
.text(function (item) { return item.label; });
|
|
418
|
+
controlsGroup.raise();
|
|
419
|
+
};
|
|
420
|
+
if (!zoomConfiguration.enabled) {
|
|
421
|
+
overlayGroup.selectAll("g.".concat(configuration.selector, "-zoom-controls")).remove();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
var attachZoom = function () {
|
|
425
|
+
var overlay = overlayGroup.select('rect.kchart-tooltip-overlay');
|
|
426
|
+
if (!overlay.node()) {
|
|
427
|
+
overlay = overlayGroup.selectAll("rect.".concat(configuration.selector, "-zoom-overlay"))
|
|
428
|
+
.data([undefined])
|
|
429
|
+
.join('rect')
|
|
430
|
+
.attr('class', "".concat(configuration.selector, "-zoom-overlay"))
|
|
431
|
+
.attr('width', width)
|
|
432
|
+
.attr('height', height)
|
|
433
|
+
.style('fill', 'transparent')
|
|
434
|
+
.style('pointer-events', 'all');
|
|
435
|
+
}
|
|
436
|
+
var overlayNode = overlay.node();
|
|
437
|
+
if (!overlayNode) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
var zoomBehavior = (0, d3_zoom_1.zoom)()
|
|
441
|
+
.scaleExtent([minZoom, maxZoom])
|
|
442
|
+
.filter(function (event) {
|
|
443
|
+
if (event.type === 'wheel')
|
|
444
|
+
return zoomConfiguration.wheel;
|
|
445
|
+
if (event.type === 'mousedown')
|
|
446
|
+
return zoomConfiguration.pan && event.button === 0;
|
|
447
|
+
if (event.type === 'touchstart' || event.type === 'touchmove')
|
|
448
|
+
return zoomConfiguration.pan;
|
|
449
|
+
return true;
|
|
450
|
+
})
|
|
451
|
+
.on('zoom', function (event) {
|
|
452
|
+
applyZoomTransform(event.transform);
|
|
453
|
+
renderZoomControls();
|
|
247
454
|
});
|
|
455
|
+
overlay.call(zoomBehavior);
|
|
456
|
+
overlayNode.__zoom = regionZoomTransform;
|
|
457
|
+
renderZoomControls();
|
|
458
|
+
};
|
|
459
|
+
if (typeof queueMicrotask === 'function') {
|
|
460
|
+
queueMicrotask(attachZoom);
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
setTimeout(attachZoom, 0);
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
tooltip: function (_a) {
|
|
467
|
+
var _b, _c, _d, _e, _f, _g;
|
|
468
|
+
var seriesGroup = _a.seriesGroup, mouseX = _a.mouseX, mouseY = _a.mouseY;
|
|
469
|
+
if (configuration.tooltip === false) {
|
|
470
|
+
return undefined;
|
|
471
|
+
}
|
|
472
|
+
var active;
|
|
473
|
+
var _h = getLocalPoint(mouseX, mouseY), localMouseX = _h[0], localMouseY = _h[1];
|
|
474
|
+
seriesGroup.selectAll("path.".concat(configuration.selector))
|
|
475
|
+
.style('fill', function (item) { return resolveRegionFill(item, configuration); })
|
|
476
|
+
.style('stroke', function (item) { return resolveRegionStroke(item, configuration); })
|
|
477
|
+
.style('stroke-width', (_b = configuration.strokeWidth) !== null && _b !== void 0 ? _b : 1.2)
|
|
478
|
+
.each(function findHit(item) {
|
|
479
|
+
if (!active && pointHitsPath(this, localMouseX, localMouseY)) {
|
|
480
|
+
active = item;
|
|
481
|
+
}
|
|
248
482
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
.data(labelConfiguration.mode === 'callout' ? labelItems : [], function (item) { return item.key; })
|
|
252
|
-
.join('path')
|
|
253
|
-
.attr('class', "".concat(configuration.selector, "-callout"))
|
|
254
|
-
.attr('d', function (item) { return "M".concat(item.centroid[0], ",").concat(item.centroid[1], " L").concat(item.labelX, ",").concat(item.labelY); })
|
|
255
|
-
.style('fill', 'none')
|
|
256
|
-
.style('stroke', labelConfiguration.calloutStroke)
|
|
257
|
-
.style('stroke-width', 1)
|
|
258
|
-
.style('stroke-opacity', labelConfiguration.calloutOpacity)
|
|
259
|
-
.style('pointer-events', 'none');
|
|
260
|
-
group.selectAll("text.".concat(configuration.selector, "-label"))
|
|
261
|
-
.data(labelItems, function (item) { return item.key; })
|
|
262
|
-
.join('text')
|
|
263
|
-
.attr('class', "".concat(configuration.selector, "-label"))
|
|
264
|
-
.attr('x', function (item) { return item.labelX; })
|
|
265
|
-
.attr('y', function (item) { return item.labelY; })
|
|
266
|
-
.attr('text-anchor', function (item) { return item.anchor; })
|
|
267
|
-
.attr('dominant-baseline', 'middle')
|
|
268
|
-
.style('fill', labelConfiguration.fill)
|
|
269
|
-
.style('font-size', "".concat(labelConfiguration.fontSize, "px"))
|
|
270
|
-
.style('font-weight', labelConfiguration.fontWeight)
|
|
271
|
-
.style('paint-order', 'stroke')
|
|
272
|
-
.style('stroke', labelConfiguration.stroke)
|
|
273
|
-
.style('stroke-width', labelConfiguration.strokeWidth)
|
|
274
|
-
.style('pointer-events', 'none')
|
|
275
|
-
.text(function (item) { return labelConfiguration.formatter(item); });
|
|
276
|
-
},
|
|
277
|
-
tooltip: function (_a) {
|
|
278
|
-
var _b, _c, _d, _e, _f, _g;
|
|
279
|
-
var seriesGroup = _a.seriesGroup, mouseX = _a.mouseX, mouseY = _a.mouseY;
|
|
280
|
-
if (configuration.tooltip === false) {
|
|
281
|
-
return undefined;
|
|
282
|
-
}
|
|
283
|
-
var active;
|
|
284
|
-
seriesGroup.selectAll("path.".concat(configuration.selector))
|
|
285
|
-
.style('fill', function (item) { return resolveRegionFill(item, configuration); })
|
|
286
|
-
.style('stroke', function (item) { return resolveRegionStroke(item, configuration); })
|
|
287
|
-
.style('stroke-width', (_b = configuration.strokeWidth) !== null && _b !== void 0 ? _b : 1.2)
|
|
288
|
-
.each(function findHit(item) {
|
|
289
|
-
if (!active && pointHitsPath(this, mouseX, mouseY)) {
|
|
290
|
-
active = item;
|
|
483
|
+
if (!active) {
|
|
484
|
+
return undefined;
|
|
291
485
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
486
|
+
seriesGroup.selectAll("path.".concat(configuration.selector))
|
|
487
|
+
.filter(function (item) { return item.key === (active === null || active === void 0 ? void 0 : active.key); })
|
|
488
|
+
.style('fill', typeof configuration.hoverFill === 'function'
|
|
489
|
+
? configuration.hoverFill(active)
|
|
490
|
+
: (_c = configuration.hoverFill) !== null && _c !== void 0 ? _c : resolveRegionFill(active, configuration))
|
|
491
|
+
.style('stroke', (_d = configuration.hoverStroke) !== null && _d !== void 0 ? _d : '#ffffff')
|
|
492
|
+
.style('stroke-width', (_e = configuration.hoverStrokeWidth) !== null && _e !== void 0 ? _e : Math.max(2, (_f = configuration.strokeWidth) !== null && _f !== void 0 ? _f : 1.2));
|
|
493
|
+
var _j = getScreenPoint(active.centroid), tooltipX = _j[0], tooltipY = _j[1];
|
|
494
|
+
return {
|
|
495
|
+
data: (_g = active.data) !== null && _g !== void 0 ? _g : active,
|
|
496
|
+
x: tooltipX,
|
|
497
|
+
y: tooltipY,
|
|
498
|
+
distance: 0,
|
|
499
|
+
color: resolveRegionFill(active, configuration),
|
|
500
|
+
html: createTooltipHtml(active, configuration)
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
clearTooltip: function (_a) {
|
|
504
|
+
var _b;
|
|
505
|
+
var seriesGroup = _a.seriesGroup;
|
|
506
|
+
seriesGroup.selectAll("path.".concat(configuration.selector))
|
|
507
|
+
.style('fill', function (item) { return resolveRegionFill(item, configuration); })
|
|
508
|
+
.style('stroke', function (item) { return resolveRegionStroke(item, configuration); })
|
|
509
|
+
.style('stroke-width', (_b = configuration.strokeWidth) !== null && _b !== void 0 ? _b : 1.2);
|
|
510
|
+
},
|
|
511
|
+
destroy: function (_a) {
|
|
512
|
+
var overlayGroup = _a.overlayGroup;
|
|
513
|
+
overlayGroup.selectAll("g.".concat(configuration.selector, "-zoom-controls")).remove();
|
|
295
514
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
.style('fill', typeof configuration.hoverFill === 'function'
|
|
299
|
-
? configuration.hoverFill(active)
|
|
300
|
-
: (_c = configuration.hoverFill) !== null && _c !== void 0 ? _c : resolveRegionFill(active, configuration))
|
|
301
|
-
.style('stroke', (_d = configuration.hoverStroke) !== null && _d !== void 0 ? _d : '#ffffff')
|
|
302
|
-
.style('stroke-width', (_e = configuration.hoverStrokeWidth) !== null && _e !== void 0 ? _e : Math.max(2, (_f = configuration.strokeWidth) !== null && _f !== void 0 ? _f : 1.2));
|
|
303
|
-
return {
|
|
304
|
-
data: (_g = active.data) !== null && _g !== void 0 ? _g : active,
|
|
305
|
-
x: active.centroid[0],
|
|
306
|
-
y: active.centroid[1],
|
|
307
|
-
distance: 0,
|
|
308
|
-
color: resolveRegionFill(active, configuration),
|
|
309
|
-
html: createTooltipHtml(active, configuration)
|
|
310
|
-
};
|
|
311
|
-
},
|
|
312
|
-
clearTooltip: function (_a) {
|
|
313
|
-
var _b;
|
|
314
|
-
var seriesGroup = _a.seriesGroup;
|
|
315
|
-
seriesGroup.selectAll("path.".concat(configuration.selector))
|
|
316
|
-
.style('fill', function (item) { return resolveRegionFill(item, configuration); })
|
|
317
|
-
.style('stroke', function (item) { return resolveRegionStroke(item, configuration); })
|
|
318
|
-
.style('stroke-width', (_b = configuration.strokeWidth) !== null && _b !== void 0 ? _b : 1.2);
|
|
319
|
-
}
|
|
320
|
-
}); };
|
|
515
|
+
});
|
|
516
|
+
};
|
|
321
517
|
exports.createGeoRegionMapSeries = createGeoRegionMapSeries;
|
|
322
518
|
var createWorldCountryMapSeries = function (configuration) { return (0, exports.createGeoRegionMapSeries)(__assign(__assign({ featureKey: 'name', labelKey: 'name', missingFill: 'rgba(142, 160, 173, 0.2)' }, configuration), { geoJson: WORLD_COUNTRY_GEOJSON })); };
|
|
323
519
|
exports.createWorldCountryMapSeries = createWorldCountryMapSeries;
|