sea-chart 0.0.1

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.
Files changed (214) hide show
  1. package/README.md +4 -0
  2. package/lib/assets/icons/area-chart.svg +10 -0
  3. package/lib/assets/icons/bar-chart.svg +12 -0
  4. package/lib/assets/icons/card.svg +22 -0
  5. package/lib/assets/icons/combination-chart.svg +17 -0
  6. package/lib/assets/icons/dtable-logo.svg +16 -0
  7. package/lib/assets/icons/facet-chart.svg +12 -0
  8. package/lib/assets/icons/gauge.svg +18 -0
  9. package/lib/assets/icons/heat-map.svg +14 -0
  10. package/lib/assets/icons/histogram.svg +12 -0
  11. package/lib/assets/icons/line-chart.svg +12 -0
  12. package/lib/assets/icons/map.svg +20 -0
  13. package/lib/assets/icons/pie-chart.svg +11 -0
  14. package/lib/assets/icons/rectangular-tree-diagram.svg +10 -0
  15. package/lib/assets/icons/scatter-chart.svg +15 -0
  16. package/lib/assets/icons/type-change.svg +17 -0
  17. package/lib/assets/img/area-chart.png +0 -0
  18. package/lib/assets/img/area-group-chart.png +0 -0
  19. package/lib/assets/img/bar-group.png +0 -0
  20. package/lib/assets/img/bar-stack.png +0 -0
  21. package/lib/assets/img/bar.png +0 -0
  22. package/lib/assets/img/combination-chart.png +0 -0
  23. package/lib/assets/img/compared-chart.png +0 -0
  24. package/lib/assets/img/completeness-chart.png +0 -0
  25. package/lib/assets/img/custom-bar.png +0 -0
  26. package/lib/assets/img/dashboard-chart.png +0 -0
  27. package/lib/assets/img/group-completeness-chart.png +0 -0
  28. package/lib/assets/img/group_line.png +0 -0
  29. package/lib/assets/img/heat-map.png +0 -0
  30. package/lib/assets/img/horizontal-bar.png +0 -0
  31. package/lib/assets/img/horizontal-group-bar.png +0 -0
  32. package/lib/assets/img/line.png +0 -0
  33. package/lib/assets/img/map-bubble.png +0 -0
  34. package/lib/assets/img/map.png +0 -0
  35. package/lib/assets/img/mirror.png +0 -0
  36. package/lib/assets/img/number-card.png +0 -0
  37. package/lib/assets/img/pie.png +0 -0
  38. package/lib/assets/img/pivot-table.png +0 -0
  39. package/lib/assets/img/ring.png +0 -0
  40. package/lib/assets/img/scatter.png +0 -0
  41. package/lib/assets/img/stacked-horizontal-bar.png +0 -0
  42. package/lib/assets/img/treemap.png +0 -0
  43. package/lib/assets/img/trend-chart.png +0 -0
  44. package/lib/assets/img/world-map-bubble.png +0 -0
  45. package/lib/assets/img/world-map.png +0 -0
  46. package/lib/components/collaborator/index.js +24 -0
  47. package/lib/components/formatter/area.js +162 -0
  48. package/lib/components/formatter/bar-group.js +160 -0
  49. package/lib/components/formatter/bar.js +150 -0
  50. package/lib/components/formatter/basic-number-card.js +138 -0
  51. package/lib/components/formatter/chart-component.js +266 -0
  52. package/lib/components/formatter/combination.js +407 -0
  53. package/lib/components/formatter/dashboard.js +182 -0
  54. package/lib/components/formatter/horizontal-bar-group.js +161 -0
  55. package/lib/components/formatter/horizontal-bar.js +152 -0
  56. package/lib/components/formatter/horizontal-component.js +91 -0
  57. package/lib/components/formatter/index.js +181 -0
  58. package/lib/components/formatter/line-group.js +157 -0
  59. package/lib/components/formatter/line.js +170 -0
  60. package/lib/components/formatter/pie.js +201 -0
  61. package/lib/components/formatter/ring.js +277 -0
  62. package/lib/components/formatter/table/index.css +103 -0
  63. package/lib/components/formatter/table/index.js +42 -0
  64. package/lib/components/formatter/table/one-dimension-table-no-numeric-columns.js +145 -0
  65. package/lib/components/formatter/table/one-dimension-table-with-numeric-columns.js +193 -0
  66. package/lib/components/formatter/table/pivot-table-display-name.js +249 -0
  67. package/lib/components/formatter/table/two-dimension-table.js +241 -0
  68. package/lib/components/formatter/treemap.js +213 -0
  69. package/lib/components/icon/index.css +5 -0
  70. package/lib/components/icon/index.js +22 -0
  71. package/lib/components/index.js +5 -0
  72. package/lib/components/loading/index.css +54 -0
  73. package/lib/components/loading/index.js +10 -0
  74. package/lib/components/number-input/index.js +31 -0
  75. package/lib/components/pixel-editor/index.css +29 -0
  76. package/lib/components/pixel-editor/index.js +42 -0
  77. package/lib/components/select-group/index.css +67 -0
  78. package/lib/components/select-group/index.js +63 -0
  79. package/lib/components/settings/advance-bar-settings/data-settings.js +120 -0
  80. package/lib/components/settings/advance-bar-settings/index.js +3 -0
  81. package/lib/components/settings/advance-bar-settings/style-settings.js +149 -0
  82. package/lib/components/settings/bar-settings/data-settings.js +137 -0
  83. package/lib/components/settings/bar-settings/index.js +3 -0
  84. package/lib/components/settings/bar-settings/style-settings.js +163 -0
  85. package/lib/components/settings/basic-number-card/data-settings.js +121 -0
  86. package/lib/components/settings/basic-number-card/index.js +3 -0
  87. package/lib/components/settings/basic-number-card/style-settings.js +42 -0
  88. package/lib/components/settings/combination-settings/data-settings.js +256 -0
  89. package/lib/components/settings/combination-settings/index.js +3 -0
  90. package/lib/components/settings/combination-settings/style-settings.js +183 -0
  91. package/lib/components/settings/dashboard-settings/data-settings.js +167 -0
  92. package/lib/components/settings/dashboard-settings/index.js +2 -0
  93. package/lib/components/settings/data-settings.js +67 -0
  94. package/lib/components/settings/horizontal-bar-settings/data-settings.js +45 -0
  95. package/lib/components/settings/horizontal-bar-settings/index.js +3 -0
  96. package/lib/components/settings/horizontal-bar-settings/style-settings.js +38 -0
  97. package/lib/components/settings/index.css +73 -0
  98. package/lib/components/settings/index.js +74 -0
  99. package/lib/components/settings/pie-settings/data-settings.js +123 -0
  100. package/lib/components/settings/pie-settings/index.js +3 -0
  101. package/lib/components/settings/pie-settings/style-settings.js +123 -0
  102. package/lib/components/settings/style-settings.js +100 -0
  103. package/lib/components/settings/table-settings/data-settings.js +488 -0
  104. package/lib/components/settings/table-settings/index.js +2 -0
  105. package/lib/components/settings/time-comparison-settings/data-settings.js +157 -0
  106. package/lib/components/settings/time-comparison-settings/index.js +3 -0
  107. package/lib/components/settings/time-comparison-settings/style-settings.js +191 -0
  108. package/lib/components/settings/widgets/basic-summary/index.css +12 -0
  109. package/lib/components/settings/widgets/basic-summary/index.js +173 -0
  110. package/lib/components/settings/widgets/common-data-settings.js +42 -0
  111. package/lib/components/settings/widgets/data-filter/index.css +17 -0
  112. package/lib/components/settings/widgets/data-filter/index.js +76 -0
  113. package/lib/components/settings/widgets/data-sort.js +38 -0
  114. package/lib/components/settings/widgets/date-summary-item.js +126 -0
  115. package/lib/components/settings/widgets/display-values-settings/index.css +13 -0
  116. package/lib/components/settings/widgets/display-values-settings/index.js +37 -0
  117. package/lib/components/settings/widgets/divider/index.css +4 -0
  118. package/lib/components/settings/widgets/divider/index.js +10 -0
  119. package/lib/components/settings/widgets/font-settings/font-size-settings.js +31 -0
  120. package/lib/components/settings/widgets/font-settings/font-weight-settings.js +46 -0
  121. package/lib/components/settings/widgets/font-settings/index.js +3 -0
  122. package/lib/components/settings/widgets/group-by.js +168 -0
  123. package/lib/components/settings/widgets/label-color.js +30 -0
  124. package/lib/components/settings/widgets/min-max-setting.js +64 -0
  125. package/lib/components/settings/widgets/mininum-slice-percent.js +72 -0
  126. package/lib/components/settings/widgets/numeric-summary-item.js +109 -0
  127. package/lib/components/settings/widgets/select-table/index.css +0 -0
  128. package/lib/components/settings/widgets/select-table/index.js +49 -0
  129. package/lib/components/settings/widgets/stack.js +58 -0
  130. package/lib/components/settings/widgets/statistic-type/index.css +31 -0
  131. package/lib/components/settings/widgets/statistic-type/index.js +54 -0
  132. package/lib/components/settings/widgets/summary-method-setting.js +80 -0
  133. package/lib/components/settings/widgets/summary-settings.js +394 -0
  134. package/lib/components/settings/widgets/switch/index.css +37 -0
  135. package/lib/components/settings/widgets/switch/index.js +21 -0
  136. package/lib/components/settings/widgets/text-horizontal-settings.js +23 -0
  137. package/lib/components/settings/widgets/time-picker.js +182 -0
  138. package/lib/components/settings/widgets/title-settings/index.js +58 -0
  139. package/lib/components/settings/widgets/title-settings/title-text.js +31 -0
  140. package/lib/components/settings/widgets/x-axios.js +0 -0
  141. package/lib/components/settings/widgets/y-axis-group-settings.js +399 -0
  142. package/lib/components/types-dialog/index.css +97 -0
  143. package/lib/components/types-dialog/index.js +127 -0
  144. package/lib/constants/geolocation.js +11 -0
  145. package/lib/constants/index.js +164 -0
  146. package/lib/constants/model.js +167 -0
  147. package/lib/constants/style.js +13 -0
  148. package/lib/constants/type-image.js +32 -0
  149. package/lib/constants/type.js +97 -0
  150. package/lib/context.js +49 -0
  151. package/lib/index.js +6 -0
  152. package/lib/intl.js +37 -0
  153. package/lib/layout/index.js +4 -0
  154. package/lib/layout/statistic/index.css +53 -0
  155. package/lib/layout/statistic/index.js +190 -0
  156. package/lib/layout/title/index.css +3 -0
  157. package/lib/layout/title/index.js +41 -0
  158. package/lib/locale/index.js +11 -0
  159. package/lib/locale/lang/de.js +141 -0
  160. package/lib/locale/lang/en.js +143 -0
  161. package/lib/locale/lang/es.js +141 -0
  162. package/lib/locale/lang/fr.js +141 -0
  163. package/lib/locale/lang/pt.js +141 -0
  164. package/lib/locale/lang/ru.js +141 -0
  165. package/lib/locale/lang/zh_CN.js +143 -0
  166. package/lib/model/area-group.js +51 -0
  167. package/lib/model/area.js +42 -0
  168. package/lib/model/bar-group.js +54 -0
  169. package/lib/model/bar-stack.js +51 -0
  170. package/lib/model/bar.js +48 -0
  171. package/lib/model/base-model.js +11 -0
  172. package/lib/model/basic-number-card.js +32 -0
  173. package/lib/model/combination.js +48 -0
  174. package/lib/model/compare-bar.js +49 -0
  175. package/lib/model/completeness-group.js +34 -0
  176. package/lib/model/completeness.js +28 -0
  177. package/lib/model/dashboard.js +26 -0
  178. package/lib/model/generic-model.js +235 -0
  179. package/lib/model/heat-map.js +33 -0
  180. package/lib/model/horizontal-bar.js +48 -0
  181. package/lib/model/horizontal-group-bar.js +53 -0
  182. package/lib/model/index.js +36 -0
  183. package/lib/model/line-group.js +54 -0
  184. package/lib/model/line.js +48 -0
  185. package/lib/model/map-bubble.js +37 -0
  186. package/lib/model/map.js +37 -0
  187. package/lib/model/mirror.js +36 -0
  188. package/lib/model/pie.js +36 -0
  189. package/lib/model/ring.js +36 -0
  190. package/lib/model/scatter.js +29 -0
  191. package/lib/model/stacked-horizontal-bar.js +42 -0
  192. package/lib/model/statistic.js +22 -0
  193. package/lib/model/table.js +33 -0
  194. package/lib/model/tree-map.js +30 -0
  195. package/lib/model/trend.js +34 -0
  196. package/lib/model/user.js +22 -0
  197. package/lib/model/world-map-bubble.js +36 -0
  198. package/lib/model/world-map.js +36 -0
  199. package/lib/utils/cell-format-utils.js +41 -0
  200. package/lib/utils/chart.js +6 -0
  201. package/lib/utils/collaborator-utils.js +40 -0
  202. package/lib/utils/column-utils.js +247 -0
  203. package/lib/utils/custom-g2.js +612 -0
  204. package/lib/utils/data-filter/filter-item-utils.js +80 -0
  205. package/lib/utils/data-filter/filters-utils.js +406 -0
  206. package/lib/utils/data-filter/index.js +3 -0
  207. package/lib/utils/date-translate.js +66 -0
  208. package/lib/utils/index.js +50 -0
  209. package/lib/utils/key-generator.js +13 -0
  210. package/lib/utils/object-utils.js +61 -0
  211. package/lib/utils/options-utils.js +61 -0
  212. package/lib/utils/statistic-column-2-sql-column-utils.js +499 -0
  213. package/lib/utils/statistic-utils.js +1685 -0
  214. package/package.json +160 -0
@@ -0,0 +1,182 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Component } from 'react';
6
+ import { isNumber } from 'dtable-utils';
7
+ import { Chart, registerShape } from '../../utils/custom-g2';
8
+ import { StatisticsUtils } from '../../utils';
9
+ var Dashboard = /*#__PURE__*/function (_Component) {
10
+ _inherits(Dashboard, _Component);
11
+ var _super = _createSuper(Dashboard);
12
+ function Dashboard() {
13
+ var _this;
14
+ _classCallCheck(this, Dashboard);
15
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
+ args[_key] = arguments[_key];
17
+ }
18
+ _this = _super.call.apply(_super, [this].concat(args));
19
+ _this.componentDidMount = function () {
20
+ _this.drawChart();
21
+ };
22
+ _this.drawChart = function () {
23
+ var _this$props = _this.props,
24
+ statistic = _this$props.statistic,
25
+ theme = _this$props.theme,
26
+ canvasStyle = _this$props.canvasStyle,
27
+ result = _this$props.result;
28
+ var value = isNumber(result) ? result : 0;
29
+ var config = statistic.config;
30
+ _this.chart = new Chart({
31
+ container: _this.container,
32
+ autoFit: true,
33
+ width: '100%',
34
+ height: '100%'
35
+ });
36
+ registerShape('point', 'pointer', {
37
+ draw: function draw(cfg, container) {
38
+ var group = container.addGroup();
39
+ var center = this.parsePoint({
40
+ x: 0,
41
+ y: 0
42
+ });
43
+ group.addShape('line', {
44
+ attrs: {
45
+ x1: center.x,
46
+ y1: center.y - 15,
47
+ x2: cfg.x,
48
+ y2: cfg.y - 15,
49
+ stroke: cfg.color,
50
+ lineWidth: 5,
51
+ lineCap: 'round'
52
+ }
53
+ });
54
+ group.addShape('circle', {
55
+ attrs: {
56
+ x: center.x,
57
+ y: center.y - 15,
58
+ r: 9.75,
59
+ stroke: cfg.color,
60
+ lineWidth: 4.5,
61
+ fill: '#fff'
62
+ }
63
+ });
64
+ return group;
65
+ }
66
+ });
67
+ var number = value > 1 ? 10 : value * 10;
68
+ var data = [{
69
+ value: number
70
+ }];
71
+ _this.chart.data(data);
72
+ _this.chart.scale('value', {
73
+ min: 0,
74
+ max: 10,
75
+ tickInterval: 1
76
+ });
77
+ _this.chart.coordinate('polar', {
78
+ startAngle: -9 / 8 * Math.PI,
79
+ endAngle: 1 / 8 * Math.PI,
80
+ radius: 0.75
81
+ });
82
+ _this.chart.axis('1', false);
83
+ _this.chart.axis('value', {
84
+ line: null,
85
+ label: {
86
+ offset: -36,
87
+ style: {
88
+ fontSize: 12,
89
+ textAlign: 'center',
90
+ textBaseline: 'middle'
91
+ }
92
+ },
93
+ subTickLine: {
94
+ count: 4,
95
+ length: -15
96
+ },
97
+ tickLine: {
98
+ length: -24
99
+ },
100
+ grid: null,
101
+ offsetY: -15
102
+ });
103
+ _this.chart.legend(false);
104
+ _this.chart.point().position('value*1').shape('pointer').color('#1890FF').animate({
105
+ appear: {
106
+ animation: 'fade-in'
107
+ }
108
+ });
109
+ _this.chart.annotation().arc({
110
+ top: false,
111
+ start: [0, 1],
112
+ end: [10, 1],
113
+ style: {
114
+ stroke: '#CBCBCB',
115
+ lineWidth: 10,
116
+ lineDash: null
117
+ },
118
+ offsetY: -15
119
+ });
120
+ _this.chart.annotation().arc({
121
+ start: [0, 1],
122
+ end: [data[0].value, 1],
123
+ style: {
124
+ stroke: '#1890FF',
125
+ lineWidth: 10,
126
+ lineDash: null
127
+ },
128
+ offsetY: -15
129
+ });
130
+ _this.chart.annotation().text({
131
+ position: ['50%', '85%'],
132
+ content: config.name,
133
+ style: {
134
+ fontSize: canvasStyle.height > 240 ? 20 : 12,
135
+ fill: '#545454',
136
+ textAlign: 'center'
137
+ },
138
+ offsetY: -10
139
+ });
140
+ var shownValue = value * 100;
141
+ var shownDotPos = "".concat(shownValue).indexOf('.');
142
+ if (shownDotPos > -1 && shownDotPos < "".concat(shownValue).length - 2) {
143
+ shownValue = shownValue.toFixed(1);
144
+ }
145
+ _this.chart.annotation().text({
146
+ position: ['50%', '90%'],
147
+ content: "".concat(shownValue, " %"),
148
+ style: {
149
+ fontSize: canvasStyle.height > 240 ? 36 : 16,
150
+ fill: theme.textColor,
151
+ textAlign: 'center'
152
+ },
153
+ offsetY: 0
154
+ });
155
+ _this.chart.render();
156
+ _this.container.title = "".concat(data[0].value * 10, " %");
157
+ };
158
+ return _this;
159
+ }
160
+ _createClass(Dashboard, [{
161
+ key: "componentDidUpdate",
162
+ value: function componentDidUpdate(prevProps) {
163
+ if (StatisticsUtils.shouldChartComponentUpdate(prevProps, this.props)) {
164
+ this.chart && this.chart.destroy();
165
+ this.drawChart();
166
+ }
167
+ }
168
+ }, {
169
+ key: "render",
170
+ value: function render() {
171
+ var _this2 = this;
172
+ return /*#__PURE__*/React.createElement("div", {
173
+ ref: function ref(_ref) {
174
+ return _this2.container = _ref;
175
+ },
176
+ className: "seastatistic-container w-100"
177
+ });
178
+ }
179
+ }]);
180
+ return Dashboard;
181
+ }(Component);
182
+ export default Dashboard;
@@ -0,0 +1,161 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import classnames from 'classnames';
8
+ import { EMPTY_NAME } from '../../constants';
9
+ import { StatisticsUtils } from '../../utils';
10
+ import HorizontalComponent from './horizontal-component';
11
+ import intl from '../../intl';
12
+ var HorizontalBarGroup = /*#__PURE__*/function (_HorizontalComponent) {
13
+ _inherits(HorizontalBarGroup, _HorizontalComponent);
14
+ var _super = _createSuper(HorizontalBarGroup);
15
+ function HorizontalBarGroup(props) {
16
+ var _this;
17
+ _classCallCheck(this, HorizontalBarGroup);
18
+ _this = _super.call(this, props);
19
+ _this.createChart = function () {
20
+ var statistic = _this.props.statistic;
21
+ var display_data = statistic.config.display_data;
22
+ var appendPadding = [0, display_data ? 17 : 0, 0, 0];
23
+ _this.initChart(_this.container, {
24
+ appendPadding: appendPadding
25
+ });
26
+ _this.chart.on('interval:click', function (e) {
27
+ _this.props.toggleRecords(e.data.data);
28
+ });
29
+ };
30
+ _this.clearChart = function () {
31
+ _this.chart.annotation().clear(true);
32
+ _this.chart.clear(true);
33
+ };
34
+ _this.drawChart = function () {
35
+ var data = _this.props.result;
36
+ data = StatisticsUtils.formatEmptyName(data, '', intl.get('Empty'));
37
+ if (!Array.isArray(data)) return;
38
+ _this.chart.scale(_this.groupName, {
39
+ type: 'cat'
40
+ });
41
+ _this.loadData(data);
42
+ _this.draw(data);
43
+ _this.chart.render();
44
+ };
45
+ _this.draw = function (data) {
46
+ var _this$props = _this.props,
47
+ statistic = _this$props.statistic,
48
+ summaryColumn = _this$props.summaryColumn,
49
+ theme = _this$props.theme;
50
+ var _statistic$config = statistic.config,
51
+ horizontal_axis_summary_method = _statistic$config.horizontal_axis_summary_method,
52
+ display_data = _statistic$config.display_data,
53
+ label_font_size = _statistic$config.label_font_size;
54
+ var chartBarColor = _this.groupName;
55
+ var newData = _this.getChartGroupData(data);
56
+ _this.drawLabels(newData);
57
+
58
+ // set Coord type
59
+ _this.chart.coordinate('rect');
60
+ _this.autoAdjustDataOptions(statistic, data, summaryColumn);
61
+ _this.chart.interval().label(display_data ? 'value' : false, {
62
+ formatter: function formatter(value) {
63
+ return value;
64
+ },
65
+ style: {
66
+ fontSize: StatisticsUtils.getLabelFontSize(label_font_size),
67
+ fill: theme.textColor
68
+ }
69
+ }).position('name*value').color(chartBarColor).tooltip('name*value*group_name*raw_name', function (name, value, group_name, raw_name) {
70
+ return {
71
+ title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
72
+ value: StatisticsUtils.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
+ return _this;
109
+ }
110
+ _createClass(HorizontalBarGroup, [{
111
+ key: "componentDidMount",
112
+ value: function componentDidMount() {
113
+ this.createChart();
114
+ this.drawChart();
115
+ this.renderHorizontalLabel(this.props.statistic, this.props.tables);
116
+ }
117
+ }, {
118
+ key: "componentDidUpdate",
119
+ value: function componentDidUpdate(prevProps) {
120
+ if (StatisticsUtils.shouldChartComponentUpdate(prevProps, this.props)) {
121
+ this.chart && this.chart.destroy();
122
+ this.createChart();
123
+ this.drawChart();
124
+ this.renderHorizontalLabel(prevProps.statistic, prevProps.tables);
125
+ }
126
+ }
127
+ }, {
128
+ key: "componentWillUnmount",
129
+ value: function componentWillUnmount() {
130
+ this.chart && this.chart.destroy();
131
+ }
132
+ }, {
133
+ key: "render",
134
+ value: function render() {
135
+ var _this2 = this;
136
+ var statistic = this.props.statistic;
137
+ return /*#__PURE__*/React.createElement("div", {
138
+ className: classnames('seastatistic-container w-100', {
139
+ 'show-vertical-axis-label': this.isShowVerticalAxisLabel(statistic),
140
+ 'show-horizontal-axis-label': this.isShowHorizontalAxisLabel(statistic)
141
+ }),
142
+ ref: function ref(_ref) {
143
+ return _this2.container = _ref;
144
+ }
145
+ });
146
+ }
147
+ }]);
148
+ return HorizontalBarGroup;
149
+ }(HorizontalComponent);
150
+ HorizontalBarGroup.propTypes = {
151
+ canvasStyle: PropTypes.object,
152
+ statistic: PropTypes.object,
153
+ groupbyColumn: PropTypes.object,
154
+ columnGroupbyColumn: PropTypes.object,
155
+ summaryColumn: PropTypes.object,
156
+ result: PropTypes.array,
157
+ tables: PropTypes.array,
158
+ theme: PropTypes.object,
159
+ toggleRecords: PropTypes.func
160
+ };
161
+ export default HorizontalBarGroup;
@@ -0,0 +1,152 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import classnames from 'classnames';
8
+ import { STATISTIC_SUMMARY_TYPE, STATISTIC_SUMMARY_SHOW } from '../../constants';
9
+ import { StatisticsUtils } from '../../utils';
10
+ import HorizontalComponent from './horizontal-component';
11
+ import intl from '../../intl';
12
+ var HorizontalBar = /*#__PURE__*/function (_HorizontalComponent) {
13
+ _inherits(HorizontalBar, _HorizontalComponent);
14
+ var _super = _createSuper(HorizontalBar);
15
+ function HorizontalBar(props) {
16
+ var _this;
17
+ _classCallCheck(this, HorizontalBar);
18
+ _this = _super.call(this, props);
19
+ _this.createChart = function () {
20
+ var statistic = _this.props.statistic;
21
+ var display_data = statistic.config.display_data;
22
+ var appendPadding = [0, display_data ? 17 : 0, 0, 0]; // used to display value on the right
23
+ _this.initChart(_this.container, {
24
+ appendPadding: appendPadding
25
+ });
26
+ _this.chart.on('interval:click', function (e) {
27
+ _this.props.toggleRecords(e.data.data);
28
+ });
29
+ };
30
+ _this.clearChart = function () {
31
+ _this.chart.annotation().clear(true);
32
+ _this.chart.clear(true);
33
+ };
34
+ _this.drawChart = function () {
35
+ var data = _this.props.result;
36
+ data = StatisticsUtils.formatEmptyName(data, '', intl.get('Empty'));
37
+ if (!Array.isArray(data)) return;
38
+ _this.loadData(data);
39
+ _this.draw(data);
40
+ _this.chart.render();
41
+ _this.renderHorizontalLabel(_this.props.statistic, _this.props.tables);
42
+ };
43
+ _this.draw = function (data) {
44
+ var _this$props = _this.props,
45
+ statistic = _this$props.statistic,
46
+ summaryColumn = _this$props.summaryColumn,
47
+ theme = _this$props.theme;
48
+ var _statistic$config = statistic.config,
49
+ horizontal_axis_summary_type = _statistic$config.horizontal_axis_summary_type,
50
+ horizontal_axis_summary_method = _statistic$config.horizontal_axis_summary_method,
51
+ horizontal_axis_label_color = _statistic$config.horizontal_axis_label_color,
52
+ display_data = _statistic$config.display_data,
53
+ label_font_size = _statistic$config.label_font_size;
54
+ var 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(statistic, data, summaryColumn);
61
+ _this.chart.interval().label(display_data ? 'value' : false, {
62
+ style: {
63
+ fontSize: StatisticsUtils.getLabelFontSize(label_font_size),
64
+ fill: theme.textColor
65
+ }
66
+ }).position('name*value').color(chartBarColor).tooltip('name*value', function (name, value) {
67
+ return {
68
+ title: horizontal_axis_summary_type === STATISTIC_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(STATISTIC_SUMMARY_SHOW[horizontal_axis_summary_method]),
69
+ value: StatisticsUtils.getSummaryValueDisplayString(summaryColumn, value, horizontal_axis_summary_method),
70
+ name: 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
+ return _this;
102
+ }
103
+ _createClass(HorizontalBar, [{
104
+ key: "componentDidMount",
105
+ value: function componentDidMount() {
106
+ this.createChart();
107
+ this.drawChart();
108
+ }
109
+ }, {
110
+ key: "componentDidUpdate",
111
+ value: function componentDidUpdate(prevProps) {
112
+ if (StatisticsUtils.shouldChartComponentUpdate(prevProps, this.props)) {
113
+ this.chart && this.chart.destroy();
114
+ this.createChart();
115
+ this.drawChart();
116
+ }
117
+ }
118
+ }, {
119
+ key: "componentWillUnmount",
120
+ value: function componentWillUnmount() {
121
+ this.chart && this.chart.destroy();
122
+ }
123
+ }, {
124
+ key: "render",
125
+ value: function render() {
126
+ var _this2 = this;
127
+ var statistic = this.props.statistic;
128
+ return /*#__PURE__*/React.createElement("div", {
129
+ className: classnames('seastatistic-container w-100', {
130
+ 'show-vertical-axis-label': this.isShowVerticalAxisLabel(statistic),
131
+ 'show-horizontal-axis-label': this.isShowHorizontalAxisLabel(statistic)
132
+ }),
133
+ ref: function ref(_ref) {
134
+ return _this2.container = _ref;
135
+ }
136
+ });
137
+ }
138
+ }]);
139
+ return HorizontalBar;
140
+ }(HorizontalComponent);
141
+ HorizontalBar.propTypes = {
142
+ canvasStyle: PropTypes.object,
143
+ statistic: PropTypes.object,
144
+ groupbyColumn: PropTypes.object,
145
+ columnGroupbyColumn: PropTypes.object,
146
+ summaryColumn: PropTypes.object,
147
+ result: PropTypes.array,
148
+ tables: PropTypes.array,
149
+ theme: PropTypes.object,
150
+ toggleRecords: PropTypes.func
151
+ };
152
+ export default HorizontalBar;
@@ -0,0 +1,91 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import { getTableById, getTableColumnByKey } from 'dtable-utils';
6
+ import ChartComponent from './chart-component';
7
+ import { STATISTIC_SUMMARY_TYPE, LABEL_POSITION_TYPE } from '../../constants';
8
+ import intl from '../../intl';
9
+ var HorizontalComponent = /*#__PURE__*/function (_ChartComponent) {
10
+ _inherits(HorizontalComponent, _ChartComponent);
11
+ var _super = _createSuper(HorizontalComponent);
12
+ function HorizontalComponent() {
13
+ var _this;
14
+ _classCallCheck(this, HorizontalComponent);
15
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
+ args[_key] = arguments[_key];
17
+ }
18
+ _this = _super.call.apply(_super, [this].concat(args));
19
+ _this.renderHorizontalLabel = function (statistic, tables) {
20
+ if (!_this.chart || !statistic) return;
21
+ var _statistic$config = statistic.config,
22
+ table_id = _statistic$config.table_id,
23
+ x_axis_column_key = _statistic$config.x_axis_column_key,
24
+ y_axis_summary_column_key = _statistic$config.y_axis_summary_column_key,
25
+ y_axis_label_position = _statistic$config.y_axis_label_position,
26
+ x_axis_label_position = _statistic$config.x_axis_label_position,
27
+ y_axis_summary_type = _statistic$config.y_axis_summary_type,
28
+ show_vertical_axis_label = _statistic$config.show_vertical_axis_label,
29
+ show_horizontal_axis_label = _statistic$config.show_horizontal_axis_label;
30
+ var table = getTableById(tables, table_id);
31
+ var autoPadding = _this.chart.autoPadding;
32
+ var textColor = '#999999';
33
+ var xAxisID = "chart-x-axis-label_".concat(statistic.id);
34
+ var chartContainer = _this.chart.getCanvas().get('container');
35
+ var xLabel = chartContainer.querySelector("#".concat(xAxisID));
36
+ if (!xLabel && show_horizontal_axis_label) {
37
+ var div = document.createElement('div');
38
+ div.id = xAxisID;
39
+ div.className = 'chart-axis-label';
40
+ if (y_axis_summary_type === STATISTIC_SUMMARY_TYPE.COUNT) {
41
+ div.innerHTML = intl.get('Amount');
42
+ } else {
43
+ var column = getTableColumnByKey(table, y_axis_summary_column_key);
44
+ div.innerHTML = "".concat(column ? column.name : '');
45
+ }
46
+ div.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
47
+ chartContainer.appendChild(div);
48
+ }
49
+ if (xLabel && show_horizontal_axis_label) {
50
+ xLabel.setAttribute('style', "color:".concat(textColor, "; width: 100%; text-align: ").concat(x_axis_label_position, "; bottom: -20px; position: absolute"));
51
+ }
52
+ if (xLabel && !show_horizontal_axis_label) {
53
+ xLabel.parentNode.removeChild(xLabel);
54
+ }
55
+ var yAxisID = "chart-y-axis-label_".concat(statistic.id);
56
+ var yLabel = chartContainer.querySelector("#".concat(yAxisID));
57
+ if (!yLabel && show_vertical_axis_label) {
58
+ var _div = document.createElement('div');
59
+ _div.id = yAxisID;
60
+ _div.className = 'chart-axis-label';
61
+ var _column = getTableColumnByKey(table, x_axis_column_key) || {};
62
+ _div.innerHTML = _column.name || '';
63
+ var containerHeight = chartContainer.offsetHeight;
64
+ var textAlign = 'center';
65
+ if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) textAlign = 'left';
66
+ if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) textAlign = 'right';
67
+ _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)"));
68
+ chartContainer.appendChild(_div);
69
+ }
70
+ if (yLabel && show_horizontal_axis_label) {
71
+ var _containerHeight = chartContainer.offsetHeight;
72
+ var _textAlign = 'center';
73
+ if (y_axis_label_position === LABEL_POSITION_TYPE.BOTTOM) _textAlign = 'left';
74
+ if (y_axis_label_position === LABEL_POSITION_TYPE.TOP) _textAlign = 'right';
75
+ 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)"));
76
+ }
77
+ if (yLabel && !show_horizontal_axis_label) {
78
+ yLabel.parentNode.removeChild(yLabel);
79
+ }
80
+ };
81
+ _this.isShowVerticalAxisLabel = function (statistic) {
82
+ return !!(statistic && statistic.config && statistic.config.show_vertical_axis_label);
83
+ };
84
+ _this.isShowHorizontalAxisLabel = function (statistic) {
85
+ return !!(statistic && statistic.config && statistic.config.show_horizontal_axis_label);
86
+ };
87
+ return _this;
88
+ }
89
+ return _createClass(HorizontalComponent);
90
+ }(ChartComponent);
91
+ export { HorizontalComponent as default };