sea-chart 2.0.9 → 2.0.11

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.
package/dist/api/index.js CHANGED
@@ -59,7 +59,7 @@ class SeaChartAPI {
59
59
  dtableUuid,
60
60
  accessToken
61
61
  } = _this;
62
- const url = dtableDB + 'api/v1/query/' + dtableUuid;
62
+ const url = dtableDB + '/api/v2/dtables/' + dtableUuid + '/sql/';
63
63
  const data = {
64
64
  sql,
65
65
  convert_keys,
@@ -69,7 +69,8 @@ const TypesDialog = _ref => {
69
69
  }, [onChange, selectedType, onToggle]);
70
70
  const handleFilterTypes = (0, _react.useCallback)(() => {
71
71
  if (hideTypeToggle) {
72
- const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram'].includes(item.name));
72
+ const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram', 'Bar_chart'].includes(item.name));
73
+ newChartTypes[1].children = newChartTypes[1].children.slice(0, 2);
73
74
  return newChartTypes;
74
75
  }
75
76
  return _constants.CHART_TYPES;
@@ -306,7 +306,7 @@ const BAR_MAP_TO_HORIZONTAL_MAP = exports.BAR_MAP_TO_HORIZONTAL_MAP = {
306
306
  y_axis_label_color: 'horizontal_axis_label_color',
307
307
  y_axis_auto_range: 'horizontal_axis_auto_range',
308
308
  y_axis_max: 'horizontal_axis_max',
309
- y_axis_mix: 'horizontal_axis_min'
309
+ y_axis_min: 'horizontal_axis_min'
310
310
  };
311
311
  const DEFAULT_NUMBER_FORMAT_OBJECT = exports.DEFAULT_NUMBER_FORMAT_OBJECT = {
312
312
  format: _dtableUtils.DEFAULT_NUMBER_FORMAT
@@ -324,6 +324,7 @@ class ChartDataSQL {
324
324
  const {
325
325
  x_axis_column_key,
326
326
  x_axis_geolocation_granularity,
327
+ x_axis_date_granularity,
327
328
  y_axis_summary_type,
328
329
  y_axis_summary_column_key,
329
330
  y_axis_summary_method,
@@ -339,7 +340,7 @@ class ChartDataSQL {
339
340
  }
340
341
  this._update_filter_sql(true, groupby_column);
341
342
  const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
342
- 'date_granularity': 'day',
343
+ 'date_granularity': x_axis_date_granularity,
343
344
  'geolocation_granularity': x_axis_geolocation_granularity
344
345
  });
345
346
  let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
@@ -9,6 +9,7 @@ exports.default = void 0;
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var d3 = _interopRequireWildcard(require("d3"));
12
+ var _classnames = _interopRequireDefault(require("classnames"));
12
13
  var _dtableUtils = require("dtable-utils");
13
14
  var _constants = require("../../constants");
14
15
  var _chartUtils = require("../../utils/chart-utils");
@@ -22,13 +23,17 @@ class BarCompare extends _chartComponent.default {
22
23
  const {
23
24
  chart
24
25
  } = this.props;
26
+ const {
27
+ y_axis_show_label,
28
+ x_axis_show_label
29
+ } = chart.config;
25
30
  const initConfig = {
26
31
  insertPadding: 30,
27
- borderRadius: 10,
28
- overflowHeight: 20 // Fillet the bottom corner beyond the axis and then cover it with a mask
32
+ borderRadius: 0.2,
33
+ marginLeft: y_axis_show_label ? 20 : 0,
34
+ marginBottom: x_axis_show_label ? 20 : 0
29
35
  };
30
36
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
31
- this.initDefs();
32
37
  };
33
38
  this.drawChart = () => {
34
39
  let {
@@ -43,31 +48,28 @@ class BarCompare extends _chartComponent.default {
43
48
  const {
44
49
  chart,
45
50
  globalTheme,
46
- chartColorTheme,
47
- canvasStyle
51
+ chartColorTheme
48
52
  } = this.props;
49
53
  const theme = _constants.CHART_THEME_COLOR[globalTheme];
50
- const {
51
- previewType
52
- } = canvasStyle || {};
53
54
  const {
54
55
  display_increase,
55
- y_axis_auto_range,
56
+ y_axis_auto_range = true,
56
57
  y_axis_min,
57
58
  y_axis_max
58
59
  } = chart.config;
59
60
  const {
60
61
  width: chartWidth,
61
62
  height: chartHeight,
62
- insertPadding,
63
- borderRadius,
64
- overflowHeight
63
+ insertPadding
65
64
  } = this.chartBoundingClientRect;
66
65
  data = data.sort((a, b) => d3.ascending(a.name, b.name));
67
- const fx = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
66
+ 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]);
67
+
68
+ // Y axis
69
+ 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));
70
+ const fx = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
68
71
  const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
69
72
  const x = d3.scaleBand().domain(d3.group(data, d => d.group_name).keys()).range([0, fx.bandwidth()]);
70
- 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]);
71
73
 
72
74
  // X axis
73
75
  this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
@@ -77,17 +79,8 @@ class BarCompare extends _chartComponent.default {
77
79
  g.selectAll('text').attr('fill', theme.textColor);
78
80
  });
79
81
 
80
- // Y axis
81
- this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
82
- g.select('.domain').remove();
83
- g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
84
- g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
85
- g.selectAll('text').attr('font-size', theme.fontSize);
86
- g.selectAll('text').attr('fill', theme.textColor);
87
- });
88
-
89
82
  // Rect group
90
- this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).attr('mask', "url(#mask-wrapper-".concat(previewType, "-").concat(chart === null || chart === void 0 ? void 0 : chart.id, ")")).selectAll().data(() => d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
83
+ this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).selectAll().data(() => d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
91
84
  let [name, dum] = _ref;
92
85
  // Each group is horizontally centered
93
86
  const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
@@ -97,7 +90,17 @@ class BarCompare extends _chartComponent.default {
97
90
  .selectAll().data(_ref2 => {
98
91
  let [a, d] = _ref2;
99
92
  return d;
100
- }).join('rect').attr('x', (d, index) => index * x.bandwidth()).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value) === 0 ? 0 : y(0) - y(d.value) + overflowHeight).attr('rx', borderRadius).attr('fill', d => color(d.group_name)).attr('data-value', d => d.value).attr('data-groupName', d => d.name).on('click', (event, data) => {
93
+ }).join('rect').attr('x', (d, index) => index * x.bandwidth()).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value) === 0 ? 0 : y(0) - y(d.value)).attr('fill', d => color(d.group_name)).attr('data-value', d => d.value).attr('data-groupName', d => d.name).attr('data-slugid', d => d.slugId).call(g => {
94
+ g.nodes().forEach(rect => {
95
+ const parentNode = rect.parentNode;
96
+ // add rect borderRadius
97
+ this.addClipPath({
98
+ rect,
99
+ parentNode,
100
+ rectId: rect.getAttribute('data-slugid')
101
+ });
102
+ });
103
+ }).on('click', (event, data) => {
101
104
  this.props.toggleRecords(data);
102
105
  }).on('mouseover', event => {
103
106
  this.showTooltip(event, color);
@@ -113,7 +116,12 @@ class BarCompare extends _chartComponent.default {
113
116
  this.drawIncreaseLine(increaseData);
114
117
  }
115
118
  this.setColorMap(data, chartColorTheme);
116
- this.setLegend('group_name', theme, 'top-right', data);
119
+ this.setLegend({
120
+ legendName: 'group_name',
121
+ theme,
122
+ legendPosition: 'top-right',
123
+ data
124
+ });
117
125
  };
118
126
  this.showTooltip = (event, colorScale, isCircle) => {
119
127
  const {
@@ -216,7 +224,6 @@ class BarCompare extends _chartComponent.default {
216
224
  wrapper.append('path').attr('fill', 'none').attr('stroke', increase_line_color || '#fbd44a').attr('stroke-width', 2).attr('d', () => line(increaseData));
217
225
 
218
226
  // circle
219
- console.log('wrapper', wrapper);
220
227
  circleData.forEach(item => {
221
228
  wrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', increase_line_color || '#fbd44a').attr('data-text', item.value).attr('data-name', item.name).call(g => {
222
229
  // circle label
@@ -297,13 +304,19 @@ class BarCompare extends _chartComponent.default {
297
304
  this.chart.node() && this.chart.node().remove();
298
305
  }
299
306
  render() {
307
+ const {
308
+ chart
309
+ } = this.props;
300
310
  const {
301
311
  tooltipData,
302
312
  toolTipPosition
303
313
  } = this.state;
304
314
  return /*#__PURE__*/_react.default.createElement("div", {
305
- className: "sea-chart-container",
306
- ref: ref => this.container = ref
315
+ ref: ref => this.container = ref,
316
+ className: (0, _classnames.default)('sea-chart-container', {
317
+ 'show-x-axis-label': this.isShowXAxisLabel(chart),
318
+ 'show-y-axis-label': this.isShowYAxisLabel(chart)
319
+ })
307
320
  }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
308
321
  tooltipData: tooltipData,
309
322
  toolTipPosition: toolTipPosition,
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var _lodashEs = require("lodash-es");
12
12
  var d3 = _interopRequireWildcard(require("d3"));
13
13
  var _slugid = _interopRequireDefault(require("slugid"));
14
+ var _classnames = _interopRequireDefault(require("classnames"));
14
15
  var _intl = _interopRequireDefault(require("../../intl"));
15
16
  var _chartUtils = require("../../utils/chart-utils");
16
17
  var _constants = require("../../constants");
@@ -28,9 +29,15 @@ class BarCustom extends _chartComponent.default {
28
29
  const {
29
30
  chart
30
31
  } = this.props;
32
+ const {
33
+ y_axis_show_label,
34
+ x_axis_show_label
35
+ } = chart.config;
31
36
  const initConfig = {
32
37
  insertPadding: 30,
33
- borderRadius: 5
38
+ borderRadius: 0.2,
39
+ marginLeft: y_axis_show_label ? 20 : 0,
40
+ marginBottom: x_axis_show_label ? 20 : 0
34
41
  };
35
42
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
36
43
  };
@@ -130,17 +137,19 @@ class BarCustom extends _chartComponent.default {
130
137
  const {
131
138
  width: chartWidth,
132
139
  height: chartHeight,
133
- insertPadding,
134
- borderRadius
140
+ insertPadding
135
141
  } = this.chartBoundingClientRect;
136
142
  const organizedData = this.organizeData(data);
137
143
  const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
138
- const fx = d3.scaleBand().domain(new Set(organizedData.map(d => d.name))).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
139
- const x = d3.scaleBand().domain(new Set(data.map(d => d.y_axis_type))).range([0, fx.bandwidth()]);
140
144
  const allSeries = this.getAllSeries(organizedData);
141
145
  const niceEnd = d3.nice(0, d3.max(allSeries, d => d[1]), 5)[1];
142
146
  const y = d3.scaleLinear().domain([0, niceEnd]).range([chartHeight - insertPadding, insertPadding]);
143
147
 
148
+ // Y axis
149
+ 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));
150
+ const fx = d3.scaleBand().domain(new Set(organizedData.map(d => d.name))).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
151
+ const x = d3.scaleBand().domain(new Set(data.map(d => d.y_axis_type))).range([0, fx.bandwidth()]);
152
+
144
153
  // X axis
145
154
  this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
146
155
  g.selectAll('.domain').attr('stroke', theme.XAxisColor);
@@ -149,35 +158,28 @@ class BarCustom extends _chartComponent.default {
149
158
  g.selectAll('text').attr('fill', theme.textColor);
150
159
  });
151
160
 
152
- // Y axis
153
- this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
154
- g.select('.domain').remove();
155
- g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
156
- g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
157
- g.selectAll('text').attr('font-size', theme.fontSize);
158
- g.selectAll('text').attr('fill', theme.textColor);
159
- });
160
-
161
161
  // Rect group
162
162
  this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).selectAll().data(organizedData).join('g').attr('transform', d => {
163
163
  const {
164
164
  name
165
165
  } = d;
166
166
  return "translate(".concat(fx(name), ",0)");
167
- }).selectAll().data(d => d.stacks).join('g').attr('class', 'stackGroup').attr('data-slugid', d => d.slugid).selectAll().data(d => d.series).join('rect').attr('class', 'stack').attr('data-isTop', (_, index, arr) => {
168
- return index === arr.length - 1;
169
- }).attr('x', d => x(d.stackKey)).attr('y', d => y(d[0][1])).attr('width', x.bandwidth()).attr('height', d => {
167
+ }).attr('data-transform', d => {
168
+ const {
169
+ name
170
+ } = d;
171
+ return fx(name);
172
+ }).selectAll().data(d => d.stacks).join('g').attr('class', 'stackGroup').attr('data-slugid', d => d.slugid).selectAll().data(d => d.series).join('rect').attr('class', 'stack').attr('x', d => x(d.stackKey)).attr('y', d => y(d[0][1])).attr('width', x.bandwidth()).attr('height', d => {
170
173
  const height = y(d[0][0]) - y(d[0][1]);
171
174
  return isNaN(height) ? 0 : height;
172
175
  }).attr('fill', d => color(d.key)).attr('data-value', d => d.stackData.value).attr('data-rectId', d => d.stackData.slugId).attr('data-groupName', d => d.stackData.group_name).attr('data-title', d => d.stackData.name).call(g => {
173
176
  // add rect borderRadius
174
177
  Array.from(g._parents).forEach(group => {
175
- const topRect = Array.from(group.children).find(rect => rect.getAttribute('data-isTop') === 'true');
176
- // use clipPath
177
- const clipRect = d3.select(topRect.cloneNode()).attr('rx', borderRadius).attr('height', Number(topRect.getAttribute('height')) + borderRadius);
178
- const clipPath = d3.select(group).append('clipPath').attr('id', group.getAttribute('data-slugid'));
179
- clipPath.node().appendChild(clipRect.node());
180
- d3.select(topRect).attr('clip-path', "url(#".concat(group.getAttribute('data-slugid'), ")"));
178
+ const topRect = Array.from(group.children).reverse().find(rect => Number(rect.getAttribute('height')) !== 0);
179
+ // Add mask rect
180
+ if (topRect) {
181
+ this.addMaskRect(group, topRect, x.bandwidth(), color);
182
+ }
181
183
  });
182
184
  if (display_each_block_data) {
183
185
  this.handleLabelToRectCenter(g, x.bandwidth());
@@ -196,7 +198,13 @@ class BarCustom extends _chartComponent.default {
196
198
  if (display_goal_line && goal_label && goal_value) {
197
199
  this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
198
200
  }
199
- this.setLegend('group_name', theme, 'top-right', data, color);
201
+ this.setLegend({
202
+ legendName: 'group_name',
203
+ theme,
204
+ legendPosition: 'top-right',
205
+ data,
206
+ colorScale: color
207
+ });
200
208
  };
201
209
  this.handleLabelToRectCenter = (g, xWidth) => {
202
210
  const {
@@ -207,20 +215,43 @@ class BarCustom extends _chartComponent.default {
207
215
  label_font_size
208
216
  } = chart.config;
209
217
  const theme = _constants.CHART_THEME_COLOR[globalTheme];
210
- const rects = g.nodes();
211
- rects.forEach(rect => {
212
- this.addLabelToRectCenter({
213
- container: rect.parentNode,
214
- x: Number(rect.getAttribute('x')),
215
- y: Number(rect.getAttribute('y')),
216
- xWidth,
217
- yheight: Number(rect.getAttribute('height')),
218
- theme,
219
- label_font_size,
220
- text: rect.getAttribute('data-value')
218
+ Array.from(g._parents).forEach(group => {
219
+ Array.from(group.children).forEach(rect => {
220
+ // The height is 0, and the label is not displayed.
221
+ if (Number(rect.getAttribute('height')) === 0) return;
222
+ this.addLabelToRectCenter({
223
+ container: rect.parentNode,
224
+ x: Number(rect.getAttribute('x')),
225
+ y: Number(rect.getAttribute('y')),
226
+ xWidth,
227
+ yheight: Number(rect.getAttribute('height')),
228
+ theme,
229
+ label_font_size,
230
+ text: rect.getAttribute('data-value')
231
+ });
221
232
  });
222
233
  });
223
234
  };
235
+ this.addMaskRect = (topG, rect, xWidth, colorScale) => {
236
+ const {
237
+ borderRadius
238
+ } = this.chartBoundingClientRect;
239
+ // Add mask rect
240
+ d3.select(topG).append('foreignObject').attr('class', 'stack-wrapper').attr('x', rect.getAttribute('x')).attr('data-x', topG.parentNode.getAttribute('data-transform')).attr('y', rect.getAttribute('y')).attr('width', xWidth).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-title', rect.getAttribute('data-title')).attr('data-rectId', rect.getAttribute('data-rectId')).on('click', (event, data) => {
241
+ this.props.toggleRecords(data);
242
+ }).on('mouseover', event => {
243
+ this.showTooltip(event, colorScale, true);
244
+ this.handleStacksAcitveAndInActiveState('inActive', event);
245
+ }).on('mousemove', event => {
246
+ this.moveTooltip(event, true);
247
+ }).on('mouseleave', (event, data) => {
248
+ this.hiddenTooltip();
249
+ this.handleStacksAcitveAndInActiveState('active', event);
250
+ }).append('xhtml:div').attr('class', 'stack').attr('data-rectId', rect.getAttribute('data-rectId')).attr('style', "width: 100%; height: 100%; background-color: ".concat(rect.getAttribute('fill'), "; border-radius: ").concat(xWidth * borderRadius, "px ").concat(xWidth * borderRadius, "px 0px 0px"));
251
+
252
+ // Remove old rect
253
+ d3.select(rect).remove();
254
+ };
224
255
  this.handleStacksAcitveAndInActiveState = (state, event) => {
225
256
  const rectsWrapper = event.currentTarget.parentNode.parentNode.parentNode;
226
257
  const allGroup = Array.from(rectsWrapper.children);
@@ -228,8 +259,10 @@ class BarCustom extends _chartComponent.default {
228
259
  allGroup.forEach(group => {
229
260
  Array.from(group.children).forEach(rectGroup => {
230
261
  Array.from(rectGroup.children).forEach(rect => {
231
- if (rect.getAttribute('class') === 'stack') {
232
- d3.select(rect).attr('opacity', 1);
262
+ const isDiv = rect.getAttribute('class') === 'stack-wrapper';
263
+ const curRect = isDiv ? rect.children[0] : rect;
264
+ if (curRect.getAttribute('class') === 'stack') {
265
+ isDiv ? curRect.style.opacity = 1 : d3.select(curRect).attr('opacity', 1);
233
266
  }
234
267
  });
235
268
  });
@@ -240,19 +273,27 @@ class BarCustom extends _chartComponent.default {
240
273
  allGroup.forEach(group => {
241
274
  Array.from(group.children).forEach(rectGroup => {
242
275
  Array.from(rectGroup.children).forEach(rect => {
243
- if (rect.getAttribute('class') === 'stack' && rect.getAttribute('data-rectId') !== curRectId) {
244
- d3.select(rect).attr('opacity', 0.3);
276
+ const isDiv = rect.getAttribute('class') === 'stack-wrapper';
277
+ const curRect = isDiv ? rect.children[0] : rect;
278
+ if (curRect.getAttribute('class') === 'stack' && curRect.getAttribute('data-rectId') !== curRectId) {
279
+ isDiv ? curRect.style.opacity = 0.3 : d3.select(curRect).attr('opacity', 0.3);
245
280
  }
246
281
  });
247
282
  });
248
283
  });
249
284
  }
250
285
  };
251
- this.showTooltip = (event, colorScale) => {
252
- const {
286
+ this.showTooltip = (event, colorScale, isDiv) => {
287
+ let {
253
288
  offsetX,
254
289
  offsetY
255
290
  } = event;
291
+ if (isDiv) {
292
+ const initX = Number(event.currentTarget.getAttribute('data-x'));
293
+ const initY = Number(event.currentTarget.getAttribute('y'));
294
+ offsetX = offsetX + initX;
295
+ offsetY = offsetY + initY;
296
+ }
256
297
  const title = event.currentTarget.getAttribute('data-title');
257
298
  const name = event.currentTarget.getAttribute('data-groupName');
258
299
  const value = event.currentTarget.getAttribute('data-value');
@@ -274,11 +315,17 @@ class BarCustom extends _chartComponent.default {
274
315
  }
275
316
  });
276
317
  };
277
- this.moveTooltip = event => {
278
- const {
318
+ this.moveTooltip = (event, isDiv) => {
319
+ let {
279
320
  offsetX,
280
321
  offsetY
281
322
  } = event;
323
+ if (isDiv) {
324
+ const initX = Number(event.currentTarget.getAttribute('data-x'));
325
+ const initY = Number(event.currentTarget.getAttribute('y'));
326
+ offsetX = offsetX + initX;
327
+ offsetY = offsetY + initY;
328
+ }
282
329
  this.setState({
283
330
  toolTipPosition: {
284
331
  offsetX,
@@ -315,13 +362,19 @@ class BarCustom extends _chartComponent.default {
315
362
  window.removeEventListener('resize', this.handleResize);
316
363
  }
317
364
  render() {
365
+ const {
366
+ chart
367
+ } = this.props;
318
368
  const {
319
369
  tooltipData,
320
370
  toolTipPosition
321
371
  } = this.state;
322
372
  return /*#__PURE__*/_react.default.createElement("div", {
323
- className: "sea-chart-container",
324
- ref: ref => this.container = ref
373
+ ref: ref => this.container = ref,
374
+ className: (0, _classnames.default)('sea-chart-container', {
375
+ 'show-x-axis-label': this.isShowXAxisLabel(chart),
376
+ 'show-y-axis-label': this.isShowYAxisLabel(chart)
377
+ })
325
378
  }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
326
379
  tooltipData: tooltipData,
327
380
  toolTipPosition: toolTipPosition,
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var _dtableUtils = require("dtable-utils");
12
12
  var _lodashEs = require("lodash-es");
13
13
  var d3 = _interopRequireWildcard(require("d3"));
14
+ var _classnames = _interopRequireDefault(require("classnames"));
14
15
  var _intl = _interopRequireDefault(require("../../intl"));
15
16
  var _columnUtils = require("../../utils/column-utils");
16
17
  var _constants = require("../../constants");
@@ -30,13 +31,21 @@ class BarGroup extends _chartComponent.default {
30
31
  const {
31
32
  chart
32
33
  } = this.props;
34
+ const {
35
+ y_axis_show_label,
36
+ x_axis_show_label,
37
+ y_axis_show_value,
38
+ display_each_block_data,
39
+ type
40
+ } = chart.config;
33
41
  const initConfig = {
34
42
  insertPadding: 30,
35
- borderRadius: 10,
36
- overflowHeight: 20 // Fillet the bottom corner beyond the axis and then cover it with a mask
43
+ borderRadius: 0.2,
44
+ marginLeft: y_axis_show_label ? 20 : 0,
45
+ marginBottom: x_axis_show_label ? 20 : 0,
46
+ marginTop: y_axis_show_value || type === _constants.CHART_TYPE.BAR_STACK && display_each_block_data ? 15 : 0
37
47
  };
38
48
  this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
39
- this.initDefs();
40
49
  };
41
50
  this.drawChart = () => {
42
51
  const {
@@ -66,23 +75,18 @@ class BarGroup extends _chartComponent.default {
66
75
  chart,
67
76
  globalTheme,
68
77
  chartColorTheme,
69
- tables,
70
- canvasStyle
78
+ tables
71
79
  } = this.props;
72
80
  const {
73
81
  display_goal_line,
74
82
  goal_value,
75
83
  goal_label
76
84
  } = chart.style_config || {};
77
- const {
78
- previewType
79
- } = canvasStyle || {};
80
85
  const {
81
86
  width: chartWidth,
82
87
  height: chartHeight,
83
88
  insertPadding,
84
- borderRadius,
85
- overflowHeight
89
+ marginTop
86
90
  } = this.chartBoundingClientRect;
87
91
  const {
88
92
  type,
@@ -101,9 +105,12 @@ class BarGroup extends _chartComponent.default {
101
105
  const useSingleSelectColumnColor = (column_groupby_column === null || column_groupby_column === void 0 ? void 0 : column_groupby_column.type) === _dtableUtils.CellType.SINGLE_SELECT && color_theme === _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
102
106
  useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme); // use single select column color
103
107
 
104
- const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1);
108
+ 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 + marginTop]);
109
+
110
+ // Y axis
111
+ 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));
112
+ const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1);
105
113
  const x = d3.scaleBand().domain(new Set(data.map(d => d.group_name))).range([0, fx.bandwidth()]);
106
- 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]);
107
114
 
108
115
  // X axis
109
116
  this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
@@ -113,17 +120,8 @@ class BarGroup extends _chartComponent.default {
113
120
  g.selectAll('text').attr('fill', theme.textColor);
114
121
  });
115
122
 
116
- // Y axis
117
- this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
118
- g.select('.domain').remove();
119
- g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
120
- g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
121
- g.selectAll('text').attr('font-size', theme.fontSize);
122
- g.selectAll('text').attr('fill', theme.textColor);
123
- });
124
-
125
123
  // Rect group
126
- this.chart.append('g').attr('mask', "url(#mask-wrapper-".concat(previewType, "-").concat(chart === null || chart === void 0 ? void 0 : chart.id, ")")).selectAll().data(d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
124
+ this.chart.append('g').selectAll().data(d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
127
125
  let [name, dum] = _ref;
128
126
  // Each group is horizontally centered
129
127
  const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
@@ -133,9 +131,16 @@ class BarGroup extends _chartComponent.default {
133
131
  .selectAll().data(_ref2 => {
134
132
  let [_, d] = _ref2;
135
133
  return d;
136
- }).join('rect').attr('x', (d, index) => index * x.bandwidth()).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value) + overflowHeight).attr('rx', borderRadius).attr('fill', d => this.colorMap[d.group_name] || _constants.CHART_STYLE_COLORS[0]).attr('data-value', d => d.value).attr('data-groupName', d => d.name).call(g => {
134
+ }).join('rect').attr('x', (d, index) => index * x.bandwidth()).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value)).attr('fill', d => this.colorMap[d.group_name] || _constants.CHART_STYLE_COLORS[0]).attr('data-value', d => d.value).attr('data-groupName', d => d.name).attr('data-slugid', d => d.slugId).call(g => {
137
135
  g.nodes().forEach(rect => {
138
136
  const parentNode = rect.parentNode;
137
+ // add rect borderRadius
138
+ this.addClipPath({
139
+ rect,
140
+ parentNode,
141
+ rectId: rect.getAttribute('data-slugid')
142
+ });
143
+
139
144
  // Add label
140
145
  if (type === _constants.CHART_TYPE.BAR_STACK) {
141
146
  if (y_axis_show_value) {
@@ -148,8 +153,7 @@ class BarGroup extends _chartComponent.default {
148
153
  yheight: Number(rect.getAttribute('height')),
149
154
  theme,
150
155
  label_font_size,
151
- text: rect.getAttribute('data-value'),
152
- overflowHeight
156
+ text: rect.getAttribute('data-value')
153
157
  });
154
158
  }
155
159
  if (display_each_block_data) {
@@ -191,7 +195,13 @@ class BarGroup extends _chartComponent.default {
191
195
  if (display_goal_line && goal_label && goal_value) {
192
196
  this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
193
197
  }
194
- this.setLegend('group_name', theme, 'top-right', data);
198
+ this.setLegend({
199
+ legendName: 'group_name',
200
+ theme,
201
+ legendPosition: 'top-right',
202
+ data,
203
+ groupColumn: this.props.columnGroupbyColumn
204
+ });
195
205
  };
196
206
  this.showTooltip = event => {
197
207
  const {
@@ -267,13 +277,19 @@ class BarGroup extends _chartComponent.default {
267
277
  window.removeEventListener('resize', this.debouncedHandleResize);
268
278
  }
269
279
  render() {
280
+ const {
281
+ chart
282
+ } = this.props;
270
283
  const {
271
284
  tooltipData,
272
285
  toolTipPosition
273
286
  } = this.state;
274
287
  return /*#__PURE__*/_react.default.createElement("div", {
275
- className: "sea-chart-container",
276
- ref: ref => this.container = ref
288
+ ref: ref => this.container = ref,
289
+ className: (0, _classnames.default)('sea-chart-container', {
290
+ 'show-x-axis-label': this.isShowXAxisLabel(chart),
291
+ 'show-y-axis-label': this.isShowYAxisLabel(chart)
292
+ })
277
293
  }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
278
294
  tooltipData: tooltipData,
279
295
  toolTipPosition: toolTipPosition,