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,149 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { EMPTY_NAME } from '../../constants';
|
|
5
|
+
import { ChartUtils } from '../../utils';
|
|
6
|
+
import HorizontalComponent from './horizontal-component';
|
|
7
|
+
import intl from '../../intl';
|
|
8
|
+
class HorizontalBarGroup extends HorizontalComponent {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.createChart = () => {
|
|
12
|
+
const {
|
|
13
|
+
chart
|
|
14
|
+
} = this.props;
|
|
15
|
+
const {
|
|
16
|
+
display_data
|
|
17
|
+
} = chart.config;
|
|
18
|
+
const appendPadding = [0, display_data ? 17 : 0, 0, 0];
|
|
19
|
+
this.initChart(this.container, {
|
|
20
|
+
appendPadding
|
|
21
|
+
});
|
|
22
|
+
this.chart.on('interval:click', e => {
|
|
23
|
+
this.props.toggleRecords(e.data.data);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
this.clearChart = () => {
|
|
27
|
+
this.chart.annotation().clear(true);
|
|
28
|
+
this.chart.clear(true);
|
|
29
|
+
};
|
|
30
|
+
this.drawChart = () => {
|
|
31
|
+
let {
|
|
32
|
+
result: data
|
|
33
|
+
} = this.props;
|
|
34
|
+
data = ChartUtils.formatEmptyName(data, '', intl.get('Empty'));
|
|
35
|
+
if (!Array.isArray(data)) return;
|
|
36
|
+
this.chart.scale(this.groupName, {
|
|
37
|
+
type: 'cat'
|
|
38
|
+
});
|
|
39
|
+
this.loadData(data);
|
|
40
|
+
this.draw(data);
|
|
41
|
+
this.chart.render();
|
|
42
|
+
};
|
|
43
|
+
this.draw = data => {
|
|
44
|
+
const {
|
|
45
|
+
chart,
|
|
46
|
+
summaryColumn,
|
|
47
|
+
theme
|
|
48
|
+
} = this.props;
|
|
49
|
+
const {
|
|
50
|
+
horizontal_axis_summary_method,
|
|
51
|
+
display_data,
|
|
52
|
+
label_font_size
|
|
53
|
+
} = chart.config;
|
|
54
|
+
const chartBarColor = this.groupName;
|
|
55
|
+
const newData = this.getChartGroupData(data);
|
|
56
|
+
this.drawLabels(newData);
|
|
57
|
+
|
|
58
|
+
// set Coord type
|
|
59
|
+
this.chart.coordinate('rect');
|
|
60
|
+
this.autoAdjustDataOptions(chart, data, summaryColumn);
|
|
61
|
+
this.chart.interval().label(display_data ? 'value' : false, {
|
|
62
|
+
formatter: value => {
|
|
63
|
+
return value;
|
|
64
|
+
},
|
|
65
|
+
style: {
|
|
66
|
+
fontSize: ChartUtils.getLabelFontSize(label_font_size),
|
|
67
|
+
fill: theme.textColor
|
|
68
|
+
}
|
|
69
|
+
}).position('name*value').color(chartBarColor).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
|
|
70
|
+
return {
|
|
71
|
+
title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
|
|
72
|
+
value: ChartUtils.getSummaryValueDisplayString(summaryColumn, value, horizontal_axis_summary_method),
|
|
73
|
+
name: !group_name && typeof group_name !== 'number' ? intl.get(EMPTY_NAME) : group_name
|
|
74
|
+
};
|
|
75
|
+
}).adjust([{
|
|
76
|
+
type: 'dodge'
|
|
77
|
+
}]).state({
|
|
78
|
+
active: {
|
|
79
|
+
style: {
|
|
80
|
+
stroke: null
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.chart.tooltip({
|
|
85
|
+
showTitle: true,
|
|
86
|
+
showMarkers: false,
|
|
87
|
+
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
|
|
88
|
+
itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
|
|
89
|
+
domStyles: {
|
|
90
|
+
'g2-tooltip': {
|
|
91
|
+
borderRadius: '2px',
|
|
92
|
+
backgroundColor: '#fff',
|
|
93
|
+
padding: '10px'
|
|
94
|
+
},
|
|
95
|
+
'tooltip-item': {
|
|
96
|
+
marginTop: '5px'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
this.setNameLabelAndTooltip(theme, this.labelCount);
|
|
101
|
+
this.setValueLabel(theme);
|
|
102
|
+
this.setLegend(this.groupName, theme, 'bottom');
|
|
103
|
+
this.chart.coordinate().transpose();
|
|
104
|
+
this.chart.interaction('active-region');
|
|
105
|
+
};
|
|
106
|
+
this.chart = null;
|
|
107
|
+
this.groupName = 'group_name';
|
|
108
|
+
}
|
|
109
|
+
componentDidMount() {
|
|
110
|
+
this.createChart();
|
|
111
|
+
this.drawChart();
|
|
112
|
+
this.renderHorizontalLabel(this.props.chart, this.props.tables);
|
|
113
|
+
}
|
|
114
|
+
componentDidUpdate(prevProps) {
|
|
115
|
+
if (ChartUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
116
|
+
this.chart && this.chart.destroy();
|
|
117
|
+
this.createChart();
|
|
118
|
+
this.drawChart();
|
|
119
|
+
this.renderHorizontalLabel(prevProps.chart, prevProps.tables);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
componentWillUnmount() {
|
|
123
|
+
this.chart && this.chart.destroy();
|
|
124
|
+
}
|
|
125
|
+
render() {
|
|
126
|
+
const {
|
|
127
|
+
chart
|
|
128
|
+
} = this.props;
|
|
129
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
130
|
+
className: classnames('sea-chart-container w-100', {
|
|
131
|
+
'show-vertical-axis-label': this.isShowVerticalAxisLabel(chart),
|
|
132
|
+
'show-horizontal-axis-label': this.isShowHorizontalAxisLabel(chart)
|
|
133
|
+
}),
|
|
134
|
+
ref: ref => this.container = ref
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
HorizontalBarGroup.propTypes = {
|
|
139
|
+
canvasStyle: PropTypes.object,
|
|
140
|
+
chart: PropTypes.object,
|
|
141
|
+
groupbyColumn: PropTypes.object,
|
|
142
|
+
columnGroupbyColumn: PropTypes.object,
|
|
143
|
+
summaryColumn: PropTypes.object,
|
|
144
|
+
result: PropTypes.array,
|
|
145
|
+
tables: PropTypes.array,
|
|
146
|
+
theme: PropTypes.object,
|
|
147
|
+
toggleRecords: PropTypes.func
|
|
148
|
+
};
|
|
149
|
+
export default HorizontalBarGroup;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { CHART_SUMMARY_TYPE, CHART_SUMMARY_SHOW } from '../../constants';
|
|
5
|
+
import { ChartUtils } from '../../utils';
|
|
6
|
+
import HorizontalComponent from './horizontal-component';
|
|
7
|
+
import intl from '../../intl';
|
|
8
|
+
class HorizontalBar extends HorizontalComponent {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.createChart = () => {
|
|
12
|
+
const {
|
|
13
|
+
chart
|
|
14
|
+
} = this.props;
|
|
15
|
+
const {
|
|
16
|
+
display_data
|
|
17
|
+
} = chart.config;
|
|
18
|
+
const appendPadding = [0, display_data ? 17 : 0, 0, 0]; // used to display value on the right
|
|
19
|
+
this.initChart(this.container, {
|
|
20
|
+
appendPadding
|
|
21
|
+
});
|
|
22
|
+
this.chart.on('interval:click', e => {
|
|
23
|
+
this.props.toggleRecords(e.data.data);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
this.clearChart = () => {
|
|
27
|
+
this.chart.annotation().clear(true);
|
|
28
|
+
this.chart.clear(true);
|
|
29
|
+
};
|
|
30
|
+
this.drawChart = () => {
|
|
31
|
+
let {
|
|
32
|
+
result: data
|
|
33
|
+
} = this.props;
|
|
34
|
+
data = ChartUtils.formatEmptyName(data, '', intl.get('Empty'));
|
|
35
|
+
if (!Array.isArray(data)) return;
|
|
36
|
+
this.loadData(data);
|
|
37
|
+
this.draw(data);
|
|
38
|
+
this.chart.render();
|
|
39
|
+
this.renderHorizontalLabel(this.props.chart, this.props.tables);
|
|
40
|
+
};
|
|
41
|
+
this.draw = data => {
|
|
42
|
+
const {
|
|
43
|
+
chart,
|
|
44
|
+
summaryColumn,
|
|
45
|
+
theme
|
|
46
|
+
} = this.props;
|
|
47
|
+
const {
|
|
48
|
+
horizontal_axis_summary_type,
|
|
49
|
+
horizontal_axis_summary_method,
|
|
50
|
+
horizontal_axis_label_color,
|
|
51
|
+
display_data,
|
|
52
|
+
label_font_size
|
|
53
|
+
} = chart.config;
|
|
54
|
+
const chartBarColor = horizontal_axis_label_color || '#2a67d1';
|
|
55
|
+
data.reverse();
|
|
56
|
+
this.drawLabels(data);
|
|
57
|
+
|
|
58
|
+
// set Coord type
|
|
59
|
+
this.chart.coordinate('rect');
|
|
60
|
+
this.autoAdjustDataOptions(chart, data, summaryColumn);
|
|
61
|
+
this.chart.interval().label(display_data ? 'value' : false, {
|
|
62
|
+
style: {
|
|
63
|
+
fontSize: ChartUtils.getLabelFontSize(label_font_size),
|
|
64
|
+
fill: theme.textColor
|
|
65
|
+
}
|
|
66
|
+
}).position('name*value').color(chartBarColor).tooltip('name*value', (name, value) => {
|
|
67
|
+
return {
|
|
68
|
+
title: horizontal_axis_summary_type === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(CHART_SUMMARY_SHOW[horizontal_axis_summary_method]),
|
|
69
|
+
value: ChartUtils.getSummaryValueDisplayString(summaryColumn, value, horizontal_axis_summary_method),
|
|
70
|
+
name
|
|
71
|
+
};
|
|
72
|
+
}).state({
|
|
73
|
+
active: {
|
|
74
|
+
style: {
|
|
75
|
+
stroke: null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.chart.tooltip({
|
|
80
|
+
showTitle: true,
|
|
81
|
+
showMarkers: false,
|
|
82
|
+
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
|
|
83
|
+
itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
|
|
84
|
+
domStyles: {
|
|
85
|
+
'g2-tooltip': {
|
|
86
|
+
borderRadius: '2px',
|
|
87
|
+
backgroundColor: '#fff',
|
|
88
|
+
padding: '10px'
|
|
89
|
+
},
|
|
90
|
+
'tooltip-item': {
|
|
91
|
+
marginTop: '5px'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.setNameLabelAndTooltip(theme, this.labelCount);
|
|
96
|
+
this.setValueLabel(theme);
|
|
97
|
+
this.chart.coordinate().transpose();
|
|
98
|
+
this.chart.interaction('active-region');
|
|
99
|
+
};
|
|
100
|
+
this.chart = null;
|
|
101
|
+
}
|
|
102
|
+
componentDidMount() {
|
|
103
|
+
this.createChart();
|
|
104
|
+
this.drawChart();
|
|
105
|
+
}
|
|
106
|
+
componentDidUpdate(prevProps) {
|
|
107
|
+
if (ChartUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
108
|
+
this.chart && this.chart.destroy();
|
|
109
|
+
this.createChart();
|
|
110
|
+
this.drawChart();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
componentWillUnmount() {
|
|
114
|
+
this.chart && this.chart.destroy();
|
|
115
|
+
}
|
|
116
|
+
render() {
|
|
117
|
+
const {
|
|
118
|
+
chart
|
|
119
|
+
} = this.props;
|
|
120
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
121
|
+
className: classnames('sea-chart-container w-100', {
|
|
122
|
+
'show-vertical-axis-label': this.isShowVerticalAxisLabel(chart),
|
|
123
|
+
'show-horizontal-axis-label': this.isShowHorizontalAxisLabel(chart)
|
|
124
|
+
}),
|
|
125
|
+
ref: ref => this.container = ref
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
HorizontalBar.propTypes = {
|
|
130
|
+
canvasStyle: PropTypes.object,
|
|
131
|
+
chart: PropTypes.object,
|
|
132
|
+
groupbyColumn: PropTypes.object,
|
|
133
|
+
columnGroupbyColumn: PropTypes.object,
|
|
134
|
+
summaryColumn: PropTypes.object,
|
|
135
|
+
result: PropTypes.array,
|
|
136
|
+
tables: PropTypes.array,
|
|
137
|
+
theme: PropTypes.object,
|
|
138
|
+
toggleRecords: PropTypes.func
|
|
139
|
+
};
|
|
140
|
+
export default HorizontalBar;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getTableById, getTableColumnByKey } from 'dtable-utils';
|
|
2
|
+
import ChartComponent from './chart-component';
|
|
3
|
+
import { CHART_SUMMARY_TYPE, LABEL_POSITION_TYPE } from '../../constants';
|
|
4
|
+
import intl from '../../intl';
|
|
5
|
+
export default class HorizontalComponent extends ChartComponent {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.renderHorizontalLabel = (chart, tables) => {
|
|
9
|
+
if (!this.chart || !chart) return;
|
|
10
|
+
let {
|
|
11
|
+
table_id,
|
|
12
|
+
x_axis_column_key,
|
|
13
|
+
y_axis_summary_column_key,
|
|
14
|
+
y_axis_label_position,
|
|
15
|
+
x_axis_label_position,
|
|
16
|
+
y_axis_summary_type,
|
|
17
|
+
show_vertical_axis_label,
|
|
18
|
+
show_horizontal_axis_label
|
|
19
|
+
} = chart.config;
|
|
20
|
+
const table = getTableById(tables, table_id);
|
|
21
|
+
const autoPadding = this.chart.autoPadding;
|
|
22
|
+
const textColor = '#999999';
|
|
23
|
+
const xAxisID = "chart-x-axis-label_".concat(chart.id);
|
|
24
|
+
const chartContainer = this.chart.getCanvas().get('container');
|
|
25
|
+
const xLabel = chartContainer.querySelector("#".concat(xAxisID));
|
|
26
|
+
if (!xLabel && show_horizontal_axis_label) {
|
|
27
|
+
const div = document.createElement('div');
|
|
28
|
+
div.id = xAxisID;
|
|
29
|
+
div.className = 'chart-axis-label';
|
|
30
|
+
if (y_axis_summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
31
|
+
div.innerHTML = intl.get('Amount');
|
|
32
|
+
} else {
|
|
33
|
+
const column = getTableColumnByKey(table, y_axis_summary_column_key);
|
|
34
|
+
div.innerHTML = "".concat(column ? column.name : '');
|
|
35
|
+
}
|
|
36
|
+
div.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
|
|
37
|
+
chartContainer.appendChild(div);
|
|
38
|
+
}
|
|
39
|
+
if (xLabel && show_horizontal_axis_label) {
|
|
40
|
+
xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
|
|
41
|
+
}
|
|
42
|
+
if (xLabel && !show_horizontal_axis_label) {
|
|
43
|
+
xLabel.parentNode.removeChild(xLabel);
|
|
44
|
+
}
|
|
45
|
+
const yAxisID = "chart-y-axis-label_".concat(chart.id);
|
|
46
|
+
const yLabel = chartContainer.querySelector("#".concat(yAxisID));
|
|
47
|
+
if (!yLabel && show_vertical_axis_label) {
|
|
48
|
+
const div = document.createElement('div');
|
|
49
|
+
div.id = yAxisID;
|
|
50
|
+
div.className = 'chart-axis-label';
|
|
51
|
+
const column = getTableColumnByKey(table, x_axis_column_key) || {};
|
|
52
|
+
div.innerHTML = column.name || '';
|
|
53
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
54
|
+
let textAlign = 'center';
|
|
55
|
+
if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
56
|
+
if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
57
|
+
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)"));
|
|
58
|
+
chartContainer.appendChild(div);
|
|
59
|
+
}
|
|
60
|
+
if (yLabel && show_horizontal_axis_label) {
|
|
61
|
+
const containerHeight = chartContainer.offsetHeight;
|
|
62
|
+
let textAlign = 'center';
|
|
63
|
+
if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
|
|
64
|
+
if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
|
|
65
|
+
yLabel.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)"));
|
|
66
|
+
}
|
|
67
|
+
if (yLabel && !show_horizontal_axis_label) {
|
|
68
|
+
yLabel.parentNode.removeChild(yLabel);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
this.isShowVerticalAxisLabel = chart => {
|
|
72
|
+
return !!(chart && chart.config && chart.config.show_vertical_axis_label);
|
|
73
|
+
};
|
|
74
|
+
this.isShowHorizontalAxisLabel = chart => {
|
|
75
|
+
return !!(chart && chart.config && chart.config.show_horizontal_axis_label);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { CHART_TYPE, CHART_THEME_COLOR } from '../../constants';
|
|
3
|
+
import { ChartUtils, eventStopPropagation } from '../../utils';
|
|
4
|
+
import Table from './table';
|
|
5
|
+
import Bar from './bar';
|
|
6
|
+
import BarGroup from './bar-group';
|
|
7
|
+
import Line from './line';
|
|
8
|
+
import LineGroup from './line-group';
|
|
9
|
+
import Pie from './pie';
|
|
10
|
+
import Ring from './ring';
|
|
11
|
+
import HorizontalBar from './horizontal-bar';
|
|
12
|
+
import HorizontalBarGroup from './horizontal-bar-group';
|
|
13
|
+
import Area from './area';
|
|
14
|
+
import BasicNumericCard from './basic-number-card';
|
|
15
|
+
import Treemap from './treemap';
|
|
16
|
+
import Combination from './combination';
|
|
17
|
+
import Dashboard from './dashboard';
|
|
18
|
+
const Wrapper = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
data,
|
|
21
|
+
chart,
|
|
22
|
+
tables,
|
|
23
|
+
canvasStyle
|
|
24
|
+
} = _ref;
|
|
25
|
+
// const [statisticRecords, setStatisticRecords] = useState({});
|
|
26
|
+
// const [isStatisticRecordsDialogShow, setIsStatisticRecordsDialogShow] = useState(false);
|
|
27
|
+
// const [selectedCell, setSelectedCell] = useState({});
|
|
28
|
+
|
|
29
|
+
const toggleStatisticRecordsDialog = useCallback((statisticRecords, selectedCell) => {
|
|
30
|
+
// setIsStatisticRecordsDialogShow(!isStatisticRecordsDialogShow)
|
|
31
|
+
// setSelectedCell(selectedCell);
|
|
32
|
+
// setStatisticRecords(statisticRecords);
|
|
33
|
+
}, []);
|
|
34
|
+
const onTableClick = useCallback(event => {
|
|
35
|
+
eventStopPropagation(event);
|
|
36
|
+
}, []);
|
|
37
|
+
const {
|
|
38
|
+
result,
|
|
39
|
+
groupbyColumn,
|
|
40
|
+
columnGroupbyColumn,
|
|
41
|
+
summaryColumn,
|
|
42
|
+
chartTableColumns
|
|
43
|
+
} = data;
|
|
44
|
+
const {
|
|
45
|
+
type,
|
|
46
|
+
summary_columns,
|
|
47
|
+
summary_method
|
|
48
|
+
} = chart.config;
|
|
49
|
+
const baseProps = {
|
|
50
|
+
chart,
|
|
51
|
+
result,
|
|
52
|
+
tables,
|
|
53
|
+
groupbyColumn,
|
|
54
|
+
columnGroupbyColumn,
|
|
55
|
+
summaryColumn,
|
|
56
|
+
theme: CHART_THEME_COLOR['light'],
|
|
57
|
+
toggleRecords: toggleStatisticRecordsDialog
|
|
58
|
+
};
|
|
59
|
+
switch (type) {
|
|
60
|
+
case CHART_TYPE.TABLE:
|
|
61
|
+
{
|
|
62
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: "chart-table-wrapper",
|
|
64
|
+
onClick: onTableClick
|
|
65
|
+
}, result && /*#__PURE__*/React.createElement(Table, Object.assign({}, baseProps, {
|
|
66
|
+
summaryColumns: summary_columns,
|
|
67
|
+
summaryMethod: summary_method,
|
|
68
|
+
chartTableColumns: chartTableColumns
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
case CHART_TYPE.COMBINATION:
|
|
72
|
+
{
|
|
73
|
+
return /*#__PURE__*/React.createElement(Combination, Object.assign({}, baseProps, {
|
|
74
|
+
canvasStyle: canvasStyle
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
case CHART_TYPE.BAR:
|
|
78
|
+
{
|
|
79
|
+
return /*#__PURE__*/React.createElement(Bar, Object.assign({}, baseProps, {
|
|
80
|
+
canvasStyle: canvasStyle
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
case CHART_TYPE.BAR_GROUP:
|
|
84
|
+
{
|
|
85
|
+
const {
|
|
86
|
+
config
|
|
87
|
+
} = chart;
|
|
88
|
+
const {
|
|
89
|
+
column_groupby_column_key,
|
|
90
|
+
column_groupby_multiple_numeric_column
|
|
91
|
+
} = config;
|
|
92
|
+
const BarGroupComponent = column_groupby_column_key || column_groupby_multiple_numeric_column ? BarGroup : Bar;
|
|
93
|
+
return /*#__PURE__*/React.createElement(BarGroupComponent, Object.assign({}, baseProps, {
|
|
94
|
+
canvasStyle: canvasStyle
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
case CHART_TYPE.HORIZONTAL_BAR:
|
|
98
|
+
{
|
|
99
|
+
const {
|
|
100
|
+
config,
|
|
101
|
+
id,
|
|
102
|
+
style_config
|
|
103
|
+
} = chart;
|
|
104
|
+
const newConfig = ChartUtils.convertConfig(config);
|
|
105
|
+
const newChart = {
|
|
106
|
+
id,
|
|
107
|
+
config: newConfig,
|
|
108
|
+
style_config
|
|
109
|
+
};
|
|
110
|
+
return /*#__PURE__*/React.createElement(HorizontalBar, Object.assign({}, baseProps, {
|
|
111
|
+
canvasStyle: canvasStyle,
|
|
112
|
+
chart: newChart
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
case CHART_TYPE.HORIZONTAL_GROUP_BAR:
|
|
116
|
+
{
|
|
117
|
+
const {
|
|
118
|
+
config,
|
|
119
|
+
id,
|
|
120
|
+
style_config
|
|
121
|
+
} = chart;
|
|
122
|
+
const newConfig = ChartUtils.convertConfig(config);
|
|
123
|
+
const newChart = {
|
|
124
|
+
id,
|
|
125
|
+
config: newConfig,
|
|
126
|
+
style_config
|
|
127
|
+
};
|
|
128
|
+
const {
|
|
129
|
+
column_groupby_column_key,
|
|
130
|
+
column_groupby_multiple_numeric_column
|
|
131
|
+
} = config;
|
|
132
|
+
const HorizontalComponent = column_groupby_column_key || column_groupby_multiple_numeric_column ? HorizontalBarGroup : HorizontalBar;
|
|
133
|
+
return /*#__PURE__*/React.createElement(HorizontalComponent, Object.assign({}, baseProps, {
|
|
134
|
+
canvasStyle: canvasStyle,
|
|
135
|
+
chart: newChart
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
case CHART_TYPE.LINE_GROUP:
|
|
139
|
+
{
|
|
140
|
+
const {
|
|
141
|
+
config
|
|
142
|
+
} = chart;
|
|
143
|
+
const {
|
|
144
|
+
column_groupby_column_key,
|
|
145
|
+
column_groupby_multiple_numeric_column
|
|
146
|
+
} = config;
|
|
147
|
+
const LineGroupComponent = column_groupby_column_key || column_groupby_multiple_numeric_column ? LineGroup : Line;
|
|
148
|
+
return /*#__PURE__*/React.createElement(LineGroupComponent, Object.assign({}, baseProps, {
|
|
149
|
+
canvasStyle: canvasStyle
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
case CHART_TYPE.LINE:
|
|
153
|
+
{
|
|
154
|
+
return /*#__PURE__*/React.createElement(Line, Object.assign({}, baseProps, {
|
|
155
|
+
canvasStyle: canvasStyle
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
case CHART_TYPE.BASIC_NUMBER_CARD:
|
|
159
|
+
{
|
|
160
|
+
return /*#__PURE__*/React.createElement(BasicNumericCard, Object.assign({}, baseProps, {
|
|
161
|
+
canvasStyle: canvasStyle
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
case CHART_TYPE.AREA:
|
|
165
|
+
{
|
|
166
|
+
return /*#__PURE__*/React.createElement(Area, Object.assign({}, baseProps, {
|
|
167
|
+
canvasStyle: canvasStyle
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
case CHART_TYPE.PIE:
|
|
171
|
+
{
|
|
172
|
+
return /*#__PURE__*/React.createElement(Pie, Object.assign({}, baseProps, {
|
|
173
|
+
canvasStyle: canvasStyle
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
case CHART_TYPE.RING:
|
|
177
|
+
{
|
|
178
|
+
return /*#__PURE__*/React.createElement(Ring, Object.assign({}, baseProps, {
|
|
179
|
+
canvasStyle: canvasStyle
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
case CHART_TYPE.TREE_MAP:
|
|
183
|
+
{
|
|
184
|
+
return /*#__PURE__*/React.createElement(Treemap, Object.assign({}, baseProps, {
|
|
185
|
+
canvasStyle: canvasStyle
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
case CHART_TYPE.DASHBOARD:
|
|
189
|
+
{
|
|
190
|
+
return /*#__PURE__*/React.createElement(Dashboard, Object.assign({}, baseProps, {
|
|
191
|
+
canvasStyle: canvasStyle
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
default:
|
|
195
|
+
{
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
export default Wrapper;
|