sea-chart 2.0.1 → 2.0.2

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 (94) hide show
  1. package/dist/components/cell-factory/SimpleCellFormatter.js +1 -1
  2. package/dist/components/cell-factory/link-content.js +4 -4
  3. package/dist/components/color-picker/index.js +1 -1
  4. package/dist/components/color-popover/color-rules/color-rule.js +1 -1
  5. package/dist/components/color-popover/color-rules/index.js +1 -1
  6. package/dist/components/color-popover/color-rules-popover.js +6 -6
  7. package/dist/components/color-popover/color-selector-popover.js +2 -2
  8. package/dist/components/color-setting/color-group-selector.js +1 -1
  9. package/dist/components/common-add-tool/index.js +2 -2
  10. package/dist/components/data-process-setter/hide-column-setter.js +1 -1
  11. package/dist/components/data-process-setter/sort-setter.js +2 -2
  12. package/dist/components/drill-down-settings/drill-down-fields-popover/index.js +4 -4
  13. package/dist/components/icon/index.js +2 -2
  14. package/dist/components/popover/hide-column-popover/hide-column-popover-widgets/hide-column-item.js +1 -1
  15. package/dist/components/popover/hide-column-popover/hide-column-popover.js +1 -1
  16. package/dist/components/popover/sort-popover/sort-popover.js +1 -1
  17. package/dist/components/row-card/row-card-header-cell.js +2 -2
  18. package/dist/components/row-card/row-card-header.js +1 -1
  19. package/dist/components/row-card/row-card-item.js +2 -2
  20. package/dist/components/row-card/row-card.js +2 -2
  21. package/dist/components/statistic-record-dialog/index.js +1 -1
  22. package/dist/components/types-dialog/index.js +7 -7
  23. package/dist/context.js +2 -2
  24. package/dist/services/map-json.js +4 -4
  25. package/dist/settings/basic-number-card/style-settings.js +1 -1
  26. package/dist/settings/index.js +3 -3
  27. package/dist/settings/map-settings/map-style-settings.js +1 -1
  28. package/dist/settings/stacks-settings/index.js +1 -1
  29. package/dist/settings/style-settings.js +1 -1
  30. package/dist/settings/table-settings/data-settings.js +1 -1
  31. package/dist/settings/trend-settings/style-setting.js +2 -2
  32. package/dist/settings/widgets/chart-type/index.js +3 -3
  33. package/dist/settings/widgets/date-summary-item.js +2 -2
  34. package/dist/settings/widgets/numeric-summary-item.js +2 -2
  35. package/dist/settings/widgets/summary-settings.js +2 -2
  36. package/dist/settings/widgets/switch/index.js +1 -1
  37. package/dist/settings/widgets/y-axis-group-settings.js +1 -1
  38. package/dist/utils/chart-utils/base-utils.js +7 -7
  39. package/dist/utils/chart-utils/original-data-utils/basic-chart-calculator.js +1 -1
  40. package/dist/utils/chart-utils/original-data-utils/compare-bar-chart-calculator.js +2 -2
  41. package/dist/utils/chart-utils/original-data-utils/completeness-calculator.js +1 -1
  42. package/dist/utils/chart-utils/sql-statistics-utils.js +9 -9
  43. package/dist/utils/collaborator-utils.js +1 -1
  44. package/dist/utils/collaborator.js +2 -2
  45. package/dist/utils/column-utils.js +12 -12
  46. package/dist/utils/common-utils.js +1 -1
  47. package/dist/utils/date-translate.js +1 -1
  48. package/dist/utils/object-utils.js +1 -1
  49. package/dist/utils/options-utils.js +2 -2
  50. package/dist/utils/row-record-utils.js +2 -2
  51. package/dist/utils/sql/chart-data-sql.js +58 -58
  52. package/dist/utils/sql/column-2-sql-column.js +18 -18
  53. package/dist/view/index.js +2 -5
  54. package/dist/view/title/index.js +2 -2
  55. package/dist/view/wrapper/bar.js +168 -93
  56. package/dist/view/wrapper/basic-number-card.js +8 -8
  57. package/dist/view/wrapper/chart-component.js +16 -52
  58. package/dist/view/wrapper/index.js +1 -237
  59. package/dist/view/wrapper/table/index.js +1 -1
  60. package/dist/view/wrapper/table/one-dimension-table-with-numeric-columns.js +3 -3
  61. package/dist/view/wrapper/table/pivot-table-display-name.js +1 -1
  62. package/dist/view/wrapper/table/two-dimension-table.js +8 -8
  63. package/dist/view/wrapper/table-element/components/formatter.js +2 -2
  64. package/dist/view/wrapper/table-element/components/formatters/FileFormatter/index.js +1 -1
  65. package/dist/view/wrapper/table-element/components/formatters/link-formatter.js +17 -17
  66. package/dist/view/wrapper/table-element/components/link-formatter.js +17 -17
  67. package/dist/view/wrapper/table-element/components/record.js +3 -3
  68. package/dist/view/wrapper/table-element/components/records.js +4 -4
  69. package/dist/view/wrapper/table-element/components/utils.js +1 -1
  70. package/dist/view/wrapper/trend.js +18 -18
  71. package/package.json +5 -11
  72. package/dist/utils/custom-g2.js +0 -684
  73. package/dist/view/wrapper/area.js +0 -282
  74. package/dist/view/wrapper/bar-custom.js +0 -239
  75. package/dist/view/wrapper/bar-group.js +0 -274
  76. package/dist/view/wrapper/combination.js +0 -728
  77. package/dist/view/wrapper/compare.js +0 -383
  78. package/dist/view/wrapper/completeness.js +0 -174
  79. package/dist/view/wrapper/dashboard.js +0 -179
  80. package/dist/view/wrapper/funnel.js +0 -206
  81. package/dist/view/wrapper/heat-map.js +0 -434
  82. package/dist/view/wrapper/horizontal-bar-group.js +0 -226
  83. package/dist/view/wrapper/horizontal-bar.js +0 -175
  84. package/dist/view/wrapper/horizontal-component.js +0 -89
  85. package/dist/view/wrapper/line-group.js +0 -219
  86. package/dist/view/wrapper/line.js +0 -222
  87. package/dist/view/wrapper/map.js +0 -368
  88. package/dist/view/wrapper/mirror.js +0 -218
  89. package/dist/view/wrapper/pie.js +0 -253
  90. package/dist/view/wrapper/ring.js +0 -328
  91. package/dist/view/wrapper/scatter.js +0 -140
  92. package/dist/view/wrapper/treemap.js +0 -206
  93. package/dist/view/wrapper/world-map.js +0 -413
  94. package/dist/view/wrapper/wrappers-d3/bar.js +0 -262
@@ -1,434 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
- var _dayjs = _interopRequireDefault(require("dayjs"));
12
- var _weekOfYear = _interopRequireDefault(require("dayjs/plugin/weekOfYear"));
13
- var _dtableUtils = require("dtable-utils");
14
- var _customG = require("../../utils/custom-g2");
15
- var _intl = _interopRequireDefault(require("../../intl"));
16
- var _utils = require("../../utils");
17
- var _constants = require("../../constants");
18
- var _style = require("../../constants/style");
19
- var _chartComponent = _interopRequireDefault(require("./chart-component"));
20
- _dayjs.default.extend(_weekOfYear.default);
21
- class HeatMap extends _chartComponent.default {
22
- constructor(props) {
23
- super(props);
24
- this.createChart = () => {
25
- const appendPadding = [30, 30, 0, 45];
26
- // height for 1 year
27
- const {
28
- chart,
29
- result
30
- } = this.props;
31
- const count = result.years.length;
32
- let {
33
- grid_size,
34
- grid_distance
35
- } = chart.config;
36
- grid_size = grid_size || _constants.DEFAULT_GRID_SIZE;
37
- grid_distance = grid_distance || _constants.DEFAULT_GRID_DISTANCE;
38
- const yearHeight = grid_size * 7 + grid_distance * 6 + 8;
39
- const height = (yearHeight + 30) * count + 30 + (count - 1) * 15;
40
- const width = grid_size * 53 + grid_distance * 52 + 75; // 75: left padding + right padding
41
- this.initChart(this.container, {
42
- appendPadding,
43
- autoFit: false,
44
- height,
45
- width
46
- });
47
- this.chart.on('element:click', e => {
48
- const clickDate = e.data.data.date;
49
- const statData = result.data.find(i => i.name === clickDate);
50
- this.props.toggleRecords(statData);
51
- });
52
- };
53
- this.transformData = statData => {
54
- if (statData.length !== 0) {
55
- let data = {};
56
- let yearFirstDate = (0, _dayjs.default)(statData[0].name);
57
- this.firstDate = yearFirstDate.year() + '-01-01';
58
- statData.forEach(item => {
59
- data[item.name] = data[item.name] ? data[item.name] + item.value : item.value;
60
- });
61
- return data;
62
- }
63
- return [];
64
- };
65
- this.generateBackgroundGridData = statData => {
66
- let currentDate = new Date(this.firstDate);
67
- const year = currentDate.getFullYear();
68
- const gridData = [];
69
- const isLeapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
70
- const yearDayCount = isLeapYear ? 366 : 365;
71
- const getISOWeek = date => {
72
- const target = new Date(date.valueOf());
73
- // set 0 to monday, 6 to sunday
74
- const dayNumber = (date.getUTCDay() + 6) % 7;
75
- // set target to Thursday of this week, daynumber is days passed this week, 3 is Thursday
76
- target.setUTCDate(target.getUTCDate() - dayNumber + 3);
77
- const firstThursday = target.valueOf();
78
- target.setUTCMonth(0, 1);
79
- // find first thursday of the year
80
- // https://blog.csdn.net/theadore2017/article/details/88578753
81
- if (target.getUTCDay() !== 4) {
82
- target.setUTCMonth(0, 1 + (4 - target.getUTCDay() + 7) % 7);
83
- }
84
- return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000ms in one week
85
- };
86
- for (let i = 0; i < yearDayCount; i++) {
87
- const day = currentDate.getDay();
88
- let week = getISOWeek(currentDate) - 1;
89
- const month = currentDate.getMonth();
90
- if (week === 0 && month === 11) {
91
- week = 52;
92
- }
93
- const yearDate = currentDate.toISOString().split('T')[0];
94
- const value = statData[yearDate] || 0;
95
- this.maxValue = Math.max(this.maxValue, value);
96
- gridData.push({
97
- date: yearDate,
98
- value,
99
- day,
100
- week,
101
- month
102
- });
103
- currentDate.setDate(currentDate.getDate() + 1);
104
- }
105
- return gridData;
106
- };
107
- // get text width in canvas
108
- this.getTextWidthInCanvas = text => {
109
- let canvas = document.createElement('canvas');
110
- const context = canvas.getContext('2d');
111
- let font = context.font;
112
- const fontStyle = font.slice(font.indexOf('px'));
113
- font = 'bold ' + 12 + fontStyle;
114
- context.font = font;
115
- return Math.ceil(context.measureText(text).width);
116
- };
117
- this.getLabel = val => {
118
- const currentDate = (0, _dayjs.default)(this.firstDate).add(val * 7, 'days');
119
- let month = currentDate.month();
120
- let monthDate = currentDate.date();
121
- let isFirst = monthDate <= 7 || false;
122
-
123
- // if the week is the first week of a month
124
- // mark it to axis
125
- if (isFirst) {
126
- return _intl.default.get(_constants.MONTH_MIRROR[month]);
127
- }
128
- return '';
129
- };
130
- this.drawChart = () => {
131
- let {
132
- result: data
133
- } = this.props;
134
- data = _utils.BaseUtils.formatEmptyName(data.data, '', _intl.default.get('Empty'));
135
- if (!Array.isArray(data)) return;
136
- this.draw(data);
137
- this.renderAxisLabel(this.props.chart, this.props.tables);
138
- };
139
- this.draw = data => {
140
- this.maxValue = 0;
141
- const {
142
- chart,
143
- tables
144
- } = this.props;
145
- let {
146
- data_color,
147
- grid_size = _constants.DEFAULT_GRID_SIZE,
148
- grid_distance = _constants.DEFAULT_GRID_DISTANCE,
149
- table_id,
150
- summary_type,
151
- summary_column
152
- } = chart.config;
153
- const currentColorOption = _style.COLOR_OPTIONS.filter(item => item.name === data_color)[0] || _style.COLOR_OPTIONS[0];
154
- const {
155
- exampleColors
156
- } = currentColorOption;
157
- this.chart.tooltip({
158
- title: 'date',
159
- showMarkers: false,
160
- showTitle: false,
161
- shared: true,
162
- containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
163
- itemTpl: `<div class="g2-tooltip-content"><div style="width: max-content; text-align: left;" class="tooltip-name">{date}<div><div style="word-break: keep-all;" class="tooltip-item">${_intl.default.get(_constants.TITLE_AMOUNT)} : {value}<div></div>`,
164
- domStyles: {
165
- 'g2-tooltip': {
166
- borderRadius: '2px',
167
- backgroundColor: '#fff',
168
- padding: '10px'
169
- },
170
- 'tooltip-item': {
171
- marginTop: '5px'
172
- }
173
- }
174
- });
175
- this.chart.axis(false);
176
- this.chart.data(data);
177
- const themeColors = this.getThemeColors();
178
- let columnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
179
- if (summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
180
- const table = (0, _dtableUtils.getTableById)(tables, table_id);
181
- const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column) || {};
182
- columnData = summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
183
- }
184
- const yearHeight = grid_size * 7 + grid_distance * 6 + 8;
185
- this.chart.facet('list', {
186
- fields: ['year'],
187
- cols: 1,
188
- showTitle: true,
189
- title: {
190
- offsetY: yearHeight + 15,
191
- offsetX: -((grid_size * 53 + grid_distance * 52) / 2 + 20),
192
- style: {
193
- fontSize: 12,
194
- fill: '#000',
195
- fontWeight: '500'
196
- }
197
- },
198
- padding: [0, 0, 15, 0],
199
- spacing: [0, 15],
200
- eachView: (view, facet) => {
201
- let groupStatData = this.transformData(facet.data);
202
- const gridData = this.generateBackgroundGridData(groupStatData);
203
- const gridView = view.createView();
204
- gridView.axis('week', {
205
- position: 'top',
206
- tickLine: null,
207
- line: null,
208
- label: {
209
- offset: 3,
210
- rotate: 0,
211
- autoHide: false,
212
- autoRotate: false,
213
- autoEllipsis: false,
214
- style: {
215
- fontSize: 12,
216
- fill: themeColors.textColor
217
- },
218
- formatter: (val, label, index) => {
219
- return this.getLabel(val);
220
- }
221
- },
222
- grid: null
223
- });
224
- gridView.axis('day', {
225
- grid: null,
226
- label: {
227
- autoHide: false,
228
- autoEllipsis: false,
229
- style: {
230
- fill: themeColors.textColor
231
- }
232
- }
233
- });
234
- gridView.scale({
235
- day: {
236
- type: 'cat',
237
- values: [_intl.default.get('Sun'), _intl.default.get('Mon'), _intl.default.get('Tue'), _intl.default.get('Wed'), _intl.default.get('Thu'), _intl.default.get('Fri'), _intl.default.get('Sat')]
238
- },
239
- week: {
240
- type: 'cat'
241
- },
242
- value: {
243
- sync: true
244
- },
245
- date: {
246
- type: 'cat'
247
- }
248
- });
249
- gridView.data(gridData);
250
- gridView.polygon().position('week*day*date').color('value', value => {
251
- if (!value || value <= 0) {
252
- return '#EBEDF0';
253
- }
254
- if (value === this.maxValue) return exampleColors[8];
255
- return exampleColors[Math.floor(value / (this.maxValue / 9))];
256
- }).customInfo({
257
- grid_size,
258
- grid_distance
259
- }).shape('boundary-polygon').label(false).tooltip('date*value', (date, value) => {
260
- return {
261
- date,
262
- value: (0, _dtableUtils.getNumberDisplayString)(value, columnData)
263
- };
264
- });
265
- gridView.coordinate().reflect('y');
266
- }
267
- });
268
- this.chart.legend('value', {
269
- position: 'top-left',
270
- layout: 'horizontal',
271
- offsetY: -6,
272
- custom: true,
273
- itemSpacing: 2,
274
- itemName: {
275
- style: {
276
- fontWeight: 'bold',
277
- fill: themeColors.textColor
278
- }
279
- },
280
- items: this.getLegendItems(exampleColors)
281
- });
282
- this.chart.removeInteraction('legend-filter');
283
- requestAnimationFrame(() => {
284
- this.chart.render();
285
- });
286
- };
287
- _dayjs.default.locale('en');
288
- this.chart = null;
289
- this.maxValue = 0;
290
- }
291
- componentDidMount() {
292
- (0, _customG.registerShape)('polygon', 'boundary-polygon', {
293
- draw(cfg, container) {
294
- if (cfg && cfg.points && cfg.points.length > 0) {
295
- const group = container.addGroup();
296
- let attrs = {
297
- fill: cfg.color,
298
- lineWidth: 1,
299
- stroke: _style.FILL_BORDER_COLOR_MAP[cfg.color]
300
- };
301
- const {
302
- points,
303
- customInfo
304
- } = cfg;
305
- const {
306
- grid_size,
307
- grid_distance
308
- } = customInfo;
309
- const distance = grid_distance / 2;
310
- const offset = grid_size - 1;
311
- const parsedPoint = this.parsePoints(points);
312
- let [p0, p1, p2, p3] = parsedPoint;
313
- p0.y = p0.y + distance;
314
- p1.x = p0.x;
315
- p1.y = p0.y + offset;
316
- p2.x = p0.x + offset;
317
- p2.y = p1.y;
318
- p3.x = p0.x + offset;
319
- p3.y = p0.y;
320
- // get cell path that has radius, the cell radius is 2;
321
- const path = (0, _customG.getRectWithCornerRadius)(parsedPoint, this.coordinate, 2);
322
- attrs.path = path;
323
- group.addShape('path', {
324
- attrs,
325
- capture: cfg.data.value > 0,
326
- visible: true
327
- });
328
- return group;
329
- }
330
- }
331
- });
332
- this.createChart();
333
- this.drawChart();
334
- }
335
- componentDidUpdate(prevProps) {
336
- super.componentDidUpdate(prevProps);
337
- if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
338
- var _this$chart;
339
- ((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
340
- this.createChart();
341
- this.drawChart();
342
- }
343
- }
344
- componentWillUnmount() {
345
- var _this$chart2;
346
- ((_this$chart2 = this.chart) === null || _this$chart2 === void 0 ? void 0 : _this$chart2.autoPadding) && this.chart.destroy();
347
- }
348
- getLegendItemPath(x, y, r, index, textWidth) {
349
- // x, y represents the coordinates of the center point of the legend item marker
350
- let p0 = {
351
- x: x - 6,
352
- y: y + 6
353
- };
354
- // translate the lengend marker to right to make the first legend item text to left of the marker
355
- if (index === 0) {
356
- p0.x = p0.x + textWidth + 16;
357
- } else {
358
- p0.x = p0.x + 18;
359
- }
360
- const p1 = {
361
- x: p0.x,
362
- y: p0.y - 12
363
- };
364
- const p2 = {
365
- x: p0.x + 12,
366
- y: p0.y - 12
367
- };
368
- const p3 = {
369
- x: p0.x + 12,
370
- y: p0.y
371
- };
372
- const path = (0, _customG.getRectWithCornerRadius)([p0, p1, p2, p3], this.chart.coordinateInstance, 2);
373
- return path;
374
- }
375
- getLegendItems(colors) {
376
- const text = _intl.default.get('Less');
377
- const textWidth = this.getTextWidthInCanvas(text);
378
- const items = [{
379
- name: text,
380
- marker: {
381
- symbol: (x, y, r) => this.getLegendItemPath(x, y, r, 0, textWidth),
382
- spacing: 0,
383
- style: {
384
- fill: '#E1E3E6',
385
- lineWidth: 1,
386
- stroke: '#EBEDF0',
387
- r: 5
388
- }
389
- }
390
- }];
391
- colors.forEach((color, index) => {
392
- items.push({
393
- marker: {
394
- symbol: (x, y, r) => this.getLegendItemPath(x, y, r, index + 1, textWidth),
395
- spacing: 2,
396
- style: {
397
- fill: color,
398
- lineWidth: 1,
399
- stroke: _style.FILL_BORDER_COLOR_MAP[color],
400
- r: 5
401
- }
402
- }
403
- });
404
- });
405
- items[9].name = _intl.default.get('More');
406
- items[9].marker.spacing = 22;
407
- return items;
408
- }
409
- render() {
410
- const {
411
- chart
412
- } = this.props;
413
- return /*#__PURE__*/_react.default.createElement("div", {
414
- className: (0, _classnames.default)('sea-chart-container w-100', {
415
- 'show-x-axis-label': this.isShowXAxisLabel(chart),
416
- 'show-y-axis-label': this.isShowYAxisLabel(chart)
417
- }),
418
- ref: ref => this.container = ref
419
- });
420
- }
421
- }
422
- HeatMap.propTypes = {
423
- canvasStyle: _propTypes.default.object,
424
- chart: _propTypes.default.object,
425
- groupbyColumn: _propTypes.default.object,
426
- columnGroupbyColumn: _propTypes.default.object,
427
- summaryColumn: _propTypes.default.object,
428
- result: _propTypes.default.object,
429
- tables: _propTypes.default.array,
430
- theme: _propTypes.default.object,
431
- toggleRecords: _propTypes.default.func,
432
- customRender: _propTypes.default.func
433
- };
434
- var _default = exports.default = HeatMap;
@@ -1,226 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _lodashEs = require("lodash-es");
11
- var _classnames = _interopRequireDefault(require("classnames"));
12
- var _constants = require("dtable-ui-component/lib/constants");
13
- var _constants2 = require("../../constants");
14
- var _utils = require("../../utils");
15
- var _intl = _interopRequireDefault(require("../../intl"));
16
- var _colorRules = require("../../constants/color-rules");
17
- var _columnUtils = require("../../utils/column-utils");
18
- var _horizontalComponent = _interopRequireDefault(require("./horizontal-component"));
19
- class HorizontalBarGroup extends _horizontalComponent.default {
20
- constructor(props) {
21
- super(props);
22
- this.handleResize = (0, _lodashEs.debounce)(() => {
23
- var _this$chart;
24
- ((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
25
- this.createChart();
26
- this.drawChart();
27
- this.renderHorizontalLabel(this.props.chart, this.props.tables);
28
- }, 300);
29
- this.createChart = () => {
30
- const {
31
- chart
32
- } = this.props;
33
- const {
34
- display_data
35
- } = chart.config;
36
- this.chartTopPadding = display_data ? 17 : 0;
37
- const appendPadding = [this.chartTopPadding, 30, 0, 0];
38
- this.initChart(this.container, {
39
- appendPadding
40
- });
41
- this.chart.on('interval:click', e => {
42
- this.props.toggleRecords(e.data.data);
43
- });
44
- };
45
- this.clearChart = () => {
46
- this.chart.annotation().clear(true);
47
- this.chart.clear(true);
48
- };
49
- this.drawChart = () => {
50
- let {
51
- result: data,
52
- customRender,
53
- chart
54
- } = this.props;
55
- data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
56
- if (!Array.isArray(data)) return;
57
- this.chart.scale(this.groupName, {
58
- type: 'cat'
59
- });
60
- const {
61
- sort_type,
62
- type
63
- } = chart.config;
64
- if (type === _constants2.CHART_TYPE.STACKED_HORIZONTAL_BAR && sort_type) {
65
- data = (0, _columnUtils.sortDataByGroupSum)(data, sort_type);
66
- }
67
- this.loadData(data);
68
- this.draw(data);
69
- (0, _utils.isFunction)(customRender) && customRender(this.chart);
70
- requestAnimationFrame(() => {
71
- this.chart.render();
72
- });
73
- };
74
- this.draw = data => {
75
- const {
76
- chart,
77
- summaryColumn,
78
- globalTheme,
79
- chartColorTheme,
80
- tables
81
- } = this.props;
82
- const theme = _constants2.CHART_THEME_COLOR[globalTheme];
83
- const {
84
- horizontal_axis_summary_method,
85
- display_data,
86
- label_font_size,
87
- type,
88
- column_groupby_column_key,
89
- table_id,
90
- color_theme
91
- } = chart.config;
92
- const isGroup = type === _constants2.CHART_TYPE.HORIZONTAL_GROUP_BAR;
93
- const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
94
- const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === _constants.CellType.SINGLE_SELECT && color_theme === _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
95
- const newData = this.getChartGroupData(data);
96
- let singleBarWidth, singleBarRadius;
97
- // y-axis label width:(6 + 10)
98
- // topPadding and legend height
99
- const chartHeight = this.chart.height - 6 - 10 - this.chartTopPadding - 30;
100
- if (!isGroup) {
101
- singleBarWidth = Math.round(chartHeight / (2 * newData.length));
102
- this.markFirstOrLast(data, 'last');
103
- } else {
104
- // stacked chart
105
- const maxCountGroup = (0, _lodashEs.maxBy)(newData, 'currentGroupCount');
106
- // calculate the width of each bar in a mostCommonCountGroup
107
- singleBarWidth = Math.round(chartHeight / (2 * newData.length * maxCountGroup.currentGroupCount));
108
- }
109
- singleBarRadius = Math.min(singleBarWidth / 5, 10);
110
- this.drawLabels(newData);
111
- // set Coord type
112
- this.chart.coordinate('rect');
113
- this.autoAdjustDataOptions(chart, data, summaryColumn);
114
- const adjust = !isGroup ? {
115
- type: 'stack'
116
- } : {
117
- type: 'dodge',
118
- marginRatio: 0
119
- };
120
-
121
- // use single select column color
122
- useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
123
- this.chart.interval().animate({
124
- // custom update animation
125
- update: {
126
- animation: 'fadeIn',
127
- duration: 1000,
128
- easing: 'easeLinear'
129
- }
130
- }).label(display_data ? 'value' : false, {
131
- style: {
132
- fontSize: _utils.BaseUtils.getLabelFontSize(label_font_size),
133
- fill: theme.labelColor,
134
- ...this.labelStroke
135
- }
136
- }).position('name*value').size(singleBarWidth).color('group_name', group_name => {
137
- return this.colorMap[group_name] || _constants2.CHART_STYLE_COLORS[0];
138
- }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
139
- return {
140
- title: !name && typeof name !== 'number' ? _intl.default.get(_constants2.EMPTY_NAME) : name,
141
- value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, value, horizontal_axis_summary_method),
142
- name: !group_name && typeof group_name !== 'number' ? _intl.default.get(_constants2.EMPTY_NAME) : group_name
143
- };
144
- }).adjust([adjust]).state({
145
- active: {
146
- style: {
147
- stroke: null
148
- }
149
- }
150
- }).style('isLast', isLast => {
151
- if (adjust.type === 'stack') {
152
- if (isLast) {
153
- return {
154
- radius: [singleBarRadius, singleBarRadius, 0, 0]
155
- };
156
- } else {
157
- return {
158
- radius: [0, 0, 0, 0]
159
- };
160
- }
161
- } else {
162
- return {
163
- radius: [singleBarRadius, singleBarRadius, 0, 0]
164
- };
165
- }
166
- });
167
- if (isGroup) {
168
- this.formatDataByName(data);
169
- }
170
- this.setToolTip(isGroup, summaryColumn, horizontal_axis_summary_method);
171
- this.setNameLabelAndTooltip(theme, this.labelCount);
172
- this.setValueLabel(theme);
173
- this.chart.coordinate().transpose();
174
- this.setLegend('group_name', theme, 'top-right');
175
- this.chart.interaction('element-highlight-by-x');
176
- };
177
- this.chart = null;
178
- }
179
- componentDidMount() {
180
- this.createChart();
181
- this.drawChart();
182
- this.renderHorizontalLabel(this.props.chart, this.props.tables);
183
- window.addEventListener('resize', this.handleResize);
184
- }
185
- componentDidUpdate(prevProps) {
186
- super.componentDidUpdate(prevProps);
187
- if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
188
- var _this$chart2;
189
- ((_this$chart2 = this.chart) === null || _this$chart2 === void 0 ? void 0 : _this$chart2.autoPadding) && this.chart.destroy();
190
- this.createChart();
191
- this.drawChart();
192
- this.renderHorizontalLabel(prevProps.chart, prevProps.tables);
193
- }
194
- }
195
- componentWillUnmount() {
196
- var _this$chart3;
197
- ((_this$chart3 = this.chart) === null || _this$chart3 === void 0 ? void 0 : _this$chart3.autoPadding) && this.chart.destroy();
198
- window.removeEventListener('resize', this.handleResize);
199
- }
200
- render() {
201
- const {
202
- chart
203
- } = this.props;
204
- return /*#__PURE__*/_react.default.createElement("div", {
205
- className: (0, _classnames.default)('sea-chart-container', {
206
- 'show-x-axis-label': this.isShowXAxisLabel(chart),
207
- 'show-y-axis-label': this.isShowYAxisLabel(chart)
208
- }),
209
- ref: ref => this.container = ref
210
- });
211
- }
212
- }
213
- HorizontalBarGroup.propTypes = {
214
- canvasStyle: _propTypes.default.object,
215
- chart: _propTypes.default.object,
216
- groupbyColumn: _propTypes.default.object,
217
- columnGroupbyColumn: _propTypes.default.object,
218
- summaryColumn: _propTypes.default.object,
219
- result: _propTypes.default.array,
220
- tables: _propTypes.default.array,
221
- globalTheme: _propTypes.default.string,
222
- chartColorTheme: _propTypes.default.string,
223
- toggleRecords: _propTypes.default.func,
224
- customRender: _propTypes.default.func
225
- };
226
- var _default = exports.default = HorizontalBarGroup;