sea-chart 2.0.9 → 2.0.10
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/components/types-dialog/index.js +2 -1
- package/dist/constants/index.js +1 -1
- package/dist/view/wrapper/bar-compare.js +36 -17
- package/dist/view/wrapper/bar-custom-stack.js +89 -30
- package/dist/view/wrapper/bar-group.js +40 -18
- package/dist/view/wrapper/bar-stack.js +31 -8
- package/dist/view/wrapper/bar.js +28 -23
- package/dist/view/wrapper/chart-component.js +420 -87
- package/dist/view/wrapper/horizontal-bar-group.js +282 -0
- package/dist/view/wrapper/horizontal-bar.js +266 -0
- package/dist/view/wrapper/index.js +27 -0
- package/package.json +1 -1
|
@@ -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;
|
package/dist/constants/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
@@ -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:
|
|
28
|
-
|
|
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,13 +48,9 @@ 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
56
|
y_axis_auto_range,
|
|
@@ -59,9 +60,7 @@ class BarCompare extends _chartComponent.default {
|
|
|
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
66
|
const fx = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
@@ -87,7 +86,7 @@ class BarCompare extends _chartComponent.default {
|
|
|
87
86
|
});
|
|
88
87
|
|
|
89
88
|
// Rect group
|
|
90
|
-
this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).
|
|
89
|
+
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
90
|
let [name, dum] = _ref;
|
|
92
91
|
// Each group is horizontally centered
|
|
93
92
|
const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
|
|
@@ -97,7 +96,17 @@ class BarCompare extends _chartComponent.default {
|
|
|
97
96
|
.selectAll().data(_ref2 => {
|
|
98
97
|
let [a, d] = _ref2;
|
|
99
98
|
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)
|
|
99
|
+
}).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 => {
|
|
100
|
+
g.nodes().forEach(rect => {
|
|
101
|
+
const parentNode = rect.parentNode;
|
|
102
|
+
// add rect borderRadius
|
|
103
|
+
this.addClipPath({
|
|
104
|
+
rect,
|
|
105
|
+
parentNode,
|
|
106
|
+
rectId: rect.getAttribute('data-slugid')
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}).on('click', (event, data) => {
|
|
101
110
|
this.props.toggleRecords(data);
|
|
102
111
|
}).on('mouseover', event => {
|
|
103
112
|
this.showTooltip(event, color);
|
|
@@ -113,7 +122,12 @@ class BarCompare extends _chartComponent.default {
|
|
|
113
122
|
this.drawIncreaseLine(increaseData);
|
|
114
123
|
}
|
|
115
124
|
this.setColorMap(data, chartColorTheme);
|
|
116
|
-
this.setLegend(
|
|
125
|
+
this.setLegend({
|
|
126
|
+
legendName: 'group_name',
|
|
127
|
+
theme,
|
|
128
|
+
legendPosition: 'top-right',
|
|
129
|
+
data
|
|
130
|
+
});
|
|
117
131
|
};
|
|
118
132
|
this.showTooltip = (event, colorScale, isCircle) => {
|
|
119
133
|
const {
|
|
@@ -216,7 +230,6 @@ class BarCompare extends _chartComponent.default {
|
|
|
216
230
|
wrapper.append('path').attr('fill', 'none').attr('stroke', increase_line_color || '#fbd44a').attr('stroke-width', 2).attr('d', () => line(increaseData));
|
|
217
231
|
|
|
218
232
|
// circle
|
|
219
|
-
console.log('wrapper', wrapper);
|
|
220
233
|
circleData.forEach(item => {
|
|
221
234
|
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
235
|
// circle label
|
|
@@ -297,13 +310,19 @@ class BarCompare extends _chartComponent.default {
|
|
|
297
310
|
this.chart.node() && this.chart.node().remove();
|
|
298
311
|
}
|
|
299
312
|
render() {
|
|
313
|
+
const {
|
|
314
|
+
chart
|
|
315
|
+
} = this.props;
|
|
300
316
|
const {
|
|
301
317
|
tooltipData,
|
|
302
318
|
toolTipPosition
|
|
303
319
|
} = this.state;
|
|
304
320
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
305
|
-
|
|
306
|
-
|
|
321
|
+
ref: ref => this.container = ref,
|
|
322
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
323
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
324
|
+
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
325
|
+
})
|
|
307
326
|
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
308
327
|
tooltipData: tooltipData,
|
|
309
328
|
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:
|
|
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,8 +137,7 @@ 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');
|
|
@@ -164,6 +170,11 @@ class BarCustom extends _chartComponent.default {
|
|
|
164
170
|
name
|
|
165
171
|
} = d;
|
|
166
172
|
return "translate(".concat(fx(name), ",0)");
|
|
173
|
+
}).attr('data-transform', d => {
|
|
174
|
+
const {
|
|
175
|
+
name
|
|
176
|
+
} = d;
|
|
177
|
+
return fx(name);
|
|
167
178
|
}).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
179
|
return index === arr.length - 1;
|
|
169
180
|
}).attr('x', d => x(d.stackKey)).attr('y', d => y(d[0][1])).attr('width', x.bandwidth()).attr('height', d => {
|
|
@@ -173,11 +184,10 @@ class BarCustom extends _chartComponent.default {
|
|
|
173
184
|
// add rect borderRadius
|
|
174
185
|
Array.from(g._parents).forEach(group => {
|
|
175
186
|
const topRect = Array.from(group.children).find(rect => rect.getAttribute('data-isTop') === 'true');
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
d3.select(topRect).attr('clip-path', "url(#".concat(group.getAttribute('data-slugid'), ")"));
|
|
187
|
+
// Add mask rect
|
|
188
|
+
if (topRect) {
|
|
189
|
+
this.addMaskRect(group, topRect, x.bandwidth(), color);
|
|
190
|
+
}
|
|
181
191
|
});
|
|
182
192
|
if (display_each_block_data) {
|
|
183
193
|
this.handleLabelToRectCenter(g, x.bandwidth());
|
|
@@ -196,7 +206,13 @@ class BarCustom extends _chartComponent.default {
|
|
|
196
206
|
if (display_goal_line && goal_label && goal_value) {
|
|
197
207
|
this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
|
|
198
208
|
}
|
|
199
|
-
this.setLegend(
|
|
209
|
+
this.setLegend({
|
|
210
|
+
legendName: 'group_name',
|
|
211
|
+
theme,
|
|
212
|
+
legendPosition: 'top-right',
|
|
213
|
+
data,
|
|
214
|
+
colorScale: color
|
|
215
|
+
});
|
|
200
216
|
};
|
|
201
217
|
this.handleLabelToRectCenter = (g, xWidth) => {
|
|
202
218
|
const {
|
|
@@ -207,20 +223,41 @@ class BarCustom extends _chartComponent.default {
|
|
|
207
223
|
label_font_size
|
|
208
224
|
} = chart.config;
|
|
209
225
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
Array.from(g._parents).forEach(group => {
|
|
227
|
+
Array.from(group.children).forEach(rect => {
|
|
228
|
+
this.addLabelToRectCenter({
|
|
229
|
+
container: rect.parentNode,
|
|
230
|
+
x: Number(rect.getAttribute('x')),
|
|
231
|
+
y: Number(rect.getAttribute('y')),
|
|
232
|
+
xWidth,
|
|
233
|
+
yheight: Number(rect.getAttribute('height')),
|
|
234
|
+
theme,
|
|
235
|
+
label_font_size,
|
|
236
|
+
text: rect.getAttribute('data-value')
|
|
237
|
+
});
|
|
221
238
|
});
|
|
222
239
|
});
|
|
223
240
|
};
|
|
241
|
+
this.addMaskRect = (topG, rect, xWidth, colorScale) => {
|
|
242
|
+
const {
|
|
243
|
+
borderRadius
|
|
244
|
+
} = this.chartBoundingClientRect;
|
|
245
|
+
// Add mask rect
|
|
246
|
+
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) => {
|
|
247
|
+
this.props.toggleRecords(data);
|
|
248
|
+
}).on('mouseover', event => {
|
|
249
|
+
this.showTooltip(event, colorScale, true);
|
|
250
|
+
this.handleStacksAcitveAndInActiveState('inActive', event);
|
|
251
|
+
}).on('mousemove', event => {
|
|
252
|
+
this.moveTooltip(event, true);
|
|
253
|
+
}).on('mouseleave', (event, data) => {
|
|
254
|
+
this.hiddenTooltip();
|
|
255
|
+
this.handleStacksAcitveAndInActiveState('active', event);
|
|
256
|
+
}).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"));
|
|
257
|
+
|
|
258
|
+
// Remove old rect
|
|
259
|
+
d3.select(rect).remove();
|
|
260
|
+
};
|
|
224
261
|
this.handleStacksAcitveAndInActiveState = (state, event) => {
|
|
225
262
|
const rectsWrapper = event.currentTarget.parentNode.parentNode.parentNode;
|
|
226
263
|
const allGroup = Array.from(rectsWrapper.children);
|
|
@@ -228,8 +265,10 @@ class BarCustom extends _chartComponent.default {
|
|
|
228
265
|
allGroup.forEach(group => {
|
|
229
266
|
Array.from(group.children).forEach(rectGroup => {
|
|
230
267
|
Array.from(rectGroup.children).forEach(rect => {
|
|
231
|
-
|
|
232
|
-
|
|
268
|
+
const isDiv = rect.getAttribute('class') === 'stack-wrapper';
|
|
269
|
+
const curRect = isDiv ? rect.children[0] : rect;
|
|
270
|
+
if (curRect.getAttribute('class') === 'stack') {
|
|
271
|
+
isDiv ? curRect.style.opacity = 1 : d3.select(curRect).attr('opacity', 1);
|
|
233
272
|
}
|
|
234
273
|
});
|
|
235
274
|
});
|
|
@@ -240,19 +279,27 @@ class BarCustom extends _chartComponent.default {
|
|
|
240
279
|
allGroup.forEach(group => {
|
|
241
280
|
Array.from(group.children).forEach(rectGroup => {
|
|
242
281
|
Array.from(rectGroup.children).forEach(rect => {
|
|
243
|
-
|
|
244
|
-
|
|
282
|
+
const isDiv = rect.getAttribute('class') === 'stack-wrapper';
|
|
283
|
+
const curRect = isDiv ? rect.children[0] : rect;
|
|
284
|
+
if (curRect.getAttribute('class') === 'stack' && curRect.getAttribute('data-rectId') !== curRectId) {
|
|
285
|
+
isDiv ? curRect.style.opacity = 0.3 : d3.select(curRect).attr('opacity', 0.3);
|
|
245
286
|
}
|
|
246
287
|
});
|
|
247
288
|
});
|
|
248
289
|
});
|
|
249
290
|
}
|
|
250
291
|
};
|
|
251
|
-
this.showTooltip = (event, colorScale) => {
|
|
252
|
-
|
|
292
|
+
this.showTooltip = (event, colorScale, isDiv) => {
|
|
293
|
+
let {
|
|
253
294
|
offsetX,
|
|
254
295
|
offsetY
|
|
255
296
|
} = event;
|
|
297
|
+
if (isDiv) {
|
|
298
|
+
const initX = Number(event.currentTarget.getAttribute('data-x'));
|
|
299
|
+
const initY = Number(event.currentTarget.getAttribute('y'));
|
|
300
|
+
offsetX = offsetX + initX;
|
|
301
|
+
offsetY = offsetY + initY;
|
|
302
|
+
}
|
|
256
303
|
const title = event.currentTarget.getAttribute('data-title');
|
|
257
304
|
const name = event.currentTarget.getAttribute('data-groupName');
|
|
258
305
|
const value = event.currentTarget.getAttribute('data-value');
|
|
@@ -274,11 +321,17 @@ class BarCustom extends _chartComponent.default {
|
|
|
274
321
|
}
|
|
275
322
|
});
|
|
276
323
|
};
|
|
277
|
-
this.moveTooltip = event => {
|
|
278
|
-
|
|
324
|
+
this.moveTooltip = (event, isDiv) => {
|
|
325
|
+
let {
|
|
279
326
|
offsetX,
|
|
280
327
|
offsetY
|
|
281
328
|
} = event;
|
|
329
|
+
if (isDiv) {
|
|
330
|
+
const initX = Number(event.currentTarget.getAttribute('data-x'));
|
|
331
|
+
const initY = Number(event.currentTarget.getAttribute('y'));
|
|
332
|
+
offsetX = offsetX + initX;
|
|
333
|
+
offsetY = offsetY + initY;
|
|
334
|
+
}
|
|
282
335
|
this.setState({
|
|
283
336
|
toolTipPosition: {
|
|
284
337
|
offsetX,
|
|
@@ -315,13 +368,19 @@ class BarCustom extends _chartComponent.default {
|
|
|
315
368
|
window.removeEventListener('resize', this.handleResize);
|
|
316
369
|
}
|
|
317
370
|
render() {
|
|
371
|
+
const {
|
|
372
|
+
chart
|
|
373
|
+
} = this.props;
|
|
318
374
|
const {
|
|
319
375
|
tooltipData,
|
|
320
376
|
toolTipPosition
|
|
321
377
|
} = this.state;
|
|
322
378
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
323
|
-
|
|
324
|
-
|
|
379
|
+
ref: ref => this.container = ref,
|
|
380
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
381
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
382
|
+
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
383
|
+
})
|
|
325
384
|
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
326
385
|
tooltipData: tooltipData,
|
|
327
386
|
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:
|
|
36
|
-
|
|
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
|
-
|
|
85
|
-
overflowHeight
|
|
89
|
+
marginTop
|
|
86
90
|
} = this.chartBoundingClientRect;
|
|
87
91
|
const {
|
|
88
92
|
type,
|
|
@@ -103,7 +107,7 @@ class BarGroup extends _chartComponent.default {
|
|
|
103
107
|
|
|
104
108
|
const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1);
|
|
105
109
|
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]);
|
|
110
|
+
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]);
|
|
107
111
|
|
|
108
112
|
// X axis
|
|
109
113
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
@@ -123,7 +127,7 @@ class BarGroup extends _chartComponent.default {
|
|
|
123
127
|
});
|
|
124
128
|
|
|
125
129
|
// Rect group
|
|
126
|
-
this.chart.append('g').
|
|
130
|
+
this.chart.append('g').selectAll().data(d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
|
|
127
131
|
let [name, dum] = _ref;
|
|
128
132
|
// Each group is horizontally centered
|
|
129
133
|
const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
|
|
@@ -133,9 +137,16 @@ class BarGroup extends _chartComponent.default {
|
|
|
133
137
|
.selectAll().data(_ref2 => {
|
|
134
138
|
let [_, d] = _ref2;
|
|
135
139
|
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)
|
|
140
|
+
}).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
141
|
g.nodes().forEach(rect => {
|
|
138
142
|
const parentNode = rect.parentNode;
|
|
143
|
+
// add rect borderRadius
|
|
144
|
+
this.addClipPath({
|
|
145
|
+
rect,
|
|
146
|
+
parentNode,
|
|
147
|
+
rectId: rect.getAttribute('data-slugid')
|
|
148
|
+
});
|
|
149
|
+
|
|
139
150
|
// Add label
|
|
140
151
|
if (type === _constants.CHART_TYPE.BAR_STACK) {
|
|
141
152
|
if (y_axis_show_value) {
|
|
@@ -148,8 +159,7 @@ class BarGroup extends _chartComponent.default {
|
|
|
148
159
|
yheight: Number(rect.getAttribute('height')),
|
|
149
160
|
theme,
|
|
150
161
|
label_font_size,
|
|
151
|
-
text: rect.getAttribute('data-value')
|
|
152
|
-
overflowHeight
|
|
162
|
+
text: rect.getAttribute('data-value')
|
|
153
163
|
});
|
|
154
164
|
}
|
|
155
165
|
if (display_each_block_data) {
|
|
@@ -191,7 +201,13 @@ class BarGroup extends _chartComponent.default {
|
|
|
191
201
|
if (display_goal_line && goal_label && goal_value) {
|
|
192
202
|
this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
|
|
193
203
|
}
|
|
194
|
-
this.setLegend(
|
|
204
|
+
this.setLegend({
|
|
205
|
+
legendName: 'group_name',
|
|
206
|
+
theme,
|
|
207
|
+
legendPosition: 'top-right',
|
|
208
|
+
data,
|
|
209
|
+
groupColumn: this.props.columnGroupbyColumn
|
|
210
|
+
});
|
|
195
211
|
};
|
|
196
212
|
this.showTooltip = event => {
|
|
197
213
|
const {
|
|
@@ -267,13 +283,19 @@ class BarGroup extends _chartComponent.default {
|
|
|
267
283
|
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
268
284
|
}
|
|
269
285
|
render() {
|
|
286
|
+
const {
|
|
287
|
+
chart
|
|
288
|
+
} = this.props;
|
|
270
289
|
const {
|
|
271
290
|
tooltipData,
|
|
272
291
|
toolTipPosition
|
|
273
292
|
} = this.state;
|
|
274
293
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
275
|
-
|
|
276
|
-
|
|
294
|
+
ref: ref => this.container = ref,
|
|
295
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
296
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
297
|
+
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
298
|
+
})
|
|
277
299
|
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
278
300
|
tooltipData: tooltipData,
|
|
279
301
|
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,9 +31,17 @@ class BarStack 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
|
+
display_each_block_data
|
|
38
|
+
} = chart.config;
|
|
33
39
|
const initConfig = {
|
|
34
40
|
insertPadding: 30,
|
|
35
|
-
borderRadius:
|
|
41
|
+
borderRadius: 0.2,
|
|
42
|
+
marginLeft: y_axis_show_label ? 20 : 0,
|
|
43
|
+
marginBottom: x_axis_show_label ? 20 : 0,
|
|
44
|
+
marginTop: display_each_block_data ? 15 : 0
|
|
36
45
|
};
|
|
37
46
|
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
38
47
|
};
|
|
@@ -89,7 +98,8 @@ class BarStack extends _chartComponent.default {
|
|
|
89
98
|
const {
|
|
90
99
|
width: chartWidth,
|
|
91
100
|
height: chartHeight,
|
|
92
|
-
insertPadding
|
|
101
|
+
insertPadding,
|
|
102
|
+
marginTop
|
|
93
103
|
} = this.chartBoundingClientRect;
|
|
94
104
|
const series = d3.stack().keys(d3.union(data.map(d => d.group_name))).value((_ref, key) => {
|
|
95
105
|
var _group$get;
|
|
@@ -98,7 +108,7 @@ class BarStack extends _chartComponent.default {
|
|
|
98
108
|
})(d3.index(data, d => d.name, d => d.group_name));
|
|
99
109
|
const x = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
100
110
|
const niceEnd = d3.nice(0, d3.max(series, d => d3.max(d, d => d[1])), 5)[1];
|
|
101
|
-
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
|
|
111
|
+
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
102
112
|
|
|
103
113
|
// X axis
|
|
104
114
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
@@ -168,7 +178,13 @@ class BarStack extends _chartComponent.default {
|
|
|
168
178
|
if (display_goal_line && goal_label && goal_value) {
|
|
169
179
|
this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
|
|
170
180
|
}
|
|
171
|
-
this.setLegend(
|
|
181
|
+
this.setLegend({
|
|
182
|
+
legendName: 'group_name',
|
|
183
|
+
theme,
|
|
184
|
+
legendPosition: 'top-right',
|
|
185
|
+
data,
|
|
186
|
+
groupColumn: this.props.columnGroupbyColumn
|
|
187
|
+
});
|
|
172
188
|
};
|
|
173
189
|
this.showTooltip = event => {
|
|
174
190
|
const offsetX = d3.pointer(event)[0];
|
|
@@ -229,7 +245,7 @@ class BarStack extends _chartComponent.default {
|
|
|
229
245
|
}).on('mouseleave', (event, data) => {
|
|
230
246
|
this.hiddenTooltip();
|
|
231
247
|
this.handleAcitveAndInActiveState('active', event);
|
|
232
|
-
}).append('xhtml:div').attr('style', "width: 100%; height: 100%; background-color: ".concat(rect.getAttribute('fill'), "; border-radius: ").concat(borderRadius, "px ").concat(borderRadius, "px 0px 0px"));
|
|
248
|
+
}).append('xhtml:div').attr('style', "width: 100%; height: 100%; background-color: ".concat(rect.getAttribute('fill'), "; border-radius: ").concat(xWidth * borderRadius, "px ").concat(xWidth * borderRadius, "px 0px 0px"));
|
|
233
249
|
|
|
234
250
|
// Remove old rect
|
|
235
251
|
d3.select(rect).remove();
|
|
@@ -245,7 +261,8 @@ class BarStack extends _chartComponent.default {
|
|
|
245
261
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
246
262
|
const groupData = d3.group(data, d => d.name);
|
|
247
263
|
const group_name = rect.getAttribute('data-groupName');
|
|
248
|
-
|
|
264
|
+
let stackSum = 0;
|
|
265
|
+
groupData.get(group_name).forEach(n => stackSum += n.value);
|
|
249
266
|
this.addLabelToRectTop({
|
|
250
267
|
container: topG,
|
|
251
268
|
xWidth: Number(x.bandwidth()),
|
|
@@ -304,13 +321,19 @@ class BarStack extends _chartComponent.default {
|
|
|
304
321
|
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
305
322
|
}
|
|
306
323
|
render() {
|
|
324
|
+
const {
|
|
325
|
+
chart
|
|
326
|
+
} = this.props;
|
|
307
327
|
const {
|
|
308
328
|
tooltipData,
|
|
309
329
|
toolTipPosition
|
|
310
330
|
} = this.state;
|
|
311
331
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
312
|
-
|
|
313
|
-
|
|
332
|
+
ref: ref => this.container = ref,
|
|
333
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
334
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
335
|
+
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
336
|
+
})
|
|
314
337
|
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
315
338
|
tooltipData: tooltipData,
|
|
316
339
|
toolTipPosition: toolTipPosition,
|