sea-chart 2.0.1 → 2.0.2
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/cell-factory/SimpleCellFormatter.js +1 -1
- package/dist/components/cell-factory/link-content.js +4 -4
- package/dist/components/color-picker/index.js +1 -1
- package/dist/components/color-popover/color-rules/color-rule.js +1 -1
- package/dist/components/color-popover/color-rules/index.js +1 -1
- package/dist/components/color-popover/color-rules-popover.js +6 -6
- package/dist/components/color-popover/color-selector-popover.js +2 -2
- package/dist/components/color-setting/color-group-selector.js +1 -1
- package/dist/components/common-add-tool/index.js +2 -2
- package/dist/components/data-process-setter/hide-column-setter.js +1 -1
- package/dist/components/data-process-setter/sort-setter.js +2 -2
- package/dist/components/drill-down-settings/drill-down-fields-popover/index.js +4 -4
- package/dist/components/icon/index.js +2 -2
- package/dist/components/popover/hide-column-popover/hide-column-popover-widgets/hide-column-item.js +1 -1
- package/dist/components/popover/hide-column-popover/hide-column-popover.js +1 -1
- package/dist/components/popover/sort-popover/sort-popover.js +1 -1
- package/dist/components/row-card/row-card-header-cell.js +2 -2
- package/dist/components/row-card/row-card-header.js +1 -1
- package/dist/components/row-card/row-card-item.js +2 -2
- package/dist/components/row-card/row-card.js +2 -2
- package/dist/components/statistic-record-dialog/index.js +1 -1
- package/dist/components/types-dialog/index.js +7 -7
- package/dist/context.js +2 -2
- package/dist/services/map-json.js +4 -4
- package/dist/settings/basic-number-card/style-settings.js +1 -1
- package/dist/settings/index.js +3 -3
- package/dist/settings/map-settings/map-style-settings.js +1 -1
- package/dist/settings/stacks-settings/index.js +1 -1
- package/dist/settings/style-settings.js +1 -1
- package/dist/settings/table-settings/data-settings.js +1 -1
- package/dist/settings/trend-settings/style-setting.js +2 -2
- package/dist/settings/widgets/chart-type/index.js +3 -3
- package/dist/settings/widgets/date-summary-item.js +2 -2
- package/dist/settings/widgets/numeric-summary-item.js +2 -2
- package/dist/settings/widgets/summary-settings.js +2 -2
- package/dist/settings/widgets/switch/index.js +1 -1
- package/dist/settings/widgets/y-axis-group-settings.js +1 -1
- package/dist/utils/chart-utils/base-utils.js +7 -7
- package/dist/utils/chart-utils/original-data-utils/basic-chart-calculator.js +1 -1
- package/dist/utils/chart-utils/original-data-utils/compare-bar-chart-calculator.js +2 -2
- package/dist/utils/chart-utils/original-data-utils/completeness-calculator.js +1 -1
- package/dist/utils/chart-utils/sql-statistics-utils.js +9 -9
- package/dist/utils/collaborator-utils.js +1 -1
- package/dist/utils/collaborator.js +2 -2
- package/dist/utils/column-utils.js +12 -12
- package/dist/utils/common-utils.js +1 -1
- package/dist/utils/date-translate.js +1 -1
- package/dist/utils/object-utils.js +1 -1
- package/dist/utils/options-utils.js +2 -2
- package/dist/utils/row-record-utils.js +2 -2
- package/dist/utils/sql/chart-data-sql.js +58 -58
- package/dist/utils/sql/column-2-sql-column.js +18 -18
- package/dist/view/index.js +2 -5
- package/dist/view/title/index.js +2 -2
- package/dist/view/wrapper/bar.js +168 -93
- package/dist/view/wrapper/basic-number-card.js +8 -8
- package/dist/view/wrapper/chart-component.js +16 -52
- package/dist/view/wrapper/index.js +1 -237
- package/dist/view/wrapper/table/index.js +1 -1
- package/dist/view/wrapper/table/one-dimension-table-with-numeric-columns.js +3 -3
- package/dist/view/wrapper/table/pivot-table-display-name.js +1 -1
- package/dist/view/wrapper/table/two-dimension-table.js +8 -8
- package/dist/view/wrapper/table-element/components/formatter.js +2 -2
- package/dist/view/wrapper/table-element/components/formatters/FileFormatter/index.js +1 -1
- package/dist/view/wrapper/table-element/components/formatters/link-formatter.js +17 -17
- package/dist/view/wrapper/table-element/components/link-formatter.js +17 -17
- package/dist/view/wrapper/table-element/components/record.js +3 -3
- package/dist/view/wrapper/table-element/components/records.js +4 -4
- package/dist/view/wrapper/table-element/components/utils.js +1 -1
- package/dist/view/wrapper/trend.js +18 -18
- package/package.json +5 -11
- package/dist/utils/custom-g2.js +0 -684
- package/dist/view/wrapper/area.js +0 -282
- package/dist/view/wrapper/bar-custom.js +0 -239
- package/dist/view/wrapper/bar-group.js +0 -274
- package/dist/view/wrapper/combination.js +0 -728
- package/dist/view/wrapper/compare.js +0 -383
- package/dist/view/wrapper/completeness.js +0 -174
- package/dist/view/wrapper/dashboard.js +0 -179
- package/dist/view/wrapper/funnel.js +0 -206
- package/dist/view/wrapper/heat-map.js +0 -434
- package/dist/view/wrapper/horizontal-bar-group.js +0 -226
- package/dist/view/wrapper/horizontal-bar.js +0 -175
- package/dist/view/wrapper/horizontal-component.js +0 -89
- package/dist/view/wrapper/line-group.js +0 -219
- package/dist/view/wrapper/line.js +0 -222
- package/dist/view/wrapper/map.js +0 -368
- package/dist/view/wrapper/mirror.js +0 -218
- package/dist/view/wrapper/pie.js +0 -253
- package/dist/view/wrapper/ring.js +0 -328
- package/dist/view/wrapper/scatter.js +0 -140
- package/dist/view/wrapper/treemap.js +0 -206
- package/dist/view/wrapper/world-map.js +0 -413
- package/dist/view/wrapper/wrappers-d3/bar.js +0 -262
|
@@ -1,222 +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 _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
var _utils = require("../../utils");
|
|
12
|
-
var _intl = _interopRequireDefault(require("../../intl"));
|
|
13
|
-
var _constants = require("../../constants");
|
|
14
|
-
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
15
|
-
class Line extends _chartComponent.default {
|
|
16
|
-
constructor(props) {
|
|
17
|
-
super(props);
|
|
18
|
-
this.createChart = () => {
|
|
19
|
-
const {
|
|
20
|
-
chart
|
|
21
|
-
} = this.props;
|
|
22
|
-
const {
|
|
23
|
-
y_axis_show_value
|
|
24
|
-
} = chart.config;
|
|
25
|
-
const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0];
|
|
26
|
-
this.initChart(this.container, {
|
|
27
|
-
appendPadding
|
|
28
|
-
});
|
|
29
|
-
this.chart.on('point:click', e => {
|
|
30
|
-
this.props.toggleRecords(e.data.data);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
this.clearChart = () => {
|
|
34
|
-
this.chart.annotation().clear(true);
|
|
35
|
-
this.chart.clear(true);
|
|
36
|
-
};
|
|
37
|
-
this.drawChart = () => {
|
|
38
|
-
let {
|
|
39
|
-
result: data,
|
|
40
|
-
chart,
|
|
41
|
-
summaryColumn,
|
|
42
|
-
customRender
|
|
43
|
-
} = this.props;
|
|
44
|
-
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
45
|
-
if (!Array.isArray(data)) return;
|
|
46
|
-
this.loadData(data);
|
|
47
|
-
this.draw(data);
|
|
48
|
-
this.autoAdjustDataOptions(chart, data, summaryColumn);
|
|
49
|
-
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
50
|
-
requestAnimationFrame(() => {
|
|
51
|
-
this.chart.render();
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
this.draw = data => {
|
|
55
|
-
const {
|
|
56
|
-
chart,
|
|
57
|
-
globalTheme,
|
|
58
|
-
chartColorTheme,
|
|
59
|
-
summaryColumn,
|
|
60
|
-
tables
|
|
61
|
-
} = this.props;
|
|
62
|
-
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
63
|
-
const {
|
|
64
|
-
table_id,
|
|
65
|
-
y_axis_column_key,
|
|
66
|
-
y_axis_summary_column_key,
|
|
67
|
-
y_axis_label_color,
|
|
68
|
-
y_axis_show_value,
|
|
69
|
-
label_font_size,
|
|
70
|
-
line_type,
|
|
71
|
-
y_axis_summary_type,
|
|
72
|
-
y_axis_summary_method,
|
|
73
|
-
color_option
|
|
74
|
-
// y_axis_label_color_rules
|
|
75
|
-
} = chart.config;
|
|
76
|
-
const chartWidth = this.chart.width - 6 - 10; // 10 is y-axis number width and 6 is gap between number and y axis line
|
|
77
|
-
const {
|
|
78
|
-
display_goal_line,
|
|
79
|
-
goal_label,
|
|
80
|
-
goal_value
|
|
81
|
-
} = chart.style_config || {};
|
|
82
|
-
let chartBarColor;
|
|
83
|
-
// default color
|
|
84
|
-
chartBarColor = _constants.CHART_STYLE_COLORS[0];
|
|
85
|
-
// use theme color has higher priority
|
|
86
|
-
if (chartColorTheme) {
|
|
87
|
-
chartBarColor = _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors[0];
|
|
88
|
-
}
|
|
89
|
-
// use specific color has higher priority then theme color
|
|
90
|
-
if (color_option === _constants.TYPE_COLOR_USING.USE_SPECIFIC_COLORS && y_axis_label_color) {
|
|
91
|
-
chartBarColor = y_axis_label_color;
|
|
92
|
-
}
|
|
93
|
-
this.drawLabels(data);
|
|
94
|
-
|
|
95
|
-
// y axis label
|
|
96
|
-
const title = this.getTitle(tables, table_id, y_axis_summary_type, y_axis_column_key || y_axis_summary_column_key);
|
|
97
|
-
const isSmooth = line_type === _constants.CHART_LINE_TYPES[1];
|
|
98
|
-
|
|
99
|
-
// set Coord type
|
|
100
|
-
this.chart.coordinate('rect');
|
|
101
|
-
this.chart.line().label(y_axis_show_value ? 'value' : false, {
|
|
102
|
-
style: {
|
|
103
|
-
fontSize: _utils.BaseUtils.getLabelFontSize(label_font_size),
|
|
104
|
-
fill: theme.labelColor,
|
|
105
|
-
stroke: '#fff',
|
|
106
|
-
lineWidth: 1
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
// .animate({
|
|
110
|
-
// appear: {
|
|
111
|
-
// animation: 'fadeIn',
|
|
112
|
-
// duration: 1000,
|
|
113
|
-
// easing: 'easeLinear'
|
|
114
|
-
// }
|
|
115
|
-
// })
|
|
116
|
-
.position('name*value').color(chartBarColor).shape(isSmooth ? 'smooth' : 'line').style({
|
|
117
|
-
lineWidth: 2,
|
|
118
|
-
opacity: 1
|
|
119
|
-
}).tooltip('name*value', (name, value) => {
|
|
120
|
-
return {
|
|
121
|
-
title,
|
|
122
|
-
value: _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method),
|
|
123
|
-
name
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
let point;
|
|
127
|
-
point = this.chart.point().position('name*value').color(chartBarColor).animate({
|
|
128
|
-
appear: {
|
|
129
|
-
animation: 'fadeIn',
|
|
130
|
-
duration: 1000,
|
|
131
|
-
easing: 'easeLinear'
|
|
132
|
-
}
|
|
133
|
-
}).shape('circle').size(3).style({
|
|
134
|
-
stroke: 0,
|
|
135
|
-
fillOpacity: 1,
|
|
136
|
-
opacity: y_axis_show_value ? 1 : 0
|
|
137
|
-
}).tooltip(false);
|
|
138
|
-
|
|
139
|
-
// this.chart.on('tooltip:show', () => {
|
|
140
|
-
// if (line.styleOption.cfg.opacity === 0.3) return;
|
|
141
|
-
// line.style({
|
|
142
|
-
// opacity: 0.3,
|
|
143
|
-
// lineWidth: 3,
|
|
144
|
-
// });
|
|
145
|
-
// if (point) point.style({
|
|
146
|
-
// fillOpacity: 0.3,
|
|
147
|
-
// stroke: 0,
|
|
148
|
-
// });
|
|
149
|
-
// this.chart.render();
|
|
150
|
-
// });
|
|
151
|
-
|
|
152
|
-
// this.chart.on('tooltip:hide', () => {
|
|
153
|
-
// if (line.styleOption.cfg.opacity === 1) return;
|
|
154
|
-
// line.style({
|
|
155
|
-
// opacity: 1,
|
|
156
|
-
// lineWidth: 3,
|
|
157
|
-
// });
|
|
158
|
-
// if (point) point.style({
|
|
159
|
-
// fillOpacity: 1,
|
|
160
|
-
// stroke: 0,
|
|
161
|
-
// });
|
|
162
|
-
// this.chart.render();
|
|
163
|
-
// });
|
|
164
|
-
|
|
165
|
-
if (display_goal_line && goal_label && goal_value) {
|
|
166
|
-
this.setDispalyGoalLine(goal_label, goal_value, chartWidth);
|
|
167
|
-
}
|
|
168
|
-
this.setToolTipForLine();
|
|
169
|
-
this.setNameLabelAndTooltip(theme, this.labelCount);
|
|
170
|
-
this.setValueLabel(theme);
|
|
171
|
-
};
|
|
172
|
-
this.chart = null;
|
|
173
|
-
this.needRenderAxisLabel = true;
|
|
174
|
-
}
|
|
175
|
-
componentDidMount() {
|
|
176
|
-
this.createChart();
|
|
177
|
-
this.drawChart();
|
|
178
|
-
this.renderAxisLabel(this.props.chart, this.props.tables);
|
|
179
|
-
super.componentDidMount();
|
|
180
|
-
}
|
|
181
|
-
componentDidUpdate(prevProps) {
|
|
182
|
-
super.componentDidUpdate(prevProps);
|
|
183
|
-
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
184
|
-
var _this$chart;
|
|
185
|
-
((_this$chart = this.chart) === null || _this$chart === void 0 ? void 0 : _this$chart.autoPadding) && this.chart.destroy();
|
|
186
|
-
this.createChart();
|
|
187
|
-
this.drawChart();
|
|
188
|
-
this.renderAxisLabel(prevProps.chart, prevProps.tables);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
componentWillUnmount() {
|
|
192
|
-
var _this$chart2;
|
|
193
|
-
((_this$chart2 = this.chart) === null || _this$chart2 === void 0 ? void 0 : _this$chart2.autoPadding) && this.chart.destroy();
|
|
194
|
-
super.componentWillUnmount();
|
|
195
|
-
}
|
|
196
|
-
render() {
|
|
197
|
-
const {
|
|
198
|
-
chart
|
|
199
|
-
} = this.props;
|
|
200
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
201
|
-
className: (0, _classnames.default)('sea-chart-container ', {
|
|
202
|
-
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
203
|
-
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
204
|
-
}),
|
|
205
|
-
ref: ref => this.container = ref
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
Line.propTypes = {
|
|
210
|
-
canvasStyle: _propTypes.default.object,
|
|
211
|
-
chart: _propTypes.default.object,
|
|
212
|
-
groupbyColumn: _propTypes.default.object,
|
|
213
|
-
columnGroupbyColumn: _propTypes.default.object,
|
|
214
|
-
summaryColumn: _propTypes.default.object,
|
|
215
|
-
result: _propTypes.default.array,
|
|
216
|
-
tables: _propTypes.default.array,
|
|
217
|
-
globalTheme: _propTypes.default.string,
|
|
218
|
-
chartColorTheme: _propTypes.default.string,
|
|
219
|
-
toggleRecords: _propTypes.default.func,
|
|
220
|
-
customRender: _propTypes.default.func
|
|
221
|
-
};
|
|
222
|
-
var _default = exports.default = Line;
|
package/dist/view/wrapper/map.js
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
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 = Map;
|
|
9
|
-
var _Loading2 = _interopRequireDefault(require("dtable-ui-component/lib/Loading"));
|
|
10
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var _dtableUtils = require("dtable-utils");
|
|
13
|
-
var _dataSet = require("@antv/data-set");
|
|
14
|
-
var _constants = require("../../constants");
|
|
15
|
-
var _customG = require("../../utils/custom-g2");
|
|
16
|
-
var _mapJson = _interopRequireDefault(require("../../services/map-json"));
|
|
17
|
-
var _colorRules = require("../../constants/color-rules");
|
|
18
|
-
var _context = _interopRequireDefault(require("../../context"));
|
|
19
|
-
var _utils = require("../../utils");
|
|
20
|
-
const CHART_STYLE_CONFIG = {
|
|
21
|
-
'g2-tooltip': {
|
|
22
|
-
borderRadius: '2px',
|
|
23
|
-
backgroundColor: '#fff',
|
|
24
|
-
padding: '10px'
|
|
25
|
-
},
|
|
26
|
-
'tooltip-item': {
|
|
27
|
-
marginTop: '5px'
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const getDefaultChartStyleByKey = key => {
|
|
31
|
-
return CHART_STYLE_CONFIG[key] || {};
|
|
32
|
-
};
|
|
33
|
-
function createChart(container) {
|
|
34
|
-
// width / height = 1.5 for chinese map
|
|
35
|
-
const {
|
|
36
|
-
width,
|
|
37
|
-
height
|
|
38
|
-
} = (0, _utils.getMapCanvasStyle)(container, 1.5);
|
|
39
|
-
let config = {
|
|
40
|
-
container: container,
|
|
41
|
-
width,
|
|
42
|
-
height
|
|
43
|
-
};
|
|
44
|
-
return new _customG.Chart(config);
|
|
45
|
-
}
|
|
46
|
-
function initChart(currentChart, props) {
|
|
47
|
-
const {
|
|
48
|
-
result,
|
|
49
|
-
toggleRecords
|
|
50
|
-
} = props;
|
|
51
|
-
currentChart.on('element:click', e => {
|
|
52
|
-
const data = e.data.data;
|
|
53
|
-
const clickData = result.find(i => i.name === data.name);
|
|
54
|
-
if (clickData) {
|
|
55
|
-
toggleRecords(clickData);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
currentChart.tooltip({
|
|
59
|
-
showTitle: false,
|
|
60
|
-
showMarkers: false,
|
|
61
|
-
shared: true,
|
|
62
|
-
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
|
|
63
|
-
itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{name}<div><div class="tooltip-item">数量: {value}<div></div>',
|
|
64
|
-
domStyles: {
|
|
65
|
-
'g2-tooltip': getDefaultChartStyleByKey('g2-tooltip'),
|
|
66
|
-
'tooltip-item': getDefaultChartStyleByKey('tooltip-item')
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
currentChart.scale({
|
|
70
|
-
longitude: {
|
|
71
|
-
sync: true
|
|
72
|
-
},
|
|
73
|
-
latitude: {
|
|
74
|
-
sync: true
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
currentChart.axis(false);
|
|
78
|
-
}
|
|
79
|
-
function mapGetNumberDisplayString(value, columnData, summaryMethod) {
|
|
80
|
-
if (summaryMethod === _constants.CHART_SUMMARY_TYPE.Distinct_values) {
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
return (0, _dtableUtils.getNumberDisplayString)(value, columnData);
|
|
84
|
-
}
|
|
85
|
-
const formatStatisticData = (statisticData, mapData, type) => {
|
|
86
|
-
if (!statisticData) return [];
|
|
87
|
-
let statisticNewData = [];
|
|
88
|
-
let sum = 0;
|
|
89
|
-
statisticData.forEach((item, index) => {
|
|
90
|
-
if (item && item.name) {
|
|
91
|
-
let matchFeature = mapData.features.find(feature => feature.properties.name.indexOf(item.name) > -1);
|
|
92
|
-
if (matchFeature) {
|
|
93
|
-
statisticNewData.push({
|
|
94
|
-
name: matchFeature.properties.name,
|
|
95
|
-
value: item.value || 0
|
|
96
|
-
});
|
|
97
|
-
if (type === 'map_bubble') {
|
|
98
|
-
sum += item.value;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if (type === 'map_bubble') {
|
|
104
|
-
statisticNewData.sum = sum;
|
|
105
|
-
}
|
|
106
|
-
return statisticNewData;
|
|
107
|
-
};
|
|
108
|
-
function Map(props) {
|
|
109
|
-
const {
|
|
110
|
-
result: statisticData,
|
|
111
|
-
chart
|
|
112
|
-
} = props;
|
|
113
|
-
|
|
114
|
-
// mapLocation is initially set to null, in this case mapLevel is country, so doesn't here
|
|
115
|
-
const {
|
|
116
|
-
map_location: mapLocation,
|
|
117
|
-
map_level: mapLevel = _constants.MAP_LEVEL.COUNTRY,
|
|
118
|
-
type,
|
|
119
|
-
data_color,
|
|
120
|
-
bubble_color,
|
|
121
|
-
legend_size,
|
|
122
|
-
legend_direction,
|
|
123
|
-
summary_type,
|
|
124
|
-
summary_column_key,
|
|
125
|
-
summary_method,
|
|
126
|
-
table_id
|
|
127
|
-
} = chart.config;
|
|
128
|
-
const chartRef = (0, _react.useRef)(null);
|
|
129
|
-
const chartContainerRef = (0, _react.useRef)(null);
|
|
130
|
-
const dataSetRef = (0, _react.useRef)(null);
|
|
131
|
-
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
132
|
-
const [mapData, setMapData] = (0, _react.useState)(null);
|
|
133
|
-
const renderCommonChart = (0, _react.useCallback)(function (statisticNewData) {
|
|
134
|
-
const currentDataSet = dataSetRef.current;
|
|
135
|
-
const currentChart = chartRef.current;
|
|
136
|
-
const userDataView = currentDataSet.getView('statisticViewModel').source(statisticNewData).transform({
|
|
137
|
-
geoDataView: currentDataSet.getView('mapDataModel'),
|
|
138
|
-
field: 'name',
|
|
139
|
-
type: 'geo.region',
|
|
140
|
-
as: ['longitude', 'latitude']
|
|
141
|
-
});
|
|
142
|
-
const currentColorOption = _colorRules.COLOR_OPTIONS.filter(item => item.name === data_color)[0] || _colorRules.COLOR_OPTIONS[0];
|
|
143
|
-
const {
|
|
144
|
-
exampleColors,
|
|
145
|
-
highlightedBorderColor
|
|
146
|
-
} = currentColorOption;
|
|
147
|
-
let columnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
148
|
-
if (summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
|
|
149
|
-
const table = (0, _dtableUtils.getTableById)(table_id);
|
|
150
|
-
const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key) || {};
|
|
151
|
-
columnData = summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
152
|
-
}
|
|
153
|
-
const statisticView = currentChart.createView();
|
|
154
|
-
statisticView.data(userDataView.rows);
|
|
155
|
-
|
|
156
|
-
// TODO
|
|
157
|
-
// const themeColors = getThemeColors();
|
|
158
|
-
const legendDirection = legend_direction || 'vertical';
|
|
159
|
-
const size = legend_size || 1;
|
|
160
|
-
statisticView.polygon().position('longitude*latitude').color('value', `${exampleColors[0]}-${exampleColors[4]}-${exampleColors[8]}`).style({
|
|
161
|
-
lineWidth: 1,
|
|
162
|
-
stroke: '#bdbdbd',
|
|
163
|
-
strokeOpacity: 0.5
|
|
164
|
-
}).state({
|
|
165
|
-
active: {
|
|
166
|
-
style: {
|
|
167
|
-
lineWidth: 1,
|
|
168
|
-
stroke: highlightedBorderColor
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}).tooltip('name*value*color', (name, value, color) => {
|
|
172
|
-
return {
|
|
173
|
-
name,
|
|
174
|
-
color,
|
|
175
|
-
value
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
chartRef.current.legend({
|
|
179
|
-
layout: legendDirection,
|
|
180
|
-
position: legendDirection === 'vertical' ? 'left-bottom' : 'bottom-left',
|
|
181
|
-
rail: {
|
|
182
|
-
type: 'color',
|
|
183
|
-
defaultLength: 100 * size
|
|
184
|
-
},
|
|
185
|
-
label: {
|
|
186
|
-
spacing: 2,
|
|
187
|
-
style: {
|
|
188
|
-
// TODO
|
|
189
|
-
// use data_color temporarily
|
|
190
|
-
fill: data_color,
|
|
191
|
-
stroke: '#fff'
|
|
192
|
-
},
|
|
193
|
-
align: legendDirection === 'vertical' ? 'right' : 'bottom',
|
|
194
|
-
formatter: value => {
|
|
195
|
-
return mapGetNumberDisplayString(value, columnData, summary_method);
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
slidable: false
|
|
199
|
-
});
|
|
200
|
-
statisticView.interaction('element-active');
|
|
201
|
-
statisticView.render();
|
|
202
|
-
return statisticView;
|
|
203
|
-
}, [data_color, legend_direction, legend_size, summary_column_key, summary_method, summary_type, table_id]);
|
|
204
|
-
const renderBubbleChart = (0, _react.useCallback)(function (statisticNewData) {
|
|
205
|
-
const currentDataSet = dataSetRef.current;
|
|
206
|
-
const currentChart = chartRef.current;
|
|
207
|
-
const userDv = currentDataSet.createView().source(statisticNewData).transform({
|
|
208
|
-
geoDataView: currentDataSet.getView('mapDataModel'),
|
|
209
|
-
field: 'name',
|
|
210
|
-
type: 'geo.centroid',
|
|
211
|
-
as: ['longitude', 'latitude']
|
|
212
|
-
});
|
|
213
|
-
let columnData = _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
214
|
-
if (summary_type === _constants.CHART_SUMMARY_TYPE.ADVANCED) {
|
|
215
|
-
const table = (0, _dtableUtils.getTableById)(table_id);
|
|
216
|
-
const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, summary_column_key) || {};
|
|
217
|
-
columnData = summaryColumn.data || _constants.DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
218
|
-
}
|
|
219
|
-
const statisticView = currentChart.createView();
|
|
220
|
-
statisticView.data(userDv.rows);
|
|
221
|
-
currentChart.theme({
|
|
222
|
-
defaultColor: bubble_color || '#2a67d1'
|
|
223
|
-
});
|
|
224
|
-
statisticView.point().position('longitude*latitude').size('value', value => {
|
|
225
|
-
const percent = value / statisticNewData.sum;
|
|
226
|
-
let size = percent * 100;
|
|
227
|
-
return size;
|
|
228
|
-
}).shape('circle').color(bubble_color || '#2a67d1').tooltip('name*value*color', (name, value, color) => {
|
|
229
|
-
return {
|
|
230
|
-
name,
|
|
231
|
-
color,
|
|
232
|
-
value
|
|
233
|
-
};
|
|
234
|
-
}).style({
|
|
235
|
-
fillOpacity: 0.6,
|
|
236
|
-
stroke: bubble_color || '#2a67d1'
|
|
237
|
-
}).state({
|
|
238
|
-
active: {
|
|
239
|
-
style: {
|
|
240
|
-
lineWidth: 1,
|
|
241
|
-
stroke: bubble_color || '#2a67d1',
|
|
242
|
-
fillOpacity: 0.9
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// const themeColors = this.getThemeColors();
|
|
248
|
-
const legendDirection = legend_direction || 'vertical';
|
|
249
|
-
const size = legend_size || 1;
|
|
250
|
-
currentChart.legend({
|
|
251
|
-
layout: legendDirection,
|
|
252
|
-
position: legendDirection === 'vertical' ? 'left-bottom' : 'bottom-left',
|
|
253
|
-
rail: {
|
|
254
|
-
type: 'size',
|
|
255
|
-
defaultLength: 100 * size
|
|
256
|
-
},
|
|
257
|
-
label: {
|
|
258
|
-
style: {
|
|
259
|
-
// fill: themeColors.textColor,
|
|
260
|
-
fill: data_color
|
|
261
|
-
},
|
|
262
|
-
align: legendDirection === 'vertical' ? 'right' : 'bottom',
|
|
263
|
-
formatter: value => {
|
|
264
|
-
return mapGetNumberDisplayString(value, columnData, summary_method);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
slidable: false
|
|
268
|
-
});
|
|
269
|
-
statisticView.interaction('element-active');
|
|
270
|
-
statisticView.render();
|
|
271
|
-
return statisticView;
|
|
272
|
-
}, [bubble_color, data_color, legend_direction, legend_size, summary_column_key, summary_method, summary_type, table_id]);
|
|
273
|
-
(0, _react.useEffect)(() => {
|
|
274
|
-
const handleResize = () => {
|
|
275
|
-
const container = chartContainerRef.current;
|
|
276
|
-
const {
|
|
277
|
-
width,
|
|
278
|
-
height
|
|
279
|
-
} = (0, _utils.getMapCanvasStyle)(container, 1.5);
|
|
280
|
-
chartRef.current.changeSize(width, height);
|
|
281
|
-
};
|
|
282
|
-
window.addEventListener('resize', handleResize);
|
|
283
|
-
return () => {
|
|
284
|
-
window.removeEventListener('resize', handleResize);
|
|
285
|
-
};
|
|
286
|
-
}, []);
|
|
287
|
-
|
|
288
|
-
// used to fetch mapJson data
|
|
289
|
-
(0, _react.useEffect)(() => {
|
|
290
|
-
(async () => {
|
|
291
|
-
try {
|
|
292
|
-
const mediaUrl = _context.default.getSetting('mediaUrl');
|
|
293
|
-
const mapJson = await (0, _mapJson.default)(mapLevel, mapLocation, mediaUrl);
|
|
294
|
-
setMapData(mapJson);
|
|
295
|
-
setIsLoading(false);
|
|
296
|
-
} catch (error) {
|
|
297
|
-
console.error(error);
|
|
298
|
-
setIsLoading(false);
|
|
299
|
-
}
|
|
300
|
-
})();
|
|
301
|
-
}, [mapLevel, mapLocation]);
|
|
302
|
-
|
|
303
|
-
// used to init map background
|
|
304
|
-
// if no statistics data, then render empty map
|
|
305
|
-
(0, _react.useEffect)(() => {
|
|
306
|
-
if (!chartRef.current) {
|
|
307
|
-
chartRef.current = createChart(chartContainerRef.current);
|
|
308
|
-
}
|
|
309
|
-
// triggered after mapData is set
|
|
310
|
-
if (!mapData) return;
|
|
311
|
-
const currentChart = chartRef.current;
|
|
312
|
-
initChart(currentChart, props);
|
|
313
|
-
const dataSet = new _dataSet.DataSet();
|
|
314
|
-
dataSetRef.current = dataSet;
|
|
315
|
-
// transform map data
|
|
316
|
-
const data = dataSet.createView('mapDataModel').source(mapData, {
|
|
317
|
-
type: 'GeoJSON'
|
|
318
|
-
});
|
|
319
|
-
const mapView = currentChart.createView();
|
|
320
|
-
// // draw background map
|
|
321
|
-
mapView.data(data.rows);
|
|
322
|
-
mapView.tooltip(false);
|
|
323
|
-
mapView.polygon().position('longitude*latitude').style({
|
|
324
|
-
fill: '#e2e2e2',
|
|
325
|
-
stroke: '#bdbdbd',
|
|
326
|
-
lineWidth: 1
|
|
327
|
-
});
|
|
328
|
-
dataSet.createView('statisticViewModel');
|
|
329
|
-
mapView.render();
|
|
330
|
-
return () => {
|
|
331
|
-
currentChart.destroy();
|
|
332
|
-
};
|
|
333
|
-
},
|
|
334
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
335
|
-
[mapData]);
|
|
336
|
-
(0, _react.useEffect)(() => {
|
|
337
|
-
const currentChart = chartRef.current;
|
|
338
|
-
// need mapData and statisticData to render
|
|
339
|
-
if (!Array.isArray(statisticData) || !mapData) return;
|
|
340
|
-
const statisticNewData = formatStatisticData(statisticData, mapData, type);
|
|
341
|
-
if (statisticNewData.length === 0) {
|
|
342
|
-
currentChart.legend(false);
|
|
343
|
-
currentChart.render();
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
let currentView;
|
|
347
|
-
if (type.includes('bubble')) {
|
|
348
|
-
currentView = renderBubbleChart(statisticNewData);
|
|
349
|
-
} else {
|
|
350
|
-
currentView = renderCommonChart(statisticNewData);
|
|
351
|
-
}
|
|
352
|
-
currentChart.render();
|
|
353
|
-
return () => {
|
|
354
|
-
currentView && currentView.destroy();
|
|
355
|
-
};
|
|
356
|
-
}, [statisticData, mapData, type, renderCommonChart, renderBubbleChart]);
|
|
357
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isLoading && /*#__PURE__*/_react.default.createElement("div", {
|
|
358
|
-
className: 'statistic-chart-loading-container'
|
|
359
|
-
}, /*#__PURE__*/_react.default.createElement(_Loading2.default, null)), /*#__PURE__*/_react.default.createElement("div", {
|
|
360
|
-
className: (0, _classnames.default)('sea-chart-container '),
|
|
361
|
-
style: {
|
|
362
|
-
display: 'flex',
|
|
363
|
-
justifyContent: 'center',
|
|
364
|
-
alignItems: 'center'
|
|
365
|
-
},
|
|
366
|
-
ref: chartContainerRef
|
|
367
|
-
}));
|
|
368
|
-
}
|