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,413 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _Loading2 = _interopRequireDefault(require("dtable-ui-component/lib/Loading"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _index = _interopRequireDefault(require("@antv/data-set/lib/index"));
12
- var _dtableUtils = require("dtable-utils");
13
- var _classnames = _interopRequireDefault(require("classnames"));
14
- var _customG = require("../../utils/custom-g2");
15
- var _intl = _interopRequireDefault(require("../../intl"));
16
- var _mapJson = _interopRequireDefault(require("../../services/map-json"));
17
- var _utils = require("../../utils");
18
- var _colorRules = require("../../constants/color-rules");
19
- var _constants = require("../../constants");
20
- var _context = _interopRequireDefault(require("../../context"));
21
- const reg = /^([A-Za-z])/;
22
- const fixData = (statisticData, countryMap, chartType) => {
23
- if (!statisticData) return [];
24
- let statisticNewData = [];
25
- let sum = 0;
26
- statisticData.forEach(item => {
27
- if (item && item.name) {
28
- let nameType, name, name_cn;
29
- if (reg.test(item.name)) {
30
- nameType = 'en';
31
- name = item.name;
32
- name_cn = countryMap.get(name);
33
- } else {
34
- nameType = 'zh-cn';
35
- name = countryMap.get(item.name);
36
- name_cn = item.name;
37
- }
38
- const value = item.value;
39
- if (name_cn && name) {
40
- const existedData = statisticNewData.find(i => i.name === name);
41
- if (existedData) {
42
- existedData.value += value;
43
- existedData.formatted_value = parseInt(existedData.formatted_value) + parseInt(item.formatted_value) + '';
44
- } else {
45
- statisticNewData.push({
46
- name_cn,
47
- name,
48
- nameType,
49
- value: value || 0,
50
- formatted_value: item.formatted_value + ''
51
- });
52
- }
53
- if (chartType === _constants.CHART_TYPE.WORLD_MAP_BUBBLE) {
54
- sum += item.value;
55
- }
56
- }
57
- }
58
- });
59
- if (chartType === _constants.CHART_TYPE.WORLD_MAP_BUBBLE) {
60
- statisticNewData.sum = sum;
61
- }
62
- return statisticNewData;
63
- };
64
- const CHART_STYLE_CONFIG = {
65
- 'g2-tooltip': {
66
- borderRadius: '2px',
67
- backgroundColor: '#fff',
68
- padding: '10px'
69
- },
70
- 'tooltip-item': {
71
- marginTop: '5px'
72
- }
73
- };
74
- const getDefaultChartStyleByKey = key => {
75
- return CHART_STYLE_CONFIG[key] || {};
76
- };
77
- function createChart(container) {
78
- // width / height = 1.5 for chinese map
79
- const {
80
- width,
81
- height
82
- } = (0, _utils.getMapCanvasStyle)(container, 2.1);
83
- let config = {
84
- container: container,
85
- width,
86
- height
87
- };
88
- return new _customG.Chart(config);
89
- }
90
- function initChart(currentChart, props) {
91
- const {
92
- result,
93
- toggleRecords,
94
- isCalculateByView
95
- } = props;
96
- if (isCalculateByView) {
97
- currentChart.on('element:click', e => {
98
- const lang = _intl.default.lang;
99
- const data = e.data.data;
100
- const countryName = lang === 'zh-cn' ? data.name_cn : data.name;
101
- const clickData = result.find(i => i.name === countryName);
102
- if (clickData) {
103
- toggleRecords(clickData);
104
- }
105
- });
106
- }
107
- currentChart.tooltip({
108
- showTitle: false,
109
- showMarkers: false,
110
- shared: true,
111
- containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
112
- itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{name}<div><div class="tooltip-item">数量: {value}<div></div>',
113
- domStyles: {
114
- 'g2-tooltip': getDefaultChartStyleByKey('g2-tooltip'),
115
- 'tooltip-item': getDefaultChartStyleByKey('tooltip-item')
116
- }
117
- });
118
- currentChart.scale({
119
- longitude: {
120
- sync: true
121
- },
122
- latitude: {
123
- sync: true
124
- }
125
- });
126
- currentChart.axis(false);
127
- }
128
- function mapGetNumberDisplayString(value, columnData, summaryMethod) {
129
- if (summaryMethod === _constants.CHART_SUMMARY_TYPE.Distinct_values) {
130
- return value;
131
- }
132
- return (0, _dtableUtils.getNumberDisplayString)(value, columnData);
133
- }
134
- function getThemeColors() {
135
- let themeColors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
136
- let theme = arguments.length > 1 ? arguments[1] : undefined;
137
- // dark->custom->light
138
- if (theme === _constants.THEME_NAME_MAP.DARK) {
139
- themeColors = _constants.CHART_THEME_COLOR.dark;
140
- }
141
- return themeColors || _constants.CHART_THEME_COLOR[_constants.THEME_NAME_MAP.LIGHT];
142
- }
143
- function WorldMap(props) {
144
- let {
145
- result: statisticData,
146
- chart,
147
- isCalculateByView
148
- } = props;
149
- if (isCalculateByView) {
150
- statisticData = statisticData.map(v => {
151
- var _v$name;
152
- v.name = ((_v$name = v.name) === null || _v$name === void 0 ? void 0 : _v$name.country_region) || v.name || '';
153
- return v;
154
- });
155
- }
156
-
157
- // mapLocation is initially set to null, in this case mapLevel is country, so doesn't here
158
- const {
159
- // map_location: mapLocation,
160
- // map_level: mapLevel = MAP_LEVEL.COUNTRY,
161
- type,
162
- data_color,
163
- bubble_color,
164
- legend_size,
165
- legend_direction,
166
- summary_type,
167
- summary_column_key,
168
- summary_method,
169
- table_id
170
- } = chart.config;
171
- const chartRef = (0, _react.useRef)(null);
172
- const chartContainerRef = (0, _react.useRef)(null);
173
- const dataSetRef = (0, _react.useRef)(null);
174
- const [isLoading, setIsLoading] = (0, _react.useState)(true);
175
- const [mapData, setMapData] = (0, _react.useState)(null);
176
- const renderCommonChart = (0, _react.useCallback)(function (statisticNewData) {
177
- const currentDataSet = dataSetRef.current;
178
- const currentChart = chartRef.current;
179
- const userDataView = currentDataSet.getView('statisticViewModel').source(statisticNewData).transform({
180
- geoDataView: currentDataSet.getView('mapDataModel'),
181
- field: 'name',
182
- type: 'geo.region',
183
- as: ['longitude', 'latitude']
184
- });
185
- const currentColorOption = _colorRules.COLOR_OPTIONS.filter(item => item.name === data_color)[0] || _colorRules.COLOR_OPTIONS[0];
186
- const {
187
- exampleColors,
188
- highlightedBorderColor
189
- } = currentColorOption;
190
- let columnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
191
- if (summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
192
- const table = (0, _dtableUtils.getTableById)(table_id);
193
- const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key) || {};
194
- columnData = summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
195
- }
196
- const statisticView = currentChart.createView();
197
- statisticView.data(userDataView.rows);
198
- statisticView.polygon().position('longitude*latitude').color('value', `${exampleColors[0]}-${exampleColors[4]}-${exampleColors[8]}`).style({
199
- lineWidth: 1,
200
- stroke: '#bdbdbd',
201
- strokeOpacity: 0.5
202
- }).state({
203
- active: {
204
- style: {
205
- lineWidth: 1,
206
- stroke: highlightedBorderColor
207
- }
208
- }
209
- }).tooltip('name*formatted_value*color*nameType*name_cn', (name, value, color, nameType, name_cn) => {
210
- return {
211
- name: nameType === 'en' ? name : name_cn,
212
- color,
213
- value
214
- };
215
- });
216
- const themeColors = getThemeColors();
217
- const legendDirection = legend_direction || 'vertical';
218
- const size = legend_size || 1;
219
- chartRef.current.legend({
220
- layout: legendDirection,
221
- position: legendDirection === 'vertical' ? 'left-bottom' : 'bottom-left',
222
- rail: {
223
- type: 'color',
224
- defaultLength: 100 * size
225
- },
226
- label: {
227
- spacing: 2,
228
- style: {
229
- fill: themeColors.textColor,
230
- stroke: '#fff'
231
- },
232
- align: legendDirection === 'vertical' ? 'right' : 'bottom',
233
- formatter: value => {
234
- return mapGetNumberDisplayString(value, columnData, summary_method);
235
- }
236
- },
237
- slidable: false
238
- });
239
- statisticView.interaction('element-active');
240
- statisticView.render();
241
- return statisticView;
242
- }, [data_color, legend_direction, legend_size, summary_column_key, summary_method, summary_type, table_id]);
243
- const renderBubbleChart = (0, _react.useCallback)(function (statisticNewData) {
244
- const currentDataSet = dataSetRef.current;
245
- const currentChart = chartRef.current;
246
- const userDv = currentDataSet.createView().source(statisticNewData).transform({
247
- geoDataView: currentDataSet.getView('mapDataModel'),
248
- field: 'name',
249
- type: 'geo.centroid',
250
- as: ['longitude', 'latitude']
251
- });
252
- let columnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
253
- if (summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
254
- const table = (0, _dtableUtils.getTableById)(table_id);
255
- const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key) || {};
256
- columnData = summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
257
- }
258
- const statisticView = currentChart.createView();
259
- statisticView.data(userDv.rows);
260
- currentChart.theme({
261
- defaultColor: bubble_color || '#2a67d1'
262
- });
263
- statisticView.point().position('longitude*latitude').size('value', value => {
264
- const percent = value / statisticNewData.sum;
265
- let size = percent * 100;
266
- return size;
267
- }).shape('circle').color(bubble_color || '#2a67d1').tooltip('name*formatted_value*color*nameType*name_cn', (name, value, color, nameType, name_cn) => {
268
- return {
269
- name: nameType === 'en' ? name : name_cn,
270
- color,
271
- value
272
- };
273
- }).style({
274
- fillOpacity: 0.6,
275
- stroke: bubble_color || '#2a67d1'
276
- }).state({
277
- active: {
278
- style: {
279
- lineWidth: 1,
280
- stroke: bubble_color || '#2a67d1',
281
- fillOpacity: 0.9
282
- }
283
- }
284
- });
285
- const themeColors = getThemeColors();
286
- const legendDirection = legend_direction || 'vertical';
287
- const size = legend_size || 1;
288
- currentChart.legend({
289
- layout: legendDirection,
290
- position: legendDirection === 'vertical' ? 'left-bottom' : 'bottom-left',
291
- rail: {
292
- type: 'size',
293
- defaultLength: 100 * size
294
- },
295
- label: {
296
- style: {
297
- fill: themeColors.textColor
298
- // fill: data_color
299
- },
300
- align: legendDirection === 'vertical' ? 'right' : 'bottom',
301
- formatter: value => {
302
- return mapGetNumberDisplayString(value, columnData, summary_method);
303
- }
304
- },
305
- slidable: false
306
- });
307
- statisticView.interaction('element-active');
308
- statisticView.render();
309
- return statisticView;
310
- }, [bubble_color, legend_direction, legend_size, summary_column_key, summary_method, summary_type, table_id]);
311
- (0, _react.useEffect)(() => {
312
- const handleResize = () => {
313
- const container = chartContainerRef.current;
314
- const {
315
- width,
316
- height
317
- } = (0, _utils.getMapCanvasStyle)(container, 2.1);
318
- chartRef.current.changeSize(width, height);
319
- };
320
- window.addEventListener('resize', handleResize);
321
- return () => {
322
- window.removeEventListener('resize', handleResize);
323
- };
324
- }, []);
325
-
326
- // used to fetch mapJson data
327
- // only triggered once
328
- (0, _react.useEffect)(() => {
329
- (async () => {
330
- try {
331
- const mediaUrl = _context.default.getSetting('mediaUrl');
332
- const mapJson = await (0, _mapJson.default)(_constants.MAP_LEVEL.WORLD, '', mediaUrl);
333
- setMapData(mapJson);
334
- setIsLoading(false);
335
- } catch (error) {
336
- console.error(error);
337
- setIsLoading(false);
338
- }
339
- })();
340
- }, []);
341
-
342
- // used to init map background
343
- // if no statistics data, then render empty map
344
- (0, _react.useEffect)(() => {
345
- if (!chartRef.current) {
346
- chartRef.current = createChart(chartContainerRef.current);
347
- }
348
- // triggered after mapData is set
349
- if (!mapData) return;
350
- const currentChart = chartRef.current;
351
- initChart(currentChart, props);
352
- const dataSet = new _index.default();
353
- dataSetRef.current = dataSet;
354
- // transform map data
355
- const data = dataSet.createView('mapDataModel').source(mapData, {
356
- type: 'GeoJSON'
357
- });
358
- const mapView = currentChart.createView();
359
- // // draw background map
360
- mapView.data(data.rows);
361
- mapView.tooltip(false);
362
- mapView.polygon().position('longitude*latitude').style({
363
- fill: '#e2e2e2',
364
- stroke: '#bdbdbd',
365
- lineWidth: 1
366
- });
367
- dataSet.createView('statisticViewModel');
368
- mapView.render();
369
- return () => {
370
- currentChart.destroy();
371
- };
372
- },
373
- // eslint-disable-next-line react-hooks/exhaustive-deps
374
- [mapData]);
375
- (0, _react.useEffect)(() => {
376
- const currentChart = chartRef.current;
377
- // need mapData and statisticData to render
378
- if (!Array.isArray(statisticData) || !mapData) return;
379
- const countryMap = new Map();
380
- mapData.features.forEach(item => {
381
- countryMap.set(item.properties.name, item.properties.name_cn);
382
- countryMap.set(item.properties.name_cn, item.properties.name);
383
- });
384
- const mapFormattedData = fixData(statisticData, countryMap, type);
385
- if (mapFormattedData.length === 0) {
386
- currentChart.legend(false);
387
- currentChart.render();
388
- return;
389
- }
390
- let currentView;
391
- if (type.includes('bubble')) {
392
- currentView = renderBubbleChart(mapFormattedData);
393
- } else {
394
- currentView = renderCommonChart(mapFormattedData);
395
- }
396
- currentChart.render();
397
- return () => {
398
- currentView && currentView.destroy();
399
- };
400
- }, [statisticData, mapData, type, renderCommonChart, renderBubbleChart]);
401
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isLoading && /*#__PURE__*/_react.default.createElement("div", {
402
- className: 'statistic-chart-loading-container'
403
- }, /*#__PURE__*/_react.default.createElement(_Loading2.default, null)), /*#__PURE__*/_react.default.createElement("div", {
404
- className: (0, _classnames.default)('sea-chart-container '),
405
- style: {
406
- display: 'flex',
407
- justifyContent: 'center',
408
- alignItems: 'center'
409
- },
410
- ref: chartContainerRef
411
- }));
412
- }
413
- var _default = exports.default = WorldMap;
@@ -1,262 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _react = _interopRequireDefault(require("react"));
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
- var _lodashEs = require("lodash-es");
12
- var d3 = _interopRequireWildcard(require("d3"));
13
- var _constants = require("../../../constants");
14
- var _utils = require("../../../utils");
15
- var _colorUtils = require("../../../utils/color-utils");
16
- var _intl = _interopRequireDefault(require("../../../intl"));
17
- var _chartComponent = _interopRequireDefault(require("../chart-component"));
18
- class Bar extends _chartComponent.default {
19
- constructor(props) {
20
- super(props);
21
- this.handleResize = () => {
22
- this.chart.node() && this.chart.node().remove();
23
- this.createChart();
24
- this.drawChart();
25
- };
26
- this.createChart = () => {
27
- this.initD3Chart(this.container);
28
- };
29
- this.drawChart = () => {
30
- const {
31
- customRender
32
- } = this.props;
33
- let {
34
- result: data
35
- } = this.props;
36
- data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
37
- if (!Array.isArray(data)) return;
38
- this.draw(data);
39
- this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
40
- (0, _utils.isFunction)(customRender) && customRender(this.chart);
41
- };
42
- this.getFillColor = data => {
43
- const {
44
- chart,
45
- chartColorTheme
46
- } = this.props;
47
- const {
48
- y_axis_label_color,
49
- color_option,
50
- y_axis_label_color_rules
51
- } = chart.config;
52
- let chartBarColor = y_axis_label_color || _constants.CHART_STYLE_COLORS[0];
53
- if (chartColorTheme) {
54
- chartBarColor = _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors[0];
55
- }
56
- const colorRules = color_option === _constants.TYPE_COLOR_USING.USE_RULES && y_axis_label_color_rules && (0, _colorUtils.getConvertedColorRules)(y_axis_label_color_rules);
57
- const color = (0, _colorUtils.getLabelColor)({
58
- chart: chart.config,
59
- colorRules,
60
- value: data.value
61
- });
62
- return color || chartBarColor;
63
- };
64
- this.showTooltip = (event, data, title) => {
65
- const {
66
- offsetX,
67
- offsetY
68
- } = event;
69
- const newTooltipData = {
70
- title: title,
71
- items: [{
72
- color: this.getFillColor(data),
73
- name: data.name,
74
- value: data.value
75
- }]
76
- };
77
- this.setState({
78
- tooltipData: newTooltipData
79
- });
80
- this.setState({
81
- toolTipPosition: {
82
- offsetX,
83
- offsetY
84
- }
85
- });
86
- };
87
- this.moveTooltip = event => {
88
- const {
89
- offsetX,
90
- offsetY
91
- } = event;
92
- this.setState({
93
- toolTipPosition: {
94
- offsetX,
95
- offsetY
96
- }
97
- });
98
- };
99
- this.hiddenTooltip = event => {
100
- this.setState({
101
- toolTipPosition: null
102
- });
103
- };
104
- this.setActiveAndInActiveState = (state, data) => {
105
- const {
106
- chart
107
- } = this.props;
108
- const paths = d3.selectAll(`.rects-wrapper-${chart === null || chart === void 0 ? void 0 : chart.id} path`);
109
- if (state === 'active') {
110
- paths.nodes().forEach(path => {
111
- d3.select(path).attr('opacity', 1);
112
- });
113
- return;
114
- }
115
- paths.nodes().forEach(path => {
116
- if (path.id !== data.slugId) {
117
- d3.select(path).attr('opacity', 0.3);
118
- }
119
- });
120
- };
121
- this.draw = data => {
122
- const {
123
- chart,
124
- globalTheme,
125
- tables
126
- } = this.props;
127
- const theme = _constants.CHART_THEME_COLOR[globalTheme];
128
- const {
129
- display_goal_line,
130
- goal_value,
131
- goal_label
132
- } = chart.style_config || {};
133
- const {
134
- y_axis_summary_type,
135
- y_axis_summary_column_key,
136
- y_axis_column_key,
137
- y_axis_show_value,
138
- label_font_size,
139
- table_id,
140
- y_axis_max,
141
- y_axis_min,
142
- y_axis_auto_range
143
- } = chart.config;
144
- const tooltipTitle = this.getTitle(tables, table_id, y_axis_summary_type, y_axis_column_key || y_axis_summary_column_key);
145
- const {
146
- width: chartWidth,
147
- height: chartHeight
148
- } = this.chartBoundingClientRect;
149
- const insertPadding = 30;
150
- const borderRadius = 10;
151
- const x = d3.scaleBand().domain(data.map(item => item.name)).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
152
- const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, d3.max(data, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
153
- this.chart.append('g').attr('transform', `translate(0, ${chartHeight - insertPadding})`).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
154
- g.selectAll('.domain').attr('stroke', theme.XAxisColor);
155
- g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
156
- g.selectAll('text').attr('font-size', theme.fontSize);
157
- g.selectAll('text').attr('fill', theme.textColor);
158
- });
159
- this.chart.append('g').attr('transform', `translate(${insertPadding}, 0)`).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
160
- g.select('.domain').remove();
161
- g.selectAll('line').node().remove(); // delete the first line
162
- g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
163
- g.selectAll('text').attr('font-size', theme.fontSize);
164
- g.selectAll('text').attr('fill', theme.textColor);
165
- });
166
- this.chart.append('g').attr('class', `rects-wrapper-${chart === null || chart === void 0 ? void 0 : chart.id}`).selectAll().data(data).join('path').attr('fill', d => d3.color(this.getFillColor(d))).attr('data-x', d => x(d.name)).attr('data-y', d => y(d.value)).attr('data-width', x.bandwidth()).attr('data-value', d => d.value).attr('id', (d, index) => d.slugId).attr('d', d => {
167
- // Do not draw if the range is smaller than the minimum
168
- if (!y_axis_auto_range && d.value <= y_axis_min) {
169
- return '';
170
- }
171
- const path = d3.path();
172
- const startX = x(d.name);
173
- const startY = y(d.value);
174
- path.moveTo(startX, startY + borderRadius);
175
- path.quadraticCurveTo(startX, startY, startX + borderRadius, startY);
176
- path.lineTo(startX + x.bandwidth() - borderRadius, startY);
177
- path.quadraticCurveTo(startX + x.bandwidth(), startY, startX + x.bandwidth(), startY + borderRadius);
178
- path.lineTo(startX + x.bandwidth(), y_axis_auto_range ? y(0) : y(y_axis_min));
179
- path.lineTo(startX, y_axis_auto_range ? y(0) : y(y_axis_min));
180
- path.closePath();
181
- return path.toString();
182
- }).call(g => {
183
- const parentNode = d3.select('.rects-wrapper');
184
- g.nodes().forEach(path => {
185
- // Add label
186
- if (y_axis_show_value) {
187
- parentNode.append('text').attr('y', Number(path.dataset.y) - 10).attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(path.dataset.value).call(g => {
188
- const {
189
- width
190
- } = g.node().getBoundingClientRect();
191
- g.attr('x', Number(path.dataset.x) + Number(path.dataset.width) / 2 - width);
192
- });
193
- }
194
- });
195
- }).on('click', (event, data) => {
196
- this.props.toggleRecords(data);
197
- }).on('mouseover', (event, data) => {
198
- this.showTooltip(event, data, tooltipTitle);
199
- this.setActiveAndInActiveState('inActive', data);
200
- }).on('mousemove', event => {
201
- this.moveTooltip(event);
202
- }).on('mouseleave', (event, data) => {
203
- this.hiddenTooltip();
204
- this.setActiveAndInActiveState('active', data);
205
- });
206
- if (display_goal_line) {
207
- this.chart.append('g').attr('class', 'annotation-wrapper').append('line').attr('stroke', '#aaa').attr('x1', insertPadding).attr('y1', y(goal_value)).attr('x2', chartWidth - insertPadding).attr('y2', y(goal_value)).call(g => {
208
- const parentNode = d3.select('.annotation-wrapper');
209
- parentNode.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', y(goal_value) - 10).attr('fill', '#666').text(goal_label);
210
- });
211
- }
212
- };
213
- this.chart = null;
214
- this.state = {
215
- tooltipData: null,
216
- toolTipPosition: null
217
- };
218
- }
219
- componentDidMount() {
220
- this.createChart();
221
- this.drawChart();
222
- this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
223
- window.addEventListener('resize', this.debouncedHandleResize);
224
- }
225
- componentDidUpdate(prevProps) {
226
- super.componentDidUpdate(prevProps);
227
- if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
228
- var _this$chart;
229
- ((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
230
- this.createChart();
231
- this.drawChart();
232
- }
233
- }
234
- componentWillUnmount() {
235
- this.chart.node() && this.chart.node().remove();
236
- window.removeEventListener('resize', this.debouncedHandleResize);
237
- }
238
- render() {
239
- const {
240
- tooltipData,
241
- toolTipPosition
242
- } = this.state;
243
- return /*#__PURE__*/_react.default.createElement("div", {
244
- className: "sea-chart-container",
245
- ref: ref => this.container = ref
246
- }, this.getToolTipContainer(tooltipData, toolTipPosition));
247
- }
248
- }
249
- Bar.propTypes = {
250
- canvasStyle: _propTypes.default.object,
251
- chart: _propTypes.default.object,
252
- groupbyColumn: _propTypes.default.object,
253
- columnGroupbyColumn: _propTypes.default.object,
254
- summaryColumn: _propTypes.default.object,
255
- result: _propTypes.default.array,
256
- tables: _propTypes.default.array,
257
- globalTheme: _propTypes.default.string,
258
- chartColorTheme: _propTypes.default.string,
259
- toggleRecords: _propTypes.default.func,
260
- customRender: _propTypes.default.func
261
- };
262
- var _default = exports.default = Bar;