dtable-statistic 4.0.8 → 4.0.10

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.
@@ -306,8 +306,7 @@ function getGroupbyNumericColumnsChartResults(rows, formulaRows, groupbyColumn,
306
306
  return getGroupChartStatResult(table, value, groupbyColumn, numericSummaryColumnKey, rows, formulaRows, includeEmpty, groupbyDateGranularity, groupbyGeolocationGranularity, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, summaryColumn, summaryType, summaryMethod, columnGroupbyMultipleNumericColumn, yAxisType);
307
307
  }
308
308
  function calculateGeolocationBasicChart(chart, value, username, userId) {
309
- var type = chart.type,
310
- table_id = chart.table_id,
309
+ var table_id = chart.table_id,
311
310
  view_id = chart.view_id,
312
311
  geo_column = chart.geo_column,
313
312
  geolocation_granularity = chart.geolocation_granularity,
@@ -315,9 +314,6 @@ function calculateGeolocationBasicChart(chart, value, username, userId) {
315
314
  summary_column = chart.summary_column,
316
315
  summary_method = chart.summary_method;
317
316
  var geolocationGranularity = geolocation_granularity;
318
- if (type === STAT_TYPE.WORLD_MAP || type === STAT_TYPE.WORLD_MAP_BUBBLE) {
319
- geolocationGranularity = null;
320
- }
321
317
  var table = TableUtils.getTableById(value.tables, table_id);
322
318
  var view = table && Views.getViewById(table.views, view_id);
323
319
  if (!view) {
package/es/model/ring.js CHANGED
@@ -25,13 +25,14 @@ var Ring = /*#__PURE__*/function (_BaseModel) {
25
25
  if (_this.summary_method === SUMMARY_METHOD_MAP.Row_count) {
26
26
  _this.summary_method = SUMMARY_METHOD_MAP.Max;
27
27
  }
28
- _this.show_legend = object.show_legend;
29
- _this.display_label = object.display_label;
28
+ _this.show_legend = isBoolean(object.show_legend) ? object.show_legend : true;
29
+ _this.display_label = isBoolean(object.display_label) ? object.display_label : true;
30
30
  _this.show_percent = object.show_percent;
31
31
  _this.sort_type = object.sort_type;
32
32
  _this.minimum_slice_percent = object.minimum_slice_percent;
33
33
  _this.display_annotation = isBoolean(object.display_annotation) ? object.display_annotation : true;
34
34
  _this.annotation_font_size = object.annotation_font_size;
35
+ _this.label_font_size = object.label_font_size;
35
36
  _this.label_format = object.label_format;
36
37
  _this.label_position = object.label_position;
37
38
  return _this;
@@ -24,8 +24,14 @@ var DashBoardService = /*#__PURE__*/function () {
24
24
  _createClass(DashBoardService, [{
25
25
  key: "initStatistics",
26
26
  value: function initStatistics(value, updateStatistics, deletePluginSettings) {
27
- this.statistics = value && value.statistics || [];
28
- if (this.statistics.length === 0) {
27
+ var baseStatistics = value && value.statistics || [];
28
+ var advancedStatistics = this.getAdvancedStatistics(value);
29
+ var hasBaseStatistics = baseStatistics.length > 0;
30
+ var hasAdvancedStatistics = advancedStatistics.length > 0;
31
+ this.statistics = baseStatistics;
32
+
33
+ // init default dashboard if neither base-statistics nor advanced-statistics
34
+ if (!hasBaseStatistics && !hasAdvancedStatistics) {
29
35
  this.statistics = [new StatisticDashBoard({
30
36
  _id: generatorUniqueId([]),
31
37
  stat_items: [],
@@ -36,11 +42,15 @@ var DashBoardService = /*#__PURE__*/function () {
36
42
  this.needSave = false;
37
43
 
38
44
  // convert to advance-statistic
39
- if (!hasOwnProperty(this.statistics[0], 'stat_items')) {
45
+ if (hasBaseStatistics && !hasOwnProperty(this.statistics[0], 'stat_items')) {
40
46
  this.needSave = true;
41
47
  this.convert2AdvanceStatistic();
42
48
  }
43
- this.mergeAdvancedStatistics(value, deletePluginSettings);
49
+
50
+ // merge advanced statistics
51
+ if (hasAdvancedStatistics) {
52
+ this.mergeAdvancedStatistics(advancedStatistics, deletePluginSettings);
53
+ }
44
54
  this.filterInvalidCharts();
45
55
  if (this.needSave) {
46
56
  this.needSave = false;
@@ -148,12 +158,16 @@ var DashBoardService = /*#__PURE__*/function () {
148
158
  return this.chartService.generatorChart(convertedChart);
149
159
  }
150
160
  }, {
151
- key: "mergeAdvancedStatistics",
152
- value: function mergeAdvancedStatistics(value, deletePluginSettings) {
161
+ key: "getAdvancedStatistics",
162
+ value: function getAdvancedStatistics(value) {
153
163
  if (!value || !hasOwnProperty(value, 'plugin_settings') || !hasOwnProperty(value.plugin_settings, ADVANCED_STATISTICS_NAME)) {
154
- return;
164
+ return [];
155
165
  }
156
- var advancedStatistics = value.plugin_settings[ADVANCED_STATISTICS_NAME];
166
+ return value.plugin_settings[ADVANCED_STATISTICS_NAME] || [];
167
+ }
168
+ }, {
169
+ key: "mergeAdvancedStatistics",
170
+ value: function mergeAdvancedStatistics(advancedStatistics, deletePluginSettings) {
157
171
  if (!Array.isArray(advancedStatistics) || advancedStatistics.length === 0 || this.statistics.some(function (dashboard) {
158
172
  return dashboard.from_advanced;
159
173
  }) // already merged from advanced
@@ -324,7 +324,10 @@ var PivotSettings = /*#__PURE__*/function (_Component) {
324
324
  _this.onChangeMultiSummaryMethod = function (index, option) {
325
325
  var _ref9 = _this.props.statItem || {},
326
326
  summary_columns_option = _ref9.summary_columns_option;
327
- summary_columns_option[index].method = option.value;
327
+ summary_columns_option = Array.isArray(summary_columns_option) ? _toConsumableArray(summary_columns_option) : [];
328
+ summary_columns_option[index] = Object.assign({}, summary_columns_option[index], {
329
+ method: option.value
330
+ });
328
331
  _this.props.updateStatItem(Object.assign({}, _this.props.statItem, {
329
332
  summary_columns_option: summary_columns_option
330
333
  }));
@@ -56,14 +56,16 @@ var BaseChart = /*#__PURE__*/function (_Component) {
56
56
  return ticksLen > 0 ? ticksLen : data.length;
57
57
  };
58
58
  _this.getThemeColors = function () {
59
+ var themeColors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
60
+ // dark->custom->light
59
61
  var _this$props = _this.props,
60
62
  isPreview = _this$props.isPreview,
61
63
  isEnlarge = _this$props.isEnlarge,
62
64
  theme = _this$props.theme;
63
- if (isEnlarge || !isPreview) {
64
- return STAT_ITEM_THEME_COLORS.light;
65
+ if (theme === THEME_NAME_MAP.DARK && !isEnlarge && isPreview) {
66
+ themeColors = STAT_ITEM_THEME_COLORS.dark;
65
67
  }
66
- return theme === THEME_NAME_MAP.DARK ? STAT_ITEM_THEME_COLORS[THEME_NAME_MAP.DARK] : STAT_ITEM_THEME_COLORS[THEME_NAME_MAP.LIGHT];
68
+ return themeColors || STAT_ITEM_THEME_COLORS[THEME_NAME_MAP.LIGHT];
67
69
  };
68
70
  _this.getAxisLabelColor = function (textColor) {
69
71
  var _this$props2 = _this.props,
@@ -12,7 +12,7 @@ import { Chart } from '../custom-g2';
12
12
  import { getCurrentTheme, sortDataByGroupSum } from '../utils/common-utils';
13
13
  import { getChartGroups } from '../utils/basic-chart-utils';
14
14
  import { getConvertedColorRules, getLabelColor } from '../utils/color-utils';
15
- import { DEFAULT_NUMBER_FORMAT_OBJECT, EMPTY_NAME, LABEL_CONFIG_CHANGED, STATISTICS_COUNT_SHOW, STAT_TYPE, SUMMARY_TYPE, TITLE_AMOUNT, TYPE_COLOR_USING, USEABLE_COLOR_TYPES } from '../constants';
15
+ import { DATA_SORT_TYPE, DEFAULT_NUMBER_FORMAT_OBJECT, EMPTY_NAME, LABEL_CONFIG_CHANGED, STATISTICS_COUNT_SHOW, STAT_TYPE, SUMMARY_TYPE, TITLE_AMOUNT, TYPE_COLOR_USING, USEABLE_COLOR_TYPES } from '../constants';
16
16
  var propTypes = {
17
17
  isPreview: PropTypes.bool,
18
18
  isEdit: PropTypes.bool,
@@ -45,7 +45,13 @@ var HorizontalBarChart = /*#__PURE__*/function (_BaseChart) {
45
45
  _this.initChartHandler();
46
46
  var data = originalData;
47
47
  if (type == STAT_TYPE.STACKED_HORIZONTAL_BAR && sort_type) {
48
- data = sortDataByGroupSum(originalData, sort_type);
48
+ var convertedSortType = sort_type;
49
+ if (sort_type === DATA_SORT_TYPE.ASCENDING) {
50
+ convertedSortType = DATA_SORT_TYPE.DESCENDING;
51
+ } else if (sort_type === DATA_SORT_TYPE.DESCENDING) {
52
+ convertedSortType = DATA_SORT_TYPE.ASCENDING;
53
+ }
54
+ data = sortDataByGroupSum(originalData, convertedSortType);
49
55
  }
50
56
  _this.chart.on('interval:click', function (e) {
51
57
  _this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
@@ -32,7 +32,7 @@ var PivotTable = /*#__PURE__*/function (_BaseChart) {
32
32
  if (!Object.keys(statData).length > 0) return '';
33
33
  var pivot_columns = statData.pivot_columns;
34
34
  var column_groupby_column_key = statItem.column_groupby_column_key;
35
- var themeColors = _this.getThemeColors();
35
+ var themeColors = _this.getThemeColors('#212529');
36
36
  if (Array.isArray(pivot_columns) && pivot_columns.length > 100) {
37
37
  return /*#__PURE__*/React.createElement("div", {
38
38
  className: 'statistic-chart-text'
@@ -6,10 +6,10 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
6
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
7
  import React, { PureComponent } from 'react';
8
8
  import intl from 'react-intl-universal';
9
- import { CellType, isNumber, TableUtils, Views } from 'dtable-store';
9
+ import { FORMULA_COLUMN_TYPES_MAP, isNumber, TableUtils, Views } from 'dtable-store';
10
10
  import PivotTableDisplayName from './pivot-table-display-name';
11
11
  import { isMobile } from '../../utils';
12
- import { TITLE_TOTAL } from '../../constants';
12
+ import { STATISTICS_COUNT_TYPE, SUMMARY_METHOD_MAP, TITLE_TOTAL } from '../../constants';
13
13
  import styles from './statistic-pivot-table.module.css';
14
14
  var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
15
15
  _inherits(TwoDimensionTable, _PureComponent);
@@ -59,6 +59,95 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
59
59
  }
60
60
  return 0;
61
61
  };
62
+ _this.getCellValueFromRow = function (row, formulaRow, columnType, columnKey, sqlKey, isSqlQuery) {
63
+ if (!isSqlQuery) {
64
+ if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
65
+ var cellValue = formulaRow[columnKey];
66
+ return Array.isArray(cellValue) ? cellValue[0] : cellValue;
67
+ }
68
+ return row[columnKey];
69
+ }
70
+ return row[sqlKey];
71
+ };
72
+ _this.getSummaryTotal = function (summaryColumnType, summaryColumnKey, sqlKey, summaryType, summaryMethod, rows, formulaRows, isSqlQuery) {
73
+ if (summaryType === STATISTICS_COUNT_TYPE.COUNT) {
74
+ return rows.length;
75
+ }
76
+ if (summaryType !== STATISTICS_COUNT_TYPE.ADVANCED) {
77
+ return 0;
78
+ }
79
+ switch (summaryMethod) {
80
+ case SUMMARY_METHOD_MAP.Distinct_values:
81
+ {
82
+ var count = 0;
83
+ var existMap = {};
84
+ rows.forEach(function (row) {
85
+ var formulaRow = formulaRows && formulaRows[row._id];
86
+ var cellValue = _this.getCellValueFromRow(row, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
87
+ if (!cellValue) {
88
+ if (cellValue === 0) {
89
+ cellValue = '0';
90
+ } else {
91
+ cellValue = !!cellValue;
92
+ }
93
+ }
94
+ if (!existMap[cellValue]) {
95
+ existMap[cellValue] = true;
96
+ count++;
97
+ }
98
+ });
99
+ return count;
100
+ }
101
+ case SUMMARY_METHOD_MAP.Sum:
102
+ case SUMMARY_METHOD_MAP.Mean:
103
+ {
104
+ var sum = 0;
105
+ var validNumbersCount = 0;
106
+ rows.forEach(function (row) {
107
+ var formulaRow = formulaRows && formulaRows[row._id];
108
+ var cellValue = _this.getCellValueFromRow(row, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
109
+ if (isNumber(cellValue)) {
110
+ validNumbersCount++;
111
+ sum += cellValue;
112
+ }
113
+ });
114
+ if (summaryMethod === SUMMARY_METHOD_MAP.Sum) {
115
+ sum = Number.parseFloat(sum.toFixed(8));
116
+ } else if (summaryMethod === SUMMARY_METHOD_MAP.Mean) {
117
+ sum = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
118
+ }
119
+ return sum;
120
+ }
121
+ case SUMMARY_METHOD_MAP.Max:
122
+ case SUMMARY_METHOD_MAP.Min:
123
+ {
124
+ if (rows.length === 0) {
125
+ return 0;
126
+ }
127
+ var result = rows.reduce(function (current, next) {
128
+ var currentFormulaRow = formulaRows && formulaRows[current._id];
129
+ var nextFormulaRow = formulaRows && formulaRows[next._id];
130
+ var currentValue = _this.getCellValueFromRow(current, currentFormulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
131
+ var nextValue = _this.getCellValueFromRow(next, nextFormulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
132
+ if (!nextValue && nextValue !== 0) {
133
+ return current;
134
+ }
135
+ var isNextGreater = currentValue < nextValue;
136
+ if (summaryMethod === SUMMARY_METHOD_MAP.Min) {
137
+ return isNextGreater ? current : next;
138
+ } else {
139
+ return isNextGreater ? next : current;
140
+ }
141
+ });
142
+ var formulaRow = formulaRows && formulaRows[result._id];
143
+ return _this.getCellValueFromRow(result, formulaRow, summaryColumnType, summaryColumnKey, sqlKey, isSqlQuery);
144
+ }
145
+ default:
146
+ {
147
+ return 0;
148
+ }
149
+ }
150
+ };
62
151
  _this.getCells = function (row, summaryColumn) {
63
152
  var _this$props2 = _this.props,
64
153
  pivotResult = _this$props2.pivotResult,
@@ -83,19 +172,7 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
83
172
  sqlKey = column.sqlKey,
84
173
  method = column.method;
85
174
  if (Array.isArray(rowData)) {
86
- var sum = 0;
87
- rowData.forEach(function (rowDataItem) {
88
- if (!isSqlQuery) {
89
- if (type === CellType.FORMULA) {
90
- var formulaRow = formulaRows[rowDataItem._id];
91
- sum += _this.getNumberValue(formulaRow[key]);
92
- return;
93
- }
94
- sum += _this.getNumberValue(rowDataItem[key]);
95
- return;
96
- }
97
- sum += _this.getNumberValue(rowDataItem[sqlKey]);
98
- });
175
+ var sum = _this.getSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, rowData, formulaRows, isSqlQuery);
99
176
  summary_multiple_columns.push(sum);
100
177
  formatted_summary_multiple_columns.push(getSummaryValueDisplayString(column, sum, method));
101
178
  return;
@@ -304,22 +381,12 @@ var TwoDimensionTable = /*#__PURE__*/function (_PureComponent) {
304
381
  var isValidTotalDisplayValue = true;
305
382
  if (column_groupby_multiple_numeric_column) {
306
383
  var total = 0;
307
- pivotColumnCell.forEach(function (item) {
308
- pivot_summary_multiple_columns.forEach(function (jtem) {
309
- var type = jtem.type,
310
- key = jtem.key,
311
- sqlKey = jtem.sqlKey;
312
- if (!isSqlQuery) {
313
- if (type === CellType.FORMULA) {
314
- var formulaRow = formulaRows[item._id];
315
- total += _this.getNumberValue(formulaRow[key]);
316
- return;
317
- }
318
- total += _this.getNumberValue(item[key]);
319
- return;
320
- }
321
- total += _this.getNumberValue(item[sqlKey]);
322
- });
384
+ pivot_summary_multiple_columns.forEach(function (summaryCol) {
385
+ var type = summaryCol.type,
386
+ key = summaryCol.key,
387
+ sqlKey = summaryCol.sqlKey,
388
+ method = summaryCol.method;
389
+ total += _this.getSummaryTotal(type, key, sqlKey, STATISTICS_COUNT_TYPE.ADVANCED, method, pivotColumnCell, formulaRows, isSqlQuery);
323
390
  });
324
391
  totalDisplayValue = total;
325
392
  allTotalDisplay += total;
@@ -1,5 +1,6 @@
1
1
  import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, generatorBase64Code, isNumber, TableUtils } from 'dtable-store';
2
2
  import { STAT_TYPE, DEFAULT_LABEL_FONT_SIZE, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, CHART_STYLE_COLORS, PIE_COLOR_OPTIONS, SUMMARY_METHOD_MAP } from '../constants';
3
+ import StatUtils from './stat-utils';
3
4
  export var generatorUniqueId = function generatorUniqueId(list) {
4
5
  var uniqueId;
5
6
  var isUnique = false;
@@ -310,12 +311,10 @@ export var sortDataByGroupSum = function sortDataByGroupSum(data, sortType) {
310
311
  });
311
312
  }
312
313
  });
313
- var sortSum = sortType == 'ascending' ? function (a, b) {
314
- return a.valueSum - b.valueSum;
315
- } : function (a, b) {
316
- return b.valueSum - a.valueSum;
317
- };
318
- return nameSumMap.sort(sortSum).reduce(function (accumulator, currentItem) {
314
+
315
+ // sort group
316
+ StatUtils.sortDataByKey(nameSumMap, 'valueSum', sortType);
317
+ return nameSumMap.reduce(function (accumulator, currentItem) {
319
318
  return accumulator.concat(currentItem.items);
320
319
  }, []);
321
320
  };
@@ -2,7 +2,7 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import { DateUtils, isNumber, isNumericColumn, CellType, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, sortText, sortNumber, sortDate, sortSingleSelect, getPrecisionNumber, getFormulaDisplayString, getGeolocationDisplayString, getDateDisplayString, getNumberDisplayString } from 'dtable-store';
4
4
  import { getClientFormulaDisplayString } from '../utils';
5
- import { STATISTICS_COUNT_TYPE, SUMMARY_METHOD_MAP } from '../constants';
5
+ import { DATA_SORT_TYPE, STATISTICS_COUNT_TYPE, SUMMARY_METHOD_MAP } from '../constants';
6
6
  var SUPPORT_SORT_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.SINGLE_SELECT, CellType.FORMULA, CellType.LINK_FORMULA, CellType.CTIME, CellType.MTIME, CellType.RATE];
7
7
  var getValidCollaborators = function getValidCollaborators(collaborators, emails) {
8
8
  if (!Array.isArray(emails)) {
@@ -207,24 +207,29 @@ var StatUtils = /*#__PURE__*/function () {
207
207
  });
208
208
  }
209
209
  }, {
210
- key: "sortStatisticData",
211
- value: function sortStatisticData(statistics, sort_type) {
212
- statistics.sort(function (currResult, nextResult) {
213
- var current = currResult.value;
214
- var next = nextResult.value;
215
- if (!current && current !== 0) {
210
+ key: "sortDataByKey",
211
+ value: function sortDataByKey(data, key, sortType) {
212
+ data.sort(function (curr, next) {
213
+ var currentVal = curr[key];
214
+ var nextVal = next[key];
215
+ if (!currentVal && currentVal !== 0) {
216
216
  return -1;
217
217
  }
218
- if (!next && next !== 0) {
218
+ if (!nextVal && nextVal !== 0) {
219
219
  return 1;
220
220
  }
221
- if (sort_type === 'ascending') {
222
- return current > next ? 1 : -1;
221
+ if (sortType === DATA_SORT_TYPE.ASCENDING) {
222
+ return currentVal > nextVal ? 1 : -1;
223
223
  } else {
224
- return current > next ? -1 : 1;
224
+ return currentVal > nextVal ? -1 : 1;
225
225
  }
226
226
  });
227
227
  }
228
+ }, {
229
+ key: "sortStatisticData",
230
+ value: function sortStatisticData(statistics, sort_type) {
231
+ this.sortDataByKey(statistics, 'value', sort_type);
232
+ }
228
233
  }, {
229
234
  key: "getTotal",
230
235
  value: function getTotal(summary_column_key, summary_column_type, summary_type, summary_method) {
@@ -78,7 +78,7 @@ export function summaryDurationResult(result, duration, summaryType, summaryMeth
78
78
  var days = duration === 'days_30' ? 30 : 7;
79
79
  var endDate = currentTime.format('YYYY-MM-DD');
80
80
  var middleDate = currentTime.subtract(days, 'days').format('YYYY-MM-DD');
81
- var startDate = currentTime.subtract(days, 'days').format('YYYY-MM-DD');
81
+ var startDate = dayjs(middleDate).subtract(days, 'days').format('YYYY-MM-DD');
82
82
  var compareValue = [];
83
83
  var comparedValue = [];
84
84
  if (useDataDb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.0.8",
3
+ "version": "4.0.10",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",
@@ -12,7 +12,7 @@
12
12
  "@seafile/seafile-calendar": "0.0.24",
13
13
  "comlink": "^4.3.1",
14
14
  "dayjs": "1.10.7",
15
- "dtable-store": "4.0.2",
15
+ "dtable-store": "4.0.6",
16
16
  "dtable-web-api": "4.0.1",
17
17
  "glamor": "^2.20.40",
18
18
  "html2canvas": "^1.4.1",