sea-chart 2.0.42 → 2.0.44

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 (60) hide show
  1. package/dist/components/color-popover/color-rules/rule-filters/number-input.js +2 -2
  2. package/dist/components/drill-down-settings/drill-down-fields-popover/index.js +2 -2
  3. package/dist/components/tooltip/index.js +11 -4
  4. package/dist/constants/index.js +8 -3
  5. package/dist/context.js +10 -7
  6. package/dist/model/base-model.js +4 -0
  7. package/dist/model/combination.js +4 -0
  8. package/dist/model/horizontal-bar.js +4 -0
  9. package/dist/model/horizontal-group-bar.js +5 -1
  10. package/dist/model/stacked-horizontal-bar.js +4 -0
  11. package/dist/settings/advance-bar-settings/style-settings.js +24 -7
  12. package/dist/settings/bar-settings/style-settings.js +24 -7
  13. package/dist/settings/combination-settings/style-settings.js +35 -10
  14. package/dist/settings/time-comparison-settings/style-settings.js +24 -7
  15. package/dist/settings/widgets/axis-title-font-settings/index.js +39 -0
  16. package/dist/utils/cell-format-utils.js +2 -2
  17. package/dist/utils/chart-utils/base-utils.js +49 -13
  18. package/dist/utils/chart-utils/original-data-utils/basic-chart-calculator.js +4 -3
  19. package/dist/utils/chart-utils/original-data-utils/mirror-calculator.js +3 -3
  20. package/dist/utils/chart-utils/original-data-utils/pivot-table-calculator.js +2 -2
  21. package/dist/utils/chart-utils/sql-statistics-utils.js +64 -18
  22. package/dist/utils/row-record-utils.js +21 -5
  23. package/dist/utils/sql/column-2-sql-column.js +2 -0
  24. package/dist/view/index.css +0 -17
  25. package/dist/view/wrapper/area-group.js +14 -25
  26. package/dist/view/wrapper/area.js +14 -27
  27. package/dist/view/wrapper/bar-compare.js +10 -15
  28. package/dist/view/wrapper/bar-custom-stack.js +19 -81
  29. package/dist/view/wrapper/bar-group.js +15 -50
  30. package/dist/view/wrapper/bar-stack.js +12 -40
  31. package/dist/view/wrapper/bar.js +10 -23
  32. package/dist/view/wrapper/basic-number-card.js +9 -2
  33. package/dist/view/wrapper/chart-component.js +461 -76
  34. package/dist/view/wrapper/combination.js +17 -29
  35. package/dist/view/wrapper/completeness-group.js +13 -59
  36. package/dist/view/wrapper/completeness.js +14 -60
  37. package/dist/view/wrapper/dashboard.js +8 -14
  38. package/dist/view/wrapper/funnel.js +6 -18
  39. package/dist/view/wrapper/heat-map.js +80 -50
  40. package/dist/view/wrapper/horizontal-bar-group.js +14 -25
  41. package/dist/view/wrapper/horizontal-bar-stack.js +16 -61
  42. package/dist/view/wrapper/horizontal-bar.js +10 -25
  43. package/dist/view/wrapper/index.js +3 -0
  44. package/dist/view/wrapper/line-group.js +11 -21
  45. package/dist/view/wrapper/line.js +11 -23
  46. package/dist/view/wrapper/map-bubble.js +9 -14
  47. package/dist/view/wrapper/map-world-bubble.js +9 -14
  48. package/dist/view/wrapper/map-world.js +9 -14
  49. package/dist/view/wrapper/map.js +9 -13
  50. package/dist/view/wrapper/mirror.js +7 -20
  51. package/dist/view/wrapper/pie.js +9 -12
  52. package/dist/view/wrapper/ring.js +10 -13
  53. package/dist/view/wrapper/scatter.js +13 -23
  54. package/dist/view/wrapper/table/pivot-table-display-name.js +2 -2
  55. package/dist/view/wrapper/table-element/components/formatter.js +2 -2
  56. package/dist/view/wrapper/table-element/components/records-body.js +8 -2
  57. package/dist/view/wrapper/table-element/components/records.js +2 -4
  58. package/dist/view/wrapper/treemap.js +8 -18
  59. package/dist/view/wrapper/trend.js +3 -2
  60. package/package.json +2 -2
@@ -1,26 +1,17 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce } from 'lodash-es';
4
3
  import * as d3 from 'd3';
5
- import classNames from 'classnames';
6
4
  import dayjs from 'dayjs';
7
5
  import { getTableById, getTableColumnByKey, getNumberDisplayString } from 'dtable-utils';
8
- import dayOfYear from 'dayjs/plugin/dayOfYear';
9
6
  import { FILL_BORDER_COLOR_MAP, COLOR_OPTIONS } from '../../constants/style';
10
7
  import { DEFAULT_GRID_SIZE, DEFAULT_GRID_DISTANCE, DEFAULT_NUMBER_FORMAT_OBJECT, CHART_SUMMARY_TYPE, TITLE_AMOUNT } from '../../constants';
11
8
  import { BaseUtils } from '../../utils';
12
9
  import intl from '../../intl';
13
10
  import ToolTip from '../../components/tooltip';
14
11
  import ChartComponent from './chart-component';
15
- dayjs.extend(dayOfYear);
16
12
  class HeatMap extends ChartComponent {
17
13
  constructor(props) {
18
14
  super(props);
19
- this.handleResize = () => {
20
- this.destroyChart();
21
- this.createChart();
22
- this.drawChart();
23
- };
24
15
  this.createChart = () => {
25
16
  const {
26
17
  chart,
@@ -29,7 +20,8 @@ class HeatMap extends ChartComponent {
29
20
  const initConfig = {
30
21
  insertPadding: 30,
31
22
  borderRadius: 0.06,
32
- monthAxisHeight: 30
23
+ monthAxisHeight: 30,
24
+ titleHeight: 20
33
25
  };
34
26
  const {
35
27
  width,
@@ -50,9 +42,11 @@ class HeatMap extends ChartComponent {
50
42
  this.getCustomWidthAndHeight = (result, chartConfig, initConfig) => {
51
43
  const {
52
44
  insertPadding,
53
- monthAxisHeight
45
+ monthAxisHeight,
46
+ titleHeight
54
47
  } = initConfig;
55
- const count = result.years.length;
48
+ const years = (result === null || result === void 0 ? void 0 : result.years) || [];
49
+ const count = years.length;
56
50
  let {
57
51
  grid_size,
58
52
  grid_distance
@@ -60,13 +54,49 @@ class HeatMap extends ChartComponent {
60
54
  grid_size = grid_size || DEFAULT_GRID_SIZE;
61
55
  grid_distance = grid_distance || DEFAULT_GRID_DISTANCE;
62
56
  const yearHeight = grid_size * 7 + grid_distance * 6; // height for 1 year
63
- const height = (yearHeight + monthAxisHeight) * count + (insertPadding + insertPadding); // monthAxisHeight is axis height, insertPadding is top and bottm height
64
- const width = grid_size * 53 + grid_distance * 52 + (insertPadding + insertPadding); // insertPadding is left and right width
57
+ const height = (titleHeight + yearHeight + monthAxisHeight) * count + (insertPadding + insertPadding);
58
+ const weekCount = Math.max(...years.map(year => this.getYearWeekCount(year)), 53);
59
+ const width = grid_size * weekCount + grid_distance * (weekCount - 1) + (insertPadding + insertPadding);
65
60
  return {
66
61
  width,
67
62
  height
68
63
  };
69
64
  };
65
+ this.shouldHeatMapUpdate = prevProps => {
66
+ if (BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) return true;
67
+ const prevResult = prevProps.result || {};
68
+ const currentResult = this.props.result || {};
69
+ const prevYears = prevResult.years || [];
70
+ const currentYears = currentResult.years || [];
71
+ if (prevYears.length !== currentYears.length) return true;
72
+ for (let i = 0; i < currentYears.length; i++) {
73
+ if (prevYears[i] !== currentYears[i]) return true;
74
+ }
75
+ const prevData = prevResult.data || [];
76
+ const currentData = currentResult.data || [];
77
+ if (prevData.length !== currentData.length) return true;
78
+ for (let i = 0; i < currentData.length; i++) {
79
+ const prevItem = prevData[i] || {};
80
+ const currentItem = currentData[i] || {};
81
+ if (prevItem.name !== currentItem.name || prevItem.value !== currentItem.value) return true;
82
+ }
83
+ return false;
84
+ };
85
+ this.getDayOfYear = date => {
86
+ const dateObj = dayjs(date);
87
+ const yearStart = dayjs(`${dateObj.year()}-01-01`);
88
+ return dateObj.diff(yearStart, 'day') + 1;
89
+ };
90
+ this.getWeekIndex = date => {
91
+ const dateObj = dayjs(date);
92
+ const yearStart = dayjs(`${dateObj.year()}-01-01`);
93
+ const dayOfYear = this.getDayOfYear(date);
94
+ const firstDayOfYear = yearStart.day();
95
+ return Math.floor((dayOfYear - 1 + firstDayOfYear) / 7) + 1;
96
+ };
97
+ this.getYearWeekCount = year => {
98
+ return this.getWeekIndex(dayjs(`${year}-12-31`));
99
+ };
70
100
  this.showTooltip = (event, data, columnData) => {
71
101
  const {
72
102
  offsetX,
@@ -121,16 +151,20 @@ class HeatMap extends ChartComponent {
121
151
  height: chartHeight,
122
152
  insertPadding,
123
153
  borderRadius,
124
- monthAxisHeight
154
+ titleHeight
125
155
  } = this.chartBoundingClientRect;
126
- let {
156
+ const {
127
157
  data_color,
128
- grid_size,
129
158
  table_id,
130
159
  summary_type,
131
160
  summary_column
132
161
  } = chart.config;
162
+ let {
163
+ grid_size,
164
+ grid_distance
165
+ } = chart.config;
133
166
  grid_size = grid_size ? grid_size : DEFAULT_GRID_SIZE;
167
+ grid_distance = grid_distance ? grid_distance : DEFAULT_GRID_DISTANCE;
134
168
  const currentColorOption = COLOR_OPTIONS.filter(item => item.name === data_color)[0] || COLOR_OPTIONS[0];
135
169
  const {
136
170
  exampleColors
@@ -150,10 +184,13 @@ class HeatMap extends ChartComponent {
150
184
  // Fy scale
151
185
  const fyDomain = new Set(years.map(d => d));
152
186
  const fy = d3.scaleBand().domain(fyDomain).range([insertPadding, chartHeight - insertPadding]).paddingInner(0).paddingOuter(0);
153
- Array.from(fyDomain).forEach((year, index) => {
187
+ Array.from(fyDomain).forEach(year => {
188
+ const bandTop = fy(year) + titleHeight;
189
+
154
190
  // Y axis
155
- const y = d3.scaleBand().domain(this.weeks).range([fy(year), fy(year) + (fy.bandwidth() - monthAxisHeight)]).paddingInner(0).paddingOuter(0);
156
- yAxisWrapper.append('g').attr('class', `y-axis-${year}`).attr('transform', `translate(${insertPadding}, 0)`).call(d3.axisLeft(y).tickSizeInner(0).tickSizeOuter(0).tickFormat(d => intl.get(d))).call(g => {
191
+ const weekYScale = d3.scaleOrdinal().domain(this.weeks).range(this.weeks.map((_, i) => bandTop + i * (grid_size + grid_distance)));
192
+ const yAxisScale = d3.scaleOrdinal().domain(this.weeks).range(this.weeks.map((_, i) => bandTop + i * (grid_size + grid_distance) + grid_size / 2));
193
+ yAxisWrapper.append('g').attr('class', `y-axis-${year}`).attr('transform', `translate(${insertPadding}, 0)`).call(d3.axisLeft(yAxisScale).tickSizeInner(0).tickSizeOuter(0).tickFormat(d => intl.get(d))).call(g => {
157
194
  g.select('.domain').remove();
158
195
  g.selectAll('text').attr('font-size', 12);
159
196
  g.selectAll('text').attr('fill', themeColors.textColor);
@@ -165,7 +202,7 @@ class HeatMap extends ChartComponent {
165
202
  const weekDomain = Array.from({
166
203
  length: weekCount
167
204
  }, (_, i) => i + 1);
168
- const weekScale = d3.scaleBand().domain(weekDomain).range([insertPadding, chartWidth - insertPadding]).paddingInner(0).paddingOuter(0);
205
+ const weekScale = d3.scaleOrdinal().domain(weekDomain).range(weekDomain.map((_, i) => insertPadding + i * (grid_size + grid_distance)));
169
206
 
170
207
  // year
171
208
  const yearWrapper = contentWrapper.append('g').attr('class', `year-wrapper-${year}`);
@@ -175,19 +212,15 @@ class HeatMap extends ChartComponent {
175
212
  const monthWrapper = yearWrapper.append('g').attr('class', `month-${this.months[monthIndex]}`);
176
213
  // day
177
214
  days.forEach((d, index) => {
178
- monthWrapper.append('rect').attr('class', () => `day-${dayjs(d).dayOfYear()}`).attr('x', () => {
179
- let curWeek = dayjs(d).week();
180
- // The last few days are the first week of the next year
181
- if (monthIndex === 11 && curWeek === 1) {
182
- curWeek = weekCount;
183
- }
215
+ monthWrapper.append('rect').attr('class', () => `day-${this.getDayOfYear(d)}`).attr('x', () => {
216
+ const curWeek = this.getWeekIndex(d);
184
217
  if (index === 0) {
185
218
  monthTranslateX.push(weekScale(curWeek));
186
- } // Record the x position of the first day of each month
219
+ }
187
220
  return weekScale(curWeek);
188
221
  }).attr('y', () => {
189
222
  const curWeek = this.weeks[dayjs(d).day()];
190
- return y(curWeek);
223
+ return weekYScale(curWeek);
191
224
  }).attr('width', grid_size).attr('height', grid_size).attr('rx', grid_size * borderRadius).attr('fill', () => this.getRectColor(d, data, 'fill', exampleColors)).attr('stroke', () => this.getRectColor(d, data, 'stroke', exampleColors)).attr('stroke-width', 1).on('click', () => {
192
225
  const curDate = data.find(item => item.name === dayjs(d).format('YYYY-MM-DD'));
193
226
  if (curDate) {
@@ -211,19 +244,23 @@ class HeatMap extends ChartComponent {
211
244
 
212
245
  // X axis
213
246
  const x = d3.scalePoint().domain(this.months).range([insertPadding, chartWidth - insertPadding]);
214
- xAxisWrapper.append('g').attr('class', `x-axis-${year}`).attr('transform', `translate(0, ${fy(year) + fy.bandwidth() - monthAxisHeight})`).call(d3.axisBottom(x).tickSizeInner(0).tickSizeOuter(0).tickFormat(d => intl.get(d))).call(g => {
247
+ xAxisWrapper.append('g').attr('class', `x-axis-${year}`).attr('transform', `translate(0, ${bandTop + (grid_size * 7 + grid_distance * 6)})`).call(d3.axisBottom(x).tickSizeInner(0).tickSizeOuter(0).tickFormat(d => intl.get(d))).call(g => {
215
248
  g.select('.domain').remove();
216
249
  g.selectAll('.tick').nodes().forEach((item, index) => {
217
- const curTranslateX = monthTranslateX[index] + weekScale.bandwidth() / 2;
250
+ const monthX = monthTranslateX[index];
251
+ if (!Number.isFinite(monthX)) {
252
+ d3.select(item).attr('opacity', 0);
253
+ return;
254
+ }
255
+ const curTranslateX = monthX + grid_size / 2;
218
256
  d3.select(item).attr('transform', `translate(${curTranslateX}, 0)`);
219
257
  });
220
258
  g.selectAll('text').attr('font-size', 12);
221
259
  g.selectAll('text').attr('fill', themeColors.textColor);
222
260
  });
223
-
224
- // Title
225
- titleWrapper.append('text').attr('class', `text-${year}`).attr('x', 0).attr('y', fy(year) + fy.bandwidth()).attr('fill', '#000').attr('font-size', 12).attr('font-weight', 500).text(year);
261
+ titleWrapper.append('text').attr('class', `text-${year}`).attr('x', 0).attr('y', fy(year) + titleHeight - 6).attr('fill', '#000').attr('font-size', 12).attr('font-weight', 500).text(year);
226
262
  });
263
+ this.animateFadeIn(contentWrapper.selectAll('rect'));
227
264
  this.setLegendForHeatMap({
228
265
  exampleColors: ['#EBEDF0', ...exampleColors],
229
266
  themeColors
@@ -231,12 +268,12 @@ class HeatMap extends ChartComponent {
231
268
  };
232
269
  this.generateYearDates = year => {
233
270
  const dates = [];
234
- let current = dayjs(`${year}-01-01`);
235
- while (current.year() === year) {
236
- dates.push(current);
237
- current = current.add(1, 'day');
271
+ const isLeapYear = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
272
+ const dayCount = isLeapYear ? 366 : 365;
273
+ for (let i = 0; i < dayCount; i++) {
274
+ dates.push(dayjs(`${year}-01-01`).add(i, 'day'));
238
275
  }
239
- const weekCount = Math.ceil(dates.length / 7);
276
+ const weekCount = this.getYearWeekCount(year);
240
277
  return [d3.groups(dates, d => dayjs(d).month()), weekCount];
241
278
  };
242
279
  this.getRectColor = (d, data, type, exampleColors) => {
@@ -263,12 +300,11 @@ class HeatMap extends ChartComponent {
263
300
  componentDidMount() {
264
301
  this.createChart();
265
302
  this.drawChart();
266
- this.debouncedHandleResize = debounce(this.handleResize, 300);
267
- window.addEventListener('resize', this.debouncedHandleResize);
303
+ super.componentDidMount();
268
304
  }
269
305
  componentDidUpdate(prevProps) {
270
306
  super.componentDidUpdate(prevProps);
271
- if (BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
307
+ if (this.shouldHeatMapUpdate(prevProps)) {
272
308
  this.destroyChart();
273
309
  this.createChart();
274
310
  this.drawChart();
@@ -276,22 +312,16 @@ class HeatMap extends ChartComponent {
276
312
  }
277
313
  componentWillUnmount() {
278
314
  this.destroyChart();
279
- window.removeEventListener('resize', this.debouncedHandleResize);
315
+ super.componentWillUnmount();
280
316
  }
281
317
  render() {
282
- const {
283
- chart
284
- } = this.props;
285
318
  const {
286
319
  tooltipData,
287
320
  toolTipPosition
288
321
  } = this.state;
289
322
  return /*#__PURE__*/React.createElement("div", {
290
323
  ref: ref => this.container = ref,
291
- className: classNames('sea-chart-container', {
292
- 'show-x-axis-label': this.isShowXAxisLabel(chart),
293
- 'show-y-axis-label': this.isShowYAxisLabel(chart)
294
- })
324
+ className: "sea-chart-container"
295
325
  }, /*#__PURE__*/React.createElement(ToolTip, {
296
326
  tooltipData: tooltipData,
297
327
  toolTipPosition: toolTipPosition,
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce, cloneDeep } from 'lodash-es';
4
- import classNames from 'classnames';
3
+ import { cloneDeep } from 'lodash-es';
5
4
  import * as d3 from 'd3';
6
- import { CellType } from 'dtable-utils';
5
+ import { CellType, isEmpty } from 'dtable-utils';
7
6
  import dayjs from 'dayjs';
8
7
  import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR, CHART_STYLE_COLORS } from '../../constants';
9
8
  import { BaseUtils, isFunction } from '../../utils';
@@ -15,11 +14,6 @@ import ChartComponent from './chart-component';
15
14
  class HorizontalBarGroup extends ChartComponent {
16
15
  constructor(props) {
17
16
  super(props);
18
- this.handleResize = debounce(() => {
19
- this.destroyChart();
20
- this.createChart();
21
- this.drawChart();
22
- }, 300);
23
17
  this.createChart = () => {
24
18
  const {
25
19
  chart
@@ -32,8 +26,8 @@ class HorizontalBarGroup extends ChartComponent {
32
26
  const initConfig = {
33
27
  insertPadding: 30,
34
28
  borderRadius: 0.2,
35
- marginLeft: show_vertical_axis_label ? 20 : 0,
36
- marginBottom: show_horizontal_axis_label ? 20 : 0,
29
+ marginLeft: show_vertical_axis_label ? this.getAxisTitleHeight(chart.config.vertical_axis_label_font_size) : 0,
30
+ marginBottom: show_horizontal_axis_label ? this.getAxisTitleHeight(chart.config.horizontal_axis_label_font_size) : 0,
37
31
  marginRight: display_data ? 15 : 0
38
32
  };
39
33
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
@@ -93,7 +87,7 @@ class HorizontalBarGroup extends ChartComponent {
93
87
  const emptyName = intl.get(EMPTY_NAME);
94
88
  data = data.map(item => {
95
89
  const rawGroupName = item.group_name;
96
- if (rawGroupName === null || rawGroupName === undefined || rawGroupName === '') return item;
90
+ if (isEmpty(rawGroupName)) return item;
97
91
  if (rawGroupName === emptyName) return item;
98
92
  const dateValue = dayjs(rawGroupName);
99
93
  if (!dateValue.isValid()) return item;
@@ -149,14 +143,12 @@ class HorizontalBarGroup extends ChartComponent {
149
143
  var _this$colorMap$colorK;
150
144
  const colorKey = d.group_name || d.group_name === 0 ? d.group_name : '';
151
145
  return (_this$colorMap$colorK = this.colorMap[colorKey]) !== null && _this$colorMap$colorK !== void 0 ? _this$colorMap$colorK : CHART_STYLE_COLORS[0];
152
- }).attr('value', d => d.value).attr('data-slugid', d => d.slugId).attr('data-groupName', d => d.name).call(g => {
146
+ }).attr('value', d => d.value).attr('data-groupName', d => d.name).call(g => {
153
147
  // add rect borderRadius
154
148
  g.nodes().forEach(rect => {
155
149
  this.addClipPath({
156
150
  rect,
157
- parentNode: rect.parentNode,
158
- attr: 'x',
159
- rectId: rect.getAttribute('data-slugid')
151
+ attr: 'x'
160
152
  });
161
153
  });
162
154
 
@@ -185,6 +177,9 @@ class HorizontalBarGroup extends ChartComponent {
185
177
  }).on('mouseleave', event => {
186
178
  this.hiddenTooltip();
187
179
  this.handleAcitveAndInActiveState('active', event);
180
+ }).call(g => {
181
+ this.animateRectGrowInX(g);
182
+ this.animateFadeIn(contentWrapper.selectAll('text'), this.transitionDuration, this.transitionDuration * 0.5);
188
183
  });
189
184
  this.setLegend({
190
185
  legendName: 'group_name',
@@ -218,7 +213,7 @@ class HorizontalBarGroup extends ChartComponent {
218
213
  title: !title && typeof title !== 'number' ? intl.get(EMPTY_NAME) : title,
219
214
  items: children.map(child => {
220
215
  const data = child.__data__;
221
- const groupName = data.group_name === null || data.group_name === undefined || data.group_name === '' ? intl.get(EMPTY_NAME) : data.group_name;
216
+ const groupName = isEmpty(data.group_name) ? intl.get(EMPTY_NAME) : data.group_name;
222
217
  return {
223
218
  color: this.colorMap[groupName] || CHART_STYLE_COLORS[0],
224
219
  name: groupName,
@@ -262,7 +257,7 @@ class HorizontalBarGroup extends ChartComponent {
262
257
  componentDidMount() {
263
258
  this.createChart();
264
259
  this.drawChart();
265
- window.addEventListener('resize', this.handleResize);
260
+ super.componentDidMount();
266
261
  }
267
262
  componentDidUpdate(prevProps) {
268
263
  super.componentDidUpdate(prevProps);
@@ -274,22 +269,16 @@ class HorizontalBarGroup extends ChartComponent {
274
269
  }
275
270
  componentWillUnmount() {
276
271
  this.destroyChart();
277
- window.removeEventListener('resize', this.handleResize);
272
+ super.componentWillUnmount();
278
273
  }
279
274
  render() {
280
- const {
281
- chart
282
- } = this.props;
283
275
  const {
284
276
  tooltipData,
285
277
  toolTipPosition
286
278
  } = this.state;
287
279
  return /*#__PURE__*/React.createElement("div", {
288
280
  ref: ref => this.container = ref,
289
- className: classNames('sea-chart-container', {
290
- 'show-x-axis-label': this.isShowHorizontalAxisLabel(chart),
291
- 'show-y-axis-label': this.isShowVerticalAxisLabel(chart)
292
- })
281
+ className: "sea-chart-container"
293
282
  }, /*#__PURE__*/React.createElement(ToolTip, {
294
283
  tooltipData: tooltipData,
295
284
  toolTipPosition: toolTipPosition,
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce, cloneDeep } from 'lodash-es';
4
- import classNames from 'classnames';
3
+ import { cloneDeep } from 'lodash-es';
5
4
  import * as d3 from 'd3';
6
5
  import { CellType } from 'dtable-utils';
7
6
  import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR, CHART_STYLE_COLORS } from '../../constants';
@@ -14,11 +13,6 @@ import ChartComponent from './chart-component';
14
13
  class HorizontalBarStack extends ChartComponent {
15
14
  constructor(props) {
16
15
  super(props);
17
- this.handleResize = debounce(() => {
18
- this.destroyChart();
19
- this.createChart();
20
- this.drawChart();
21
- }, 300);
22
16
  this.createChart = () => {
23
17
  const {
24
18
  chart
@@ -30,8 +24,8 @@ class HorizontalBarStack extends ChartComponent {
30
24
  const initConfig = {
31
25
  insertPadding: 30,
32
26
  borderRadius: 0.2,
33
- marginLeft: show_vertical_axis_label ? 20 : 0,
34
- marginBottom: show_horizontal_axis_label ? 20 : 0
27
+ marginLeft: show_vertical_axis_label ? this.getAxisTitleHeight(chart.config.vertical_axis_label_font_size) : 0,
28
+ marginBottom: show_horizontal_axis_label ? this.getAxisTitleHeight(chart.config.horizontal_axis_label_font_size) : 0
35
29
  };
36
30
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
37
31
  };
@@ -129,8 +123,7 @@ class HorizontalBarStack extends ChartComponent {
129
123
  return x(d[0]) - Number(yAxis.node().getAttribute('data-axisWidth'));
130
124
  }).attr('y', (d, index) => y(d.groupKey)).attr('width', d => x(d[1]) - x(d[0])).attr('height', y.bandwidth()).attr('fill', d => {
131
125
  return this.colorMap[d.data.group_name] || CHART_STYLE_COLORS[0];
132
- }).attr('data-value', d => d.data.value).attr('data-slugid', d => d.data.slugId).attr('data-groupName', d => d.data.name).attr('data-stackKey', d => d.key).call(g => {
133
- // add rect borderRadius
126
+ }).attr('data-value', d => d.data.value).attr('data-groupName', d => d.data.name).attr('data-stackKey', d => d.key).call(g => {
134
127
  const allGroup = this.getAllGroup(contentWrapper);
135
128
  allGroup.forEach(group => {
136
129
  const firstEl = group[0];
@@ -155,8 +148,10 @@ class HorizontalBarStack extends ChartComponent {
155
148
  });
156
149
  });
157
150
  }
151
+ this.animateFadeIn(contentWrapper.selectAll('text'), this.transitionDuration, this.transitionDuration * 0.5);
152
+ this.animateStackGrowInX(g);
158
153
  }).on('click', (event, data) => {
159
- this.props.toggleRecords(data);
154
+ this.toggleRecords(data.data);
160
155
  }).on('mouseover', event => {
161
156
  this.showTooltip(event);
162
157
  this.handleAcitveAndInActiveState('inActive', event);
@@ -180,7 +175,7 @@ class HorizontalBarStack extends ChartComponent {
180
175
  const curGroupName = event.currentTarget.getAttribute('data-groupName');
181
176
  this.setActiveAndInActiveState(state, allGroup, curGroupName);
182
177
  };
183
- this.showTooltip = (event, isDiv) => {
178
+ this.showTooltip = event => {
184
179
  const {
185
180
  summaryColumn,
186
181
  chart
@@ -188,16 +183,10 @@ class HorizontalBarStack extends ChartComponent {
188
183
  const {
189
184
  horizontal_axis_summary_method
190
185
  } = chart.config;
191
- let {
186
+ const {
192
187
  offsetX,
193
188
  offsetY
194
189
  } = event;
195
- if (isDiv) {
196
- const initX = Number(event.currentTarget.getAttribute('data-x'));
197
- const initY = Number(event.currentTarget.getAttribute('y'));
198
- offsetX = offsetX + initX;
199
- offsetY = offsetY + initY;
200
- }
201
190
  const title = event.currentTarget.getAttribute('data-groupName');
202
191
  const stackName = event.currentTarget.getAttribute('data-stackKey');
203
192
  const stackValue = event.currentTarget.getAttribute('data-value');
@@ -219,17 +208,11 @@ class HorizontalBarStack extends ChartComponent {
219
208
  }
220
209
  });
221
210
  };
222
- this.moveTooltip = (event, isDiv) => {
223
- let {
211
+ this.moveTooltip = event => {
212
+ const {
224
213
  offsetX,
225
214
  offsetY
226
215
  } = event;
227
- if (isDiv) {
228
- const initX = Number(event.currentTarget.getAttribute('data-x'));
229
- const initY = Number(event.currentTarget.getAttribute('y'));
230
- offsetX = offsetX + initX;
231
- offsetY = offsetY + initY;
232
- }
233
216
  this.setState({
234
217
  toolTipPosition: {
235
218
  offsetX,
@@ -282,28 +265,7 @@ class HorizontalBarStack extends ChartComponent {
282
265
  return allGroup;
283
266
  };
284
267
  this.addMaskRect = (topG, rect, yAxis) => {
285
- const xWidth = Number(rect.getAttribute('height'));
286
- const {
287
- borderRadius
288
- } = this.chartBoundingClientRect;
289
- // Add mask rect
290
- d3.select(topG).append('foreignObject').attr('opacity', rect.getAttribute('opacity')).attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('width', rect.getAttribute('width')).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-stackKey', rect.getAttribute('data-stackKey')).attr('data-x', () => {
291
- const x = Number(rect.getAttribute('x'));
292
- return x + Number(yAxis.node().getAttribute('data-axisWidth'));
293
- }).on('click', (event, data) => {
294
- this.props.toggleRecords(data);
295
- }).on('mouseover', event => {
296
- this.showTooltip(event, true);
297
- this.handleAcitveAndInActiveState('inActive', event);
298
- }).on('mousemove', event => {
299
- this.moveTooltip(event, true);
300
- }).on('mouseleave', event => {
301
- this.hiddenTooltip();
302
- this.handleAcitveAndInActiveState('active', event);
303
- }).append('xhtml:div').attr('style', `width: 100%; height: 100%; background-color: ${rect.getAttribute('fill')}; border-radius: 0px ${xWidth * borderRadius}px ${xWidth * borderRadius}px 0px`);
304
-
305
- // Remove old rect
306
- d3.select(rect).remove();
268
+ return this.addRoundedClip(rect, 'x');
307
269
  };
308
270
  this.chart = null;
309
271
  this.state = {
@@ -314,7 +276,7 @@ class HorizontalBarStack extends ChartComponent {
314
276
  componentDidMount() {
315
277
  this.createChart();
316
278
  this.drawChart();
317
- window.addEventListener('resize', this.handleResize);
279
+ super.componentDidMount();
318
280
  }
319
281
  componentDidUpdate(prevProps) {
320
282
  super.componentDidUpdate(prevProps);
@@ -325,24 +287,17 @@ class HorizontalBarStack extends ChartComponent {
325
287
  }
326
288
  }
327
289
  componentWillUnmount() {
328
- var _this$chart;
329
- ((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
330
- window.removeEventListener('resize', this.handleResize);
290
+ this.destroyChart();
291
+ super.componentWillUnmount();
331
292
  }
332
293
  render() {
333
- const {
334
- chart
335
- } = this.props;
336
294
  const {
337
295
  tooltipData,
338
296
  toolTipPosition
339
297
  } = this.state;
340
298
  return /*#__PURE__*/React.createElement("div", {
341
299
  ref: ref => this.container = ref,
342
- className: classNames('sea-chart-container', {
343
- 'show-x-axis-label': this.isShowHorizontalAxisLabel(chart),
344
- 'show-y-axis-label': this.isShowVerticalAxisLabel(chart)
345
- })
300
+ className: "sea-chart-container"
346
301
  }, /*#__PURE__*/React.createElement(ToolTip, {
347
302
  tooltipData: tooltipData,
348
303
  toolTipPosition: toolTipPosition,
@@ -1,8 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce } from 'lodash-es';
4
3
  import * as d3 from 'd3';
5
- import classNames from 'classnames';
6
4
  import { TYPE_COLOR_USING, CHART_STYLE_COLORS, CHART_THEME_COLOR } from '../../constants';
7
5
  import { BaseUtils, isFunction } from '../../utils';
8
6
  import { getLabelColor, getConvertedColorRules } from '../../utils/color-utils';
@@ -12,11 +10,6 @@ import ChartComponent from './chart-component';
12
10
  class HorizontalBar extends ChartComponent {
13
11
  constructor(props) {
14
12
  super(props);
15
- this.handleResize = () => {
16
- this.destroyChart();
17
- this.createChart();
18
- this.drawChart();
19
- };
20
13
  this.createChart = () => {
21
14
  const {
22
15
  chart
@@ -29,8 +22,8 @@ class HorizontalBar extends ChartComponent {
29
22
  const initConfig = {
30
23
  insertPadding: 30,
31
24
  borderRadius: 0.2,
32
- marginLeft: show_vertical_axis_label ? 20 : 0,
33
- marginBottom: show_horizontal_axis_label ? 20 : 0,
25
+ marginLeft: show_vertical_axis_label ? this.getAxisTitleHeight(chart.config.vertical_axis_label_font_size) : 0,
26
+ marginBottom: show_horizontal_axis_label ? this.getAxisTitleHeight(chart.config.horizontal_axis_label_font_size) : 0,
34
27
  marginRight: display_data ? 15 : 0
35
28
  };
36
29
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
@@ -116,14 +109,12 @@ class HorizontalBar extends ChartComponent {
116
109
  value: d.value
117
110
  });
118
111
  return color || chartBarColor;
119
- }).attr('value', d => d.value).attr('data-slugid', d => d.slugId).attr('data-groupName', d => d.name).call(g => {
112
+ }).attr('value', d => d.value).attr('data-groupName', d => d.name).call(g => {
120
113
  // add rect borderRadius
121
114
  g.nodes().forEach(rect => {
122
115
  this.addClipPath({
123
116
  rect,
124
- parentNode: rect.parentNode,
125
- attr: 'x',
126
- rectId: rect.getAttribute('data-slugid')
117
+ attr: 'x'
127
118
  });
128
119
  });
129
120
 
@@ -152,6 +143,9 @@ class HorizontalBar extends ChartComponent {
152
143
  }).on('mouseleave', (event, data) => {
153
144
  this.hiddenTooltip();
154
145
  this.handleAcitveAndInActiveState('active', event);
146
+ }).call(g => {
147
+ this.animateRectGrowInX(g);
148
+ this.animateFadeIn(contentWrapper.selectAll('text'), this.transitionDuration, this.transitionDuration * 0.5);
155
149
  });
156
150
  };
157
151
  this.handleAcitveAndInActiveState = (state, event) => {
@@ -217,11 +211,9 @@ class HorizontalBar extends ChartComponent {
217
211
  };
218
212
  }
219
213
  componentDidMount() {
220
- super.componentDidMount();
221
214
  this.createChart();
222
215
  this.drawChart();
223
- this.debouncedHandleResize = debounce(this.handleResize, 300);
224
- window.addEventListener('resize', this.debouncedHandleResize);
216
+ super.componentDidMount();
225
217
  }
226
218
  componentDidUpdate(prevProps) {
227
219
  super.componentDidUpdate(prevProps);
@@ -232,24 +224,17 @@ class HorizontalBar extends ChartComponent {
232
224
  }
233
225
  }
234
226
  componentWillUnmount() {
235
- super.componentWillUnmount();
236
227
  this.destroyChart();
237
- window.removeEventListener('resize', this.debouncedHandleResize);
228
+ super.componentWillUnmount();
238
229
  }
239
230
  render() {
240
- const {
241
- chart
242
- } = this.props;
243
231
  const {
244
232
  tooltipData,
245
233
  toolTipPosition
246
234
  } = this.state;
247
235
  return /*#__PURE__*/React.createElement("div", {
248
236
  ref: ref => this.container = ref,
249
- className: classNames('sea-chart-container', {
250
- 'show-x-axis-label': this.isShowHorizontalAxisLabel(chart),
251
- 'show-y-axis-label': this.isShowVerticalAxisLabel(chart)
252
- })
237
+ className: "sea-chart-container"
253
238
  }, /*#__PURE__*/React.createElement(ToolTip, {
254
239
  tooltipData: tooltipData,
255
240
  toolTipPosition: toolTipPosition,
@@ -63,6 +63,9 @@ const Wrapper = _ref => {
63
63
  setIsStatisticRecordsDialogShow(!isStatisticRecordsDialogShow);
64
64
  }, [isStatisticRecordsDialogShow]);
65
65
  const renderChart = () => {
66
+ if (!data || !chart || !chart.config) {
67
+ return null;
68
+ }
66
69
  const {
67
70
  result,
68
71
  groupbyColumn,