sea-chart 2.0.21 → 2.0.23
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 +125 -29
- 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/dist/view/wrapper/scatter.js +1 -1
- package/package.json +1 -1
|
@@ -69,7 +69,8 @@ class BarStack extends _chartComponent.default {
|
|
|
69
69
|
globalTheme,
|
|
70
70
|
chartColorTheme,
|
|
71
71
|
tables,
|
|
72
|
-
columnGroupbyColumn
|
|
72
|
+
columnGroupbyColumn,
|
|
73
|
+
summaryColumn
|
|
73
74
|
} = this.props;
|
|
74
75
|
const {
|
|
75
76
|
display_goal_line,
|
|
@@ -78,6 +79,7 @@ class BarStack extends _chartComponent.default {
|
|
|
78
79
|
} = chart.style_config || {};
|
|
79
80
|
const {
|
|
80
81
|
y_axis_show_value,
|
|
82
|
+
y_axis_summary_method,
|
|
81
83
|
display_each_block_data,
|
|
82
84
|
table_id,
|
|
83
85
|
column_groupby_column_key,
|
|
@@ -107,11 +109,11 @@ class BarStack extends _chartComponent.default {
|
|
|
107
109
|
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
108
110
|
|
|
109
111
|
// Y axis
|
|
110
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
|
|
112
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
111
113
|
const x = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.5).paddingOuter(0.1);
|
|
112
114
|
|
|
113
115
|
// X axis
|
|
114
|
-
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
116
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
115
117
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
116
118
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
117
119
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
@@ -120,14 +122,14 @@ class BarStack extends _chartComponent.default {
|
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
// Rect group
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
+
this.contentWrapper = this.chart.append('g').attr('class', 'content-wrapper');
|
|
126
|
+
this.contentWrapper.selectAll().data(series).join('g').attr('data-key', d => d.key).selectAll('rect').data(D => {
|
|
125
127
|
const data = D.map(d => {
|
|
126
128
|
d.key = D.key;
|
|
127
129
|
return d;
|
|
128
130
|
});
|
|
129
131
|
return data;
|
|
130
|
-
}).join('rect').attr('x', d => x(d.data[0])).attr('y', d => y(d[1])).attr('height', d => {
|
|
132
|
+
}).join('rect').attr('opacity', 1).attr('x', d => x(d.data[0])).attr('y', d => y(d[1])).attr('height', d => {
|
|
131
133
|
const height = y(d[0]) - y(d[1]);
|
|
132
134
|
return (0, _lodashEs.isNaN)(height) ? 0 : height;
|
|
133
135
|
}).attr('width', x.bandwidth()).attr('fill', d => this.colorMap[d.key] || _constants.CHART_STYLE_COLORS[0]).attr('data-value', d => {
|
|
@@ -202,6 +204,13 @@ class BarStack extends _chartComponent.default {
|
|
|
202
204
|
return groupRects;
|
|
203
205
|
};
|
|
204
206
|
this.showTooltip = event => {
|
|
207
|
+
const {
|
|
208
|
+
summaryColumn,
|
|
209
|
+
chart
|
|
210
|
+
} = this.props;
|
|
211
|
+
const {
|
|
212
|
+
y_axis_summary_method
|
|
213
|
+
} = chart;
|
|
205
214
|
const offsetX = d3.pointer(event)[0];
|
|
206
215
|
const offsetY = d3.pointer(event)[1];
|
|
207
216
|
const curRect = event.currentTarget;
|
|
@@ -212,7 +221,7 @@ class BarStack extends _chartComponent.default {
|
|
|
212
221
|
items: [{
|
|
213
222
|
color: this.colorMap[curGroup.getAttribute('data-key')],
|
|
214
223
|
name: curGroup.getAttribute('data-key'),
|
|
215
|
-
value: curRect.getAttribute('data-value')
|
|
224
|
+
value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(curRect.getAttribute('data-value')), y_axis_summary_method)
|
|
216
225
|
}]
|
|
217
226
|
};
|
|
218
227
|
this.setState({
|
|
@@ -241,7 +250,7 @@ class BarStack extends _chartComponent.default {
|
|
|
241
250
|
});
|
|
242
251
|
};
|
|
243
252
|
this.handleAcitveAndInActiveState = (state, event) => {
|
|
244
|
-
const allGroup = Array.from(this.
|
|
253
|
+
const allGroup = Array.from(this.contentWrapper.node().children);
|
|
245
254
|
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
246
255
|
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
247
256
|
};
|
|
@@ -250,7 +259,7 @@ class BarStack extends _chartComponent.default {
|
|
|
250
259
|
borderRadius
|
|
251
260
|
} = this.chartBoundingClientRect;
|
|
252
261
|
// Add mask rect
|
|
253
|
-
d3.select(topG).append('foreignObject').attr('x', rect.getAttribute('x')).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')).on('click', (event, data) => {
|
|
262
|
+
d3.select(topG).append('foreignObject').attr('x', rect.getAttribute('x')).attr('y', rect.getAttribute('y')).attr('opacity', rect.getAttribute('opacity')).attr('width', xWidth).attr('height', rect.getAttribute('height')).attr('data-groupName', rect.getAttribute('data-groupName')).attr('data-value', rect.getAttribute('data-value')).on('click', (event, data) => {
|
|
254
263
|
this.props.toggleRecords(data);
|
|
255
264
|
}).on('mouseover', event => {
|
|
256
265
|
this.showTooltip(event);
|
|
@@ -268,10 +277,12 @@ class BarStack extends _chartComponent.default {
|
|
|
268
277
|
this.addLabelByEachStack = (data, topG, rect, x) => {
|
|
269
278
|
const {
|
|
270
279
|
globalTheme,
|
|
271
|
-
chart
|
|
280
|
+
chart,
|
|
281
|
+
summaryColumn
|
|
272
282
|
} = this.props;
|
|
273
283
|
const {
|
|
274
|
-
label_font_size
|
|
284
|
+
label_font_size,
|
|
285
|
+
y_axis_summary_method
|
|
275
286
|
} = chart.config;
|
|
276
287
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
277
288
|
const groupData = d3.group(data, d => d.name);
|
|
@@ -285,16 +296,18 @@ class BarStack extends _chartComponent.default {
|
|
|
285
296
|
y: Number(rect.getAttribute('y')),
|
|
286
297
|
theme,
|
|
287
298
|
label_font_size,
|
|
288
|
-
text: stackSum
|
|
299
|
+
text: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(stackSum), y_axis_summary_method)
|
|
289
300
|
});
|
|
290
301
|
};
|
|
291
302
|
this.handleLabelToRectCenter = (g, xWidth) => {
|
|
292
303
|
const {
|
|
293
304
|
globalTheme,
|
|
294
|
-
chart
|
|
305
|
+
chart,
|
|
306
|
+
summaryColumn
|
|
295
307
|
} = this.props;
|
|
296
308
|
const {
|
|
297
|
-
label_font_size
|
|
309
|
+
label_font_size,
|
|
310
|
+
y_axis_summary_method
|
|
298
311
|
} = chart.config;
|
|
299
312
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
300
313
|
g._parents.forEach(group => {
|
|
@@ -309,7 +322,7 @@ class BarStack extends _chartComponent.default {
|
|
|
309
322
|
yheight: Number(rect.getAttribute('height')),
|
|
310
323
|
theme,
|
|
311
324
|
label_font_size,
|
|
312
|
-
text: rect.getAttribute('data-value')
|
|
325
|
+
text: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(rect.getAttribute('data-value')), y_axis_summary_method)
|
|
313
326
|
});
|
|
314
327
|
});
|
|
315
328
|
});
|
package/dist/view/wrapper/bar.js
CHANGED
|
@@ -79,6 +79,13 @@ class Bar extends _chartComponent.default {
|
|
|
79
79
|
return color || chartBarColor;
|
|
80
80
|
};
|
|
81
81
|
this.showTooltip = (event, data, title) => {
|
|
82
|
+
const {
|
|
83
|
+
summaryColumn,
|
|
84
|
+
chart
|
|
85
|
+
} = this.props;
|
|
86
|
+
const {
|
|
87
|
+
y_axis_summary_method
|
|
88
|
+
} = chart.config;
|
|
82
89
|
const {
|
|
83
90
|
offsetX,
|
|
84
91
|
offsetY
|
|
@@ -88,7 +95,7 @@ class Bar extends _chartComponent.default {
|
|
|
88
95
|
items: [{
|
|
89
96
|
color: this.getFillColor(data),
|
|
90
97
|
name: data.name,
|
|
91
|
-
value: data.value
|
|
98
|
+
value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(data.value), y_axis_summary_method)
|
|
92
99
|
}]
|
|
93
100
|
};
|
|
94
101
|
this.setState({
|
|
@@ -127,7 +134,8 @@ class Bar extends _chartComponent.default {
|
|
|
127
134
|
const {
|
|
128
135
|
chart,
|
|
129
136
|
globalTheme,
|
|
130
|
-
tables
|
|
137
|
+
tables,
|
|
138
|
+
summaryColumn
|
|
131
139
|
} = this.props;
|
|
132
140
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
133
141
|
const {
|
|
@@ -137,6 +145,7 @@ class Bar extends _chartComponent.default {
|
|
|
137
145
|
} = chart.style_config || {};
|
|
138
146
|
const {
|
|
139
147
|
y_axis_summary_type,
|
|
148
|
+
y_axis_summary_method,
|
|
140
149
|
y_axis_summary_column_key,
|
|
141
150
|
y_axis_column_key,
|
|
142
151
|
y_axis_show_value,
|
|
@@ -154,28 +163,32 @@ class Bar extends _chartComponent.default {
|
|
|
154
163
|
marginTop
|
|
155
164
|
} = this.chartBoundingClientRect;
|
|
156
165
|
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]);
|
|
157
|
-
|
|
166
|
+
|
|
167
|
+
// Y axis
|
|
168
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
158
169
|
const x = d3.scaleBand().domain(data.map(item => item.name)).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.5).paddingOuter(0.1);
|
|
159
|
-
|
|
170
|
+
|
|
171
|
+
// X axis
|
|
172
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
160
173
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
161
174
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
162
175
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
163
176
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
164
177
|
this.checkTickOverlap(g);
|
|
165
178
|
});
|
|
166
|
-
const
|
|
167
|
-
|
|
179
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper');
|
|
180
|
+
contentWrapper.selectAll().data(data).join('rect').attr('opacity', 1).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('data-slugid', d => d.slugId).attr('x', d => x(d.name)).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value)).call(g => {
|
|
168
181
|
g.nodes().forEach(path => {
|
|
169
182
|
// Add label
|
|
170
183
|
if (y_axis_show_value) {
|
|
171
184
|
this.addLabelToRectTop({
|
|
172
|
-
container:
|
|
185
|
+
container: contentWrapper.node(),
|
|
173
186
|
xWidth: Number(path.dataset.width),
|
|
174
187
|
x: Number(path.dataset.x),
|
|
175
188
|
y: Number(path.dataset.y),
|
|
176
189
|
theme,
|
|
177
190
|
label_font_size,
|
|
178
|
-
text: path.dataset.value
|
|
191
|
+
text: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(path.dataset.value), y_axis_summary_method)
|
|
179
192
|
});
|
|
180
193
|
}
|
|
181
194
|
// add rect borderRadius
|
|
@@ -192,8 +205,8 @@ class Bar extends _chartComponent.default {
|
|
|
192
205
|
this.handleAcitveAndInActiveState('inActive', event);
|
|
193
206
|
}).on('mousemove', event => {
|
|
194
207
|
this.moveTooltip(event);
|
|
195
|
-
}).on('mouseleave',
|
|
196
|
-
this.hiddenTooltip();
|
|
208
|
+
}).on('mouseleave', event => {
|
|
209
|
+
this.hiddenTooltip(event);
|
|
197
210
|
this.handleAcitveAndInActiveState('active', event);
|
|
198
211
|
});
|
|
199
212
|
if (display_goal_line && goal_label && goal_value) {
|
|
@@ -13,7 +13,6 @@ var _dtableUtils = require("dtable-utils");
|
|
|
13
13
|
var _utils = require("../../utils");
|
|
14
14
|
var _constants = require("../../constants");
|
|
15
15
|
var _intl = _interopRequireDefault(require("../../intl"));
|
|
16
|
-
var _columnUtils = require("../../utils/column-utils");
|
|
17
16
|
require("../../assets/css/sea-chart-d3-tooltip.css");
|
|
18
17
|
class ChartComponent extends _react.Component {
|
|
19
18
|
constructor(props) {
|
|
@@ -57,9 +56,10 @@ class ChartComponent extends _react.Component {
|
|
|
57
56
|
} = container.getBoundingClientRect();
|
|
58
57
|
const {
|
|
59
58
|
marginLeft = 0,
|
|
59
|
+
marginRight = 0,
|
|
60
60
|
marginBottom = 0
|
|
61
61
|
} = initConfig;
|
|
62
|
-
const width = containerWidth - marginLeft;
|
|
62
|
+
const width = containerWidth - marginLeft - marginRight;
|
|
63
63
|
const height = containerHeight - marginBottom;
|
|
64
64
|
_this.chart = d3.create('svg').attr('id', id).attr('width', width).attr('height', height).attr('viewBox', [0, 0, width, height]);
|
|
65
65
|
_this.container.appendChild(_this.chart.node());
|
|
@@ -239,7 +239,17 @@ class ChartComponent extends _react.Component {
|
|
|
239
239
|
x_axis_label_position,
|
|
240
240
|
y_axis_summary_type,
|
|
241
241
|
type,
|
|
242
|
-
title_name
|
|
242
|
+
title_name,
|
|
243
|
+
// left axis - combination chart
|
|
244
|
+
show_y_axis_left_label,
|
|
245
|
+
y_axis_left_label_position,
|
|
246
|
+
y_axis_left_summary_type,
|
|
247
|
+
y_axis_left_summary_column,
|
|
248
|
+
// right axis - combination chart
|
|
249
|
+
show_y_axis_right_label,
|
|
250
|
+
y_axis_right_label_position,
|
|
251
|
+
y_axis_right_summary_type,
|
|
252
|
+
y_axis_right_summary_column
|
|
243
253
|
} = chart.config;
|
|
244
254
|
if (y_axis_summary_column_key) {
|
|
245
255
|
y_axis_column_key = y_axis_summary_column_key;
|
|
@@ -247,6 +257,8 @@ class ChartComponent extends _react.Component {
|
|
|
247
257
|
const table = (0, _dtableUtils.getTableById)(tables, table_id);
|
|
248
258
|
let textColor;
|
|
249
259
|
this.globalTheme === _constants.THEME_NAME_MAP.DARK ? textColor = '#fff' : textColor = '#999';
|
|
260
|
+
|
|
261
|
+
// xAxis
|
|
250
262
|
const xAxisID = "chart-x-axis-label_".concat(chart.id);
|
|
251
263
|
const xLabel = chartContainer === null || chartContainer === void 0 ? void 0 : chartContainer.querySelector("#".concat(xAxisID));
|
|
252
264
|
const {
|
|
@@ -267,6 +279,8 @@ class ChartComponent extends _react.Component {
|
|
|
267
279
|
if (xLabel && !x_axis_show_label) {
|
|
268
280
|
xLabel.parentNode.removeChild(xLabel);
|
|
269
281
|
}
|
|
282
|
+
|
|
283
|
+
// yAxis
|
|
270
284
|
const yAxisID = "chart-y-axis-label_".concat(chart.id);
|
|
271
285
|
const yLabel = chartContainer.querySelector("#".concat(yAxisID));
|
|
272
286
|
const divHeight = 20;
|
|
@@ -304,6 +318,68 @@ class ChartComponent extends _react.Component {
|
|
|
304
318
|
if (yLabel && !y_axis_show_label) {
|
|
305
319
|
yLabel.parentNode.removeChild(yLabel);
|
|
306
320
|
}
|
|
321
|
+
|
|
322
|
+
// yAxis(left) - combination chart
|
|
323
|
+
const yAxisLeftID = "chart-y-axis-left-label_".concat(chart.id);
|
|
324
|
+
const yAxisLeftLabel = chartContainer.querySelector("#".concat(yAxisLeftID));
|
|
325
|
+
if (!yAxisLeftLabel && show_y_axis_left_label) {
|
|
326
|
+
const div = document.createElement('div');
|
|
327
|
+
div.id = yAxisLeftID;
|
|
328
|
+
div.className = 'chart-axis-label text-truncate';
|
|
329
|
+
if (y_axis_left_summary_type === _constants.CHART_SUMMARY_TYPE.COUNT) {
|
|
330
|
+
div.innerHTML = _intl.default.get('Amount');
|
|
331
|
+
} else {
|
|
332
|
+
const column = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_left_summary_column) || {};
|
|
333
|
+
div.innerHTML = column.name || '';
|
|
334
|
+
}
|
|
335
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
336
|
+
let textAlign = 'center';
|
|
337
|
+
if (y_axis_left_label_position === _constants.LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
338
|
+
if (y_axis_left_label_position === _constants.LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
339
|
+
div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; height: ").concat(divHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 - divHeight / 2, "px, ").concat(containerHeight / 2 - divHeight / 2, "px) rotate(-90deg)"));
|
|
340
|
+
chartContainer.appendChild(div);
|
|
341
|
+
}
|
|
342
|
+
if (yAxisLeftLabel && show_y_axis_left_label) {
|
|
343
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
344
|
+
let textAlign = 'center';
|
|
345
|
+
if (y_axis_left_label_position === 'bottom') textAlign = 'left';
|
|
346
|
+
if (y_axis_left_label_position === 'top') textAlign = 'right';
|
|
347
|
+
yAxisLeftLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; height: ").concat(divHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 - divHeight / 2, "px, ").concat(containerHeight / 2 - divHeight / 2, "px) rotate(-90deg)"));
|
|
348
|
+
}
|
|
349
|
+
if (yAxisLeftLabel && !show_y_axis_left_label) {
|
|
350
|
+
yAxisLeftLabel.parentNode.removeChild(yAxisLeftLabel);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// yAxis(right) - combination chart
|
|
354
|
+
const yAxisRightID = "chart-y-axis-right-label_".concat(chart.id);
|
|
355
|
+
const yAxisRightLabel = chartContainer.querySelector("#".concat(yAxisRightID));
|
|
356
|
+
if (!yAxisRightLabel && show_y_axis_right_label) {
|
|
357
|
+
const div = document.createElement('div');
|
|
358
|
+
div.id = yAxisRightID;
|
|
359
|
+
div.className = 'chart-axis-label text-truncate';
|
|
360
|
+
if (y_axis_right_summary_type === _constants.CHART_SUMMARY_TYPE.COUNT) {
|
|
361
|
+
div.innerHTML = _intl.default.get('Amount');
|
|
362
|
+
} else {
|
|
363
|
+
const column = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_right_summary_column) || {};
|
|
364
|
+
div.innerHTML = column.name || '';
|
|
365
|
+
}
|
|
366
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
367
|
+
let textAlign = 'center';
|
|
368
|
+
if (y_axis_right_label_position === _constants.LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
369
|
+
if (y_axis_right_label_position === _constants.LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
370
|
+
div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; height: ").concat(divHeight, "px; text-align: ").concat(textAlign, "; top: 0; right: 0; transform: translate(").concat(containerHeight / 2 - divHeight / 2, "px, ").concat(containerHeight / 2 - divHeight / 2, "px) rotate(-90deg)"));
|
|
371
|
+
chartContainer.appendChild(div);
|
|
372
|
+
}
|
|
373
|
+
if (yAxisRightLabel && show_y_axis_right_label) {
|
|
374
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
375
|
+
let textAlign = 'center';
|
|
376
|
+
if (y_axis_right_label_position === 'bottom') textAlign = 'left';
|
|
377
|
+
if (y_axis_right_label_position === 'top') textAlign = 'right';
|
|
378
|
+
yAxisRightLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; height: ").concat(divHeight, "px; text-align: ").concat(textAlign, "; top: 0; right: 0; transform: translate(").concat(containerHeight / 2 - divHeight / 2, "px, ").concat(containerHeight / 2 - divHeight / 2, "px) rotate(-90deg)"));
|
|
379
|
+
}
|
|
380
|
+
if (yAxisRightLabel && !show_y_axis_right_label) {
|
|
381
|
+
yAxisRightLabel.parentNode.removeChild(yAxisRightLabel);
|
|
382
|
+
}
|
|
307
383
|
};
|
|
308
384
|
this.renderHorizontalLabel = (chart, tables, chartContainer) => {
|
|
309
385
|
if (!this.chart || !chart) return;
|
|
@@ -599,7 +675,8 @@ class ChartComponent extends _react.Component {
|
|
|
599
675
|
legendRectWidth: 20,
|
|
600
676
|
legendRectHeight: 6,
|
|
601
677
|
r: 3,
|
|
602
|
-
legendItemPaddingTop:
|
|
678
|
+
legendItemPaddingTop: 5,
|
|
679
|
+
legendItemTextPaddingTop: 13,
|
|
603
680
|
legendItemMargin: 20,
|
|
604
681
|
legendRecTextGap: 8,
|
|
605
682
|
legendPageNavWrapperWidth: 100,
|
|
@@ -622,6 +699,21 @@ class ChartComponent extends _react.Component {
|
|
|
622
699
|
const groupsData = this.getLegendDataGroups(legendData);
|
|
623
700
|
const legendWrapper = this.chart.append('g').attr('class', 'legend-wrapper');
|
|
624
701
|
|
|
702
|
+
// legend offset bottom and When there is only one line of legend, it is displayed in the center (for scatter chart)
|
|
703
|
+
if (bottomLegendSpace) {
|
|
704
|
+
queueMicrotask(() => {
|
|
705
|
+
let curTranslateX = 0;
|
|
706
|
+
const curTranslateY = bottomLegendSpace ? chartHeight - bottomLegendSpace : 0;
|
|
707
|
+
if (groupsData.length === 1) {
|
|
708
|
+
const {
|
|
709
|
+
width
|
|
710
|
+
} = legendWrapper.node().getBoundingClientRect();
|
|
711
|
+
curTranslateX = (chartWidth - width - insertPadding * 2) / 2;
|
|
712
|
+
}
|
|
713
|
+
legendWrapper.attr('transform', "translate(".concat(curTranslateX, ",").concat(curTranslateY, ")"));
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
|
|
625
717
|
// Render first group legend
|
|
626
718
|
this.renderLegend({
|
|
627
719
|
legendWrapper,
|
|
@@ -633,6 +725,7 @@ class ChartComponent extends _react.Component {
|
|
|
633
725
|
// Render Page navigator
|
|
634
726
|
if (groupsData.length > 1) {
|
|
635
727
|
const {
|
|
728
|
+
legendItemTextPaddingTop,
|
|
636
729
|
legendPageNavWrapperWidth,
|
|
637
730
|
legendItemMargin
|
|
638
731
|
} = this.legendConfig;
|
|
@@ -640,10 +733,10 @@ class ChartComponent extends _react.Component {
|
|
|
640
733
|
const pageNavigator = legendWrapper.append('g').attr('class', 'legend-flip-page');
|
|
641
734
|
|
|
642
735
|
// count
|
|
643
|
-
pageNavigator.append('text').attr('class', 'legend-count').attr('
|
|
736
|
+
pageNavigator.append('text').attr('class', 'legend-count').attr('x', 15).attr('y', legendItemTextPaddingTop).attr('fill', theme.legendTextColor).attr('font-size', theme.legendFontSize).text("".concat(curCount + 1, "/").concat(groupsData.length));
|
|
644
737
|
|
|
645
738
|
// prev page
|
|
646
|
-
pageNavigator.append('polygon').attr('class', 'legend-prev-page').attr('points', this.calcEquilateralTriangle(5,
|
|
739
|
+
pageNavigator.append('polygon').attr('class', 'legend-prev-page').attr('points', this.calcEquilateralTriangle(5, 8, 12)).attr('fill', theme.legendPageNavigatorMarkerColor).attr('opacity', curCount === 0 ? 0.45 : 1).attr('style', 'cursor: pointer;').on('click', event => {
|
|
647
740
|
if (curCount > 0) {
|
|
648
741
|
curCount--;
|
|
649
742
|
this.renderLegend({
|
|
@@ -657,7 +750,7 @@ class ChartComponent extends _react.Component {
|
|
|
657
750
|
});
|
|
658
751
|
|
|
659
752
|
// next page
|
|
660
|
-
pageNavigator.append('polygon').attr('class', 'legend-next-page').attr('points', this.calcEquilateralTriangle(45,
|
|
753
|
+
pageNavigator.append('polygon').attr('class', 'legend-next-page').attr('points', this.calcEquilateralTriangle(45, 8, 12, 'bottom')).attr('fill', theme.legendPageNavigatorMarkerColor).attr('opacity', curCount === groupsData.length - 1 ? 0.45 : 1).attr('style', 'cursor: pointer;').on('click', event => {
|
|
661
754
|
if (curCount < groupsData.length - 1) {
|
|
662
755
|
curCount++;
|
|
663
756
|
this.renderLegend({
|
|
@@ -690,8 +783,7 @@ class ChartComponent extends _react.Component {
|
|
|
690
783
|
} = g.node().parentNode.getBoundingClientRect();
|
|
691
784
|
groupTranslateY = groupTranslateY + height + legendItemMargin;
|
|
692
785
|
}
|
|
693
|
-
|
|
694
|
-
g.attr('transform', "translate(".concat(groupTranslateX, ", ").concat(curTranslateY, ")"));
|
|
786
|
+
g.attr('transform', "translate(".concat(groupTranslateX, ", ").concat(groupTranslateY, ")"));
|
|
695
787
|
});
|
|
696
788
|
}
|
|
697
789
|
};
|
|
@@ -705,6 +797,7 @@ class ChartComponent extends _react.Component {
|
|
|
705
797
|
} = _ref2;
|
|
706
798
|
const {
|
|
707
799
|
legendItemPaddingTop,
|
|
800
|
+
legendItemTextPaddingTop,
|
|
708
801
|
legendRectWidth,
|
|
709
802
|
legendRectHeight,
|
|
710
803
|
r,
|
|
@@ -741,7 +834,7 @@ class ChartComponent extends _react.Component {
|
|
|
741
834
|
// Add text
|
|
742
835
|
g.nodes().forEach(rect => {
|
|
743
836
|
const parentNode = rect.parentNode;
|
|
744
|
-
d3.select(parentNode).append('text').attr('x', legendRectWidth + legendRecTextGap).attr('fill', theme.legendTextColor).attr('font-size', theme.legendFontSize).text(this.formatterLegendName(rect.dataset.text)).attr('data-text', rect.dataset.text).attr('
|
|
837
|
+
d3.select(parentNode).append('text').attr('x', legendRectWidth + legendRecTextGap).attr('fill', theme.legendTextColor).attr('font-size', theme.legendFontSize).text(this.formatterLegendName(rect.dataset.text)).attr('data-text', rect.dataset.text).attr('y', legendItemTextPaddingTop);
|
|
745
838
|
});
|
|
746
839
|
const legendItems = Array.from(legendWrapper.node().children).filter(item => item.getAttribute('class') !== 'legend-flip-page');
|
|
747
840
|
const {
|
|
@@ -915,20 +1008,15 @@ class ChartComponent extends _react.Component {
|
|
|
915
1008
|
}
|
|
916
1009
|
};
|
|
917
1010
|
this.setLegendItemOffset = (legendItems, end) => {
|
|
918
|
-
const {
|
|
919
|
-
height: chartHeight,
|
|
920
|
-
bottomLegendSpace
|
|
921
|
-
} = this.chartBoundingClientRect;
|
|
922
1011
|
const endItem = legendItems[legendItems.length - 1];
|
|
923
1012
|
const endTranslateX = Number(endItem.getAttribute('data-translateX'));
|
|
924
1013
|
const {
|
|
925
1014
|
width: endWidth
|
|
926
1015
|
} = endItem.getBoundingClientRect();
|
|
927
1016
|
const offset = end - (endTranslateX + endWidth);
|
|
928
|
-
const curTranslateY = bottomLegendSpace ? chartHeight - bottomLegendSpace : 0; // legend offset bottom
|
|
929
1017
|
legendItems.forEach(legendItem => {
|
|
930
1018
|
const curTranslateX = Number(legendItem.getAttribute('data-translateX')) + offset;
|
|
931
|
-
d3.select(legendItem).attr('transform', "translate(".concat(curTranslateX, ",
|
|
1019
|
+
d3.select(legendItem).attr('transform', "translate(".concat(curTranslateX, ", 0)")).attr('data-translateX', curTranslateX);
|
|
932
1020
|
d3.select(legendItem).attr('opacity', 1);
|
|
933
1021
|
});
|
|
934
1022
|
};
|
|
@@ -1122,6 +1210,12 @@ class ChartComponent extends _react.Component {
|
|
|
1122
1210
|
this.isShowYAxisLabel = chart => {
|
|
1123
1211
|
return !!(chart && chart.config && chart.config.y_axis_show_label);
|
|
1124
1212
|
};
|
|
1213
|
+
this.isShowYAxisLeftLabel = chart => {
|
|
1214
|
+
return !!(chart && chart.config && chart.config.show_y_axis_left_label);
|
|
1215
|
+
};
|
|
1216
|
+
this.isShowYAxisRightLabel = chart => {
|
|
1217
|
+
return !!(chart && chart.config && chart.config.show_y_axis_right_label);
|
|
1218
|
+
};
|
|
1125
1219
|
this.getThemeColors = function () {
|
|
1126
1220
|
let themeColors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1127
1221
|
let theme = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -1132,11 +1226,10 @@ class ChartComponent extends _react.Component {
|
|
|
1132
1226
|
return themeColors || _constants.CHART_THEME_COLOR[_constants.THEME_NAME_MAP.LIGHT];
|
|
1133
1227
|
};
|
|
1134
1228
|
this.setDispalyGoalLine = (goal_label, goal_value, insertPadding, yScale) => {
|
|
1135
|
-
var _this$chart$node;
|
|
1136
1229
|
const {
|
|
1137
1230
|
width: chartWidth
|
|
1138
1231
|
} = this.chartBoundingClientRect;
|
|
1139
|
-
const annotationWrapper = this.chart.append('g').attr('class', "annotation-wrapper
|
|
1232
|
+
const annotationWrapper = this.chart.append('g').attr('class', "annotation-wrapper");
|
|
1140
1233
|
annotationWrapper.append('line').attr('stroke', '#aaa').attr('x1', insertPadding).attr('y1', yScale(goal_value)).attr('x2', chartWidth - insertPadding).attr('y2', yScale(goal_value)).attr('stroke-dasharray', '8,3').call(g => {
|
|
1141
1234
|
annotationWrapper.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', yScale(goal_value) - 10).attr('fill', '#666').text(goal_label);
|
|
1142
1235
|
});
|
|
@@ -1207,9 +1300,9 @@ class ChartComponent extends _react.Component {
|
|
|
1207
1300
|
this.setActiveAndInActiveState = (state, allGroup, curGroupName, chartType) => {
|
|
1208
1301
|
if (state === 'active') {
|
|
1209
1302
|
allGroup.forEach(g => {
|
|
1210
|
-
const rects = Array.from(g.children);
|
|
1303
|
+
const rects = Array.from(g.children).filter(item => item.tagName !== 'text');
|
|
1211
1304
|
rects.forEach(item => {
|
|
1212
|
-
d3.select(item).transition().duration(
|
|
1305
|
+
d3.select(item).transition().duration(this.transitionDuration).attr('opacity', 1);
|
|
1213
1306
|
if ([_constants.CHART_TYPE.PIE, _constants.CHART_TYPE.RING].includes(chartType)) {
|
|
1214
1307
|
d3.select(item).attr('stroke-width', 2);
|
|
1215
1308
|
}
|
|
@@ -1218,10 +1311,10 @@ class ChartComponent extends _react.Component {
|
|
|
1218
1311
|
}
|
|
1219
1312
|
if (state === 'inActive') {
|
|
1220
1313
|
allGroup.forEach(g => {
|
|
1221
|
-
const rects = Array.from(g.children);
|
|
1314
|
+
const rects = Array.from(g.children).filter(item => item.tagName !== 'text');
|
|
1222
1315
|
rects.forEach(item => {
|
|
1223
1316
|
if (item.getAttribute('data-groupName') !== curGroupName) {
|
|
1224
|
-
d3.selectAll([item]).transition().duration(
|
|
1317
|
+
d3.selectAll([item]).transition().duration(this.transitionDuration).attr('opacity', 0.3);
|
|
1225
1318
|
} else {
|
|
1226
1319
|
if ([_constants.CHART_TYPE.PIE, _constants.CHART_TYPE.RING].includes(chartType)) {
|
|
1227
1320
|
d3.select(item).attr('stroke-width', 0.5);
|
|
@@ -1252,29 +1345,30 @@ class ChartComponent extends _react.Component {
|
|
|
1252
1345
|
clipRect.attr('rx', borderRadiusVal);
|
|
1253
1346
|
clipRect.attr('height', Number(rect.getAttribute('height')) + borderRadiusVal);
|
|
1254
1347
|
}
|
|
1255
|
-
const clipPath = d3.select(parentNode).append('clipPath').attr('id', rectId);
|
|
1348
|
+
const clipPath = d3.select(parentNode).append('clipPath').attr('opacity', 1).attr('id', rectId);
|
|
1256
1349
|
clipPath.node().appendChild(clipRect.node());
|
|
1257
1350
|
d3.select(rect).attr('clip-path', "url(#".concat(rectId, ")"));
|
|
1258
1351
|
};
|
|
1259
|
-
this.drawYaxis = (g, theme)
|
|
1352
|
+
this.drawYaxis = function (g, theme) {
|
|
1353
|
+
let rightAxisOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1260
1354
|
const {
|
|
1261
1355
|
width: chartWidth,
|
|
1262
1356
|
insertPadding
|
|
1263
|
-
} =
|
|
1357
|
+
} = _this.chartBoundingClientRect;
|
|
1264
1358
|
// remove domain
|
|
1265
1359
|
g.select('.domain').remove();
|
|
1266
1360
|
|
|
1267
1361
|
// add text
|
|
1268
1362
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
1269
1363
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
1270
|
-
|
|
1364
|
+
_this.checkTextOverflow(g.selectAll('text').nodes());
|
|
1271
1365
|
|
|
1272
1366
|
// line
|
|
1273
1367
|
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
1274
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2 -
|
|
1368
|
+
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2 - _this.horizontalOverflowOffset - rightAxisOffset).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
1275
1369
|
|
|
1276
1370
|
// update g translateX
|
|
1277
|
-
g.attr('transform', "translate(".concat(insertPadding +
|
|
1371
|
+
g.attr('transform', "translate(".concat(insertPadding + _this.horizontalOverflowOffset, ", 0)"));
|
|
1278
1372
|
};
|
|
1279
1373
|
this.checkTextOverflow = allTextEl => {
|
|
1280
1374
|
const {
|
|
@@ -1288,7 +1382,7 @@ class ChartComponent extends _react.Component {
|
|
|
1288
1382
|
});
|
|
1289
1383
|
const maxTextWidth = Math.max(...allTextWidth);
|
|
1290
1384
|
this.horizontalOverflowOffset = 0;
|
|
1291
|
-
if (maxTextWidth > insertPadding) {
|
|
1385
|
+
if (maxTextWidth + 3 > insertPadding) {
|
|
1292
1386
|
// horizontal overflow
|
|
1293
1387
|
const offset = maxTextWidth + 3 - insertPadding; // 3 is text and line default spacing
|
|
1294
1388
|
this.horizontalOverflowOffset = offset;
|
|
@@ -1443,6 +1537,8 @@ class ChartComponent extends _react.Component {
|
|
|
1443
1537
|
};
|
|
1444
1538
|
this.initLabelStroke(props === null || props === void 0 ? void 0 : props.globalTheme);
|
|
1445
1539
|
this.chartBoundingClientRect = {};
|
|
1540
|
+
this.transitionDuration = 500;
|
|
1541
|
+
this.areaTransitionDuration = 200;
|
|
1446
1542
|
}
|
|
1447
1543
|
componentDidUpdate(prevProps) {
|
|
1448
1544
|
if (prevProps.globalTheme !== this.props.globalTheme) {
|