sea-chart 2.0.14 → 2.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,371 @@
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 _classnames = _interopRequireDefault(require("classnames"));
14
+ var _constants = require("../../constants");
15
+ var _utils = require("../../utils");
16
+ var _intl = _interopRequireDefault(require("../../intl"));
17
+ var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
18
+ var _chartComponent = _interopRequireDefault(require("./chart-component"));
19
+ class Line extends _chartComponent.default {
20
+ constructor(props) {
21
+ super(props);
22
+ this.handleResize = () => {
23
+ this.chart.node() && this.chart.node().remove();
24
+ this.createChart();
25
+ this.drawChart();
26
+ };
27
+ this.createChart = () => {
28
+ const {
29
+ chart
30
+ } = this.props;
31
+ const {
32
+ y_axis_show_label,
33
+ x_axis_show_label,
34
+ y_axis_show_value
35
+ } = chart.config;
36
+ const initConfig = {
37
+ insertPadding: 30,
38
+ marginLeft: y_axis_show_label ? 20 : 0,
39
+ marginBottom: x_axis_show_label ? 20 : 0,
40
+ marginTop: y_axis_show_value ? 15 : 0
41
+ };
42
+ this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
43
+ };
44
+ this.drawChart = () => {
45
+ const {
46
+ customRender
47
+ } = this.props;
48
+ let {
49
+ result: data
50
+ } = this.props;
51
+ data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
52
+ if (!Array.isArray(data)) return;
53
+ this.draw(data);
54
+ this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
55
+ (0, _utils.isFunction)(customRender) && customRender(this.chart);
56
+ };
57
+ this.showTooltip = (event, data, title) => {
58
+ const {
59
+ offsetX,
60
+ offsetY
61
+ } = event;
62
+ const newTooltipData = {
63
+ title: title,
64
+ items: [{
65
+ color: this.getLineColor(),
66
+ name: data.name,
67
+ value: data.value
68
+ }]
69
+ };
70
+ this.setState({
71
+ tooltipData: newTooltipData
72
+ });
73
+ this.setState({
74
+ toolTipPosition: {
75
+ offsetX,
76
+ offsetY
77
+ }
78
+ });
79
+ };
80
+ this.moveTooltip = (event, data, title) => {
81
+ const {
82
+ offsetX,
83
+ offsetY
84
+ } = event;
85
+ const newTooltipData = {
86
+ title: title,
87
+ items: [{
88
+ color: this.getLineColor(),
89
+ name: data.name,
90
+ value: data.value
91
+ }]
92
+ };
93
+ this.setState({
94
+ tooltipData: newTooltipData
95
+ });
96
+ this.setState({
97
+ toolTipPosition: {
98
+ offsetX,
99
+ offsetY
100
+ }
101
+ });
102
+ };
103
+ this.hiddenTooltip = event => {
104
+ this.setState({
105
+ toolTipPosition: null
106
+ });
107
+ };
108
+ this.draw = data => {
109
+ const {
110
+ chart,
111
+ globalTheme,
112
+ tables
113
+ } = this.props;
114
+ const theme = _constants.CHART_THEME_COLOR[globalTheme];
115
+ const {
116
+ display_goal_line,
117
+ goal_value,
118
+ goal_label
119
+ } = chart.style_config || {};
120
+ const {
121
+ table_id,
122
+ y_axis_column_key,
123
+ y_axis_summary_column_key,
124
+ y_axis_show_value,
125
+ label_font_size,
126
+ line_type,
127
+ y_axis_summary_type,
128
+ y_axis_max,
129
+ y_axis_min,
130
+ y_axis_auto_range
131
+ } = chart.config;
132
+ const {
133
+ width: chartWidth,
134
+ height: chartHeight,
135
+ insertPadding,
136
+ marginTop
137
+ } = this.chartBoundingClientRect;
138
+ const chartBarColor = this.getLineColor();
139
+ const tooltipTitle = this.getTitle(tables, table_id, y_axis_summary_type, y_axis_column_key || y_axis_summary_column_key);
140
+
141
+ // Y axis
142
+ const niceEnd = d3.nice(0, d3.max(data, d => d.value), 5)[1];
143
+ const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min || 0, y_axis_max || niceEnd]).range([chartHeight - insertPadding, insertPadding + marginTop]);
144
+ this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
145
+
146
+ // X axis
147
+ const xDomain = data.map(item => item.name);
148
+ const x = d3.scaleBand().domain(xDomain).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
149
+ this.ticksWrapper = this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
150
+ this.ticksAddName(g);
151
+ g.selectAll('.domain').attr('stroke', theme.XAxisColor);
152
+ g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
153
+ g.selectAll('text').attr('font-size', theme.fontSize);
154
+ g.selectAll('text').attr('fill', theme.textColor);
155
+ this.checkTickOverlap(g);
156
+ });
157
+
158
+ // Line
159
+ const circleData = xDomain.map(() => ({}));
160
+ const line = d3.line().x((d, index) => {
161
+ const xVal = x(d.name) + x.bandwidth() / 2;
162
+ circleData[index]['x'] = xVal;
163
+ circleData[index]['name'] = d.name;
164
+ return xVal;
165
+ }).y((d, index) => {
166
+ const yVal = y(d.value);
167
+ circleData[index]['y'] = yVal;
168
+ circleData[index]['value'] = d.value;
169
+ return yVal;
170
+ }).curve(line_type === _constants.CHART_LINE_TYPES[1] ? d3.curveBumpX : d3.curveLinear);
171
+ const rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
172
+ rectsWrapper.append('path').attr('fill', 'none').attr('stroke', chartBarColor).attr('stroke-width', 2).attr('d', () => line(data));
173
+
174
+ // circle
175
+ circleData.forEach(item => {
176
+ rectsWrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', chartBarColor).attr('opacity', y_axis_show_value ? 1 : 0).attr('data-text', item.value).attr('data-name', item.name).call(g => {
177
+ // circle label
178
+ if (y_axis_show_value) {
179
+ const curCircleEl = g.node();
180
+ rectsWrapper.append('text').attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(curCircleEl.getAttribute('data-text')).call(g => {
181
+ const {
182
+ width
183
+ } = g.node().getBoundingClientRect();
184
+ const translateX = Number(curCircleEl.getAttribute('cx')) - width / 2;
185
+ const translateY = Number(curCircleEl.getAttribute('cy')) - 10;
186
+ g.attr('transform', "translate(".concat(translateX, ", ").concat(translateY, ")"));
187
+ });
188
+ }
189
+ }).on('click', (event, data) => {
190
+ this.props.toggleRecords(data);
191
+ });
192
+ });
193
+ this.chart.on('mouseover', event => {
194
+ this.updateCircleAndTickStyle({
195
+ event,
196
+ state: 'zoomIn',
197
+ circleData,
198
+ rectsWrapper,
199
+ eventState: 'over',
200
+ tooltipTitle
201
+ });
202
+ }).on('mousemove', event => {
203
+ this.updateCircleAndTickStyle({
204
+ event,
205
+ state: 'zoomIn',
206
+ circleData,
207
+ rectsWrapper,
208
+ eventState: 'move',
209
+ tooltipTitle
210
+ });
211
+ }).on('mouseleave', event => {
212
+ this.updateCircleAndTickStyle({
213
+ event,
214
+ state: 'zoomOut',
215
+ circleData,
216
+ rectsWrapper,
217
+ eventState: 'leave',
218
+ tooltipTitle
219
+ });
220
+ });
221
+ if (display_goal_line && goal_label && goal_value) {
222
+ this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
223
+ }
224
+ };
225
+ this.updateCircleAndTickStyle = _ref => {
226
+ var _rectsWrapper$selectA, _this$ticksWrapper$se;
227
+ let {
228
+ event,
229
+ state,
230
+ circleData,
231
+ rectsWrapper,
232
+ eventState,
233
+ tooltipTitle
234
+ } = _ref;
235
+ const {
236
+ y_axis_show_value
237
+ } = this.props.chart.config;
238
+ const {
239
+ height: chartHeight,
240
+ insertPadding,
241
+ marginTop
242
+ } = this.chartBoundingClientRect;
243
+ const {
244
+ offsetX
245
+ } = event;
246
+ const minDistanceItem = this.getMinDistanceItem(offsetX, circleData);
247
+ const circleList = (_rectsWrapper$selectA = rectsWrapper.selectAll('circle')) === null || _rectsWrapper$selectA === void 0 ? void 0 : _rectsWrapper$selectA.nodes();
248
+ if (circleList.length !== 0) {
249
+ if (state === 'zoomIn') {
250
+ circleList.forEach(circle => {
251
+ const name = circle.getAttribute('data-name');
252
+ if (name === minDistanceItem.name) {
253
+ d3.select(circle).attr('opacity', 1);
254
+ d3.select(circle).attr('r', 5);
255
+ } else {
256
+ d3.select(circle).attr('opacity', 0);
257
+ d3.select(circle).attr('r', 3);
258
+ }
259
+ });
260
+ } else {
261
+ circleList.forEach(circle => {
262
+ !y_axis_show_value && d3.select(circle).attr('opacity', 0);
263
+ d3.select(circle).attr('r', 3);
264
+ });
265
+ }
266
+ }
267
+ const ticks = (_this$ticksWrapper$se = this.ticksWrapper.selectAll('.tick line')) === null || _this$ticksWrapper$se === void 0 ? void 0 : _this$ticksWrapper$se.nodes();
268
+ if (ticks.length !== 0) {
269
+ if (state === 'zoomIn') {
270
+ ticks.forEach(tick => {
271
+ const name = tick.getAttribute('data-name');
272
+ if (name === minDistanceItem.name) {
273
+ d3.select(tick).attr('y2', -(chartHeight - insertPadding * 2 - marginTop));
274
+ } else {
275
+ d3.select(tick).attr('y2', 0);
276
+ }
277
+ });
278
+ } else {
279
+ ticks.forEach(tick => {
280
+ d3.select(tick).attr('y2', 0);
281
+ });
282
+ }
283
+ }
284
+
285
+ // tooltip
286
+ if (eventState === 'over') {
287
+ this.showTooltip(event, minDistanceItem, tooltipTitle);
288
+ }
289
+ if (eventState === 'move') {
290
+ this.moveTooltip(event, minDistanceItem, tooltipTitle);
291
+ }
292
+ if (eventState === 'leave') {
293
+ this.hiddenTooltip();
294
+ }
295
+ };
296
+ this.getLineColor = () => {
297
+ const {
298
+ chart,
299
+ chartColorTheme
300
+ } = this.props;
301
+ const {
302
+ y_axis_label_color,
303
+ color_option
304
+ } = chart.config;
305
+ let chartBarColor = _constants.CHART_STYLE_COLORS[0];
306
+ if (chartColorTheme) {
307
+ chartBarColor = _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors[0];
308
+ }
309
+ if (color_option === _constants.TYPE_COLOR_USING.USE_SPECIFIC_COLORS && y_axis_label_color) {
310
+ chartBarColor = y_axis_label_color;
311
+ }
312
+ return chartBarColor;
313
+ };
314
+ this.chart = null;
315
+ this.state = {
316
+ tooltipData: null,
317
+ toolTipPosition: null
318
+ };
319
+ }
320
+ componentDidMount() {
321
+ this.createChart();
322
+ this.drawChart();
323
+ this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
324
+ window.addEventListener('resize', this.debouncedHandleResize);
325
+ }
326
+ componentDidUpdate(prevProps) {
327
+ super.componentDidUpdate(prevProps);
328
+ if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
329
+ this.createChart();
330
+ this.drawChart();
331
+ }
332
+ }
333
+ componentWillUnmount() {
334
+ this.chart.node() && this.chart.node().remove();
335
+ window.removeEventListener('resize', this.debouncedHandleResize);
336
+ }
337
+ render() {
338
+ const {
339
+ chart
340
+ } = this.props;
341
+ const {
342
+ tooltipData,
343
+ toolTipPosition
344
+ } = this.state;
345
+ return /*#__PURE__*/_react.default.createElement("div", {
346
+ ref: ref => this.container = ref,
347
+ className: (0, _classnames.default)('sea-chart-container', {
348
+ 'show-x-axis-label': this.isShowXAxisLabel(chart),
349
+ 'show-y-axis-label': this.isShowYAxisLabel(chart)
350
+ })
351
+ }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
352
+ tooltipData: tooltipData,
353
+ toolTipPosition: toolTipPosition,
354
+ chart: this.chart
355
+ }));
356
+ }
357
+ }
358
+ Line.propTypes = {
359
+ canvasStyle: _propTypes.default.object,
360
+ chart: _propTypes.default.object,
361
+ groupbyColumn: _propTypes.default.object,
362
+ columnGroupbyColumn: _propTypes.default.object,
363
+ summaryColumn: _propTypes.default.object,
364
+ result: _propTypes.default.array,
365
+ tables: _propTypes.default.array,
366
+ globalTheme: _propTypes.default.string,
367
+ chartColorTheme: _propTypes.default.string,
368
+ toggleRecords: _propTypes.default.func,
369
+ customRender: _propTypes.default.func
370
+ };
371
+ var _default = exports.default = Line;
@@ -0,0 +1,275 @@
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 _intl = _interopRequireDefault(require("../../intl"));
16
+ var _colorRules = require("../../constants/color-rules");
17
+ var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
18
+ var _chartComponent = _interopRequireDefault(require("./chart-component"));
19
+ class Pie extends _chartComponent.default {
20
+ constructor(props) {
21
+ super(props);
22
+ this.createChart = () => {
23
+ const {
24
+ chart
25
+ } = this.props;
26
+ const {
27
+ show_legend
28
+ } = chart.config;
29
+ const initConfig = {
30
+ insertPadding: 30,
31
+ rightLegendSpace: show_legend ? 150 : 0
32
+ };
33
+ this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
34
+ };
35
+ this.handleResize = () => {
36
+ this.chart.node() && this.chart.node().remove();
37
+ this.createChart();
38
+ this.drawChart();
39
+ };
40
+ this.drawChart = () => {
41
+ const {
42
+ result: data,
43
+ customRender
44
+ } = this.props;
45
+ this.draw(data);
46
+ (0, _utils.isFunction)(customRender) && customRender(this.chart);
47
+ };
48
+ this.draw = data => {
49
+ const {
50
+ chart,
51
+ tables,
52
+ globalTheme,
53
+ chartColorTheme
54
+ } = this.props;
55
+ const theme = _constants.CHART_THEME_COLOR[globalTheme];
56
+ const {
57
+ show_legend,
58
+ display_label,
59
+ label_position,
60
+ label_font_size,
61
+ color_theme
62
+ } = chart.config;
63
+ const {
64
+ width: chartWidth,
65
+ height: chartHeight,
66
+ insertPadding,
67
+ rightLegendSpace
68
+ } = this.chartBoundingClientRect;
69
+ this.isInnerLabel = !label_position || label_position === _constants.CHART_LABEL_POSITIONS[0];
70
+ const currentTheme = _utils.BaseUtils.getCurrentTheme(chartColorTheme);
71
+ const useSingleSelectColumnColor = color_theme === _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
72
+ const {
73
+ data: newData,
74
+ colorMap
75
+ } = _utils.BaseUtils.formatPieChartData(data, chart, tables, currentTheme, useSingleSelectColumnColor);
76
+ if (!Array.isArray(newData) || newData.length === 0) return;
77
+
78
+ // Color
79
+ const colorDomain = new Set(data.map(d => d.name));
80
+ const colorRange = Array.from(colorDomain).map(name => colorMap[name === null || name === void 0 ? void 0 : name.trim()]);
81
+ const color = d3.scaleOrdinal().domain(colorDomain).range(colorRange);
82
+
83
+ // Pie and Arc
84
+ const pie = d3.pie().sort(null).value(d => d.value);
85
+ const arcs = pie(data);
86
+ const arc = d3.arc().innerRadius(Math.min(chartWidth, chartHeight) / 2 * 0.7 * 0.03).outerRadius(Math.min(chartWidth, chartHeight) / 2 * 0.7);
87
+
88
+ // Draw Pie
89
+ this.chart.append('g').attr('stroke', 'white').attr('stroke-width', 2).selectAll().data(arcs).join('path').attr('fill', d => color(d.data.name)).attr('d', arc).attr('data-groupName', d => d.data.name).call(g => {
90
+ var _g$node$parentNode;
91
+ const {
92
+ width,
93
+ height
94
+ } = (_g$node$parentNode = g.node().parentNode) === null || _g$node$parentNode === void 0 ? void 0 : _g$node$parentNode.getBoundingClientRect();
95
+ const left = width / 2 + insertPadding;
96
+ const top = height / 2 + insertPadding;
97
+ const offsetX = (chartWidth - (insertPadding + rightLegendSpace) - insertPadding - width) / 2;
98
+ const offsetY = (chartHeight - insertPadding - insertPadding - height) / 2;
99
+ d3.select(g.node().parentNode).attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")"));
100
+
101
+ // Draw label
102
+ if (display_label) {
103
+ const labelRadius = this.isInnerLabel ? arc.outerRadius()() * 0.7 : arc.outerRadius()() * 1.2;
104
+ const arcLabel = d3.arc().innerRadius(labelRadius).outerRadius(labelRadius);
105
+ this.chart.append('g').attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")")).attr('text-anchor', 'middle').selectAll().data(arcs).join('text').attr('transform', d => "translate(".concat(arcLabel.centroid(d), ")")).text(d => {
106
+ const {
107
+ value,
108
+ percent
109
+ } = d.data;
110
+ return this.getLabel(value, percent);
111
+ }).attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size));
112
+
113
+ // Line
114
+ if (!this.isInnerLabel) {
115
+ const lineRadius = arc.outerRadius()() * 0.5;
116
+ const arcLine = d3.arc().innerRadius(lineRadius).outerRadius(lineRadius);
117
+ this.chart.append('g').attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")")).selectAll().data(arcs).join('line').attr('transform', d => "translate(".concat(arcLine.centroid(d), ")")).attr('x1', d => arcLine.centroid(d)[0]).attr('y1', d => arcLine.centroid(d)[1]).attr('x2', d => arcLine.centroid(d)[0] * 1.2).attr('y2', d => arcLine.centroid(d)[1] * 1.2).attr('stroke', d => color(d.data.name)).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size));
118
+ }
119
+ }
120
+ }).on('click', (event, rowData) => {
121
+ this.props.toggleRecords(rowData.data);
122
+ }).on('mouseover', (event, rowData) => {
123
+ this.showTooltip(event, rowData.data, color);
124
+ this.handleAcitveAndInActiveState('inActive', event);
125
+ }).on('mousemove', event => {
126
+ this.moveTooltip(event);
127
+ }).on('mouseleave', (event, data) => {
128
+ this.hiddenTooltip();
129
+ this.handleAcitveAndInActiveState('active', event);
130
+ });
131
+ if (show_legend) {
132
+ this.setLegend({
133
+ legendName: 'name',
134
+ theme,
135
+ legendPosition: 'center-right',
136
+ data,
137
+ colorScale: color
138
+ });
139
+ }
140
+ };
141
+ this.showTooltip = (event, data, colorScale) => {
142
+ const {
143
+ offsetX,
144
+ offsetY
145
+ } = event;
146
+ const {
147
+ value,
148
+ percent
149
+ } = data;
150
+ const newTooltipData = {
151
+ title: false,
152
+ items: [{
153
+ color: colorScale(data.name),
154
+ name: this.getTooltipName(data.name),
155
+ value: this.getLabel(value, percent)
156
+ }]
157
+ };
158
+ this.setState({
159
+ tooltipData: newTooltipData
160
+ });
161
+ this.setState({
162
+ toolTipPosition: {
163
+ offsetX,
164
+ offsetY
165
+ }
166
+ });
167
+ };
168
+ this.moveTooltip = event => {
169
+ const {
170
+ offsetX,
171
+ offsetY
172
+ } = event;
173
+ this.setState({
174
+ toolTipPosition: {
175
+ offsetX,
176
+ offsetY
177
+ }
178
+ });
179
+ };
180
+ this.hiddenTooltip = event => {
181
+ this.setState({
182
+ toolTipPosition: null
183
+ });
184
+ };
185
+ this.handleAcitveAndInActiveState = (state, event) => {
186
+ const allGroup = [event.currentTarget.parentNode];
187
+ const curGroupName = event.currentTarget.getAttribute('data-groupName');
188
+ this.setActiveAndInActiveState(state, allGroup, curGroupName);
189
+ };
190
+ this.getLabel = (val, percent) => {
191
+ const {
192
+ chart,
193
+ summaryColumn
194
+ } = this.props;
195
+ const {
196
+ summary_method,
197
+ display_label,
198
+ label_format
199
+ } = chart.config;
200
+ const value = _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, val, summary_method);
201
+ if (!display_label || !value || !percent) {
202
+ return '';
203
+ }
204
+ switch (label_format) {
205
+ case _constants.CHART_LABEL_FORMATS[0]:
206
+ return percent;
207
+ case _constants.CHART_LABEL_FORMATS[1]:
208
+ return value;
209
+ case _constants.CHART_LABEL_FORMATS[2]:
210
+ return "".concat(value, " (").concat(percent, ")");
211
+ default:
212
+ return percent;
213
+ }
214
+ };
215
+ this.getTooltipName = name => {
216
+ let title = name;
217
+ if (!name || name.trim() === 'undefined' || name.trim() === 'null') {
218
+ title = _intl.default.get('Empty');
219
+ } else if (name === '_Others') {
220
+ title = _intl.default.get('Others');
221
+ }
222
+ return title;
223
+ };
224
+ this.chart = null;
225
+ this.state = {
226
+ tooltipData: null,
227
+ toolTipPosition: null
228
+ };
229
+ }
230
+ componentDidMount() {
231
+ this.createChart();
232
+ this.drawChart();
233
+ this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
234
+ window.addEventListener('resize', this.debouncedHandleResize);
235
+ }
236
+ componentDidUpdate(prevProps) {
237
+ super.componentDidUpdate(prevProps);
238
+ if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
239
+ this.chart.node() && this.chart.node().remove();
240
+ this.createChart();
241
+ this.drawChart();
242
+ }
243
+ }
244
+ componentWillUnmount() {
245
+ this.chart.node() && this.chart.node().remove();
246
+ window.removeEventListener('resize', this.debouncedHandleResize);
247
+ }
248
+ render() {
249
+ const {
250
+ tooltipData,
251
+ toolTipPosition
252
+ } = this.state;
253
+ return /*#__PURE__*/_react.default.createElement("div", {
254
+ ref: ref => this.container = ref,
255
+ className: "sea-chart-container"
256
+ }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
257
+ tooltipData: tooltipData,
258
+ toolTipPosition: toolTipPosition,
259
+ chart: this.chart
260
+ }));
261
+ }
262
+ }
263
+ Pie.propTypes = {
264
+ canvasStyle: _propTypes.default.object,
265
+ chart: _propTypes.default.object,
266
+ groupbyColumn: _propTypes.default.object,
267
+ summaryColumn: _propTypes.default.object,
268
+ result: _propTypes.default.array,
269
+ tables: _propTypes.default.array,
270
+ globalTheme: _propTypes.default.string,
271
+ chartColorTheme: _propTypes.default.string,
272
+ toggleRecords: _propTypes.default.func,
273
+ customRender: _propTypes.default.func
274
+ };
275
+ var _default = exports.default = Pie;