sea-chart 2.0.2-alpha.3 → 2.0.3
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/view/wrapper/bar.js
CHANGED
|
@@ -225,6 +225,8 @@ class Bar extends _chartComponent.default {
|
|
|
225
225
|
componentDidUpdate(prevProps) {
|
|
226
226
|
super.componentDidUpdate(prevProps);
|
|
227
227
|
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
228
|
+
var _this$chart;
|
|
229
|
+
((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
|
|
228
230
|
this.createChart();
|
|
229
231
|
this.drawChart();
|
|
230
232
|
}
|
|
@@ -198,7 +198,7 @@ class ChartComponent extends _react.Component {
|
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
|
-
this.renderAxisLabel = (chart, tables,
|
|
201
|
+
this.renderAxisLabel = (chart, tables, container) => {
|
|
202
202
|
var _this$chart2;
|
|
203
203
|
if (!this.chart || !chart) return;
|
|
204
204
|
let {
|
|
@@ -226,6 +226,7 @@ class ChartComponent extends _react.Component {
|
|
|
226
226
|
let textColor;
|
|
227
227
|
this.globalTheme === _constants.THEME_NAME_MAP.DARK ? textColor = '#fff' : textColor = '#999';
|
|
228
228
|
const xAxisID = "chart-x-axis-label_".concat(chart.id);
|
|
229
|
+
const chartContainer = container || this.chart.getCanvas().get('container');
|
|
229
230
|
const xLabel = chartContainer === null || chartContainer === void 0 ? void 0 : chartContainer.querySelector("#".concat(xAxisID));
|
|
230
231
|
if (!xLabel && x_axis_show_label) {
|
|
231
232
|
const div = document.createElement('div');
|
|
@@ -11,7 +11,6 @@ var _constants = require("../../constants");
|
|
|
11
11
|
var _statisticRecordDialog = _interopRequireDefault(require("../../components/statistic-record-dialog"));
|
|
12
12
|
var _table = _interopRequireDefault(require("./table"));
|
|
13
13
|
var _bar = _interopRequireDefault(require("./bar"));
|
|
14
|
-
var _barGroup = _interopRequireDefault(require("./bar-group"));
|
|
15
14
|
var _basicNumberCard = _interopRequireDefault(require("./basic-number-card"));
|
|
16
15
|
var _trend = _interopRequireDefault(require("./trend"));
|
|
17
16
|
var _tableElement = _interopRequireDefault(require("./table-element"));
|
|
@@ -95,12 +94,6 @@ const Wrapper = _ref => {
|
|
|
95
94
|
canvasStyle: canvasStyle
|
|
96
95
|
}));
|
|
97
96
|
}
|
|
98
|
-
case _constants.CHART_TYPE.BAR_GROUP:
|
|
99
|
-
{
|
|
100
|
-
return /*#__PURE__*/_react.default.createElement(_barGroup.default, Object.assign({}, baseProps, {
|
|
101
|
-
canvasStyle: canvasStyle
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
97
|
case _constants.CHART_TYPE.BASIC_NUMBER_CARD:
|
|
105
98
|
{
|
|
106
99
|
return /*#__PURE__*/_react.default.createElement(_basicNumberCard.default, Object.assign({}, baseProps, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sea-chart",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@dnd-kit/core": "^6.1.0",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"slugid": "~5.0.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"dtable-ui-component": "6.0.
|
|
24
|
+
"dtable-ui-component": "6.0.5",
|
|
25
25
|
"dtable-utils": "~5.0.*",
|
|
26
26
|
"prop-types": "15.8.1",
|
|
27
27
|
"react": "18.3.1",
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
-
var _dtableUtils = require("dtable-utils");
|
|
11
|
-
var _lodashEs = require("lodash-es");
|
|
12
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
var _intl = _interopRequireDefault(require("../../intl"));
|
|
14
|
-
var _columnUtils = require("../../utils/column-utils");
|
|
15
|
-
var _constants = require("../../constants");
|
|
16
|
-
var _utils = require("../../utils");
|
|
17
|
-
var _colorRules = require("../../constants/color-rules");
|
|
18
|
-
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
19
|
-
class BarGroup extends _chartComponent.default {
|
|
20
|
-
constructor(props) {
|
|
21
|
-
super(props);
|
|
22
|
-
this.handleResize = () => {
|
|
23
|
-
this.chart && this.chart.destroy();
|
|
24
|
-
this.createChart();
|
|
25
|
-
// this.drawChart();
|
|
26
|
-
};
|
|
27
|
-
this.createChart = () => {
|
|
28
|
-
const {
|
|
29
|
-
chart
|
|
30
|
-
} = this.props;
|
|
31
|
-
const {
|
|
32
|
-
y_axis_show_value
|
|
33
|
-
} = chart.config;
|
|
34
|
-
const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0];
|
|
35
|
-
this.initChart(this.container, {
|
|
36
|
-
appendPadding
|
|
37
|
-
});
|
|
38
|
-
this.chart.on('interval:click', e => {
|
|
39
|
-
this.props.toggleRecords(e.data.data);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
this.clearChart = () => {
|
|
43
|
-
this.chart.annotation().clear(true);
|
|
44
|
-
this.chart.clear(true);
|
|
45
|
-
};
|
|
46
|
-
this.drawChart = () => {
|
|
47
|
-
let {
|
|
48
|
-
result: data
|
|
49
|
-
} = this.props;
|
|
50
|
-
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
51
|
-
if (!Array.isArray(data)) return;
|
|
52
|
-
this.chart.scale(this.groupName, {
|
|
53
|
-
type: 'cat'
|
|
54
|
-
});
|
|
55
|
-
const {
|
|
56
|
-
chart
|
|
57
|
-
} = this.props;
|
|
58
|
-
const {
|
|
59
|
-
sort_type,
|
|
60
|
-
type
|
|
61
|
-
} = chart.config;
|
|
62
|
-
if (type === _constants.CHART_TYPE.BAR_STACK && sort_type) {
|
|
63
|
-
data = (0, _columnUtils.sortDataByGroupSum)(data, sort_type);
|
|
64
|
-
}
|
|
65
|
-
this.loadData(data);
|
|
66
|
-
this.draw(data);
|
|
67
|
-
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
68
|
-
};
|
|
69
|
-
this.draw = data => {
|
|
70
|
-
const {
|
|
71
|
-
chart,
|
|
72
|
-
summaryColumn,
|
|
73
|
-
globalTheme,
|
|
74
|
-
chartColorTheme,
|
|
75
|
-
customRender,
|
|
76
|
-
tables
|
|
77
|
-
} = this.props;
|
|
78
|
-
const {
|
|
79
|
-
type,
|
|
80
|
-
y_axis_summary_method,
|
|
81
|
-
y_axis_show_value,
|
|
82
|
-
label_font_size,
|
|
83
|
-
display_each_block_data,
|
|
84
|
-
y_axis_summary_type,
|
|
85
|
-
table_id,
|
|
86
|
-
column_groupby_column_key,
|
|
87
|
-
color_theme
|
|
88
|
-
} = chart.config;
|
|
89
|
-
const {
|
|
90
|
-
display_goal_line,
|
|
91
|
-
goal_value,
|
|
92
|
-
goal_label
|
|
93
|
-
} = chart.style_config || {};
|
|
94
|
-
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
95
|
-
const isGroup = type === _constants.CHART_TYPE.BAR_GROUP;
|
|
96
|
-
const newData = this.getChartGroupData(data);
|
|
97
|
-
const column_groupby_column = this.getColumn(tables, table_id, column_groupby_column_key);
|
|
98
|
-
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;
|
|
99
|
-
let singleBarWidth, singleBarRadius;
|
|
100
|
-
// y-axis label width:6 + 10
|
|
101
|
-
const chartWidth = this.chart.width - 6 - 10; // 10 is y-axis number width and 6 is gap between number and y axis line
|
|
102
|
-
if (!isGroup) {
|
|
103
|
-
singleBarWidth = Math.round(chartWidth / (2 * newData.length));
|
|
104
|
-
this.markFirstOrLast(data, 'first');
|
|
105
|
-
} else {
|
|
106
|
-
const maxCountGroup = (0, _lodashEs.maxBy)(newData, 'currentGroupCount');
|
|
107
|
-
// y-axis label width:6 + 10
|
|
108
|
-
singleBarWidth = maxCountGroup && Math.round(chartWidth / (2 * newData.length * maxCountGroup.currentGroupCount));
|
|
109
|
-
}
|
|
110
|
-
singleBarRadius = Math.min(singleBarWidth / 5, 10);
|
|
111
|
-
this.drawLabels(newData);
|
|
112
|
-
// set Coord type
|
|
113
|
-
this.chart.coordinate('rect');
|
|
114
|
-
this.autoAdjustDataOptions(chart, data, summaryColumn);
|
|
115
|
-
let yAxisShowValue = y_axis_show_value;
|
|
116
|
-
if (type === _constants.CHART_TYPE.BAR_STACK) {
|
|
117
|
-
yAxisShowValue = display_each_block_data;
|
|
118
|
-
let summaryColumnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
119
|
-
if (y_axis_summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
|
|
120
|
-
summaryColumnData = (summaryColumn === null || summaryColumn === void 0 ? void 0 : summaryColumn.data) || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
121
|
-
}
|
|
122
|
-
// get the total value of each stack
|
|
123
|
-
const dv = new DataSet.DataView().source(data);
|
|
124
|
-
dv.transform({
|
|
125
|
-
type: 'aggregate',
|
|
126
|
-
fields: ['value'],
|
|
127
|
-
operations: ['sum'],
|
|
128
|
-
as: ['value_sum'],
|
|
129
|
-
groupBy: ['name']
|
|
130
|
-
});
|
|
131
|
-
if (yAxisShowValue) {
|
|
132
|
-
dv.rows.forEach(item => {
|
|
133
|
-
this.chart.annotation().text({
|
|
134
|
-
content: () => {
|
|
135
|
-
if (y_axis_summary_method === _constants.CHART_SUMMARY_TYPE.DISTINCT_VALUES) {
|
|
136
|
-
return item.value_sum;
|
|
137
|
-
}
|
|
138
|
-
return (0, _dtableUtils.getNumberDisplayString)(item.value_sum, summaryColumnData);
|
|
139
|
-
},
|
|
140
|
-
position: {
|
|
141
|
-
name: item.name,
|
|
142
|
-
value: item.value_sum
|
|
143
|
-
},
|
|
144
|
-
offsetY: -10,
|
|
145
|
-
offsetX: -5
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// dodgePadding set to 0, cause width bewteen bars is designed to 0
|
|
152
|
-
const adjust = !isGroup ? {
|
|
153
|
-
type: 'stack'
|
|
154
|
-
} : {
|
|
155
|
-
type: 'dodge',
|
|
156
|
-
marginRatio: 0
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// use single select column color
|
|
160
|
-
useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
|
|
161
|
-
this.chart.interval().animate({
|
|
162
|
-
// custom update animation
|
|
163
|
-
update: {
|
|
164
|
-
animation: 'fadeIn',
|
|
165
|
-
duration: 1000,
|
|
166
|
-
easing: 'easeLinear'
|
|
167
|
-
}
|
|
168
|
-
}).label(y_axis_show_value ? 'value' : false, {
|
|
169
|
-
style: {
|
|
170
|
-
fontSize: _utils.BaseUtils.getLabelFontSize(label_font_size),
|
|
171
|
-
fill: theme.labelColor,
|
|
172
|
-
...this.labelStroke
|
|
173
|
-
},
|
|
174
|
-
position: type === _constants.CHART_TYPE.BAR_STACK ? 'middle' : ''
|
|
175
|
-
}).position('name*value').size(singleBarWidth).color('group_name', group_name => {
|
|
176
|
-
return this.colorMap[group_name] || _constants.CHART_STYLE_COLORS[0];
|
|
177
|
-
}).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
|
|
178
|
-
return {
|
|
179
|
-
title: !name && typeof name !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : name,
|
|
180
|
-
value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method),
|
|
181
|
-
name: !group_name && typeof group_name !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : group_name
|
|
182
|
-
};
|
|
183
|
-
}).adjust([adjust]).state({
|
|
184
|
-
active: {
|
|
185
|
-
style: {
|
|
186
|
-
stroke: null
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}).style('isFirst', isFirst => {
|
|
190
|
-
if (adjust.type === 'stack') {
|
|
191
|
-
if (isFirst) {
|
|
192
|
-
return {
|
|
193
|
-
radius: [singleBarRadius, singleBarRadius, 0, 0]
|
|
194
|
-
};
|
|
195
|
-
} else {
|
|
196
|
-
return {
|
|
197
|
-
radius: [0, 0, 0, 0]
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
return {
|
|
202
|
-
radius: [singleBarRadius, singleBarRadius, 0, 0]
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
if (isGroup) {
|
|
207
|
-
this.formatDataByName(data);
|
|
208
|
-
}
|
|
209
|
-
if (display_goal_line && goal_label && goal_value) {
|
|
210
|
-
this.setDispalyGoalLine(goal_label, goal_value, chartWidth);
|
|
211
|
-
}
|
|
212
|
-
this.setToolTip(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
|
|
213
|
-
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
214
|
-
this.setNameLabelAndTooltip(theme, this.labelCount);
|
|
215
|
-
this.setValueLabel(theme);
|
|
216
|
-
this.setLegend('group_name', theme, 'top-right');
|
|
217
|
-
this.chart.interaction('element-highlight-by-x');
|
|
218
|
-
};
|
|
219
|
-
this.chart = null;
|
|
220
|
-
}
|
|
221
|
-
componentDidMount() {
|
|
222
|
-
this.createChart();
|
|
223
|
-
// this.drawChart();
|
|
224
|
-
this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
|
|
225
|
-
window.addEventListener('resize', this.debouncedHandleResize);
|
|
226
|
-
}
|
|
227
|
-
componentDidUpdate(prevProps) {
|
|
228
|
-
super.componentDidUpdate(prevProps);
|
|
229
|
-
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
230
|
-
this.createChart();
|
|
231
|
-
// this.drawChart();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
componentWillUnmount() {
|
|
235
|
-
var _this$chart;
|
|
236
|
-
((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
|
|
237
|
-
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
238
|
-
}
|
|
239
|
-
render() {
|
|
240
|
-
const {
|
|
241
|
-
chart
|
|
242
|
-
} = this.props;
|
|
243
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
244
|
-
className: (0, _classnames.default)('sea-chart-container', {
|
|
245
|
-
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
246
|
-
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
247
|
-
}),
|
|
248
|
-
ref: ref => this.container = ref
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
BarGroup.propTypes = {
|
|
253
|
-
canvasStyle: _propTypes.default.object,
|
|
254
|
-
chart: _propTypes.default.object,
|
|
255
|
-
groupbyColumn: _propTypes.default.object,
|
|
256
|
-
columnGroupbyColumn: _propTypes.default.object,
|
|
257
|
-
summaryColumn: _propTypes.default.object,
|
|
258
|
-
result: _propTypes.default.array,
|
|
259
|
-
tables: _propTypes.default.array,
|
|
260
|
-
globalTheme: _propTypes.default.string,
|
|
261
|
-
chartColorTheme: _propTypes.default.string,
|
|
262
|
-
toggleRecords: _propTypes.default.func,
|
|
263
|
-
customRender: _propTypes.default.func
|
|
264
|
-
};
|
|
265
|
-
var _default = exports.default = BarGroup;
|