sea-chart 2.0.8 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/tooltip/index.js +92 -0
- package/dist/components/types-dialog/index.js +2 -4
- package/dist/constants/index.js +1 -1
- package/dist/view/wrapper/bar-compare.js +345 -0
- package/dist/view/wrapper/bar-custom-stack.js +403 -0
- package/dist/view/wrapper/bar-group.js +46 -19
- package/dist/view/wrapper/bar-stack.js +40 -15
- package/dist/view/wrapper/bar.js +36 -26
- package/dist/view/wrapper/chart-component.js +425 -133
- package/dist/view/wrapper/horizontal-bar-group.js +282 -0
- package/dist/view/wrapper/horizontal-bar.js +266 -0
- package/dist/view/wrapper/index.js +41 -0
- package/package.json +2 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
12
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
14
|
+
var _dtableUtils = require("dtable-utils");
|
|
15
|
+
var _constants = require("../../constants");
|
|
16
|
+
var _utils = require("../../utils");
|
|
17
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
18
|
+
var _colorRules = require("../../constants/color-rules");
|
|
19
|
+
var _columnUtils = require("../../utils/column-utils");
|
|
20
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
21
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
22
|
+
class HorizontalBarGroup extends _chartComponent.default {
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super(props);
|
|
25
|
+
this.handleResize = (0, _lodashEs.debounce)(() => {
|
|
26
|
+
this.chart.node() && this.chart.node().remove();
|
|
27
|
+
this.createChart();
|
|
28
|
+
this.drawChart();
|
|
29
|
+
}, 300);
|
|
30
|
+
this.createChart = () => {
|
|
31
|
+
const {
|
|
32
|
+
chart
|
|
33
|
+
} = this.props;
|
|
34
|
+
const {
|
|
35
|
+
show_horizontal_axis_label,
|
|
36
|
+
show_vertical_axis_label,
|
|
37
|
+
display_data
|
|
38
|
+
} = chart.config;
|
|
39
|
+
const initConfig = {
|
|
40
|
+
insertPadding: 30,
|
|
41
|
+
borderRadius: 0.2,
|
|
42
|
+
marginLeft: show_vertical_axis_label ? 20 : 0,
|
|
43
|
+
marginBottom: show_horizontal_axis_label ? 20 : 0,
|
|
44
|
+
marginRight: 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
|
+
let {
|
|
50
|
+
result: data,
|
|
51
|
+
customRender,
|
|
52
|
+
chart
|
|
53
|
+
} = this.props;
|
|
54
|
+
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
55
|
+
if (!Array.isArray(data)) return;
|
|
56
|
+
const {
|
|
57
|
+
sort_type,
|
|
58
|
+
type
|
|
59
|
+
} = chart.config;
|
|
60
|
+
if (type === _constants.CHART_TYPE.STACKED_HORIZONTAL_BAR && sort_type) {
|
|
61
|
+
data = (0, _columnUtils.sortDataByGroupSum)(data, sort_type);
|
|
62
|
+
}
|
|
63
|
+
this.draw(data);
|
|
64
|
+
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
65
|
+
this.renderHorizontalLabel(this.props.chart, this.props.tables, this.container);
|
|
66
|
+
};
|
|
67
|
+
this.draw = data => {
|
|
68
|
+
const {
|
|
69
|
+
chart,
|
|
70
|
+
globalTheme,
|
|
71
|
+
chartColorTheme,
|
|
72
|
+
tables
|
|
73
|
+
} = this.props;
|
|
74
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
75
|
+
const {
|
|
76
|
+
display_data,
|
|
77
|
+
label_font_size,
|
|
78
|
+
column_groupby_column_key,
|
|
79
|
+
table_id,
|
|
80
|
+
color_theme,
|
|
81
|
+
horizontal_axis_auto_range,
|
|
82
|
+
horizontal_axis_min,
|
|
83
|
+
horizontal_axis_max
|
|
84
|
+
} = chart.config;
|
|
85
|
+
const {
|
|
86
|
+
width: chartWidth,
|
|
87
|
+
height: chartHeight,
|
|
88
|
+
insertPadding,
|
|
89
|
+
marginRight
|
|
90
|
+
} = this.chartBoundingClientRect;
|
|
91
|
+
const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
|
|
92
|
+
const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === _dtableUtils.CellType.SINGLE_SELECT && color_theme === _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
|
|
93
|
+
useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
|
|
94
|
+
const fy = d3.scaleBand().domain(new Set(data.map(d => d.name))).range([chartHeight - insertPadding, insertPadding]).paddingInner(0.1);
|
|
95
|
+
const y = d3.scaleBand().domain(new Set(data.map(d => d.group_name))).range([0, fy.bandwidth()]);
|
|
96
|
+
const yAxis = this.chart.append('g').call(d3.axisLeft(fy).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
97
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
98
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
99
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
100
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
101
|
+
// Update axis transform
|
|
102
|
+
const {
|
|
103
|
+
width: axisWidth
|
|
104
|
+
} = g.node().getBoundingClientRect();
|
|
105
|
+
g.attr('transform', "translate(".concat(axisWidth, ", 0)")).attr('data-axisWidth', axisWidth);
|
|
106
|
+
});
|
|
107
|
+
const niceEnd = d3.nice(0, d3.max(data, d => d.value), 5)[1];
|
|
108
|
+
const x = d3.scaleLinear().domain(horizontal_axis_auto_range ? [0, niceEnd] : [horizontal_axis_min || 0, horizontal_axis_max || niceEnd]).range([Number(yAxis.node().getAttribute('data-axisWidth')), chartWidth - insertPadding - marginRight]);
|
|
109
|
+
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
110
|
+
g.selectAll('.domain').remove();
|
|
111
|
+
g.selectAll('.tick line').node() && g.selectAll('.tick line').node().remove(); // delete the first line
|
|
112
|
+
g.selectAll('.tick line').attr('y2', -(chartHeight - insertPadding * 2)).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
113
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
114
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Rect group
|
|
118
|
+
const rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).attr('transform', "translate(".concat(Number(yAxis.node().getAttribute('data-axisWidth')), ", 0)"));
|
|
119
|
+
rectsWrapper.selectAll().data(d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
|
|
120
|
+
let [name, dum] = _ref;
|
|
121
|
+
const offset = (fy.bandwidth() - dum.length * y.bandwidth()) / 2;
|
|
122
|
+
return "translate(0, ".concat(fy(name) + offset, ")");
|
|
123
|
+
})
|
|
124
|
+
// rect item
|
|
125
|
+
.selectAll().data(_ref2 => {
|
|
126
|
+
let [_, d] = _ref2;
|
|
127
|
+
return d;
|
|
128
|
+
}).join('rect').attr('x', 0).attr('y', (d, index) => index * y.bandwidth()).attr('width', d => x(d.value) - x(0)).attr('height', y.bandwidth()).attr('fill', d => {
|
|
129
|
+
return this.colorMap[d.group_name] || _constants.CHART_STYLE_COLORS[0];
|
|
130
|
+
}).attr('value', d => d.value).attr('data-slugid', d => d.slugId).attr('data-groupName', d => d.name).call(g => {
|
|
131
|
+
// add rect borderRadius
|
|
132
|
+
g.nodes().forEach(rect => {
|
|
133
|
+
this.addClipPath({
|
|
134
|
+
rect,
|
|
135
|
+
parentNode: rect.parentNode,
|
|
136
|
+
attr: 'x',
|
|
137
|
+
rectId: rect.getAttribute('data-slugid')
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Add label
|
|
142
|
+
g.nodes().forEach(rect => {
|
|
143
|
+
if (display_data) {
|
|
144
|
+
this.addLabelToRectRight({
|
|
145
|
+
container: rect.parentNode,
|
|
146
|
+
xWidth: Number(rect.getAttribute('width')),
|
|
147
|
+
yHeight: Number(rect.getAttribute('height')),
|
|
148
|
+
y: Number(rect.getAttribute('y')),
|
|
149
|
+
theme,
|
|
150
|
+
label_font_size,
|
|
151
|
+
text: Number(rect.getAttribute('value'))
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}).on('click', (event, data) => {
|
|
156
|
+
this.props.toggleRecords(data);
|
|
157
|
+
}).on('mouseover', event => {
|
|
158
|
+
this.showTooltip(event);
|
|
159
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
160
|
+
}).on('mousemove', event => {
|
|
161
|
+
this.moveTooltip(event);
|
|
162
|
+
}).on('mouseleave', event => {
|
|
163
|
+
this.hiddenTooltip();
|
|
164
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
165
|
+
});
|
|
166
|
+
this.setLegend({
|
|
167
|
+
legendName: 'group_name',
|
|
168
|
+
theme,
|
|
169
|
+
legendPosition: 'top-left',
|
|
170
|
+
data,
|
|
171
|
+
groupColumn: this.props.columnGroupbyColumn
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
175
|
+
const allGroup = Array.from(event.currentTarget.parentNode.parentNode.children);
|
|
176
|
+
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
177
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
178
|
+
};
|
|
179
|
+
this.showTooltip = event => {
|
|
180
|
+
const {
|
|
181
|
+
offsetX,
|
|
182
|
+
offsetY
|
|
183
|
+
} = event;
|
|
184
|
+
const title = event.currentTarget.getAttribute('data-groupName');
|
|
185
|
+
const children = Array.from(event.currentTarget.parentNode.children).filter(item => item.tagName === 'rect');
|
|
186
|
+
const newTooltipData = {
|
|
187
|
+
title: !title && typeof title !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : title,
|
|
188
|
+
items: children.map(child => {
|
|
189
|
+
const data = child.__data__;
|
|
190
|
+
return {
|
|
191
|
+
color: this.colorMap[data.group_name] || _constants.CHART_STYLE_COLORS[0],
|
|
192
|
+
name: data.group_name,
|
|
193
|
+
value: data.value
|
|
194
|
+
};
|
|
195
|
+
})
|
|
196
|
+
};
|
|
197
|
+
this.setState({
|
|
198
|
+
tooltipData: newTooltipData
|
|
199
|
+
});
|
|
200
|
+
this.setState({
|
|
201
|
+
toolTipPosition: {
|
|
202
|
+
offsetX,
|
|
203
|
+
offsetY
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
this.moveTooltip = event => {
|
|
208
|
+
const {
|
|
209
|
+
offsetX,
|
|
210
|
+
offsetY
|
|
211
|
+
} = event;
|
|
212
|
+
this.setState({
|
|
213
|
+
toolTipPosition: {
|
|
214
|
+
offsetX,
|
|
215
|
+
offsetY
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
this.hiddenTooltip = event => {
|
|
220
|
+
this.setState({
|
|
221
|
+
toolTipPosition: null
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
this.chart = null;
|
|
225
|
+
this.state = {
|
|
226
|
+
tooltipData: null,
|
|
227
|
+
toolTipPosition: null
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
componentDidMount() {
|
|
231
|
+
this.createChart();
|
|
232
|
+
this.drawChart();
|
|
233
|
+
window.addEventListener('resize', this.handleResize);
|
|
234
|
+
}
|
|
235
|
+
componentDidUpdate(prevProps) {
|
|
236
|
+
super.componentDidUpdate(prevProps);
|
|
237
|
+
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
238
|
+
this.chart.node() && this.chart.node().remove();
|
|
239
|
+
this.createChart();
|
|
240
|
+
this.drawChart();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
componentWillUnmount() {
|
|
244
|
+
var _this$chart;
|
|
245
|
+
((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
|
|
246
|
+
window.removeEventListener('resize', this.handleResize);
|
|
247
|
+
}
|
|
248
|
+
render() {
|
|
249
|
+
const {
|
|
250
|
+
chart
|
|
251
|
+
} = this.props;
|
|
252
|
+
const {
|
|
253
|
+
tooltipData,
|
|
254
|
+
toolTipPosition
|
|
255
|
+
} = this.state;
|
|
256
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
257
|
+
ref: ref => this.container = ref,
|
|
258
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
259
|
+
'show-x-axis-label': this.isShowHorizontalAxisLabel(chart),
|
|
260
|
+
'show-y-axis-label': this.isShowVerticalAxisLabel(chart)
|
|
261
|
+
})
|
|
262
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
263
|
+
tooltipData: tooltipData,
|
|
264
|
+
toolTipPosition: toolTipPosition,
|
|
265
|
+
chart: this.chart
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
HorizontalBarGroup.propTypes = {
|
|
270
|
+
canvasStyle: _propTypes.default.object,
|
|
271
|
+
chart: _propTypes.default.object,
|
|
272
|
+
groupbyColumn: _propTypes.default.object,
|
|
273
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
274
|
+
summaryColumn: _propTypes.default.object,
|
|
275
|
+
result: _propTypes.default.array,
|
|
276
|
+
tables: _propTypes.default.array,
|
|
277
|
+
globalTheme: _propTypes.default.string,
|
|
278
|
+
chartColorTheme: _propTypes.default.string,
|
|
279
|
+
toggleRecords: _propTypes.default.func,
|
|
280
|
+
customRender: _propTypes.default.func
|
|
281
|
+
};
|
|
282
|
+
var _default = exports.default = HorizontalBarGroup;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
12
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
13
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
|
+
var _constants = require("../../constants");
|
|
15
|
+
var _utils = require("../../utils");
|
|
16
|
+
var _colorUtils = require("../../utils/color-utils");
|
|
17
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
18
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
19
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
20
|
+
class HorizontalBar 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_horizontal_axis_label,
|
|
34
|
+
show_vertical_axis_label,
|
|
35
|
+
display_data
|
|
36
|
+
} = chart.config;
|
|
37
|
+
const initConfig = {
|
|
38
|
+
insertPadding: 30,
|
|
39
|
+
borderRadius: 0.2,
|
|
40
|
+
marginLeft: show_vertical_axis_label ? 20 : 0,
|
|
41
|
+
marginBottom: show_horizontal_axis_label ? 20 : 0,
|
|
42
|
+
marginRight: display_data ? 15 : 0
|
|
43
|
+
};
|
|
44
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
45
|
+
};
|
|
46
|
+
this.drawChart = () => {
|
|
47
|
+
let {
|
|
48
|
+
result: data,
|
|
49
|
+
customRender
|
|
50
|
+
} = this.props;
|
|
51
|
+
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
52
|
+
if (!Array.isArray(data)) return;
|
|
53
|
+
this.draw(data);
|
|
54
|
+
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
55
|
+
this.renderHorizontalLabel(this.props.chart, this.props.tables, this.container);
|
|
56
|
+
};
|
|
57
|
+
this.draw = data => {
|
|
58
|
+
const {
|
|
59
|
+
chart,
|
|
60
|
+
globalTheme,
|
|
61
|
+
chartColorTheme,
|
|
62
|
+
tables
|
|
63
|
+
} = this.props;
|
|
64
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
65
|
+
const {
|
|
66
|
+
table_id,
|
|
67
|
+
horizontal_axis_summary_type,
|
|
68
|
+
horizontal_axis_column_key,
|
|
69
|
+
color_option,
|
|
70
|
+
horizontal_axis_label_color_rules,
|
|
71
|
+
horizontal_axis_label_color,
|
|
72
|
+
display_data,
|
|
73
|
+
label_font_size,
|
|
74
|
+
horizontal_axis_auto_range,
|
|
75
|
+
horizontal_axis_min,
|
|
76
|
+
horizontal_axis_max
|
|
77
|
+
} = chart.config;
|
|
78
|
+
const {
|
|
79
|
+
width: chartWidth,
|
|
80
|
+
height: chartHeight,
|
|
81
|
+
insertPadding,
|
|
82
|
+
marginRight
|
|
83
|
+
} = this.chartBoundingClientRect;
|
|
84
|
+
let chartBarColor = horizontal_axis_label_color || _constants.CHART_STYLE_COLORS[0];
|
|
85
|
+
if (chartColorTheme) {
|
|
86
|
+
chartBarColor = _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors[0];
|
|
87
|
+
}
|
|
88
|
+
const colorRules = color_option === _constants.TYPE_COLOR_USING.USE_RULES && horizontal_axis_label_color_rules && (0, _colorUtils.getConvertedColorRules)(horizontal_axis_label_color_rules);
|
|
89
|
+
const tooltipTitle = this.getTitle(tables, table_id, horizontal_axis_summary_type, horizontal_axis_column_key);
|
|
90
|
+
data.reverse();
|
|
91
|
+
const y = d3.scaleBand().domain(data.map(item => item.name)).range([chartHeight - insertPadding, insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
92
|
+
const yAxis = this.chart.append('g').call(d3.axisLeft(y).tickSizeOuter(0).tickPadding(0).tickSizeInner(5)).call(g => {
|
|
93
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
94
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
95
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
96
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
97
|
+
// Update axis transform
|
|
98
|
+
const {
|
|
99
|
+
width: axisWidth
|
|
100
|
+
} = g.node().getBoundingClientRect();
|
|
101
|
+
g.attr('transform', "translate(".concat(axisWidth, ", 0)")).attr('data-axisWidth', axisWidth);
|
|
102
|
+
});
|
|
103
|
+
const niceEnd = d3.nice(0, d3.max(data, d => d.value), 5)[1];
|
|
104
|
+
const x = d3.scaleLinear().domain(horizontal_axis_auto_range ? [0, niceEnd] : [horizontal_axis_min || 0, horizontal_axis_max || niceEnd]).range([Number(yAxis.node().getAttribute('data-axisWidth')), chartWidth - insertPadding - marginRight]);
|
|
105
|
+
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeInner(0).ticks(5)).call(g => {
|
|
106
|
+
g.selectAll('.domain').remove();
|
|
107
|
+
g.selectAll('.tick line').node() && g.selectAll('.tick line').node().remove(); // delete the first line
|
|
108
|
+
g.selectAll('.tick line').attr('y2', -(chartHeight - insertPadding * 2)).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
109
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
110
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
111
|
+
});
|
|
112
|
+
const rectsWrapper = this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).attr('transform', "translate(".concat(Number(yAxis.node().getAttribute('data-axisWidth')), ", 0)"));
|
|
113
|
+
rectsWrapper.selectAll().data(data).join('rect').attr('x', 0).attr('y', d => y(d.name)).attr('width', d => x(d.value) - x(0)).attr('height', y.bandwidth()).attr('fill', d => {
|
|
114
|
+
const color = (0, _colorUtils.getLabelColor)({
|
|
115
|
+
chart: chart.config,
|
|
116
|
+
colorRules,
|
|
117
|
+
value: d.value
|
|
118
|
+
});
|
|
119
|
+
return color || chartBarColor;
|
|
120
|
+
}).attr('value', d => d.value).attr('data-slugid', d => d.slugId).attr('data-groupName', d => d.name).call(g => {
|
|
121
|
+
// add rect borderRadius
|
|
122
|
+
g.nodes().forEach(rect => {
|
|
123
|
+
this.addClipPath({
|
|
124
|
+
rect,
|
|
125
|
+
parentNode: rect.parentNode,
|
|
126
|
+
attr: 'x',
|
|
127
|
+
rectId: rect.getAttribute('data-slugid')
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Add label
|
|
132
|
+
g.nodes().forEach(rect => {
|
|
133
|
+
if (display_data) {
|
|
134
|
+
this.addLabelToRectRight({
|
|
135
|
+
container: g._parents[0],
|
|
136
|
+
xWidth: Number(rect.getAttribute('width')),
|
|
137
|
+
yHeight: Number(rect.getAttribute('height')),
|
|
138
|
+
y: Number(rect.getAttribute('y')),
|
|
139
|
+
theme,
|
|
140
|
+
label_font_size,
|
|
141
|
+
text: Number(rect.getAttribute('value'))
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}).on('click', (event, data) => {
|
|
146
|
+
this.props.toggleRecords(data);
|
|
147
|
+
}).on('mouseover', (event, data) => {
|
|
148
|
+
this.showTooltip(event, data, tooltipTitle, colorRules, chartBarColor);
|
|
149
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
150
|
+
}).on('mousemove', event => {
|
|
151
|
+
this.moveTooltip(event);
|
|
152
|
+
}).on('mouseleave', (event, data) => {
|
|
153
|
+
this.hiddenTooltip();
|
|
154
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
158
|
+
const allGroup = [event.currentTarget.parentNode];
|
|
159
|
+
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
160
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
161
|
+
};
|
|
162
|
+
this.showTooltip = (event, data, title, colorRules, chartBarColor) => {
|
|
163
|
+
const {
|
|
164
|
+
chart
|
|
165
|
+
} = this.props;
|
|
166
|
+
const {
|
|
167
|
+
offsetX,
|
|
168
|
+
offsetY
|
|
169
|
+
} = event;
|
|
170
|
+
const newTooltipData = {
|
|
171
|
+
title: title,
|
|
172
|
+
items: [{
|
|
173
|
+
color: (0, _colorUtils.getLabelColor)({
|
|
174
|
+
chart: chart.config,
|
|
175
|
+
colorRules,
|
|
176
|
+
value: data.value
|
|
177
|
+
}) || chartBarColor,
|
|
178
|
+
name: data.name,
|
|
179
|
+
value: data.value
|
|
180
|
+
}]
|
|
181
|
+
};
|
|
182
|
+
this.setState({
|
|
183
|
+
tooltipData: newTooltipData
|
|
184
|
+
});
|
|
185
|
+
this.setState({
|
|
186
|
+
toolTipPosition: {
|
|
187
|
+
offsetX,
|
|
188
|
+
offsetY
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
this.moveTooltip = event => {
|
|
193
|
+
const {
|
|
194
|
+
offsetX,
|
|
195
|
+
offsetY
|
|
196
|
+
} = event;
|
|
197
|
+
this.setState({
|
|
198
|
+
toolTipPosition: {
|
|
199
|
+
offsetX,
|
|
200
|
+
offsetY
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
this.hiddenTooltip = event => {
|
|
205
|
+
this.setState({
|
|
206
|
+
toolTipPosition: null
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
this.chart = null;
|
|
210
|
+
this.state = {
|
|
211
|
+
tooltipData: null,
|
|
212
|
+
toolTipPosition: null
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
componentDidMount() {
|
|
216
|
+
super.componentDidMount();
|
|
217
|
+
this.createChart();
|
|
218
|
+
this.drawChart();
|
|
219
|
+
this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
|
|
220
|
+
window.addEventListener('resize', this.debouncedHandleResize);
|
|
221
|
+
}
|
|
222
|
+
componentDidUpdate(prevProps) {
|
|
223
|
+
super.componentDidUpdate(prevProps);
|
|
224
|
+
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
225
|
+
this.drawChart();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
componentWillUnmount() {
|
|
229
|
+
super.componentWillUnmount();
|
|
230
|
+
this.chart.node() && this.chart.node().remove();
|
|
231
|
+
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
232
|
+
}
|
|
233
|
+
render() {
|
|
234
|
+
const {
|
|
235
|
+
chart
|
|
236
|
+
} = this.props;
|
|
237
|
+
const {
|
|
238
|
+
tooltipData,
|
|
239
|
+
toolTipPosition
|
|
240
|
+
} = this.state;
|
|
241
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
242
|
+
ref: ref => this.container = ref,
|
|
243
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
244
|
+
'show-x-axis-label': this.isShowHorizontalAxisLabel(chart),
|
|
245
|
+
'show-y-axis-label': this.isShowVerticalAxisLabel(chart)
|
|
246
|
+
})
|
|
247
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
248
|
+
tooltipData: tooltipData,
|
|
249
|
+
toolTipPosition: toolTipPosition,
|
|
250
|
+
chart: this.chart
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
HorizontalBar.propTypes = {
|
|
255
|
+
canvasStyle: _propTypes.default.object,
|
|
256
|
+
chart: _propTypes.default.object,
|
|
257
|
+
groupbyColumn: _propTypes.default.object,
|
|
258
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
259
|
+
summaryColumn: _propTypes.default.object,
|
|
260
|
+
result: _propTypes.default.array,
|
|
261
|
+
tables: _propTypes.default.array,
|
|
262
|
+
globalTheme: _propTypes.default.string,
|
|
263
|
+
chartColorTheme: _propTypes.default.string,
|
|
264
|
+
toggleRecords: _propTypes.default.func
|
|
265
|
+
};
|
|
266
|
+
var _default = exports.default = HorizontalBar;
|
|
@@ -8,11 +8,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _constants = require("../../constants");
|
|
11
|
+
var _utils = require("../../utils");
|
|
11
12
|
var _statisticRecordDialog = _interopRequireDefault(require("../../components/statistic-record-dialog"));
|
|
12
13
|
var _table = _interopRequireDefault(require("./table"));
|
|
13
14
|
var _bar = _interopRequireDefault(require("./bar"));
|
|
14
15
|
var _barGroup = _interopRequireDefault(require("./bar-group"));
|
|
15
16
|
var _barStack = _interopRequireDefault(require("./bar-stack"));
|
|
17
|
+
var _barCompare = _interopRequireDefault(require("./bar-compare"));
|
|
18
|
+
var _barCustomStack = _interopRequireDefault(require("./bar-custom-stack"));
|
|
19
|
+
var _horizontalBar = _interopRequireDefault(require("./horizontal-bar"));
|
|
20
|
+
var _horizontalBarGroup = _interopRequireDefault(require("./horizontal-bar-group"));
|
|
16
21
|
var _basicNumberCard = _interopRequireDefault(require("./basic-number-card"));
|
|
17
22
|
var _trend = _interopRequireDefault(require("./trend"));
|
|
18
23
|
var _tableElement = _interopRequireDefault(require("./table-element"));
|
|
@@ -115,6 +120,42 @@ const Wrapper = _ref => {
|
|
|
115
120
|
canvasStyle: canvasStyle
|
|
116
121
|
}));
|
|
117
122
|
}
|
|
123
|
+
case _constants.CHART_TYPE.COMPARE_BAR:
|
|
124
|
+
{
|
|
125
|
+
return /*#__PURE__*/_react.default.createElement(_barCompare.default, Object.assign({}, baseProps, {
|
|
126
|
+
canvasStyle: canvasStyle
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
case _constants.CHART_TYPE.BAR_CUSTOM:
|
|
130
|
+
{
|
|
131
|
+
return /*#__PURE__*/_react.default.createElement(_barCustomStack.default, Object.assign({}, baseProps, {
|
|
132
|
+
canvasStyle: canvasStyle
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
case _constants.CHART_TYPE.HORIZONTAL_BAR:
|
|
136
|
+
{
|
|
137
|
+
return /*#__PURE__*/_react.default.createElement(_horizontalBar.default, Object.assign({}, baseProps, {
|
|
138
|
+
canvasStyle: canvasStyle
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
case _constants.CHART_TYPE.HORIZONTAL_GROUP_BAR:
|
|
142
|
+
{
|
|
143
|
+
const {
|
|
144
|
+
config,
|
|
145
|
+
id,
|
|
146
|
+
style_config
|
|
147
|
+
} = chart;
|
|
148
|
+
const newConfig = _utils.BaseUtils.convertConfig(config);
|
|
149
|
+
const newChart = {
|
|
150
|
+
id,
|
|
151
|
+
config: newConfig,
|
|
152
|
+
style_config
|
|
153
|
+
};
|
|
154
|
+
return /*#__PURE__*/_react.default.createElement(_horizontalBarGroup.default, Object.assign({}, baseProps, {
|
|
155
|
+
canvasStyle: canvasStyle,
|
|
156
|
+
chart: newChart
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
118
159
|
case _constants.CHART_TYPE.BASIC_NUMBER_CARD:
|
|
119
160
|
{
|
|
120
161
|
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.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@dnd-kit/core": "^6.1.0",
|
|
@@ -135,6 +135,7 @@
|
|
|
135
135
|
"react-cookies": "0.1.1",
|
|
136
136
|
"react-dev-utils": "^12.0.1",
|
|
137
137
|
"react-dom": "~18.3.1",
|
|
138
|
+
"react-i18next": "12.1.4",
|
|
138
139
|
"regenerator-runtime": "^0.14.1",
|
|
139
140
|
"release-it": "16.2.1",
|
|
140
141
|
"resolve": "1.12.0",
|