sea-chart 2.0.21 → 2.0.22
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/assets/css/sea-chart-d3-tooltip.css +2 -1
- package/dist/components/types-dialog/index.js +1 -1
- package/dist/view/wrapper/area-group.js +20 -20
- package/dist/view/wrapper/area.js +20 -20
- package/dist/view/wrapper/bar-compare.js +9 -7
- package/dist/view/wrapper/bar-custom-stack.js +7 -7
- package/dist/view/wrapper/bar-group.js +16 -7
- package/dist/view/wrapper/bar-stack.js +28 -15
- package/dist/view/wrapper/bar.js +23 -10
- package/dist/view/wrapper/chart-component.js +108 -21
- package/dist/view/wrapper/combination.js +504 -0
- package/dist/view/wrapper/completeness-group.js +12 -12
- package/dist/view/wrapper/completeness.js +10 -10
- package/dist/view/wrapper/horizontal-bar-group.js +21 -8
- package/dist/view/wrapper/horizontal-bar-stack.js +22 -13
- package/dist/view/wrapper/horizontal-bar.js +17 -7
- package/dist/view/wrapper/index.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,504 @@
|
|
|
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 _dtableUtils = require("dtable-utils");
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
13
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
16
|
+
var _constants = require("../../constants");
|
|
17
|
+
var _utils = require("../../utils");
|
|
18
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
19
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
20
|
+
class Combination extends _chartComponent.default {
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
this.handleResize = () => {
|
|
24
|
+
this.chart.node() && this.chart.node().remove();
|
|
25
|
+
this.createChart();
|
|
26
|
+
this.drawChart();
|
|
27
|
+
};
|
|
28
|
+
this.createChart = () => {
|
|
29
|
+
const {
|
|
30
|
+
chart
|
|
31
|
+
} = this.props;
|
|
32
|
+
const {
|
|
33
|
+
show_y_axis_left_label,
|
|
34
|
+
show_y_axis_right_label,
|
|
35
|
+
x_axis_show_label,
|
|
36
|
+
display_data
|
|
37
|
+
} = chart.config;
|
|
38
|
+
const initConfig = {
|
|
39
|
+
insertPadding: 30,
|
|
40
|
+
borderRadius: 0.2,
|
|
41
|
+
marginLeft: show_y_axis_left_label ? 20 : 0,
|
|
42
|
+
marginRight: show_y_axis_right_label ? 20 : 0,
|
|
43
|
+
marginBottom: x_axis_show_label ? 20 : 0,
|
|
44
|
+
marginTop: display_data ? 15 : 0
|
|
45
|
+
};
|
|
46
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
47
|
+
};
|
|
48
|
+
this.drawChart = () => {
|
|
49
|
+
const {
|
|
50
|
+
customRender
|
|
51
|
+
} = this.props;
|
|
52
|
+
let {
|
|
53
|
+
result: data
|
|
54
|
+
} = this.props;
|
|
55
|
+
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
56
|
+
if (!Array.isArray(data)) return;
|
|
57
|
+
this.draw(data);
|
|
58
|
+
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
59
|
+
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
60
|
+
};
|
|
61
|
+
this.draw = data => {
|
|
62
|
+
const {
|
|
63
|
+
chart,
|
|
64
|
+
globalTheme,
|
|
65
|
+
tables,
|
|
66
|
+
chartColorTheme
|
|
67
|
+
} = this.props;
|
|
68
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
69
|
+
const currentTheme = _utils.BaseUtils.getCurrentTheme(chartColorTheme);
|
|
70
|
+
const {
|
|
71
|
+
display_goal_line,
|
|
72
|
+
goal_value,
|
|
73
|
+
goal_label
|
|
74
|
+
} = chart.style_config || {};
|
|
75
|
+
const {
|
|
76
|
+
width: chartWidth,
|
|
77
|
+
height: chartHeight,
|
|
78
|
+
insertPadding,
|
|
79
|
+
marginTop
|
|
80
|
+
} = this.chartBoundingClientRect;
|
|
81
|
+
const {
|
|
82
|
+
table_id,
|
|
83
|
+
y_axis_left_summary_column,
|
|
84
|
+
y_axis_right_summary_column,
|
|
85
|
+
y_axis_left_summary_method,
|
|
86
|
+
y_axis_left_summary_type,
|
|
87
|
+
y_axis_right_summary_type,
|
|
88
|
+
y_axis_left_group_by_multiple_numeric_column,
|
|
89
|
+
y_axis_auto_range_left,
|
|
90
|
+
y_axis_min_left,
|
|
91
|
+
y_axis_max_left,
|
|
92
|
+
y_axis_auto_range_right,
|
|
93
|
+
y_axis_min_right,
|
|
94
|
+
y_axis_max_right,
|
|
95
|
+
display_data,
|
|
96
|
+
display_data_field,
|
|
97
|
+
label_font_size
|
|
98
|
+
} = chart.config;
|
|
99
|
+
const table = (0, _dtableUtils.getTableById)(tables, table_id);
|
|
100
|
+
const leftSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_left_summary_column) || {};
|
|
101
|
+
const rightSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_right_summary_column) || {};
|
|
102
|
+
const leftTitle = this.getTitle(tables, table_id, y_axis_left_summary_type, y_axis_left_summary_column);
|
|
103
|
+
const rightTitle = this.getTitle(tables, table_id, y_axis_right_summary_type, y_axis_right_summary_column);
|
|
104
|
+
const showLeftValue = display_data && this.valueFieldMap['value_left'].includes(display_data_field);
|
|
105
|
+
let showRightValue = display_data && this.valueFieldMap['value_right'].includes(display_data_field);
|
|
106
|
+
if (display_data && !display_data_field) {
|
|
107
|
+
// if display_data is open, default show right value
|
|
108
|
+
showRightValue = true;
|
|
109
|
+
}
|
|
110
|
+
this.setCombinationColorMap(data, leftSummaryColumn, rightSummaryColumn);
|
|
111
|
+
const rightNiceEnd = d3.nice(0, d3.max(data, d => d.value_right), 5)[1];
|
|
112
|
+
const rightY = d3.scaleLinear().domain(y_axis_auto_range_right ? [d3.min(data, d => d.value_right), rightNiceEnd] : [y_axis_min_right, y_axis_max_right]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
113
|
+
|
|
114
|
+
// Y axis (right)
|
|
115
|
+
const rightAxisWrapper = this.chart.append('g').attr('class', 'y-axis-wrapper-right').attr('transform', "translate(".concat(chartWidth - insertPadding, ",0)")).call(d3.axisRight(rightY).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(rightSummaryColumn, d, y_axis_right_summary_column))).call(g => {
|
|
116
|
+
g.select('.domain').remove();
|
|
117
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
118
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
119
|
+
});
|
|
120
|
+
const rightAxisOffset = this.getRightAxisOffset(rightAxisWrapper);
|
|
121
|
+
const leftNiceEnd = d3.nice(0, d3.max(data, d => d.value_left), 5)[1];
|
|
122
|
+
const leftY = d3.scaleLinear().domain(y_axis_auto_range_left ? [0, leftNiceEnd] : [y_axis_min_left, y_axis_max_left]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
123
|
+
|
|
124
|
+
// Y axis (left)
|
|
125
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper-left').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(leftY).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(leftSummaryColumn, d, y_axis_left_summary_method))).call(g => this.drawYaxis(g, theme, rightAxisOffset));
|
|
126
|
+
const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding - rightAxisOffset]).paddingInner(0.5).paddingOuter(0.1);
|
|
127
|
+
const x = d3.scaleBand().domain(y_axis_left_group_by_multiple_numeric_column ? new Set(data.map(d => d.group_name)) : new Set([data[0]])).range([0, fx.bandwidth()]).paddingInner(y_axis_left_group_by_multiple_numeric_column ? 0.2 : 0).paddingOuter(0);
|
|
128
|
+
|
|
129
|
+
// X axis
|
|
130
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
131
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
132
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
133
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
134
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
135
|
+
this.checkTickOverlap(g);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Rect group
|
|
139
|
+
this.chart.append('g').attr('class', 'content-wrapper').selectAll().data(d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
|
|
140
|
+
let [name, dum] = _ref;
|
|
141
|
+
return "translate(".concat(fx(name), ",0)");
|
|
142
|
+
})
|
|
143
|
+
// rect item
|
|
144
|
+
.selectAll().data(_ref2 => {
|
|
145
|
+
let [_, d] = _ref2;
|
|
146
|
+
return d;
|
|
147
|
+
}).join('rect').attr('opacity', 1).attr('x', (d, index) => {
|
|
148
|
+
if (y_axis_left_group_by_multiple_numeric_column) {
|
|
149
|
+
return x(d.group_name);
|
|
150
|
+
}
|
|
151
|
+
return 0;
|
|
152
|
+
}).attr('y', d => leftY(d.value_left)).attr('width', x.bandwidth()).attr('height', d => leftY(0) - leftY(d.value_left)).attr('fill', d => {
|
|
153
|
+
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
154
|
+
return currentTheme.colors[0];
|
|
155
|
+
}
|
|
156
|
+
return d.color;
|
|
157
|
+
}).attr('data-value', d => _utils.BaseUtils.getSummaryValueDisplayString(leftSummaryColumn, d.value_left, y_axis_left_summary_method)).attr('data-groupName', d => d.name).attr('data-slugid', d => d.slugId).call(g => {
|
|
158
|
+
g.nodes().forEach(rect => {
|
|
159
|
+
const parentNode = rect.parentNode;
|
|
160
|
+
// add rect borderRadius
|
|
161
|
+
this.addClipPath({
|
|
162
|
+
rect,
|
|
163
|
+
parentNode,
|
|
164
|
+
rectId: rect.getAttribute('data-slugid')
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Add label
|
|
168
|
+
if (showLeftValue) {
|
|
169
|
+
this.addLabelToRectTop({
|
|
170
|
+
container: parentNode,
|
|
171
|
+
xWidth: Number(x.bandwidth()),
|
|
172
|
+
x: Number(rect.getAttribute('x')),
|
|
173
|
+
y: Number(rect.getAttribute('y')),
|
|
174
|
+
theme,
|
|
175
|
+
label_font_size,
|
|
176
|
+
text: rect.dataset.value
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}).on('click', (event, data) => {
|
|
181
|
+
this.props.toggleRecords({
|
|
182
|
+
...data,
|
|
183
|
+
isQueryBySql: true
|
|
184
|
+
});
|
|
185
|
+
}).on('mouseover', event => {
|
|
186
|
+
this.showTooltip(event, {
|
|
187
|
+
leftSummaryColumn,
|
|
188
|
+
leftTitle
|
|
189
|
+
});
|
|
190
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
191
|
+
}).on('mousemove', event => {
|
|
192
|
+
this.moveTooltip(event);
|
|
193
|
+
}).on('mouseleave', (event, data) => {
|
|
194
|
+
this.hiddenTooltip();
|
|
195
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Line group
|
|
199
|
+
this.drawRightContent(data, fx, rightY, showRightValue, rightSummaryColumn, rightTitle);
|
|
200
|
+
if (display_goal_line && goal_label && goal_value) {
|
|
201
|
+
this.setDispalyGoalLine(goal_label, goal_value, insertPadding, rightY);
|
|
202
|
+
}
|
|
203
|
+
const legendData = this.getCombinatinoLegendData(data, leftSummaryColumn, rightSummaryColumn);
|
|
204
|
+
this.setLegend({
|
|
205
|
+
legendName: 'group_name',
|
|
206
|
+
theme,
|
|
207
|
+
legendPosition: 'top-right',
|
|
208
|
+
data: legendData,
|
|
209
|
+
chart
|
|
210
|
+
});
|
|
211
|
+
this.updateLastLegendToCircle();
|
|
212
|
+
};
|
|
213
|
+
this.getRightAxisOffset = rightAxisWrapper => {
|
|
214
|
+
const {
|
|
215
|
+
width: chartWidth,
|
|
216
|
+
insertPadding
|
|
217
|
+
} = this.chartBoundingClientRect;
|
|
218
|
+
const {
|
|
219
|
+
width: rightAxisWidth
|
|
220
|
+
} = rightAxisWrapper.node().getBoundingClientRect();
|
|
221
|
+
let offset = 0;
|
|
222
|
+
if (rightAxisWidth > insertPadding) {
|
|
223
|
+
offset = rightAxisWidth - insertPadding;
|
|
224
|
+
rightAxisWrapper.attr('transform', "translate(".concat(chartWidth - insertPadding - offset, ",0)"));
|
|
225
|
+
return offset;
|
|
226
|
+
}
|
|
227
|
+
return offset;
|
|
228
|
+
};
|
|
229
|
+
this.getCombinatinoLegendData = (data, leftSummaryColumn, rightSummaryColumn) => {
|
|
230
|
+
const {
|
|
231
|
+
chart
|
|
232
|
+
} = this.props;
|
|
233
|
+
const {
|
|
234
|
+
y_axis_left_group_by_multiple_numeric_column
|
|
235
|
+
} = chart.config;
|
|
236
|
+
const newData = [];
|
|
237
|
+
// left legend item
|
|
238
|
+
if (y_axis_left_group_by_multiple_numeric_column) {
|
|
239
|
+
const groups = d3.groups(data, d => d.group_name);
|
|
240
|
+
groups.forEach(_ref3 => {
|
|
241
|
+
let [groupName] = _ref3;
|
|
242
|
+
newData.push({
|
|
243
|
+
group_name: groupName
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
if (leftSummaryColumn !== null && leftSummaryColumn !== void 0 && leftSummaryColumn.name) {
|
|
248
|
+
newData.push({
|
|
249
|
+
group_name: leftSummaryColumn.name
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// right legend item
|
|
254
|
+
if (rightSummaryColumn !== null && rightSummaryColumn !== void 0 && rightSummaryColumn.name) {
|
|
255
|
+
newData.push({
|
|
256
|
+
group_name: String(rightSummaryColumn.name) + ' '
|
|
257
|
+
}); // Add a space character to avoid merging with the previous left legend
|
|
258
|
+
}
|
|
259
|
+
return newData;
|
|
260
|
+
};
|
|
261
|
+
this.setCombinationColorMap = (data, leftSummaryColumn, rightSummaryColumn) => {
|
|
262
|
+
const {
|
|
263
|
+
chart,
|
|
264
|
+
chartColorTheme
|
|
265
|
+
} = this.props;
|
|
266
|
+
const {
|
|
267
|
+
y_axis_left_group_by_multiple_numeric_column
|
|
268
|
+
} = chart.config;
|
|
269
|
+
const currentTheme = _utils.BaseUtils.getCurrentTheme(chartColorTheme);
|
|
270
|
+
|
|
271
|
+
// left color map
|
|
272
|
+
if (y_axis_left_group_by_multiple_numeric_column) {
|
|
273
|
+
this.colorMap = data.reduce((acc, cur, index) => {
|
|
274
|
+
if (!acc[cur.group_name]) {
|
|
275
|
+
acc[cur.group_name] = cur.color;
|
|
276
|
+
}
|
|
277
|
+
return acc;
|
|
278
|
+
}, {});
|
|
279
|
+
} else {
|
|
280
|
+
this.colorMap = {
|
|
281
|
+
[leftSummaryColumn.name]: currentTheme.colors[0]
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// right color map
|
|
286
|
+
const name = rightSummaryColumn.name + ' '; // Add a space character to avoid merging with the previous left legend
|
|
287
|
+
this.colorMap[name] = currentTheme.colors[1];
|
|
288
|
+
};
|
|
289
|
+
this.drawRightContent = (data, fx, rightY, showRightValue, rightSummaryColumn, rightTitle) => {
|
|
290
|
+
const {
|
|
291
|
+
chart,
|
|
292
|
+
chartColorTheme,
|
|
293
|
+
globalTheme
|
|
294
|
+
} = this.props;
|
|
295
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
296
|
+
const currentTheme = _utils.BaseUtils.getCurrentTheme(chartColorTheme);
|
|
297
|
+
const {
|
|
298
|
+
line_type,
|
|
299
|
+
label_font_size,
|
|
300
|
+
y_axis_right_summary_column
|
|
301
|
+
} = chart.config;
|
|
302
|
+
const circleData = data.map(() => ({}));
|
|
303
|
+
const line = d3.line().x((d, index) => {
|
|
304
|
+
const x = fx(d.name) + fx.bandwidth() / 2;
|
|
305
|
+
circleData[index]['x'] = x;
|
|
306
|
+
circleData[index]['name'] = d.name;
|
|
307
|
+
return x;
|
|
308
|
+
}).y((d, index) => {
|
|
309
|
+
const y = rightY(d.value_right);
|
|
310
|
+
circleData[index]['y'] = y;
|
|
311
|
+
circleData[index]['value'] = d.value_right;
|
|
312
|
+
return y;
|
|
313
|
+
}).curve(line_type === _constants.CHART_LINE_TYPES[1] ? d3.curveBumpX : d3.curveLinear);
|
|
314
|
+
const rightContentWrapper = this.chart.append('g').attr('class', 'lines-wrapper');
|
|
315
|
+
|
|
316
|
+
// line
|
|
317
|
+
rightContentWrapper.append('path').attr('fill', 'none').attr('stroke', currentTheme.colors[1]).attr('stroke-width', 2).attr('d', () => line(data));
|
|
318
|
+
|
|
319
|
+
// circle
|
|
320
|
+
circleData.forEach(item => {
|
|
321
|
+
rightContentWrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', currentTheme.colors[1]).attr('data-text', item.value).attr('data-name', item.name).call(g => {
|
|
322
|
+
// circle label
|
|
323
|
+
if (showRightValue) {
|
|
324
|
+
const curCircleEl = g.node();
|
|
325
|
+
rightContentWrapper.append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(_utils.BaseUtils.getSummaryValueDisplayString(rightSummaryColumn, Number(curCircleEl.getAttribute('data-text')), y_axis_right_summary_column)).call(g => {
|
|
326
|
+
const {
|
|
327
|
+
width
|
|
328
|
+
} = g.node().getBoundingClientRect();
|
|
329
|
+
const translateX = Number(curCircleEl.getAttribute('cx')) - width / 2;
|
|
330
|
+
const translateY = Number(curCircleEl.getAttribute('cy')) - 10;
|
|
331
|
+
g.attr('transform', "translate(".concat(translateX, ", ").concat(translateY, ")"));
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}).on('mouseover', event => {
|
|
335
|
+
this.updateCombinationCircleStyle(event, 'zoomIn');
|
|
336
|
+
this.showTooltip(event, {
|
|
337
|
+
isCircle: true,
|
|
338
|
+
rightSummaryColumn,
|
|
339
|
+
rightTitle
|
|
340
|
+
});
|
|
341
|
+
}).on('mousemove', event => {
|
|
342
|
+
this.moveTooltip(event);
|
|
343
|
+
}).on('mouseleave', event => {
|
|
344
|
+
this.hiddenTooltip();
|
|
345
|
+
this.updateCombinationCircleStyle(event, 'zoomOut');
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
this.showTooltip = (event, _ref4) => {
|
|
350
|
+
let {
|
|
351
|
+
isCircle,
|
|
352
|
+
leftSummaryColumn,
|
|
353
|
+
leftTitle,
|
|
354
|
+
rightSummaryColumn,
|
|
355
|
+
rightTitle
|
|
356
|
+
} = _ref4;
|
|
357
|
+
const {
|
|
358
|
+
chart,
|
|
359
|
+
chartColorTheme
|
|
360
|
+
} = this.props;
|
|
361
|
+
const {
|
|
362
|
+
y_axis_left_summary_method,
|
|
363
|
+
y_axis_left_group_by_multiple_numeric_column,
|
|
364
|
+
y_axis_right_summary_method
|
|
365
|
+
} = chart.config;
|
|
366
|
+
const currentTheme = _utils.BaseUtils.getCurrentTheme(chartColorTheme);
|
|
367
|
+
const {
|
|
368
|
+
offsetX,
|
|
369
|
+
offsetY
|
|
370
|
+
} = event;
|
|
371
|
+
const newTooltipData = {};
|
|
372
|
+
if (isCircle) {
|
|
373
|
+
newTooltipData['title'] = !rightTitle && typeof rightTitle !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : rightTitle;
|
|
374
|
+
newTooltipData['items'] = [{
|
|
375
|
+
color: currentTheme.colors[1],
|
|
376
|
+
name: event.target.getAttribute('data-name'),
|
|
377
|
+
value: _utils.BaseUtils.getSummaryValueDisplayString(rightSummaryColumn, Number(event.target.getAttribute('data-text')), y_axis_right_summary_method)
|
|
378
|
+
}];
|
|
379
|
+
} else {
|
|
380
|
+
const curGroup = event.target.parentNode;
|
|
381
|
+
const [curGroupName, data] = curGroup.__data__;
|
|
382
|
+
newTooltipData['title'] = !curGroupName && typeof curGroupName !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : curGroupName;
|
|
383
|
+
newTooltipData['items'] = data.map(item => {
|
|
384
|
+
return {
|
|
385
|
+
color: y_axis_left_group_by_multiple_numeric_column ? this.colorMap[item.group_name] : currentTheme.colors[0],
|
|
386
|
+
name: y_axis_left_group_by_multiple_numeric_column ? item.group_name : leftTitle,
|
|
387
|
+
value: _utils.BaseUtils.getSummaryValueDisplayString(leftSummaryColumn, Number(item.value_left), y_axis_left_summary_method)
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
this.setState({
|
|
392
|
+
tooltipData: newTooltipData
|
|
393
|
+
});
|
|
394
|
+
this.setState({
|
|
395
|
+
toolTipPosition: {
|
|
396
|
+
offsetX,
|
|
397
|
+
offsetY
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
this.moveTooltip = event => {
|
|
402
|
+
const {
|
|
403
|
+
offsetX,
|
|
404
|
+
offsetY
|
|
405
|
+
} = event;
|
|
406
|
+
this.setState({
|
|
407
|
+
toolTipPosition: {
|
|
408
|
+
offsetX,
|
|
409
|
+
offsetY
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
this.hiddenTooltip = event => {
|
|
414
|
+
this.setState({
|
|
415
|
+
toolTipPosition: null
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
419
|
+
const curGroup = event.target.parentNode;
|
|
420
|
+
const allGroup = Array.from(curGroup.parentNode.children);
|
|
421
|
+
const [curGroupName] = curGroup.__data__;
|
|
422
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
423
|
+
};
|
|
424
|
+
this.updateCombinationCircleStyle = (event, state) => {
|
|
425
|
+
if (state === 'zoomIn') {
|
|
426
|
+
d3.select(event.currentTarget).transition().duration(this.transitionDuration).attr('r', 5);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const circles = d3.select(event.currentTarget.parentNode).selectAll('circle').nodes();
|
|
430
|
+
circles.forEach(circle => d3.select(circle).transition().duration(this.transitionDuration).attr('r', 3));
|
|
431
|
+
};
|
|
432
|
+
this.updateLastLegendToCircle = () => {
|
|
433
|
+
const legendWrapper = this.chart.select('.legend-wrapper').node();
|
|
434
|
+
if (legendWrapper) {
|
|
435
|
+
const lastLegendItem = Array.from(legendWrapper.children).at(-1);
|
|
436
|
+
const rectEl = d3.select(lastLegendItem).select('rect').node();
|
|
437
|
+
if (rectEl) {
|
|
438
|
+
d3.select(rectEl).attr('width', 12).attr('height', 12).attr('x', 5).attr('y', 2).attr('rx', 2);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
this.chart = null;
|
|
443
|
+
this.state = {
|
|
444
|
+
tooltipData: null,
|
|
445
|
+
toolTipPosition: null
|
|
446
|
+
};
|
|
447
|
+
this.valueFieldMap = {
|
|
448
|
+
value_left: ['Y_axis_(lift_side)', 'All'],
|
|
449
|
+
value_right: ['Y_axis_(right_side)', 'All']
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
componentDidMount() {
|
|
453
|
+
this.createChart();
|
|
454
|
+
this.drawChart();
|
|
455
|
+
this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
|
|
456
|
+
window.addEventListener('resize', this.debouncedHandleResize);
|
|
457
|
+
}
|
|
458
|
+
componentDidUpdate(prevProps) {
|
|
459
|
+
super.componentDidUpdate(prevProps);
|
|
460
|
+
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
461
|
+
this.createChart();
|
|
462
|
+
this.drawChart();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
componentWillUnmount() {
|
|
466
|
+
this.chart.node() && this.chart.node().remove();
|
|
467
|
+
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
468
|
+
}
|
|
469
|
+
render() {
|
|
470
|
+
const {
|
|
471
|
+
chart
|
|
472
|
+
} = this.props;
|
|
473
|
+
const {
|
|
474
|
+
tooltipData,
|
|
475
|
+
toolTipPosition
|
|
476
|
+
} = this.state;
|
|
477
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
478
|
+
ref: ref => this.container = ref,
|
|
479
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
480
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
481
|
+
'show-y-axis-left-label': this.isShowYAxisLeftLabel(chart),
|
|
482
|
+
'show-y-axis-right-label': this.isShowYAxisRightLabel(chart)
|
|
483
|
+
})
|
|
484
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
485
|
+
tooltipData: tooltipData,
|
|
486
|
+
toolTipPosition: toolTipPosition,
|
|
487
|
+
chart: this.chart
|
|
488
|
+
}));
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
Combination.propTypes = {
|
|
492
|
+
canvasStyle: _propTypes.default.object,
|
|
493
|
+
chart: _propTypes.default.object,
|
|
494
|
+
groupbyColumn: _propTypes.default.object,
|
|
495
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
496
|
+
summaryColumn: _propTypes.default.object,
|
|
497
|
+
result: _propTypes.default.array,
|
|
498
|
+
tables: _propTypes.default.array,
|
|
499
|
+
globalTheme: _propTypes.default.string,
|
|
500
|
+
chartColorTheme: _propTypes.default.string,
|
|
501
|
+
toggleRecords: _propTypes.default.func,
|
|
502
|
+
customRender: _propTypes.default.func
|
|
503
|
+
};
|
|
504
|
+
var _default = exports.default = Combination;
|
|
@@ -76,7 +76,7 @@ class Completeness extends _chartComponent.default {
|
|
|
76
76
|
// Y axis
|
|
77
77
|
const fy = d3.scaleBand().domain(newSeries.map(item => item[0])).range([chartHeight - insertPadding, insertPadding]).paddingInner(0.5).paddingOuter(0.1);
|
|
78
78
|
const y = d3.scaleBand().domain(new Set(data.map(d => d.groupby))).range([0, fy.bandwidth()]).paddingInner(0).paddingOuter(0);
|
|
79
|
-
const yAxis = this.chart.append('g').call(d3.axisLeft(fy).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
79
|
+
const yAxis = this.chart.append('g').attr('class', 'y-axis-wrapper').call(d3.axisLeft(fy).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
80
80
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
81
81
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
82
82
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
@@ -93,7 +93,7 @@ class Completeness extends _chartComponent.default {
|
|
|
93
93
|
const allSeries = this.getAllSeries(newSeries);
|
|
94
94
|
const niceEnd = d3.nice(0, d3.max(allSeries, d => d.sumValue), 5)[1];
|
|
95
95
|
const x = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min || 0, y_axis_max || niceEnd]).range([Number(yAxis.node().getAttribute('data-axisWidth')), chartWidth - insertPadding - marginRight]);
|
|
96
|
-
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5)).call(g => {
|
|
96
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5)).call(g => {
|
|
97
97
|
g.selectAll('.domain').remove();
|
|
98
98
|
g.selectAll('.tick line').node() && g.selectAll('.tick line').node().remove(); // delete the first line
|
|
99
99
|
g.selectAll('.tick line').attr('y2', -(chartHeight - insertPadding * 2)).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
@@ -102,8 +102,8 @@ class Completeness extends _chartComponent.default {
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
// Rect group
|
|
105
|
-
const
|
|
106
|
-
|
|
105
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper').attr('transform', "translate(".concat(Number(yAxis.node().getAttribute('data-axisWidth')), ", 0)"));
|
|
106
|
+
contentWrapper.selectAll().data(newSeries).join('g').attr('transform', _ref => {
|
|
107
107
|
let [name, dum] = _ref;
|
|
108
108
|
const offset = (fy.bandwidth() - dum.length * y.bandwidth()) / 2;
|
|
109
109
|
return "translate(0, ".concat(fy(name) + offset, ")");
|
|
@@ -124,7 +124,7 @@ class Completeness extends _chartComponent.default {
|
|
|
124
124
|
}).selectAll().data(_ref5 => {
|
|
125
125
|
let [_, d] = _ref5;
|
|
126
126
|
return d;
|
|
127
|
-
}).join('rect').attr('class', 'rect').attr('x', d => x(d[0]) - Number(yAxis.node().getAttribute('data-axisWidth'))).attr('y', d => y.bandwidth() * d.serieIndex).attr('data-y', d => y.bandwidth() * d.serieIndex).attr('width', d => x(d[1]) - x(d[0])).attr('height', y.bandwidth()).attr('fill', d => {
|
|
127
|
+
}).join('rect').attr('class', 'rect').attr('opacity', 1).attr('x', d => x(d[0]) - Number(yAxis.node().getAttribute('data-axisWidth'))).attr('y', d => y.bandwidth() * d.serieIndex).attr('data-y', d => y.bandwidth() * d.serieIndex).attr('width', d => x(d[1]) - x(d[0])).attr('height', y.bandwidth()).attr('fill', d => {
|
|
128
128
|
const key = d.key;
|
|
129
129
|
const groupby = d.rawData.groupby;
|
|
130
130
|
if (key === 'rest') {
|
|
@@ -136,7 +136,7 @@ class Completeness extends _chartComponent.default {
|
|
|
136
136
|
return colors[0];
|
|
137
137
|
}).attr('data-value', d => d.rawData.value).attr('data-groupName', d => d.rawData.slugId).attr('data-tooltipTitle', d => d.rawData.name).attr('data-tooltipName', d => d.key).attr('data-groupBy', d => d.rawData.groupby).call(g => {
|
|
138
138
|
// add rect borderRadius
|
|
139
|
-
const allGroup = this.getAllGroup(
|
|
139
|
+
const allGroup = this.getAllGroup(contentWrapper);
|
|
140
140
|
allGroup.forEach(group => {
|
|
141
141
|
group.forEach(rects => {
|
|
142
142
|
const firstEl = rects[0];
|
|
@@ -146,7 +146,7 @@ class Completeness extends _chartComponent.default {
|
|
|
146
146
|
|
|
147
147
|
// Add label
|
|
148
148
|
if (show_percentage) {
|
|
149
|
-
const newAllGroup = this.getAllGroup(
|
|
149
|
+
const newAllGroup = this.getAllGroup(contentWrapper);
|
|
150
150
|
newAllGroup.forEach(group => {
|
|
151
151
|
group.forEach(rects => {
|
|
152
152
|
const firstEl = rects[0];
|
|
@@ -184,9 +184,9 @@ class Completeness extends _chartComponent.default {
|
|
|
184
184
|
});
|
|
185
185
|
};
|
|
186
186
|
this.handleAcitveAndInActiveState = (state, event) => {
|
|
187
|
-
const
|
|
187
|
+
const contentWrapper = Array.from(event.currentTarget.parentNode.parentNode.parentNode.children);
|
|
188
188
|
const allGroup = [];
|
|
189
|
-
|
|
189
|
+
contentWrapper.forEach(g => {
|
|
190
190
|
const groups = Array.from(g.children);
|
|
191
191
|
groups.forEach(groupRect => {
|
|
192
192
|
const rects = Array.from(groupRect.children);
|
|
@@ -299,9 +299,9 @@ class Completeness extends _chartComponent.default {
|
|
|
299
299
|
});
|
|
300
300
|
return allSeries;
|
|
301
301
|
};
|
|
302
|
-
this.getAllGroup =
|
|
302
|
+
this.getAllGroup = contentWrapper => {
|
|
303
303
|
const allGroup = [];
|
|
304
|
-
Array.from(
|
|
304
|
+
Array.from(contentWrapper.node().children).forEach(item => {
|
|
305
305
|
const group = [];
|
|
306
306
|
Array.from(item.children).forEach(jtem => {
|
|
307
307
|
const childGroup = [];
|
|
@@ -323,7 +323,7 @@ class Completeness extends _chartComponent.default {
|
|
|
323
323
|
borderRadius
|
|
324
324
|
} = this.chartBoundingClientRect;
|
|
325
325
|
// Add mask rect
|
|
326
|
-
d3.select(topG).append('foreignObject').attr('class', rect.getAttribute('class')).attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('data-y', rect.parentNode.parentNode.getAttribute('data-transform')).attr('width', rect.getAttribute('width')).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-tooltipTitle', rect.getAttribute('data-tooltipTitle')).attr('data-tooltipName', rect.getAttribute('data-tooltipName')).attr('data-groupBy', rect.getAttribute('data-groupBy')).attr('data-x', () => {
|
|
326
|
+
d3.select(topG).append('foreignObject').attr('class', rect.getAttribute('class')).attr('opacity', rect.getAttribute('opacity')).attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('data-y', rect.parentNode.parentNode.getAttribute('data-transform')).attr('width', rect.getAttribute('width')).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-tooltipTitle', rect.getAttribute('data-tooltipTitle')).attr('data-tooltipName', rect.getAttribute('data-tooltipName')).attr('data-groupBy', rect.getAttribute('data-groupBy')).attr('data-x', () => {
|
|
327
327
|
const x = Number(rect.getAttribute('x'));
|
|
328
328
|
return x + Number(yAxis.node().getAttribute('data-axisWidth'));
|
|
329
329
|
}).on('click', (event, data) => {
|
|
@@ -77,7 +77,7 @@ class Completeness extends _chartComponent.default {
|
|
|
77
77
|
|
|
78
78
|
// Y axis
|
|
79
79
|
const y = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([chartHeight - insertPadding, insertPadding]).paddingInner(0.5).paddingOuter(0.1);
|
|
80
|
-
const yAxis = this.chart.append('g').call(d3.axisLeft(y).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
80
|
+
const yAxis = this.chart.append('g').attr('class', 'y-axis-wrapper').call(d3.axisLeft(y).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
81
81
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
82
82
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
83
83
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
@@ -93,7 +93,7 @@ class Completeness extends _chartComponent.default {
|
|
|
93
93
|
// X axis
|
|
94
94
|
const niceEnd = d3.nice(0, d3.max(newSeries, d => d[1].sumValue), 5)[1];
|
|
95
95
|
const x = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min || 0, y_axis_max || niceEnd]).range([Number(yAxis.node().getAttribute('data-axisWidth')), chartWidth - insertPadding - marginRight]);
|
|
96
|
-
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5)).call(g => {
|
|
96
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5)).call(g => {
|
|
97
97
|
g.selectAll('.domain').remove();
|
|
98
98
|
g.selectAll('.tick line').node() && g.selectAll('.tick line').node().remove(); // delete the first line
|
|
99
99
|
g.selectAll('.tick line').attr('y2', -(chartHeight - insertPadding * 2)).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
@@ -102,8 +102,8 @@ class Completeness extends _chartComponent.default {
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
// Rect group
|
|
105
|
-
const
|
|
106
|
-
|
|
105
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper').attr('transform', "translate(".concat(Number(yAxis.node().getAttribute('data-axisWidth')), ", 0)"));
|
|
106
|
+
contentWrapper.selectAll().data(newSeries).join('g').attr('data-completedRate', d => {
|
|
107
107
|
const restData = d[1].find(item => item.key === 'rest');
|
|
108
108
|
const completedRate = restData.data.completedRate;
|
|
109
109
|
if (completedRate === 'empty') return '';
|
|
@@ -112,13 +112,13 @@ class Completeness extends _chartComponent.default {
|
|
|
112
112
|
let [groupKey, d] = _ref2;
|
|
113
113
|
d.forEach(item => item['groupKey'] = groupKey);
|
|
114
114
|
return d;
|
|
115
|
-
}).join('rect').attr('x', (d, index) => {
|
|
115
|
+
}).join('rect').attr('opacity', 1).attr('x', (d, index) => {
|
|
116
116
|
return x(d[0]) - Number(yAxis.node().getAttribute('data-axisWidth'));
|
|
117
117
|
}).attr('y', (d, index) => y(d.groupKey)).attr('width', d => x(d[1]) - x(d[0])).attr('height', y.bandwidth()).attr('fill', d => {
|
|
118
118
|
return d.key === 'rest' ? '#bdbdbd' : colors[0];
|
|
119
119
|
}).attr('data-value', d => d.data.value).attr('data-groupName', d => d.data.slugId).attr('data-tooltipTitle', d => d.groupKey).attr('data-tooltipName', d => d.key).call(g => {
|
|
120
120
|
// add rect borderRadius
|
|
121
|
-
const allGroup = this.getAllGroup(
|
|
121
|
+
const allGroup = this.getAllGroup(contentWrapper);
|
|
122
122
|
allGroup.forEach(group => {
|
|
123
123
|
const firstEl = group[0];
|
|
124
124
|
firstEl && this.addMaskRect(firstEl === null || firstEl === void 0 ? void 0 : firstEl.parentNode, firstEl, yAxis);
|
|
@@ -126,7 +126,7 @@ class Completeness extends _chartComponent.default {
|
|
|
126
126
|
|
|
127
127
|
// Add label
|
|
128
128
|
if (show_percentage) {
|
|
129
|
-
const newAllGroup = this.getAllGroup(
|
|
129
|
+
const newAllGroup = this.getAllGroup(contentWrapper);
|
|
130
130
|
newAllGroup.forEach(group => {
|
|
131
131
|
const firstEl = group[0];
|
|
132
132
|
firstEl && this.addLabelToRectRight({
|
|
@@ -246,9 +246,9 @@ class Completeness extends _chartComponent.default {
|
|
|
246
246
|
});
|
|
247
247
|
return newSeries;
|
|
248
248
|
};
|
|
249
|
-
this.getAllGroup =
|
|
249
|
+
this.getAllGroup = contentWrapper => {
|
|
250
250
|
const allGroup = [];
|
|
251
|
-
Array.from(
|
|
251
|
+
Array.from(contentWrapper.node().children).forEach(item => {
|
|
252
252
|
const group = [];
|
|
253
253
|
Array.from(item.children).forEach(child => {
|
|
254
254
|
if (Number(child.getAttribute('width')) !== 0) {
|
|
@@ -266,7 +266,7 @@ class Completeness extends _chartComponent.default {
|
|
|
266
266
|
borderRadius
|
|
267
267
|
} = this.chartBoundingClientRect;
|
|
268
268
|
// Add mask rect
|
|
269
|
-
d3.select(topG).append('foreignObject').attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('width', rect.getAttribute('width')).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-tooltipTitle', rect.getAttribute('data-tooltipTitle')).attr('data-tooltipName', rect.getAttribute('data-tooltipName')).attr('data-x', () => {
|
|
269
|
+
d3.select(topG).append('foreignObject').attr('opacity', rect.getAttribute('opacity')).attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('width', rect.getAttribute('width')).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).attr('data-tooltipTitle', rect.getAttribute('data-tooltipTitle')).attr('data-tooltipName', rect.getAttribute('data-tooltipName')).attr('data-x', () => {
|
|
270
270
|
const x = Number(rect.getAttribute('x'));
|
|
271
271
|
return x + Number(yAxis.node().getAttribute('data-axisWidth'));
|
|
272
272
|
}).on('click', (event, data) => {
|