dtable-statistic 4.3.15 → 4.4.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.
@@ -39,7 +39,10 @@ async function calculateResult(chart, value, _ref) {
39
39
  const isGroupChart = !!groupColumn;
40
40
  let result = [];
41
41
  if (!isGroupChart) {
42
- const memo = new Map();
42
+ const completedColumn = (0, _dtableUtils.getTableColumnByKey)(table, completed_column);
43
+ const targetColumn = (0, _dtableUtils.getTableColumnByKey)(table, target_column);
44
+ let labelCountMap = {};
45
+ let labels = [];
43
46
  statRows.forEach(row => {
44
47
  let {
45
48
  _id: rowId
@@ -52,43 +55,59 @@ async function calculateResult(chart, value, _ref) {
52
55
  label = label[0];
53
56
  }
54
57
  label = (0, _rowUtils.getFormattedLabel)(nameColumn, label, value.collaborators);
55
- if (!memo.get(label)) {
56
- const completedColumn = (0, _dtableUtils.getTableColumnByKey)(table, completed_column);
57
- const targetColumn = (0, _dtableUtils.getTableColumnByKey)(table, target_column);
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 (currentValue >= targetValue) {
63
- result.unshift({
64
- name: label,
65
- value: currentValue,
66
- type: 'completed',
67
- current_value: currentValue,
68
- target_value: targetValue
69
- });
70
- } else {
71
- result.unshift({
72
- name: label,
73
- value: currentValue,
74
- type: 'completed',
75
- current_value: currentValue,
76
- target_value: targetValue
77
- }, {
78
- name: label,
79
- value: targetValue - currentValue,
80
- type: 'uncompleted',
81
- current_value: currentValue,
82
- target_value: targetValue
83
- });
84
- }
85
- memo.set(label, 1);
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
+ });
86
102
  }
87
103
  }
88
104
  });
89
105
  } else {
90
- const memo = new Map();
91
- const colorMap = {};
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 = [];
92
111
  let colorIndex = 0;
93
112
  let isFormulaType = _dtableUtils.FORMULA_COLUMN_TYPES_MAP[groupColumn.type];
94
113
  const isGroupColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(groupColumn);
@@ -116,54 +135,72 @@ async function calculateResult(chart, value, _ref) {
116
135
  colorMap[groupLabel] = color;
117
136
  colorIndex++;
118
137
  }
119
- let cache = memo.get(label);
120
- if (groupLabel && (!cache || !cache[groupLabel])) {
121
- const completedColumn = (0, _dtableUtils.getTableColumnByKey)(table, completed_column);
122
- const targetColumn = (0, _dtableUtils.getTableColumnByKey)(table, target_column);
138
+ if (groupLabel) {
123
139
  let currentValue = (0, _rowUtils.getCellValue)(row, formulaRow, completedColumn);
124
140
  let targetValue = (0, _rowUtils.getCellValue)(row, formulaRow, targetColumn);
125
141
  currentValue = (0, _dtableUtils.isNumber)(currentValue) ? currentValue : 0;
126
142
  targetValue = (0, _dtableUtils.isNumber)(targetValue) ? targetValue : 0;
127
- if (currentValue >= targetValue) {
128
- result.unshift({
129
- name: label,
130
- group_label: groupLabel,
131
- value: currentValue,
132
- color,
133
- type: 'completed',
134
- current_value: currentValue,
135
- target_value: targetValue
136
- });
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;
137
147
  } else {
138
- result.unshift({
139
- name: label,
140
- group_label: groupLabel,
141
- value: currentValue,
142
- color,
143
- type: 'completed',
144
- current_value: currentValue,
145
- target_value: targetValue
146
- }, {
147
- name: label,
148
- group_label: groupLabel,
149
- value: targetValue - currentValue,
150
- color,
151
- type: 'uncompleted',
152
- current_value: currentValue,
153
- target_value: targetValue
154
- });
155
- }
156
- if (cache) {
157
- cache[groupLabel] = 1;
158
- memo.set(label, cache);
159
- } else {
160
- memo.set(label, {
161
- [groupLabel]: 1
148
+ labelCountMap[concatLabel] = {
149
+ currentValue,
150
+ targetValue
151
+ };
152
+ labelGroups.push({
153
+ key: concatLabel,
154
+ label,
155
+ groupLabel
162
156
  });
163
157
  }
164
158
  }
165
159
  }
166
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
+ });
167
204
  result.colorMap = colorMap;
168
205
  }
169
206
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.3.15",
3
+ "version": "4.4.0",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",
@@ -22,9 +22,9 @@
22
22
  "reactstrap": "8.9.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "dtable-ui-component": "~4.3.*",
26
- "dtable-utils": "~4.3.*",
27
- "dtable-web-api": "~4.3.*",
25
+ "dtable-ui-component": "~4.4.*",
26
+ "dtable-utils": "~4.4.*",
27
+ "dtable-web-api": "~4.4.*",
28
28
  "@antv/scale": "0.3.14"
29
29
  },
30
30
  "devDependencies": {
@@ -56,9 +56,9 @@
56
56
  "css-minimizer-webpack-plugin": "^3.2.0",
57
57
  "dotenv": "^10.0.0",
58
58
  "dotenv-expand": "^5.1.0",
59
- "dtable-ui-component": "4.3.10",
60
- "dtable-utils": "4.3.9",
61
- "dtable-web-api": "4.3.5",
59
+ "dtable-ui-component": "4.4.0",
60
+ "dtable-utils": "4.4.0",
61
+ "dtable-web-api": "4.4.0",
62
62
  "dtable-store": "4.3.6",
63
63
  "eslint": "^8.3.0",
64
64
  "eslint-config-react-app": "^7.0.1",