sea-chart 2.0.8 → 2.0.9
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/tooltip/index.js +92 -0
- package/dist/components/types-dialog/index.js +0 -3
- package/dist/view/wrapper/bar-compare.js +326 -0
- package/dist/view/wrapper/bar-custom-stack.js +344 -0
- package/dist/view/wrapper/bar-group.js +6 -1
- package/dist/view/wrapper/bar-stack.js +9 -7
- package/dist/view/wrapper/bar.js +9 -4
- package/dist/view/wrapper/chart-component.js +9 -50
- package/dist/view/wrapper/index.js +14 -0
- package/package.json +2 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
const ToolTip = _ref => {
|
|
10
|
+
let {
|
|
11
|
+
tooltipData,
|
|
12
|
+
toolTipPosition,
|
|
13
|
+
chart
|
|
14
|
+
} = _ref;
|
|
15
|
+
const tooltipRef = (0, _react.useRef)(null);
|
|
16
|
+
const [position, setPosition] = (0, _react.useState)({
|
|
17
|
+
offsetX: -9999,
|
|
18
|
+
offsetY: -9999
|
|
19
|
+
});
|
|
20
|
+
const {
|
|
21
|
+
title,
|
|
22
|
+
items
|
|
23
|
+
} = tooltipData || {
|
|
24
|
+
title: '',
|
|
25
|
+
items: []
|
|
26
|
+
};
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
if (!toolTipPosition) {
|
|
29
|
+
setPosition({
|
|
30
|
+
offsetX: -9999,
|
|
31
|
+
offsetY: -9999
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (chart && toolTipPosition) {
|
|
36
|
+
const width = Number(chart.node().getAttribute('width'));
|
|
37
|
+
const height = Number(chart.node().getAttribute('height'));
|
|
38
|
+
const {
|
|
39
|
+
height: tooltipHeight,
|
|
40
|
+
width: tooltipWidth
|
|
41
|
+
} = tooltipRef.current.getBoundingClientRect();
|
|
42
|
+
const {
|
|
43
|
+
offsetX,
|
|
44
|
+
offsetY
|
|
45
|
+
} = toolTipPosition;
|
|
46
|
+
const distance = 30;
|
|
47
|
+
const insertPadding = 30;
|
|
48
|
+
let translateX = offsetX + distance;
|
|
49
|
+
let translateY = offsetY;
|
|
50
|
+
const endOffsetX = offsetX + distance + tooltipWidth + insertPadding;
|
|
51
|
+
const endOffsetY = offsetY + tooltipHeight + insertPadding;
|
|
52
|
+
// Right overflow
|
|
53
|
+
if (endOffsetX > width) {
|
|
54
|
+
translateX = offsetX - distance - tooltipWidth - insertPadding;
|
|
55
|
+
}
|
|
56
|
+
// Bottom overflow
|
|
57
|
+
if (endOffsetY > height) {
|
|
58
|
+
translateY = offsetY - (endOffsetY - height);
|
|
59
|
+
}
|
|
60
|
+
setPosition({
|
|
61
|
+
offsetX: translateX,
|
|
62
|
+
offsetY: translateY
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, [chart, toolTipPosition, tooltipRef]);
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
|
+
ref: tooltipRef,
|
|
68
|
+
className: "sea-chart-d3-tooltip-container",
|
|
69
|
+
style: {
|
|
70
|
+
transform: "translate(".concat(position.offsetX, "px, ").concat(position.offsetY, "px)")
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
73
|
+
className: "sea-chart-d3-tooltip-title"
|
|
74
|
+
}, title), /*#__PURE__*/_react.default.createElement("ul", {
|
|
75
|
+
className: "sea-chart-d3-tooltip-list"
|
|
76
|
+
}, items.map((item, index) => {
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement("li", {
|
|
78
|
+
className: "sea-chart-d3-tooltip-list-item",
|
|
79
|
+
key: index
|
|
80
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
81
|
+
className: "sea-chart-d3-tooltip-marker",
|
|
82
|
+
style: {
|
|
83
|
+
backgroundColor: item.color
|
|
84
|
+
}
|
|
85
|
+
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
86
|
+
className: "sea-chart-d3-tooltip-name"
|
|
87
|
+
}, item.name), /*#__PURE__*/_react.default.createElement("span", {
|
|
88
|
+
className: "sea-chart-d3-tooltip-value"
|
|
89
|
+
}, item.value));
|
|
90
|
+
})));
|
|
91
|
+
};
|
|
92
|
+
var _default = exports.default = ToolTip;
|
|
@@ -70,9 +70,6 @@ const TypesDialog = _ref => {
|
|
|
70
70
|
const handleFilterTypes = (0, _react.useCallback)(() => {
|
|
71
71
|
if (hideTypeToggle) {
|
|
72
72
|
const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram'].includes(item.name));
|
|
73
|
-
newChartTypes.forEach(item => {
|
|
74
|
-
item.children = item.children.slice(0, 3);
|
|
75
|
-
});
|
|
76
73
|
return newChartTypes;
|
|
77
74
|
}
|
|
78
75
|
return _constants.CHART_TYPES;
|
|
@@ -0,0 +1,326 @@
|
|
|
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 d3 = _interopRequireWildcard(require("d3"));
|
|
12
|
+
var _dtableUtils = require("dtable-utils");
|
|
13
|
+
var _constants = require("../../constants");
|
|
14
|
+
var _chartUtils = require("../../utils/chart-utils");
|
|
15
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
16
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
17
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
18
|
+
class BarCompare extends _chartComponent.default {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.createChart = () => {
|
|
22
|
+
const {
|
|
23
|
+
chart
|
|
24
|
+
} = this.props;
|
|
25
|
+
const initConfig = {
|
|
26
|
+
insertPadding: 30,
|
|
27
|
+
borderRadius: 10,
|
|
28
|
+
overflowHeight: 20 // Fillet the bottom corner beyond the axis and then cover it with a mask
|
|
29
|
+
};
|
|
30
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
31
|
+
this.initDefs();
|
|
32
|
+
};
|
|
33
|
+
this.drawChart = () => {
|
|
34
|
+
let {
|
|
35
|
+
result: data
|
|
36
|
+
} = this.props;
|
|
37
|
+
data = _chartUtils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
38
|
+
if (!Array.isArray(data)) return;
|
|
39
|
+
this.draw(data);
|
|
40
|
+
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
41
|
+
};
|
|
42
|
+
this.draw = data => {
|
|
43
|
+
const {
|
|
44
|
+
chart,
|
|
45
|
+
globalTheme,
|
|
46
|
+
chartColorTheme,
|
|
47
|
+
canvasStyle
|
|
48
|
+
} = this.props;
|
|
49
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
50
|
+
const {
|
|
51
|
+
previewType
|
|
52
|
+
} = canvasStyle || {};
|
|
53
|
+
const {
|
|
54
|
+
display_increase,
|
|
55
|
+
y_axis_auto_range,
|
|
56
|
+
y_axis_min,
|
|
57
|
+
y_axis_max
|
|
58
|
+
} = chart.config;
|
|
59
|
+
const {
|
|
60
|
+
width: chartWidth,
|
|
61
|
+
height: chartHeight,
|
|
62
|
+
insertPadding,
|
|
63
|
+
borderRadius,
|
|
64
|
+
overflowHeight
|
|
65
|
+
} = this.chartBoundingClientRect;
|
|
66
|
+
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);
|
|
68
|
+
const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
|
|
69
|
+
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
|
+
|
|
72
|
+
// X axis
|
|
73
|
+
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
74
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
75
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
76
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
77
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
78
|
+
});
|
|
79
|
+
|
|
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
|
+
// 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 => {
|
|
91
|
+
let [name, dum] = _ref;
|
|
92
|
+
// Each group is horizontally centered
|
|
93
|
+
const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
|
|
94
|
+
return "translate(".concat(fx(name) + offset, ",0)");
|
|
95
|
+
})
|
|
96
|
+
// rect item
|
|
97
|
+
.selectAll().data(_ref2 => {
|
|
98
|
+
let [a, d] = _ref2;
|
|
99
|
+
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) => {
|
|
101
|
+
this.props.toggleRecords(data);
|
|
102
|
+
}).on('mouseover', event => {
|
|
103
|
+
this.showTooltip(event, color);
|
|
104
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
105
|
+
}).on('mousemove', event => {
|
|
106
|
+
this.moveTooltip(event, color);
|
|
107
|
+
}).on('mouseleave', event => {
|
|
108
|
+
this.hiddenTooltip();
|
|
109
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
110
|
+
});
|
|
111
|
+
if (display_increase) {
|
|
112
|
+
const increaseData = this.getIncreaseData(data);
|
|
113
|
+
this.drawIncreaseLine(increaseData);
|
|
114
|
+
}
|
|
115
|
+
this.setColorMap(data, chartColorTheme);
|
|
116
|
+
this.setLegend('group_name', theme, 'top-right', data);
|
|
117
|
+
};
|
|
118
|
+
this.showTooltip = (event, colorScale, isCircle) => {
|
|
119
|
+
const {
|
|
120
|
+
y_axis_summary_type,
|
|
121
|
+
y_axis_summary_method,
|
|
122
|
+
increase_line_color
|
|
123
|
+
} = this.props.chart.config;
|
|
124
|
+
const {
|
|
125
|
+
offsetX,
|
|
126
|
+
offsetY
|
|
127
|
+
} = event;
|
|
128
|
+
let newTooltipData = {};
|
|
129
|
+
if (isCircle) {
|
|
130
|
+
const circleEl = event.target;
|
|
131
|
+
newTooltipData = {
|
|
132
|
+
title: _intl.default.get(_constants.TITLE_INCREASE),
|
|
133
|
+
items: [{
|
|
134
|
+
color: increase_line_color || '#fbd44a',
|
|
135
|
+
name: circleEl.getAttribute('data-name'),
|
|
136
|
+
value: circleEl.getAttribute('data-text')
|
|
137
|
+
}]
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
const curGroup = event.target.parentNode;
|
|
141
|
+
const [, data] = curGroup.__data__;
|
|
142
|
+
newTooltipData = {
|
|
143
|
+
title: y_axis_summary_type === 'count' ? _intl.default.get(_constants.TITLE_AMOUNT) : _intl.default.get(_constants.CHART_SUMMARY_SHOW[y_axis_summary_method]),
|
|
144
|
+
items: data.map(item => {
|
|
145
|
+
return {
|
|
146
|
+
color: colorScale(item.group_name),
|
|
147
|
+
name: item.group_name,
|
|
148
|
+
value: item.value
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
this.setState({
|
|
154
|
+
tooltipData: newTooltipData
|
|
155
|
+
});
|
|
156
|
+
this.setState({
|
|
157
|
+
toolTipPosition: {
|
|
158
|
+
offsetX,
|
|
159
|
+
offsetY
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
this.moveTooltip = event => {
|
|
164
|
+
const {
|
|
165
|
+
offsetX,
|
|
166
|
+
offsetY
|
|
167
|
+
} = event;
|
|
168
|
+
this.setState({
|
|
169
|
+
toolTipPosition: {
|
|
170
|
+
offsetX,
|
|
171
|
+
offsetY
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
this.hiddenTooltip = event => {
|
|
176
|
+
this.setState({
|
|
177
|
+
toolTipPosition: null
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
this.drawIncreaseLine = increaseData => {
|
|
181
|
+
const {
|
|
182
|
+
chart,
|
|
183
|
+
globalTheme
|
|
184
|
+
} = this.props;
|
|
185
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
186
|
+
const {
|
|
187
|
+
label_font_size,
|
|
188
|
+
y_axis_auto_range,
|
|
189
|
+
y_axis_min,
|
|
190
|
+
y_axis_max,
|
|
191
|
+
increase_line_color,
|
|
192
|
+
display_increase_percentage
|
|
193
|
+
} = chart.config;
|
|
194
|
+
const {
|
|
195
|
+
width: chartWidth,
|
|
196
|
+
height: chartHeight,
|
|
197
|
+
insertPadding
|
|
198
|
+
} = this.chartBoundingClientRect;
|
|
199
|
+
const circleData = increaseData.map(() => ({}));
|
|
200
|
+
const lineX = d3.scaleBand().domain(increaseData.map(d => d.name)).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
201
|
+
const lineY = d3.scaleLinear().domain(y_axis_auto_range ? [d3.min(increaseData, d => d.value), d3.max(increaseData, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
|
|
202
|
+
const line = d3.line().x((d, index) => {
|
|
203
|
+
const x = lineX(d.name) + lineX.bandwidth() / 2;
|
|
204
|
+
circleData[index]['x'] = x;
|
|
205
|
+
circleData[index]['name'] = d.name;
|
|
206
|
+
return x;
|
|
207
|
+
}).y((d, index) => {
|
|
208
|
+
const y = lineY(d.value);
|
|
209
|
+
circleData[index]['y'] = y;
|
|
210
|
+
circleData[index]['value'] = d.formatValue;
|
|
211
|
+
return y;
|
|
212
|
+
}).curve(d3.curveBumpX);
|
|
213
|
+
const wrapper = this.chart.append('g').attr('class', "increase-line-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
214
|
+
|
|
215
|
+
// line
|
|
216
|
+
wrapper.append('path').attr('fill', 'none').attr('stroke', increase_line_color || '#fbd44a').attr('stroke-width', 2).attr('d', () => line(increaseData));
|
|
217
|
+
|
|
218
|
+
// circle
|
|
219
|
+
console.log('wrapper', wrapper);
|
|
220
|
+
circleData.forEach(item => {
|
|
221
|
+
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
|
+
// circle label
|
|
223
|
+
if (display_increase_percentage) {
|
|
224
|
+
const curCircleEl = g.node();
|
|
225
|
+
wrapper.append('text').attr('fill', theme.labelColor).attr('font-size', _chartUtils.BaseUtils.getLabelFontSize(label_font_size)).text(curCircleEl.getAttribute('data-text')).call(g => {
|
|
226
|
+
const {
|
|
227
|
+
width
|
|
228
|
+
} = g.node().getBoundingClientRect();
|
|
229
|
+
const translateX = Number(curCircleEl.getAttribute('cx')) - width / 2;
|
|
230
|
+
const translateY = Number(curCircleEl.getAttribute('cy')) - 10;
|
|
231
|
+
g.attr('transform', "translate(".concat(translateX, ", ").concat(translateY, ")"));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}).on('mouseover', event => {
|
|
235
|
+
this.updateCircleStyle(event, 'zoomIn');
|
|
236
|
+
this.showTooltip(event, '', true);
|
|
237
|
+
}).on('mousemove', event => {
|
|
238
|
+
this.moveTooltip(event);
|
|
239
|
+
}).on('mouseleave', event => {
|
|
240
|
+
this.hiddenTooltip();
|
|
241
|
+
this.updateCircleStyle(event, 'zoomOut');
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
this.getIncreaseData = data => {
|
|
246
|
+
const increaseData = [];
|
|
247
|
+
d3.group(data, d => d.name).forEach((value, key) => {
|
|
248
|
+
var _increaseValue$, _increaseValue$2;
|
|
249
|
+
const increaseValue = value.filter(d => (d === null || d === void 0 ? void 0 : d.increase_value) !== undefined) || [{
|
|
250
|
+
increaseValue: 0
|
|
251
|
+
}];
|
|
252
|
+
const formatValue = (0, _dtableUtils.getNumberDisplayString)((_increaseValue$ = increaseValue[0]) === null || _increaseValue$ === void 0 ? void 0 : _increaseValue$.increase_value, {
|
|
253
|
+
format: 'percent'
|
|
254
|
+
});
|
|
255
|
+
const data = {
|
|
256
|
+
name: key,
|
|
257
|
+
value: ((_increaseValue$2 = increaseValue[0]) === null || _increaseValue$2 === void 0 ? void 0 : _increaseValue$2.increase_value) || 0,
|
|
258
|
+
formatValue: formatValue || '0%',
|
|
259
|
+
rowData: value
|
|
260
|
+
};
|
|
261
|
+
increaseData.push(data);
|
|
262
|
+
});
|
|
263
|
+
return increaseData;
|
|
264
|
+
};
|
|
265
|
+
this.updateCircleStyle = (event, state) => {
|
|
266
|
+
if (state === 'zoomIn') {
|
|
267
|
+
d3.select(event.currentTarget).attr('r', 5);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const circles = d3.select(event.currentTarget.parentNode).selectAll('circle').nodes();
|
|
271
|
+
circles.forEach(circle => d3.select(circle).attr('r', 3));
|
|
272
|
+
};
|
|
273
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
274
|
+
const curGroup = event.target.parentNode;
|
|
275
|
+
const allGroup = Array.from(curGroup.parentNode.children);
|
|
276
|
+
const [curGroupName] = curGroup.__data__;
|
|
277
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
278
|
+
};
|
|
279
|
+
this.chart = null;
|
|
280
|
+
this.state = {
|
|
281
|
+
tooltipData: null,
|
|
282
|
+
toolTipPosition: null
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
componentDidMount() {
|
|
286
|
+
this.createChart();
|
|
287
|
+
this.drawChart();
|
|
288
|
+
}
|
|
289
|
+
componentDidUpdate(prevProps) {
|
|
290
|
+
super.componentDidUpdate(prevProps);
|
|
291
|
+
if (_chartUtils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
292
|
+
this.createChart();
|
|
293
|
+
this.drawChart();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
componentWillUnmount() {
|
|
297
|
+
this.chart.node() && this.chart.node().remove();
|
|
298
|
+
}
|
|
299
|
+
render() {
|
|
300
|
+
const {
|
|
301
|
+
tooltipData,
|
|
302
|
+
toolTipPosition
|
|
303
|
+
} = this.state;
|
|
304
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
305
|
+
className: "sea-chart-container",
|
|
306
|
+
ref: ref => this.container = ref
|
|
307
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
308
|
+
tooltipData: tooltipData,
|
|
309
|
+
toolTipPosition: toolTipPosition,
|
|
310
|
+
chart: this.chart
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
BarCompare.propTypes = {
|
|
315
|
+
canvasStyle: _propTypes.default.object,
|
|
316
|
+
chart: _propTypes.default.object,
|
|
317
|
+
groupbyColumn: _propTypes.default.object,
|
|
318
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
319
|
+
summaryColumn: _propTypes.default.object,
|
|
320
|
+
result: _propTypes.default.array,
|
|
321
|
+
tables: _propTypes.default.array,
|
|
322
|
+
globalTheme: _propTypes.default.string,
|
|
323
|
+
chartColorTheme: _propTypes.default.string,
|
|
324
|
+
toggleRecords: _propTypes.default.func
|
|
325
|
+
};
|
|
326
|
+
var _default = exports.default = BarCompare;
|
|
@@ -0,0 +1,344 @@
|
|
|
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 _slugid = _interopRequireDefault(require("slugid"));
|
|
14
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
15
|
+
var _chartUtils = require("../../utils/chart-utils");
|
|
16
|
+
var _constants = require("../../constants");
|
|
17
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
18
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
19
|
+
class BarCustom extends _chartComponent.default {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.handleResize = (0, _lodashEs.debounce)(() => {
|
|
23
|
+
this.chart.node() && this.chart.node().remove();
|
|
24
|
+
this.createChart();
|
|
25
|
+
this.drawChart();
|
|
26
|
+
}, 300);
|
|
27
|
+
this.createChart = () => {
|
|
28
|
+
const {
|
|
29
|
+
chart
|
|
30
|
+
} = this.props;
|
|
31
|
+
const initConfig = {
|
|
32
|
+
insertPadding: 30,
|
|
33
|
+
borderRadius: 5
|
|
34
|
+
};
|
|
35
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
36
|
+
};
|
|
37
|
+
this.drawChart = () => {
|
|
38
|
+
let {
|
|
39
|
+
result: data
|
|
40
|
+
} = this.props;
|
|
41
|
+
data = _chartUtils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
42
|
+
if (!Array.isArray(data)) return;
|
|
43
|
+
this.draw(data);
|
|
44
|
+
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
45
|
+
};
|
|
46
|
+
this.organizeData = data => {
|
|
47
|
+
const dataMap = {};
|
|
48
|
+
// values is not 0
|
|
49
|
+
data.forEach(item => {
|
|
50
|
+
// name
|
|
51
|
+
if (!dataMap[item.name]) {
|
|
52
|
+
item.isFirst = 1;
|
|
53
|
+
dataMap[item.name] = {
|
|
54
|
+
[item.y_axis_type]: [item]
|
|
55
|
+
};
|
|
56
|
+
} else {
|
|
57
|
+
// same name but different y_axis_type
|
|
58
|
+
if (!dataMap[item.name][item.y_axis_type]) {
|
|
59
|
+
item.isFirst = 1;
|
|
60
|
+
dataMap[item.name][item.y_axis_type] = [item];
|
|
61
|
+
} else {
|
|
62
|
+
item.isFirst = 0;
|
|
63
|
+
dataMap[item.name][item.y_axis_type].push(item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const stacksData = this.handleStacks(dataMap);
|
|
68
|
+
return stacksData;
|
|
69
|
+
};
|
|
70
|
+
this.handleStacks = organizedData => {
|
|
71
|
+
const stacksData = [];
|
|
72
|
+
Object.keys(organizedData).forEach(key => {
|
|
73
|
+
const item = organizedData[key];
|
|
74
|
+
const stacks = [];
|
|
75
|
+
Object.keys(item).forEach(itemKey => {
|
|
76
|
+
const value = item[itemKey];
|
|
77
|
+
|
|
78
|
+
// stack data
|
|
79
|
+
const series = d3.stack().keys(d3.union(value.map(d => d.group_name))).value((_ref, key) => {
|
|
80
|
+
var _group$get;
|
|
81
|
+
let [_, group] = _ref;
|
|
82
|
+
return (_group$get = group.get(String(key))) === null || _group$get === void 0 ? void 0 : _group$get.value;
|
|
83
|
+
})(d3.index(value, d => d.name, d => d.group_name));
|
|
84
|
+
|
|
85
|
+
// add custom key
|
|
86
|
+
series.forEach(s => {
|
|
87
|
+
s['stackKey'] = itemKey;
|
|
88
|
+
s['stackData'] = value.find(d => d.group_name === s.key);
|
|
89
|
+
});
|
|
90
|
+
stacks.push({
|
|
91
|
+
key: itemKey,
|
|
92
|
+
value,
|
|
93
|
+
series,
|
|
94
|
+
slugid: _slugid.default.nice()
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
stacksData.push({
|
|
98
|
+
name: key,
|
|
99
|
+
stacks
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return stacksData;
|
|
103
|
+
};
|
|
104
|
+
this.getAllSeries = organizedData => {
|
|
105
|
+
const allSeries = [];
|
|
106
|
+
organizedData.forEach(item => {
|
|
107
|
+
item.stacks.forEach(stack => {
|
|
108
|
+
stack.series.forEach(s => {
|
|
109
|
+
allSeries.push(s[0]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return allSeries;
|
|
114
|
+
};
|
|
115
|
+
this.draw = data => {
|
|
116
|
+
const {
|
|
117
|
+
chart,
|
|
118
|
+
globalTheme,
|
|
119
|
+
chartColorTheme
|
|
120
|
+
} = this.props;
|
|
121
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
122
|
+
const {
|
|
123
|
+
display_each_block_data
|
|
124
|
+
} = chart.config;
|
|
125
|
+
const {
|
|
126
|
+
display_goal_line,
|
|
127
|
+
goal_value,
|
|
128
|
+
goal_label
|
|
129
|
+
} = chart.style_config || {};
|
|
130
|
+
const {
|
|
131
|
+
width: chartWidth,
|
|
132
|
+
height: chartHeight,
|
|
133
|
+
insertPadding,
|
|
134
|
+
borderRadius
|
|
135
|
+
} = this.chartBoundingClientRect;
|
|
136
|
+
const organizedData = this.organizeData(data);
|
|
137
|
+
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
|
+
const allSeries = this.getAllSeries(organizedData);
|
|
141
|
+
const niceEnd = d3.nice(0, d3.max(allSeries, d => d[1]), 5)[1];
|
|
142
|
+
const y = d3.scaleLinear().domain([0, niceEnd]).range([chartHeight - insertPadding, insertPadding]);
|
|
143
|
+
|
|
144
|
+
// X axis
|
|
145
|
+
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
146
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
147
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
148
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
149
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
150
|
+
});
|
|
151
|
+
|
|
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
|
+
// Rect group
|
|
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
|
+
const {
|
|
164
|
+
name
|
|
165
|
+
} = d;
|
|
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 => {
|
|
170
|
+
const height = y(d[0][0]) - y(d[0][1]);
|
|
171
|
+
return isNaN(height) ? 0 : height;
|
|
172
|
+
}).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
|
+
// add rect borderRadius
|
|
174
|
+
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'), ")"));
|
|
181
|
+
});
|
|
182
|
+
if (display_each_block_data) {
|
|
183
|
+
this.handleLabelToRectCenter(g, x.bandwidth());
|
|
184
|
+
}
|
|
185
|
+
}).on('click', (event, data) => {
|
|
186
|
+
this.props.toggleRecords(data);
|
|
187
|
+
}).on('mouseover', event => {
|
|
188
|
+
this.showTooltip(event, color);
|
|
189
|
+
this.handleStacksAcitveAndInActiveState('inActive', event);
|
|
190
|
+
}).on('mousemove', event => {
|
|
191
|
+
this.moveTooltip(event);
|
|
192
|
+
}).on('mouseleave', event => {
|
|
193
|
+
this.hiddenTooltip();
|
|
194
|
+
this.handleStacksAcitveAndInActiveState('active', event);
|
|
195
|
+
});
|
|
196
|
+
if (display_goal_line && goal_label && goal_value) {
|
|
197
|
+
this.setDispalyGoalLine(goal_label, goal_value, insertPadding, y);
|
|
198
|
+
}
|
|
199
|
+
this.setLegend('group_name', theme, 'top-right', data, color);
|
|
200
|
+
};
|
|
201
|
+
this.handleLabelToRectCenter = (g, xWidth) => {
|
|
202
|
+
const {
|
|
203
|
+
globalTheme,
|
|
204
|
+
chart
|
|
205
|
+
} = this.props;
|
|
206
|
+
const {
|
|
207
|
+
label_font_size
|
|
208
|
+
} = chart.config;
|
|
209
|
+
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')
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
this.handleStacksAcitveAndInActiveState = (state, event) => {
|
|
225
|
+
const rectsWrapper = event.currentTarget.parentNode.parentNode.parentNode;
|
|
226
|
+
const allGroup = Array.from(rectsWrapper.children);
|
|
227
|
+
if (state === 'active') {
|
|
228
|
+
allGroup.forEach(group => {
|
|
229
|
+
Array.from(group.children).forEach(rectGroup => {
|
|
230
|
+
Array.from(rectGroup.children).forEach(rect => {
|
|
231
|
+
if (rect.getAttribute('class') === 'stack') {
|
|
232
|
+
d3.select(rect).attr('opacity', 1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (state === 'inActive') {
|
|
239
|
+
const curRectId = event.currentTarget.getAttribute('data-rectId');
|
|
240
|
+
allGroup.forEach(group => {
|
|
241
|
+
Array.from(group.children).forEach(rectGroup => {
|
|
242
|
+
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);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
this.showTooltip = (event, colorScale) => {
|
|
252
|
+
const {
|
|
253
|
+
offsetX,
|
|
254
|
+
offsetY
|
|
255
|
+
} = event;
|
|
256
|
+
const title = event.currentTarget.getAttribute('data-title');
|
|
257
|
+
const name = event.currentTarget.getAttribute('data-groupName');
|
|
258
|
+
const value = event.currentTarget.getAttribute('data-value');
|
|
259
|
+
const newTooltipData = {
|
|
260
|
+
title: !title && typeof title !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : title,
|
|
261
|
+
items: [{
|
|
262
|
+
color: colorScale(name),
|
|
263
|
+
name: !name && typeof name !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : name,
|
|
264
|
+
value
|
|
265
|
+
}]
|
|
266
|
+
};
|
|
267
|
+
this.setState({
|
|
268
|
+
tooltipData: newTooltipData
|
|
269
|
+
});
|
|
270
|
+
this.setState({
|
|
271
|
+
toolTipPosition: {
|
|
272
|
+
offsetX,
|
|
273
|
+
offsetY
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
this.moveTooltip = event => {
|
|
278
|
+
const {
|
|
279
|
+
offsetX,
|
|
280
|
+
offsetY
|
|
281
|
+
} = event;
|
|
282
|
+
this.setState({
|
|
283
|
+
toolTipPosition: {
|
|
284
|
+
offsetX,
|
|
285
|
+
offsetY
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
this.hiddenTooltip = event => {
|
|
290
|
+
this.setState({
|
|
291
|
+
toolTipPosition: null
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
this.chart = null;
|
|
295
|
+
this.state = {
|
|
296
|
+
tooltipData: null,
|
|
297
|
+
toolTipPosition: null
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
componentDidMount() {
|
|
301
|
+
this.createChart();
|
|
302
|
+
this.drawChart();
|
|
303
|
+
window.addEventListener('resize', this.handleResize);
|
|
304
|
+
}
|
|
305
|
+
componentDidUpdate(prevProps) {
|
|
306
|
+
super.componentDidUpdate(prevProps);
|
|
307
|
+
if (_chartUtils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
308
|
+
this.chart.node() && this.chart.node().remove();
|
|
309
|
+
this.createChart();
|
|
310
|
+
this.drawChart();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
componentWillUnmount() {
|
|
314
|
+
this.chart.node() && this.chart.node().remove();
|
|
315
|
+
window.removeEventListener('resize', this.handleResize);
|
|
316
|
+
}
|
|
317
|
+
render() {
|
|
318
|
+
const {
|
|
319
|
+
tooltipData,
|
|
320
|
+
toolTipPosition
|
|
321
|
+
} = this.state;
|
|
322
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
323
|
+
className: "sea-chart-container",
|
|
324
|
+
ref: ref => this.container = ref
|
|
325
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
326
|
+
tooltipData: tooltipData,
|
|
327
|
+
toolTipPosition: toolTipPosition,
|
|
328
|
+
chart: this.chart
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
BarCustom.propTypes = {
|
|
333
|
+
canvasStyle: _propTypes.default.object,
|
|
334
|
+
chart: _propTypes.default.object,
|
|
335
|
+
groupbyColumn: _propTypes.default.object,
|
|
336
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
337
|
+
summaryColumn: _propTypes.default.object,
|
|
338
|
+
result: _propTypes.default.array,
|
|
339
|
+
tables: _propTypes.default.array,
|
|
340
|
+
globalTheme: _propTypes.default.string,
|
|
341
|
+
chartColorTheme: _propTypes.default.string,
|
|
342
|
+
toggleRecords: _propTypes.default.func
|
|
343
|
+
};
|
|
344
|
+
var _default = exports.default = BarCustom;
|
|
@@ -16,6 +16,7 @@ var _columnUtils = require("../../utils/column-utils");
|
|
|
16
16
|
var _constants = require("../../constants");
|
|
17
17
|
var _utils = require("../../utils");
|
|
18
18
|
var _colorRules = require("../../constants/color-rules");
|
|
19
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
19
20
|
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
20
21
|
class BarGroup extends _chartComponent.default {
|
|
21
22
|
constructor(props) {
|
|
@@ -273,7 +274,11 @@ class BarGroup extends _chartComponent.default {
|
|
|
273
274
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
274
275
|
className: "sea-chart-container",
|
|
275
276
|
ref: ref => this.container = ref
|
|
276
|
-
},
|
|
277
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
278
|
+
tooltipData: tooltipData,
|
|
279
|
+
toolTipPosition: toolTipPosition,
|
|
280
|
+
chart: this.chart
|
|
281
|
+
}));
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
284
|
BarGroup.propTypes = {
|
|
@@ -16,6 +16,7 @@ var _columnUtils = require("../../utils/column-utils");
|
|
|
16
16
|
var _constants = require("../../constants");
|
|
17
17
|
var _utils = require("../../utils");
|
|
18
18
|
var _colorRules = require("../../constants/color-rules");
|
|
19
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
19
20
|
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
20
21
|
class BarStack extends _chartComponent.default {
|
|
21
22
|
constructor(props) {
|
|
@@ -117,7 +118,8 @@ class BarStack extends _chartComponent.default {
|
|
|
117
118
|
});
|
|
118
119
|
|
|
119
120
|
// Rect group
|
|
120
|
-
this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id))
|
|
121
|
+
this.rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
122
|
+
this.rectsWrapper.selectAll().data(series).join('g').attr('data-key', d => d.key).selectAll('rect').data(D => {
|
|
121
123
|
const data = D.map(d => {
|
|
122
124
|
d.key = D.key;
|
|
123
125
|
return d;
|
|
@@ -208,11 +210,7 @@ class BarStack extends _chartComponent.default {
|
|
|
208
210
|
});
|
|
209
211
|
};
|
|
210
212
|
this.handleAcitveAndInActiveState = (state, event) => {
|
|
211
|
-
const
|
|
212
|
-
chart
|
|
213
|
-
} = this.props;
|
|
214
|
-
const rectsWrapper = d3.selectAll(".rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
215
|
-
const allGroup = Array.from(rectsWrapper.node().children);
|
|
213
|
+
const allGroup = Array.from(this.rectsWrapper.node().children);
|
|
216
214
|
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
217
215
|
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
218
216
|
};
|
|
@@ -313,7 +311,11 @@ class BarStack extends _chartComponent.default {
|
|
|
313
311
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
314
312
|
className: "sea-chart-container",
|
|
315
313
|
ref: ref => this.container = ref
|
|
316
|
-
},
|
|
314
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
315
|
+
tooltipData: tooltipData,
|
|
316
|
+
toolTipPosition: toolTipPosition,
|
|
317
|
+
chart: this.chart
|
|
318
|
+
}));
|
|
317
319
|
}
|
|
318
320
|
}
|
|
319
321
|
BarStack.propTypes = {
|
package/dist/view/wrapper/bar.js
CHANGED
|
@@ -14,6 +14,7 @@ var _constants = require("../../constants");
|
|
|
14
14
|
var _utils = require("../../utils");
|
|
15
15
|
var _colorUtils = require("../../utils/color-utils");
|
|
16
16
|
var _intl = _interopRequireDefault(require("../../intl"));
|
|
17
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
17
18
|
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
18
19
|
class Bar extends _chartComponent.default {
|
|
19
20
|
constructor(props) {
|
|
@@ -158,7 +159,8 @@ class Bar extends _chartComponent.default {
|
|
|
158
159
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
159
160
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
160
161
|
});
|
|
161
|
-
this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id))
|
|
162
|
+
const rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
163
|
+
rectsWrapper.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('data-groupName', d => d.name).attr('id', (d, index) => d.slugId).attr('d', d => {
|
|
162
164
|
// Do not draw if the range is smaller than the minimum
|
|
163
165
|
if (!y_axis_auto_range && d.value <= y_axis_min) {
|
|
164
166
|
return '';
|
|
@@ -175,12 +177,11 @@ class Bar extends _chartComponent.default {
|
|
|
175
177
|
path.closePath();
|
|
176
178
|
return path.toString();
|
|
177
179
|
}).call(g => {
|
|
178
|
-
const parentNode = d3.select(".rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
179
180
|
g.nodes().forEach(path => {
|
|
180
181
|
// Add label
|
|
181
182
|
if (y_axis_show_value) {
|
|
182
183
|
this.addLabelToRectTop({
|
|
183
|
-
container:
|
|
184
|
+
container: rectsWrapper.node(),
|
|
184
185
|
xWidth: Number(path.dataset.width),
|
|
185
186
|
x: Number(path.dataset.x),
|
|
186
187
|
y: Number(path.dataset.y),
|
|
@@ -236,7 +237,11 @@ class Bar extends _chartComponent.default {
|
|
|
236
237
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
237
238
|
className: "sea-chart-container",
|
|
238
239
|
ref: ref => this.container = ref
|
|
239
|
-
},
|
|
240
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
241
|
+
tooltipData: tooltipData,
|
|
242
|
+
toolTipPosition: toolTipPosition,
|
|
243
|
+
chart: this.chart
|
|
244
|
+
}));
|
|
240
245
|
}
|
|
241
246
|
}
|
|
242
247
|
Bar.propTypes = {
|
|
@@ -504,6 +504,7 @@ class ChartComponent extends _react.Component {
|
|
|
504
504
|
let theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.CHART_THEME_COLOR['light'];
|
|
505
505
|
let legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'top-left';
|
|
506
506
|
let data = arguments.length > 3 ? arguments[3] : undefined;
|
|
507
|
+
let colorScale = arguments.length > 4 ? arguments[4] : undefined;
|
|
507
508
|
if (!_this.chart) return;
|
|
508
509
|
const {
|
|
509
510
|
width: chartWidth,
|
|
@@ -527,16 +528,16 @@ class ChartComponent extends _react.Component {
|
|
|
527
528
|
legendData = d3.group(data, d => d[legendName]);
|
|
528
529
|
direction = -1;
|
|
529
530
|
}
|
|
530
|
-
_this.chart.append('g').attr('class', "legend-wrapper-".concat((_this$chart$node = _this.chart.node()) === null || _this$chart$node === void 0 ? void 0 : _this$chart$node.id)).attr('transform', "translate(".concat(translateX, ", 0)"))
|
|
531
|
+
const legendWrapper = _this.chart.append('g').attr('class', "legend-wrapper-".concat((_this$chart$node = _this.chart.node()) === null || _this$chart$node === void 0 ? void 0 : _this$chart$node.id)).attr('transform', "translate(".concat(translateX, ", 0)"));
|
|
532
|
+
legendWrapper.selectAll().data(legendData).join('g').append('rect').attr('width', legendRectWidth).attr('height', legendRectHeight).attr('rx', r).attr('fill', _ref => {
|
|
531
533
|
let [groupName] = _ref;
|
|
534
|
+
if (colorScale) return colorScale(groupName);
|
|
532
535
|
return _this.colorMap[groupName] || _constants.CHART_STYLE_COLORS[0];
|
|
533
536
|
}).attr('data-text', _ref2 => {
|
|
534
537
|
let [groupName] = _ref2;
|
|
535
538
|
return groupName;
|
|
536
539
|
}).call(g => {
|
|
537
|
-
|
|
538
|
-
const legendWrapper = d3.selectAll(".legend-wrapper-".concat((_this$chart$node2 = _this.chart.node()) === null || _this$chart$node2 === void 0 ? void 0 : _this$chart$node2.id)).node();
|
|
539
|
-
const legendItems = Array.from(legendWrapper.children);
|
|
540
|
+
const legendItems = Array.from(legendWrapper.node().children);
|
|
540
541
|
const legendItemCount = legendItems.length;
|
|
541
542
|
|
|
542
543
|
// Add text
|
|
@@ -689,47 +690,6 @@ class ChartComponent extends _react.Component {
|
|
|
689
690
|
const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
|
|
690
691
|
this.chart.tooltip(settings);
|
|
691
692
|
};
|
|
692
|
-
this.getToolTipContainer = (tooltipData, position) => {
|
|
693
|
-
const {
|
|
694
|
-
offsetX,
|
|
695
|
-
offsetY
|
|
696
|
-
} = position || {
|
|
697
|
-
offsetX: -9999,
|
|
698
|
-
offsetY: -9999
|
|
699
|
-
};
|
|
700
|
-
const {
|
|
701
|
-
title,
|
|
702
|
-
items
|
|
703
|
-
} = tooltipData || {
|
|
704
|
-
title: '',
|
|
705
|
-
items: []
|
|
706
|
-
};
|
|
707
|
-
const dom = /*#__PURE__*/_react.default.createElement("div", {
|
|
708
|
-
className: "sea-chart-d3-tooltip-container",
|
|
709
|
-
style: {
|
|
710
|
-
transform: "translate(".concat(offsetX + 50, "px, ").concat(offsetY, "px)")
|
|
711
|
-
}
|
|
712
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
713
|
-
className: "sea-chart-d3-tooltip-title"
|
|
714
|
-
}, title), /*#__PURE__*/_react.default.createElement("ul", {
|
|
715
|
-
className: "sea-chart-d3-tooltip-list"
|
|
716
|
-
}, items.map((item, index) => {
|
|
717
|
-
return /*#__PURE__*/_react.default.createElement("li", {
|
|
718
|
-
className: "sea-chart-d3-tooltip-list-item",
|
|
719
|
-
key: index
|
|
720
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
721
|
-
className: "sea-chart-d3-tooltip-marker",
|
|
722
|
-
style: {
|
|
723
|
-
backgroundColor: item.color
|
|
724
|
-
}
|
|
725
|
-
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
726
|
-
className: "sea-chart-d3-tooltip-name"
|
|
727
|
-
}, item.name), /*#__PURE__*/_react.default.createElement("span", {
|
|
728
|
-
className: "sea-chart-d3-tooltip-value"
|
|
729
|
-
}, item.value));
|
|
730
|
-
})));
|
|
731
|
-
return dom;
|
|
732
|
-
};
|
|
733
693
|
this.setToolTipForLine = () => {
|
|
734
694
|
const settings = this.getToolTipSettings();
|
|
735
695
|
const lineToolTipSettings = {
|
|
@@ -797,14 +757,13 @@ class ChartComponent extends _react.Component {
|
|
|
797
757
|
return themeColors || _constants.CHART_THEME_COLOR[_constants.THEME_NAME_MAP.LIGHT];
|
|
798
758
|
};
|
|
799
759
|
this.setDispalyGoalLine = (goal_label, goal_value, insertPadding, yScale) => {
|
|
800
|
-
var _this$chart$
|
|
760
|
+
var _this$chart$node2;
|
|
801
761
|
const {
|
|
802
762
|
width: chartWidth
|
|
803
763
|
} = this.chartBoundingClientRect;
|
|
804
|
-
this.chart.append('g').attr('class', "annotation-wrapper-".concat((_this$chart$
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
parentNode.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', yScale(goal_value) - 10).attr('fill', '#666').text(goal_label);
|
|
764
|
+
const annotationWrapper = this.chart.append('g').attr('class', "annotation-wrapper-".concat((_this$chart$node2 = this.chart.node()) === null || _this$chart$node2 === void 0 ? void 0 : _this$chart$node2.id));
|
|
765
|
+
annotationWrapper.append('line').attr('stroke', '#aaa').attr('x1', insertPadding).attr('y1', yScale(goal_value)).attr('x2', chartWidth - insertPadding).attr('y2', yScale(goal_value)).call(g => {
|
|
766
|
+
annotationWrapper.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', yScale(goal_value) - 10).attr('fill', '#666').text(goal_label);
|
|
808
767
|
});
|
|
809
768
|
};
|
|
810
769
|
this.addLabelToRectTop = _ref3 => {
|
|
@@ -13,6 +13,8 @@ var _table = _interopRequireDefault(require("./table"));
|
|
|
13
13
|
var _bar = _interopRequireDefault(require("./bar"));
|
|
14
14
|
var _barGroup = _interopRequireDefault(require("./bar-group"));
|
|
15
15
|
var _barStack = _interopRequireDefault(require("./bar-stack"));
|
|
16
|
+
var _barCompare = _interopRequireDefault(require("./bar-compare"));
|
|
17
|
+
var _barCustomStack = _interopRequireDefault(require("./bar-custom-stack"));
|
|
16
18
|
var _basicNumberCard = _interopRequireDefault(require("./basic-number-card"));
|
|
17
19
|
var _trend = _interopRequireDefault(require("./trend"));
|
|
18
20
|
var _tableElement = _interopRequireDefault(require("./table-element"));
|
|
@@ -115,6 +117,18 @@ const Wrapper = _ref => {
|
|
|
115
117
|
canvasStyle: canvasStyle
|
|
116
118
|
}));
|
|
117
119
|
}
|
|
120
|
+
case _constants.CHART_TYPE.COMPARE_BAR:
|
|
121
|
+
{
|
|
122
|
+
return /*#__PURE__*/_react.default.createElement(_barCompare.default, Object.assign({}, baseProps, {
|
|
123
|
+
canvasStyle: canvasStyle
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
case _constants.CHART_TYPE.BAR_CUSTOM:
|
|
127
|
+
{
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(_barCustomStack.default, Object.assign({}, baseProps, {
|
|
129
|
+
canvasStyle: canvasStyle
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
118
132
|
case _constants.CHART_TYPE.BASIC_NUMBER_CARD:
|
|
119
133
|
{
|
|
120
134
|
return /*#__PURE__*/_react.default.createElement(_basicNumberCard.default, Object.assign({}, baseProps, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sea-chart",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@dnd-kit/core": "^6.1.0",
|
|
@@ -135,6 +135,7 @@
|
|
|
135
135
|
"react-cookies": "0.1.1",
|
|
136
136
|
"react-dev-utils": "^12.0.1",
|
|
137
137
|
"react-dom": "~18.3.1",
|
|
138
|
+
"react-i18next": "12.1.4",
|
|
138
139
|
"regenerator-runtime": "^0.14.1",
|
|
139
140
|
"release-it": "16.2.1",
|
|
140
141
|
"resolve": "1.12.0",
|