sea-chart 0.0.1-beta
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/README.md +120 -0
- package/dist/assets/icons/area-chart.svg +10 -0
- package/dist/assets/icons/bar-chart.svg +12 -0
- package/dist/assets/icons/card.svg +22 -0
- package/dist/assets/icons/combination-chart.svg +17 -0
- package/dist/assets/icons/dtable-logo.svg +16 -0
- package/dist/assets/icons/facet-chart.svg +12 -0
- package/dist/assets/icons/gauge.svg +18 -0
- package/dist/assets/icons/heat-map.svg +14 -0
- package/dist/assets/icons/histogram.svg +12 -0
- package/dist/assets/icons/line-chart.svg +12 -0
- package/dist/assets/icons/map.svg +20 -0
- package/dist/assets/icons/pie-chart.svg +11 -0
- package/dist/assets/icons/rectangular-tree-diagram.svg +10 -0
- package/dist/assets/icons/scatter-chart.svg +15 -0
- package/dist/assets/icons/type-change.svg +17 -0
- package/dist/assets/img/area-chart.png +0 -0
- package/dist/assets/img/area-group-chart.png +0 -0
- package/dist/assets/img/bar-group.png +0 -0
- package/dist/assets/img/bar-stack.png +0 -0
- package/dist/assets/img/bar.png +0 -0
- package/dist/assets/img/combination-chart.png +0 -0
- package/dist/assets/img/compared-chart.png +0 -0
- package/dist/assets/img/completeness-chart.png +0 -0
- package/dist/assets/img/custom-bar.png +0 -0
- package/dist/assets/img/dashboard-chart.png +0 -0
- package/dist/assets/img/group-completeness-chart.png +0 -0
- package/dist/assets/img/group_line.png +0 -0
- package/dist/assets/img/heat-map.png +0 -0
- package/dist/assets/img/horizontal-bar.png +0 -0
- package/dist/assets/img/horizontal-group-bar.png +0 -0
- package/dist/assets/img/line.png +0 -0
- package/dist/assets/img/map-bubble.png +0 -0
- package/dist/assets/img/map.png +0 -0
- package/dist/assets/img/mirror.png +0 -0
- package/dist/assets/img/number-card.png +0 -0
- package/dist/assets/img/pie.png +0 -0
- package/dist/assets/img/pivot-table.png +0 -0
- package/dist/assets/img/ring.png +0 -0
- package/dist/assets/img/scatter.png +0 -0
- package/dist/assets/img/stacked-horizontal-bar.png +0 -0
- package/dist/assets/img/treemap.png +0 -0
- package/dist/assets/img/trend-chart.png +0 -0
- package/dist/assets/img/world-map-bubble.png +0 -0
- package/dist/assets/img/world-map.png +0 -0
- package/dist/components/collaborator/index.js +26 -0
- package/dist/components/icon/index.css +5 -0
- package/dist/components/icon/index.js +24 -0
- package/dist/components/index.js +8 -0
- package/dist/components/loading/index.css +54 -0
- package/dist/components/loading/index.js +12 -0
- package/dist/components/number-input/index.js +31 -0
- package/dist/components/pixel-editor/index.css +29 -0
- package/dist/components/pixel-editor/index.js +38 -0
- package/dist/components/select-group/index.css +67 -0
- package/dist/components/select-group/index.js +52 -0
- package/dist/components/types-dialog/index.css +97 -0
- package/dist/components/types-dialog/index.js +116 -0
- package/dist/constants/geolocation.js +11 -0
- package/dist/constants/index.js +184 -0
- package/dist/constants/model.js +187 -0
- package/dist/constants/style.js +15 -0
- package/dist/constants/type-image.js +59 -0
- package/dist/constants/type.js +124 -0
- package/dist/context.js +33 -0
- package/dist/editor/index.css +0 -0
- package/dist/editor/index.js +36 -0
- package/dist/index.js +6 -0
- package/dist/intl.js +37 -0
- package/dist/locale/index.js +18 -0
- package/dist/locale/lang/de.js +141 -0
- package/dist/locale/lang/en.js +143 -0
- package/dist/locale/lang/es.js +141 -0
- package/dist/locale/lang/fr.js +141 -0
- package/dist/locale/lang/pt.js +141 -0
- package/dist/locale/lang/ru.js +141 -0
- package/dist/locale/lang/zh_CN.js +143 -0
- package/dist/model/area-group.js +41 -0
- package/dist/model/area.js +32 -0
- package/dist/model/bar-group.js +44 -0
- package/dist/model/bar-stack.js +41 -0
- package/dist/model/bar.js +38 -0
- package/dist/model/base-model.js +9 -0
- package/dist/model/basic-number-card.js +22 -0
- package/dist/model/chart.js +23 -0
- package/dist/model/combination.js +38 -0
- package/dist/model/compare-bar.js +39 -0
- package/dist/model/completeness-group.js +24 -0
- package/dist/model/completeness.js +18 -0
- package/dist/model/dashboard.js +16 -0
- package/dist/model/generic-model.js +224 -0
- package/dist/model/heat-map.js +23 -0
- package/dist/model/horizontal-bar.js +38 -0
- package/dist/model/horizontal-group-bar.js +43 -0
- package/dist/model/index.js +63 -0
- package/dist/model/line-group.js +44 -0
- package/dist/model/line.js +38 -0
- package/dist/model/map-bubble.js +27 -0
- package/dist/model/map.js +27 -0
- package/dist/model/mirror.js +26 -0
- package/dist/model/pie.js +26 -0
- package/dist/model/ring.js +26 -0
- package/dist/model/scatter.js +19 -0
- package/dist/model/stacked-horizontal-bar.js +32 -0
- package/dist/model/table.js +23 -0
- package/dist/model/tree-map.js +20 -0
- package/dist/model/trend.js +24 -0
- package/dist/model/user.js +15 -0
- package/dist/model/world-map-bubble.js +26 -0
- package/dist/model/world-map.js +26 -0
- package/dist/settings/advance-bar-settings/data-settings.js +143 -0
- package/dist/settings/advance-bar-settings/index.js +3 -0
- package/dist/settings/advance-bar-settings/style-settings.js +161 -0
- package/dist/settings/bar-settings/data-settings.js +162 -0
- package/dist/settings/bar-settings/index.js +3 -0
- package/dist/settings/bar-settings/style-settings.js +179 -0
- package/dist/settings/basic-number-card/data-settings.js +126 -0
- package/dist/settings/basic-number-card/index.js +3 -0
- package/dist/settings/basic-number-card/style-settings.js +42 -0
- package/dist/settings/combination-settings/data-settings.js +279 -0
- package/dist/settings/combination-settings/index.js +3 -0
- package/dist/settings/combination-settings/style-settings.js +174 -0
- package/dist/settings/dashboard-settings/data-settings.js +179 -0
- package/dist/settings/dashboard-settings/index.js +2 -0
- package/dist/settings/data-settings.js +73 -0
- package/dist/settings/horizontal-bar-settings/data-settings.js +55 -0
- package/dist/settings/horizontal-bar-settings/index.js +3 -0
- package/dist/settings/horizontal-bar-settings/style-settings.js +46 -0
- package/dist/settings/index.css +85 -0
- package/dist/settings/index.js +76 -0
- package/dist/settings/pie-settings/data-settings.js +146 -0
- package/dist/settings/pie-settings/index.js +3 -0
- package/dist/settings/pie-settings/style-settings.js +141 -0
- package/dist/settings/style-settings.js +118 -0
- package/dist/settings/table-settings/data-settings.js +549 -0
- package/dist/settings/table-settings/index.js +2 -0
- package/dist/settings/time-comparison-settings/data-settings.js +172 -0
- package/dist/settings/time-comparison-settings/index.js +3 -0
- package/dist/settings/time-comparison-settings/style-settings.js +213 -0
- package/dist/settings/widgets/basic-summary/index.css +12 -0
- package/dist/settings/widgets/basic-summary/index.js +176 -0
- package/dist/settings/widgets/chart-type/index.css +31 -0
- package/dist/settings/widgets/chart-type/index.js +59 -0
- package/dist/settings/widgets/common-data-settings.js +48 -0
- package/dist/settings/widgets/data-filter/index.css +17 -0
- package/dist/settings/widgets/data-filter/index.js +89 -0
- package/dist/settings/widgets/data-sort.js +44 -0
- package/dist/settings/widgets/date-summary-item.js +111 -0
- package/dist/settings/widgets/display-values-settings/index.css +13 -0
- package/dist/settings/widgets/display-values-settings/index.js +42 -0
- package/dist/settings/widgets/divider/index.css +4 -0
- package/dist/settings/widgets/divider/index.js +12 -0
- package/dist/settings/widgets/font-settings/font-size-settings.js +33 -0
- package/dist/settings/widgets/font-settings/font-weight-settings.js +44 -0
- package/dist/settings/widgets/font-settings/index.js +3 -0
- package/dist/settings/widgets/group-by.js +160 -0
- package/dist/settings/widgets/label-color.js +30 -0
- package/dist/settings/widgets/min-max-setting.js +52 -0
- package/dist/settings/widgets/mininum-slice-percent.js +63 -0
- package/dist/settings/widgets/numeric-summary-item.js +90 -0
- package/dist/settings/widgets/select-table/index.css +0 -0
- package/dist/settings/widgets/select-table/index.js +38 -0
- package/dist/settings/widgets/stack.js +50 -0
- package/dist/settings/widgets/summary-method-setting.js +66 -0
- package/dist/settings/widgets/summary-settings.js +411 -0
- package/dist/settings/widgets/switch/index.css +37 -0
- package/dist/settings/widgets/switch/index.js +24 -0
- package/dist/settings/widgets/text-horizontal-settings.js +25 -0
- package/dist/settings/widgets/time-picker.js +173 -0
- package/dist/settings/widgets/title-settings/index.js +60 -0
- package/dist/settings/widgets/title-settings/title-text.js +25 -0
- package/dist/settings/widgets/x-axios.js +0 -0
- package/dist/settings/widgets/y-axis-group-settings.js +438 -0
- package/dist/utils/cell-format-utils.js +42 -0
- package/dist/utils/chart-data-sql.js +606 -0
- package/dist/utils/chart-utils.js +1800 -0
- package/dist/utils/chart.js +6 -0
- package/dist/utils/collaborator-utils.js +39 -0
- package/dist/utils/column-2-sql-column.js +551 -0
- package/dist/utils/column-utils.js +208 -0
- package/dist/utils/custom-g2.js +612 -0
- package/dist/utils/date-translate.js +66 -0
- package/dist/utils/index.js +48 -0
- package/dist/utils/key-generator.js +13 -0
- package/dist/utils/object-utils.js +45 -0
- package/dist/utils/options-utils.js +60 -0
- package/dist/view/index.css +53 -0
- package/dist/view/index.js +189 -0
- package/dist/view/title/index.css +3 -0
- package/dist/view/title/index.js +46 -0
- package/dist/view/wrapper/area.js +150 -0
- package/dist/view/wrapper/bar-group.js +148 -0
- package/dist/view/wrapper/bar.js +138 -0
- package/dist/view/wrapper/basic-number-card.js +127 -0
- package/dist/view/wrapper/chart-component.js +261 -0
- package/dist/view/wrapper/combination.js +399 -0
- package/dist/view/wrapper/dashboard.js +164 -0
- package/dist/view/wrapper/horizontal-bar-group.js +149 -0
- package/dist/view/wrapper/horizontal-bar.js +140 -0
- package/dist/view/wrapper/horizontal-component.js +78 -0
- package/dist/view/wrapper/index.js +200 -0
- package/dist/view/wrapper/line-group.js +145 -0
- package/dist/view/wrapper/line.js +157 -0
- package/dist/view/wrapper/pie.js +185 -0
- package/dist/view/wrapper/ring.js +264 -0
- package/dist/view/wrapper/table/index.css +103 -0
- package/dist/view/wrapper/table/index.js +31 -0
- package/dist/view/wrapper/table/one-dimension-table-no-numeric-columns.js +144 -0
- package/dist/view/wrapper/table/one-dimension-table-with-numeric-columns.js +198 -0
- package/dist/view/wrapper/table/pivot-table-display-name.js +247 -0
- package/dist/view/wrapper/table/two-dimension-table.js +249 -0
- package/dist/view/wrapper/treemap.js +186 -0
- package/package.json +151 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import { getTableById, getTableColumnByKey } from 'dtable-utils';
|
|
4
|
+
import { Chart } from '../../utils/custom-g2';
|
|
5
|
+
import { ChartUtils } from '../../utils';
|
|
6
|
+
import { CHART_SUMMARY_TYPE, LABEL_COLORS, CHART_SUMMARY_SHOW, LABEL_POSITION_TYPE, EMPTY_NAME } from '../../constants';
|
|
7
|
+
import intl from '../../intl';
|
|
8
|
+
class Combination extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.clearChart = () => {
|
|
12
|
+
this.chart.annotation().clear(true);
|
|
13
|
+
this.chart.clear(true);
|
|
14
|
+
};
|
|
15
|
+
this.drawChart = () => {
|
|
16
|
+
let {
|
|
17
|
+
result: data
|
|
18
|
+
} = this.props;
|
|
19
|
+
this.draw(data);
|
|
20
|
+
};
|
|
21
|
+
this.draw = data => {
|
|
22
|
+
if (!Array.isArray(data)) return;
|
|
23
|
+
const {
|
|
24
|
+
chart,
|
|
25
|
+
theme,
|
|
26
|
+
tables,
|
|
27
|
+
themeName
|
|
28
|
+
} = this.props;
|
|
29
|
+
const {
|
|
30
|
+
table_id,
|
|
31
|
+
y_axis_left_summary_column,
|
|
32
|
+
y_axis_right_summary_column,
|
|
33
|
+
y_axis_left_summary_method,
|
|
34
|
+
y_axis_right_summary_method,
|
|
35
|
+
y_axis_left_summary_type,
|
|
36
|
+
y_axis_right_summary_type,
|
|
37
|
+
y_axis_left_group_by_multiple_numeric_column,
|
|
38
|
+
y_axis_auto_range_left,
|
|
39
|
+
y_axis_min_left,
|
|
40
|
+
y_axis_max_left,
|
|
41
|
+
y_axis_auto_range_right,
|
|
42
|
+
y_axis_min_right,
|
|
43
|
+
y_axis_max_right,
|
|
44
|
+
display_data,
|
|
45
|
+
label_font_size
|
|
46
|
+
} = chart.config;
|
|
47
|
+
this.chart = new Chart({
|
|
48
|
+
container: this.container,
|
|
49
|
+
autoFit: true,
|
|
50
|
+
width: '100%',
|
|
51
|
+
height: '100%',
|
|
52
|
+
appendPadding: [display_data ? 17 : 0, 0, 0, 0]
|
|
53
|
+
});
|
|
54
|
+
const currentTheme = ChartUtils.getCurrentTheme(themeName);
|
|
55
|
+
this.chart.data(data);
|
|
56
|
+
this.chart.coordinate('rect');
|
|
57
|
+
const table = getTableById(tables, table_id);
|
|
58
|
+
const leftSummaryColumn = getTableColumnByKey(table, y_axis_left_summary_column) || {};
|
|
59
|
+
const rightSummaryColumn = getTableColumnByKey(table, y_axis_right_summary_column) || {};
|
|
60
|
+
let leftValueScaleOptions = {
|
|
61
|
+
formatter: value => {
|
|
62
|
+
return ChartUtils.getSummaryValueDisplayString(leftSummaryColumn, value, y_axis_left_summary_method);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
let rightValueScaleOptions = {
|
|
66
|
+
formatter: value => {
|
|
67
|
+
return ChartUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (!y_axis_auto_range_left) {
|
|
71
|
+
leftValueScaleOptions = Object.assign(leftValueScaleOptions, {
|
|
72
|
+
min: y_axis_min_left,
|
|
73
|
+
max: y_axis_max_left
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (!y_axis_auto_range_right) {
|
|
77
|
+
rightValueScaleOptions = Object.assign(rightValueScaleOptions, {
|
|
78
|
+
min: y_axis_min_right,
|
|
79
|
+
max: y_axis_max_right
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
this.chart.scale({
|
|
83
|
+
name: {
|
|
84
|
+
type: 'cat'
|
|
85
|
+
},
|
|
86
|
+
// Automatic adjustment of maximum and minimum values
|
|
87
|
+
value_left: leftValueScaleOptions,
|
|
88
|
+
value_right: rightValueScaleOptions
|
|
89
|
+
});
|
|
90
|
+
this.chart.axis('name', {
|
|
91
|
+
label: {
|
|
92
|
+
style: {
|
|
93
|
+
fill: theme.textColor
|
|
94
|
+
},
|
|
95
|
+
formatter: name => {
|
|
96
|
+
const isString = typeof name === 'string';
|
|
97
|
+
if (!isString) name = String(name);
|
|
98
|
+
if (name === 'undefined') {
|
|
99
|
+
return intl.get(EMPTY_NAME);
|
|
100
|
+
}
|
|
101
|
+
if (name.length > 10) {
|
|
102
|
+
return "".concat(name.slice(0, 10), "...");
|
|
103
|
+
}
|
|
104
|
+
return name;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
line: {
|
|
108
|
+
style: theme.gridColor
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
this.chart.axis('value_left', {
|
|
112
|
+
grid: {
|
|
113
|
+
line: {
|
|
114
|
+
style: {
|
|
115
|
+
stroke: theme.gridColor
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
label: {
|
|
120
|
+
style: {
|
|
121
|
+
fill: theme.textColor
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.chart.axis('value_right', {
|
|
126
|
+
grid: null,
|
|
127
|
+
label: {
|
|
128
|
+
style: {
|
|
129
|
+
fill: theme.textColor
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
let legendPosition = 'bottom';
|
|
134
|
+
this.chart.legend({
|
|
135
|
+
custom: true,
|
|
136
|
+
position: legendPosition,
|
|
137
|
+
itemName: {
|
|
138
|
+
style: {
|
|
139
|
+
fill: theme.textColor
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
items: this.getLegend(leftSummaryColumn, rightSummaryColumn, table, currentTheme)
|
|
143
|
+
});
|
|
144
|
+
this.chart.interval().position('name*value_left').color('color', color => {
|
|
145
|
+
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
146
|
+
return currentTheme.colors[0];
|
|
147
|
+
}
|
|
148
|
+
return color;
|
|
149
|
+
}).adjust('dodge').tooltip('name*value_left', (name, value) => {
|
|
150
|
+
return {
|
|
151
|
+
title: y_axis_left_summary_type === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(CHART_SUMMARY_SHOW[y_axis_left_summary_method]),
|
|
152
|
+
value: ChartUtils.getSummaryValueDisplayString(leftSummaryColumn, value, y_axis_left_summary_method),
|
|
153
|
+
name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
this.chart.tooltip({
|
|
157
|
+
showMarkers: false
|
|
158
|
+
});
|
|
159
|
+
this.chart.line().position('name*value_right').color(currentTheme.colors[1]).size(3).tooltip('name*value_right', (name, value) => {
|
|
160
|
+
return {
|
|
161
|
+
title: y_axis_right_summary_type === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(CHART_SUMMARY_SHOW[y_axis_right_summary_method]),
|
|
162
|
+
value: ChartUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method),
|
|
163
|
+
name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
this.chart.point().position('name*value_right').color(currentTheme.colors[1]).size(3).shape('circle').label(display_data ? 'value_right' : false, {
|
|
167
|
+
style: {
|
|
168
|
+
fontSize: ChartUtils.getLabelFontSize(label_font_size),
|
|
169
|
+
fill: theme.textColor
|
|
170
|
+
}
|
|
171
|
+
}).tooltip('name*value_right', (name, value) => {
|
|
172
|
+
return {
|
|
173
|
+
title: y_axis_right_summary_type === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(CHART_SUMMARY_SHOW[y_axis_right_summary_method]),
|
|
174
|
+
value: ChartUtils.getSummaryValueDisplayString(rightSummaryColumn, value, y_axis_right_summary_method),
|
|
175
|
+
name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
this.chart.removeInteraction('legend-filter');
|
|
179
|
+
this.chart.render();
|
|
180
|
+
this.renderAxisLabel();
|
|
181
|
+
};
|
|
182
|
+
this.renderAxisLabel = () => {
|
|
183
|
+
if (!this.chart) return;
|
|
184
|
+
let {
|
|
185
|
+
chart,
|
|
186
|
+
tables
|
|
187
|
+
} = this.props;
|
|
188
|
+
const {
|
|
189
|
+
config
|
|
190
|
+
} = chart;
|
|
191
|
+
const {
|
|
192
|
+
table_id,
|
|
193
|
+
x_axis_column_key,
|
|
194
|
+
show_y_axis_left_label,
|
|
195
|
+
show_y_axis_right_label,
|
|
196
|
+
x_axis_show_label,
|
|
197
|
+
y_axis_left_label_position,
|
|
198
|
+
y_axis_right_label_position,
|
|
199
|
+
y_axis_left_summary_column,
|
|
200
|
+
y_axis_right_summary_column,
|
|
201
|
+
x_axis_label_position,
|
|
202
|
+
y_axis_left_summary_type,
|
|
203
|
+
y_axis_right_summary_type
|
|
204
|
+
} = config;
|
|
205
|
+
const table = getTableById(tables, table_id);
|
|
206
|
+
const autoPadding = this.chart.autoPadding;
|
|
207
|
+
const textColor = '#999';
|
|
208
|
+
const xAxisID = "chart-x-axis-label_".concat(chart.id);
|
|
209
|
+
const chartContainer = this.chart.getCanvas().get('container');
|
|
210
|
+
const xLabel = chartContainer.querySelector("#".concat(xAxisID));
|
|
211
|
+
if (!xLabel && x_axis_show_label) {
|
|
212
|
+
const div = document.createElement('div');
|
|
213
|
+
div.id = xAxisID;
|
|
214
|
+
div.className = 'chart-axis-label text-truncate';
|
|
215
|
+
const column = getTableColumnByKey(table, x_axis_column_key);
|
|
216
|
+
div.innerHTML = "".concat(column ? column.name : '');
|
|
217
|
+
div.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
|
|
218
|
+
chartContainer.appendChild(div);
|
|
219
|
+
}
|
|
220
|
+
if (xLabel && x_axis_show_label) {
|
|
221
|
+
xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
|
|
222
|
+
}
|
|
223
|
+
if (xLabel && !x_axis_show_label) {
|
|
224
|
+
xLabel.parentNode.removeChild(xLabel);
|
|
225
|
+
}
|
|
226
|
+
const yAxisLeftID = "chart-y-axis-left-label_".concat(chart.id);
|
|
227
|
+
const yAxisLeftLabel = chartContainer.querySelector("#".concat(yAxisLeftID));
|
|
228
|
+
if (!yAxisLeftLabel && show_y_axis_left_label) {
|
|
229
|
+
const div = document.createElement('div');
|
|
230
|
+
div.id = yAxisLeftID;
|
|
231
|
+
div.className = 'chart-axis-label text-truncate';
|
|
232
|
+
if (y_axis_left_summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
233
|
+
div.innerHTML = intl.get('Amount');
|
|
234
|
+
} else {
|
|
235
|
+
const column = getTableColumnByKey(table, y_axis_left_summary_column) || {};
|
|
236
|
+
div.innerHTML = column.name || '';
|
|
237
|
+
}
|
|
238
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
239
|
+
let textAlign = 'center';
|
|
240
|
+
if (y_axis_left_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
241
|
+
if (y_axis_left_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
242
|
+
div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
|
|
243
|
+
chartContainer.appendChild(div);
|
|
244
|
+
}
|
|
245
|
+
if (yAxisLeftLabel && show_y_axis_left_label) {
|
|
246
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
247
|
+
let textAlign = 'center';
|
|
248
|
+
if (y_axis_left_label_position === 'bottom') textAlign = 'left';
|
|
249
|
+
if (y_axis_left_label_position === 'top') textAlign = 'right';
|
|
250
|
+
yAxisLeftLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; left: 0; transform: translate(-").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
|
|
251
|
+
}
|
|
252
|
+
if (yAxisLeftLabel && !show_y_axis_left_label) {
|
|
253
|
+
yAxisLeftLabel.parentNode.removeChild(yAxisLeftLabel);
|
|
254
|
+
}
|
|
255
|
+
const yAxisRightID = "chart-y-axis-right-label_".concat(chart.id);
|
|
256
|
+
const yAxisRightLabel = chartContainer.querySelector("#".concat(yAxisRightID));
|
|
257
|
+
if (!yAxisRightLabel && show_y_axis_right_label) {
|
|
258
|
+
const div = document.createElement('div');
|
|
259
|
+
div.id = yAxisRightID;
|
|
260
|
+
div.className = 'chart-axis-label text-truncate';
|
|
261
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
262
|
+
div.innerHTML = intl.get('Amount');
|
|
263
|
+
} else {
|
|
264
|
+
const column = getTableColumnByKey(table, y_axis_right_summary_column) || {};
|
|
265
|
+
div.innerHTML = column.name || '';
|
|
266
|
+
}
|
|
267
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
268
|
+
let textAlign = 'center';
|
|
269
|
+
if (y_axis_right_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
270
|
+
if (y_axis_right_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
271
|
+
div.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; right: 0; transform: translate(").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
|
|
272
|
+
chartContainer.appendChild(div);
|
|
273
|
+
}
|
|
274
|
+
if (yAxisRightLabel && show_y_axis_right_label) {
|
|
275
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
276
|
+
let textAlign = 'center';
|
|
277
|
+
if (y_axis_right_label_position === 'bottom') textAlign = 'left';
|
|
278
|
+
if (y_axis_right_label_position === 'top') textAlign = 'right';
|
|
279
|
+
yAxisRightLabel.setAttribute('style', "color:".concat(textColor, "; position: absolute; width: ").concat(containerHeight, "px; text-align: ").concat(textAlign, "; top: 0; right: 0; transform: translate(").concat(containerHeight / 2 + 12, "px, ").concat((containerHeight - autoPadding.bottom) / 2 + autoPadding.bottom / 4, "px) rotate(-90deg)"));
|
|
280
|
+
}
|
|
281
|
+
if (yAxisRightLabel && !show_y_axis_right_label) {
|
|
282
|
+
yAxisRightLabel.parentNode.removeChild(yAxisRightLabel);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
this.getLegend = (leftSummaryColumn, rightSummaryColumn, table, currentTheme) => {
|
|
286
|
+
const {
|
|
287
|
+
chart
|
|
288
|
+
} = this.props;
|
|
289
|
+
const {
|
|
290
|
+
y_axis_left_group_by_multiple_numeric_column,
|
|
291
|
+
y_axis_left_group_by_numeric_columns
|
|
292
|
+
} = chart.config;
|
|
293
|
+
const legendItems = [];
|
|
294
|
+
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
295
|
+
legendItems.push({
|
|
296
|
+
value: 'value_left',
|
|
297
|
+
name: leftSummaryColumn.name || intl.get('Left'),
|
|
298
|
+
marker: {
|
|
299
|
+
symbol: 'square',
|
|
300
|
+
style: {
|
|
301
|
+
fill: currentTheme.colors[0],
|
|
302
|
+
r: 5
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}, {
|
|
306
|
+
value: 'value_right',
|
|
307
|
+
name: rightSummaryColumn.name || intl.get('Right'),
|
|
308
|
+
marker: {
|
|
309
|
+
symbol: 'hyphen',
|
|
310
|
+
style: {
|
|
311
|
+
stroke: currentTheme.colors[1],
|
|
312
|
+
r: 5,
|
|
313
|
+
lineWidth: 3
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
legendItems.push({
|
|
319
|
+
value: 'value_left',
|
|
320
|
+
name: leftSummaryColumn.name || intl.get('Left'),
|
|
321
|
+
marker: {
|
|
322
|
+
fill: LABEL_COLORS[0],
|
|
323
|
+
symbol: 'square',
|
|
324
|
+
style: {
|
|
325
|
+
r: 5
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
330
|
+
const column = getTableColumnByKey(table, item.column_key);
|
|
331
|
+
if (column) {
|
|
332
|
+
legendItems.push({
|
|
333
|
+
value: 'group_name',
|
|
334
|
+
name: column.name || intl.get('Left'),
|
|
335
|
+
marker: {
|
|
336
|
+
symbol: 'square',
|
|
337
|
+
style: {
|
|
338
|
+
fill: LABEL_COLORS[(index + 1) % 12],
|
|
339
|
+
r: 5
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
legendItems.push({
|
|
346
|
+
value: 'value_right',
|
|
347
|
+
name: rightSummaryColumn.name || intl.get('Right'),
|
|
348
|
+
marker: {
|
|
349
|
+
symbol: 'hyphen',
|
|
350
|
+
style: {
|
|
351
|
+
stroke: currentTheme.colors[1],
|
|
352
|
+
r: 5,
|
|
353
|
+
lineWidth: 3
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return legendItems;
|
|
359
|
+
};
|
|
360
|
+
this.isShowXAxisLabel = chart => {
|
|
361
|
+
return !!(chart && chart.config && chart.config.x_axis_show_label);
|
|
362
|
+
};
|
|
363
|
+
this.isShowYAxisLeftLabel = chart => {
|
|
364
|
+
return !!(chart && chart.config && chart.config.show_y_axis_left_label);
|
|
365
|
+
};
|
|
366
|
+
this.isShowYAxisRightLabel = chart => {
|
|
367
|
+
return !!(chart && chart.config && chart.config.show_y_axis_right_label);
|
|
368
|
+
};
|
|
369
|
+
this.chart = null;
|
|
370
|
+
}
|
|
371
|
+
componentDidMount() {
|
|
372
|
+
this.drawChart();
|
|
373
|
+
this.renderAxisLabel(this.props.chart, this.props.tables);
|
|
374
|
+
}
|
|
375
|
+
componentDidUpdate(prevProps) {
|
|
376
|
+
if (ChartUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
377
|
+
this.chart && this.chart.destroy();
|
|
378
|
+
this.drawChart();
|
|
379
|
+
this.renderAxisLabel(prevProps.chart, prevProps.tables);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
componentWillUnmount() {
|
|
383
|
+
this.chart && this.chart.destroy();
|
|
384
|
+
}
|
|
385
|
+
render() {
|
|
386
|
+
const {
|
|
387
|
+
chart
|
|
388
|
+
} = this.props;
|
|
389
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
390
|
+
className: classnames('sea-chart-container w-100', {
|
|
391
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
392
|
+
'show-y-axis-left-label': this.isShowYAxisLeftLabel(chart),
|
|
393
|
+
'show-y-axis-right-label': this.isShowYAxisRightLabel(chart)
|
|
394
|
+
}),
|
|
395
|
+
ref: ref => this.container = ref
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
export default Combination;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { isNumber } from 'dtable-utils';
|
|
3
|
+
import { Chart, registerShape } from '../../utils/custom-g2';
|
|
4
|
+
import { ChartUtils } from '../../utils';
|
|
5
|
+
class Dashboard extends Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.componentDidMount = () => {
|
|
9
|
+
this.drawChart();
|
|
10
|
+
};
|
|
11
|
+
this.drawChart = () => {
|
|
12
|
+
const {
|
|
13
|
+
chart,
|
|
14
|
+
theme,
|
|
15
|
+
canvasStyle,
|
|
16
|
+
result
|
|
17
|
+
} = this.props;
|
|
18
|
+
const value = isNumber(result) ? result : 0;
|
|
19
|
+
const {
|
|
20
|
+
config
|
|
21
|
+
} = chart;
|
|
22
|
+
this.chart = new Chart({
|
|
23
|
+
container: this.container,
|
|
24
|
+
autoFit: true,
|
|
25
|
+
width: '100%',
|
|
26
|
+
height: '100%'
|
|
27
|
+
});
|
|
28
|
+
registerShape('point', 'pointer', {
|
|
29
|
+
draw(cfg, container) {
|
|
30
|
+
const group = container.addGroup();
|
|
31
|
+
const center = this.parsePoint({
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0
|
|
34
|
+
});
|
|
35
|
+
group.addShape('line', {
|
|
36
|
+
attrs: {
|
|
37
|
+
x1: center.x,
|
|
38
|
+
y1: center.y - 15,
|
|
39
|
+
x2: cfg.x,
|
|
40
|
+
y2: cfg.y - 15,
|
|
41
|
+
stroke: cfg.color,
|
|
42
|
+
lineWidth: 5,
|
|
43
|
+
lineCap: 'round'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
group.addShape('circle', {
|
|
47
|
+
attrs: {
|
|
48
|
+
x: center.x,
|
|
49
|
+
y: center.y - 15,
|
|
50
|
+
r: 9.75,
|
|
51
|
+
stroke: cfg.color,
|
|
52
|
+
lineWidth: 4.5,
|
|
53
|
+
fill: '#fff'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return group;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const number = value > 1 ? 10 : value * 10;
|
|
60
|
+
const data = [{
|
|
61
|
+
value: number
|
|
62
|
+
}];
|
|
63
|
+
this.chart.data(data);
|
|
64
|
+
this.chart.scale('value', {
|
|
65
|
+
min: 0,
|
|
66
|
+
max: 10,
|
|
67
|
+
tickInterval: 1
|
|
68
|
+
});
|
|
69
|
+
this.chart.coordinate('polar', {
|
|
70
|
+
startAngle: -9 / 8 * Math.PI,
|
|
71
|
+
endAngle: 1 / 8 * Math.PI,
|
|
72
|
+
radius: 0.75
|
|
73
|
+
});
|
|
74
|
+
this.chart.axis('1', false);
|
|
75
|
+
this.chart.axis('value', {
|
|
76
|
+
line: null,
|
|
77
|
+
label: {
|
|
78
|
+
offset: -36,
|
|
79
|
+
style: {
|
|
80
|
+
fontSize: 12,
|
|
81
|
+
textAlign: 'center',
|
|
82
|
+
textBaseline: 'middle'
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
subTickLine: {
|
|
86
|
+
count: 4,
|
|
87
|
+
length: -15
|
|
88
|
+
},
|
|
89
|
+
tickLine: {
|
|
90
|
+
length: -24
|
|
91
|
+
},
|
|
92
|
+
grid: null,
|
|
93
|
+
offsetY: -15
|
|
94
|
+
});
|
|
95
|
+
this.chart.legend(false);
|
|
96
|
+
this.chart.point().position('value*1').shape('pointer').color('#1890FF').animate({
|
|
97
|
+
appear: {
|
|
98
|
+
animation: 'fade-in'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
this.chart.annotation().arc({
|
|
102
|
+
top: false,
|
|
103
|
+
start: [0, 1],
|
|
104
|
+
end: [10, 1],
|
|
105
|
+
style: {
|
|
106
|
+
stroke: '#CBCBCB',
|
|
107
|
+
lineWidth: 10,
|
|
108
|
+
lineDash: null
|
|
109
|
+
},
|
|
110
|
+
offsetY: -15
|
|
111
|
+
});
|
|
112
|
+
this.chart.annotation().arc({
|
|
113
|
+
start: [0, 1],
|
|
114
|
+
end: [data[0].value, 1],
|
|
115
|
+
style: {
|
|
116
|
+
stroke: '#1890FF',
|
|
117
|
+
lineWidth: 10,
|
|
118
|
+
lineDash: null
|
|
119
|
+
},
|
|
120
|
+
offsetY: -15
|
|
121
|
+
});
|
|
122
|
+
this.chart.annotation().text({
|
|
123
|
+
position: ['50%', '85%'],
|
|
124
|
+
content: config.name,
|
|
125
|
+
style: {
|
|
126
|
+
fontSize: canvasStyle.height > 240 ? 20 : 12,
|
|
127
|
+
fill: '#545454',
|
|
128
|
+
textAlign: 'center'
|
|
129
|
+
},
|
|
130
|
+
offsetY: -10
|
|
131
|
+
});
|
|
132
|
+
let shownValue = value * 100;
|
|
133
|
+
const shownDotPos = "".concat(shownValue).indexOf('.');
|
|
134
|
+
if (shownDotPos > -1 && shownDotPos < "".concat(shownValue).length - 2) {
|
|
135
|
+
shownValue = shownValue.toFixed(1);
|
|
136
|
+
}
|
|
137
|
+
this.chart.annotation().text({
|
|
138
|
+
position: ['50%', '90%'],
|
|
139
|
+
content: "".concat(shownValue, " %"),
|
|
140
|
+
style: {
|
|
141
|
+
fontSize: canvasStyle.height > 240 ? 36 : 16,
|
|
142
|
+
fill: theme.textColor,
|
|
143
|
+
textAlign: 'center'
|
|
144
|
+
},
|
|
145
|
+
offsetY: 0
|
|
146
|
+
});
|
|
147
|
+
this.chart.render();
|
|
148
|
+
this.container.title = "".concat(data[0].value * 10, " %");
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
componentDidUpdate(prevProps) {
|
|
152
|
+
if (ChartUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
153
|
+
this.chart && this.chart.destroy();
|
|
154
|
+
this.drawChart();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
render() {
|
|
158
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
159
|
+
ref: ref => this.container = ref,
|
|
160
|
+
className: "sea-chart-container w-100"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export default Dashboard;
|