sea-chart 2.0.36 → 2.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/api/index.js +59 -17
  2. package/dist/assets/css/sea-chart-d3-tooltip.css +1 -0
  3. package/dist/components/color-popover/color-rules-popover.js +2 -4
  4. package/dist/components/drill-down-settings/drill-down-fields-popover/index.js +4 -5
  5. package/dist/components/icon/index.js +13 -9
  6. package/dist/components/number-input/index.js +13 -7
  7. package/dist/components/popover/hide-column-popover/hide-column-popover-widgets/hide-column-item.js +3 -7
  8. package/dist/components/popover/hide-column-popover/hide-column-popover.css +1 -5
  9. package/dist/components/popover/hide-column-popover/hide-column-popover.js +4 -2
  10. package/dist/components/popover/sort-popover/sort-popover.js +7 -6
  11. package/dist/components/statistic-record-dialog/index.js +8 -9
  12. package/dist/components/tooltip/index.js +8 -26
  13. package/dist/editor/index.js +1 -5
  14. package/dist/locale/lang/de.js +0 -1
  15. package/dist/locale/lang/en.js +0 -1
  16. package/dist/locale/lang/es.js +0 -1
  17. package/dist/locale/lang/fr.js +0 -1
  18. package/dist/locale/lang/pt.js +0 -1
  19. package/dist/locale/lang/ru.js +0 -1
  20. package/dist/locale/lang/zh_CN.js +0 -1
  21. package/dist/model/funnel.js +2 -2
  22. package/dist/model/map-bubble.js +0 -4
  23. package/dist/services/map-json.js +0 -3
  24. package/dist/settings/advance-bar-settings/data-settings.js +1 -1
  25. package/dist/settings/advance-bar-settings/style-settings.js +3 -4
  26. package/dist/settings/bar-settings/data-settings.js +1 -1
  27. package/dist/settings/bar-settings/style-settings.js +2 -2
  28. package/dist/settings/basic-number-card/data-settings.js +2 -3
  29. package/dist/settings/combination-settings/data-settings.js +1 -0
  30. package/dist/settings/combination-settings/style-settings.js +2 -2
  31. package/dist/settings/dashboard-settings/data-settings.js +2 -3
  32. package/dist/settings/funnel-settings/components/funnel-layer-setting.js +7 -7
  33. package/dist/settings/index.js +3 -8
  34. package/dist/settings/table-element-settings/components/data-filter.js +25 -24
  35. package/dist/settings/table-element-settings/index.css +31 -1
  36. package/dist/settings/table-settings/data-settings.js +2 -3
  37. package/dist/settings/time-comparison-settings/style-settings.js +2 -2
  38. package/dist/settings/widgets/basic-summary/index.js +7 -8
  39. package/dist/settings/widgets/common-data-settings.js +6 -7
  40. package/dist/settings/widgets/data-filter/index.js +22 -30
  41. package/dist/settings/widgets/group-by.js +3 -4
  42. package/dist/settings/widgets/summary-settings.js +2 -3
  43. package/dist/settings/widgets/y-axis-group-settings.js +2 -3
  44. package/dist/utils/cell-format-utils.js +7 -9
  45. package/dist/utils/chart-utils/base-utils.js +86 -194
  46. package/dist/utils/chart-utils/index.js +3 -5
  47. package/dist/utils/chart-utils/original-data-utils/basic-chart-calculator.js +5 -5
  48. package/dist/utils/chart-utils/original-data-utils/card-calculator.js +2 -8
  49. package/dist/utils/chart-utils/original-data-utils/dashboard-calculator.js +3 -12
  50. package/dist/utils/chart-utils/original-data-utils/pivot-table-calculator.js +1 -4
  51. package/dist/utils/chart-utils/original-data-utils/scatter-calculator.js +0 -1
  52. package/dist/utils/chart-utils/original-data-utils/trend-calculator.js +3 -24
  53. package/dist/utils/chart-utils/sql-statistics-utils.js +177 -182
  54. package/dist/utils/column-utils.js +7 -20
  55. package/dist/utils/contexts.js +2 -5
  56. package/dist/utils/index.js +4 -25
  57. package/dist/utils/row-record-utils.js +20 -100
  58. package/dist/utils/sql/column-2-sql-column.js +10 -10
  59. package/dist/utils/trend-utils.js +2 -15
  60. package/dist/view/index.css +8 -2
  61. package/dist/view/index.js +9 -14
  62. package/dist/view/wrapper/area-group.js +7 -15
  63. package/dist/view/wrapper/bar-compare.js +2 -18
  64. package/dist/view/wrapper/bar-custom-stack.js +9 -35
  65. package/dist/view/wrapper/bar-group.js +26 -55
  66. package/dist/view/wrapper/bar-stack.js +2 -2
  67. package/dist/view/wrapper/basic-number-card.js +3 -27
  68. package/dist/view/wrapper/chart-component.js +440 -43
  69. package/dist/view/wrapper/completeness-group.js +49 -104
  70. package/dist/view/wrapper/dashboard.js +18 -68
  71. package/dist/view/wrapper/horizontal-bar-group.js +6 -26
  72. package/dist/view/wrapper/horizontal-bar-stack.js +2 -2
  73. package/dist/view/wrapper/line-group.js +3 -8
  74. package/dist/view/wrapper/map-world-bubble.js +0 -1
  75. package/dist/view/wrapper/map-world.js +0 -1
  76. package/dist/view/wrapper/pie.js +1 -1
  77. package/dist/view/wrapper/ring.js +1 -1
  78. package/dist/view/wrapper/scatter.js +6 -8
  79. package/dist/view/wrapper/table/two-dimension-table.js +2 -3
  80. package/dist/view/wrapper/table-element/components/records-header/index.js +1 -0
  81. package/dist/view/wrapper/table-element/components/resize-column-handle/resize-column-handle.js +1 -3
  82. package/dist/view/wrapper/table-element/index.js +21 -16
  83. package/dist/view/wrapper/trend.js +1 -24
  84. package/package.json +14 -17
@@ -37,7 +37,7 @@ class ChartComponent extends _react.Component {
37
37
  }
38
38
  }, 300);
39
39
  this.destroyChart = () => {
40
- this.chart && this.chart.node() && this.chart.node().remove();
40
+ this.chart.node() && this.chart.node().remove();
41
41
  };
42
42
  this.getTitle = (tables, table_id, yAxisType, yAxisKey) => {
43
43
  return yAxisType === _constants.CHART_SUMMARY_TYPE.COUNT ? _intl.default.get('Amount') : this.getAxisLabel(tables, table_id, yAxisKey);
@@ -213,6 +213,22 @@ class ChartComponent extends _react.Component {
213
213
  });
214
214
  });
215
215
  };
216
+ this.drawLabels = function () {
217
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
218
+ if (!_this.chart) return;
219
+ const {
220
+ width
221
+ } = _this.chart.coordinateBBox;
222
+ _this.labelCount = data.length;
223
+ if (Math.floor(width / _this.labelCount) <= 20) {
224
+ let displayLabels = _this.getChartDisplayLabels(width, 20, data);
225
+ _this.labelCount = displayLabels.length;
226
+ _this.chart.scale('name', {
227
+ type: 'cat',
228
+ ticks: displayLabels
229
+ });
230
+ }
231
+ };
216
232
  this.renderAxisLabel = (chart, tables, chartContainer) => {
217
233
  if (!this.chart || !chart) return;
218
234
  let {
@@ -277,8 +293,7 @@ class ChartComponent extends _react.Component {
277
293
  const div = document.createElement('div');
278
294
  div.id = yAxisID;
279
295
  div.className = 'chart-axis-label';
280
- // SCATTER always has y_axis_column_key
281
- if (y_axis_summary_type === _constants.CHART_SUMMARY_TYPE.COUNT && type !== _constants.CHART_TYPE.SCATTER) {
296
+ if (y_axis_summary_type === _constants.CHART_SUMMARY_TYPE.COUNT) {
282
297
  div.innerHTML = _intl.default.get('Amount');
283
298
  } else {
284
299
  const column = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_column_key) || {};
@@ -446,6 +461,186 @@ class ChartComponent extends _react.Component {
446
461
  this.isShowHorizontalAxisLabel = chart => {
447
462
  return !!(chart && chart.config && chart.config.show_horizontal_axis_label);
448
463
  };
464
+ // Automatic adjustment of maximum and minimum values
465
+ this.autoAdjustDataOptions = function (chart) {
466
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
467
+ let summaryColumn = arguments.length > 2 ? arguments[2] : undefined;
468
+ if (!_this.chart || !chart) return;
469
+ let valueScaleOptions = {};
470
+ const {
471
+ config
472
+ } = chart;
473
+ const {
474
+ y_axis_auto_range,
475
+ y_axis_min,
476
+ y_axis_max,
477
+ y_axis_summary_method
478
+ } = config;
479
+ if (summaryColumn) {
480
+ valueScaleOptions['formatter'] = value => {
481
+ return _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method);
482
+ };
483
+ }
484
+ if (y_axis_auto_range === undefined || y_axis_auto_range) {
485
+ valueScaleOptions['nice'] = true;
486
+ } else {
487
+ valueScaleOptions['min'] = y_axis_min;
488
+ valueScaleOptions['max'] = y_axis_max;
489
+ // set the filter rule
490
+ _this.chart.filter('value', value => {
491
+ return value >= y_axis_min;
492
+ });
493
+ // filter the data
494
+ _this.chart.filterData(data);
495
+ }
496
+ _this.chart.scale({
497
+ name: {
498
+ type: 'cat'
499
+ },
500
+ value: valueScaleOptions
501
+ });
502
+ };
503
+ // set axis label and tooltip
504
+ this.setNameLabelAndTooltip = function () {
505
+ let theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.CHART_THEME_COLOR['light'];
506
+ let labelCount = arguments.length > 1 ? arguments[1] : undefined;
507
+ if (!_this.chart) return;
508
+ _this.chart.axis('name', {
509
+ line: {
510
+ style: {
511
+ stroke: theme.XAxisColor,
512
+ lineWidth: 1
513
+ }
514
+ },
515
+ tickLine: {
516
+ length: 5,
517
+ // color of the tick line
518
+ stroke: theme.XAxisColor
519
+ },
520
+ label: {
521
+ style: {
522
+ fill: theme.textColor,
523
+ fontSize: theme.fontSize
524
+ },
525
+ offset: 10,
526
+ autoRotate: true,
527
+ rotate: labelCount > 11 ? 0.3 : 0,
528
+ formatter: name => {
529
+ const isString = typeof name === 'string';
530
+ if (!isString) name = String(name);
531
+ if (name === 'undefined') {
532
+ return _intl.default.get(_constants.EMPTY_NAME);
533
+ }
534
+ if (name.length > 10) {
535
+ return (0, _utils.formatXAxisLabel)(name);
536
+ }
537
+ return name;
538
+ }
539
+ }
540
+ });
541
+ };
542
+ // set value label
543
+ this.setValueLabel = function () {
544
+ let theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.CHART_THEME_COLOR['light'];
545
+ if (!_this.chart) return;
546
+ _this.chart.axis('value', {
547
+ label: {
548
+ offset: 6,
549
+ style: {
550
+ fontSize: theme.fontSize,
551
+ fill: theme.textColor
552
+ }
553
+ },
554
+ grid: {
555
+ line: {
556
+ style: {
557
+ stroke: theme.gridColor,
558
+ lineDash: [8, 3]
559
+ }
560
+ }
561
+ }
562
+ });
563
+ };
564
+ this.labelFormatter = name => {
565
+ let label = name;
566
+ if (name.length > 10) {
567
+ label = "".concat(name.slice(0, 10), "...");
568
+ }
569
+ if (name === '' || name === 'undefined') {
570
+ label = _intl.default.get(_constants.EMPTY_NAME);
571
+ }
572
+ return label;
573
+ };
574
+ this.getLegendConfig = function () {
575
+ let theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.CHART_THEME_COLOR['light'];
576
+ let legendPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top-right';
577
+ return {
578
+ // custom: true,
579
+ position: legendPosition,
580
+ itemName: {
581
+ style: {
582
+ // fill: theme.textColor,
583
+ fill: theme.legendTextColor,
584
+ fontSize: theme.legendFontSize
585
+ },
586
+ formatter: name => {
587
+ if (!name && typeof name !== 'number' || name.trim() === 'undefined' || name.trim() === 'null') {
588
+ return _intl.default.get(_constants.EMPTY_NAME);
589
+ } else if (name === '_Others') {
590
+ return _intl.default.get('Others');
591
+ } else {
592
+ return _intl.default.get(name) || name;
593
+ }
594
+ }
595
+ },
596
+ pageNavigator: {
597
+ text: {
598
+ style: {
599
+ fill: theme.legendTextColor
600
+ }
601
+ },
602
+ marker: {
603
+ style: {
604
+ fill: theme.legendPageNavigatorMarkerColor,
605
+ inactiveFill: theme.legendPageNavigatorMarkerColor,
606
+ inactiveOpacity: 0.45
607
+ }
608
+ }
609
+ },
610
+ itemHeight: 30,
611
+ marker: {
612
+ symbol:
613
+ // 'square',
614
+ // use cavans to custom legend,returns a path command array
615
+ (x, y) => {
616
+ x = x + 6;
617
+ y = y - 1;
618
+ // The total width of the capsule is 20px, and its height is 6px. Thus, the radius of the semi-circle is half the height, which is 3px.
619
+ const r = 3;
620
+ // The width of the rectangular part in the middle of the capsule is the total width minus the diameters of the two semi-circles, which is 14px.
621
+ const rectWidth = 14;
622
+ return [['M', x - rectWidth / 2, y - r],
623
+ // Start from the left edge of the left semi-circle
624
+ ['L', x + rectWidth / 2, y - r],
625
+ // Draw the top line to the left edge of the right semi-circle
626
+ ['A', r, r, 0, 0, 1, x + rectWidth / 2, y + r],
627
+ // Draw the right semi-circle
628
+ ['L', x - rectWidth / 2, y + r],
629
+ // Draw the bottom line back to the right edge of the left semi-circle
630
+ ['A', r, r, 0, 0, 1, x - rectWidth / 2, y - r] // Draw the left semi-circle
631
+ ];
632
+ },
633
+ style: style => {
634
+ // fill legend with stroke color
635
+ if (style.stroke) {
636
+ style.fill = style.stroke;
637
+ }
638
+ return style;
639
+ },
640
+ spacing: 15
641
+ }
642
+ };
643
+ };
449
644
  this.formatterLegendName = name => {
450
645
  if (!name && typeof name !== 'number' || name.trim() === 'undefined' || name.trim() === 'null') {
451
646
  return _intl.default.get(_constants.EMPTY_NAME);
@@ -455,7 +650,85 @@ class ChartComponent extends _react.Component {
455
650
  return _intl.default.get(name) || name;
456
651
  }
457
652
  };
458
- this.setLegend = _ref => {
653
+ // set legend for heat map
654
+ this.setLegendForHeatMap = _ref => {
655
+ let {
656
+ exampleColors,
657
+ themeColors
658
+ } = _ref;
659
+ const legendOffsetY = 3;
660
+ const legendItemTextWidth = 32;
661
+ const legendItemWidth = 12;
662
+ const legendItemHeight = 12;
663
+ const legendItemGap = 3;
664
+ const legendItemRadius = 2;
665
+ const legendWrapper = this.chart.append('g').attr('class', 'legend-heat-map-wrapper').attr('transform', "translate(0, ".concat(legendOffsetY, ")"));
666
+
667
+ // less
668
+ legendWrapper.append('text').attr('y', 10).attr('fill', themeColors.textColor).attr('font-size', 12).attr('font-weight', 'bold').text(_intl.default.get('Less'));
669
+ // rect
670
+ exampleColors.forEach((color, index) => {
671
+ legendWrapper.append('rect').attr('x', legendItemTextWidth + index * legendItemWidth + index * legendItemGap).attr('width', legendItemWidth).attr('height', legendItemHeight).attr('rx', legendItemRadius).attr('fill', color).attr('stroke', _style.FILL_BORDER_COLOR_MAP[color]).attr('stroke-width', 1);
672
+ });
673
+ // more
674
+ legendWrapper.append('text').attr('x', 182).attr('y', 10).attr('fill', themeColors.textColor).attr('font-size', 12).attr('font-weight', 'bold').text(_intl.default.get('More'));
675
+ };
676
+ // set continuous legend
677
+ this.setContinuousLegend = _ref2 => {
678
+ var _this$chart$node2;
679
+ let {
680
+ previewType,
681
+ theme,
682
+ colorRange = [],
683
+ legendDirection,
684
+ legendSize,
685
+ legendTextRange,
686
+ bubbleColor,
687
+ type
688
+ } = _ref2;
689
+ const {
690
+ width: chartWidth,
691
+ height: chartHeight,
692
+ insertPadding
693
+ } = this.chartBoundingClientRect;
694
+ const legendRectWidth = legendDirection === 'vertical' ? 12 : Math.min(legendSize * 100, chartWidth - insertPadding * 2);
695
+ const legendRectHeight = legendDirection === 'vertical' ? Math.min(legendSize * 100, chartHeight - insertPadding * 2) : 12;
696
+ const legendTextOffset = 2;
697
+ const legendTextHeightSpace = legendDirection === 'vertical' ? 0 : 14 + legendTextOffset;
698
+ if (![_constants.CHART_TYPE.MAP_BUBBLE, _constants.CHART_TYPE.WORLD_MAP_BUBBLE].includes(type)) {
699
+ var _this$chart$node;
700
+ // add linearGradient
701
+ const gradient = this.chart.append('defs').attr('class', 'linear-gradient-wrapper').append('linearGradient').attr("id", "gradient-".concat((_this$chart$node = this.chart.node()) === null || _this$chart$node === void 0 ? void 0 : _this$chart$node.id, "-").concat(previewType)).attr("x1", '0%').attr("y1", '0%').attr("x2", legendDirection === 'vertical' ? '0%' : '100%').attr("y2", legendDirection === 'vertical' ? '100%' : '0%');
702
+ gradient.append('stop').attr('offset', '0%').attr('stop-color', "".concat(colorRange[0]));
703
+ gradient.append('stop').attr('offset', '50%').attr('stop-color', "".concat(colorRange[4]));
704
+ gradient.append('stop').attr('offset', '100%').attr('stop-color', "".concat(colorRange[8]));
705
+ }
706
+
707
+ // add legend
708
+ const continuousLegendWrapper = this.chart.append('g').attr('class', 'legend-continuous-wrapper').attr('transform', "translate(0, ".concat(chartHeight - legendRectHeight - legendTextHeightSpace, ")"));
709
+ continuousLegendWrapper.append('rect').attr('width', legendRectWidth).attr('height', legendRectHeight).attr('fill', [_constants.CHART_TYPE.MAP_BUBBLE, _constants.CHART_TYPE.WORLD_MAP_BUBBLE].includes(type) ? bubbleColor : "url(#gradient-".concat((_this$chart$node2 = this.chart.node()) === null || _this$chart$node2 === void 0 ? void 0 : _this$chart$node2.id, "-").concat(previewType, ")")).call(g => {
710
+ if ([_constants.CHART_TYPE.MAP_BUBBLE, _constants.CHART_TYPE.WORLD_MAP_BUBBLE].includes(type)) {
711
+ continuousLegendWrapper.append('polygon').attr('points', "0,0 ".concat(legendRectWidth - 0.5, ",0 0,").concat(legendRectHeight - 0.5)).attr('fill', '#fff').attr('stroke', '#fff');
712
+ }
713
+ });
714
+ continuousLegendWrapper.append('text').attr('class', 'range-start').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).text(legendTextRange[0]).call(g => {
715
+ const {
716
+ height
717
+ } = g.node().getBoundingClientRect();
718
+ g.attr('x', legendDirection === 'vertical' ? legendRectWidth + legendTextOffset : legendTextOffset);
719
+ g.attr('y', legendDirection === 'vertical' ? height : height + legendRectHeight);
720
+ });
721
+ continuousLegendWrapper.append('text').attr('class', 'range-end').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).text(legendTextRange[1]).call(g => {
722
+ const {
723
+ width,
724
+ height
725
+ } = g.node().getBoundingClientRect();
726
+ g.attr('x', legendDirection === 'vertical' ? legendRectWidth + legendTextOffset : legendRectWidth - width);
727
+ g.attr('y', legendDirection === 'vertical' ? legendRectHeight - legendTextOffset : height + legendRectHeight);
728
+ });
729
+ };
730
+ // set legend
731
+ this.setLegend = _ref3 => {
459
732
  var _chart$config, _chart$config2;
460
733
  let {
461
734
  legendName,
@@ -465,7 +738,7 @@ class ChartComponent extends _react.Component {
465
738
  colorScale,
466
739
  groupColumn,
467
740
  chart
468
- } = _ref;
741
+ } = _ref3;
469
742
  if (!this.chart) return;
470
743
  this.legendConfig = {
471
744
  legendRectWidth: [_constants.CHART_TYPE.SCATTER, _constants.CHART_TYPE.MIRROR].includes(chart === null || chart === void 0 ? void 0 : (_chart$config = chart.config) === null || _chart$config === void 0 ? void 0 : _chart$config.type) ? 8 : 20,
@@ -499,7 +772,6 @@ class ChartComponent extends _react.Component {
499
772
  // legend offset bottom and When there is only one line of legend, it is displayed in the center (for scatter chart)
500
773
  if (bottomLegendSpace) {
501
774
  queueMicrotask(() => {
502
- if (!legendWrapper.node()) return;
503
775
  const {
504
776
  width,
505
777
  height
@@ -582,18 +854,18 @@ class ChartComponent extends _react.Component {
582
854
  } = g.node().parentNode.getBoundingClientRect();
583
855
  groupTranslateY = groupTranslateY + height + legendItemMargin;
584
856
  }
585
- g.attr('transform', "translate(".concat(groupTranslateX, ",").concat(groupTranslateY, ")"));
857
+ g.attr('transform', "translate(".concat(groupTranslateX, ", ").concat(groupTranslateY, ")"));
586
858
  });
587
859
  }
588
860
  };
589
- this.renderLegend = _ref2 => {
861
+ this.renderLegend = _ref4 => {
590
862
  let {
591
863
  legendWrapper,
592
864
  groupData,
593
865
  colorScale,
594
866
  theme,
595
867
  text
596
- } = _ref2;
868
+ } = _ref4;
597
869
  const {
598
870
  legendItemPaddingTop,
599
871
  legendItemTextPaddingTop,
@@ -619,15 +891,15 @@ class ChartComponent extends _react.Component {
619
891
  d3.select(item).remove();
620
892
  });
621
893
  }
622
- legendWrapper.selectAll().data(groupData).join('g').attr('data-groupName', _ref3 => {
623
- let [groupName] = _ref3;
894
+ legendWrapper.selectAll().data(groupData).join('g').attr('data-groupName', _ref5 => {
895
+ let [groupName] = _ref5;
624
896
  return groupName;
625
- }).append('rect').attr('width', legendRectWidth).attr('height', legendRectHeight).attr('y', legendItemPaddingTop).attr('rx', r).attr('fill', _ref4 => {
626
- let [groupName] = _ref4;
897
+ }).append('rect').attr('width', legendRectWidth).attr('height', legendRectHeight).attr('y', legendItemPaddingTop).attr('rx', r).attr('fill', _ref6 => {
898
+ let [groupName] = _ref6;
627
899
  if (colorScale) return colorScale(groupName);
628
900
  return this.colorMap[groupName] || _constants.CHART_STYLE_COLORS[0];
629
- }).attr('data-text', _ref5 => {
630
- let [groupName] = _ref5;
901
+ }).attr('data-text', _ref7 => {
902
+ let [groupName] = _ref7;
631
903
  return groupName;
632
904
  }).call(g => {
633
905
  // Add text
@@ -845,6 +1117,19 @@ class ChartComponent extends _react.Component {
845
1117
  if (type === _constants.CHART_TYPE.MIRROR) return 0;
846
1118
  return 3;
847
1119
  };
1120
+ // theta is pie or ring chart
1121
+ this.setLegendForTheta = function (legendName) {
1122
+ let theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.CHART_THEME_COLOR['light'];
1123
+ let legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom';
1124
+ let offsetX = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1125
+ if (!_this.chart) return;
1126
+ const basicLegendConfig = _this.getLegendConfig(theme, legendPosition);
1127
+ if (offsetX) {
1128
+ basicLegendConfig.offsetX = offsetX;
1129
+ }
1130
+ basicLegendConfig.itemName.style.fontSize = theme.fontSize;
1131
+ _this.chart.legend(legendName, basicLegendConfig);
1132
+ };
848
1133
  this.calcEquilateralTriangle = (cx, cy, size, direction) => {
849
1134
  const height = size * Math.sqrt(3) / 2;
850
1135
  if (direction === 'bottom') {
@@ -971,6 +1256,131 @@ class ChartComponent extends _react.Component {
971
1256
  }
972
1257
  return statisticNewData;
973
1258
  };
1259
+ this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
1260
+ const obj = {
1261
+ showMarkers: false,
1262
+ containerTpl: "<div class=\"g2-tooltip\">\n <div class=\"g2-tooltip-title\">{title}</div>\n <ul class=\"g2-tooltip-list\"></ul>\n </div>",
1263
+ itemTpl: "<li class=\"g2-tooltip-list-item\">\n <span class=\"g2-tooltip-marker\" style=\"background-color:{color};display:inline-block;\"></span>\n <span class=\"g2-tooltip-name\">{name}</span>\n <span class=\"g2-tooltip-value\">{value}</span>\n </li>",
1264
+ domStyles: {
1265
+ 'g2-tooltip': {
1266
+ boxSizing: 'border-box',
1267
+ minWidth: '178px',
1268
+ borderRadius: '3px',
1269
+ border: '1px solid #e2e2e2',
1270
+ backgroundColor: '#fff',
1271
+ padding: '16px',
1272
+ paddingTop: '8px',
1273
+ paddingBottom: '8px',
1274
+ marginLeft: '20px',
1275
+ boxShadow: '0px 0px 1px 1px rgba(0,0,0,0.1)'
1276
+ },
1277
+ 'g2-tooltip-title': {
1278
+ color: '#333333',
1279
+ fontSize: '14px',
1280
+ paddingBottom: '10px',
1281
+ maxWidth: '160px',
1282
+ whiteSpace: 'nowrap',
1283
+ overflow: 'hidden',
1284
+ lineHeight: '14px',
1285
+ textOverflow: 'ellipsis'
1286
+ },
1287
+ 'g2-tooltip-list-item': {
1288
+ marginTop: '8px',
1289
+ marginBottom: '8px',
1290
+ display: 'flex'
1291
+ },
1292
+ 'g2-tooltip-marker': {
1293
+ width: '12px',
1294
+ height: '12px',
1295
+ borderRadius: '2px',
1296
+ marginRight: '8px'
1297
+ },
1298
+ 'g2-tooltip-name': {
1299
+ display: 'inline-block',
1300
+ fontSize: '12px',
1301
+ minWidth: '80px',
1302
+ whiteSpace: 'nowrap',
1303
+ overflow: 'hidden',
1304
+ lineHeight: '12px',
1305
+ textOverflow: 'ellipsis'
1306
+ },
1307
+ 'g2-tooltip-value': {
1308
+ fontSize: '12px'
1309
+ }
1310
+ }
1311
+ };
1312
+ if (isGroup) {
1313
+ obj.customItems = items => {
1314
+ const activeItem = items[0];
1315
+ const name = activeItem.data.name;
1316
+ return this.formatedDataByName[name].map(item => {
1317
+ return {
1318
+ color: useSingleSelectColumnColor ? item.group_color : this.colorMap[item.group_name] || _constants.CHART_STYLE_COLORS[0],
1319
+ data: item,
1320
+ name: !item.group_name && typeof item.group_name !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : item.group_name,
1321
+ title: item.name,
1322
+ value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, item.value, y_axis_summary_method)
1323
+ };
1324
+ });
1325
+ };
1326
+ }
1327
+ return obj;
1328
+ };
1329
+ this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
1330
+ const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
1331
+ this.chart.tooltip(settings);
1332
+ };
1333
+ this.setToolTipForLine = () => {
1334
+ const settings = this.getToolTipSettings();
1335
+ const lineToolTipSettings = {
1336
+ showCrosshairs: true,
1337
+ showTitle: true,
1338
+ shared: true,
1339
+ showMarkers: true,
1340
+ marker: {
1341
+ strokeOpacity: 0,
1342
+ r: 5
1343
+ },
1344
+ crosshairs: {
1345
+ line: {
1346
+ fill: '#F3F3F3'
1347
+ }
1348
+ }
1349
+ };
1350
+ this.chart.tooltip({
1351
+ ...settings,
1352
+ ...lineToolTipSettings
1353
+ });
1354
+ };
1355
+ this.setToolTipForArea = () => {
1356
+ const settings = this.getToolTipSettings();
1357
+ const lineToolTipSettings = {
1358
+ showCrosshairs: true,
1359
+ showTitle: true,
1360
+ shared: true,
1361
+ showMarkers: true,
1362
+ marker: {
1363
+ strokeOpacity: 0,
1364
+ r: 6
1365
+ },
1366
+ crosshairs: {
1367
+ line: {
1368
+ fill: '#F3F3F3'
1369
+ }
1370
+ }
1371
+ };
1372
+ this.chart.tooltip({
1373
+ ...settings,
1374
+ ...lineToolTipSettings
1375
+ });
1376
+ };
1377
+ // theta is pie or ring chart
1378
+ this.setToolTipForTheta = () => {
1379
+ const settings = this.getToolTipSettings();
1380
+ settings.showTitle = false;
1381
+ settings.containerTpl = "<div class=\"g2-tooltip\">\n <ul class=\"g2-tooltip-list\"></ul>\n </div>";
1382
+ this.chart.tooltip(settings);
1383
+ };
974
1384
  this.isShowXAxisLabel = chart => {
975
1385
  return !!(chart && chart.config && chart.config.x_axis_show_label);
976
1386
  };
@@ -1001,7 +1411,7 @@ class ChartComponent extends _react.Component {
1001
1411
  annotationWrapper.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', yScale(goal_value) - 10).attr('fill', '#666').text(goal_label);
1002
1412
  });
1003
1413
  };
1004
- this.addLabelToRectTop = _ref6 => {
1414
+ this.addLabelToRectTop = _ref8 => {
1005
1415
  let {
1006
1416
  container,
1007
1417
  x,
@@ -1010,16 +1420,15 @@ class ChartComponent extends _react.Component {
1010
1420
  theme,
1011
1421
  label_font_size,
1012
1422
  text
1013
- } = _ref6;
1423
+ } = _ref8;
1014
1424
  d3.select(container).append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('y', Number(y) - 10).attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(text).call(g => {
1015
- if (!g.node()) return;
1016
1425
  const {
1017
1426
  width
1018
1427
  } = g.node().getBoundingClientRect();
1019
1428
  g.attr('x', Number(x) + Number(xWidth) / 2 - width / 2);
1020
1429
  });
1021
1430
  };
1022
- this.addLabelToRectRight = _ref7 => {
1431
+ this.addLabelToRectRight = _ref9 => {
1023
1432
  let {
1024
1433
  container,
1025
1434
  x,
@@ -1029,7 +1438,7 @@ class ChartComponent extends _react.Component {
1029
1438
  theme,
1030
1439
  label_font_size,
1031
1440
  text
1032
- } = _ref7;
1441
+ } = _ref9;
1033
1442
  d3.select(container).append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('x', Number(x) + Number(xWidth) + 10).attr('y', Number(y)).attr('fill', theme.labelColor).attr('dominant-baseline', 'hanging').attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(text).call(g => {
1034
1443
  if (g.node()) {
1035
1444
  var _g$node;
@@ -1040,7 +1449,7 @@ class ChartComponent extends _react.Component {
1040
1449
  }
1041
1450
  });
1042
1451
  };
1043
- this.addLabelToRectCenter = _ref8 => {
1452
+ this.addLabelToRectCenter = _ref10 => {
1044
1453
  let {
1045
1454
  chartType,
1046
1455
  container,
@@ -1051,9 +1460,8 @@ class ChartComponent extends _react.Component {
1051
1460
  theme,
1052
1461
  label_font_size,
1053
1462
  text
1054
- } = _ref8;
1463
+ } = _ref10;
1055
1464
  d3.select(container).append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(text).call(g => {
1056
- if (!g.node()) return;
1057
1465
  const {
1058
1466
  width,
1059
1467
  height
@@ -1094,32 +1502,25 @@ class ChartComponent extends _react.Component {
1094
1502
  }
1095
1503
  };
1096
1504
  // Use clipPath to make rectangle rounded corners
1097
- this.addClipPath = _ref9 => {
1505
+ this.addClipPath = _ref11 => {
1098
1506
  let {
1099
1507
  rect,
1100
1508
  parentNode,
1101
1509
  attr,
1102
- rectId,
1103
- borderRadiusVal
1104
- } = _ref9;
1510
+ rectId
1511
+ } = _ref11;
1105
1512
  const {
1106
1513
  borderRadius
1107
1514
  } = this.chartBoundingClientRect;
1108
1515
  const clipRect = d3.select(rect.cloneNode());
1109
1516
  if (attr === 'x') {
1110
- const rectHeight = Number(rect.getAttribute('height'));
1111
- const rectWidth = Number(rect.getAttribute('width'));
1112
- const computedBorderRadius = Math.min(rectHeight * borderRadius, rectWidth / 2);
1113
- const safeBorderRadius = Math.min(borderRadiusVal !== null && borderRadiusVal !== void 0 ? borderRadiusVal : computedBorderRadius, rectWidth / 2, rectHeight / 2);
1114
- clipRect.attr('rx', safeBorderRadius);
1115
- clipRect.attr('x', Number(rect.getAttribute('x')) - safeBorderRadius).attr('width', rectWidth + safeBorderRadius);
1517
+ const borderRadiusVal = Number(rect.getAttribute('height')) * borderRadius;
1518
+ clipRect.attr('rx', borderRadiusVal);
1519
+ clipRect.attr('x', Number(rect.getAttribute('x')) - borderRadiusVal).attr('width', Number(rect.getAttribute('width')) + borderRadiusVal);
1116
1520
  } else {
1117
- const rectWidth = Number(rect.getAttribute('width'));
1118
- const rectHeight = Number(rect.getAttribute('height'));
1119
- const computedBorderRadius = Math.min(rectWidth * borderRadius, rectHeight / 2);
1120
- const safeBorderRadius = Math.min(borderRadiusVal !== null && borderRadiusVal !== void 0 ? borderRadiusVal : computedBorderRadius, rectWidth / 2, rectHeight / 2);
1121
- clipRect.attr('rx', safeBorderRadius);
1122
- clipRect.attr('height', rectHeight + safeBorderRadius);
1521
+ const borderRadiusVal = Number(rect.getAttribute('width')) * borderRadius;
1522
+ clipRect.attr('rx', borderRadiusVal);
1523
+ clipRect.attr('height', Number(rect.getAttribute('height')) + borderRadiusVal);
1123
1524
  }
1124
1525
  const clipPath = d3.select(parentNode).append('clipPath').attr('opacity', 1).attr('id', rectId);
1125
1526
  clipPath.node().appendChild(clipRect.node());
@@ -1173,7 +1574,6 @@ class ChartComponent extends _react.Component {
1173
1574
  // Hide overlapping ticks
1174
1575
  for (let i = 0; i < allTicks.length; i++) {
1175
1576
  const curText = d3.select(allTicks[i]).select('text').node();
1176
- if (!curText) continue;
1177
1577
  const {
1178
1578
  right: curRight,
1179
1579
  bottom: curBottom
@@ -1238,7 +1638,6 @@ class ChartComponent extends _react.Component {
1238
1638
  viewBox[0] = "-".concat(width - insertPadding);
1239
1639
  viewBox[viewBox.length - 2] = "".concat(Number(viewWidth) + (width - insertPadding));
1240
1640
  queueMicrotask(() => {
1241
- if (!this.chart) return;
1242
1641
  this.chart.attr('viewBox', viewBox.join(','));
1243
1642
  });
1244
1643
  }
@@ -1271,7 +1670,6 @@ class ChartComponent extends _react.Component {
1271
1670
  const viewHeight = viewBox[viewBox.length - 1];
1272
1671
  viewBox[viewBox.length - 1] = "".concat(Number(viewHeight) + (height - insertPadding));
1273
1672
  queueMicrotask(() => {
1274
- if (!this.chart) return;
1275
1673
  this.chart.attr('viewBox', viewBox.join(','));
1276
1674
  });
1277
1675
  }
@@ -1283,7 +1681,6 @@ class ChartComponent extends _react.Component {
1283
1681
  ticks.forEach(tick => {
1284
1682
  var _d3$select$select;
1285
1683
  const text = (_d3$select$select = d3.select(tick).select('text')) === null || _d3$select$select === void 0 ? void 0 : _d3$select$select.node();
1286
- if (!text) return;
1287
1684
  d3.select(tick).select('line').attr('data-name', text.innerHTML);
1288
1685
  });
1289
1686
  }