dtable-statistic 4.4.24-alpha.9 → 5.0.0

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 (198) hide show
  1. package/es/assets/css/color-picker.css +53 -0
  2. package/es/assets/css/color-rules-popover.css +144 -0
  3. package/es/assets/css/dashboard.css +0 -1
  4. package/es/assets/css/dialog.css +0 -30
  5. package/es/assets/css/slider.css +77 -0
  6. package/es/assets/css/statistic-chart.module.css +11 -0
  7. package/es/assets/css/statistic-custom-title.module.css +3 -0
  8. package/es/assets/css/statistic-custom.module.css +4 -0
  9. package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
  10. package/es/assets/css/statistic-time-picker.module.css +21 -0
  11. package/es/calculator/base-calculator.js +80 -0
  12. package/es/calculator/basic-chart-calculator.js +349 -0
  13. package/es/calculator/combination-calculator.js +246 -0
  14. package/es/calculator/compare-bar-calculator.js +197 -0
  15. package/es/calculator/completeness-calculator.js +215 -0
  16. package/es/calculator/copy-value.js +53 -0
  17. package/es/calculator/dashboard-calculator.js +70 -0
  18. package/es/calculator/heat-map-calculator.js +148 -0
  19. package/es/calculator/horizontal-bar-calculator.js +67 -0
  20. package/es/calculator/index.js +81 -0
  21. package/es/calculator/map-calculator.js +103 -0
  22. package/es/calculator/mirror-calculator.js +146 -0
  23. package/es/calculator/number-card-calculator.js +60 -0
  24. package/es/calculator/pivot-table-calculator.js +821 -0
  25. package/es/calculator/scatter-calculator.js +75 -0
  26. package/es/calculator/thread-manager.js +57 -0
  27. package/es/calculator/trend-calculator.js +113 -0
  28. package/es/calculator/workers/basic-chart-calculator-worker.js +495 -0
  29. package/es/calculator/workers/calculator.worker.js +44 -0
  30. package/es/calculator/workers/card-calculator-worker.js +40 -0
  31. package/es/calculator/workers/combination-calculator-worker.js +276 -0
  32. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +150 -0
  33. package/es/calculator/workers/completeness-calculator-worker.js +208 -0
  34. package/es/calculator/workers/dashboard-calculator-worker.js +68 -0
  35. package/es/calculator/workers/mirror-calculator-worker.js +152 -0
  36. package/es/calculator/workers/pivot-table-calculator-worker.js +718 -0
  37. package/es/calculator/workers/scatter-calculator-worker.js +80 -0
  38. package/es/calculator/workers/trend-calculator-worker.js +108 -0
  39. package/es/calculator/world-map-calculator.js +124 -0
  40. package/es/components/dialog/chart-addition-edit-dialog.js +90 -0
  41. package/es/components/dialog/chart-addition-widgets/chart-selector.js +259 -0
  42. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +83 -0
  43. package/es/components/dialog/enlarged-chart-dialog.js +13 -8
  44. package/es/components/dialog/statistic-record-dialog/index.js +34 -25
  45. package/es/components/dialog/statistic-types-dialog/index.css +14 -0
  46. package/es/components/dialog/statistic-types-dialog/index.js +62 -0
  47. package/es/components/dropdown-menu/statistic-dropdown-menu.js +2 -2
  48. package/es/components/popover/color-rules/color-rule.js +183 -0
  49. package/es/components/popover/color-rules/index.js +87 -0
  50. package/es/components/popover/color-rules/rule-filters/filter.js +221 -0
  51. package/es/components/popover/color-rules/rule-filters/index.css +210 -0
  52. package/es/components/popover/color-rules/rule-filters/index.js +97 -0
  53. package/es/components/popover/color-rules/rule-filters/number-input.js +78 -0
  54. package/es/components/popover/color-rules-popover.js +218 -0
  55. package/es/components/popover/color-selector-popover.js +83 -0
  56. package/es/constants/index.js +2 -1
  57. package/es/custom-g2.js +644 -0
  58. package/es/dashboard.js +31 -9
  59. package/es/desktop-dashboard.js +32 -51
  60. package/es/mobile-dashboard.js +16 -8
  61. package/es/model/bar-group.js +58 -0
  62. package/es/model/bar.js +47 -0
  63. package/es/model/base-model.js +18 -0
  64. package/es/model/basic-number-card.js +25 -0
  65. package/es/model/combination.js +48 -0
  66. package/es/model/compare-bar.js +56 -0
  67. package/es/model/completeness-group.js +31 -0
  68. package/es/model/completeness.js +25 -0
  69. package/es/model/custom-bar.js +25 -0
  70. package/es/model/dashboard.js +20 -0
  71. package/es/model/generic-model.js +222 -0
  72. package/es/model/heat-map.js +33 -0
  73. package/es/model/horizontal-bar-group.js +55 -0
  74. package/es/model/horizontal-bar.js +47 -0
  75. package/es/model/index.js +187 -0
  76. package/es/model/map.js +38 -0
  77. package/es/model/mirror.js +33 -0
  78. package/es/model/pie.js +38 -0
  79. package/es/model/ring.js +40 -0
  80. package/es/model/scatter.js +22 -0
  81. package/es/model/table.js +32 -0
  82. package/es/model/trend.js +32 -0
  83. package/es/model/world-map.js +34 -0
  84. package/es/service/chart-service.js +15 -8
  85. package/es/service/dashboard-service.js +29 -25
  86. package/es/stat-editor/chart-name-editor.js +68 -0
  87. package/es/stat-editor/index.js +75 -0
  88. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +153 -0
  89. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +422 -0
  90. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +203 -0
  91. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +23 -0
  92. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +104 -0
  93. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +334 -0
  94. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +119 -0
  95. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +132 -0
  96. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +240 -0
  97. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
  98. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +138 -0
  99. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +331 -0
  100. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +143 -0
  101. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +109 -0
  102. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +153 -0
  103. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +144 -0
  104. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +214 -0
  105. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +121 -0
  106. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +172 -0
  107. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +366 -0
  108. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +142 -0
  109. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +150 -0
  110. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +473 -0
  111. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +182 -0
  112. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +564 -0
  113. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +112 -0
  114. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +87 -0
  115. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +187 -0
  116. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +300 -0
  117. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +113 -0
  118. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +289 -0
  119. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +58 -0
  120. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +359 -0
  121. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +48 -0
  122. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +121 -0
  123. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +143 -0
  124. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +269 -0
  125. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +104 -0
  126. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +366 -0
  127. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +55 -0
  128. package/es/stat-editor/stat-settings/color-setting/color-picker.js +130 -0
  129. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +374 -0
  130. package/es/stat-editor/stat-settings/map/map-level.js +72 -0
  131. package/es/stat-editor/stat-settings/map/map-province-city.js +151 -0
  132. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +108 -0
  133. package/es/stat-editor/stat-settings/public-setting/base-settings.js +154 -0
  134. package/es/stat-editor/stat-settings/public-setting/calender.js +125 -0
  135. package/es/stat-editor/stat-settings/public-setting/column-settings.js +24 -0
  136. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +62 -0
  137. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +61 -0
  138. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +35 -0
  139. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +60 -0
  140. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +123 -0
  141. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +33 -0
  142. package/es/stat-editor/stat-settings/public-setting/type-settings/index.css +29 -0
  143. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +82 -0
  144. package/es/stat-list/chart-preview.js +20 -19
  145. package/es/stat-list/index.js +21 -15
  146. package/es/stat-view/area-chart.js +551 -0
  147. package/es/stat-view/bar-chart.js +582 -0
  148. package/es/stat-view/base-chart.js +132 -0
  149. package/es/stat-view/basic-number-card.js +201 -0
  150. package/es/stat-view/combination-chart.js +546 -0
  151. package/es/stat-view/compare-chart.js +483 -0
  152. package/es/stat-view/completeness-chart.js +390 -0
  153. package/es/stat-view/custom-bar.js +418 -0
  154. package/es/stat-view/dashboard-chart.js +266 -0
  155. package/es/stat-view/heat-map.js +463 -0
  156. package/es/stat-view/horizontal-bar-chart.js +562 -0
  157. package/es/stat-view/index.js +156 -47
  158. package/es/stat-view/line-chart.js +518 -0
  159. package/es/stat-view/map.js +448 -0
  160. package/es/stat-view/mirror.js +275 -0
  161. package/es/stat-view/pie-chart.js +290 -0
  162. package/es/stat-view/pivot-table/index.js +196 -0
  163. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +156 -0
  164. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +176 -0
  165. package/es/stat-view/pivot-table/pivot-table-display-name.js +215 -0
  166. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
  167. package/es/stat-view/pivot-table/two-dimension-table.js +384 -0
  168. package/es/stat-view/ring-chart.js +392 -0
  169. package/es/stat-view/scatter-chart.js +306 -0
  170. package/es/stat-view/treemap-chart.js +253 -0
  171. package/es/stat-view/trend-chart.js +249 -0
  172. package/es/stat-view/world-map.js +431 -0
  173. package/es/tabs/tab.js +2 -2
  174. package/es/utils/basic-chart-utils.js +29 -0
  175. package/es/utils/cell-format.js +115 -0
  176. package/es/utils/collaborator.js +50 -0
  177. package/es/utils/color-utils.js +134 -0
  178. package/es/utils/column-utils.js +110 -0
  179. package/es/utils/column.js +20 -0
  180. package/es/utils/common-utils.js +352 -2
  181. package/es/utils/date-format.js +71 -0
  182. package/es/utils/export-table-utils.js +69 -0
  183. package/es/utils/index.js +89 -12
  184. package/es/utils/map.js +114 -0
  185. package/es/utils/model.js +19 -0
  186. package/es/utils/row-utils.js +134 -0
  187. package/es/utils/search.js +73 -0
  188. package/es/utils/sql-utils.js +359 -0
  189. package/es/utils/stat-utils.js +351 -0
  190. package/es/utils/trend-utils.js +135 -0
  191. package/package.json +8 -6
  192. package/es/components/dialog/chart-edit-dialog.js +0 -93
  193. package/es/components/dtable-popover.js +0 -97
  194. package/es/components/dtable-search-input.js +0 -135
  195. package/es/components/index.js +0 -41
  196. package/es/components/loading.js +0 -15
  197. package/es/components/modal-portal.js +0 -26
  198. package/es/model/conver-statItem.js +0 -124
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = calculateResult;
8
+ var _dtableUtils = require("dtable-utils");
9
+ var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
10
+ var _commonUtils = require("../../utils/common-utils");
11
+ var _constants = require("../../constants");
12
+ var _rowUtils = require("../../utils/row-utils");
13
+ async function calculateResult(chart, value, _ref) {
14
+ let {
15
+ getViewRows,
16
+ getTableFormulaResults
17
+ } = _ref;
18
+ const {
19
+ table_id,
20
+ view_id,
21
+ x_axis_column_key,
22
+ x_axis_include_empty,
23
+ x_axis_date_granularity: groupby_date_granularity,
24
+ x_axis_geolocation_granularity: groupby_geolocation_granularity,
25
+ y_axis_left_summary_column,
26
+ y_axis_right_summary_column,
27
+ y_axis_left_summary_type,
28
+ y_axis_right_summary_type,
29
+ y_axis_left_summary_method,
30
+ y_axis_right_summary_method,
31
+ y_axis_left_group_by_multiple_numeric_column,
32
+ y_axis_left_group_by_numeric_columns
33
+ } = chart;
34
+ const table = (0, _dtableUtils.getTableById)(value.tables, table_id);
35
+ const view = table && (0, _dtableUtils.getViewById)(table.views, view_id);
36
+ if (!view) {
37
+ return [];
38
+ }
39
+ const xAxisColumn = (0, _dtableUtils.getTableColumnByKey)(table, x_axis_column_key);
40
+ if (!xAxisColumn) return [];
41
+ const statRows = await getViewRows(view, table);
42
+ const formulaRows = await getTableFormulaResults(table, statRows);
43
+ const column1 = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_left_summary_column);
44
+ const column2 = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_right_summary_column);
45
+ const leftResultMap = new Map();
46
+ const rightResultMap = new Map();
47
+ let isColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(xAxisColumn);
48
+ let leftSummaryColumn = {};
49
+ let leftSummaryColumnKeys = [];
50
+ if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
51
+ if (column1) {
52
+ leftSummaryColumn[y_axis_left_summary_column] = {
53
+ method: y_axis_left_summary_method,
54
+ column_name: column1.name,
55
+ type: column1.type,
56
+ data: column1.data,
57
+ color: _constants.LABEL_COLORS[0]
58
+ };
59
+ }
60
+ if (y_axis_left_group_by_multiple_numeric_column) {
61
+ y_axis_left_group_by_numeric_columns.forEach((item, index) => {
62
+ const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, item.column_key);
63
+ if (summaryColumn) {
64
+ leftSummaryColumn[item.column_key] = {
65
+ method: item.summary_method,
66
+ column_name: summaryColumn.name,
67
+ type: summaryColumn.type,
68
+ data: summaryColumn.data,
69
+ color: _constants.LABEL_COLORS[(index + 1) % 12]
70
+ };
71
+ }
72
+ });
73
+ }
74
+ leftSummaryColumnKeys = Object.keys(leftSummaryColumn);
75
+ }
76
+ statRows.forEach(row => {
77
+ let {
78
+ _id: rowId
79
+ } = row;
80
+ let formulaRow = formulaRows[rowId];
81
+ const currentValue = row[xAxisColumn.key];
82
+ let label = _statUtils.default.getGroupLabel(currentValue, formulaRow, xAxisColumn, groupby_date_granularity, groupby_geolocation_granularity, value);
83
+
84
+ // collect left y axis data
85
+ if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.COUNT) {
86
+ if (isColumnDataAsAnArray) {
87
+ if (label.length > 0) {
88
+ label.forEach(name => {
89
+ let currentValue = leftResultMap.get(name) || 0;
90
+ currentValue = currentValue + 1;
91
+ leftResultMap.set(name, currentValue);
92
+ });
93
+ }
94
+ if (label.length === 0 && x_axis_include_empty) {
95
+ let currentValue = leftResultMap.get(null) || 0;
96
+ currentValue += 1;
97
+ leftResultMap.set(null, currentValue);
98
+ }
99
+ } else {
100
+ if (x_axis_include_empty || label) {
101
+ let currentLabelCount = leftResultMap.get(label) || 0;
102
+ currentLabelCount = currentLabelCount + 1;
103
+ leftResultMap.set(label, currentLabelCount);
104
+ }
105
+ }
106
+ }
107
+ if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
108
+ if (isColumnDataAsAnArray) {
109
+ if (label.length > 0) {
110
+ label.forEach(name => {
111
+ const currentLabelMap = leftResultMap.get(name) || {};
112
+ leftSummaryColumnKeys.forEach(key => {
113
+ const cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, {
114
+ ...leftSummaryColumn[key],
115
+ key
116
+ });
117
+ const currentLabelList = currentLabelMap[key] || [];
118
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
119
+ currentLabelList.push(cellValue);
120
+ }
121
+ currentLabelMap[key] = currentLabelList;
122
+ });
123
+ leftResultMap.set(name, currentLabelMap);
124
+ });
125
+ }
126
+ if (label.length === 0 && x_axis_include_empty) {
127
+ let currentValue = leftResultMap.get(null) || {};
128
+ leftSummaryColumnKeys.forEach(key => {
129
+ const cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, {
130
+ ...leftSummaryColumn[key],
131
+ key
132
+ });
133
+ const currentLabelList = currentValue[key] || [];
134
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
135
+ currentLabelList.push(cellValue);
136
+ }
137
+ currentValue[key] = currentLabelList;
138
+ });
139
+ leftResultMap.set(null, currentValue);
140
+ }
141
+ } else {
142
+ if (x_axis_include_empty || label) {
143
+ const currentValue = leftResultMap.get(label) || {};
144
+ leftSummaryColumnKeys.forEach(key => {
145
+ const cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, {
146
+ ...leftSummaryColumn[key],
147
+ key
148
+ });
149
+ const currentList = currentValue[key] || [];
150
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
151
+ currentList.push(cellValue);
152
+ }
153
+ currentValue[key] = currentList;
154
+ });
155
+ leftResultMap.set(label, currentValue);
156
+ }
157
+ }
158
+ }
159
+
160
+ // collect right y axis data
161
+ if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.COUNT) {
162
+ if (isColumnDataAsAnArray) {
163
+ if (label.length > 0) {
164
+ label.forEach(name => {
165
+ let currentValue = rightResultMap.get(name) || 0;
166
+ currentValue = currentValue + 1;
167
+ rightResultMap.set(name, currentValue);
168
+ });
169
+ }
170
+ if (label.length === 0 && x_axis_include_empty) {
171
+ let currentValue = rightResultMap.get(null) || 0;
172
+ currentValue += 1;
173
+ rightResultMap.set(null, currentValue);
174
+ }
175
+ } else {
176
+ if (x_axis_include_empty || label) {
177
+ let currentLabelCount = rightResultMap.get(label) || 0;
178
+ currentLabelCount = currentLabelCount + 1;
179
+ rightResultMap.set(label, currentLabelCount);
180
+ }
181
+ }
182
+ }
183
+ if (y_axis_right_summary_column && y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
184
+ const cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, column2);
185
+ if (isColumnDataAsAnArray) {
186
+ if (label.length > 0) {
187
+ label.forEach(name => {
188
+ const currentLabelList = rightResultMap.get(name) || [];
189
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
190
+ currentLabelList.push(cellValue);
191
+ }
192
+ rightResultMap.set(name, currentLabelList);
193
+ });
194
+ }
195
+ if (label.length === 0 && x_axis_include_empty) {
196
+ let currentValue = rightResultMap.get(null) || [];
197
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
198
+ currentValue.push(cellValue);
199
+ }
200
+ rightResultMap.set(null, currentValue);
201
+ }
202
+ } else {
203
+ if (x_axis_include_empty || label) {
204
+ const currentLabelList = rightResultMap.get(label) || [];
205
+ if ((0, _dtableUtils.isNumber)(cellValue)) {
206
+ currentLabelList.push(cellValue);
207
+ }
208
+ rightResultMap.set(label, currentLabelList);
209
+ }
210
+ }
211
+ }
212
+ });
213
+
214
+ // Summary collect data
215
+ let results = [];
216
+ let targetMap = leftResultMap;
217
+ if (leftSummaryColumnKeys.length === 0 && y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
218
+ targetMap = rightResultMap;
219
+ }
220
+ for (let item of targetMap) {
221
+ const key = item[0];
222
+ const leftValue = item[1];
223
+ let value1 = 0;
224
+ let value2 = 0;
225
+ let formattedValueLeft = value1;
226
+ let formattedValueRight = value2;
227
+ const rightValue = rightResultMap.get(key);
228
+ if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.COUNT) {
229
+ value2 = rightValue;
230
+ formattedValueRight = value2;
231
+ }
232
+ if (y_axis_right_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
233
+ value2 = (0, _commonUtils.getSummaryResult)(rightValue, y_axis_right_summary_method);
234
+ formattedValueRight = _statUtils.default.getFormattedValue(value2, column2, y_axis_right_summary_method);
235
+ }
236
+ if (!y_axis_left_group_by_multiple_numeric_column) {
237
+ if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.COUNT) {
238
+ value1 = leftValue;
239
+ formattedValueLeft = value1;
240
+ }
241
+ if (y_axis_left_summary_type === _constants.SUMMARY_TYPE.ADVANCED) {
242
+ const list = leftValue[column1.key];
243
+ value1 = (0, _commonUtils.getSummaryResult)(list, y_axis_left_summary_method);
244
+ formattedValueLeft = _statUtils.default.getFormattedValue(value1, column1, y_axis_left_summary_method);
245
+ }
246
+ results.push({
247
+ name: key,
248
+ value_left: value1,
249
+ value_right: value2,
250
+ formatted_value_left: formattedValueLeft,
251
+ formatted_value_right: formattedValueRight
252
+ });
253
+ } else {
254
+ leftSummaryColumnKeys.forEach(columnKey => {
255
+ const summaryColumn = leftSummaryColumn[columnKey];
256
+ const summaryMethod = summaryColumn.method;
257
+ const list = leftValue[columnKey];
258
+ const value = (0, _commonUtils.getSummaryResult)(list, summaryMethod);
259
+ formattedValueLeft = _statUtils.default.getFormattedValue(value, summaryColumn, summaryMethod);
260
+ results.push({
261
+ name: key,
262
+ value_left: value,
263
+ color: leftSummaryColumn[columnKey].color,
264
+ value_right: value2,
265
+ formatted_value_left: formattedValueLeft,
266
+ formatted_value_right: formattedValueRight
267
+ });
268
+ });
269
+ }
270
+ }
271
+ _statUtils.default.sortStatistics(results, xAxisColumn, 'name');
272
+ results.forEach(item => {
273
+ item.name = (0, _rowUtils.getFormattedLabel)(xAxisColumn, item.name, value.collaborators);
274
+ });
275
+ return results;
276
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _dtableUtils = require("dtable-utils");
9
+ var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
10
+ var _commonUtils = require("../../utils/common-utils");
11
+ var _rowUtils = require("../../utils/row-utils");
12
+ var _constants = require("../../constants");
13
+ async function calculateChart(chart, value, _ref) {
14
+ let {
15
+ getViewRows,
16
+ getTableFormulaResults
17
+ } = _ref;
18
+ const {
19
+ table_id,
20
+ view_id,
21
+ x_axis_column_key,
22
+ y_axis_summary_type,
23
+ y_axis_summary_method,
24
+ y_axis_column_key,
25
+ x_axis_date_granularity,
26
+ x_axis_date_range_start,
27
+ x_axis_date_range_end,
28
+ x_axis_compared_date_range_start,
29
+ x_axis_compared_date_range_end,
30
+ display_increase
31
+ } = chart;
32
+ const groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
33
+ const groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
34
+ const table = (0, _dtableUtils.getTableById)(value.tables, table_id);
35
+ const view = table && (0, _dtableUtils.getViewById)(table.views, view_id);
36
+ if (!view || !x_axis_column_key) {
37
+ return [];
38
+ }
39
+ const groupbyColumn = (0, _dtableUtils.getTableColumnByKey)(table, x_axis_column_key);
40
+ if (!groupbyColumn) {
41
+ return [];
42
+ }
43
+ const summaryColumn = (0, _dtableUtils.getTableColumnByKey)(table, y_axis_column_key) || {};
44
+ const statRows = await getViewRows(view, table);
45
+ const formulaRows = await getTableFormulaResults(table, statRows);
46
+ const dateRangeResultMap = new Map();
47
+ const comparedDateRangeResultMap = new Map();
48
+ const isAdvance = y_axis_summary_type === _constants.SUMMARY_TYPE.ADVANCED;
49
+ statRows.forEach(row => {
50
+ const {
51
+ _id: rowId
52
+ } = row;
53
+ const cellValue = row[groupbyColumn.key];
54
+ const formulaRow = formulaRows[rowId];
55
+ if (!cellValue) return;
56
+ if (cellValue >= x_axis_date_range_start && cellValue <= x_axis_date_range_end || cellValue >= x_axis_compared_date_range_start && cellValue <= x_axis_compared_date_range_end) {
57
+ const name = _statUtils.default.getGroupLabel(cellValue, formulaRow, groupbyColumn, x_axis_date_granularity, '', value);
58
+ if (cellValue >= x_axis_date_range_start && cellValue <= x_axis_date_range_end) {
59
+ if (isAdvance) {
60
+ const currentValue = dateRangeResultMap.get(name);
61
+ const _cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, summaryColumn);
62
+ if (!currentValue) {
63
+ dateRangeResultMap.set(name, [_cellValue]);
64
+ } else {
65
+ currentValue.push(_cellValue);
66
+ }
67
+ } else {
68
+ const currentValue = dateRangeResultMap.get(name);
69
+ if (!currentValue) {
70
+ dateRangeResultMap.set(name, 1);
71
+ } else {
72
+ dateRangeResultMap.set(name, currentValue + 1);
73
+ }
74
+ }
75
+ } else {
76
+ if (isAdvance) {
77
+ const currentValue = comparedDateRangeResultMap.get(name);
78
+ const _cellValue = (0, _rowUtils.getCellValue)(row, formulaRow, summaryColumn);
79
+ if (!currentValue && summaryColumn) {
80
+ comparedDateRangeResultMap.set(name, [_cellValue]);
81
+ } else {
82
+ currentValue.push(_cellValue);
83
+ }
84
+ } else {
85
+ const currentValue = comparedDateRangeResultMap.get(name);
86
+ if (!currentValue) {
87
+ comparedDateRangeResultMap.set(name, 1);
88
+ } else {
89
+ comparedDateRangeResultMap.set(name, currentValue + 1);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ });
95
+ let dateRangeResult = [];
96
+ let comparedDateRangeResult = [];
97
+ const data = summaryColumn.data || {};
98
+ for (let item of dateRangeResultMap) {
99
+ const key = item[0];
100
+ let value = item[1];
101
+ let formatted_value = value;
102
+ if (isAdvance) {
103
+ value = (0, _commonUtils.getSummaryResult)(value, y_axis_summary_method, data.precision);
104
+ formatted_value = _statUtils.default.getFormattedValue(value, summaryColumn, y_axis_summary_method);
105
+ }
106
+ dateRangeResult.push({
107
+ name: key,
108
+ group_name: groupName1,
109
+ raw_name: key,
110
+ value,
111
+ formatted_value
112
+ });
113
+ }
114
+ _statUtils.default.sortStatistics(dateRangeResult, groupbyColumn, 'name');
115
+ for (let item of comparedDateRangeResultMap) {
116
+ const key = item[0];
117
+ let value = item[1];
118
+ let formatted_value = value;
119
+ if (isAdvance) {
120
+ value = (0, _commonUtils.getSummaryResult)(value, y_axis_summary_method, data.precision);
121
+ formatted_value = _statUtils.default.getFormattedValue(value, summaryColumn, y_axis_summary_method);
122
+ }
123
+ comparedDateRangeResult.push({
124
+ name: key,
125
+ group_name: groupName2,
126
+ raw_name: key,
127
+ value,
128
+ formatted_value
129
+ });
130
+ }
131
+ _statUtils.default.sortStatistics(comparedDateRangeResult, groupbyColumn, 'name');
132
+ for (let i = 0; i < dateRangeResult.length; i++) {
133
+ if (!comparedDateRangeResult[i]) break;
134
+ comparedDateRangeResult[i].name = dateRangeResult[i].name;
135
+ if (display_increase) {
136
+ const value1 = dateRangeResult[i].value;
137
+ const value2 = comparedDateRangeResult[i].value || 0.001;
138
+ if (!value2) {
139
+ comparedDateRangeResult[i].increase_value = 1;
140
+ } else {
141
+ comparedDateRangeResult[i].increase_value = Number(((value1 - value2) / value2).toFixed(2));
142
+ }
143
+ }
144
+ }
145
+ if (comparedDateRangeResult.length > dateRangeResult.length) {
146
+ comparedDateRangeResult = comparedDateRangeResult.slice(0, dateRangeResult.length);
147
+ }
148
+ return [...comparedDateRangeResult, ...dateRangeResult];
149
+ }
150
+ var _default = exports.default = calculateChart;
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _dtableUtils = require("dtable-utils");
9
+ var _commonUtils = require("../../utils/common-utils");
10
+ var _rowUtils = require("../../utils/row-utils");
11
+ var _statUtils = _interopRequireDefault(require("../../utils/stat-utils"));
12
+ var _constants = require("../../constants");
13
+ async function calculateResult(chart, value, _ref) {
14
+ let {
15
+ getViewRows,
16
+ getTableFormulaResults
17
+ } = _ref;
18
+ const {
19
+ table_id,
20
+ view_id,
21
+ name_column,
22
+ completed_column,
23
+ target_column,
24
+ group_column,
25
+ date_granularity,
26
+ geolocation_granularity
27
+ } = chart;
28
+ const table = (0, _dtableUtils.getTableById)(value.tables, table_id);
29
+ const view = table && (0, _dtableUtils.getViewById)(table.views, view_id);
30
+ if (!view) {
31
+ return [];
32
+ }
33
+ const nameColumn = (0, _dtableUtils.getTableColumnByKey)(table, name_column);
34
+ if (!nameColumn) return [];
35
+ const statRows = await getViewRows(view, table);
36
+ const formulaRows = await getTableFormulaResults(table, statRows);
37
+ const groupColumn = (0, _dtableUtils.getTableColumnByKey)(table, group_column);
38
+ const isColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(nameColumn);
39
+ const isGroupChart = !!groupColumn;
40
+ let result = [];
41
+ if (!isGroupChart) {
42
+ const completedColumn = (0, _dtableUtils.getTableColumnByKey)(table, completed_column);
43
+ const targetColumn = (0, _dtableUtils.getTableColumnByKey)(table, target_column);
44
+ let labelCountMap = {};
45
+ let labels = [];
46
+ statRows.forEach(row => {
47
+ let {
48
+ _id: rowId
49
+ } = row;
50
+ let formulaRow = formulaRows[rowId] || {};
51
+ const name = row[nameColumn.key];
52
+ if (name || Number.isFinite(name)) {
53
+ let label = _statUtils.default.getGroupLabel(name, formulaRow, nameColumn, '', '', value);
54
+ if (isColumnDataAsAnArray) {
55
+ label = label[0];
56
+ }
57
+ label = (0, _rowUtils.getFormattedLabel)(nameColumn, label, value.collaborators);
58
+ let currentValue = (0, _rowUtils.getCellValue)(row, formulaRow, completedColumn);
59
+ let targetValue = (0, _rowUtils.getCellValue)(row, formulaRow, targetColumn);
60
+ currentValue = (0, _dtableUtils.isNumber)(currentValue) ? currentValue : 0;
61
+ targetValue = (0, _dtableUtils.isNumber)(targetValue) ? targetValue : 0;
62
+ if (labelCountMap[label]) {
63
+ labelCountMap[label].currentValue = currentValue + labelCountMap[label].currentValue;
64
+ labelCountMap[label].targetValue = targetValue + labelCountMap[label].targetValue;
65
+ } else {
66
+ labelCountMap[label] = {
67
+ currentValue,
68
+ targetValue
69
+ };
70
+ labels.push(label);
71
+ }
72
+ }
73
+ });
74
+ labels.forEach(label => {
75
+ if (labelCountMap[label]) {
76
+ const {
77
+ currentValue,
78
+ targetValue
79
+ } = labelCountMap[label];
80
+ if (currentValue < targetValue) {
81
+ result.unshift({
82
+ name: label,
83
+ value: currentValue,
84
+ type: 'completed',
85
+ current_value: currentValue,
86
+ target_value: targetValue
87
+ }, {
88
+ name: label,
89
+ value: targetValue - currentValue,
90
+ type: 'uncompleted',
91
+ current_value: currentValue,
92
+ target_value: targetValue
93
+ });
94
+ } else {
95
+ result.unshift({
96
+ name: label,
97
+ value: currentValue,
98
+ type: 'completed',
99
+ current_value: currentValue,
100
+ target_value: targetValue
101
+ });
102
+ }
103
+ }
104
+ });
105
+ } else {
106
+ const completedColumn = (0, _dtableUtils.getTableColumnByKey)(table, completed_column);
107
+ const targetColumn = (0, _dtableUtils.getTableColumnByKey)(table, target_column);
108
+ let labelCountMap = {};
109
+ let colorMap = {};
110
+ let labelGroups = [];
111
+ let colorIndex = 0;
112
+ let isFormulaType = _dtableUtils.FORMULA_COLUMN_TYPES_MAP[groupColumn.type];
113
+ const isGroupColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(groupColumn);
114
+ statRows.forEach(row => {
115
+ let {
116
+ _id: rowId
117
+ } = row;
118
+ let formulaRow = formulaRows[rowId] || {};
119
+ const name = row[nameColumn.key],
120
+ groupLabelName = !isFormulaType ? row[groupColumn.key] : formulaRow[rowId][groupColumn.key];
121
+ if ((name || Number.isFinite(name)) && (groupLabelName || Number.isFinite(groupLabelName))) {
122
+ let label = _statUtils.default.getGroupLabel(name, formulaRow, nameColumn, '', '', value),
123
+ groupLabel = _statUtils.default.getGroupLabel(groupLabelName, formulaRow, groupColumn, date_granularity, geolocation_granularity, value);
124
+ if (isColumnDataAsAnArray) {
125
+ label = label[0];
126
+ }
127
+ if (isGroupColumnDataAsAnArray) {
128
+ groupLabel = groupLabel[0];
129
+ }
130
+ label = (0, _rowUtils.getFormattedLabel)(nameColumn, label, value.collaborators);
131
+ groupLabel = (0, _rowUtils.getFormattedLabel)(groupColumn, groupLabel, value.collaborators);
132
+ let color = colorMap[groupLabel];
133
+ if (!color) {
134
+ color = _constants.PIE_CHART_COLORS[colorIndex % 12];
135
+ colorMap[groupLabel] = color;
136
+ colorIndex++;
137
+ }
138
+ if (groupLabel) {
139
+ let currentValue = (0, _rowUtils.getCellValue)(row, formulaRow, completedColumn);
140
+ let targetValue = (0, _rowUtils.getCellValue)(row, formulaRow, targetColumn);
141
+ currentValue = (0, _dtableUtils.isNumber)(currentValue) ? currentValue : 0;
142
+ targetValue = (0, _dtableUtils.isNumber)(targetValue) ? targetValue : 0;
143
+ const concatLabel = "".concat(label, "_").concat(groupLabel);
144
+ if (labelCountMap[concatLabel]) {
145
+ labelCountMap[concatLabel].currentValue = currentValue + labelCountMap[concatLabel].currentValue;
146
+ labelCountMap[concatLabel].targetValue = targetValue + labelCountMap[concatLabel].targetValue;
147
+ } else {
148
+ labelCountMap[concatLabel] = {
149
+ currentValue,
150
+ targetValue
151
+ };
152
+ labelGroups.push({
153
+ key: concatLabel,
154
+ label,
155
+ groupLabel
156
+ });
157
+ }
158
+ }
159
+ }
160
+ });
161
+ labelGroups.forEach(labelGroup => {
162
+ const {
163
+ key,
164
+ label,
165
+ groupLabel
166
+ } = labelGroup;
167
+ if (labelCountMap[key]) {
168
+ const color = colorMap[groupLabel];
169
+ const {
170
+ currentValue,
171
+ targetValue
172
+ } = labelCountMap[key];
173
+ if (currentValue < targetValue) {
174
+ result.unshift({
175
+ name: label,
176
+ group_label: groupLabel,
177
+ value: currentValue,
178
+ color,
179
+ type: 'completed',
180
+ current_value: currentValue,
181
+ target_value: targetValue
182
+ }, {
183
+ name: label,
184
+ group_label: groupLabel,
185
+ value: targetValue - currentValue,
186
+ color,
187
+ type: 'uncompleted',
188
+ current_value: currentValue,
189
+ target_value: targetValue
190
+ });
191
+ } else {
192
+ result.unshift({
193
+ name: label,
194
+ group_label: groupLabel,
195
+ value: currentValue,
196
+ color,
197
+ type: 'completed',
198
+ current_value: currentValue,
199
+ target_value: targetValue
200
+ });
201
+ }
202
+ }
203
+ });
204
+ result.colorMap = colorMap;
205
+ }
206
+ return result;
207
+ }
208
+ var _default = exports.default = calculateResult;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _dtableUtils = require("dtable-utils");
8
+ var _commonUtils = require("../../utils/common-utils");
9
+ var _rowUtils = require("../../utils/row-utils");
10
+ async function calculateResult(chart, value, _ref) {
11
+ let {
12
+ getViewRows,
13
+ getTableFormulaResults
14
+ } = _ref;
15
+ const {
16
+ table_id,
17
+ view_id,
18
+ target_value_column,
19
+ target_value_column_summary_method,
20
+ total_value_column,
21
+ total_value_column_summary_method
22
+ } = chart;
23
+ const selectedTable = (0, _dtableUtils.getTableById)(value.tables, table_id);
24
+ const selectedView = selectedTable && (0, _dtableUtils.getViewById)(selectedTable.views, view_id);
25
+ const selectedColumn1 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, target_value_column);
26
+ const selectedColumn2 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, total_value_column);
27
+ const statRows = await getViewRows(selectedView, selectedTable);
28
+ if (statRows.length === 0) {
29
+ return 0;
30
+ }
31
+ const isNumericColumn1 = selectedColumn1 && (0, _dtableUtils.isNumericColumn)(selectedColumn1);
32
+ const isNumericColumn2 = selectedColumn2 && (0, _dtableUtils.isNumericColumn)(selectedColumn2);
33
+ const formulaRows = isNumericColumn1 || isNumericColumn2 ? await getTableFormulaResults(selectedTable, statRows) : {};
34
+ let result1;
35
+ let result2;
36
+ let numberList1 = [];
37
+ let numberList2 = [];
38
+ statRows.forEach(row => {
39
+ const formulaRow = formulaRows[row._id];
40
+ if (isNumericColumn1) {
41
+ const cellValue1 = (0, _rowUtils.getCellValue)(row, formulaRow, selectedColumn1);
42
+ if ((0, _dtableUtils.isNumber)(cellValue1)) {
43
+ numberList1.push(cellValue1);
44
+ }
45
+ }
46
+ if (isNumericColumn2) {
47
+ const cellValue2 = (0, _rowUtils.getCellValue)(row, formulaRow, selectedColumn2);
48
+ if ((0, _dtableUtils.isNumber)(cellValue2)) {
49
+ numberList2.push(cellValue2);
50
+ }
51
+ }
52
+ });
53
+ if (target_value_column_summary_method === 'Row_count') {
54
+ result1 = statRows.length;
55
+ } else {
56
+ result1 = (0, _commonUtils.getSummaryResult)(numberList1, target_value_column_summary_method);
57
+ }
58
+ if (total_value_column_summary_method === 'Row_count') {
59
+ result2 = statRows.length;
60
+ } else {
61
+ result2 = (0, _commonUtils.getSummaryResult)(numberList2, total_value_column_summary_method);
62
+ }
63
+ if (result2 === 0) {
64
+ return 0;
65
+ }
66
+ return result1 / result2;
67
+ }
68
+ var _default = exports.default = calculateResult;