sea-chart 2.0.10 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +1 -1
- package/dist/utils/sql/chart-data-sql.js +2 -1
- package/dist/view/wrapper/bar-compare.js +7 -12
- package/dist/view/wrapper/bar-custom-stack.js +10 -15
- package/dist/view/wrapper/bar-group.js +6 -11
- package/dist/view/wrapper/bar-stack.js +32 -13
- package/dist/view/wrapper/bar.js +3 -8
- package/dist/view/wrapper/chart-component.js +110 -9
- package/dist/view/wrapper/index.js +3 -2
- package/package.json +1 -1
package/dist/api/index.js
CHANGED
|
@@ -324,6 +324,7 @@ class ChartDataSQL {
|
|
|
324
324
|
const {
|
|
325
325
|
x_axis_column_key,
|
|
326
326
|
x_axis_geolocation_granularity,
|
|
327
|
+
x_axis_date_granularity,
|
|
327
328
|
y_axis_summary_type,
|
|
328
329
|
y_axis_summary_column_key,
|
|
329
330
|
y_axis_summary_method,
|
|
@@ -339,7 +340,7 @@ class ChartDataSQL {
|
|
|
339
340
|
}
|
|
340
341
|
this._update_filter_sql(true, groupby_column);
|
|
341
342
|
const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
|
|
342
|
-
'date_granularity':
|
|
343
|
+
'date_granularity': x_axis_date_granularity,
|
|
343
344
|
'geolocation_granularity': x_axis_geolocation_granularity
|
|
344
345
|
});
|
|
345
346
|
let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
|
|
@@ -53,7 +53,7 @@ class BarCompare extends _chartComponent.default {
|
|
|
53
53
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
54
54
|
const {
|
|
55
55
|
display_increase,
|
|
56
|
-
y_axis_auto_range,
|
|
56
|
+
y_axis_auto_range = true,
|
|
57
57
|
y_axis_min,
|
|
58
58
|
y_axis_max
|
|
59
59
|
} = chart.config;
|
|
@@ -63,10 +63,13 @@ class BarCompare extends _chartComponent.default {
|
|
|
63
63
|
insertPadding
|
|
64
64
|
} = this.chartBoundingClientRect;
|
|
65
65
|
data = data.sort((a, b) => d3.ascending(a.name, b.name));
|
|
66
|
-
const
|
|
66
|
+
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, d3.max(data, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
|
|
67
|
+
|
|
68
|
+
// Y axis
|
|
69
|
+
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
|
|
70
|
+
const fx = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
67
71
|
const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
|
|
68
72
|
const x = d3.scaleBand().domain(d3.group(data, d => d.group_name).keys()).range([0, fx.bandwidth()]);
|
|
69
|
-
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]);
|
|
70
73
|
|
|
71
74
|
// X axis
|
|
72
75
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
@@ -74,15 +77,7 @@ class BarCompare extends _chartComponent.default {
|
|
|
74
77
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
75
78
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
76
79
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Y axis
|
|
80
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
81
|
-
g.select('.domain').remove();
|
|
82
|
-
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
83
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
84
|
-
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
85
|
-
g.selectAll('text').attr('fill', theme.textColor);
|
|
80
|
+
this.checkTickOverlap(g);
|
|
86
81
|
});
|
|
87
82
|
|
|
88
83
|
// Rect group
|
|
@@ -141,27 +141,22 @@ class BarCustom extends _chartComponent.default {
|
|
|
141
141
|
} = this.chartBoundingClientRect;
|
|
142
142
|
const organizedData = this.organizeData(data);
|
|
143
143
|
const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
|
|
144
|
-
const fx = d3.scaleBand().domain(new Set(organizedData.map(d => d.name))).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
145
|
-
const x = d3.scaleBand().domain(new Set(data.map(d => d.y_axis_type))).range([0, fx.bandwidth()]);
|
|
146
144
|
const allSeries = this.getAllSeries(organizedData);
|
|
147
145
|
const niceEnd = d3.nice(0, d3.max(allSeries, d => d[1]), 5)[1];
|
|
148
146
|
const y = d3.scaleLinear().domain([0, niceEnd]).range([chartHeight - insertPadding, insertPadding]);
|
|
149
147
|
|
|
148
|
+
// Y axis
|
|
149
|
+
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
|
|
150
|
+
const fx = d3.scaleBand().domain(new Set(organizedData.map(d => d.name))).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
151
|
+
const x = d3.scaleBand().domain(new Set(data.map(d => d.y_axis_type))).range([0, fx.bandwidth()]);
|
|
152
|
+
|
|
150
153
|
// X axis
|
|
151
154
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
152
155
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
153
156
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
154
157
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
155
158
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Y axis
|
|
159
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
160
|
-
g.select('.domain').remove();
|
|
161
|
-
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
162
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
163
|
-
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
164
|
-
g.selectAll('text').attr('fill', theme.textColor);
|
|
159
|
+
this.checkTickOverlap(g);
|
|
165
160
|
});
|
|
166
161
|
|
|
167
162
|
// Rect group
|
|
@@ -175,15 +170,13 @@ class BarCustom extends _chartComponent.default {
|
|
|
175
170
|
name
|
|
176
171
|
} = d;
|
|
177
172
|
return fx(name);
|
|
178
|
-
}).selectAll().data(d => d.stacks).join('g').attr('class', 'stackGroup').attr('data-slugid', d => d.slugid).selectAll().data(d => d.series).join('rect').attr('class', 'stack').attr('
|
|
179
|
-
return index === arr.length - 1;
|
|
180
|
-
}).attr('x', d => x(d.stackKey)).attr('y', d => y(d[0][1])).attr('width', x.bandwidth()).attr('height', d => {
|
|
173
|
+
}).selectAll().data(d => d.stacks).join('g').attr('class', 'stackGroup').attr('data-slugid', d => d.slugid).selectAll().data(d => d.series).join('rect').attr('class', 'stack').attr('x', d => x(d.stackKey)).attr('y', d => y(d[0][1])).attr('width', x.bandwidth()).attr('height', d => {
|
|
181
174
|
const height = y(d[0][0]) - y(d[0][1]);
|
|
182
175
|
return isNaN(height) ? 0 : height;
|
|
183
176
|
}).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 => {
|
|
184
177
|
// add rect borderRadius
|
|
185
178
|
Array.from(g._parents).forEach(group => {
|
|
186
|
-
const topRect = Array.from(group.children).find(rect => rect.getAttribute('
|
|
179
|
+
const topRect = Array.from(group.children).reverse().find(rect => Number(rect.getAttribute('height')) !== 0);
|
|
187
180
|
// Add mask rect
|
|
188
181
|
if (topRect) {
|
|
189
182
|
this.addMaskRect(group, topRect, x.bandwidth(), color);
|
|
@@ -225,6 +218,8 @@ class BarCustom extends _chartComponent.default {
|
|
|
225
218
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
226
219
|
Array.from(g._parents).forEach(group => {
|
|
227
220
|
Array.from(group.children).forEach(rect => {
|
|
221
|
+
// The height is 0, and the label is not displayed.
|
|
222
|
+
if (Number(rect.getAttribute('height')) === 0) return;
|
|
228
223
|
this.addLabelToRectCenter({
|
|
229
224
|
container: rect.parentNode,
|
|
230
225
|
x: Number(rect.getAttribute('x')),
|
|
@@ -105,25 +105,20 @@ class BarGroup extends _chartComponent.default {
|
|
|
105
105
|
const useSingleSelectColumnColor = (column_groupby_column === null || column_groupby_column === void 0 ? void 0 : column_groupby_column.type) === _dtableUtils.CellType.SINGLE_SELECT && color_theme === _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
|
|
106
106
|
useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme); // use single select column color
|
|
107
107
|
|
|
108
|
-
const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1);
|
|
109
|
-
const x = d3.scaleBand().domain(new Set(data.map(d => d.group_name))).range([0, fx.bandwidth()]);
|
|
110
108
|
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, d3.max(data, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
111
109
|
|
|
110
|
+
// Y axis
|
|
111
|
+
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
|
|
112
|
+
const fx = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
113
|
+
const x = d3.scaleBand().domain(new Set(data.map(d => d.group_name))).range([0, fx.bandwidth()]);
|
|
114
|
+
|
|
112
115
|
// X axis
|
|
113
116
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
114
117
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
115
118
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
116
119
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
117
120
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// Y axis
|
|
121
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
122
|
-
g.select('.domain').remove();
|
|
123
|
-
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
124
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
125
|
-
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
126
|
-
g.selectAll('text').attr('fill', theme.textColor);
|
|
121
|
+
this.checkTickOverlap(g);
|
|
127
122
|
});
|
|
128
123
|
|
|
129
124
|
// Rect group
|
|
@@ -106,25 +106,20 @@ class BarStack extends _chartComponent.default {
|
|
|
106
106
|
let [_, group] = _ref;
|
|
107
107
|
return (_group$get = group.get(String(key))) === null || _group$get === void 0 ? void 0 : _group$get.value;
|
|
108
108
|
})(d3.index(data, d => d.name, d => d.group_name));
|
|
109
|
-
const x = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
110
109
|
const niceEnd = d3.nice(0, d3.max(series, d => d3.max(d, d => d[1])), 5)[1];
|
|
111
110
|
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
112
111
|
|
|
112
|
+
// Y axis
|
|
113
|
+
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));
|
|
114
|
+
const x = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
115
|
+
|
|
113
116
|
// X axis
|
|
114
117
|
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
115
118
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
116
119
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
117
120
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
118
121
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// Y axis
|
|
122
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
123
|
-
g.select('.domain').remove();
|
|
124
|
-
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
125
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
126
|
-
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
127
|
-
g.selectAll('text').attr('fill', theme.textColor);
|
|
122
|
+
this.checkTickOverlap(g);
|
|
128
123
|
});
|
|
129
124
|
|
|
130
125
|
// Rect group
|
|
@@ -151,14 +146,23 @@ class BarStack extends _chartComponent.default {
|
|
|
151
146
|
} = d;
|
|
152
147
|
return data[0];
|
|
153
148
|
}).call(g => {
|
|
149
|
+
const groupRects = this.handleGroupRects(series, g._parents);
|
|
150
|
+
groupRects.forEach(group => {
|
|
151
|
+
var _firstEl;
|
|
152
|
+
const reverseGroup = group.reverse();
|
|
153
|
+
let firstEl = reverseGroup[0]; // firstEl is top level rect
|
|
154
|
+
if (Number(firstEl.getAttribute('height')) === 0) {
|
|
155
|
+
firstEl = reverseGroup.slice(1).find(item => Number(item.getAttribute('height')) !== 0);
|
|
156
|
+
}
|
|
157
|
+
// Add mask rect
|
|
158
|
+
firstEl && this.addMaskRect((_firstEl = firstEl) === null || _firstEl === void 0 ? void 0 : _firstEl.parentNode, firstEl, x.bandwidth());
|
|
159
|
+
});
|
|
154
160
|
const [topG] = g._parents.slice(-1);
|
|
155
|
-
Array.from(topG.children).forEach(rect => {
|
|
161
|
+
Array.from(topG.children).forEach((rect, index) => {
|
|
156
162
|
// Add label (get the total value of each stack)
|
|
157
163
|
if (display_each_block_data) {
|
|
158
164
|
this.addLabelByEachStack(data, topG, rect, x);
|
|
159
165
|
}
|
|
160
|
-
// Add mask rect
|
|
161
|
-
this.addMaskRect(topG, rect, x.bandwidth());
|
|
162
166
|
});
|
|
163
167
|
// Add label
|
|
164
168
|
if (y_axis_show_value) {
|
|
@@ -186,6 +190,19 @@ class BarStack extends _chartComponent.default {
|
|
|
186
190
|
groupColumn: this.props.columnGroupbyColumn
|
|
187
191
|
});
|
|
188
192
|
};
|
|
193
|
+
// Horizontal stacking processing position vertical stacking
|
|
194
|
+
this.handleGroupRects = (series, gParents) => {
|
|
195
|
+
const groupRects = [];
|
|
196
|
+
const len = series[0].length;
|
|
197
|
+
for (let i = 0; i < len; i++) {
|
|
198
|
+
const rects = [];
|
|
199
|
+
gParents.forEach(item => {
|
|
200
|
+
rects.push(item.children[i]);
|
|
201
|
+
});
|
|
202
|
+
groupRects.push(rects);
|
|
203
|
+
}
|
|
204
|
+
return groupRects;
|
|
205
|
+
};
|
|
189
206
|
this.showTooltip = event => {
|
|
190
207
|
const offsetX = d3.pointer(event)[0];
|
|
191
208
|
const offsetY = d3.pointer(event)[1];
|
|
@@ -284,6 +301,8 @@ class BarStack extends _chartComponent.default {
|
|
|
284
301
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
285
302
|
g._parents.forEach(group => {
|
|
286
303
|
Array.from(group.children).forEach(rect => {
|
|
304
|
+
// The height is 0, and the label is not displayed.
|
|
305
|
+
if (Number(rect.getAttribute('height')) === 0) return;
|
|
287
306
|
this.addLabelToRectCenter({
|
|
288
307
|
container: group,
|
|
289
308
|
x: Number(rect.getAttribute('x')),
|
package/dist/view/wrapper/bar.js
CHANGED
|
@@ -153,20 +153,15 @@ class Bar extends _chartComponent.default {
|
|
|
153
153
|
insertPadding,
|
|
154
154
|
marginTop
|
|
155
155
|
} = this.chartBoundingClientRect;
|
|
156
|
-
const x = d3.scaleBand().domain(data.map(item => item.name)).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
|
|
157
156
|
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
|
+
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));
|
|
158
|
+
const x = d3.scaleBand().domain(data.map(item => item.name)).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
|
|
158
159
|
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
159
160
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
160
161
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
161
162
|
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
162
163
|
g.selectAll('text').attr('fill', theme.textColor);
|
|
163
|
-
|
|
164
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
165
|
-
g.select('.domain').remove();
|
|
166
|
-
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
167
|
-
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
168
|
-
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
169
|
-
g.selectAll('text').attr('fill', theme.textColor);
|
|
164
|
+
this.checkTickOverlap(g);
|
|
170
165
|
});
|
|
171
166
|
const rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
172
167
|
rectsWrapper.selectAll().data(data).join('rect').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 => {
|
|
@@ -740,25 +740,26 @@ class ChartComponent extends _react.Component {
|
|
|
740
740
|
} = this.getLegendBoundary(legendPosition);
|
|
741
741
|
legendItems.forEach((item, index) => {
|
|
742
742
|
let translateX = start;
|
|
743
|
-
const
|
|
743
|
+
const prevItem = legendItems[index - 1];
|
|
744
744
|
if (index > 0) {
|
|
745
745
|
const {
|
|
746
746
|
width
|
|
747
|
-
} =
|
|
748
|
-
const prevTranslateX = Number(
|
|
747
|
+
} = prevItem.getBoundingClientRect();
|
|
748
|
+
const prevTranslateX = Number(prevItem.getAttribute('data-translateX'));
|
|
749
749
|
translateX = prevTranslateX + width + legendItemMargin;
|
|
750
750
|
}
|
|
751
|
+
d3.select(item).attr('transform', "translate(".concat(translateX, ",0)")).attr('data-translateX', translateX);
|
|
751
752
|
|
|
752
753
|
// legend items add offset
|
|
753
754
|
if (legendPosition === 'top-right') {
|
|
754
755
|
d3.select(item).attr('opacity', 0);
|
|
756
|
+
// Execute only once
|
|
755
757
|
if (index === legendItems.length - 1) {
|
|
756
758
|
queueMicrotask(() => {
|
|
757
759
|
this.setLegendItemOffset(legendItems, end);
|
|
758
760
|
});
|
|
759
761
|
}
|
|
760
762
|
}
|
|
761
|
-
d3.select(item).attr('transform', "translate(".concat(translateX, ",0)")).attr('data-translateX', translateX);
|
|
762
763
|
});
|
|
763
764
|
});
|
|
764
765
|
};
|
|
@@ -783,6 +784,7 @@ class ChartComponent extends _react.Component {
|
|
|
783
784
|
let allWidth = start;
|
|
784
785
|
const groupsData = [];
|
|
785
786
|
const newLegendData = (0, _lodashEs.cloneDeep)(legendData);
|
|
787
|
+
let lastIndex = 0;
|
|
786
788
|
legendData.forEach((item, index) => {
|
|
787
789
|
const virtualLegend = this.chart.append('g').attr('opacity', 0);
|
|
788
790
|
virtualLegend.append('rect').attr('width', legendRectWidth).attr('height', legendRectHeight).attr('rx', r);
|
|
@@ -792,15 +794,16 @@ class ChartComponent extends _react.Component {
|
|
|
792
794
|
} = virtualLegend.node().getBoundingClientRect();
|
|
793
795
|
const itemWidth = index === legendData.length - 1 ? width : width + legendItemMargin; // last item no used margin
|
|
794
796
|
allWidth = allWidth + itemWidth;
|
|
795
|
-
if (allWidth
|
|
796
|
-
groupsData.push(newLegendData.slice(0, index));
|
|
797
|
-
newLegendData.splice(0, index);
|
|
798
|
-
|
|
797
|
+
if (allWidth > end) {
|
|
798
|
+
groupsData.push(newLegendData.slice(0, index - lastIndex));
|
|
799
|
+
newLegendData.splice(0, index - lastIndex);
|
|
800
|
+
lastIndex = index;
|
|
801
|
+
allWidth = start + itemWidth;
|
|
799
802
|
}
|
|
800
803
|
virtualLegend.remove();
|
|
801
804
|
});
|
|
802
805
|
const restLegendItems = newLegendData.slice(0);
|
|
803
|
-
groupsData.push(restLegendItems);
|
|
806
|
+
restLegendItems.length !== 0 && groupsData.push(restLegendItems);
|
|
804
807
|
return groupsData;
|
|
805
808
|
};
|
|
806
809
|
this.getLegendBoundary = legendPosition => {
|
|
@@ -1162,6 +1165,104 @@ class ChartComponent extends _react.Component {
|
|
|
1162
1165
|
clipPath.node().appendChild(clipRect.node());
|
|
1163
1166
|
d3.select(rect).attr('clip-path', "url(#".concat(rectId, ")"));
|
|
1164
1167
|
};
|
|
1168
|
+
this.drawYaxis = (g, theme) => {
|
|
1169
|
+
const {
|
|
1170
|
+
width: chartWidth,
|
|
1171
|
+
insertPadding
|
|
1172
|
+
} = this.chartBoundingClientRect;
|
|
1173
|
+
// remove domain
|
|
1174
|
+
g.select('.domain').remove();
|
|
1175
|
+
|
|
1176
|
+
// add text
|
|
1177
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
1178
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
1179
|
+
this.checkTextOverflow(g.selectAll('text').nodes());
|
|
1180
|
+
|
|
1181
|
+
// line
|
|
1182
|
+
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
1183
|
+
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2 - this.horizontalOverflowOffset).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
1184
|
+
|
|
1185
|
+
// update g translateX
|
|
1186
|
+
g.attr('transform', "translate(".concat(insertPadding + this.horizontalOverflowOffset, ", 0)"));
|
|
1187
|
+
};
|
|
1188
|
+
this.checkTextOverflow = allTextEl => {
|
|
1189
|
+
const {
|
|
1190
|
+
insertPadding
|
|
1191
|
+
} = this.chartBoundingClientRect;
|
|
1192
|
+
const allTextWidth = allTextEl.map(item => {
|
|
1193
|
+
const {
|
|
1194
|
+
width
|
|
1195
|
+
} = item.getBoundingClientRect();
|
|
1196
|
+
return width;
|
|
1197
|
+
});
|
|
1198
|
+
const maxTextWidth = Math.max(...allTextWidth);
|
|
1199
|
+
this.horizontalOverflowOffset = 0;
|
|
1200
|
+
if (maxTextWidth > insertPadding) {
|
|
1201
|
+
// horizontal overflow
|
|
1202
|
+
const offset = maxTextWidth + 3 - insertPadding; // 3 is text and line default spacing
|
|
1203
|
+
this.horizontalOverflowOffset = offset;
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
this.checkTickOverlap = g => {
|
|
1207
|
+
const allTicks = g.selectAll('.tick').nodes();
|
|
1208
|
+
// Hide overlapping ticks
|
|
1209
|
+
for (let i = 0; i < allTicks.length; i++) {
|
|
1210
|
+
const curText = d3.select(allTicks[i]).select('text').node();
|
|
1211
|
+
const {
|
|
1212
|
+
right: curRight
|
|
1213
|
+
} = curText.getBoundingClientRect();
|
|
1214
|
+
for (let j = i + 1; j < allTicks.length; j++) {
|
|
1215
|
+
const nextText = d3.select(allTicks[j]).select('text').node();
|
|
1216
|
+
if (curText && nextText) {
|
|
1217
|
+
const {
|
|
1218
|
+
left: nextLeft
|
|
1219
|
+
} = nextText.getBoundingClientRect();
|
|
1220
|
+
if (curRight >= nextLeft) {
|
|
1221
|
+
i = j;
|
|
1222
|
+
d3.select(nextText.parentNode).attr('opacity', 0);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const {
|
|
1228
|
+
width: maxWidth
|
|
1229
|
+
} = g.node().getBoundingClientRect();
|
|
1230
|
+
let allWidth = 0;
|
|
1231
|
+
// Can't fit tilted text
|
|
1232
|
+
for (let tick of allTicks) {
|
|
1233
|
+
const {
|
|
1234
|
+
width
|
|
1235
|
+
} = tick.getBoundingClientRect();
|
|
1236
|
+
allWidth = allWidth + width;
|
|
1237
|
+
if (allWidth > maxWidth) break;
|
|
1238
|
+
}
|
|
1239
|
+
if (allWidth > maxWidth) {
|
|
1240
|
+
allTicks.forEach(tick => {
|
|
1241
|
+
const opacityVal = tick.getAttribute('opacity');
|
|
1242
|
+
if (Number(opacityVal) !== 0) {
|
|
1243
|
+
// roate
|
|
1244
|
+
d3.select(tick).select('text').attr('transform', 'rotate(45)').style('text-anchor', 'start').attr('dy', '0.4em').attr('dx', '0.4em');
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// Text overflow
|
|
1250
|
+
const {
|
|
1251
|
+
height
|
|
1252
|
+
} = g.node().getBoundingClientRect();
|
|
1253
|
+
const {
|
|
1254
|
+
insertPadding
|
|
1255
|
+
} = this.chartBoundingClientRect;
|
|
1256
|
+
if (height > insertPadding) {
|
|
1257
|
+
const viewBox = this.chart.node().getAttribute('viewBox').split(',');
|
|
1258
|
+
const viewHeight = viewBox[viewBox.length - 1];
|
|
1259
|
+
const newViewHeight = Number(viewHeight) + (height - insertPadding);
|
|
1260
|
+
viewBox[viewBox.length - 1] = "".concat(newViewHeight);
|
|
1261
|
+
queueMicrotask(() => {
|
|
1262
|
+
this.chart.attr('viewBox', viewBox.join(','));
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1165
1266
|
this.initLabelStroke(props === null || props === void 0 ? void 0 : props.globalTheme);
|
|
1166
1267
|
this.chartBoundingClientRect = {};
|
|
1167
1268
|
}
|
|
@@ -113,9 +113,10 @@ const Wrapper = _ref => {
|
|
|
113
113
|
config
|
|
114
114
|
} = chart;
|
|
115
115
|
const {
|
|
116
|
-
column_groupby_multiple_numeric_column
|
|
116
|
+
column_groupby_multiple_numeric_column,
|
|
117
|
+
column_groupby_column_key
|
|
117
118
|
} = config;
|
|
118
|
-
const BarGroupComponent = column_groupby_multiple_numeric_column ? _barStack.default :
|
|
119
|
+
const BarGroupComponent = column_groupby_column_key || column_groupby_multiple_numeric_column ? _barStack.default : _bar.default;
|
|
119
120
|
return /*#__PURE__*/_react.default.createElement(BarGroupComponent, Object.assign({}, baseProps, {
|
|
120
121
|
canvasStyle: canvasStyle
|
|
121
122
|
}));
|