@evergis/charts 3.1.9 → 3.1.11

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.
@@ -0,0 +1,3723 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var styled = require('styled-components');
8
+ var styled__default = _interopDefault(styled);
9
+ var React = require('react');
10
+ var React__default = _interopDefault(React);
11
+ var d3 = require('d3');
12
+ var ReactDOMServer = _interopDefault(require('react-dom/server'));
13
+ var lodash = require('lodash');
14
+ var reactDom = require('react-dom');
15
+
16
+ function _extends() {
17
+ _extends = Object.assign || function (target) {
18
+ for (var i = 1; i < arguments.length; i++) {
19
+ var source = arguments[i];
20
+
21
+ for (var key in source) {
22
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
23
+ target[key] = source[key];
24
+ }
25
+ }
26
+ }
27
+
28
+ return target;
29
+ };
30
+
31
+ return _extends.apply(this, arguments);
32
+ }
33
+
34
+ function _objectWithoutPropertiesLoose(source, excluded) {
35
+ if (source == null) return {};
36
+ var target = {};
37
+ var sourceKeys = Object.keys(source);
38
+ var key, i;
39
+
40
+ for (i = 0; i < sourceKeys.length; i++) {
41
+ key = sourceKeys[i];
42
+ if (excluded.indexOf(key) >= 0) continue;
43
+ target[key] = source[key];
44
+ }
45
+
46
+ return target;
47
+ }
48
+
49
+ function _taggedTemplateLiteralLoose(strings, raw) {
50
+ if (!raw) {
51
+ raw = strings.slice(0);
52
+ }
53
+
54
+ strings.raw = raw;
55
+ return strings;
56
+ }
57
+
58
+ var _templateObject;
59
+ const Wrapper = /*#__PURE__*/styled__default.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n width: 100%;\n box-sizing: border-box;\n"])));
60
+
61
+ function useNode() {
62
+ const [node, onSetNode] = React.useState(null);
63
+ const ref = React.useCallback(onSetNode, [onSetNode]);
64
+ return [ref, node];
65
+ }
66
+
67
+ function throttle(fn, wait) {
68
+ let isCalled = false;
69
+ return function () {
70
+ if (!isCalled) {
71
+ fn(...arguments);
72
+ isCalled = true;
73
+ setTimeout(function () {
74
+ isCalled = false;
75
+ }, wait);
76
+ }
77
+ };
78
+ }
79
+
80
+ const THROTTLE_DELAY = 44;
81
+ const useResize = (width, callback, delay) => {
82
+ const throttledCallback = React.useMemo(() => {
83
+ return callback ? throttle(callback, delay || THROTTLE_DELAY) : undefined;
84
+ }, [callback, delay]);
85
+ React.useEffect(() => {
86
+ throttledCallback && typeof width !== 'number' && window.addEventListener('resize', throttledCallback);
87
+ return () => throttledCallback && window.removeEventListener('resize', throttledCallback);
88
+ }, [width, throttledCallback]);
89
+ };
90
+
91
+ const appendSvg = (node, width, height) => {
92
+ d3.select(node).select('svg').remove();
93
+ const svg = d3.select(node).append('svg').attr('width', width).attr('height', height);
94
+ return svg;
95
+ };
96
+
97
+ var _templateObject$1;
98
+ const SwipeScrollContainer = /*#__PURE__*/styled__default.div(_templateObject$1 || (_templateObject$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n overflow: hidden;\n user-select: none;\n"])));
99
+
100
+ function animate(_ref) {
101
+ let {
102
+ duration,
103
+ timing,
104
+ draw
105
+ } = _ref;
106
+ const start = performance.now();
107
+ let requestId;
108
+ requestAnimationFrame(function requestAnimate(time) {
109
+ let timeFraction = (time - start) / duration;
110
+
111
+ if (timeFraction < 1) {
112
+ requestId = requestAnimationFrame(requestAnimate);
113
+ }
114
+
115
+ if (timeFraction > 1) cancelAnimationFrame(requestId);
116
+ const progress = timing(timeFraction);
117
+ draw(progress, requestId);
118
+ });
119
+ }
120
+ const easeOutQuad = time => time * (2 - time);
121
+
122
+ const range = (num, min, max) => Math.min(Math.max(num, min), max);
123
+
124
+ const defaultRefs = {
125
+ animation: 0,
126
+ speed: 0,
127
+ timestamp: 0,
128
+ startX: 0,
129
+ currentX: 0
130
+ };
131
+ const useSwipe = (node, _ref) => {
132
+ let {
133
+ width,
134
+ duration,
135
+ animationFunc,
136
+ onSwipe
137
+ } = _ref;
138
+ const container = d3.select(node);
139
+ const body = d3.select('body');
140
+ const documentSelect = d3.select(document);
141
+ const refs = React.useRef(defaultRefs);
142
+ React.useEffect(() => {
143
+ if (width && refs.current.animation) {
144
+ cancelAnimationFrame(refs.current.animation);
145
+ refs.current = defaultRefs;
146
+ }
147
+ }, [width]);
148
+ const onMove = React.useCallback(event => {
149
+ const {
150
+ width: nodeWidth
151
+ } = node ? node.getBoundingClientRect() : {
152
+ width: 0
153
+ };
154
+ const [x] = d3.pointer(event.type.includes('touch') ? event.touches[0] : event);
155
+ const newX = x - refs.current.startX;
156
+ const maxX = width - nodeWidth;
157
+ const translateX = range(newX, -maxX, 0);
158
+ container.style('transform', "translateX(" + translateX + "px)");
159
+
160
+ if (refs.current.currentX) {
161
+ const hundred = 100;
162
+ const now = Date.now();
163
+ const dt = now - refs.current.timestamp;
164
+ const dx = translateX - refs.current.currentX;
165
+ const speedX = Math.round(dx / dt * hundred);
166
+ refs.current.speed = speedX;
167
+ refs.current.timestamp = now;
168
+ }
169
+
170
+ refs.current.currentX = translateX;
171
+ onSwipe && onSwipe(translateX, container);
172
+ }, [onSwipe, width, node, container]);
173
+ const onEnd = React.useCallback(() => {
174
+ const {
175
+ width: nodeWidth
176
+ } = node ? node.getBoundingClientRect() : {
177
+ width: 0
178
+ };
179
+ documentSelect.on('mousemove.swipe touchmove.swipe mouseup.swipe touchend.swipe', null);
180
+ body.style('cursor', null);
181
+
182
+ if (width > nodeWidth) {
183
+ container.style('cursor', 'grab');
184
+ } else {
185
+ container.style('cursor', null);
186
+ }
187
+
188
+ const dt = Date.now() - refs.current.timestamp;
189
+ const dtEnd = 44;
190
+
191
+ if (dt < dtEnd) {
192
+ animate({
193
+ duration: duration,
194
+ timing: animationFunc || easeOutQuad,
195
+ draw: (progress, requestId) => {
196
+ refs.current.animation = requestId;
197
+ const px = Math.round(refs.current.speed * 2 * progress);
198
+ const currX = refs.current.currentX + px;
199
+ const maxX = width - nodeWidth;
200
+ const translateX = range(currX, -maxX, 0);
201
+ const transX = Math.max(Math.min(currX, maxX), 0);
202
+
203
+ if (refs.current.currentX !== transX) {
204
+ container.style('transform', "translateX(" + translateX + "px)");
205
+ onSwipe && onSwipe(translateX, container);
206
+ }
207
+ }
208
+ });
209
+ }
210
+ }, [body, animationFunc, onSwipe, container, duration, node, width, documentSelect]);
211
+ const onStart = React.useCallback(event => {
212
+ const isTouch = event.type.includes('touch');
213
+ const [x] = d3.pointer(isTouch ? event.touches[0] : event, node);
214
+ const {
215
+ left
216
+ } = node && node.parentElement ? node.parentElement.getBoundingClientRect() : {
217
+ left: 0
218
+ };
219
+ body.style('cursor', 'grabbing');
220
+ container.style('cursor', 'grabbing');
221
+
222
+ if (refs.current.animation) {
223
+ cancelAnimationFrame(refs.current.animation);
224
+ refs.current = defaultRefs;
225
+ }
226
+
227
+ refs.current.startX = Math.max(x + left, 0);
228
+ documentSelect.on('mousemove.swipe touchmove.swipe', onMove);
229
+ documentSelect.on('mouseup.swipe touchend.swipe', onEnd);
230
+ }, [container, body, node, onEnd, onMove, documentSelect]);
231
+ React.useEffect(() => {
232
+ if (node) {
233
+ const {
234
+ width: nodeWidth
235
+ } = node.getBoundingClientRect();
236
+
237
+ if (width > nodeWidth) {
238
+ container.style('cursor', 'grab');
239
+ container.on('mousedown.swipe touchstart.swipe', onStart);
240
+ }
241
+ }
242
+ }, [container, onStart, node, width]);
243
+ };
244
+
245
+ const _excluded = ["children", "width", "onSwipe"];
246
+ const SwipeScroll = _ref => {
247
+ let {
248
+ children,
249
+ width,
250
+ onSwipe
251
+ } = _ref,
252
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
253
+
254
+ const [ref, draggingNode] = useNode();
255
+ useSwipe(draggingNode, _extends({
256
+ width,
257
+ onSwipe
258
+ }, props));
259
+ return React__default.createElement(SwipeScrollContainer, Object.assign({}, props), React__default.createElement("div", {
260
+ ref: ref
261
+ }, children));
262
+ };
263
+ SwipeScroll.defaultProps = {
264
+ duration: 1400
265
+ };
266
+
267
+ const degByIndex = (index, count) => {
268
+ const degs = 360;
269
+ const deg = degs / count * index;
270
+ return deg;
271
+ };
272
+
273
+ const getTextAnchor = (index, length) => {
274
+ const deg = degByIndex(index, length);
275
+ const halfAngle = 180;
276
+
277
+ if ([0, halfAngle].includes(deg)) {
278
+ return 'middle';
279
+ }
280
+
281
+ if (deg < halfAngle) {
282
+ return 'start';
283
+ }
284
+
285
+ return 'end';
286
+ };
287
+
288
+ var _templateObject$2;
289
+
290
+ const getTranslate = _ref => {
291
+ let {
292
+ anchor,
293
+ index,
294
+ translateX,
295
+ translateY
296
+ } = _ref;
297
+
298
+ if (index === 0 && anchor === 'middle') {
299
+ return "translate(calc(-50% + " + translateX + "px), calc(-100% + " + translateY + "px))";
300
+ } else if (anchor === 'middle') {
301
+ return "translate(calc(-50% + " + translateX + "px), calc(" + translateY + "px))";
302
+ } else if (anchor === 'start') {
303
+ return "translate(calc(" + translateX + "px), calc(-50% + " + translateY + "px))";
304
+ } else if (anchor === 'end') {
305
+ return "translate(calc(-100% + " + translateX + "px), calc(-50% + " + translateY + "px))";
306
+ }
307
+
308
+ return "translate(" + translateX + "px, " + translateY + "px)";
309
+ };
310
+
311
+ const LabelContainer = /*#__PURE__*/styled__default.div.attrs(props => ({
312
+ style: {
313
+ transform: getTranslate(props)
314
+ }
315
+ }))(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n"])));
316
+
317
+ const labelClassName = 'd3-chart-label';
318
+ const drawRadialLabels = _ref => {
319
+ let {
320
+ node,
321
+ dataLength,
322
+ radiusScale,
323
+ maxValue,
324
+ angleSlice,
325
+ radius,
326
+ xOffset,
327
+ yOffset,
328
+ translateX,
329
+ translateY,
330
+ renderLabel,
331
+ selectLabel
332
+ } = _ref;
333
+ const d3container = d3.select(node);
334
+ d3container.selectAll("." + labelClassName).remove();
335
+
336
+ const pxToValue = value => maxValue / radius * value;
337
+
338
+ const axisX = i => radiusScale(maxValue + pxToValue(xOffset || 0)) * Math.cos(angleSlice * i - Math.PI / 2);
339
+
340
+ const axisY = i => radiusScale((maxValue + pxToValue(yOffset || 0)) * Math.sin(angleSlice * i - Math.PI / 2));
341
+
342
+ const labels = Array.from({
343
+ length: dataLength
344
+ }, (_, index) => ({
345
+ x: Math.ceil(axisX(index)),
346
+ y: Math.ceil(axisY(index))
347
+ }));
348
+ labels.forEach((_ref2, index) => {
349
+ let {
350
+ x,
351
+ y
352
+ } = _ref2;
353
+ const anchor = getTextAnchor(index, dataLength);
354
+ const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer, {
355
+ anchor: anchor,
356
+ translateX: translateX || 0,
357
+ translateY: translateY || 0,
358
+ index: index,
359
+ style: {
360
+ left: x,
361
+ top: y
362
+ }
363
+ }, typeof renderLabel === 'function' ? renderLabel(anchor, index) : renderLabel));
364
+ const label = d3container.append('div').attr('class', labelClassName).html(html);
365
+ selectLabel(label, anchor, index);
366
+ });
367
+ };
368
+
369
+ var _templateObject$3, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
370
+ const getTranslate$1 = _ref => {
371
+ let {
372
+ anchor,
373
+ index,
374
+ translateX,
375
+ translateY
376
+ } = _ref;
377
+
378
+ if (index === 0 && anchor === 'middle') {
379
+ return "translate(calc(-50% + " + translateX + "px), calc(-100% + " + translateY + "px))";
380
+ } else if (anchor === 'middle') {
381
+ return "translate(calc(-50% + " + translateX + "px), calc(" + translateY + "px))";
382
+ } else if (anchor === 'start') {
383
+ return "translate(calc(" + translateX + "px), calc(-50% + " + translateY + "px))";
384
+ } else if (anchor === 'end') {
385
+ return "translate(calc(-100% + " + translateX + "px), calc(-50% + " + translateY + "px))";
386
+ }
387
+
388
+ return "translate(" + translateX + "px, " + translateY + "px)";
389
+ };
390
+ const Label = /*#__PURE__*/styled__default.div(_templateObject$3 || (_templateObject$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n font-size: 12px;\n"])));
391
+ const Name = /*#__PURE__*/styled__default.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: center;\n max-width: 120px;\n"])));
392
+ const middleBadgeStyles = /*#__PURE__*/styled.css(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 50%;\n right: 0;\n transform: translate(calc(100% + 6px), -50%);\n"])));
393
+ const DefaultBadge = /*#__PURE__*/styled__default.div(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n padding: 2px 4px;\n border-radius: 4px;\n color: rgb(255, 255, 255);\n background-color: rgb(144, 197, 61);\n margin-left: 8px;\n"])));
394
+ const MiddleBadge = /*#__PURE__*/styled__default(DefaultBadge)(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n ", "\n"])), middleBadgeStyles);
395
+ const BadgePrefix = /*#__PURE__*/styled__default.div(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-left: 4px;\n font-size: 10px;\n color: rgba(255, 255, 255, 0.54);\n"])));
396
+
397
+ var _templateObject$4;
398
+ const radarChartclassNames = {
399
+ radar: 'radar',
400
+ radarAxis: 'radarAxis',
401
+ radarAxisTextGlobal: 'radarAxisTextGlobal',
402
+ radarAxisText: 'radarAxisText',
403
+ radarPolygon: 'radarPolygon',
404
+ radarLabel: 'radarLabel',
405
+ radarLabelName: 'radarLabelName',
406
+ radarLabelBadge: 'radarLabelBadge',
407
+ radarLabelBadgePrefix: 'radarLabelBadgePrefix',
408
+ radarCircle: 'radarCircle'
409
+ };
410
+ const SvgWrapper = /*#__PURE__*/styled__default(Wrapper)(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n path,\n line,\n circle {\n fill: none;\n stroke-width: 1px;\n stroke: rgba(149, 149, 149, 0.18);\n }\n }\n .", " {\n font-size: 12px;\n fill-opacity: 0.56;\n }\n .", " {\n fill-opacity: 0.06;\n stroke-width: 2px;\n fill: rgb(144, 197, 61);\n stroke: rgb(144, 197, 61);\n }\n .", " {\n fill: rgb(144, 197, 61);\n }\n"])), radarChartclassNames.radarAxis, radarChartclassNames.radarAxisText, radarChartclassNames.radarPolygon, radarChartclassNames.radarCircle);
411
+
412
+ const draw = (node, props) => {
413
+ const {
414
+ data,
415
+ curve,
416
+ polar,
417
+ formatValue,
418
+ badgePrefix,
419
+ labelOffset,
420
+ circleRadius,
421
+ svgElements,
422
+ renderLabel: _renderLabel,
423
+ customize,
424
+ formatAxisValue,
425
+ radarStyles,
426
+ labelIndex,
427
+ selectLabel: _selectLabel
428
+ } = props;
429
+
430
+ if (node !== null && data.length) {
431
+ const defaultBleedLength = 10;
432
+ const bleedLength = typeof props.bleedLength === 'number' ? props.bleedLength : defaultBleedLength;
433
+ const {
434
+ width: nodeWidth
435
+ } = node.getBoundingClientRect();
436
+ const width = props.width || nodeWidth;
437
+ const defaultHeight = 400;
438
+ const height = props.height || defaultHeight;
439
+ const minValue = props.minValue || Math.min(0, d3.min(data, i => d3.min(i.map(_ref => {
440
+ let {
441
+ value
442
+ } = _ref;
443
+ return value;
444
+ }))));
445
+ const maxValue = (props.maxValue || Math.max(0, d3.max(data, i => d3.max(i.map(_ref2 => {
446
+ let {
447
+ value
448
+ } = _ref2;
449
+ return value;
450
+ }))))) - minValue;
451
+ const paddingX = props.paddingX || 0;
452
+ const paddingY = props.paddingY || 0;
453
+ const radius = Math.min((width - paddingX * 2 - bleedLength * 2) / 2, (height - paddingY * 2 - bleedLength * 2) / 2);
454
+ const defaultLevels = 4;
455
+ const ticks = d3.scaleLinear().domain([0, maxValue || 1]).range([]).ticks(props.levels || defaultLevels);
456
+ const lastTick = ticks[ticks.length - 1];
457
+ const newLastTick = lastTick + (ticks[1] - ticks[0]);
458
+
459
+ if (lastTick < maxValue) {
460
+ ticks.push(newLastTick);
461
+ }
462
+
463
+ const levels = props.levels || ticks.length - 1;
464
+ const newMaxValue = ticks[ticks.length - 1];
465
+ const angleSlice = Math.PI * 2 / data[0].length;
466
+ const radiusScale = d3.scaleLinear().range([0, radius]).domain([0, newMaxValue]);
467
+ const radarLine = d3.lineRadial().curve(d3.curveLinearClosed) // @ts-ignore
468
+ .radius(_ref3 => {
469
+ let {
470
+ value
471
+ } = _ref3;
472
+ return radiusScale(value);
473
+ }).angle((_, i) => i * angleSlice);
474
+ const radarValue = d3.lineRadial().curve(curve || d3.curveLinearClosed) // @ts-ignore
475
+ .radius(_ref4 => {
476
+ let {
477
+ value
478
+ } = _ref4;
479
+ return radiusScale(value);
480
+ }).angle((_, i) => i * angleSlice);
481
+ const svg = appendSvg(node, width, height);
482
+ const globalCenter = svg.append('g');
483
+ const levelsGrid = d3.range(1, levels + 1).reverse();
484
+
485
+ const axisGridY = value => -value * radius / levels;
486
+
487
+ const getAxisValue = value => newMaxValue * value / levels;
488
+
489
+ const gridGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarAxis).selectAll().data([data[0]]).enter();
490
+ const radarGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radar);
491
+ const axis = gridGlobal.selectAll().data(data[0].map(_ref5 => {
492
+ let {
493
+ name
494
+ } = _ref5;
495
+ return name;
496
+ })).enter();
497
+ let maxGridHeight = 0;
498
+
499
+ if (polar) {
500
+ levelsGrid.forEach(value => {
501
+ const path = gridGlobal.append('circle').attr('cx', 0).attr('cy', 0).attr('r', () => radius / levels * value);
502
+ const circleNode = path.node();
503
+ const circleHeight = circleNode.getBoundingClientRect().height;
504
+ maxGridHeight = Math.max(maxGridHeight, circleHeight);
505
+ });
506
+ } else {
507
+ levelsGrid.map(getAxisValue).forEach(value => {
508
+ const path = gridGlobal.append('path').attr('d', () => // @ts-ignore
509
+ radarLine(Array.from({
510
+ length: data[0].length
511
+ }, () => ({
512
+ value
513
+ }))));
514
+ const pathNode = path.node();
515
+ const pathHeight = pathNode.getBoundingClientRect().height;
516
+ maxGridHeight = Math.max(maxGridHeight, pathHeight);
517
+ });
518
+ }
519
+
520
+ const radiusByMaxValue = radiusScale(newMaxValue) + bleedLength;
521
+ axis.append('line').attr('x1', 0).attr('y1', 0).attr('x2', (_, i) => Math.round(radiusByMaxValue * Math.cos(angleSlice * i - Math.PI / 2))).attr('y2', (_, i) => Math.round(radiusByMaxValue * Math.sin(angleSlice * i - Math.PI / 2)));
522
+ radarGlobal.selectAll('path').data(data).join('path').attr('class', radarChartclassNames.radarPolygon).attr('style', (_, index) => (radarStyles == null ? void 0 : radarStyles[index]) || '').attr('d', d => radarValue( // @ts-ignore
523
+ d.map(dataItem => _extends({}, dataItem, {
524
+ value: dataItem.value - minValue
525
+ }))));
526
+ const format = d3.format(',');
527
+ const axisTextGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarAxisTextGlobal);
528
+ axisTextGlobal.selectAll('text').data(levelsGrid).enter().append('text').attr('class', radarChartclassNames.radarAxisText).attr('x', '4').attr('y', axisGridY).attr('dy', 0).attr('dominant-baseline', 'central').text((value, index) => {
529
+ const axisValue = getAxisValue(value) + minValue;
530
+ return formatAxisValue ? formatAxisValue(axisValue, index) : format(axisValue);
531
+ });
532
+ circleRadius && data.forEach(item => {
533
+ const circleGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarCircle);
534
+ item.forEach((_ref6, i) => {
535
+ let {
536
+ value
537
+ } = _ref6;
538
+ circleGlobal.append('circle').attr('cx', Math.round(radiusScale(value) * Math.cos(angleSlice * i - Math.PI / 2))).attr('cy', Math.round(radiusScale(value * Math.sin(angleSlice * i - Math.PI / 2)))).attr('r', circleRadius);
539
+ });
540
+ });
541
+ const defaultLabelOffset = 8;
542
+ const heightInner = height - bleedLength - paddingY;
543
+ const translateX = width / 2;
544
+ const translateY = heightInner / 2 + (heightInner - maxGridHeight) / 2;
545
+ const offset = bleedLength + (labelOffset || defaultLabelOffset);
546
+ globalCenter.attr('transform', "translate(" + translateX + "," + translateY + ")");
547
+ drawRadialLabels({
548
+ node,
549
+ maxValue: newMaxValue,
550
+ translateX,
551
+ translateY,
552
+ dataLength: data[labelIndex || 0].length,
553
+ angleSlice,
554
+ radius,
555
+ radiusScale,
556
+ xOffset: offset,
557
+ yOffset: offset,
558
+ renderLabel: (anchor, index) => {
559
+ const items = data.map(item => item[index]);
560
+ const Badge = anchor === 'middle' ? MiddleBadge : DefaultBadge;
561
+ const item = data[labelIndex || 0][index];
562
+ const {
563
+ name,
564
+ value
565
+ } = item;
566
+ return _renderLabel ? _renderLabel({
567
+ item,
568
+ items,
569
+ anchor,
570
+ index
571
+ }) : React__default.createElement(Label, {
572
+ className: radarChartclassNames.radarLabel
573
+ }, React__default.createElement(Name, {
574
+ className: radarChartclassNames.radarLabelName
575
+ }, name), React__default.createElement(Badge, {
576
+ className: radarChartclassNames.radarLabelBadge
577
+ }, formatValue ? formatValue(value, index) : format(value), badgePrefix && React__default.createElement(BadgePrefix, {
578
+ className: radarChartclassNames.radarLabelBadgePrefix
579
+ }, badgePrefix)));
580
+ },
581
+ selectLabel: (label, anchor, index) => {
582
+ if (_selectLabel) {
583
+ const items = data.map(item => item[index]);
584
+ const item = data[labelIndex || 0][index];
585
+
586
+ _selectLabel(label, {
587
+ index,
588
+ item,
589
+ items,
590
+ anchor
591
+ });
592
+ }
593
+ }
594
+ });
595
+
596
+ if (svgElements) {
597
+ const html = ReactDOMServer.renderToString(svgElements);
598
+ svg.append('g').html(html);
599
+ }
600
+
601
+ customize && customize(svg);
602
+ }
603
+ };
604
+
605
+ const RadarChart = props => {
606
+ const {
607
+ className,
608
+ style
609
+ } = props;
610
+ const [ref, node] = useNode();
611
+ React.useEffect(() => {
612
+ node && draw(node, props);
613
+ }, [node, props]);
614
+
615
+ const onDraw = () => draw(node, props);
616
+
617
+ useResize(props.width, onDraw);
618
+ return React__default.createElement("div", {
619
+ className: className,
620
+ style: style
621
+ }, React__default.createElement(SvgWrapper, {
622
+ ref: ref
623
+ }));
624
+ };
625
+ RadarChart.defaultProps = {
626
+ height: 400,
627
+ data: [],
628
+ curve: d3.curveLinearClosed
629
+ };
630
+
631
+ function radiansToDegrees(radians) {
632
+ const flatAngle = 180;
633
+ return radians * flatAngle / Math.PI;
634
+ }
635
+ function degreesToRadians(degrees) {
636
+ const flatAngle = 180;
637
+ return degrees * (Math.PI / flatAngle);
638
+ }
639
+
640
+ var _templateObject$5;
641
+ const pieChartclassNames = {
642
+ pieGlobal: 'pieGlobal',
643
+ pieSlice: 'pieSlice',
644
+ pieSliceLabel: 'pieSliceLabel',
645
+ pieSliceLabelValue: 'pieSliceLabelValue',
646
+ pieSliceLabelName: 'pieSliceLabelName',
647
+ pieRadialLabel: 'pieRadialLabel',
648
+ pieRadialLink: 'pieRadialLink',
649
+ pieTooltipContainer: 'pieTooltipContainer',
650
+ pieTooltipFlex: 'pieTooltipFlex',
651
+ pieTooltip: 'pieTooltip',
652
+ pieTooltipItem: 'pieTooltipItem',
653
+ pieTooltipName: 'pieTooltipName',
654
+ pieTooltipValue: 'pieTooltipValue',
655
+ pieTooltipColorBox: 'pieTooltipColorBox',
656
+ pieFullChartTooltipCircle: 'pieFullChartTooltipCircle'
657
+ };
658
+ const SvgWrapper$1 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$5 || (_templateObject$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n fill: #4a4a4a;\n }\n .", " {\n position: absolute;\n max-width: 128px;\n }\n .", " {\n stroke: #000;\n }\n .", " {\n fill: transparent;\n cursor: pointer;\n }\n"])), pieChartclassNames.pieSliceLabel, pieChartclassNames.pieRadialLabel, pieChartclassNames.pieRadialLink, pieChartclassNames.pieFullChartTooltipCircle);
659
+
660
+ const getMidFactor = d => d.startAngle + (d.endAngle - d.startAngle) / 2 < Math.PI ? 1 : -1;
661
+ const getAlign = d => {
662
+ const midangle = d.startAngle + (d.endAngle - d.startAngle) / 2;
663
+ return midangle < Math.PI ? 'start' : 'end';
664
+ };
665
+
666
+ const drawRadialLabels$1 = _ref => {
667
+ let {
668
+ arc,
669
+ enableRadialLabels,
670
+ global,
671
+ node,
672
+ radius,
673
+ dataReady,
674
+ radialLabelsLinkHorizontalLength,
675
+ formatRadialLabel,
676
+ radialLabelsTextXOffset,
677
+ translateX,
678
+ translateY,
679
+ radialLabelYOffset,
680
+ radialAngleXOffset
681
+ } = _ref;
682
+ const d3container = d3.select(node);
683
+ d3container.selectAll("." + pieChartclassNames.pieRadialLabel).remove();
684
+
685
+ if (enableRadialLabels) {
686
+ const defaultRadialLabelsLinkHorizontalLength = 4;
687
+ const outerArc = d3.arc().innerRadius(radius).outerRadius(radius);
688
+ global.selectAll('allPolylines').data(dataReady).enter().append('polyline').attr('class', pieChartclassNames.pieRadialLink).style('fill', 'none').attr('points', d => {
689
+ const midFactor = getMidFactor(d);
690
+ const posA = arc.centroid(d);
691
+ const posB = outerArc.centroid(d);
692
+ const posC = outerArc.centroid(d);
693
+ const posCPi = [(radius + (radialLabelsLinkHorizontalLength || defaultRadialLabelsLinkHorizontalLength)) * midFactor, posC[1]];
694
+ return [[posA[0], posA[1]], [posB[0] + (radialAngleXOffset || 0) * midFactor, posB[1] - (radialLabelYOffset || 0) * d.index], [posCPi[0], posCPi[1] - (radialLabelYOffset || 0) * d.index]];
695
+ });
696
+
697
+ const getPosition = d => {
698
+ const pos = outerArc.centroid(d);
699
+ return [(radius + (radialLabelsLinkHorizontalLength || defaultRadialLabelsLinkHorizontalLength)) * getMidFactor(d), pos[1]];
700
+ };
701
+
702
+ const defaultRadialLabelsTextXOffset = 4;
703
+ d3container.selectAll('allLabels').data(dataReady).enter().append('div') // @ts-ignore
704
+ .html(d => {
705
+ const html = ReactDOMServer.renderToString( // @ts-ignore
706
+ formatRadialLabel ? formatRadialLabel(d) : d.data.name);
707
+ return html;
708
+ }).attr('class', pieChartclassNames.pieRadialLabel) // @ts-ignore
709
+ .style('transform', d => getTranslate$1({
710
+ anchor: getAlign(d),
711
+ index: d.index,
712
+ translateX,
713
+ translateY: translateY - (radialLabelYOffset || 0) * d.index
714
+ })) // @ts-ignore
715
+ .style('left', // @ts-ignore
716
+ d => getPosition(d)[0] - (getAlign(d) === 'start' ? -(radialLabelsTextXOffset || defaultRadialLabelsTextXOffset) : radialLabelsTextXOffset || defaultRadialLabelsTextXOffset) + "px") // @ts-ignore
717
+ .style('top', d => getPosition(d)[1] + "px") // @ts-ignore
718
+ .style('text-align', getAlign);
719
+ }
720
+ };
721
+
722
+ var _templateObject$6, _templateObject2$1, _templateObject3$1, _templateObject4$1, _templateObject5$1, _templateObject6$1, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14;
723
+ const TooltipFlex = /*#__PURE__*/styled__default.div(_templateObject$6 || (_templateObject$6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n pointer-events: none;\n white-space: nowrap;\n"])));
724
+ const LabelFlex = /*#__PURE__*/styled__default(TooltipFlex)(_templateObject2$1 || (_templateObject2$1 = /*#__PURE__*/_taggedTemplateLiteralLoose([""])));
725
+ const LabelFlexCenter = /*#__PURE__*/styled__default(LabelFlex)(_templateObject3$1 || (_templateObject3$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n align-items: center;\n"])));
726
+ const TooltipContainer = /*#__PURE__*/styled__default.div(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n font-size: 11px;\n color: #fff;\n margin-bottom: 8px;\n padding: 4px 6px;\n background-color: rgba(48, 69, 79, 1);\n border-radius: 4px;\n box-shadow: 0 0.1875rem 0.5rem rgba(48, 69, 79, 0.06);\n :before {\n content: '';\n position: absolute;\n bottom: 0;\n left: 50%;\n transform: translate(-50%, 100%);\n width: 0;\n height: 0;\n border-style: solid;\n border-width: 4px 3px 0 3px;\n border-color: rgba(48, 69, 79, 1) transparent transparent transparent;\n }\n"])));
727
+ const TooltipGroupName = /*#__PURE__*/styled__default.div(_templateObject5$1 || (_templateObject5$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 14px;\n margin-bottom: 6px;\n"])));
728
+ const TooltipItem = /*#__PURE__*/styled__default.div(_templateObject6$1 || (_templateObject6$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-bottom: 0.25rem;\n &:last-of-type {\n margin-bottom: 0;\n }\n"])));
729
+ const ColFlex = /*#__PURE__*/styled__default.div(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-right: 4px;\n"])));
730
+ const ColorBox = /*#__PURE__*/styled__default.div(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: 4px;\n width: 10px;\n height: 10px;\n border-radius: 2px;\n"])));
731
+ const ColorLine = /*#__PURE__*/styled__default(ColorBox)(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n height: 2px;\n border-radius: 0;\n"])));
732
+ const Name$1 = /*#__PURE__*/styled__default.div(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: 4px;\n"])));
733
+ const Value = /*#__PURE__*/styled__default.div(_templateObject11 || (_templateObject11 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: right;\n flex-shrink: 0;\n flex-grow: 1;\n"])));
734
+ const Label$1 = /*#__PURE__*/styled__default.div(_templateObject12 || (_templateObject12 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n font-size: 11px;\n color: #fff;\n font-weight: bold;\n letter-spacing: 0.52px;\n"])));
735
+ const LabelTop = /*#__PURE__*/styled__default(Label$1)(_templateObject13 || (_templateObject13 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n top: 6px;\n"])));
736
+ const LabelBottom = /*#__PURE__*/styled__default(Label$1)(_templateObject14 || (_templateObject14 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n bottom: 6px;\n"])));
737
+
738
+ const drawTooltip = _ref => {
739
+ let {
740
+ fullChartTooltip,
741
+ global,
742
+ tooltipRoot,
743
+ data,
744
+ tooltipClassName,
745
+ tooltipBind,
746
+ renderTooltip,
747
+ arc,
748
+ allSlices,
749
+ tooltipStyle,
750
+ width,
751
+ height,
752
+ radius
753
+ } = _ref;
754
+ const container = tooltipRoot || document.querySelector('body');
755
+ const format = d3.format(',');
756
+ const pieTooltipContainer = d3.select(container).select("." + pieChartclassNames.pieTooltipContainer);
757
+ const isEmpty = pieTooltipContainer.empty();
758
+ const tooltipContainer = isEmpty ? d3.select(container).append('div').attr('class', pieChartclassNames.pieTooltipContainer + " " + (tooltipClassName || '')).style('position', 'absolute').style('opacity', '0').style('z-index', '103') : pieTooltipContainer;
759
+
760
+ if (tooltipStyle) {
761
+ Object.entries(tooltipStyle).forEach(_ref2 => {
762
+ let [prop, val] = _ref2;
763
+ return tooltipContainer.style(prop, val);
764
+ });
765
+ }
766
+
767
+ tooltipContainer.html('');
768
+ let isVisible = false;
769
+
770
+ const setVisible = visible => {
771
+ isVisible = Boolean(visible);
772
+ const opacity = isVisible ? '1' : '0';
773
+ tooltipContainer.style('opacity', opacity);
774
+ };
775
+
776
+ const setPosition = (event, pieChartDatum) => {
777
+ let [x, y] = d3.pointer(event, document);
778
+
779
+ if (!tooltipBind && fullChartTooltip) {
780
+ const [itemX, itemY] = d3.pointer(event, event.target);
781
+ x = x - itemX;
782
+ y = y - itemY;
783
+ } else if (!tooltipBind) {
784
+ const globalNode = global.node();
785
+ const {
786
+ x: itemX,
787
+ y: itemY,
788
+ width: itemWidth,
789
+ height: itemHeight
790
+ } = globalNode ? globalNode.getBoundingClientRect() : {
791
+ x: 0,
792
+ y: 0,
793
+ width: 0,
794
+ height: 0
795
+ };
796
+ const [arcX, arcY] = arc.centroid(pieChartDatum);
797
+ x = itemX + itemWidth / 2 + arcX;
798
+ y = itemY + itemHeight / 2 + arcY;
799
+ }
800
+
801
+ tooltipContainer.style('left', x + 'px').style('top', y + 'px');
802
+ };
803
+
804
+ const setTooltip = (event, pieChartDatum) => {
805
+ setVisible(true);
806
+ setPosition(event, pieChartDatum);
807
+ const pieChartData = pieChartDatum ? [pieChartDatum.data] : data;
808
+ tooltipContainer.html(() => {
809
+ const html = ReactDOMServer.renderToString(React__default.createElement(TooltipFlex, {
810
+ className: pieChartclassNames.pieTooltipFlex
811
+ }, React__default.createElement(TooltipContainer, {
812
+ className: pieChartclassNames.pieTooltip
813
+ }, renderTooltip ? renderTooltip(pieChartData) : React__default.createElement(React__default.Fragment, null, pieChartData.map((_ref3, index) => {
814
+ let {
815
+ color,
816
+ name,
817
+ value
818
+ } = _ref3;
819
+ return React__default.createElement(TooltipItem, {
820
+ key: name + "-" + index,
821
+ className: pieChartclassNames.pieTooltipItem
822
+ }, color && React__default.createElement(ColorBox, {
823
+ className: pieChartclassNames.pieTooltipColorBox,
824
+ style: {
825
+ backgroundColor: color
826
+ }
827
+ }), name && React__default.createElement(Name$1, {
828
+ className: pieChartclassNames.pieTooltipName
829
+ }, name), React__default.createElement(Value, {
830
+ className: pieChartclassNames.pieTooltipValue
831
+ }, format(value)));
832
+ })))));
833
+ return html;
834
+ });
835
+ };
836
+
837
+ if (fullChartTooltip) {
838
+ global.on('mouseover.fulltooltip', event => setTooltip(event));
839
+ global.on('mouseout.fulltooltip', () => {
840
+ tooltipContainer.html('');
841
+ setVisible();
842
+ });
843
+
844
+ if (width && height) {
845
+ global.append('circle').attr('class', pieChartclassNames.pieFullChartTooltipCircle).attr('r', radius).attr('cx', 0).attr('cy', 0);
846
+ }
847
+
848
+ if (!tooltipBind) {
849
+ global.on('touchmove.tooltipBind mousemove.tooltipBind', event => setPosition(event));
850
+ }
851
+ } else {
852
+ allSlices.on('mouseover.slice', setTooltip);
853
+
854
+ if (!tooltipBind) {
855
+ allSlices.on('touchmove.slice mousemove.slice', setPosition);
856
+ }
857
+
858
+ allSlices.on('mouseout.slice', () => {
859
+ tooltipContainer.html('');
860
+ setVisible();
861
+ });
862
+ }
863
+ };
864
+
865
+ const draw$1 = (node, props) => {
866
+ const {
867
+ data,
868
+ padAngle,
869
+ onClick,
870
+ outerRadius,
871
+ startAngle,
872
+ endAngle,
873
+ cornerRadius,
874
+ margin,
875
+ enableSlicesLabels,
876
+ formatSliceLabel,
877
+ slicesLabelsSkipAngle,
878
+ enableSlicesLabelsName,
879
+ formatSliceLabelName,
880
+ borderWidth,
881
+ borderColor,
882
+ enableRadialLabels,
883
+ backgroundColor,
884
+ radialLabelsLinkHorizontalLength,
885
+ radialLabelsTextXOffset,
886
+ formatRadialLabel,
887
+ radialLabelYOffset,
888
+ svgElements,
889
+ formatSliceTitle,
890
+ radialAngleXOffset,
891
+ withTooltip,
892
+ fullChartTooltip,
893
+ tooltipClassName,
894
+ tooltipBind,
895
+ renderTooltip,
896
+ tooltipStyle
897
+ } = props;
898
+
899
+ if (node !== null && data.length) {
900
+ const marginTop = margin ? margin.top : 0;
901
+ const marginRight = margin ? margin.right : 0;
902
+ const marginBottom = margin ? margin.bottom : 0;
903
+ const marginLeft = margin ? margin.left : 0;
904
+ const {
905
+ width: nodeWidth
906
+ } = node.getBoundingClientRect();
907
+ const width = props.width || nodeWidth;
908
+ const defaultHeight = 240;
909
+ const height = props.height || defaultHeight;
910
+ const radius = (Math.min(width, height) - (borderWidth || 0) * 2 - (width > height ? marginTop + marginBottom : marginRight + marginLeft)) / 2;
911
+ const svg = appendSvg(node, width, height);
912
+ const global = svg.append('g').attr('class', pieChartclassNames.pieGlobal).attr('transform', "translate(" + ((width - (marginLeft + marginRight)) / 2 + marginLeft) + "," + ((height - (marginBottom + marginTop)) / 2 + marginTop) + ")");
913
+ const maxPadAngle = 45;
914
+ const dividerPadAngle = 100;
915
+ const fullAngle = 360;
916
+ const pie = d3.pie().startAngle(-degreesToRadians(startAngle || 0)).endAngle(degreesToRadians(endAngle || fullAngle)).padAngle(padAngle ? Math.max(Math.min(padAngle / dividerPadAngle, maxPadAngle), 0) : 0).sort(null) // @ts-ignore
917
+ .value(_ref => {
918
+ let {
919
+ value
920
+ } = _ref;
921
+ return value;
922
+ }); // @ts-ignore
923
+
924
+ const dataReady = pie(data);
925
+ const maxOuterRadius = 0.95;
926
+ const arc = d3.arc().cornerRadius(cornerRadius || 0).innerRadius(radius).outerRadius(radius * Math.min(Math.max(outerRadius || 0, 0), maxOuterRadius));
927
+
928
+ if (typeof backgroundColor === 'string') {
929
+ global.append('path').attr('fill', backgroundColor).attr('d', () => // @ts-ignore
930
+ arc({
931
+ startAngle: degreesToRadians(0),
932
+ endAngle: degreesToRadians(fullAngle)
933
+ }));
934
+ }
935
+
936
+ const format = d3.format(',');
937
+ const allSlices = global.selectAll('allSlices').data(dataReady).enter().append('path') // @ts-ignore
938
+ .attr('d', arc);
939
+ allSlices.attr('class', pieChartclassNames.pieSlice).attr('fill', _ref2 => {
940
+ let {
941
+ index
942
+ } = _ref2;
943
+ return data[index].color || '';
944
+ }).attr('stroke', borderColor || '').attr('stroke-width', borderWidth || 0).attr('style', onClick ? 'cursor: pointer' : '').on('click', // @ts-ignore
945
+ (_, d) => onClick && onClick(data[d.index])).append('svg:title').text(d => formatSliceTitle ? // @ts-ignore
946
+ formatSliceTitle(d) : fullChartTooltip || withTooltip ? '' : (data[d.index].name || '') + " (" + format(data[d.index].value) + ")");
947
+
948
+ if (enableSlicesLabels) {
949
+ const text = global.selectAll('allSlices').data(dataReady).enter().append('text').attr('class', pieChartclassNames.pieSliceLabel).attr('text-anchor', 'middle').attr('dominant-baseline', 'central').attr('transform', // @ts-ignore
950
+ d => 'translate(' + arc.centroid(d) + ')');
951
+ text.append('tspan').attr('class', pieChartclassNames.pieSliceLabelValue) // @ts-ignore
952
+ .text(d => {
953
+ const deg = radiansToDegrees(d.endAngle - d.startAngle);
954
+
955
+ if (!slicesLabelsSkipAngle || deg > slicesLabelsSkipAngle) {
956
+ return formatSliceLabel ? formatSliceLabel(d) : d.value;
957
+ }
958
+ });
959
+
960
+ if (enableSlicesLabelsName) {
961
+ text.append('tspan').attr('class', pieChartclassNames.pieSliceLabelName) // @ts-ignore
962
+ .text(d => formatSliceLabelName ? formatSliceLabelName(d) : d.data.name).attr('x', '0').attr('dy', '1.2em');
963
+ }
964
+ }
965
+
966
+ drawRadialLabels$1({
967
+ arc,
968
+ enableRadialLabels,
969
+ global,
970
+ radius,
971
+ node,
972
+ dataReady,
973
+ translateX: (width - (marginLeft - marginRight)) / 2,
974
+ translateY: (height + (marginTop - marginBottom)) / 2,
975
+ radialLabelsLinkHorizontalLength,
976
+ radialLabelsTextXOffset,
977
+ formatRadialLabel,
978
+ radialLabelYOffset,
979
+ radialAngleXOffset
980
+ });
981
+
982
+ if (withTooltip || fullChartTooltip) {
983
+ drawTooltip({
984
+ fullChartTooltip,
985
+ global,
986
+ data,
987
+ tooltipClassName,
988
+ tooltipBind,
989
+ renderTooltip,
990
+ allSlices,
991
+ arc,
992
+ tooltipStyle,
993
+ width,
994
+ height,
995
+ radius
996
+ });
997
+ }
998
+
999
+ if (svgElements) {
1000
+ const html = ReactDOMServer.renderToString(svgElements);
1001
+ svg.append('g').html(html);
1002
+ }
1003
+ }
1004
+ };
1005
+
1006
+ const PieChart = props => {
1007
+ const {
1008
+ className,
1009
+ style,
1010
+ children
1011
+ } = props;
1012
+ const [ref, node] = useNode();
1013
+ React.useEffect(() => {
1014
+ node && draw$1(node, props);
1015
+ }, [node, props]);
1016
+
1017
+ const onDraw = () => draw$1(node, props);
1018
+
1019
+ useResize(props.width, onDraw);
1020
+ return React__default.createElement("div", {
1021
+ className: className,
1022
+ style: style
1023
+ }, React__default.createElement(SvgWrapper$1, {
1024
+ ref: ref
1025
+ }, children));
1026
+ };
1027
+ PieChart.defaultProps = {
1028
+ data: [],
1029
+ startAngle: 0,
1030
+ endAngle: 360,
1031
+ slicesLabelsSkipAngle: 0,
1032
+ radialLabelYOffset: 16,
1033
+ radialAngleXOffset: 8
1034
+ };
1035
+
1036
+ const defaultN = 256;
1037
+ const legendClassNames = {
1038
+ legendContainer: 'd3-legend-container',
1039
+ legendTitle: 'd3-legend-title',
1040
+ legendTick: 'd3-legend-tick',
1041
+ legendTickLine: 'd3-legend-tick-line',
1042
+ legendTickText: 'd3-legend-tick-text'
1043
+ };
1044
+
1045
+ function ramp(color, n) {
1046
+ if (n === void 0) {
1047
+ n = defaultN;
1048
+ }
1049
+
1050
+ const canvas = document.createElement('canvas');
1051
+ canvas.width = n;
1052
+ canvas.height = 1;
1053
+ const context = canvas.getContext('2d');
1054
+
1055
+ for (let i = 0; i < n; ++i) {
1056
+ context.fillStyle = color(i / (n - 1));
1057
+ context.fillRect(i, 0, 1, 1);
1058
+ }
1059
+
1060
+ return canvas;
1061
+ }
1062
+
1063
+ const legendDefaultParams = {
1064
+ tickSize: 6,
1065
+ height: 44,
1066
+ width: 320,
1067
+ marginTop: 18,
1068
+ marginBottom: 16,
1069
+ ticksDivier: 64,
1070
+ titleMarginBottom: 6
1071
+ };
1072
+ const getLegend = _ref => {
1073
+ let {
1074
+ color,
1075
+ title,
1076
+ tickSize = legendDefaultParams.tickSize,
1077
+ width = legendDefaultParams.width,
1078
+ height = legendDefaultParams.height + tickSize,
1079
+ marginTop = legendDefaultParams.marginTop,
1080
+ marginRight = 0,
1081
+ marginBottom = legendDefaultParams.marginBottom + tickSize,
1082
+ marginLeft = 0,
1083
+ ticks = legendDefaultParams.width / legendDefaultParams.ticksDivier,
1084
+ tickFormat,
1085
+ tickValues,
1086
+ titleMarginBottom
1087
+ } = _ref;
1088
+ const svg = d3.create('svg').attr('width', width).attr('height', height) // @ts-ignore
1089
+ .attr('viewBox', [0, 0, width, height]).style('overflow', 'visible').style('display', 'block');
1090
+
1091
+ let tickAdjust = g => {
1092
+ const tick = g.selectAll('.tick');
1093
+ tick.selectAll('.tick line').attr('y1', marginTop + marginBottom - height).attr('class', legendClassNames.legendTickLine);
1094
+ tick.selectAll('.tick text').attr('class', legendClassNames.legendTickText);
1095
+ tick.attr('class', legendClassNames.legendTick);
1096
+ return tick;
1097
+ };
1098
+
1099
+ let x; // Continuous
1100
+
1101
+ if (color.interpolate) {
1102
+ const n = Math.min(color.domain().length, color.range().length);
1103
+ x = color.copy().rangeRound(d3.quantize(d3.interpolate(marginLeft, width - marginRight), n));
1104
+ svg.append('image').attr('x', marginLeft).attr('y', marginTop).attr('class', legendClassNames.legendContainer).attr('width', width - marginLeft - marginRight).attr('height', height - marginTop - marginBottom).attr('preserveAspectRatio', 'none').attr('xlink:href', ramp(color.copy().domain(d3.quantize(d3.interpolate(0, 1), n))).toDataURL());
1105
+ } // Sequential
1106
+ else if (color.interpolator) {
1107
+ x = Object.assign(color.copy().interpolator(d3.interpolateRound(marginLeft, width - marginRight)), {
1108
+ range() {
1109
+ return [marginLeft, width - marginRight];
1110
+ }
1111
+
1112
+ });
1113
+ svg.append('image').attr('x', marginLeft).attr('y', marginTop).attr('width', width - marginLeft - marginRight).attr('height', height - marginTop - marginBottom).attr('preserveAspectRatio', 'none').attr('xlink:href', ramp(color.interpolator()).toDataURL()); // scaleSequentialQuantile doesn’t implement ticks or tickFormat.
1114
+
1115
+ if (!x.ticks) {
1116
+ if (tickValues === undefined) {
1117
+ const n = Math.round(ticks + 1);
1118
+ tickValues = d3.range(n).map(i => d3.quantile(color.domain(), i / (n - 1)));
1119
+ }
1120
+
1121
+ if (typeof tickFormat !== 'function') {
1122
+ tickFormat = d3.format(tickFormat === undefined ? ',f' : tickFormat);
1123
+ }
1124
+ }
1125
+ }
1126
+
1127
+ svg.append('g').attr('transform', "translate(0," + (height - marginBottom) + ")").call(d3.axisBottom(x).ticks(ticks, typeof tickFormat === 'string' ? tickFormat : undefined) // @ts-ignore
1128
+ .tickFormat(typeof tickFormat === 'function' ? tickFormat : undefined).tickSize(tickSize) // @ts-ignore
1129
+ .tickValues(tickValues)).call(tickAdjust).call(g => g.select('.domain').remove()).call(g => g.append('text').attr('x', marginLeft).attr('class', legendClassNames.legendTitle).attr('y', marginTop + marginBottom - height - (titleMarginBottom || legendDefaultParams.titleMarginBottom)).attr('fill', 'currentColor').attr('text-anchor', 'start').attr('font-weight', 'bold').text(title));
1130
+ return svg;
1131
+ };
1132
+
1133
+ var _templateObject$7;
1134
+ const calendarChartClassNames = /*#__PURE__*/_extends({
1135
+ calendarChart: 'calendarChart',
1136
+ calendarYear: 'calendarYear',
1137
+ calendarAxis: 'calendarAxis',
1138
+ calendarBody: 'calendarBody',
1139
+ calendarHeader: 'calendarHeader',
1140
+ calendarYearTitle: 'calendarYearTitle',
1141
+ calendarWeekDay: 'calendarWeekDay',
1142
+ calendarMonth: 'calendarMonth',
1143
+ calendarDays: 'calendarDays',
1144
+ calendarDay: 'calendarDay'
1145
+ }, legendClassNames);
1146
+ const headerHeight = '20px';
1147
+ const SvgWrapper$2 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$7 || (_templateObject$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n display: flex;\n margin-bottom: 16px;\n }\n .", " {\n display: inline-flex;\n align-items: flex-end;\n height: ", ";\n margin-bottom: 4px;\n font-weight: bold;\n }\n .", " {\n height: ", ";\n margin-bottom: 4px;\n position: relative;\n display: flex;\n }\n .", " {\n font-size: 14px;\n bottom: 0;\n position: absolute;\n }\n .", " {\n display: flex;\n flex-direction: column;\n margin-right: 10px;\n }\n .", " {\n font-size: 12px;\n display: inline-flex;\n align-items: center;\n justify-content: flex-end;\n }\n .", " {\n position: relative;\n }\n .", " {\n position: absolute;\n }\n"])), calendarChartClassNames.calendarYear, calendarChartClassNames.calendarYearTitle, headerHeight, calendarChartClassNames.calendarHeader, headerHeight, calendarChartClassNames.calendarMonth, calendarChartClassNames.calendarAxis, calendarChartClassNames.calendarWeekDay, calendarChartClassNames.calendarDays, calendarChartClassNames.calendarDay);
1148
+
1149
+ const draw$2 = (node, props) => {
1150
+ const {
1151
+ data,
1152
+ startSunday,
1153
+ weekdays,
1154
+ interpolator,
1155
+ monthSpacing,
1156
+ onEachDay,
1157
+ colorRange,
1158
+ legendProps
1159
+ } = props;
1160
+
1161
+ if (node !== null && data.length) {
1162
+ const years = d3.group(data, d => d.date.getUTCFullYear());
1163
+ const cellOffset = typeof props.cellOffset === 'number' ? props.cellOffset : 0;
1164
+ const weekDays = 7;
1165
+ const defaultCellSize = 18;
1166
+ const cellSize = props.cellSize || defaultCellSize;
1167
+
1168
+ const countDay = i => startSunday ? i : (i + (weekDays - 1)) % weekDays;
1169
+
1170
+ const days = weekdays || ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'];
1171
+ const sundayIndex = 6;
1172
+
1173
+ const formatDay = i => startSunday ? days[i] : i === sundayIndex ? days[0] : days[i + 1];
1174
+
1175
+ const formatDate = d3.utcFormat('%x');
1176
+ const timeWeek = startSunday ? d3.utcSunday : d3.utcMonday;
1177
+
1178
+ const getTimeWeekCount = (from, to) => timeWeek.count(d3.utcYear(from), to);
1179
+
1180
+ const getMonthSpacing = date => date.getUTCMonth() * (monthSpacing || 0);
1181
+
1182
+ const formatMonth = d3.utcFormat('%b');
1183
+ const max = d3.max(data.map(_ref => {
1184
+ let {
1185
+ value
1186
+ } = _ref;
1187
+ return value;
1188
+ }));
1189
+ const min = d3.min(data.map(_ref2 => {
1190
+ let {
1191
+ value
1192
+ } = _ref2;
1193
+ return value;
1194
+ }));
1195
+ const color = colorRange ? d3.scaleLinear().domain([min, max]) // @ts-ignore
1196
+ .range(colorRange) : d3.scaleSequential(interpolator || d3.interpolateGreens).domain([min, +max]);
1197
+ let chartWidth = 0;
1198
+ years.forEach((values, year) => {
1199
+ const min = new Date(year, 1);
1200
+ const max = d3.max(values.map(d => d.date));
1201
+ const months = max.getUTCMonth() - min.getUTCMonth();
1202
+ const weekCount = getTimeWeekCount(min, max) + 1;
1203
+ const width = weekCount * (cellSize + cellOffset) + (monthSpacing || 0) * months;
1204
+ chartWidth = Math.max(chartWidth, width);
1205
+ });
1206
+ d3.select(node).select("." + calendarChartClassNames.calendarChart).remove();
1207
+ const container = d3.select(node).append('div').attr('class', calendarChartClassNames.calendarChart);
1208
+ const year = container.selectAll('div') // @ts-ignore
1209
+ .data(years).join('div').attr('class', calendarChartClassNames.calendarYear);
1210
+ const calendarWeekdays = year.append('div').attr('class', calendarChartClassNames.calendarAxis);
1211
+ calendarWeekdays.append('div').attr('class', calendarChartClassNames.calendarYearTitle) // @ts-ignore
1212
+ .text(_ref3 => {
1213
+ let [key] = _ref3;
1214
+ return key;
1215
+ });
1216
+ calendarWeekdays.selectAll('span').data(d3.range(weekDays)).join('div').attr('class', calendarChartClassNames.calendarWeekDay).style('height', cellSize + 'px').style('margin-bottom', cellOffset + 'px').text(formatDay);
1217
+ const body = year.append('div').attr('class', calendarChartClassNames.calendarBody);
1218
+ const header = body.append('div').attr('class', calendarChartClassNames.calendarHeader);
1219
+ header.selectAll('div') // @ts-ignore
1220
+ .data(_ref4 => {
1221
+ let [_, values] = _ref4;
1222
+ const fullYearlastMonth = 12;
1223
+ const fullYearlastDate = 31;
1224
+ return d3.utcMonths(d3.utcMonth(new Date(values[0].date.getUTCFullYear(), 1, 1)), d3.utcMonth(new Date(values[0].date.getUTCFullYear(), fullYearlastMonth, fullYearlastDate)));
1225
+ }).join('div').attr('class', calendarChartClassNames.calendarMonth).style('left', d => getTimeWeekCount(d, timeWeek.ceil(d)) * (cellSize + cellOffset) + getMonthSpacing(d) + 'px') // @ts-ignore
1226
+ .text(formatMonth); // @ts-ignore
1227
+
1228
+ body.append('div').attr('class', calendarChartClassNames.calendarDays).style('height', (cellSize + cellOffset) * weekDays + 'px').style('width', chartWidth + 'px').selectAll('div') // @ts-ignore
1229
+ .data(_ref5 => {
1230
+ let [, values] = _ref5;
1231
+ return values;
1232
+ }).join('div') // @ts-ignore
1233
+ .each((data, index, elements) => {
1234
+ if (onEachDay) {
1235
+ const element = elements[index];
1236
+ const currColor = color(data.value);
1237
+ onEachDay(data, element, currColor);
1238
+ }
1239
+ }).attr('class', calendarChartClassNames.calendarDay).style('width', cellSize + 'px').style('height', cellSize + 'px') // @ts-ignore
1240
+ .style('left', d => getTimeWeekCount(d.date, d.date) * (cellSize + cellOffset) + getMonthSpacing(d.date) + 'px').style('top', // @ts-ignore
1241
+ d => countDay(d.date.getUTCDay()) * (cellSize + cellOffset) + 'px') // @ts-ignore
1242
+ .style('background-color', d => color(d.value)) // @ts-ignore
1243
+ .attr('title', d => formatDate(d.date) + " - " + d.value);
1244
+
1245
+ if (typeof legendProps === 'object') {
1246
+ const legend = getLegend(_extends({
1247
+ color: color
1248
+ }, legendProps));
1249
+ const containerNode = container.node();
1250
+ const legendSvg = legend.node();
1251
+ containerNode.appendChild(legendSvg);
1252
+ }
1253
+ }
1254
+ };
1255
+
1256
+ const CalendarChart = props => {
1257
+ const {
1258
+ className,
1259
+ style,
1260
+ children,
1261
+ data,
1262
+ startSunday,
1263
+ weekdays,
1264
+ cellOffset,
1265
+ cellSize,
1266
+ interpolator,
1267
+ monthSpacing,
1268
+ colorRange,
1269
+ legendProps
1270
+ } = props;
1271
+ const [ref, node] = useNode();
1272
+ React.useEffect(() => {
1273
+ node && draw$2(node, props); // eslint-disable-next-line
1274
+ }, [node, data, startSunday, weekdays, cellOffset, cellSize, interpolator, monthSpacing, colorRange, legendProps]);
1275
+ return React__default.createElement(SvgWrapper$2, {
1276
+ ref: ref,
1277
+ className: className,
1278
+ style: style
1279
+ }, children);
1280
+ };
1281
+ CalendarChart.defaultProps = {
1282
+ data: []
1283
+ };
1284
+
1285
+ function computeDimensions(selection) {
1286
+ let dimensions;
1287
+ const node = selection.node();
1288
+
1289
+ if (node instanceof SVGGraphicsElement) {
1290
+ // check if node is svg element
1291
+ dimensions = node.getBBox();
1292
+ } else {
1293
+ // else is html element
1294
+ dimensions = node.getBoundingClientRect();
1295
+ }
1296
+
1297
+ return dimensions;
1298
+ }
1299
+
1300
+ function none() {
1301
+ return;
1302
+ }
1303
+ function isVoid(value) {
1304
+ return value === undefined || value === null || Number.isNaN(value);
1305
+ }
1306
+
1307
+ const stackedData = data => {
1308
+ const stacks = {};
1309
+ return data.map((item, index) => {
1310
+ stacks[index] = {};
1311
+
1312
+ if (index > 0) {
1313
+ return _extends({}, item, {
1314
+ values: item.values.map((value, valuesIndex) => {
1315
+ const prevValue = stacks[index - 1][valuesIndex];
1316
+ stacks[index][valuesIndex] = Number((typeof prevValue !== 'number' ? 0 : Math.abs(prevValue)) + (typeof value !== 'number' ? 0 : Math.abs(value)));
1317
+ return stacks[index][valuesIndex];
1318
+ })
1319
+ });
1320
+ } else {
1321
+ item.values.forEach((value, valuesIndex) => {
1322
+ stacks[index][valuesIndex] = Number(value);
1323
+ });
1324
+ }
1325
+
1326
+ return item;
1327
+ });
1328
+ };
1329
+
1330
+ var _templateObject$8, _templateObject2$2;
1331
+ const lineChartClassNames = {
1332
+ lineChartYScaleGlobal: 'lineChartYScaleGlobal',
1333
+ lineChartYScaleRight: 'lineChartYScaleRight',
1334
+ lineChartXScaleGlobal: 'lineChartXScaleGlobal',
1335
+ lineChartLinesGlobal: 'lineChartLinesGlobal',
1336
+ lineChartLine: 'lineChartLine',
1337
+ lineChartAreasGlobal: 'lineChartAreasGlobal',
1338
+ lineChartArea: 'lineChartArea',
1339
+ lineChartDotsGlobalContainer: 'lineChartDotsGlobalContainer',
1340
+ lineChartDotsGlobal: 'lineChartDotsGlobal',
1341
+ lineChartDot: 'lineChartDot',
1342
+ lineChartGridGlobal: 'lineChartGridGlobal',
1343
+ lineChartGridLineX: 'lineChartGridLineX',
1344
+ lineChartGridLineY: 'lineChartGridLineY',
1345
+ lineChartLabelContainer: 'lineChartLabelContainer',
1346
+ lineChartLabelFlex: 'lineChartLabelFlex',
1347
+ lineChartLabel: 'lineChartLabel',
1348
+ lineChartMouseGlobal: 'lineChartMouseGlobal',
1349
+ lineChartMouseLine: 'lineChartMouseLine',
1350
+ lineChartMouseRect: 'lineChartMouseRect',
1351
+ lineChartMouseCircle: 'lineChartMouseCircle',
1352
+ lineChartMouseLabelContainer: 'lineChartMouseLabelContainer',
1353
+ lineChartMouseLabel: 'lineChartMouseLabel'
1354
+ };
1355
+ const SvgWrapper$3 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$8 || (_templateObject$8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", ",\n .", ",\n .", " {\n shape-rendering: crispEdges;\n }\n .", " {\n fill: none;\n stroke: steelblue;\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n .", " {\n fill-opacity: 0.24;\n }\n .", ",\n .", ",\n .", " {\n stroke: rgba(149, 149, 149, 0.24);\n }\n .", ",\n .", " {\n transition: opacity linear 200ms;\n pointer-events: none;\n stroke-width: 1px;\n }\n .", " {\n stroke: #fff;\n stroke-width: 2px;\n }\n .", " {\n shape-rendering: crispEdges;\n }\n .", " {\n fill: none;\n pointer-events: all;\n }\n"])), lineChartClassNames.lineChartYScaleGlobal, lineChartClassNames.lineChartXScaleGlobal, lineChartClassNames.lineChartGridGlobal, lineChartClassNames.lineChartLinesGlobal, lineChartClassNames.lineChartArea, lineChartClassNames.lineChartGridLineX, lineChartClassNames.lineChartGridLineY, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseCircle, lineChartClassNames.lineChartDot, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseRect);
1356
+ const TooltipStyles = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n transition: opacity linear 200ms;\n z-index: 100;\n .", " {\n justify-content: flex-start;\n align-items: center;\n pointer-events: none;\n }\n .", " {\n margin: 0 0 0 10px;\n }\n }\n"])), lineChartClassNames.lineChartMouseLabel, lineChartClassNames.lineChartLabelFlex, lineChartClassNames.lineChartLabel);
1357
+
1358
+ const drawGrid = _ref => {
1359
+ let {
1360
+ svg,
1361
+ yScale,
1362
+ xScale,
1363
+ yTicksCount,
1364
+ lastIndex,
1365
+ drawGridX,
1366
+ drawGridY
1367
+ } = _ref;
1368
+ if (!drawGridY && !drawGridX) return;
1369
+ const global = svg.append('g').attr('class', lineChartClassNames.lineChartGridGlobal);
1370
+ const yTicks = yScale.ticks(yTicksCount);
1371
+
1372
+ if (drawGridX) {
1373
+ global.append('g').selectAll('line').data(yTicks).join('line').attr('class', lineChartClassNames.lineChartGridLineX).attr('x1', () => xScale(0)).attr('x2', () => xScale(lastIndex)).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
1374
+ }
1375
+
1376
+ if (drawGridY) {
1377
+ global.append('g').selectAll('line').data(Array.from({
1378
+ length: lastIndex + 1
1379
+ }, (_, index) => index)).join('line').attr('class', lineChartClassNames.lineChartGridLineY).attr('x1', (_, index) => Math.round(xScale(index))).attr('x2', (_, index) => Math.round(xScale(index))).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
1380
+ }
1381
+ };
1382
+
1383
+ var _templateObject$9, _templateObject2$3;
1384
+ const LabelContainer$1 = /*#__PURE__*/styled__default.div(_templateObject$9 || (_templateObject$9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n font-size: 12px;\n white-space: nowrap;\n"])));
1385
+ const Label$2 = /*#__PURE__*/styled__default.div(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 4px;\n"])));
1386
+
1387
+ const labelClassName$1 = 'd3-chart-label';
1388
+ const drawLabel = _ref => {
1389
+ let {
1390
+ node,
1391
+ data,
1392
+ yScale,
1393
+ xScale,
1394
+ formatLabel,
1395
+ eachLabel
1396
+ } = _ref;
1397
+ const labelsDiv = d3.select(node).append('div').attr('class', labelClassName$1);
1398
+ const format = d3.format(','); // @ts-ignore
1399
+
1400
+ data.forEach(_ref2 => {
1401
+ let {
1402
+ values
1403
+ } = _ref2;
1404
+ labelsDiv.append('div').selectAll('div').data(values).join('div').attr('class', lineChartClassNames.lineChartLabelContainer).style('position', 'absolute').style('left', (_, index) => xScale(index) + 'px').style('top', d => yScale(d) + 'px').html((d, index, elements) => {
1405
+ const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
1406
+ className: lineChartClassNames.lineChartLabelFlex
1407
+ }, React__default.createElement(Label$2, {
1408
+ className: lineChartClassNames.lineChartLabel
1409
+ }, formatLabel ? formatLabel(d, index, elements) : format(d))));
1410
+ return html;
1411
+ }) // @ts-ignore
1412
+ .each(eachLabel ? eachLabel : none);
1413
+ });
1414
+ };
1415
+
1416
+ const _excluded$1 = ["values"];
1417
+ const drawTooltip$1 = _ref => {
1418
+ let {
1419
+ svg,
1420
+ node,
1421
+ data: argData,
1422
+ xScale,
1423
+ yScale,
1424
+ dynamicCircleRadius,
1425
+ formatDynamicTooltip,
1426
+ renderTooltip,
1427
+ stackedTooltipIndex,
1428
+ stackedTooltip,
1429
+ tooltipLineTop,
1430
+ tooltipRoot,
1431
+ tooltipClassName,
1432
+ dotSnapping,
1433
+ lastIndex
1434
+ } = _ref;
1435
+ const container = tooltipRoot || document.querySelector('body');
1436
+ const format = d3.format(',');
1437
+ const chartData = argData.filter(_ref2 => {
1438
+ let {
1439
+ tooltipOff
1440
+ } = _ref2;
1441
+ return !tooltipOff;
1442
+ });
1443
+ const data = typeof stackedTooltipIndex === 'number' ? [chartData[stackedTooltipIndex]] : stackedTooltip ? [chartData[0]] : chartData;
1444
+ const [x1, x2] = xScale.range();
1445
+ const [y1, y2] = yScale.range();
1446
+ const mouseGlobal = svg.append('g').attr('class', lineChartClassNames.lineChartMouseGlobal);
1447
+ const mouseRect = mouseGlobal.append('rect').attr('width', x2 - x1).attr('height', Math.abs(y1 - y2)).attr('class', lineChartClassNames.lineChartMouseRect).attr('transform', "translate(" + x1 + ", " + y2 + ")");
1448
+ const mouseLine = mouseGlobal.append('path').attr('class', lineChartClassNames.lineChartMouseLine).style('opacity', '0');
1449
+ const lines = svg.selectAll("." + lineChartClassNames.lineChartLine).nodes();
1450
+ const circles = mouseGlobal.selectAll('circle').data(chartData.filter(_ref3 => {
1451
+ let {
1452
+ dynamicDotOff
1453
+ } = _ref3;
1454
+ return !dynamicDotOff;
1455
+ })).join('circle').attr('class', lineChartClassNames.lineChartMouseCircle).attr('r', dynamicCircleRadius).attr('fill', _ref4 => {
1456
+ let {
1457
+ stroke
1458
+ } = _ref4;
1459
+ return stroke || 'none';
1460
+ }).attr('stroke', _ref5 => {
1461
+ let {
1462
+ stroke
1463
+ } = _ref5;
1464
+ return stroke || 'none';
1465
+ }).style('opacity', '0');
1466
+ let labelContainer = d3.select("." + lineChartClassNames.lineChartMouseLabelContainer);
1467
+
1468
+ if (labelContainer.size() === 0) {
1469
+ labelContainer = d3.select(container).append('div').attr('class', lineChartClassNames.lineChartMouseLabelContainer);
1470
+ }
1471
+
1472
+ let labels = null;
1473
+ let isVisible = false;
1474
+
1475
+ const setVisible = visible => {
1476
+ isVisible = Boolean(visible);
1477
+ const opacity = isVisible ? '1' : '0';
1478
+ mouseLine.style('opacity', opacity);
1479
+ circles.style('opacity', opacity);
1480
+ labels && labels.style('opacity', opacity);
1481
+ };
1482
+
1483
+ const mouseMove = event => {
1484
+ const [docX, docY] = d3.pointer(event, document);
1485
+ const [rectrX] = d3.pointer(event, mouseRect);
1486
+ const [nodeX, nodeY] = d3.pointer(event, node);
1487
+ const x = rectrX - (rectrX - nodeX);
1488
+ const left = nodeX + (docX - nodeX);
1489
+ const currIndex = Math.abs(xScale.invert(x));
1490
+ const positions = {};
1491
+
1492
+ const getValue = values => {
1493
+ // The returning result is fixed for the task: https://jr.everpoint.ru/browse/PUB-5648
1494
+ // Before the task it was like this (and I don't know why):
1495
+
1496
+ /* return !isVoid(values[Math.floor(currIndex + 1)])
1497
+ ? values[Math.floor(currIndex)]
1498
+ : null;*/
1499
+ return values[Math.floor(currIndex)];
1500
+ };
1501
+
1502
+ lines.forEach((line, index) => {
1503
+ let pos = {
1504
+ x: 0,
1505
+ y: 0
1506
+ };
1507
+
1508
+ if (!line.hasAttribute('d') || argData[index].tooltipOff) {
1509
+ positions[index] = pos;
1510
+ return;
1511
+ }
1512
+
1513
+ if (!dotSnapping) {
1514
+ let beginning = 0;
1515
+ let end = line.getTotalLength();
1516
+ let target = null;
1517
+
1518
+ while (true) {
1519
+ target = Math.floor((beginning + end) / 2);
1520
+ pos = line.getPointAtLength(target);
1521
+
1522
+ if ((target === end || target === beginning) && pos.x !== x) {
1523
+ break;
1524
+ }
1525
+
1526
+ if (pos.x > x) {
1527
+ end = target;
1528
+ } else if (pos.x < x) {
1529
+ beginning = target;
1530
+ } else {
1531
+ break;
1532
+ }
1533
+ }
1534
+
1535
+ positions[index] = pos;
1536
+ } else {
1537
+ const [x1, x2] = xScale.range();
1538
+ const chartWidth = x2 - x1;
1539
+ const step = chartWidth / lastIndex;
1540
+ positions[index] = {
1541
+ x: x1 + Math.round(currIndex) * step,
1542
+ y: typeof argData[index].values[Math.round(currIndex)] === "number" ? yScale(argData[index].values[Math.round(currIndex)]) : 0
1543
+ };
1544
+ }
1545
+ });
1546
+ circles.attr('transform', (lineChartData, index) => {
1547
+ const value = getValue(lineChartData.values);
1548
+ return positions[index] && value ? 'translate(' + (!dotSnapping ? x : positions[index].x) + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
1549
+ }).attr('style', _ref6 => {
1550
+ let {
1551
+ dynamicDotStyle
1552
+ } = _ref6;
1553
+ return dynamicDotStyle || '';
1554
+ });
1555
+ const datas = chartData.map((_ref7, i) => {
1556
+ let {
1557
+ values
1558
+ } = _ref7,
1559
+ rest = _objectWithoutPropertiesLoose(_ref7, _excluded$1);
1560
+
1561
+ return _extends({}, rest, {
1562
+ value: getValue(values),
1563
+ invertValue: positions[i] ? yScale.invert(positions[i].y) : 0
1564
+ });
1565
+ });
1566
+ const noHasData = datas.every(_ref8 => {
1567
+ let {
1568
+ value
1569
+ } = _ref8;
1570
+ return isVoid(value);
1571
+ });
1572
+
1573
+ if (noHasData && isVisible) {
1574
+ setVisible();
1575
+ } else if (!isVisible && !noHasData) {
1576
+ setVisible(true);
1577
+ }
1578
+
1579
+ const topIndex = Object.keys(positions).reduce((acc, key, index) => {
1580
+ var _datas$Number, _datas$Number2;
1581
+
1582
+ const prevValue = (_datas$Number = datas[Number(acc)]) == null ? void 0 : _datas$Number.value;
1583
+ const value = (_datas$Number2 = datas[Number(key)]) == null ? void 0 : _datas$Number2.value;
1584
+ const dynamicDotOff = argData == null ? void 0 : argData[index].dynamicDotOff;
1585
+ return index === 0 || isVoid(value) || dynamicDotOff ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
1586
+ }, '0');
1587
+ const labelTexts = labels && labels.style('left', (_, i) => {
1588
+ var _positions$i$x, _positions$i;
1589
+
1590
+ return !dotSnapping ? left + "px" : ((_positions$i$x = (_positions$i = positions[i]) == null ? void 0 : _positions$i.x) != null ? _positions$i$x : 0) + "px";
1591
+ }).style('top', (_, i) => {
1592
+ var _positions$index$y, _positions$index;
1593
+
1594
+ const index = typeof stackedTooltipIndex === 'number' ? stackedTooltipIndex : stackedTooltip ? topIndex : i;
1595
+ return ((_positions$index$y = (_positions$index = positions[index]) == null ? void 0 : _positions$index.y) != null ? _positions$index$y : 0) + (docY - nodeY) + "px";
1596
+ }).select("." + lineChartClassNames.lineChartLabel);
1597
+
1598
+ if (renderTooltip && labels) {
1599
+ labels.html((_, index) => {
1600
+ return ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
1601
+ className: lineChartClassNames.lineChartLabelFlex
1602
+ }, renderTooltip(datas, {
1603
+ indexX: Math.round(currIndex),
1604
+ indexY: index,
1605
+ svg,
1606
+ event
1607
+ })));
1608
+ });
1609
+ } else {
1610
+ labelTexts && labelTexts.text((_, i) => {
1611
+ const value = datas[i].value;
1612
+ const invertValue = datas[i].invertValue;
1613
+ return formatDynamicTooltip ? formatDynamicTooltip(invertValue, value) : format(invertValue);
1614
+ });
1615
+ }
1616
+
1617
+ mouseLine.attr('d', () => {
1618
+ var _positions$topIndex;
1619
+
1620
+ let d = 'M' + x + ',' + y1;
1621
+ d += ' ' + x + ',' + (tooltipLineTop ? y2 : ((_positions$topIndex = positions[topIndex]) == null ? void 0 : _positions$topIndex.y) || 0);
1622
+ return d;
1623
+ });
1624
+ };
1625
+
1626
+ mouseRect.on('mouseover.tooltip', event => {
1627
+ labels = labelContainer.selectAll('div').data(data).join('div').attr('class', lineChartClassNames.lineChartMouseLabel + " " + (tooltipClassName || '')).style('opacity', '0').style('position', 'absolute').html(() => {
1628
+ const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
1629
+ className: lineChartClassNames.lineChartLabelFlex
1630
+ }, React__default.createElement(Label$2, {
1631
+ className: lineChartClassNames.lineChartLabel
1632
+ })));
1633
+ return html;
1634
+ });
1635
+ mouseMove(event);
1636
+ });
1637
+ mouseRect.on('mouseout.tooltip', () => {
1638
+ d3.select("." + lineChartClassNames.lineChartMouseLabelContainer).selectAll('*').remove();
1639
+ setVisible();
1640
+ });
1641
+ mouseRect.on('touchmove.tooltip mousemove.tooltip', mouseMove);
1642
+ };
1643
+
1644
+ const draw$3 = (node, props) => {
1645
+ const {
1646
+ data: chartData,
1647
+ labels,
1648
+ margin,
1649
+ customYAxisSelection,
1650
+ customXAxisSelection,
1651
+ customYAxis,
1652
+ customXAxis,
1653
+ curve,
1654
+ yAxisPadding,
1655
+ xAxisPadding,
1656
+ drawGridY,
1657
+ drawGridX,
1658
+ withLabels,
1659
+ formatLabel,
1660
+ eachLabel,
1661
+ stacked,
1662
+ dynamicTooltipEnable,
1663
+ dynamicCircleRadius,
1664
+ formatDynamicTooltip,
1665
+ renderTooltip,
1666
+ stackedTooltip,
1667
+ stackedTooltipIndex,
1668
+ tooltipLineTop,
1669
+ customize,
1670
+ customYScale,
1671
+ customLine,
1672
+ tooltipClassName,
1673
+ xScaleItemWidth,
1674
+ areaCurve,
1675
+ dotSnapping,
1676
+ rightAxis
1677
+ } = props;
1678
+
1679
+ if (node !== null && chartData.length) {
1680
+ const data = stacked ? stackedData(chartData) : chartData;
1681
+ const marginTop = margin ? margin.top : 0;
1682
+ const marginRight = margin ? margin.right : 0;
1683
+ const marginBottom = margin ? margin.bottom : 0;
1684
+ const marginLeft = margin ? margin.left : 0;
1685
+ const {
1686
+ width: nodeWidth
1687
+ } = node.getBoundingClientRect();
1688
+ const width = props.width || nodeWidth;
1689
+ const height = props.height || 0;
1690
+ const min = typeof props.min === 'number' ? props.min : d3.min(data, _ref => {
1691
+ let {
1692
+ values
1693
+ } = _ref;
1694
+ return d3.min(values);
1695
+ });
1696
+ const max = typeof props.max === 'number' ? props.max : d3.max(data, _ref2 => {
1697
+ let {
1698
+ values
1699
+ } = _ref2;
1700
+ return d3.max(values);
1701
+ });
1702
+ const svg = appendSvg(node, width, height || 0);
1703
+ const yRange = [height - marginTop - marginBottom - (xAxisPadding || 0), marginTop];
1704
+ const yScale = d3.scaleLinear().domain([min || 0, max || 0]).range(yRange).nice();
1705
+ customYScale && customYScale(yScale);
1706
+ const yTicksCountDefault = 8;
1707
+ const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
1708
+ customYAxis && customYAxis(yAxisLeft);
1709
+ const yTicksCount = yAxisLeft.tickArguments()[0];
1710
+ const yAxis = svg.append('g').attr('class', lineChartClassNames.lineChartYScaleGlobal).call(yAxisLeft).call(customYAxisSelection ? customYAxisSelection : none);
1711
+ const {
1712
+ width: yAxisWidth
1713
+ } = computeDimensions(yAxis);
1714
+ yAxis.attr('transform', "translate(" + (marginLeft + yAxisWidth) + ", 0)");
1715
+ let yAxisRightWidth = 0;
1716
+
1717
+ if (rightAxis) {
1718
+ const rightAxisMin = d3.min(rightAxis);
1719
+ const rightAxisMax = d3.max(rightAxis);
1720
+ const yRightScale = d3.scaleLinear().domain([rightAxisMin || 0, rightAxisMax || 0]).range(yRange).nice();
1721
+ const yAxisRightTicks = d3.axisRight(yRightScale).ticks(yTicksCountDefault);
1722
+ const yAxisRight = svg.append('g').attr('class', lineChartClassNames.lineChartYScaleGlobal + " " + lineChartClassNames.lineChartYScaleRight).call(yAxisRightTicks).call(customYAxisSelection ? customYAxisSelection : none);
1723
+ ({
1724
+ width: yAxisRightWidth
1725
+ } = computeDimensions(yAxisRight));
1726
+ yAxisRight.attr('transform', "translate(" + (width - yAxisRightWidth) + ", 0)");
1727
+ }
1728
+ /** xScale **/
1729
+
1730
+
1731
+ const lastIndex = labels && labels.length ? labels.length - 1 : data.reduce((acc, _ref3) => {
1732
+ let {
1733
+ values
1734
+ } = _ref3;
1735
+ return Math.max(acc, values.length);
1736
+ }, 0) - 1;
1737
+ const xScale = d3.scaleLinear().domain([0, lastIndex]).range([marginLeft + yAxisWidth + (yAxisPadding || 0), width - yAxisRightWidth - marginRight]);
1738
+ const xAxisBottom = d3.axisBottom(xScale).tickFormat(value => // @ts-ignore
1739
+ labels && labels.length > 0 ? labels[value] : 0).ticks(lastIndex);
1740
+
1741
+ if (typeof xScaleItemWidth === 'number') {
1742
+ const [x1, x2] = xScale.range();
1743
+ const chartWidth = x2 - x1;
1744
+ xAxisBottom.ticks(Math.round(chartWidth / xScaleItemWidth)).tickSizeOuter(0);
1745
+ }
1746
+
1747
+ customXAxis && customXAxis(xAxisBottom);
1748
+ drawGrid({
1749
+ svg,
1750
+ yScale,
1751
+ xScale,
1752
+ yTicksCount,
1753
+ lastIndex,
1754
+ drawGridY,
1755
+ drawGridX
1756
+ });
1757
+
1758
+ if (Array.isArray(labels) && labels.length > 0) {
1759
+ const xAxis = svg.append('g').call(customXAxisSelection ? customXAxisSelection : none).attr('class', lineChartClassNames.lineChartXScaleGlobal).call(xAxisBottom);
1760
+ const {
1761
+ height: xAxisHeight
1762
+ } = computeDimensions(xAxis);
1763
+ xAxis.attr('transform', "translate(0, " + (height - Math.ceil(xAxisHeight) - marginBottom) + ")");
1764
+ }
1765
+
1766
+ const line = d3.line().defined(d => d !== null).x((_, index) => xScale(index)).y(d => yScale(d)).curve(curve || d3.curveLinear);
1767
+ customLine && customLine(line);
1768
+ const withAreas = data.some(_ref4 => {
1769
+ let {
1770
+ fill
1771
+ } = _ref4;
1772
+ return fill;
1773
+ });
1774
+
1775
+ if (withAreas) {
1776
+ let dataIndex = -2;
1777
+
1778
+ const getArea = d => {
1779
+ const {
1780
+ minAreaValues
1781
+ } = d;
1782
+ const minTick = yScale.ticks()[0];
1783
+ return d3.area().defined(d => d !== null).x((_, index) => xScale(index)).y0((value, index) => {
1784
+ if (index === 0) {
1785
+ dataIndex = dataIndex + 1;
1786
+ }
1787
+
1788
+ let minValue = minTick;
1789
+
1790
+ if (minAreaValues && typeof minAreaValues[index] === 'number') {
1791
+ minValue = minAreaValues[index] || minValue;
1792
+ } else if (minAreaValues) {
1793
+ minValue = yScale(minValue - value);
1794
+ }
1795
+
1796
+ const currData = data[dataIndex];
1797
+ return stacked ? dataIndex > -1 ? yScale(typeof currData.values[index] !== 'number' ? 0 : currData.values[index]) : yScale(minValue) : yScale(minValue);
1798
+ }).y1(d => yScale(d)).curve(areaCurve || curve || d3.curveLinear);
1799
+ };
1800
+
1801
+ svg.append('g').attr('class', lineChartClassNames.lineChartAreasGlobal).selectAll('path').data(data.filter(_ref5 => {
1802
+ let {
1803
+ fill
1804
+ } = _ref5;
1805
+ return Boolean(fill);
1806
+ })).join('path').attr('class', lineChartClassNames.lineChartArea).attr('d', d => {
1807
+ const area = getArea(d);
1808
+ return area(d.values);
1809
+ }).attr('fill', _ref6 => {
1810
+ let {
1811
+ fill
1812
+ } = _ref6;
1813
+ return fill || 'none';
1814
+ }).attr('style', _ref7 => {
1815
+ let {
1816
+ areaStyle
1817
+ } = _ref7;
1818
+ return areaStyle || '';
1819
+ });
1820
+ }
1821
+
1822
+ svg.append('g').attr('class', lineChartClassNames.lineChartLinesGlobal).selectAll('path').data(data).join('path').attr('class', lineChartClassNames.lineChartLine).attr('d', d => line(d.values)).attr('stroke', _ref8 => {
1823
+ let {
1824
+ stroke
1825
+ } = _ref8;
1826
+ return stroke || 'steelblue';
1827
+ }).attr('style', _ref9 => {
1828
+ let {
1829
+ style
1830
+ } = _ref9;
1831
+ return style || '';
1832
+ });
1833
+ const dots = data.filter(_ref10 => {
1834
+ let {
1835
+ dot
1836
+ } = _ref10;
1837
+ return dot;
1838
+ });
1839
+
1840
+ if (dots.length > 0) {
1841
+ const dotsGlobal = svg.append('g').attr('class', lineChartClassNames.lineChartDotsGlobalContainer);
1842
+ dots.forEach(item => {
1843
+ const {
1844
+ values,
1845
+ dot
1846
+ } = item;
1847
+ const {
1848
+ radius,
1849
+ style,
1850
+ filter
1851
+ } = dot;
1852
+ const dotsGroup = dotsGlobal.append('g').attr('class', lineChartClassNames.lineChartDotsGlobal);
1853
+ dotsGroup.selectAll('circle').data(values).join('circle').attr('cx', (_, index) => xScale(index)).attr('class', lineChartClassNames.lineChartDot).attr('cy', d => yScale(d)).attr('r', radius || 0).attr('style', style || '');
1854
+
1855
+ if (filter) {
1856
+ dotsGroup.selectAll('circle').select((_, i, g) => filter(item, i, g) ? g[i] : null).remove();
1857
+ }
1858
+ });
1859
+ }
1860
+
1861
+ d3.select(node).select("." + labelClassName$1).remove();
1862
+ withLabels && drawLabel({
1863
+ node,
1864
+ eachLabel,
1865
+ data,
1866
+ yScale,
1867
+ xScale,
1868
+ formatLabel
1869
+ });
1870
+
1871
+ if (dynamicTooltipEnable) {
1872
+ drawTooltip$1({
1873
+ tooltipLineTop,
1874
+ stackedTooltip,
1875
+ renderTooltip,
1876
+ stackedTooltipIndex,
1877
+ formatDynamicTooltip,
1878
+ node,
1879
+ svg,
1880
+ data,
1881
+ xScale,
1882
+ yScale,
1883
+ dynamicCircleRadius,
1884
+ tooltipClassName,
1885
+ dotSnapping,
1886
+ lastIndex
1887
+ });
1888
+ }
1889
+
1890
+ customize && customize({
1891
+ svg,
1892
+ yScale,
1893
+ xScale
1894
+ });
1895
+ }
1896
+ };
1897
+
1898
+ const LineChart = props => {
1899
+ const {
1900
+ className,
1901
+ style,
1902
+ children
1903
+ } = props;
1904
+ const [ref, node] = useNode();
1905
+ React.useEffect(() => {
1906
+ node && draw$3(node, props);
1907
+ }, [node, props]);
1908
+
1909
+ const onDraw = () => draw$3(node, props);
1910
+
1911
+ useResize(props.width, onDraw);
1912
+ return React__default.createElement("div", {
1913
+ className: className,
1914
+ style: style
1915
+ }, React__default.createElement(TooltipStyles, null), React__default.createElement(SvgWrapper$3, {
1916
+ ref: ref
1917
+ }, children));
1918
+ };
1919
+ LineChart.defaultProps = {
1920
+ data: [],
1921
+ labels: [],
1922
+ height: 240,
1923
+ yAxisPadding: 10,
1924
+ xAxisPadding: 20,
1925
+ margin: {
1926
+ top: 10,
1927
+ right: 10,
1928
+ bottom: 10,
1929
+ left: 0
1930
+ },
1931
+ dynamicCircleRadius: 4,
1932
+ stackedTooltip: false
1933
+ };
1934
+
1935
+ const barChartLinesClassNames = {
1936
+ barChartLinesGlobal: 'barChartLinesGlobal',
1937
+ barChartLine: 'barChartLine',
1938
+ barChartAreasGlobal: 'barChartAreasGlobal',
1939
+ barChartArea: 'barChartArea'
1940
+ };
1941
+ const drawLines = _ref => {
1942
+ let {
1943
+ svg,
1944
+ lineData,
1945
+ min,
1946
+ yScale,
1947
+ xScale,
1948
+ curve,
1949
+ stackedLine
1950
+ } = _ref;
1951
+ let linesSelection = null;
1952
+ let areasSelection = null;
1953
+ let area = null;
1954
+ const line = d3.line().defined(d => d !== null).x((_, index) => xScale(index) + bandwidth / 2) // @ts-ignore
1955
+ .y(d => yScale(d)).curve(curve || d3.curveLinear);
1956
+ const bandwidth = xScale.bandwidth();
1957
+ const linesData = lineData.filter(_ref2 => {
1958
+ let {
1959
+ lineType
1960
+ } = _ref2;
1961
+ return lineType === 'line';
1962
+ });
1963
+ const areasData = lineData.filter(_ref3 => {
1964
+ let {
1965
+ lineType
1966
+ } = _ref3;
1967
+ return lineType === 'area';
1968
+ });
1969
+
1970
+ if (linesData.length > 0) {
1971
+ linesSelection = svg.append('g').attr('class', barChartLinesClassNames.barChartLinesGlobal).selectAll('path').data(linesData).join('path').attr('class', barChartLinesClassNames.barChartLine).attr('d', d => line(d.values)).attr('stroke', _ref4 => {
1972
+ let {
1973
+ stroke
1974
+ } = _ref4;
1975
+ return stroke || '';
1976
+ }).attr('fill', _ref5 => {
1977
+ let {
1978
+ fill
1979
+ } = _ref5;
1980
+ return fill || 'none';
1981
+ });
1982
+ }
1983
+
1984
+ if (areasData.length > 0) {
1985
+ let dataIndex = -2;
1986
+ area = d3.area().x((_, index) => xScale(index) + bandwidth / 2).y0((_, index) => {
1987
+ if (index === 0) {
1988
+ dataIndex = dataIndex + 1;
1989
+ }
1990
+
1991
+ return stackedLine ? dataIndex > -1 ? yScale(typeof lineData[dataIndex].values[index] !== 'number' ? 0 : lineData[dataIndex].values[index]) : yScale(min) : yScale(min);
1992
+ }) // @ts-ignore
1993
+ .y1(d => yScale(d)).curve(curve || d3.curveLinear);
1994
+ areasSelection = svg.append('g').attr('class', barChartLinesClassNames.barChartAreasGlobal).selectAll('path').data(areasData).join('path').attr('class', barChartLinesClassNames.barChartArea).attr('d', d => area && area(d.values)).attr('fill', _ref6 => {
1995
+ let {
1996
+ fill
1997
+ } = _ref6;
1998
+ return fill || 'none';
1999
+ });
2000
+ }
2001
+
2002
+ return {
2003
+ areasSelection,
2004
+ linesSelection,
2005
+ area
2006
+ };
2007
+ };
2008
+
2009
+ var _templateObject$a, _templateObject2$4;
2010
+ const tooltipClassnames = {
2011
+ barChartMouseRect: 'barChartMouseRect',
2012
+ barChartMouseContainer: 'barChartMouseContainer',
2013
+ barChartTooltipFlex: 'barChartTooltipFlex',
2014
+ barChartMouseTooltip: 'barChartMouseTooltip',
2015
+ barChartTooltip: 'barChartTooltip',
2016
+ barChartTooltipItem: 'barChartTooltipItem',
2017
+ barChartTooltipColFlex: 'barChartTooltipColFlex',
2018
+ barChartTooltipGroupName: 'barChartTooltipGroupName',
2019
+ barChartColorBox: 'barChartColorBox',
2020
+ barChartColorLine: 'barChartColorLine',
2021
+ barChartTooltipName: 'barChartTooltipName',
2022
+ barChartTooltipValue: 'barChartTooltipValue'
2023
+ };
2024
+ const labelClassnames = {
2025
+ barChartLabelContainer: 'barChartLabelContainer',
2026
+ barChartLabelFlex: 'barChartLabelFlex',
2027
+ barChartLabel: 'barChartLabel'
2028
+ };
2029
+ const barChartClassNames = /*#__PURE__*/_extends({
2030
+ barChartBarGlobal: 'barChartBarGlobal',
2031
+ barChartYScaleGlobal: 'barChartYScaleGlobal',
2032
+ barChartYAxis: 'barChartYAxis',
2033
+ barChartXAxis: 'barChartXAxis',
2034
+ barChartYAxisZeroTick: 'barChartYAxisZeroTick',
2035
+ barChartGridGlobal: 'barChartGridGlobal',
2036
+ barChartGridLineX: 'barChartGridLineX',
2037
+ barChartGridLineXZero: 'barChartGridLineXZero',
2038
+ barChartGridLineYZero: 'barChartGridLineYZero',
2039
+ barChartGridLineY: 'barChartGridLineY',
2040
+ barChartSelection: 'barChartSelection'
2041
+ }, tooltipClassnames, labelClassnames, barChartLinesClassNames);
2042
+ const SvgWrapper$4 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: ", ";\n user-select: ", ";\n width: ", ";\n\n line {\n stroke-width: 1px;\n shape-rendering: crispEdges;\n }\n\n .", ",\n .", " {\n stroke: rgba(48, 69, 79, 0.06);\n }\n\n .", " {\n }\n\n .", " {\n fill: none;\n pointer-events: all;\n }\n\n .", " {\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n\n .", " {\n shape-rendering: auto;\n }\n\n .", " {\n fill-opacity: 0.24;\n }\n\n .", " {\n position: absolute;\n top: 0;\n width: 0;\n background: rgba(0, 170, 255, 0.06);\n box-shadow: 1px 0 0 #00AAFF, -1px 0 0 #00AAFF;\n pointer-events: none;\n }\n"])), _ref => {
2043
+ let {
2044
+ selectable
2045
+ } = _ref;
2046
+ return selectable && "inline-block";
2047
+ }, _ref2 => {
2048
+ let {
2049
+ selectable
2050
+ } = _ref2;
2051
+ return selectable && "none";
2052
+ }, _ref3 => {
2053
+ let {
2054
+ selectable
2055
+ } = _ref3;
2056
+ return selectable && "auto";
2057
+ }, barChartClassNames.barChartGridLineX, barChartClassNames.barChartGridLineY, barChartClassNames.barChartMouseRect, barChartClassNames.barChartMouseRect, barChartClassNames.barChartLinesGlobal, barChartClassNames.barChartLine, barChartClassNames.barChartArea, barChartClassNames.barChartSelection);
2058
+ const TooltipStyles$1 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$4 || (_templateObject2$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n z-index: 100;\n transition: all linear 144ms;\n\n .", " {\n margin-bottom: 4px;\n :last-of-type {\n margin-bottom: 0;\n }\n }\n }\n"])), barChartClassNames.barChartMouseTooltip, barChartClassNames.barChartTooltipItem);
2059
+
2060
+ const useSelection = (node, props) => {
2061
+ const drawing = React.useRef(false);
2062
+ const startX = React.useRef(0);
2063
+ const selection = React.useRef();
2064
+ const clearSelection = React.useCallback(() => {
2065
+ if (node && selection.current) {
2066
+ drawing.current = false;
2067
+ node.removeChild(selection.current);
2068
+ selection.current = undefined;
2069
+ }
2070
+ }, [node]);
2071
+ const onStartDrawing = React.useCallback(e => {
2072
+ const isTouch = Boolean(e.touches);
2073
+ e.stopPropagation();
2074
+
2075
+ if (node && e.which !== 3) {
2076
+ var _props$margin$bottom, _props$margin, _e$touches$;
2077
+
2078
+ clearSelection();
2079
+ selection.current = document.createElement("div");
2080
+ selection.current.setAttribute("class", barChartClassNames.barChartSelection);
2081
+ selection.current.setAttribute("style", "height: calc(100% - " + ((_props$margin$bottom = (_props$margin = props.margin) == null ? void 0 : _props$margin.bottom) != null ? _props$margin$bottom : 0) + "px)");
2082
+ node.appendChild(selection.current);
2083
+ drawing.current = true;
2084
+ startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
2085
+ selection.current.style.display = "block";
2086
+ selection.current.style.width = "0px";
2087
+ selection.current.style.left = startX.current + "px";
2088
+ }
2089
+ }, [node]);
2090
+ const onDraw = React.useCallback(e => {
2091
+ const isTouch = Boolean(e.touches);
2092
+ e.stopPropagation();
2093
+
2094
+ if (node && drawing.current && selection.current) {
2095
+ var _e$touches$2;
2096
+
2097
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2098
+ const offsetX = isTouch ? ((_e$touches$2 = e.touches[0]) == null ? void 0 : _e$touches$2.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
2099
+ const newWidth = offsetX - startX.current;
2100
+
2101
+ if (offsetX >= 0) {
2102
+ if (newWidth > 0) {
2103
+ selection.current.style.marginLeft = "0px";
2104
+ selection.current.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
2105
+ } else {
2106
+ selection.current.style.right = nodeWidth - startX.current + "px";
2107
+ selection.current.style.width = Math.abs(newWidth) + "px";
2108
+ selection.current.style.marginLeft = newWidth + "px";
2109
+ }
2110
+ }
2111
+
2112
+ if (isTouch) {
2113
+ if (node.offsetLeft > e.touches[0].pageX) {
2114
+ selection.current.style.right = nodeWidth - startX.current + "px";
2115
+ selection.current.style.width = startX.current + "px";
2116
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2117
+ }
2118
+ }
2119
+ }
2120
+ }, [node]);
2121
+ const onMouseLeave = React.useCallback(e => {
2122
+ if (drawing.current && node && selection.current) {
2123
+ if (node.offsetLeft > e.pageX) {
2124
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2125
+ selection.current.style.right = nodeWidth - startX.current + "px";
2126
+ selection.current.style.width = startX.current + "px";
2127
+ selection.current.style.marginLeft = "-" + startX.current + "px";
2128
+ }
2129
+
2130
+ if (node.offsetLeft + node.offsetWidth < e.pageX) {
2131
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2132
+ selection.current.style.left = startX.current + "px";
2133
+ selection.current.style.width = nodeWidth - startX.current + "px";
2134
+ selection.current.style.marginLeft = "0px";
2135
+ }
2136
+ }
2137
+ }, [node]);
2138
+ const onStopDrawing = React.useCallback(() => {
2139
+ if (node && selection.current) {
2140
+ const nodeWidth = node.firstChild.getBoundingClientRect().width;
2141
+ const selectionMinX = selection.current.offsetLeft >= 0 ? selection.current.offsetLeft <= nodeWidth ? selection.current.offsetLeft : nodeWidth : 0;
2142
+ const selectionWidth = selection.current.getBoundingClientRect().right - selection.current.getBoundingClientRect().left;
2143
+ const selectionMaxX = selection.current.offsetLeft + selectionWidth <= nodeWidth ? selection.current.offsetLeft + selectionWidth >= 0 ? selection.current.offsetLeft + selectionWidth : 0 : nodeWidth;
2144
+ const min = Math.round(selectionMinX);
2145
+ const max = Math.round(selectionMaxX);
2146
+
2147
+ if (max - min > 0 && props.onSelect) {
2148
+ props.onSelect([min, max]);
2149
+ }
2150
+ }
2151
+
2152
+ clearSelection();
2153
+ }, [node, clearSelection]);
2154
+ React.useEffect(() => {
2155
+ if (node) {
2156
+ node.childNodes.forEach(child => {
2157
+ child.style.userSelect = "none";
2158
+ });
2159
+ node.addEventListener("mousedown", onStartDrawing);
2160
+ node.addEventListener("touchstart", onStartDrawing);
2161
+ node.addEventListener("mousemove", onDraw);
2162
+ node.addEventListener("touchmove", onDraw);
2163
+ node.addEventListener("mouseleave", onMouseLeave);
2164
+ node.addEventListener("mouseup", onStopDrawing);
2165
+ node.addEventListener("touchend", onStopDrawing);
2166
+ document.addEventListener("mouseup", onStopDrawing);
2167
+ }
2168
+
2169
+ return () => {
2170
+ node == null ? void 0 : node.removeEventListener("mousedown", onStartDrawing);
2171
+ node == null ? void 0 : node.removeEventListener("touchstart", onStartDrawing);
2172
+ node == null ? void 0 : node.removeEventListener("mousemove", onDraw);
2173
+ node == null ? void 0 : node.removeEventListener("touchmove", onDraw);
2174
+ node == null ? void 0 : node.removeEventListener("mouseleave", onMouseLeave);
2175
+ node == null ? void 0 : node.removeEventListener("mouseup", onStopDrawing);
2176
+ node == null ? void 0 : node.removeEventListener("touchend", onStopDrawing);
2177
+ document.removeEventListener("mouseup", onStopDrawing);
2178
+ };
2179
+ }, [node]);
2180
+ };
2181
+
2182
+ const drawGrid$1 = _ref => {
2183
+ let {
2184
+ svg,
2185
+ yScale,
2186
+ xScale,
2187
+ yTicksCount,
2188
+ drawGridX,
2189
+ drawGridY
2190
+ } = _ref;
2191
+ if (!drawGridY && !drawGridX) return;
2192
+ const global = svg.append('g').attr('class', barChartClassNames.barChartGridGlobal);
2193
+ const yTicks = yScale.ticks(yTicksCount);
2194
+ const range = xScale.range();
2195
+ const domain = xScale.domain();
2196
+
2197
+ if (drawGridX) {
2198
+ global.append('g').selectAll('line').data(yTicks).join('line').attr('class', d => d === 0 ? barChartClassNames.barChartGridLineX + " " + barChartClassNames.barChartGridLineXZero : barChartClassNames.barChartGridLineX).attr('x1', () => range[0]).attr('x2', () => range[1]).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
2199
+ }
2200
+
2201
+ if (drawGridY) {
2202
+ const getX = index => domain[index] !== void 0 ? index === 0 ? range[0] : Math.round(xScale.step() * index + range[0] - xScale.step() / 2 * xScale.padding()) : range[1];
2203
+
2204
+ global.append('g').selectAll('line').data(Array.from({
2205
+ length: domain.length + 1
2206
+ }, (_, index) => index)).join('line').attr('class', d => d === 0 ? barChartClassNames.barChartGridLineY + " " + barChartClassNames.barChartGridLineYZero : barChartClassNames.barChartGridLineY).attr('x1', getX).attr('x2', getX).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
2207
+ }
2208
+ };
2209
+
2210
+ const _excluded$2 = ["groupName"];
2211
+ const getDomain = _ref => {
2212
+ let {
2213
+ data,
2214
+ minDomainValue,
2215
+ maxDomainValue
2216
+ } = _ref;
2217
+ let MIN = Number.POSITIVE_INFINITY;
2218
+ let MAX = Number.NEGATIVE_INFINITY;
2219
+ data.forEach(_ref2 => {
2220
+ let groups = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
2221
+
2222
+ let groupMax = 0;
2223
+ let groupMin = 0;
2224
+ Object.keys(groups).forEach(key => {
2225
+ const group = groups[key];
2226
+ let stackMax = 0;
2227
+ let stackMin = 0;
2228
+ Object.keys(group).forEach(groupKey => {
2229
+ const value = group[groupKey];
2230
+
2231
+ if (value > 0) {
2232
+ stackMax += value;
2233
+ } else {
2234
+ stackMin += value;
2235
+ }
2236
+ });
2237
+ groupMax = Math.min(groupMax, stackMin);
2238
+ groupMin = Math.max(groupMin, stackMax);
2239
+ });
2240
+ MIN = Math.min(MIN, groupMax);
2241
+ MAX = Math.max(MAX, groupMin);
2242
+ });
2243
+
2244
+ if (MIN === 0 && MAX === 0) {
2245
+ return {
2246
+ min: typeof minDomainValue === 'number' ? minDomainValue : 0,
2247
+ max: typeof maxDomainValue === 'number' ? maxDomainValue : 1
2248
+ };
2249
+ }
2250
+
2251
+ return {
2252
+ min: typeof minDomainValue === 'number' ? minDomainValue : MIN,
2253
+ max: typeof maxDomainValue === 'number' ? maxDomainValue : MAX
2254
+ };
2255
+ };
2256
+
2257
+ const _excluded$3 = ["groupName"];
2258
+ const marshaling = _ref => {
2259
+ let {
2260
+ data,
2261
+ yScale,
2262
+ xScale,
2263
+ barWidth,
2264
+ barPadding,
2265
+ colors,
2266
+ marginTop
2267
+ } = _ref;
2268
+ return data.map((_ref2, groupIndex) => {
2269
+ let {
2270
+ groupName
2271
+ } = _ref2,
2272
+ groups = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
2273
+
2274
+ const marshalledGroup = [];
2275
+ const hundred = 100;
2276
+ const bandwidth = xScale.bandwidth();
2277
+ const groupsKeys = Object.keys(groups);
2278
+ groupsKeys.forEach((key, stackIndex) => {
2279
+ const group = groups[key];
2280
+ const groupKeys = Object.keys(group);
2281
+ const barGroupWidth = (barWidth + barPadding) * groupsKeys.length - (groupKeys.length > 1 ? barPadding : 0);
2282
+ let stackMax = 0;
2283
+ let stackMin = 0;
2284
+ groupKeys.forEach(groupKey => {
2285
+ const value = group[groupKey];
2286
+ const color = colors[groupKey];
2287
+ const x = (barWidth + barPadding) * stackIndex + bandwidth / 2 - barGroupWidth / 2;
2288
+ const isPositiveValue = value > 0;
2289
+ const height = isPositiveValue ? Math.abs((yScale(stackMax - value) - yScale(stackMax) + Number.EPSILON) * hundred / hundred) : Math.abs((yScale(stackMin - value) - yScale(stackMin) + Number.EPSILON) * hundred / hundred);
2290
+
2291
+ if (isPositiveValue) {
2292
+ stackMax += value;
2293
+ }
2294
+
2295
+ const y = isPositiveValue ? (yScale(stackMax) + Number.EPSILON) * hundred / hundred : yScale(stackMin) - yScale(0) + yScale(0);
2296
+ marshalledGroup.push({
2297
+ x,
2298
+ y: y + (marginTop || 0),
2299
+ height,
2300
+ color,
2301
+ value,
2302
+ groupName: groupName,
2303
+ name: groupKey,
2304
+ stackIndex,
2305
+ groupIndex
2306
+ });
2307
+
2308
+ if (!isPositiveValue) {
2309
+ stackMin += value;
2310
+ }
2311
+ });
2312
+ });
2313
+ return marshalledGroup;
2314
+ });
2315
+ };
2316
+
2317
+ const getLabelY = (labelPosition, y2, item) => {
2318
+ switch (labelPosition) {
2319
+ case 'center':
2320
+ return item.y + item.height / 2 - y2;
2321
+
2322
+ case 'bottom':
2323
+ return item.y + item.height - y2;
2324
+
2325
+ default:
2326
+ return item.y;
2327
+ }
2328
+ };
2329
+
2330
+ const getLabel = labelPosition => {
2331
+ switch (labelPosition) {
2332
+ case 'top':
2333
+ return LabelTop;
2334
+
2335
+ case 'bottom':
2336
+ return LabelBottom;
2337
+
2338
+ default:
2339
+ return Label$1;
2340
+ }
2341
+ };
2342
+
2343
+ const _excluded$4 = ["values"];
2344
+ const drawTooltip$2 = _ref => {
2345
+ let {
2346
+ svg,
2347
+ node,
2348
+ data,
2349
+ marshalledData,
2350
+ xScale,
2351
+ yScale,
2352
+ renderTooltip,
2353
+ labelPosition,
2354
+ marginTop,
2355
+ renderLabel,
2356
+ barWidth,
2357
+ barPadding,
2358
+ dynamicTooltipEnable,
2359
+ hideTooltipGroupName,
2360
+ tooltipY,
2361
+ tooltipBind,
2362
+ lineData,
2363
+ formatTooltipValue,
2364
+ formatTooltipName,
2365
+ tooltipYDomain,
2366
+ setTooltipPosition,
2367
+ onLabelItem,
2368
+ isBarTooltip,
2369
+ bars,
2370
+ tooltipRoot,
2371
+ tooltipClassName,
2372
+ onBarClick,
2373
+ onBarHover
2374
+ } = _ref;
2375
+ d3.select(node).select("." + barChartClassNames.barChartMouseContainer).remove();
2376
+ const xScaleBandDomain = xScale.domain();
2377
+ const [x1, x2] = xScale.range();
2378
+ const [y1, y2] = yScale.range();
2379
+ const bandwidth = xScale.bandwidth();
2380
+ const format = d3.format(',');
2381
+
2382
+ const getX = index => xScaleBandDomain[index] !== void 0 ? index === 0 ? x1 : Math.round(xScale.step() * index + x1 - xScale.step() / 2 * xScale.padding()) : x2;
2383
+
2384
+ const groups = xScaleBandDomain.map(value => getX(Number(value) + 1));
2385
+ const topYDomain = tooltipYDomain ? tooltipYDomain({
2386
+ data: marshalledData,
2387
+ lineData,
2388
+ yScale
2389
+ }) : marshalledData.reduce((acc, curr, index) => {
2390
+ const lineMin = d3.min(lineData, _ref2 => {
2391
+ let {
2392
+ values
2393
+ } = _ref2;
2394
+ return typeof values[index] === 'number' ? yScale((values[index] || 0) - y2) : Number.POSITIVE_INFINITY;
2395
+ }) || Number.POSITIVE_INFINITY;
2396
+ acc.push(curr.reduce((acc, _ref3) => {
2397
+ let {
2398
+ y
2399
+ } = _ref3;
2400
+ return Math.min(acc, y, lineMin);
2401
+ }, Number.POSITIVE_INFINITY));
2402
+ return acc;
2403
+ }, []);
2404
+ const mouseGlobal = svg.append('g').attr('class', 'lineChartMouseGlobal');
2405
+ const mouseRect = mouseGlobal.append('rect').attr('width', x2 - x1).attr('height', Math.abs(y1 - y2)).attr('class', barChartClassNames.barChartMouseRect).attr('transform', "translate(" + x1 + ", " + y2 + ")");
2406
+
2407
+ if (dynamicTooltipEnable) {
2408
+ const tooltipContainer = tooltipRoot || document.querySelector('body');
2409
+ let tooltip = d3.select("." + barChartClassNames.barChartMouseTooltip);
2410
+
2411
+ if (tooltip.size() === 0) {
2412
+ tooltip = d3.select(tooltipContainer).append('div').attr('class', barChartClassNames.barChartMouseTooltip).style('opacity', '0').style('position', 'absolute').html(() => {
2413
+ const html = ReactDOMServer.renderToString(React__default.createElement(TooltipFlex, {
2414
+ className: barChartClassNames.barChartTooltipFlex
2415
+ }));
2416
+ return html;
2417
+ });
2418
+ }
2419
+
2420
+ const barChartTootipFlex = tooltip.select("." + barChartClassNames.barChartTooltipFlex);
2421
+ let isVisible = false;
2422
+ let flagCurrIndex = null;
2423
+
2424
+ const setVisible = visible => {
2425
+ isVisible = Boolean(visible);
2426
+ const opacity = isVisible ? '1' : '0';
2427
+ tooltip.style('opacity', opacity);
2428
+
2429
+ if (!isVisible) {
2430
+ tooltip.attr('class', barChartClassNames.barChartMouseTooltip);
2431
+ flagCurrIndex = null;
2432
+ tooltip.style('transition', 'none');
2433
+ tooltip.style('top', null);
2434
+ tooltip.style('left', null);
2435
+ } else {
2436
+ tooltip.attr('class', barChartClassNames.barChartMouseTooltip + " " + (tooltipClassName || ''));
2437
+ tooltip.style('transition', null);
2438
+ }
2439
+ };
2440
+
2441
+ mouseRect.on('mouseout.tooltip', () => setVisible());
2442
+ mouseRect.on('touchmove.tooltip mousemove.tooltip', event => {
2443
+ const [docX, docY] = d3.pointer(event, document);
2444
+ const [rectrX] = d3.pointer(event, mouseRect);
2445
+ const [nodeX, nodeY] = d3.pointer(event, node);
2446
+ const x = rectrX - (rectrX - nodeX);
2447
+ const offsetX = docX - nodeX;
2448
+ const offsetY = docY - nodeY;
2449
+ const currIndex = groups.findIndex(value => x <= value);
2450
+
2451
+ if (isBarTooltip) {
2452
+ const containts = document.elementsFromPoint(event.clientX, event.clientY);
2453
+ const currBars = d3.select(bars.nodes()[currIndex]).selectAll('rect').nodes();
2454
+ const isContains = containts.some(item => currBars.includes(item));
2455
+
2456
+ if (!isContains) {
2457
+ if (isVisible) {
2458
+ setVisible(false);
2459
+ }
2460
+
2461
+ mouseRect.style('cursor', 'default');
2462
+ return;
2463
+ } else {
2464
+ mouseRect.style('cursor', 'pointer');
2465
+ }
2466
+ }
2467
+
2468
+ const top = (typeof tooltipY === 'number' ? tooltipY : topYDomain[currIndex] - y2) + offsetY;
2469
+ const left = (tooltipBind ? (xScale(currIndex) || 0) + bandwidth / 2 : x) + offsetX;
2470
+
2471
+ if (tooltipBind && flagCurrIndex === currIndex) {
2472
+ return;
2473
+ }
2474
+
2475
+ let currData = marshalledData[currIndex];
2476
+
2477
+ if (Array.isArray(currData) && currData.length === 0) {
2478
+ return;
2479
+ }
2480
+
2481
+ if (lineData) {
2482
+ const currLineData = lineData.map(_ref4 => {
2483
+ let {
2484
+ values
2485
+ } = _ref4,
2486
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded$4);
2487
+
2488
+ return _extends({}, rest, {
2489
+ value: values[currIndex],
2490
+ groupName: data[currIndex] && data[currIndex].groupName
2491
+ });
2492
+ });
2493
+
2494
+ if (Array.isArray(currLineData) && Array.isArray(currData)) {
2495
+ currData = currData.concat(currLineData);
2496
+ }
2497
+ }
2498
+
2499
+ const svgWidth = svg.node().getBoundingClientRect().width;
2500
+
2501
+ if (typeof setTooltipPosition === 'function') {
2502
+ setTooltipPosition({
2503
+ left,
2504
+ top,
2505
+ tooltip,
2506
+ svgWidth
2507
+ });
2508
+ } else if (!setTooltipPosition) {
2509
+ tooltip.style('left', left + "px").style('top', top + "px");
2510
+ }
2511
+
2512
+ if (renderTooltip) {
2513
+ barChartTootipFlex.html(() => {
2514
+ const html = ReactDOMServer.renderToString(React__default.createElement(React__default.Fragment, null, renderTooltip(currData, setTooltipPosition ? {
2515
+ left,
2516
+ top,
2517
+ tooltip,
2518
+ svgWidth
2519
+ } : undefined, barWidth)));
2520
+ return html;
2521
+ });
2522
+ } else {
2523
+ if (!isVisible) {
2524
+ setVisible(true);
2525
+ }
2526
+
2527
+ barChartTootipFlex.html(() => {
2528
+ const html = ReactDOMServer.renderToString(React__default.createElement(TooltipContainer, {
2529
+ className: barChartClassNames.barChartTooltip
2530
+ }, currData && currData[0] && !hideTooltipGroupName && React__default.createElement(TooltipGroupName, {
2531
+ className: barChartClassNames.barChartTooltipGroupName
2532
+ }, currData[0].groupName), currData && currData.map(_ref5 => {
2533
+ let {
2534
+ name,
2535
+ value,
2536
+ stroke,
2537
+ fill,
2538
+ color,
2539
+ lineType
2540
+ } = _ref5;
2541
+ return React__default.createElement(TooltipItem, {
2542
+ key: name,
2543
+ className: barChartClassNames.barChartTooltipItem
2544
+ }, React__default.createElement(ColFlex, {
2545
+ className: barChartClassNames.barChartTooltipColFlex
2546
+ }, lineType ? React__default.createElement(ColorLine, {
2547
+ className: barChartClassNames.barChartColorLine,
2548
+ style: {
2549
+ backgroundColor: stroke || fill
2550
+ }
2551
+ }) : React__default.createElement(ColorBox, {
2552
+ className: barChartClassNames.barChartColorBox,
2553
+ style: {
2554
+ backgroundColor: color
2555
+ }
2556
+ }), React__default.createElement(Name$1, {
2557
+ className: barChartClassNames.barChartTooltipName
2558
+ }, formatTooltipName ? formatTooltipName(name) : name)), React__default.createElement(Value, {
2559
+ className: barChartClassNames.barChartTooltipValue
2560
+ }, formatTooltipValue ? formatTooltipValue(value, name) : format(value)));
2561
+ })));
2562
+ return html;
2563
+ });
2564
+ }
2565
+
2566
+ flagCurrIndex = currIndex;
2567
+
2568
+ if (!isVisible) {
2569
+ setVisible(true);
2570
+ }
2571
+ });
2572
+ }
2573
+
2574
+ const container = d3.select(node).append('div').attr('class', barChartClassNames.barChartMouseContainer);
2575
+ const labelContainer = container.append('div').attr('class', barChartClassNames.barChartLabelContainer).style('position', 'absolute').style('top', y2 + "px");
2576
+
2577
+ const isMouseWithin = (e, callback) => {
2578
+ const [rectrX, rectrY] = d3.pointer(e, mouseRect);
2579
+ const [nodeX, nodeY] = d3.pointer(e, node);
2580
+ const x = rectrX - (rectrX - nodeX);
2581
+ const y = rectrY - nodeY;
2582
+ const currIndex = groups.findIndex(value => x <= value);
2583
+ const dataItem = marshalledData[currIndex][0];
2584
+
2585
+ if (dataItem.height >= y1 - y) {
2586
+ callback(dataItem);
2587
+ }
2588
+ };
2589
+
2590
+ mouseGlobal.on("click", e => isMouseWithin(e, dataItem => onBarClick && onBarClick(dataItem))).on("mousemove", e => isMouseWithin(e, dataItem => onBarHover && onBarHover(dataItem))).on("mouseleave", () => onBarHover && onBarHover(undefined));
2591
+
2592
+ if (labelPosition) {
2593
+ const concatedData = lineData ? marshalledData.map((stack, index) => stack.concat(lineData.map(_ref6 => {
2594
+ let {
2595
+ values,
2596
+ name,
2597
+ stroke
2598
+ } = _ref6;
2599
+ const {
2600
+ stacksCount
2601
+ } = stack.reduce((acc, _ref7) => {
2602
+ let {
2603
+ stackIndex
2604
+ } = _ref7;
2605
+ const {
2606
+ indexFlag,
2607
+ stacksCount
2608
+ } = acc;
2609
+
2610
+ if (stackIndex !== indexFlag) {
2611
+ return {
2612
+ indexFlag: stackIndex,
2613
+ stacksCount: stacksCount + 1
2614
+ };
2615
+ }
2616
+
2617
+ return acc;
2618
+ }, {
2619
+ indexFlag: -1,
2620
+ stacksCount: 0
2621
+ });
2622
+ const barsWidth = (barWidth * stacksCount + (barPadding || 0) * (stacksCount - 1)) / 2;
2623
+ return {
2624
+ x: stack[0].x - barWidth / 2 + barsWidth,
2625
+ y: yScale(values[index]) + marginTop,
2626
+ height: 0,
2627
+ color: stroke,
2628
+ value: values[index],
2629
+ groupName: stack[0].groupName,
2630
+ name,
2631
+ stackIndex: 0,
2632
+ groupIndex: index
2633
+ };
2634
+ }))) : marshalledData;
2635
+ const groups = labelContainer.selectAll('div').data(concatedData).enter().append('div').style('position', 'absolute').style('transform', (_, index) => "translate(" + Math.round(xScale(index)) + "px," + -(marginTop || 0) + "px)");
2636
+ const LabelFlexStyled = labelPosition === 'center' ? LabelFlexCenter : LabelFlex;
2637
+ const LabelStyle = getLabel(labelPosition);
2638
+ groups.selectAll('span').data(item => onLabelItem ? onLabelItem(item) : item).join('div').style('left', item => Math.round(item.x + barWidth / 2) + "px").style('top', item => getLabelY(labelPosition, y2, item) + "px").style('position', 'absolute').html(item => ReactDOMServer.renderToString(React__default.createElement(LabelFlexStyled, {
2639
+ className: barChartClassNames.barChartLabelFlex
2640
+ }, renderLabel ? renderLabel(_extends({}, item, {
2641
+ barWidth
2642
+ })) : React__default.createElement(LabelStyle, {
2643
+ className: barChartClassNames.barChartLabel
2644
+ }, format(item.value)))));
2645
+ }
2646
+ };
2647
+
2648
+ const _excluded$5 = ["groupName"];
2649
+ const resizeBarWidth = _ref => {
2650
+ let {
2651
+ data,
2652
+ range,
2653
+ barWidth,
2654
+ barPadding,
2655
+ sectionPadding
2656
+ } = _ref;
2657
+ const groupPadding = typeof sectionPadding === 'number' ? sectionPadding : 0;
2658
+ const chartWidth = range[1] - range[0];
2659
+ const barsWidth = data.reduce((acc, _ref2) => {
2660
+ let curr = _objectWithoutPropertiesLoose(_ref2, _excluded$5);
2661
+
2662
+ return acc + Object.keys(curr).reduce((acc, _key, index) => index > 0 ? acc + (barWidth || 0) + (barPadding || 0) : acc + barWidth, 0) + groupPadding;
2663
+ }, groupPadding);
2664
+
2665
+ if (chartWidth < barsWidth) {
2666
+ return Math.floor(barWidth * (chartWidth / barsWidth));
2667
+ }
2668
+
2669
+ return barWidth;
2670
+ };
2671
+
2672
+ const MIN_BAR_HEIGHT = 2;
2673
+ const getBars = _ref => {
2674
+ let {
2675
+ groups,
2676
+ barWidth
2677
+ } = _ref;
2678
+ return groups.selectAll('rect').data(item => item).join('rect').attr('x', item => item.x).attr('y', item => item.y).attr('width', barWidth).attr('height', item => item.value === null ? 0 : Math.max(item.height, MIN_BAR_HEIGHT)).style('fill', item => item.color);
2679
+ };
2680
+
2681
+ const MIN_BAR_HEIGHT$1 = 2;
2682
+ const draw$4 = (node, props) => {
2683
+ const {
2684
+ data,
2685
+ lineData = [],
2686
+ markers = [],
2687
+ barWidth: barWidthProp,
2688
+ barPadding,
2689
+ colors,
2690
+ margin,
2691
+ xAxisPadding,
2692
+ yAxisPadding,
2693
+ drawGridY,
2694
+ drawGridX,
2695
+ customYScale,
2696
+ customXScale,
2697
+ customYAxisLeft,
2698
+ customXAxisBottom,
2699
+ customYAxis,
2700
+ customXAxis,
2701
+ customBars,
2702
+ customize,
2703
+ dynamicTooltipEnable,
2704
+ hideTooltipGroupName,
2705
+ renderTooltip,
2706
+ labelPosition,
2707
+ renderLabel,
2708
+ tooltipY,
2709
+ tooltipBind,
2710
+ stackedLine,
2711
+ curve,
2712
+ formatTooltipValue,
2713
+ formatTooltipName,
2714
+ sectionPadding,
2715
+ minValuesLine,
2716
+ tooltipYDomain,
2717
+ marshalledMap,
2718
+ minValue,
2719
+ maxValue,
2720
+ minDomainValue,
2721
+ maxDomainValue,
2722
+ drawBars,
2723
+ setTooltipPosition,
2724
+ onLabelItem,
2725
+ isBarTooltip,
2726
+ xScaleItemWidth,
2727
+ tooltipRoot,
2728
+ tooltipClassName,
2729
+ onBarClick,
2730
+ onBarHover
2731
+ } = props;
2732
+
2733
+ if (node !== null && data.length) {
2734
+ const marginTop = margin ? margin.top : 0;
2735
+ const marginRight = margin ? margin.right : 0;
2736
+ const marginBottom = margin ? margin.bottom : 0;
2737
+ const marginLeft = margin ? margin.left : 0;
2738
+ const defaultBarWidth = 12;
2739
+ const {
2740
+ width: nodeWidth
2741
+ } = node.getBoundingClientRect();
2742
+ const width = props.width || nodeWidth;
2743
+ const height = props.height || 0;
2744
+ const barDomain = getDomain({
2745
+ data,
2746
+ minDomainValue,
2747
+ maxDomainValue
2748
+ });
2749
+ const min = typeof minValue === 'number' ? minValue : Math.min(d3.min(lineData, _ref => {
2750
+ let {
2751
+ values
2752
+ } = _ref;
2753
+ return d3.min(values);
2754
+ }) || Number.POSITIVE_INFINITY, barDomain.min || 0);
2755
+ const max = typeof maxValue === 'number' ? maxValue : Math.max(d3.max(lineData, _ref2 => {
2756
+ let {
2757
+ values
2758
+ } = _ref2;
2759
+ return d3.max(values);
2760
+ }) || Number.NEGATIVE_INFINITY, barDomain.max);
2761
+ const svg = appendSvg(node, width, height || 0);
2762
+ const yTicksCountDefault = 6;
2763
+ const labels = data.map(item => item.groupName);
2764
+ let barWidth = barWidthProp || defaultBarWidth;
2765
+ const yScale = d3.scaleLinear().domain([min, max]).range([height - marginTop - marginBottom - (xAxisPadding || 0), marginTop]).nice();
2766
+ customYScale && customYScale(yScale);
2767
+ const yTicks = yScale.ticks();
2768
+ const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
2769
+ customYAxisLeft && customYAxisLeft(yAxisLeft);
2770
+ const yTicksCount = yAxisLeft.tickArguments()[0];
2771
+ const yAxis = svg.append('g').attr('class', barChartClassNames.barChartYAxis).call(yAxisLeft);
2772
+ yAxis.selectAll('.tick').attr('class', value => {
2773
+ return value === 0 ? "tick " + barChartClassNames.barChartYAxisZeroTick : 'tick';
2774
+ });
2775
+ customYAxis && customYAxis(yAxis);
2776
+ const {
2777
+ width: yAxisWidth
2778
+ } = computeDimensions(yAxis);
2779
+ const range = [marginLeft + yAxisWidth + (yAxisPadding || 0), width - marginRight];
2780
+ const xScale = d3.scaleBand().domain(d3.range(data.length)).range(range);
2781
+ barWidth = resizeBarWidth({
2782
+ data,
2783
+ sectionPadding,
2784
+ range,
2785
+ barWidth,
2786
+ barPadding
2787
+ });
2788
+ customXScale && customXScale(xScale);
2789
+ const [x1, x2] = xScale.range();
2790
+ const xAxisBottom = d3.axisBottom(xScale).tickFormat(value => labels[Number(value)]);
2791
+
2792
+ if (typeof xScaleItemWidth === 'number') {
2793
+ xAxisBottom.tickValues(xScale.domain().filter((_, i, array) => {
2794
+ const chartWidth = x2 - x1;
2795
+ const ticks = Math.round(chartWidth / xScaleItemWidth);
2796
+ const length = array.length;
2797
+ const divider = Math.round(length / ticks);
2798
+ return !(i % divider);
2799
+ })).tickSizeOuter(0);
2800
+ }
2801
+
2802
+ customXAxisBottom && customXAxisBottom(xAxisBottom, {
2803
+ node,
2804
+ labels
2805
+ });
2806
+ const xAxis = svg.append('g').call(xAxisBottom).attr('class', barChartClassNames.barChartXAxis);
2807
+ customXAxis && customXAxis(xAxis);
2808
+ const marshalled = marshaling({
2809
+ data,
2810
+ yScale,
2811
+ xScale,
2812
+ barWidth,
2813
+ barPadding: typeof barPadding === 'number' ? barPadding : 0,
2814
+ colors,
2815
+ marginTop
2816
+ });
2817
+ const marshalledData = marshalledMap ? marshalledMap(marshalled) : marshalled;
2818
+ yAxis.attr('transform', "translate( " + (marginLeft + yAxisWidth) + ", 0)");
2819
+ drawGrid$1({
2820
+ svg,
2821
+ yScale,
2822
+ xScale,
2823
+ yTicksCount,
2824
+ drawGridY,
2825
+ drawGridX
2826
+ });
2827
+ xAxis.attr('transform', "translate(0, " + (yScale(yTicks[0]) + (xAxisPadding || 0)) + ")");
2828
+ const maskId = "height-limit-mask-" + lodash.uniqueId();
2829
+ svg.append('defs').append('mask').attr('id', maskId).append('rect').attr('width', '100%').attr('height', height - marginBottom + MIN_BAR_HEIGHT$1).attr('fill', 'white');
2830
+ const gSvg = svg.append('g').attr('class', barChartClassNames.barChartBarGlobal).attr('mask', "url(#" + maskId + ")");
2831
+ const groups = gSvg.selectAll('g').data(marshalledData).enter().append('g').attr('transform', (_, i) => "translate(" + Math.round(xScale(i)) + "," + -(marginTop || 0) + ")");
2832
+ const bars = drawBars ? drawBars({
2833
+ groups,
2834
+ yScale,
2835
+ marshalledData,
2836
+ barWidth
2837
+ }) : getBars({
2838
+ groups,
2839
+ barWidth
2840
+ });
2841
+ markers.forEach(marker => {
2842
+ if (!marker) {
2843
+ return;
2844
+ }
2845
+
2846
+ if (marker.horizontal) {
2847
+ if (marker.line) {
2848
+ svg.append('line').style("stroke", marker.lineColor || marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", marginLeft + yAxisWidth).attr("y1", yScale(marker.value) + 1).attr("x2", width).attr("y2", yScale(marker.value) + 1);
2849
+ }
2850
+
2851
+ svg.append("text").attr("y", yScale(marker.value) + 1).attr("x", marginLeft + yAxisWidth).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2852
+ return;
2853
+ }
2854
+
2855
+ if (marker.line) {
2856
+ svg.append('line').style("stroke", marker.lineColor || marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", width / data.length * marker.value + 1).attr("y1", 0).attr("x2", width / data.length * marker.value + 1).attr("y2", height - marginTop - marginBottom + 8);
2857
+ }
2858
+
2859
+ svg.append("text").attr("y", height - 2).attr("x", width / data.length * marker.value + 1).attr('text-anchor', marker.align === 'right' ? 'end' : marker.align === 'left' ? 'start' : 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
2860
+ });
2861
+ let lines = null;
2862
+
2863
+ if (Array.isArray(lineData) && lineData.length > 0) {
2864
+ lines = drawLines({
2865
+ svg,
2866
+ lineData,
2867
+ xScale,
2868
+ yScale,
2869
+ min: typeof minValuesLine === 'number' ? minValuesLine : min,
2870
+ stackedLine,
2871
+ curve
2872
+ });
2873
+ }
2874
+
2875
+ customBars && customBars({
2876
+ bars,
2877
+ yScale,
2878
+ lines,
2879
+ marshalledData,
2880
+ lineData
2881
+ });
2882
+
2883
+ if (dynamicTooltipEnable || labelPosition) {
2884
+ drawTooltip$2({
2885
+ svg,
2886
+ node,
2887
+ xScale,
2888
+ yScale,
2889
+ marshalledData,
2890
+ data,
2891
+ lineData,
2892
+ renderTooltip,
2893
+ labelPosition,
2894
+ marginTop,
2895
+ renderLabel,
2896
+ barWidth,
2897
+ barPadding,
2898
+ dynamicTooltipEnable,
2899
+ hideTooltipGroupName,
2900
+ tooltipY,
2901
+ tooltipBind,
2902
+ formatTooltipValue,
2903
+ formatTooltipName,
2904
+ tooltipYDomain,
2905
+ setTooltipPosition,
2906
+ onLabelItem,
2907
+ isBarTooltip,
2908
+ bars: groups,
2909
+ tooltipRoot,
2910
+ tooltipClassName,
2911
+ onBarClick,
2912
+ onBarHover
2913
+ });
2914
+ }
2915
+
2916
+ customize && customize({
2917
+ svg,
2918
+ marshalledData,
2919
+ yScale,
2920
+ xScale,
2921
+ lineData
2922
+ });
2923
+ }
2924
+ };
2925
+
2926
+ const BarChart = props => {
2927
+ const {
2928
+ className,
2929
+ style,
2930
+ children,
2931
+ selectable
2932
+ } = props;
2933
+ const [ref, node] = useNode();
2934
+ React.useEffect(() => {
2935
+ node && draw$4(node, props);
2936
+ }, [node, props]);
2937
+
2938
+ const onDraw = () => draw$4(node, props);
2939
+
2940
+ useResize(props.width, onDraw);
2941
+ useSelection(selectable ? node : null, props);
2942
+ return React__default.createElement("div", {
2943
+ className: className,
2944
+ style: style
2945
+ }, React__default.createElement(TooltipStyles$1, null), React__default.createElement(SvgWrapper$4, {
2946
+ ref: ref,
2947
+ selectable: selectable
2948
+ }, children));
2949
+ };
2950
+ BarChart.defaultProps = {
2951
+ data: [],
2952
+ colors: {},
2953
+ margin: {
2954
+ top: 10,
2955
+ right: 10,
2956
+ bottom: 10,
2957
+ left: 0
2958
+ },
2959
+ barWidth: 12,
2960
+ barPadding: 0,
2961
+ height: 320,
2962
+ yAxisPadding: 0,
2963
+ xAxisPadding: 0,
2964
+ tooltipBind: true,
2965
+ sectionPadding: 1
2966
+ };
2967
+
2968
+ const _excluded$6 = ["value"];
2969
+ const hundred = 100;
2970
+ const useMarshaling = _ref => {
2971
+ let {
2972
+ data,
2973
+ fullExtent,
2974
+ maxValue,
2975
+ labels
2976
+ } = _ref;
2977
+ return React.useMemo(() => {
2978
+ const fullMax = d3.max(data, item => d3.sum(item, _ref2 => {
2979
+ let {
2980
+ value
2981
+ } = _ref2;
2982
+ return value;
2983
+ }));
2984
+ const scaleLinear = d3.scaleLinear().domain([0, typeof maxValue === 'number' ? maxValue : fullMax]).range([0, hundred]);
2985
+ return {
2986
+ fullMax,
2987
+ data: data.map((item, index) => {
2988
+ if (!fullExtent) {
2989
+ scaleLinear.domain([0, typeof maxValue === 'number' ? maxValue : d3.sum(item, _ref3 => {
2990
+ let {
2991
+ value
2992
+ } = _ref3;
2993
+ return value;
2994
+ })]);
2995
+ }
2996
+
2997
+ return item.map(_ref4 => {
2998
+ let {
2999
+ value
3000
+ } = _ref4,
3001
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded$6);
3002
+
3003
+ return _extends({}, rest, {
3004
+ value,
3005
+ width: scaleLinear(value),
3006
+ groupName: labels ? labels[index] : ''
3007
+ });
3008
+ });
3009
+ })
3010
+ };
3011
+ }, [data, fullExtent, maxValue, labels]);
3012
+ };
3013
+
3014
+ var _templateObject$b, _templateObject2$5, _templateObject3$2, _templateObject4$2, _templateObject5$2, _templateObject6$2, _templateObject7$1, _templateObject8$1;
3015
+ const horizontalBarChartClassNames = {
3016
+ horizontalBarChartButtonTd: 'horizontalBarChartButtonTd',
3017
+ horizontalBarChartLabelTd: 'horizontalBarChartLabelTd',
3018
+ horizontalBarChartLabelCell: 'horizontalBarChartLabelCell',
3019
+ horizontalBarChartBarTd: 'horizontalBarChartBarTd',
3020
+ horizontalBarChartBarFlex: 'horizontalBarChartBarFlex',
3021
+ horizontalBarChartBar: 'horizontalBarChartBar',
3022
+ horizontalBarChartBarFirst: 'horizontalBarChartBarFirst',
3023
+ horizontalBarChartBarLast: 'horizontalBarChartBarLast',
3024
+ horizontalBarChartBarOnly: 'horizontalBarChartBarOnly',
3025
+ horizontalBarChartTooltipFlex: 'horizontalBarChartTooltipFlex',
3026
+ horizontalBarChartStackWrapper: 'horizontalBarChartStackWrapper',
3027
+ horizontalBarChartTooltipContainer: 'horizontalBarChartTooltipContainer',
3028
+ horizontalBarChartStackSumContainer: 'horizontalBarChartStackSumContainer',
3029
+ horizontalBarChartStackSum: 'horizontalBarChartStackSum',
3030
+ horizontalBarChartXScaleTd: 'horizontalBarChartXScaleTd',
3031
+ horizontalBarChartXScaleTicks: 'horizontalBarChartXScaleTicks',
3032
+ horizontalBarChartXScaleTick: 'horizontalBarChartXScaleTick',
3033
+ horizontalBarChartTooltipItem: 'horizontalBarChartTooltipItem',
3034
+ horizontalBarChartTooltipName: 'horizontalBarChartTooltipName',
3035
+ horizontalBarChartTooltipValue: 'horizontalBarChartTooltipValue'
3036
+ };
3037
+ const Table = /*#__PURE__*/styled__default.table(_templateObject$b || (_templateObject$b = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n"])));
3038
+ const LabelCell = /*#__PURE__*/styled__default.div(_templateObject2$5 || (_templateObject2$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: right;\n"])));
3039
+ const BarFlex = /*#__PURE__*/styled__default.div(_templateObject3$2 || (_templateObject3$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n display: flex;\n height: 1rem;\n"])));
3040
+ const BarsTd = /*#__PURE__*/styled__default.td(_templateObject4$2 || (_templateObject4$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n position: relative;\n vertical-align: middle;\n"])));
3041
+ const TooltipFlex$1 = /*#__PURE__*/styled__default(TooltipFlex)(_templateObject5$2 || (_templateObject5$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 0;\n left: 50%;\n transform: translate(-50%, -50%);\n will-change: left, top;\n"])));
3042
+ const StackSumContainer = /*#__PURE__*/styled__default.div(_templateObject6$2 || (_templateObject6$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n"])));
3043
+ const StackSum = /*#__PURE__*/styled__default.div(_templateObject7$1 || (_templateObject7$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: nowrap;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(0, -50%);\n"])));
3044
+ const StackWrapper = /*#__PURE__*/styled__default.div(_templateObject8$1 || (_templateObject8$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 0;\n display: flex;\n justify-content: flex-start;\n height: 100%;\n"])));
3045
+
3046
+ const Tooltip = _ref => {
3047
+ let {
3048
+ renderTooltip,
3049
+ bars,
3050
+ style,
3051
+ className
3052
+ } = _ref;
3053
+ const format = d3.format(',');
3054
+ return React__default.createElement(TooltipFlex$1, {
3055
+ className: horizontalBarChartClassNames.horizontalBarChartTooltipFlex + " " + (className || ''),
3056
+ style: style
3057
+ }, React__default.createElement(TooltipContainer, {
3058
+ className: horizontalBarChartClassNames.horizontalBarChartTooltipContainer
3059
+ }, renderTooltip ? renderTooltip(bars) : bars.map((_ref2, index) => {
3060
+ let {
3061
+ color,
3062
+ name,
3063
+ value,
3064
+ groupName
3065
+ } = _ref2;
3066
+ return React__default.createElement(TooltipItem, {
3067
+ key: (name || '') + "-" + index + "-" + groupName,
3068
+ className: horizontalBarChartClassNames.horizontalBarChartTooltipItem
3069
+ }, color && React__default.createElement(ColorBox, {
3070
+ style: {
3071
+ backgroundColor: color
3072
+ }
3073
+ }), name && React__default.createElement(Name$1, {
3074
+ className: horizontalBarChartClassNames.horizontalBarChartTooltipName
3075
+ }, name), React__default.createElement(Value, {
3076
+ className: horizontalBarChartClassNames.horizontalBarChartTooltipValue
3077
+ }, format(value)));
3078
+ })));
3079
+ };
3080
+
3081
+ const rootElement = /*#__PURE__*/document.createElement('div');
3082
+ const useTooltip = _ref => {
3083
+ let {
3084
+ renderTooltip,
3085
+ tooltipBind,
3086
+ tooltipStyle,
3087
+ tooltipRoot,
3088
+ tooltipClassName,
3089
+ hideTooltip
3090
+ } = _ref;
3091
+ React.useEffect(() => {
3092
+ const container = tooltipRoot || document.querySelector('body');
3093
+ container && container.appendChild(rootElement);
3094
+ return () => {
3095
+ reactDom.unmountComponentAtNode(rootElement);
3096
+ };
3097
+ }, [tooltipRoot]);
3098
+ const onMouseMove = React.useCallback((event, bars) => {
3099
+ let [x, y] = d3.pointer(event, document);
3100
+
3101
+ if (!tooltipBind && 'getBoundingClientRect' in event.target) {
3102
+ const {
3103
+ width,
3104
+ height
3105
+ } = event.target.getBoundingClientRect();
3106
+ const [barX, barY] = d3.pointer(event, event.target);
3107
+ x = x - barX + width / 2;
3108
+ y = y - barY + height / 2;
3109
+ }
3110
+
3111
+ if (rootElement) {
3112
+ rootElement.style.visibility = 'visible';
3113
+ }
3114
+
3115
+ reactDom.render(React__default.createElement(Tooltip, {
3116
+ style: _extends({
3117
+ left: x,
3118
+ top: y
3119
+ }, tooltipStyle),
3120
+ bars: bars,
3121
+ renderTooltip: renderTooltip,
3122
+ className: tooltipClassName
3123
+ }), rootElement);
3124
+ }, [tooltipClassName, tooltipStyle, renderTooltip, tooltipBind]);
3125
+ const onMouseLeave = React.useCallback(() => {
3126
+ if (rootElement) {
3127
+ rootElement.style.visibility = 'hidden';
3128
+ hideTooltip && hideTooltip();
3129
+ }
3130
+ }, [hideTooltip]);
3131
+ return [onMouseMove, onMouseLeave];
3132
+ };
3133
+
3134
+ const _excluded$7 = ["item", "mouseMove", "mouseLeave", "tooltipBind"];
3135
+ const useStackWrapper = stackedTooltip => {
3136
+ return React.useMemo(() => stackedTooltip ? _ref => {
3137
+ let {
3138
+ item,
3139
+ mouseMove,
3140
+ mouseLeave,
3141
+ tooltipBind
3142
+ } = _ref,
3143
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
3144
+
3145
+ return React__default.createElement(StackWrapper, Object.assign({
3146
+ className: horizontalBarChartClassNames.horizontalBarChartStackWrapper,
3147
+ onMouseOver: event => mouseMove(event, item),
3148
+ onMouseMove: tooltipBind ? event => mouseMove(event, item) : void 0,
3149
+ onMouseOut: mouseLeave
3150
+ }, props));
3151
+ } : _ref2 => {
3152
+ let {
3153
+ children
3154
+ } = _ref2;
3155
+ return React__default.createElement(React.Fragment, null, children);
3156
+ }, [stackedTooltip]);
3157
+ };
3158
+
3159
+ var _templateObject$c;
3160
+ const BarStyled = /*#__PURE__*/styled__default.div(_templateObject$c || (_templateObject$c = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n display: inline-flex;\n height: 100%;\n"])));
3161
+
3162
+ const Bar = _ref => {
3163
+ let {
3164
+ withTooltip,
3165
+ bar,
3166
+ formatNativeTitle,
3167
+ tooltipBind,
3168
+ mouseMove,
3169
+ mouseLeave,
3170
+ pointerEventsNone,
3171
+ isFirstChild,
3172
+ isLastChild,
3173
+ isOnlyChild
3174
+ } = _ref;
3175
+ const {
3176
+ color,
3177
+ width
3178
+ } = bar;
3179
+ const ceiledWidth = Math.abs(width);
3180
+ const onMouseMove = withTooltip ? event => mouseMove(event, [bar]) : void 0;
3181
+ const onMouseLeave = withTooltip ? () => mouseLeave() : void 0;
3182
+ return React__default.createElement(BarStyled, {
3183
+ className: horizontalBarChartClassNames.horizontalBarChartBar + " " + (isFirstChild ? horizontalBarChartClassNames.horizontalBarChartBarFirst : '') + " " + (isLastChild ? horizontalBarChartClassNames.horizontalBarChartBarLast : '') + " " + (isOnlyChild ? horizontalBarChartClassNames.horizontalBarChartBarOnly : ''),
3184
+ style: {
3185
+ width: ceiledWidth + "%",
3186
+ backgroundColor: color,
3187
+ pointerEvents: pointerEventsNone ? 'none' : 'auto'
3188
+ },
3189
+ title: formatNativeTitle ? formatNativeTitle(bar) : '',
3190
+ onMouseOver: onMouseMove,
3191
+ onMouseMove: tooltipBind ? onMouseMove : void 0,
3192
+ onMouseOut: onMouseLeave
3193
+ });
3194
+ };
3195
+
3196
+ const hundred$1 = 100;
3197
+ const useScale = _ref => {
3198
+ let {
3199
+ maxValue,
3200
+ scaleTicks,
3201
+ scaleDomain
3202
+ } = _ref;
3203
+ return React.useMemo(() => {
3204
+ const scaleLinear = d3.scaleLinear().domain([0, maxValue]).range([0, hundred$1]);
3205
+ const ticks = scaleLinear.ticks(scaleTicks);
3206
+ return (scaleDomain || ticks).map(value => ({
3207
+ value,
3208
+ x: scaleLinear(value)
3209
+ }));
3210
+ }, [maxValue, scaleTicks, scaleDomain]);
3211
+ };
3212
+
3213
+ var _templateObject$d, _templateObject2$6, _templateObject3$3;
3214
+ const TickTd = /*#__PURE__*/styled__default.td(_templateObject$d || (_templateObject$d = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n"])));
3215
+ const Ticks = /*#__PURE__*/styled__default.div(_templateObject2$6 || (_templateObject2$6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n height: 1rem;\n"])));
3216
+ const Tick = /*#__PURE__*/styled__default.div(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: nowrap;\n width: 0;\n height: 0;\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n display: flex;\n align-items: center;\n justify-content: center;\n"])));
3217
+
3218
+ const XScale = _ref => {
3219
+ let {
3220
+ maxValue,
3221
+ scaleTicks,
3222
+ renderTicks,
3223
+ scaleDomain
3224
+ } = _ref;
3225
+ const range = useScale({
3226
+ maxValue,
3227
+ scaleTicks,
3228
+ scaleDomain
3229
+ });
3230
+ const format = d3.format(',');
3231
+ return React__default.createElement("tr", null, React__default.createElement("td", null), React__default.createElement(TickTd, {
3232
+ className: horizontalBarChartClassNames.horizontalBarChartXScaleTd
3233
+ }, React__default.createElement(Ticks, {
3234
+ className: horizontalBarChartClassNames.horizontalBarChartXScaleTicks
3235
+ }, range.map((tick, index, ticks) => {
3236
+ const {
3237
+ value,
3238
+ x
3239
+ } = tick;
3240
+ return React__default.createElement(Tick, {
3241
+ key: value,
3242
+ className: horizontalBarChartClassNames.horizontalBarChartXScaleTick,
3243
+ style: {
3244
+ left: x + "%",
3245
+ justifyContent: index === 0 ? 'flex-start' : index === ticks.length - 1 ? 'flex-end' : ''
3246
+ }
3247
+ }, renderTicks ? renderTicks(tick) : format(value));
3248
+ }))));
3249
+ };
3250
+
3251
+ const HorizontalBarChart = _ref => {
3252
+ let {
3253
+ data,
3254
+ className,
3255
+ style,
3256
+ children,
3257
+ labels,
3258
+ fullExtent,
3259
+ maxValue,
3260
+ formatNativeTitle,
3261
+ renderTooltip,
3262
+ withTooltip,
3263
+ withStackSum,
3264
+ tooltipBind,
3265
+ scaleTicks,
3266
+ renderTicks,
3267
+ renderButton,
3268
+ tooltipStyle,
3269
+ tooltipClassName,
3270
+ scaleDomain,
3271
+ renderDataTable,
3272
+ thead,
3273
+ withoutXScale,
3274
+ stackedTooltip,
3275
+ fullChartTooltip,
3276
+ hideTooltip
3277
+ } = _ref;
3278
+ const {
3279
+ fullMax,
3280
+ data: marshalingData
3281
+ } = useMarshaling({
3282
+ data,
3283
+ fullExtent,
3284
+ maxValue,
3285
+ labels
3286
+ });
3287
+ const [mouseMove, mouseLeave] = useTooltip({
3288
+ renderTooltip,
3289
+ tooltipBind,
3290
+ tooltipStyle,
3291
+ tooltipClassName,
3292
+ hideTooltip
3293
+ });
3294
+ const Stack = useStackWrapper(stackedTooltip);
3295
+ return React__default.createElement(Table, {
3296
+ className: className,
3297
+ style: style,
3298
+ onMouseOver: fullChartTooltip ? event => mouseMove(event, marshalingData.flat()) : void 0,
3299
+ onMouseMove: fullChartTooltip ? event => mouseMove(event, marshalingData.flat()) : void 0,
3300
+ onMouseOut: fullChartTooltip ? mouseLeave : void 0
3301
+ }, thead, React__default.createElement("tbody", null, marshalingData.map((item, rowIndex) => {
3302
+ const stackSum = (withStackSum || renderDataTable) && d3.sum(item, _ref2 => {
3303
+ let {
3304
+ value
3305
+ } = _ref2;
3306
+ return value;
3307
+ });
3308
+ const sumWidth = d3.sum(item, _ref3 => {
3309
+ let {
3310
+ width
3311
+ } = _ref3;
3312
+ return width;
3313
+ });
3314
+ return React__default.createElement("tr", {
3315
+ key: "row-" + rowIndex
3316
+ }, typeof renderButton === 'function' && React__default.createElement("td", {
3317
+ className: horizontalBarChartClassNames.horizontalBarChartButtonTd
3318
+ }, renderButton(item, rowIndex)), React__default.createElement("td", {
3319
+ className: horizontalBarChartClassNames.horizontalBarChartLabelTd
3320
+ }, labels && labels[rowIndex] && React__default.createElement(LabelCell, {
3321
+ className: horizontalBarChartClassNames.horizontalBarChartLabelCell
3322
+ }, labels[rowIndex])), React__default.createElement(BarsTd, {
3323
+ className: horizontalBarChartClassNames.horizontalBarChartBarTd,
3324
+ style: {
3325
+ pointerEvents: fullChartTooltip ? 'none' : 'auto'
3326
+ }
3327
+ }, React__default.createElement(BarFlex, {
3328
+ className: horizontalBarChartClassNames.horizontalBarChartBarFlex,
3329
+ style: {
3330
+ pointerEvents: fullChartTooltip ? 'none' : 'auto'
3331
+ }
3332
+ }, React__default.createElement(Stack, {
3333
+ style: stackedTooltip ? {
3334
+ width: sumWidth + "%"
3335
+ } : void 0,
3336
+ item: item,
3337
+ tooltipBind: tooltipBind,
3338
+ mouseMove: mouseMove,
3339
+ mouseLeave: mouseLeave
3340
+ }), item.map((bar, barIndex, array) => bar.value !== 0 && React__default.createElement(Bar, {
3341
+ key: "bar-" + (bar.name || '') + "-" + barIndex,
3342
+ formatNativeTitle: formatNativeTitle,
3343
+ bar: bar,
3344
+ tooltipBind: tooltipBind,
3345
+ pointerEventsNone: stackedTooltip || fullChartTooltip,
3346
+ withTooltip: withTooltip && !stackedTooltip,
3347
+ mouseMove: mouseMove,
3348
+ mouseLeave: mouseLeave,
3349
+ isOnlyChild: array.length === 1,
3350
+ isFirstChild: barIndex === 0 && array.length > 1,
3351
+ isLastChild: array.length - 1 === barIndex && array.length > 1
3352
+ })), withStackSum && React__default.createElement(StackSumContainer, {
3353
+ className: horizontalBarChartClassNames.horizontalBarChartStackSumContainer
3354
+ }, React__default.createElement(StackSum, {
3355
+ className: horizontalBarChartClassNames.horizontalBarChartStackSum
3356
+ }, stackSum)))), renderDataTable && renderDataTable(item, stackSum, rowIndex));
3357
+ }), !withoutXScale && React__default.createElement(XScale, {
3358
+ maxValue: typeof maxValue === 'number' ? maxValue : fullMax,
3359
+ scaleTicks: scaleTicks,
3360
+ renderTicks: renderTicks,
3361
+ scaleDomain: scaleDomain
3362
+ }), children));
3363
+ };
3364
+ HorizontalBarChart.defaultProps = {
3365
+ fullExtent: true,
3366
+ withTooltip: false,
3367
+ withStackSum: false,
3368
+ tooltipBind: false,
3369
+ scaleTicks: 4,
3370
+ withoutXScale: false
3371
+ };
3372
+
3373
+ const bubbleChartDefaultProps = {
3374
+ height: 280,
3375
+ minSize: 6,
3376
+ maxSize: 30,
3377
+ margin: {
3378
+ top: 10,
3379
+ right: 15,
3380
+ bottom: 10,
3381
+ left: 0
3382
+ },
3383
+ yAxisPadding: 10,
3384
+ xAxisPadding: 10,
3385
+ yScaleLabelPadding: 10
3386
+ };
3387
+
3388
+ var _templateObject$e, _templateObject2$7;
3389
+ const bubbleChartClassNames = {
3390
+ bubbleChartYAxis: 'bubbleChartYAxis',
3391
+ bubbleChartYAxisZeroTick: 'bubbleChartYAxisZeroTick',
3392
+ bubbleChartXAxis: 'bubbleChartXAxis',
3393
+ bubbleChartGridGlobal: 'bubbleChartGridGlobal',
3394
+ bubbleChartGridLineX: 'bubbleChartGridLineX',
3395
+ bubbleChartGridLineY: 'bubbleChartGridLineY',
3396
+ bubbleChartCircle: 'bubbleChartCircle',
3397
+ bubbleChartYScaleLabel: 'bubbleChartYScaleLabel',
3398
+ bubbleChartTooltip: 'bubbleChartTooltip',
3399
+ bubbleChartTooltipContainer: 'bubbleChartTooltipContainer',
3400
+ bubbleChartTooltipFlex: 'bubbleChartTooltipFlex',
3401
+ bubbleChartTip: 'bubbleChartTip'
3402
+ };
3403
+ const SvgWrapper$5 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$e || (_templateObject$e = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", ",\n .", ",\n .", " {\n shape-rendering: crispEdges;\n }\n\n .", ",\n .", " {\n stroke: rgba(149, 149, 149, 0.24);\n }\n\n .", " {\n font-size: 10px;\n }\n"])), bubbleChartClassNames.bubbleChartYAxis, bubbleChartClassNames.bubbleChartXAxis, bubbleChartClassNames.bubbleChartGridGlobal, bubbleChartClassNames.bubbleChartGridLineX, bubbleChartClassNames.bubbleChartGridLineY, bubbleChartClassNames.bubbleChartYScaleLabel);
3404
+ const TooltipStyles$2 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$7 || (_templateObject2$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n position: absolute;\n transition: opacity 150ms cubic-bezier(0.2, 1, 0.6, 1);\n pointer-events: none;\n z-index: 1;\n }\n"])), bubbleChartClassNames.bubbleChartTooltipContainer);
3405
+
3406
+ const drawGrid$2 = _ref => {
3407
+ let {
3408
+ svg,
3409
+ yScale,
3410
+ xScale,
3411
+ yTicksCount,
3412
+ drawGridX,
3413
+ drawGridY
3414
+ } = _ref;
3415
+ if (!drawGridY && !drawGridX) return;
3416
+ const [min, max] = xScale.domain();
3417
+ const global = svg.append('g').attr('class', bubbleChartClassNames.bubbleChartGridGlobal);
3418
+ const yTicks = yScale.ticks(yTicksCount);
3419
+
3420
+ if (drawGridX) {
3421
+ global.append('g').selectAll('line').data(yTicks).join('line').attr('class', bubbleChartClassNames.bubbleChartGridLineX).attr('x1', () => xScale(min)).attr('x2', () => xScale(max)).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
3422
+ }
3423
+
3424
+ if (drawGridY) {
3425
+ global.append('g').selectAll('line').data(xScale.ticks(yTicksCount)).join('line').attr('class', bubbleChartClassNames.bubbleChartGridLineY).attr('x1', d => Math.round(xScale(d))).attr('x2', d => Math.round(xScale(d))).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
3426
+ }
3427
+ };
3428
+
3429
+ var _templateObject$f;
3430
+ const Tooltip$1 = /*#__PURE__*/styled__default.div(_templateObject$f || (_templateObject$f = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n font-size: 12px;\n white-space: nowrap;\n"])));
3431
+
3432
+ const drawTooltip$3 = _ref => {
3433
+ let {
3434
+ bubbles,
3435
+ tooltipRoot,
3436
+ tooltipClassName,
3437
+ renderTooltip
3438
+ } = _ref;
3439
+ const root = tooltipRoot || document.querySelector('body');
3440
+ const format = d3.format(',');
3441
+ let container = d3.select(root).select("." + bubbleChartClassNames.bubbleChartTooltip);
3442
+
3443
+ if (container.node() === null) {
3444
+ container = d3.select(root).append('div').attr('class', bubbleChartClassNames.bubbleChartTooltip);
3445
+ }
3446
+
3447
+ let tooltip = container.append('div').attr('class', bubbleChartClassNames.bubbleChartTooltipContainer + " " + (tooltipClassName || '')).style('opacity', '0');
3448
+ bubbles.on('mouseover.tooltip', (event, data) => {
3449
+ const {
3450
+ sizeValue
3451
+ } = data;
3452
+ const circle = event.currentTarget;
3453
+ const {
3454
+ x,
3455
+ y,
3456
+ width
3457
+ } = circle.getBoundingClientRect();
3458
+ const left = window.pageXOffset + x + width / 2;
3459
+ const top = window.pageYOffset + y;
3460
+ tooltip.style('left', left + "px").style('top', top + "px").html(() => {
3461
+ const html = ReactDOMServer.renderToString(React__default.createElement(Tooltip$1, {
3462
+ className: bubbleChartClassNames.bubbleChartTooltipFlex
3463
+ }, React__default.createElement(TooltipContainer, {
3464
+ className: bubbleChartClassNames.bubbleChartTip
3465
+ }, format(sizeValue))));
3466
+ return html;
3467
+ });
3468
+ renderTooltip && renderTooltip({
3469
+ tooltip,
3470
+ data,
3471
+ circle
3472
+ });
3473
+ tooltip.style('opacity', '1');
3474
+ });
3475
+ bubbles.on('mouseout.tooltip', () => {
3476
+ tooltip.style('opacity', '0');
3477
+ });
3478
+ };
3479
+
3480
+ const draw$5 = (node, props) => {
3481
+ const {
3482
+ data,
3483
+ margin,
3484
+ xAxisPadding,
3485
+ yAxisPadding,
3486
+ customYScale,
3487
+ customYAxis,
3488
+ customXScale,
3489
+ customXAxis,
3490
+ minSize,
3491
+ maxSize,
3492
+ minYValue,
3493
+ maxYValue,
3494
+ drawGridY,
3495
+ drawGridX,
3496
+ scaleLog,
3497
+ xScaleItemWidth,
3498
+ bubbleStyle,
3499
+ customize,
3500
+ yScaleLabel,
3501
+ yScaleLabelPadding,
3502
+ enableTooltip,
3503
+ tooltipRoot,
3504
+ tooltipClassName,
3505
+ renderTooltip
3506
+ } = props;
3507
+
3508
+ if (node !== null && data.length) {
3509
+ const marginTop = margin ? margin.top : 0;
3510
+ const marginRight = margin ? margin.right : 0;
3511
+ const marginBottom = margin ? margin.bottom : 0;
3512
+ const marginLeft = margin ? margin.left : 0;
3513
+ const {
3514
+ width: nodeWidth
3515
+ } = node.getBoundingClientRect();
3516
+ const width = props.width || nodeWidth;
3517
+ const height = props.height || 0;
3518
+ const yTicksCountDefault = 6;
3519
+ const minY = typeof minYValue === 'number' ? minYValue : d3.min(data, _ref => {
3520
+ let {
3521
+ yValue
3522
+ } = _ref;
3523
+ return yValue;
3524
+ });
3525
+ const maxY = typeof maxYValue === 'number' ? maxYValue : d3.max(data, _ref2 => {
3526
+ let {
3527
+ yValue
3528
+ } = _ref2;
3529
+ return yValue;
3530
+ });
3531
+ const svg = appendSvg(node, width, height || 0);
3532
+ const sizeScale = scaleLog ? d3.scaleLog().domain([d3.min(data, _ref3 => {
3533
+ let {
3534
+ sizeValue
3535
+ } = _ref3;
3536
+ return sizeValue;
3537
+ }) || 0.1, d3.max(data, _ref4 => {
3538
+ let {
3539
+ sizeValue
3540
+ } = _ref4;
3541
+ return sizeValue;
3542
+ }) || 0.1]).range([minSize || bubbleChartDefaultProps.minSize || 0.1, maxSize || bubbleChartDefaultProps.maxSize || 0.1]) : d3.scaleLinear().domain([d3.min(data, _ref5 => {
3543
+ let {
3544
+ sizeValue
3545
+ } = _ref5;
3546
+ return sizeValue;
3547
+ }), d3.max(data, _ref6 => {
3548
+ let {
3549
+ sizeValue
3550
+ } = _ref6;
3551
+ return sizeValue;
3552
+ })]).range([minSize || bubbleChartDefaultProps.minSize, maxSize || bubbleChartDefaultProps.maxSize]);
3553
+ const yRange1 = height - marginTop - marginBottom - (xAxisPadding || 0);
3554
+ const yScale = scaleLog ? d3.scaleLog().domain([minY || 0.1, maxY || 0.1]).range([yRange1 || 0.1, marginTop || 0.1]).nice() : d3.scaleLinear().domain([minY, maxY]).range([yRange1, marginTop]).nice();
3555
+ customYScale && customYScale(yScale);
3556
+ const yTicks = yScale.ticks();
3557
+ const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
3558
+ const yTicksCount = yAxisLeft.tickArguments()[0];
3559
+ const yAxis = svg.append('g').attr('class', bubbleChartClassNames.bubbleChartYAxis).call(yAxisLeft);
3560
+ let yScaleLabelHeight = yScaleLabelPadding || 0;
3561
+
3562
+ if (yScaleLabel) {
3563
+ const label = svg.append('text').text(yScaleLabel).attr('class', bubbleChartClassNames.bubbleChartYScaleLabel);
3564
+ const {
3565
+ width,
3566
+ height
3567
+ } = computeDimensions(label);
3568
+ yScaleLabelHeight = yScaleLabelHeight + height;
3569
+ label.attr('transform', "rotate(-90) translate(-" + (yRange1 + marginBottom + width) / 2 + ", " + height + ")");
3570
+ }
3571
+
3572
+ yAxis.selectAll('.tick').attr('class', value => {
3573
+ return value === 0 ? "tick " + bubbleChartClassNames.bubbleChartYAxisZeroTick : 'tick';
3574
+ });
3575
+ customYAxis && customYAxis(yAxis);
3576
+ const {
3577
+ width: yAxisWidth
3578
+ } = computeDimensions(yAxis);
3579
+ const xScale = scaleLog ? d3.scaleLog().domain([d3.min(data, _ref7 => {
3580
+ let {
3581
+ xValue
3582
+ } = _ref7;
3583
+ return xValue;
3584
+ }) || 0.1, d3.max(data, _ref8 => {
3585
+ let {
3586
+ xValue
3587
+ } = _ref8;
3588
+ return xValue;
3589
+ }) || 0.1]).range([marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight || 0.1, width - marginRight || 0.1]) : d3.scaleLinear().domain([d3.min(data, _ref9 => {
3590
+ let {
3591
+ xValue
3592
+ } = _ref9;
3593
+ return xValue;
3594
+ }), d3.max(data, _ref10 => {
3595
+ let {
3596
+ xValue
3597
+ } = _ref10;
3598
+ return xValue;
3599
+ })]).range([marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight, width - marginRight]);
3600
+ customXScale && customXScale(xScale);
3601
+ const xAxisBottom = d3.axisBottom(xScale);
3602
+
3603
+ if (typeof xScaleItemWidth === 'number') {
3604
+ const [x1, x2] = xScale.range();
3605
+ const chartWidth = x2 - x1;
3606
+ xAxisBottom.ticks(Math.round(chartWidth / xScaleItemWidth)).tickSizeOuter(0);
3607
+ }
3608
+
3609
+ const xAxis = svg.append('g').call(xAxisBottom).attr('class', bubbleChartClassNames.bubbleChartXAxis);
3610
+ customXAxis && customXAxis(xAxis);
3611
+ yAxis.attr('transform', "translate(" + (marginLeft + yAxisWidth + yScaleLabelHeight) + ", 0)");
3612
+ drawGrid$2({
3613
+ svg,
3614
+ yScale,
3615
+ xScale,
3616
+ yTicksCount,
3617
+ drawGridY,
3618
+ drawGridX
3619
+ });
3620
+ xAxis.attr('transform', "translate(0, " + (yScale(yTicks[0]) + (xAxisPadding || 0)) + ")");
3621
+ const bubbles = svg.append('g').selectAll('dot').data(data).enter().append('circle').attr('class', bubbleChartClassNames.bubbleChartCircle).attr('cx', _ref11 => {
3622
+ let {
3623
+ xValue
3624
+ } = _ref11;
3625
+ return xScale(xValue);
3626
+ }).attr('cy', _ref12 => {
3627
+ let {
3628
+ yValue
3629
+ } = _ref12;
3630
+ return yScale(yValue);
3631
+ }).attr('r', _ref13 => {
3632
+ let {
3633
+ sizeValue
3634
+ } = _ref13;
3635
+ return sizeScale(sizeValue) / 2;
3636
+ }).attr('fill', _ref14 => {
3637
+ let {
3638
+ color
3639
+ } = _ref14;
3640
+ return color || 'rgba(0, 176, 113, 0.6)';
3641
+ }).attr('stroke', _ref15 => {
3642
+ let {
3643
+ stroke
3644
+ } = _ref15;
3645
+ return stroke || 'transparent';
3646
+ }).attr('style', _ref16 => {
3647
+ let {
3648
+ style
3649
+ } = _ref16;
3650
+ return style || bubbleStyle || '';
3651
+ });
3652
+
3653
+ if (enableTooltip) {
3654
+ drawTooltip$3({
3655
+ bubbles,
3656
+ tooltipRoot,
3657
+ tooltipClassName,
3658
+ renderTooltip
3659
+ });
3660
+ }
3661
+
3662
+ customize && customize({
3663
+ svg,
3664
+ bubbles,
3665
+ yScale,
3666
+ xScale,
3667
+ sizeScale
3668
+ });
3669
+ }
3670
+ };
3671
+
3672
+ const unmount = tooltipRoot => {
3673
+ const root = tooltipRoot || document.querySelector('body');
3674
+ d3.select(root).select("." + bubbleChartClassNames.bubbleChartTooltip).remove();
3675
+ };
3676
+
3677
+ const BubbleChart = props => {
3678
+ const {
3679
+ className,
3680
+ style,
3681
+ children,
3682
+ tooltipRoot
3683
+ } = props;
3684
+ const [ref, node] = useNode();
3685
+ React.useEffect(() => {
3686
+ node && draw$5(node, props);
3687
+ }, [node, props]);
3688
+ React.useEffect(() => {
3689
+ return () => unmount(tooltipRoot);
3690
+ }, [tooltipRoot]);
3691
+
3692
+ const onDraw = () => draw$5(node, props);
3693
+
3694
+ useResize(props.width, onDraw);
3695
+ return React__default.createElement("div", {
3696
+ className: className,
3697
+ style: style
3698
+ }, React__default.createElement(TooltipStyles$2, null), React__default.createElement(SvgWrapper$5, {
3699
+ ref: ref
3700
+ }, children));
3701
+ };
3702
+ BubbleChart.defaultProps = bubbleChartDefaultProps;
3703
+
3704
+ exports.BarChart = BarChart;
3705
+ exports.BubbleChart = BubbleChart;
3706
+ exports.CalendarChart = CalendarChart;
3707
+ exports.ChartWrapper = Wrapper;
3708
+ exports.HorizontalBarChart = HorizontalBarChart;
3709
+ exports.LineChart = LineChart;
3710
+ exports.PieChart = PieChart;
3711
+ exports.RadarChart = RadarChart;
3712
+ exports.SwipeScroll = SwipeScroll;
3713
+ exports.appendSvg = appendSvg;
3714
+ exports.barChartClassNames = barChartClassNames;
3715
+ exports.bubbleChartClassNames = bubbleChartClassNames;
3716
+ exports.calendarChartClassNames = calendarChartClassNames;
3717
+ exports.horizontalBarChartClassNames = horizontalBarChartClassNames;
3718
+ exports.lineChartClassNames = lineChartClassNames;
3719
+ exports.pieChartclassNames = pieChartclassNames;
3720
+ exports.radarChartclassNames = radarChartclassNames;
3721
+ exports.useNode = useNode;
3722
+ exports.useResize = useResize;
3723
+ //# sourceMappingURL=charts.cjs.development.js.map