sea-chart 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -1
- package/dist/api/index.js +101 -0
- package/{lib → dist}/components/collaborator/index.js +8 -6
- package/{lib → dist}/components/icon/index.css +1 -1
- package/{lib → dist}/components/icon/index.js +7 -5
- package/dist/components/index.js +8 -0
- package/{lib → dist}/components/loading/index.js +4 -2
- package/dist/components/number-input/index.js +31 -0
- package/{lib → dist}/components/pixel-editor/index.css +4 -4
- package/{lib → dist}/components/pixel-editor/index.js +11 -15
- package/{lib → dist}/components/select-group/index.css +10 -10
- package/dist/components/select-group/index.js +52 -0
- package/dist/components/types-dialog/index.css +97 -0
- package/dist/components/types-dialog/index.js +117 -0
- package/{lib → dist}/constants/geolocation.js +3 -3
- package/dist/constants/index.js +184 -0
- package/{lib → dist}/constants/model.js +25 -5
- package/dist/constants/style.js +15 -0
- package/dist/constants/type-image.js +59 -0
- package/dist/constants/type.js +124 -0
- package/dist/context.js +83 -0
- package/dist/editor/index.js +41 -0
- package/dist/index.js +9 -0
- package/dist/intl.js +37 -0
- package/dist/locale/index.js +18 -0
- package/{lib → dist}/locale/lang/de.js +1 -1
- package/{lib → dist}/locale/lang/en.js +1 -1
- package/{lib → dist}/locale/lang/es.js +1 -1
- package/{lib → dist}/locale/lang/fr.js +1 -1
- package/{lib → dist}/locale/lang/pt.js +1 -1
- package/{lib → dist}/locale/lang/ru.js +1 -1
- package/{lib → dist}/locale/lang/zh_CN.js +1 -1
- package/dist/model/area-group.js +41 -0
- package/dist/model/area.js +32 -0
- package/dist/model/bar-group.js +44 -0
- package/dist/model/bar-stack.js +41 -0
- package/dist/model/bar.js +38 -0
- package/dist/model/base-model.js +9 -0
- package/dist/model/basic-number-card.js +22 -0
- package/dist/model/chart.js +23 -0
- package/dist/model/combination.js +38 -0
- package/dist/model/compare-bar.js +39 -0
- package/dist/model/completeness-group.js +24 -0
- package/dist/model/completeness.js +18 -0
- package/dist/model/dashboard.js +16 -0
- package/dist/model/generic-model.js +224 -0
- package/dist/model/heat-map.js +23 -0
- package/dist/model/horizontal-bar.js +38 -0
- package/dist/model/horizontal-group-bar.js +43 -0
- package/dist/model/index.js +63 -0
- package/dist/model/line-group.js +44 -0
- package/dist/model/line.js +38 -0
- package/dist/model/map-bubble.js +27 -0
- package/dist/model/map.js +27 -0
- package/dist/model/mirror.js +26 -0
- package/dist/model/pie.js +26 -0
- package/dist/model/ring.js +26 -0
- package/dist/model/scatter.js +19 -0
- package/dist/model/stacked-horizontal-bar.js +32 -0
- package/dist/model/table.js +23 -0
- package/dist/model/tree-map.js +20 -0
- package/dist/model/trend.js +24 -0
- package/dist/model/user.js +15 -0
- package/dist/model/world-map-bubble.js +26 -0
- package/dist/model/world-map.js +26 -0
- package/{lib/components → dist}/settings/advance-bar-settings/data-settings.js +68 -45
- package/dist/settings/advance-bar-settings/style-settings.js +161 -0
- package/{lib/components → dist}/settings/bar-settings/data-settings.js +76 -51
- package/dist/settings/bar-settings/style-settings.js +179 -0
- package/dist/settings/basic-number-card/data-settings.js +126 -0
- package/dist/settings/basic-number-card/style-settings.js +42 -0
- package/dist/settings/combination-settings/data-settings.js +279 -0
- package/dist/settings/combination-settings/style-settings.js +174 -0
- package/dist/settings/dashboard-settings/data-settings.js +179 -0
- package/{lib/components → dist}/settings/data-settings.js +28 -22
- package/dist/settings/horizontal-bar-settings/data-settings.js +55 -0
- package/dist/settings/horizontal-bar-settings/style-settings.js +46 -0
- package/dist/settings/index.css +85 -0
- package/dist/settings/index.js +76 -0
- package/{lib/components → dist}/settings/pie-settings/data-settings.js +67 -44
- package/{lib/components → dist}/settings/pie-settings/style-settings.js +67 -49
- package/dist/settings/style-settings.js +118 -0
- package/{lib/components → dist}/settings/table-settings/data-settings.js +269 -208
- package/{lib/components → dist}/settings/time-comparison-settings/data-settings.js +82 -67
- package/dist/settings/time-comparison-settings/style-settings.js +213 -0
- package/dist/settings/widgets/basic-summary/index.css +12 -0
- package/dist/settings/widgets/basic-summary/index.js +176 -0
- package/{lib/components/settings/widgets/statistic-type → dist/settings/widgets/chart-type}/index.css +5 -5
- package/dist/settings/widgets/chart-type/index.js +59 -0
- package/{lib/components → dist}/settings/widgets/common-data-settings.js +24 -18
- package/dist/settings/widgets/data-filter/index.css +17 -0
- package/{lib/components → dist}/settings/widgets/data-filter/index.js +51 -37
- package/dist/settings/widgets/data-sort.js +44 -0
- package/dist/settings/widgets/date-summary-item.js +111 -0
- package/dist/settings/widgets/display-values-settings/index.css +13 -0
- package/{lib/components → dist}/settings/widgets/display-values-settings/index.js +19 -14
- package/{lib/components → dist}/settings/widgets/divider/index.css +1 -1
- package/dist/settings/widgets/divider/index.js +12 -0
- package/{lib/components → dist}/settings/widgets/font-settings/font-size-settings.js +14 -12
- package/{lib/components → dist}/settings/widgets/font-settings/font-weight-settings.js +14 -16
- package/dist/settings/widgets/group-by.js +160 -0
- package/{lib/components → dist}/settings/widgets/label-color.js +10 -10
- package/dist/settings/widgets/min-max-setting.js +52 -0
- package/dist/settings/widgets/mininum-slice-percent.js +63 -0
- package/dist/settings/widgets/numeric-summary-item.js +90 -0
- package/dist/settings/widgets/select-table/index.js +38 -0
- package/dist/settings/widgets/stack.js +50 -0
- package/dist/settings/widgets/summary-method-setting.js +66 -0
- package/dist/settings/widgets/summary-settings.js +411 -0
- package/dist/settings/widgets/switch/index.css +37 -0
- package/{lib/components → dist}/settings/widgets/switch/index.js +11 -8
- package/{lib/components → dist}/settings/widgets/text-horizontal-settings.js +12 -10
- package/dist/settings/widgets/time-picker.js +174 -0
- package/{lib/components → dist}/settings/widgets/title-settings/index.js +15 -13
- package/dist/settings/widgets/title-settings/title-text.js +25 -0
- package/dist/settings/widgets/x-axios.js +0 -0
- package/dist/settings/widgets/y-axis-group-settings.js +438 -0
- package/dist/utils/cell-format-utils.js +42 -0
- package/dist/utils/chart-data-sql.js +606 -0
- package/dist/utils/chart-utils.js +1803 -0
- package/dist/utils/chart.js +6 -0
- package/dist/utils/collaborator-manager.js +24 -0
- package/dist/utils/collaborator-utils.js +40 -0
- package/dist/utils/column-2-sql-column.js +551 -0
- package/dist/utils/column-utils.js +208 -0
- package/{lib → dist}/utils/custom-g2.js +11 -11
- package/{lib → dist}/utils/date-translate.js +11 -11
- package/dist/utils/index.js +48 -0
- package/dist/utils/key-generator.js +13 -0
- package/dist/utils/object-utils.js +45 -0
- package/{lib → dist}/utils/options-utils.js +17 -18
- package/dist/view/index.css +53 -0
- package/dist/view/index.js +169 -0
- package/{lib/layout → dist/view}/title/index.css +1 -1
- package/dist/view/title/index.js +46 -0
- package/dist/view/wrapper/area.js +150 -0
- package/dist/view/wrapper/bar-group.js +148 -0
- package/dist/view/wrapper/bar.js +138 -0
- package/dist/view/wrapper/basic-number-card.js +127 -0
- package/dist/view/wrapper/chart-component.js +261 -0
- package/dist/view/wrapper/combination.js +399 -0
- package/dist/view/wrapper/dashboard.js +164 -0
- package/dist/view/wrapper/horizontal-bar-group.js +149 -0
- package/dist/view/wrapper/horizontal-bar.js +140 -0
- package/dist/view/wrapper/horizontal-component.js +78 -0
- package/{lib/components/formatter → dist/view/wrapper}/index.js +90 -71
- package/dist/view/wrapper/line-group.js +145 -0
- package/dist/view/wrapper/line.js +157 -0
- package/dist/view/wrapper/pie.js +185 -0
- package/dist/view/wrapper/ring.js +264 -0
- package/{lib/components/formatter → dist/view/wrapper}/table/index.css +18 -18
- package/dist/view/wrapper/table/index.js +31 -0
- package/dist/view/wrapper/table/one-dimension-table-no-numeric-columns.js +144 -0
- package/dist/view/wrapper/table/one-dimension-table-with-numeric-columns.js +198 -0
- package/dist/view/wrapper/table/pivot-table-display-name.js +248 -0
- package/dist/view/wrapper/table/two-dimension-table.js +249 -0
- package/dist/view/wrapper/treemap.js +186 -0
- package/package.json +91 -100
- package/lib/components/formatter/area.js +0 -162
- package/lib/components/formatter/bar-group.js +0 -160
- package/lib/components/formatter/bar.js +0 -150
- package/lib/components/formatter/basic-number-card.js +0 -138
- package/lib/components/formatter/chart-component.js +0 -266
- package/lib/components/formatter/combination.js +0 -407
- package/lib/components/formatter/dashboard.js +0 -182
- package/lib/components/formatter/horizontal-bar-group.js +0 -161
- package/lib/components/formatter/horizontal-bar.js +0 -152
- package/lib/components/formatter/horizontal-component.js +0 -91
- package/lib/components/formatter/line-group.js +0 -157
- package/lib/components/formatter/line.js +0 -170
- package/lib/components/formatter/pie.js +0 -201
- package/lib/components/formatter/ring.js +0 -277
- package/lib/components/formatter/table/index.js +0 -42
- package/lib/components/formatter/table/one-dimension-table-no-numeric-columns.js +0 -145
- package/lib/components/formatter/table/one-dimension-table-with-numeric-columns.js +0 -193
- package/lib/components/formatter/table/pivot-table-display-name.js +0 -249
- package/lib/components/formatter/table/two-dimension-table.js +0 -241
- package/lib/components/formatter/treemap.js +0 -213
- package/lib/components/index.js +0 -5
- package/lib/components/number-input/index.js +0 -31
- package/lib/components/select-group/index.js +0 -63
- package/lib/components/settings/advance-bar-settings/style-settings.js +0 -149
- package/lib/components/settings/bar-settings/style-settings.js +0 -163
- package/lib/components/settings/basic-number-card/data-settings.js +0 -121
- package/lib/components/settings/basic-number-card/style-settings.js +0 -42
- package/lib/components/settings/combination-settings/data-settings.js +0 -256
- package/lib/components/settings/combination-settings/style-settings.js +0 -183
- package/lib/components/settings/dashboard-settings/data-settings.js +0 -167
- package/lib/components/settings/horizontal-bar-settings/data-settings.js +0 -45
- package/lib/components/settings/horizontal-bar-settings/style-settings.js +0 -38
- package/lib/components/settings/index.css +0 -73
- package/lib/components/settings/index.js +0 -74
- package/lib/components/settings/style-settings.js +0 -100
- package/lib/components/settings/time-comparison-settings/style-settings.js +0 -191
- package/lib/components/settings/widgets/basic-summary/index.css +0 -12
- package/lib/components/settings/widgets/basic-summary/index.js +0 -173
- package/lib/components/settings/widgets/data-filter/index.css +0 -17
- package/lib/components/settings/widgets/data-sort.js +0 -38
- package/lib/components/settings/widgets/date-summary-item.js +0 -126
- package/lib/components/settings/widgets/display-values-settings/index.css +0 -13
- package/lib/components/settings/widgets/divider/index.js +0 -10
- package/lib/components/settings/widgets/group-by.js +0 -168
- package/lib/components/settings/widgets/min-max-setting.js +0 -64
- package/lib/components/settings/widgets/mininum-slice-percent.js +0 -72
- package/lib/components/settings/widgets/numeric-summary-item.js +0 -109
- package/lib/components/settings/widgets/select-table/index.js +0 -49
- package/lib/components/settings/widgets/stack.js +0 -58
- package/lib/components/settings/widgets/statistic-type/index.js +0 -54
- package/lib/components/settings/widgets/summary-method-setting.js +0 -80
- package/lib/components/settings/widgets/summary-settings.js +0 -394
- package/lib/components/settings/widgets/switch/index.css +0 -37
- package/lib/components/settings/widgets/time-picker.js +0 -182
- package/lib/components/settings/widgets/title-settings/title-text.js +0 -31
- package/lib/components/settings/widgets/y-axis-group-settings.js +0 -399
- package/lib/components/types-dialog/index.css +0 -97
- package/lib/components/types-dialog/index.js +0 -127
- package/lib/constants/index.js +0 -164
- package/lib/constants/style.js +0 -13
- package/lib/constants/type-image.js +0 -32
- package/lib/constants/type.js +0 -97
- package/lib/context.js +0 -49
- package/lib/index.js +0 -6
- package/lib/intl.js +0 -37
- package/lib/layout/index.js +0 -4
- package/lib/layout/statistic/index.css +0 -53
- package/lib/layout/statistic/index.js +0 -190
- package/lib/layout/title/index.js +0 -41
- package/lib/locale/index.js +0 -11
- package/lib/model/area-group.js +0 -51
- package/lib/model/area.js +0 -42
- package/lib/model/bar-group.js +0 -54
- package/lib/model/bar-stack.js +0 -51
- package/lib/model/bar.js +0 -48
- package/lib/model/base-model.js +0 -11
- package/lib/model/basic-number-card.js +0 -32
- package/lib/model/combination.js +0 -48
- package/lib/model/compare-bar.js +0 -49
- package/lib/model/completeness-group.js +0 -34
- package/lib/model/completeness.js +0 -28
- package/lib/model/dashboard.js +0 -26
- package/lib/model/generic-model.js +0 -235
- package/lib/model/heat-map.js +0 -33
- package/lib/model/horizontal-bar.js +0 -48
- package/lib/model/horizontal-group-bar.js +0 -53
- package/lib/model/index.js +0 -36
- package/lib/model/line-group.js +0 -54
- package/lib/model/line.js +0 -48
- package/lib/model/map-bubble.js +0 -37
- package/lib/model/map.js +0 -37
- package/lib/model/mirror.js +0 -36
- package/lib/model/pie.js +0 -36
- package/lib/model/ring.js +0 -36
- package/lib/model/scatter.js +0 -29
- package/lib/model/stacked-horizontal-bar.js +0 -42
- package/lib/model/statistic.js +0 -22
- package/lib/model/table.js +0 -33
- package/lib/model/tree-map.js +0 -30
- package/lib/model/trend.js +0 -34
- package/lib/model/user.js +0 -22
- package/lib/model/world-map-bubble.js +0 -36
- package/lib/model/world-map.js +0 -36
- package/lib/utils/cell-format-utils.js +0 -41
- package/lib/utils/chart.js +0 -6
- package/lib/utils/collaborator-utils.js +0 -40
- package/lib/utils/column-utils.js +0 -247
- package/lib/utils/data-filter/filter-item-utils.js +0 -80
- package/lib/utils/data-filter/filters-utils.js +0 -406
- package/lib/utils/data-filter/index.js +0 -3
- package/lib/utils/index.js +0 -50
- package/lib/utils/key-generator.js +0 -13
- package/lib/utils/object-utils.js +0 -61
- package/lib/utils/statistic-column-2-sql-column-utils.js +0 -499
- package/lib/utils/statistic-utils.js +0 -1685
- /package/{lib → dist}/assets/icons/area-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/bar-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/card.svg +0 -0
- /package/{lib → dist}/assets/icons/combination-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/dtable-logo.svg +0 -0
- /package/{lib → dist}/assets/icons/facet-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/gauge.svg +0 -0
- /package/{lib → dist}/assets/icons/heat-map.svg +0 -0
- /package/{lib → dist}/assets/icons/histogram.svg +0 -0
- /package/{lib → dist}/assets/icons/line-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/map.svg +0 -0
- /package/{lib → dist}/assets/icons/pie-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/rectangular-tree-diagram.svg +0 -0
- /package/{lib → dist}/assets/icons/scatter-chart.svg +0 -0
- /package/{lib → dist}/assets/icons/type-change.svg +0 -0
- /package/{lib → dist}/assets/img/area-chart.png +0 -0
- /package/{lib → dist}/assets/img/area-group-chart.png +0 -0
- /package/{lib → dist}/assets/img/bar-group.png +0 -0
- /package/{lib → dist}/assets/img/bar-stack.png +0 -0
- /package/{lib → dist}/assets/img/bar.png +0 -0
- /package/{lib → dist}/assets/img/combination-chart.png +0 -0
- /package/{lib → dist}/assets/img/compared-chart.png +0 -0
- /package/{lib → dist}/assets/img/completeness-chart.png +0 -0
- /package/{lib → dist}/assets/img/custom-bar.png +0 -0
- /package/{lib → dist}/assets/img/dashboard-chart.png +0 -0
- /package/{lib → dist}/assets/img/group-completeness-chart.png +0 -0
- /package/{lib → dist}/assets/img/group_line.png +0 -0
- /package/{lib → dist}/assets/img/heat-map.png +0 -0
- /package/{lib → dist}/assets/img/horizontal-bar.png +0 -0
- /package/{lib → dist}/assets/img/horizontal-group-bar.png +0 -0
- /package/{lib → dist}/assets/img/line.png +0 -0
- /package/{lib → dist}/assets/img/map-bubble.png +0 -0
- /package/{lib → dist}/assets/img/map.png +0 -0
- /package/{lib → dist}/assets/img/mirror.png +0 -0
- /package/{lib → dist}/assets/img/number-card.png +0 -0
- /package/{lib → dist}/assets/img/pie.png +0 -0
- /package/{lib → dist}/assets/img/pivot-table.png +0 -0
- /package/{lib → dist}/assets/img/ring.png +0 -0
- /package/{lib → dist}/assets/img/scatter.png +0 -0
- /package/{lib → dist}/assets/img/stacked-horizontal-bar.png +0 -0
- /package/{lib → dist}/assets/img/treemap.png +0 -0
- /package/{lib → dist}/assets/img/trend-chart.png +0 -0
- /package/{lib → dist}/assets/img/world-map-bubble.png +0 -0
- /package/{lib → dist}/assets/img/world-map.png +0 -0
- /package/{lib → dist}/components/loading/index.css +0 -0
- /package/{lib/components/settings/widgets/select-table → dist/editor}/index.css +0 -0
- /package/{lib/components → dist}/settings/advance-bar-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/bar-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/basic-number-card/index.js +0 -0
- /package/{lib/components → dist}/settings/combination-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/dashboard-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/horizontal-bar-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/pie-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/table-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/time-comparison-settings/index.js +0 -0
- /package/{lib/components → dist}/settings/widgets/font-settings/index.js +0 -0
- /package/{lib/components/settings/widgets/x-axios.js → dist/settings/widgets/select-table/index.css} +0 -0
|
@@ -0,0 +1,1803 @@
|
|
|
1
|
+
var _class;
|
|
2
|
+
import shallowEqual from 'shallowequal';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getDateDisplayString, getFormulaDisplayString, getNumberDisplayString, getOption, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber, isNumericColumn, isDateColumn, sortText, sortNumber, sortDate, sortSingleSelect, sortFormula, getColumnOptions } from 'dtable-utils';
|
|
5
|
+
import { PIE_CHART_COLORS, CHART_SUMMARY_TYPE, CHART_SUPPORT_SORT_COLUMNS, CHART_TYPE, CHART_STYLE_SETTING_KEYS, DEFAULT_LABEL_FONT_SIZE, DEFAULT_NUMBER_FORMAT_OBJECT, SUPPORT_DATA_SORT_CHART_TYPES, X_AXIS_IS_GROUPBY_COLUMN_KEY_CHART_TYPES, STYLE_COLORS, LABEL_COLORS } from '../constants';
|
|
6
|
+
import chartColumn2SqlColumn, { summaryMethodColumn2SqlColumn } from './column-2-sql-column';
|
|
7
|
+
import { getClientFormulaDisplayString, getClientLinkDisplayString } from './cell-format-utils';
|
|
8
|
+
import { getKnownCollaboratorByEmail, generateDefaultUser } from './collaborator-utils';
|
|
9
|
+
import { getDateColumnFormat, getColumnByKey } from './column-utils';
|
|
10
|
+
import ObjectUtils from './object-utils';
|
|
11
|
+
import intl from '../intl';
|
|
12
|
+
import context from '../context';
|
|
13
|
+
class ChartUtils {
|
|
14
|
+
static formatGroupsLabel(results, chart, tables) {
|
|
15
|
+
if (!results) return;
|
|
16
|
+
let groupby_column_key, column_groupby_column_key;
|
|
17
|
+
const {
|
|
18
|
+
type,
|
|
19
|
+
config
|
|
20
|
+
} = chart;
|
|
21
|
+
if (X_AXIS_IS_GROUPBY_COLUMN_KEY_CHART_TYPES.includes(type)) {
|
|
22
|
+
groupby_column_key = config.groupby_column_key;
|
|
23
|
+
} else {
|
|
24
|
+
groupby_column_key = config.x_axis_column_key;
|
|
25
|
+
column_groupby_column_key = config.column_groupby_column_key;
|
|
26
|
+
}
|
|
27
|
+
const {
|
|
28
|
+
table_id
|
|
29
|
+
} = config;
|
|
30
|
+
const table = getTableById(tables, table_id);
|
|
31
|
+
const groupbyColumn = getTableColumnByKey(table, groupby_column_key);
|
|
32
|
+
const columnGroupbyColumn = getTableColumnByKey(table, column_groupby_column_key);
|
|
33
|
+
results.forEach(item => {
|
|
34
|
+
const {
|
|
35
|
+
name,
|
|
36
|
+
group_name
|
|
37
|
+
} = item;
|
|
38
|
+
if (groupbyColumn) {
|
|
39
|
+
this.convertResultName(item, groupbyColumn, name, 'name', 'color');
|
|
40
|
+
}
|
|
41
|
+
if (columnGroupbyColumn) {
|
|
42
|
+
this.convertResultName(item, columnGroupbyColumn, group_name, 'group_name', 'group_color');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static convertResultName(result, column, name, nameKey, colorKey) {
|
|
47
|
+
const {
|
|
48
|
+
type: columnType,
|
|
49
|
+
data: columnData
|
|
50
|
+
} = column;
|
|
51
|
+
if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
|
|
52
|
+
const options = getColumnOptions(column);
|
|
53
|
+
const selectedOption = getOption(options, name);
|
|
54
|
+
if (selectedOption) {
|
|
55
|
+
result[nameKey] = selectedOption.name;
|
|
56
|
+
result[colorKey] = selectedOption.color;
|
|
57
|
+
} else {
|
|
58
|
+
result[colorKey] = '#dbdbdb';
|
|
59
|
+
}
|
|
60
|
+
} else if (columnType === CellType.COLLABORATOR) {
|
|
61
|
+
let collaborator = getKnownCollaboratorByEmail(name);
|
|
62
|
+
if (collaborator) {
|
|
63
|
+
result[nameKey] = collaborator.name;
|
|
64
|
+
}
|
|
65
|
+
} else if (columnType === CellType.CREATOR || columnType === CellType.LAST_MODIFIER) {
|
|
66
|
+
if (name === 'anonymous') {
|
|
67
|
+
result[nameKey] = name;
|
|
68
|
+
} else {
|
|
69
|
+
const collaborator = getKnownCollaboratorByEmail(name);
|
|
70
|
+
const collaboratorTemplate = {
|
|
71
|
+
loaded: false,
|
|
72
|
+
email: name,
|
|
73
|
+
name: name
|
|
74
|
+
};
|
|
75
|
+
context.updateCollaboratorsCache(name, collaboratorTemplate);
|
|
76
|
+
if (!collaborator) {
|
|
77
|
+
context.queryUsers([name], emailUserMap => {
|
|
78
|
+
const collaborator = emailUserMap && emailUserMap[name] || generateDefaultUser(name);
|
|
79
|
+
const loadedCollaborator = {
|
|
80
|
+
...collaborator,
|
|
81
|
+
loaded: true
|
|
82
|
+
};
|
|
83
|
+
context.updateCollaboratorsCache(name, loadedCollaborator);
|
|
84
|
+
result[nameKey] = name;
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
result[nameKey] = collaborator.name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else if (columnType === CellType.NUMBER) {
|
|
91
|
+
const valueNumber = parseFloat(name);
|
|
92
|
+
result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
|
|
93
|
+
} else if (columnType === CellType.DATE) {
|
|
94
|
+
if (name && name.split('-').length === 3) {
|
|
95
|
+
let format = getDateColumnFormat(column);
|
|
96
|
+
const spaceIndex = format.indexOf(' ');
|
|
97
|
+
if (spaceIndex > -1) {
|
|
98
|
+
format = format.slice(0, spaceIndex);
|
|
99
|
+
}
|
|
100
|
+
result[nameKey] = dayjs(name).format(format);
|
|
101
|
+
}
|
|
102
|
+
} else if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
|
|
103
|
+
const {
|
|
104
|
+
result_type,
|
|
105
|
+
array_type
|
|
106
|
+
} = columnData || {};
|
|
107
|
+
if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
|
|
108
|
+
const valueNumber = parseFloat(name);
|
|
109
|
+
result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
|
|
110
|
+
} else if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
111
|
+
if (COLLABORATOR_COLUMN_TYPES.includes(array_type) && Array.isArray(name)) {
|
|
112
|
+
result[nameKey] = name.map(email => {
|
|
113
|
+
let user = array_type === CellType.COLLABORATOR ? getKnownCollaboratorByEmail(email) : getKnownCollaboratorByEmail(email);
|
|
114
|
+
return (user || {}).name;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else if (columnType === CellType.LINK) {
|
|
119
|
+
result[nameKey] = getClientFormulaDisplayString([name], columnData) || null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
static shouldChartComponentUpdate(prevProps, currentProps) {
|
|
123
|
+
return !this.isChartEqual(prevProps.chart, currentProps.chart) ||
|
|
124
|
+
// chart attributes changed
|
|
125
|
+
!shallowEqual(prevProps.canvasStyle, currentProps.canvasStyle) ||
|
|
126
|
+
// canvasStyle
|
|
127
|
+
!shallowEqual(prevProps.groupbyColumn, currentProps.groupbyColumn) ||
|
|
128
|
+
// groupbyColumn's data、type changed or not exist
|
|
129
|
+
!shallowEqual(prevProps.columnGroupbyColumn, currentProps.columnGroupbyColumn) ||
|
|
130
|
+
// columnGroupbyColumn's data、type changed or not exist
|
|
131
|
+
!shallowEqual(prevProps.summaryColumn, currentProps.summaryColumn) ||
|
|
132
|
+
// summaryColumn's data、type changed or not exist
|
|
133
|
+
this._isChartDataChange(prevProps, currentProps) || this.isChartStyleChanged(prevProps.chart, currentProps.chart);
|
|
134
|
+
}
|
|
135
|
+
static _isCombinationDataChange(prevResult, currentResult) {
|
|
136
|
+
if (prevResult.value_left !== currentResult.value_left) return true;
|
|
137
|
+
if (prevResult.value_right !== currentResult.value_right) return true;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
_class = ChartUtils;
|
|
142
|
+
ChartUtils.sortCharts = (charts, column, sortKey) => {
|
|
143
|
+
const {
|
|
144
|
+
type: columnType,
|
|
145
|
+
data
|
|
146
|
+
} = column;
|
|
147
|
+
const sortType = 'up';
|
|
148
|
+
const optionIdIndexMap = {};
|
|
149
|
+
if (columnType === CellType.SINGLE_SELECT) {
|
|
150
|
+
const {
|
|
151
|
+
options
|
|
152
|
+
} = data || {};
|
|
153
|
+
Array.isArray(options) && options.forEach((option, index) => {
|
|
154
|
+
optionIdIndexMap[option.id] = index;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
charts.sort((currResult, nextResult) => {
|
|
158
|
+
let {
|
|
159
|
+
[sortKey]: current
|
|
160
|
+
} = currResult;
|
|
161
|
+
let {
|
|
162
|
+
[sortKey]: next
|
|
163
|
+
} = nextResult;
|
|
164
|
+
if (!current && current !== 0) {
|
|
165
|
+
return -1;
|
|
166
|
+
}
|
|
167
|
+
if (!next && next !== 0) {
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
if (CHART_SUPPORT_SORT_COLUMNS.includes(columnType)) {
|
|
171
|
+
switch (columnType) {
|
|
172
|
+
case CellType.NUMBER:
|
|
173
|
+
case CellType.RATE:
|
|
174
|
+
{
|
|
175
|
+
if (current) {
|
|
176
|
+
current = current - 0;
|
|
177
|
+
}
|
|
178
|
+
if (next) {
|
|
179
|
+
next = next - 0;
|
|
180
|
+
}
|
|
181
|
+
return sortNumber(current, next, sortType);
|
|
182
|
+
}
|
|
183
|
+
case CellType.DATE:
|
|
184
|
+
case CellType.CTIME:
|
|
185
|
+
case CellType.MTIME:
|
|
186
|
+
{
|
|
187
|
+
return sortDate(current, next, sortType);
|
|
188
|
+
}
|
|
189
|
+
case CellType.SINGLE_SELECT:
|
|
190
|
+
case CellType.MULTIPLE_SELECT:
|
|
191
|
+
{
|
|
192
|
+
return sortSingleSelect(current, next, {
|
|
193
|
+
sort_type: sortType,
|
|
194
|
+
option_id_index_map: optionIdIndexMap
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
case CellType.FORMULA:
|
|
198
|
+
case CellType.LINK_FORMULA:
|
|
199
|
+
{
|
|
200
|
+
return sortFormula(current, next, sortType, {
|
|
201
|
+
columnData: data,
|
|
202
|
+
value: {}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
default:
|
|
206
|
+
{
|
|
207
|
+
return sortText(current, next, sortType);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return 0;
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
ChartUtils.sortChartData = (charts, sort_key) => {
|
|
215
|
+
charts.sort((currResult, nextResult) => {
|
|
216
|
+
const {
|
|
217
|
+
value: current
|
|
218
|
+
} = currResult;
|
|
219
|
+
const {
|
|
220
|
+
value: next
|
|
221
|
+
} = nextResult;
|
|
222
|
+
if (!current && current !== 0) return -1;
|
|
223
|
+
if (!next && next !== 0) return 1;
|
|
224
|
+
if (sort_key === 'ascending') {
|
|
225
|
+
return current > next ? 1 : -1;
|
|
226
|
+
}
|
|
227
|
+
return current > next ? -1 : 1;
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
ChartUtils.sortByDate = (currentDate, nextDate) => {
|
|
231
|
+
if (currentDate.name === 'undefined') return -1;
|
|
232
|
+
if (nextDate.name === 'undefined') return 1;
|
|
233
|
+
if (currentDate.name > nextDate.name) return 1;
|
|
234
|
+
if (currentDate.name < nextDate.name) return -1;
|
|
235
|
+
return 0;
|
|
236
|
+
};
|
|
237
|
+
ChartUtils.moveNullDataToEnd = arr => {
|
|
238
|
+
let nullData;
|
|
239
|
+
const nullDataIndex = arr.findIndex(item => {
|
|
240
|
+
return item.name === 'undefined';
|
|
241
|
+
});
|
|
242
|
+
if (nullDataIndex > -1) {
|
|
243
|
+
nullData = arr.splice(nullDataIndex, 1);
|
|
244
|
+
arr.push(...nullData);
|
|
245
|
+
}
|
|
246
|
+
return arr;
|
|
247
|
+
};
|
|
248
|
+
ChartUtils.getGroupColumn = (table, chart) => {
|
|
249
|
+
const {
|
|
250
|
+
config
|
|
251
|
+
} = chart;
|
|
252
|
+
const {
|
|
253
|
+
type
|
|
254
|
+
} = config;
|
|
255
|
+
if (X_AXIS_IS_GROUPBY_COLUMN_KEY_CHART_TYPES.includes(type)) {
|
|
256
|
+
return getTableColumnByKey(table, config.groupby_column_key);
|
|
257
|
+
}
|
|
258
|
+
if (type === CHART_TYPE.BASIC_NUMBER_CARD) {
|
|
259
|
+
return getTableColumnByKey(table, config.numeric_column_key);
|
|
260
|
+
}
|
|
261
|
+
return getTableColumnByKey(table, config.x_axis_column_key);
|
|
262
|
+
};
|
|
263
|
+
ChartUtils.getColumnGroupColumn = (table, chart) => {
|
|
264
|
+
const {
|
|
265
|
+
config
|
|
266
|
+
} = chart;
|
|
267
|
+
const {
|
|
268
|
+
type
|
|
269
|
+
} = config;
|
|
270
|
+
if (X_AXIS_IS_GROUPBY_COLUMN_KEY_CHART_TYPES.includes(type)) {
|
|
271
|
+
return getTableColumnByKey(table, config.column_groupby_column_key);
|
|
272
|
+
}
|
|
273
|
+
if ([CHART_TYPE.BAR_GROUP, CHART_TYPE.LINE_GROUP, CHART_TYPE.HORIZONTAL_GROUP_BAR].includes(type)) {
|
|
274
|
+
return getTableColumnByKey(table, config.column_groupby_column_key);
|
|
275
|
+
}
|
|
276
|
+
return getTableColumnByKey(table, config.y_axis_summary_column_key);
|
|
277
|
+
};
|
|
278
|
+
ChartUtils.getSummaryColumn = (table, chart) => {
|
|
279
|
+
const {
|
|
280
|
+
config
|
|
281
|
+
} = chart;
|
|
282
|
+
const {
|
|
283
|
+
summary_column_key,
|
|
284
|
+
y_axis_summary_column_key,
|
|
285
|
+
type,
|
|
286
|
+
numeric_column_key
|
|
287
|
+
} = config;
|
|
288
|
+
switch (type) {
|
|
289
|
+
case CHART_TYPE.BAR:
|
|
290
|
+
case CHART_TYPE.BAR_GROUP:
|
|
291
|
+
case CHART_TYPE.LINE:
|
|
292
|
+
case CHART_TYPE.LINE_GROUP:
|
|
293
|
+
case CHART_TYPE.AREA:
|
|
294
|
+
case CHART_TYPE.HORIZONTAL_BAR:
|
|
295
|
+
case CHART_TYPE.HORIZONTAL_GROUP_BAR:
|
|
296
|
+
{
|
|
297
|
+
return getTableColumnByKey(table, y_axis_summary_column_key);
|
|
298
|
+
}
|
|
299
|
+
case CHART_TYPE.BASIC_NUMBER_CARD:
|
|
300
|
+
{
|
|
301
|
+
return getTableColumnByKey(table, numeric_column_key);
|
|
302
|
+
}
|
|
303
|
+
default:
|
|
304
|
+
{
|
|
305
|
+
return getTableColumnByKey(table, summary_column_key);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
ChartUtils.getGroupName = (tables, chart) => {
|
|
310
|
+
const {
|
|
311
|
+
config
|
|
312
|
+
} = chart;
|
|
313
|
+
const table = getTableById(tables, config.table_id);
|
|
314
|
+
const column = _class.getGroupColumn(table, chart);
|
|
315
|
+
return column.name;
|
|
316
|
+
};
|
|
317
|
+
ChartUtils.getChartGroups = charts => {
|
|
318
|
+
let chartGroups = [];
|
|
319
|
+
Array.isArray(charts) && charts.forEach(item => {
|
|
320
|
+
if (!chartGroups.find(g => g.name === item.name)) {
|
|
321
|
+
chartGroups.push(item);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
return chartGroups;
|
|
325
|
+
};
|
|
326
|
+
ChartUtils.isValidExistChart = (tables, chart) => {
|
|
327
|
+
if (!chart) return false;
|
|
328
|
+
const {
|
|
329
|
+
config
|
|
330
|
+
} = chart;
|
|
331
|
+
const {
|
|
332
|
+
table_id,
|
|
333
|
+
type
|
|
334
|
+
} = config;
|
|
335
|
+
const table = getTableById(tables, table_id);
|
|
336
|
+
if (!table) return false;
|
|
337
|
+
if (config.type === CHART_TYPE.BASIC_NUMBER_CARD) {
|
|
338
|
+
const numericColumnKey = config.numeric_column_key;
|
|
339
|
+
if (!numericColumnKey) return false;
|
|
340
|
+
return getTableColumnByKey(table, numericColumnKey);
|
|
341
|
+
}
|
|
342
|
+
if (config.type === CHART_TYPE.DASHBOARD) {
|
|
343
|
+
const targetColumnKey = config.target_value_column_key;
|
|
344
|
+
if (!targetColumnKey) return false;
|
|
345
|
+
const totalColumnKey = config.total_value_column_key;
|
|
346
|
+
if (!totalColumnKey) return false;
|
|
347
|
+
if (!getTableColumnByKey(table, targetColumnKey)) return false;
|
|
348
|
+
return getTableColumnByKey(table, totalColumnKey);
|
|
349
|
+
}
|
|
350
|
+
const groupByColumnKey = config.groupby_column_key || config.x_axis_column_key || config.vertical_axis_column_key;
|
|
351
|
+
if (!groupByColumnKey) return false;
|
|
352
|
+
if (!getTableColumnByKey(table, groupByColumnKey)) return false;
|
|
353
|
+
if (type === CHART_TYPE.COMBINATION) {
|
|
354
|
+
const isExist = _class.isValidCombinationChart(config, table);
|
|
355
|
+
if (!isExist) return false;
|
|
356
|
+
} else {
|
|
357
|
+
const summaryColumnKey = config.summary_column_key || config.y_axis_summary_column_key || config.horizontal_axis_column_key;
|
|
358
|
+
const summaryType = config.summary_type || config.y_axis_summary_type || config.horizontal_axis_summary_type;
|
|
359
|
+
if (summaryType === CHART_SUMMARY_TYPE.ADVANCED && !summaryColumnKey) return false;
|
|
360
|
+
if (summaryColumnKey) {
|
|
361
|
+
return getTableColumnByKey(table, summaryColumnKey);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
};
|
|
366
|
+
ChartUtils.isValidCombinationChart = (config, table) => {
|
|
367
|
+
const summaryLeftColumnKey = config.y_axis_left_summary_column;
|
|
368
|
+
const summaryLeftType = config.y_axis_left_summary_type;
|
|
369
|
+
if (summaryLeftType === CHART_SUMMARY_TYPE.ADVANCED && !summaryLeftColumnKey) return false;
|
|
370
|
+
if (summaryLeftColumnKey) {
|
|
371
|
+
if (!getTableColumnByKey(table, summaryLeftColumnKey)) return false;
|
|
372
|
+
}
|
|
373
|
+
const summaryRightColumnKey = config.y_axis_right_summary_column;
|
|
374
|
+
const summaryRightType = config.y_axis_right_summary_type;
|
|
375
|
+
if (summaryRightType === CHART_SUMMARY_TYPE.ADVANCED && !summaryRightColumnKey) return false;
|
|
376
|
+
if (summaryRightColumnKey) {
|
|
377
|
+
return getTableColumnByKey(table, summaryRightColumnKey);
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
};
|
|
381
|
+
ChartUtils.getGroupLabelFromDB = (cellValue, column, tables) => {
|
|
382
|
+
const collaborators = context.getCollaboratorsFromCache();
|
|
383
|
+
const {
|
|
384
|
+
type,
|
|
385
|
+
data
|
|
386
|
+
} = column;
|
|
387
|
+
switch (type) {
|
|
388
|
+
case CellType.TEXT:
|
|
389
|
+
case CellType.DATE:
|
|
390
|
+
case CellType.CTIME:
|
|
391
|
+
case CellType.MTIME:
|
|
392
|
+
{
|
|
393
|
+
return cellValue || null;
|
|
394
|
+
}
|
|
395
|
+
case CellType.NUMBER:
|
|
396
|
+
{
|
|
397
|
+
if (!cellValue && cellValue !== 0) return null;
|
|
398
|
+
return getPrecisionNumber(cellValue, data);
|
|
399
|
+
}
|
|
400
|
+
case CellType.SINGLE_SELECT:
|
|
401
|
+
{
|
|
402
|
+
let isInvalidValue = data && data.options && data.options.findIndex(opt => opt.id === cellValue) < 0;
|
|
403
|
+
return isInvalidValue ? null : cellValue;
|
|
404
|
+
}
|
|
405
|
+
case CellType.MULTIPLE_SELECT:
|
|
406
|
+
{
|
|
407
|
+
let options = data && data.options;
|
|
408
|
+
if (!Array.isArray(options) || options.length === 0) return [];
|
|
409
|
+
if (!Array.isArray(cellValue) || cellValue.length === 0) return [];
|
|
410
|
+
return cellValue.filter(optionId => options.find(option => option.id === optionId));
|
|
411
|
+
}
|
|
412
|
+
case CellType.COLLABORATOR:
|
|
413
|
+
{
|
|
414
|
+
if (!Array.isArray(collaborators) || collaborators.length === 0) return [];
|
|
415
|
+
if (!Array.isArray(cellValue) || cellValue.length === 0) return [];
|
|
416
|
+
return cellValue.filter(email => collaborators.find(option => option.email === email));
|
|
417
|
+
}
|
|
418
|
+
case CellType.CREATOR:
|
|
419
|
+
case CellType.LAST_MODIFIER:
|
|
420
|
+
{
|
|
421
|
+
return cellValue ? cellValue : null;
|
|
422
|
+
}
|
|
423
|
+
case CellType.GEOLOCATION:
|
|
424
|
+
{
|
|
425
|
+
return cellValue || null;
|
|
426
|
+
}
|
|
427
|
+
case CellType.FORMULA:
|
|
428
|
+
case CellType.LINK_FORMULA:
|
|
429
|
+
{
|
|
430
|
+
const validValue = getFormulaDisplayString(cellValue, data, {
|
|
431
|
+
tables
|
|
432
|
+
});
|
|
433
|
+
if (!validValue && validValue !== 0) return null;
|
|
434
|
+
return validValue;
|
|
435
|
+
}
|
|
436
|
+
case CellType.LINK:
|
|
437
|
+
{
|
|
438
|
+
return Array.isArray(cellValue) ? cellValue.map(linked => getClientLinkDisplayString([linked], data, {})) : [];
|
|
439
|
+
}
|
|
440
|
+
case CellType.CHECKBOX:
|
|
441
|
+
{
|
|
442
|
+
return String(cellValue) === 'true' ? 'Checked' : 'Unchecked';
|
|
443
|
+
}
|
|
444
|
+
case CellType.RATE:
|
|
445
|
+
{
|
|
446
|
+
return cellValue ? String(cellValue) : null;
|
|
447
|
+
}
|
|
448
|
+
default:
|
|
449
|
+
{
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
ChartUtils.oneDimensionTableSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
455
|
+
const {
|
|
456
|
+
groupbyColumn
|
|
457
|
+
} = columnMap;
|
|
458
|
+
const {
|
|
459
|
+
summary_type
|
|
460
|
+
} = chart.config;
|
|
461
|
+
let pivot_columns = [];
|
|
462
|
+
let pivot_rows = [];
|
|
463
|
+
const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
|
|
464
|
+
if (isCount) {
|
|
465
|
+
const {
|
|
466
|
+
sqlGroupbyColumnKey,
|
|
467
|
+
sqlSummaryColumnKey
|
|
468
|
+
} = chartSQLMap;
|
|
469
|
+
let allTotal = 0;
|
|
470
|
+
sqlRows.forEach(row => {
|
|
471
|
+
const total = row[sqlSummaryColumnKey] || 0;
|
|
472
|
+
allTotal += total;
|
|
473
|
+
pivot_rows.push({
|
|
474
|
+
name: _class.getGroupLabelFromDB(row[sqlGroupbyColumnKey], groupbyColumn, tables),
|
|
475
|
+
rows: [],
|
|
476
|
+
total: {
|
|
477
|
+
total
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
return {
|
|
482
|
+
pivot_columns,
|
|
483
|
+
pivot_rows: pivot_rows,
|
|
484
|
+
pivot_columns_total: {
|
|
485
|
+
total: allTotal
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const {
|
|
490
|
+
sqlGroupbyColumnKey,
|
|
491
|
+
summarySQLColumnName2ColumnKey,
|
|
492
|
+
summaryTableColumnKey2Column,
|
|
493
|
+
summaryTableColumnKey2Method
|
|
494
|
+
} = chartSQLMap;
|
|
495
|
+
const summaryColumnKeys = Object.values(summarySQLColumnName2ColumnKey);
|
|
496
|
+
const sqlSummaryColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
|
|
497
|
+
let totalTemplate = {};
|
|
498
|
+
Object.values(summaryColumnKeys).forEach(key => {
|
|
499
|
+
const summaryMethod = summaryTableColumnKey2Method[key];
|
|
500
|
+
totalTemplate[key] = _class.initTotal(summaryMethod);
|
|
501
|
+
pivot_columns.push({
|
|
502
|
+
key
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
let allTotal = {
|
|
506
|
+
...totalTemplate
|
|
507
|
+
};
|
|
508
|
+
sqlRows.forEach(row => {
|
|
509
|
+
let rowTotal = {
|
|
510
|
+
...totalTemplate
|
|
511
|
+
};
|
|
512
|
+
sqlSummaryColumnKeys.forEach(key => {
|
|
513
|
+
let columnKey = summarySQLColumnName2ColumnKey[key];
|
|
514
|
+
let summaryColumn = summaryTableColumnKey2Column[columnKey];
|
|
515
|
+
const summaryMethod = summaryTableColumnKey2Method[columnKey];
|
|
516
|
+
let value = row[key] || _class.initTotal(summaryMethod);
|
|
517
|
+
allTotal[columnKey] = _class.getSummaryValue({
|
|
518
|
+
summaryColumn,
|
|
519
|
+
summaryMethod
|
|
520
|
+
}, allTotal[columnKey], value);
|
|
521
|
+
if (_class.isDateSummaryColumn(summaryColumn)) {
|
|
522
|
+
rowTotal[columnKey] = value;
|
|
523
|
+
} else if (_class.isNumericSummaryColumn(summaryColumn)) {
|
|
524
|
+
rowTotal[columnKey] = rowTotal[columnKey] + value;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
pivot_rows.push({
|
|
528
|
+
name: _class.getGroupLabelFromDB(row[sqlGroupbyColumnKey], groupbyColumn, tables),
|
|
529
|
+
rows: [row],
|
|
530
|
+
total: rowTotal
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
if (pivot_columns.length < 2) {
|
|
534
|
+
const pivot_column = pivot_columns[0];
|
|
535
|
+
const {
|
|
536
|
+
key
|
|
537
|
+
} = pivot_column;
|
|
538
|
+
pivot_rows.forEach(row => {
|
|
539
|
+
row.total = {
|
|
540
|
+
...row.total,
|
|
541
|
+
total: row.total[key]
|
|
542
|
+
};
|
|
543
|
+
});
|
|
544
|
+
allTotal = {
|
|
545
|
+
...allTotal,
|
|
546
|
+
total: allTotal[key]
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
_class.sortCharts(pivot_rows, groupbyColumn, 'name');
|
|
550
|
+
return {
|
|
551
|
+
pivot_columns,
|
|
552
|
+
pivot_rows,
|
|
553
|
+
pivot_columns_total: allTotal
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
ChartUtils.updateTwoDimensionColumns = (pivot_columns, key, _ref) => {
|
|
557
|
+
let {
|
|
558
|
+
isIncludeEmpty,
|
|
559
|
+
isCellValueAsAnArray
|
|
560
|
+
} = _ref;
|
|
561
|
+
if (isCellValueAsAnArray) {
|
|
562
|
+
if ((!Array.isArray(key) || key.length === 0) && isIncludeEmpty) {
|
|
563
|
+
const pivotColumnIndex = pivot_columns.findIndex(r => !r.key);
|
|
564
|
+
if (pivotColumnIndex < 0) {
|
|
565
|
+
pivot_columns.unshift({
|
|
566
|
+
key: null
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
key.forEach(k => {
|
|
572
|
+
const pivotColumnIndex = pivot_columns.findIndex(r => r.key === k);
|
|
573
|
+
if (pivotColumnIndex < 0) {
|
|
574
|
+
pivot_columns.push({
|
|
575
|
+
key: k
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const pivotColumnIndex = pivot_columns.findIndex(r => {
|
|
582
|
+
let resKey = r.key;
|
|
583
|
+
return resKey === null && key === null || resKey === undefined && key === undefined || resKey === 0 && key === 0 || resKey === key;
|
|
584
|
+
});
|
|
585
|
+
if (pivotColumnIndex < 0) {
|
|
586
|
+
pivot_columns.push({
|
|
587
|
+
key
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
ChartUtils.isSameGroup = (isColumnDataAsAnArray, source, target) => {
|
|
592
|
+
if (isColumnDataAsAnArray) {
|
|
593
|
+
return (!Array.isArray(source) || source.length === 0) && !target || source.includes(target);
|
|
594
|
+
}
|
|
595
|
+
return source === null && target === null || source === undefined && target === undefined || source === target;
|
|
596
|
+
};
|
|
597
|
+
ChartUtils.updateTwoDimensionRows = (pivot_rows, pivot_columns, index, name, count, row, isColumnDataAsAnArray, cellValue, _ref2) => {
|
|
598
|
+
let {
|
|
599
|
+
summaryMethod,
|
|
600
|
+
summaryColumn
|
|
601
|
+
} = _ref2;
|
|
602
|
+
if (index > -1) {
|
|
603
|
+
let updatedPivotRow = pivot_rows[index];
|
|
604
|
+
let {
|
|
605
|
+
cells,
|
|
606
|
+
total
|
|
607
|
+
} = updatedPivotRow;
|
|
608
|
+
pivot_columns.forEach(c => {
|
|
609
|
+
let {
|
|
610
|
+
key
|
|
611
|
+
} = c;
|
|
612
|
+
if (_class.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
613
|
+
if (cells[key]) {
|
|
614
|
+
cells[key].rows.push(row);
|
|
615
|
+
cells[key].total = _class.getSummaryValue({
|
|
616
|
+
summaryMethod,
|
|
617
|
+
summaryColumn
|
|
618
|
+
}, cells[key].total, count);
|
|
619
|
+
} else {
|
|
620
|
+
cells[key] = {
|
|
621
|
+
rows: [row],
|
|
622
|
+
total: count
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
updatedPivotRow.cells = cells;
|
|
628
|
+
updatedPivotRow.total = _class.getSummaryValue({
|
|
629
|
+
summaryMethod,
|
|
630
|
+
summaryColumn
|
|
631
|
+
}, total, count);
|
|
632
|
+
pivot_rows[index] = updatedPivotRow;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
let cells = {};
|
|
636
|
+
let total = _class.initTotal(summaryMethod);
|
|
637
|
+
pivot_columns.forEach(c => {
|
|
638
|
+
let {
|
|
639
|
+
key
|
|
640
|
+
} = c;
|
|
641
|
+
if (_class.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
642
|
+
cells[key] = {
|
|
643
|
+
rows: [row],
|
|
644
|
+
total: count
|
|
645
|
+
};
|
|
646
|
+
total = _class.getSummaryValue({
|
|
647
|
+
summaryMethod,
|
|
648
|
+
summaryColumn
|
|
649
|
+
}, total, count);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
pivot_rows.push({
|
|
653
|
+
name,
|
|
654
|
+
cells,
|
|
655
|
+
total
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
ChartUtils.getSummaryValue = (_ref3, currentValue, nextValue) => {
|
|
659
|
+
let {
|
|
660
|
+
summaryMethod,
|
|
661
|
+
summaryColumn
|
|
662
|
+
} = _ref3;
|
|
663
|
+
if (_class.isDateSummaryColumn(summaryColumn)) {
|
|
664
|
+
if (summaryMethod === 'MAX') {
|
|
665
|
+
if (currentValue && nextValue) {
|
|
666
|
+
return dayjs(currentValue).isBefore(nextValue) ? nextValue : currentValue;
|
|
667
|
+
}
|
|
668
|
+
if (!currentValue && nextValue) return nextValue;
|
|
669
|
+
return currentValue;
|
|
670
|
+
}
|
|
671
|
+
if (summaryMethod === 'MIN') {
|
|
672
|
+
if (currentValue && nextValue) {
|
|
673
|
+
return dayjs(currentValue).isBefore(nextValue) ? currentValue : nextValue;
|
|
674
|
+
}
|
|
675
|
+
if (!currentValue && nextValue) return nextValue;
|
|
676
|
+
return currentValue;
|
|
677
|
+
}
|
|
678
|
+
return currentValue;
|
|
679
|
+
}
|
|
680
|
+
if (summaryMethod === 'MAX' || summaryMethod === 'MIN') {
|
|
681
|
+
if (currentValue === null && nextValue === null) return null;
|
|
682
|
+
if (currentValue === null) return nextValue;
|
|
683
|
+
if (nextValue === null) return currentValue;
|
|
684
|
+
}
|
|
685
|
+
return (currentValue - 0 || 0) + (nextValue - 0 || 0);
|
|
686
|
+
};
|
|
687
|
+
ChartUtils.getAndUpdateTwoDimensionTotal = (pivot_columns_total, pivot_columns, pivot_rows, _ref4) => {
|
|
688
|
+
let {
|
|
689
|
+
summaryMethod,
|
|
690
|
+
summaryColumn
|
|
691
|
+
} = _ref4;
|
|
692
|
+
let pivot_table_total = _class.initTotal(summaryMethod);
|
|
693
|
+
pivot_rows.forEach(row => {
|
|
694
|
+
const {
|
|
695
|
+
cells,
|
|
696
|
+
total
|
|
697
|
+
} = row;
|
|
698
|
+
pivot_table_total = _class.getSummaryValue({
|
|
699
|
+
summaryMethod,
|
|
700
|
+
summaryColumn
|
|
701
|
+
}, pivot_table_total, total);
|
|
702
|
+
pivot_columns.forEach(column => {
|
|
703
|
+
const {
|
|
704
|
+
key
|
|
705
|
+
} = column;
|
|
706
|
+
const cell = cells[key];
|
|
707
|
+
if (cell) {
|
|
708
|
+
let pivot_column_total = pivot_columns_total && pivot_columns_total[key] ? pivot_columns_total[key] : _class.initTotal(summaryMethod);
|
|
709
|
+
pivot_columns_total[key] = _class.getSummaryValue({
|
|
710
|
+
summaryMethod,
|
|
711
|
+
summaryColumn
|
|
712
|
+
}, pivot_column_total, cell.total);
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
return pivot_table_total;
|
|
717
|
+
};
|
|
718
|
+
ChartUtils.isValidCellValue = function (cellValue) {
|
|
719
|
+
let includeEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
720
|
+
if (includeEmpty) return true;
|
|
721
|
+
if (typeof cellValue === 'boolean') return true;
|
|
722
|
+
return cellValue || cellValue === 0;
|
|
723
|
+
};
|
|
724
|
+
ChartUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
725
|
+
const {
|
|
726
|
+
groupbyColumn,
|
|
727
|
+
columnGroupbyColumn,
|
|
728
|
+
summaryColumn
|
|
729
|
+
} = columnMap || {};
|
|
730
|
+
const {
|
|
731
|
+
groupby_include_empty_cells,
|
|
732
|
+
summary_method
|
|
733
|
+
} = chart.config;
|
|
734
|
+
const {
|
|
735
|
+
sqlGroupbyColumnKey,
|
|
736
|
+
sqlColumnGroupbyColumnKey,
|
|
737
|
+
sqlSummaryColumnKey
|
|
738
|
+
} = chartSQLMap;
|
|
739
|
+
if (!sqlColumnGroupbyColumnKey) return _class.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
740
|
+
const summaryMethod = (summary_method || 'sum').toUpperCase();
|
|
741
|
+
let pivot_columns = [];
|
|
742
|
+
let pivot_rows = [];
|
|
743
|
+
let pivot_columns_total = {};
|
|
744
|
+
const isRowGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[columnGroupbyColumn.type];
|
|
745
|
+
sqlRows.forEach(row => {
|
|
746
|
+
const groupbyColumnCellValue = row[sqlGroupbyColumnKey];
|
|
747
|
+
const groupbyColumnCellValueKey = _class.getGroupLabelFromDB(groupbyColumnCellValue, groupbyColumn, tables);
|
|
748
|
+
const columnGroupbyColumnCellValue = row[sqlColumnGroupbyColumnKey];
|
|
749
|
+
const columnGroupbyColumnCellValueKey = _class.getGroupLabelFromDB(columnGroupbyColumnCellValue, columnGroupbyColumn, tables);
|
|
750
|
+
const count = !row[sqlSummaryColumnKey] && row[sqlSummaryColumnKey] !== 0 ? null : row[sqlSummaryColumnKey];
|
|
751
|
+
if (_class.isValidCellValue(columnGroupbyColumnCellValue, groupby_include_empty_cells)) {
|
|
752
|
+
_class.updateTwoDimensionColumns(pivot_columns, columnGroupbyColumnCellValueKey, {
|
|
753
|
+
isIncludeEmpty: groupby_include_empty_cells,
|
|
754
|
+
isCellValueAsAnArray: isRowGroupbyColumnDataAsAnArray
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
if (_class.isValidCellValue(groupbyColumnCellValue, groupby_include_empty_cells)) {
|
|
758
|
+
if (MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn]) {
|
|
759
|
+
if ((!Array.isArray(groupbyColumnCellValueKey) || groupbyColumnCellValueKey.length === 0) && groupby_include_empty_cells) {
|
|
760
|
+
let pivotRowIndex = pivot_rows.findIndex(r => !r.name);
|
|
761
|
+
_class.updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, null, count, row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
762
|
+
summaryMethod,
|
|
763
|
+
summaryColumn
|
|
764
|
+
});
|
|
765
|
+
} else {
|
|
766
|
+
groupbyColumnCellValueKey.forEach(n => {
|
|
767
|
+
let pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
768
|
+
_class.updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, count, row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
769
|
+
summaryMethod,
|
|
770
|
+
summaryColumn
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
} else {
|
|
775
|
+
let pivotRowIndex = pivot_rows.findIndex(r => {
|
|
776
|
+
let resName = r.name;
|
|
777
|
+
return resName === null && groupbyColumnCellValueKey === null || resName === undefined && groupbyColumnCellValueKey === undefined || resName === 0 && groupbyColumnCellValueKey === 0 || resName === groupbyColumnCellValueKey;
|
|
778
|
+
});
|
|
779
|
+
_class.updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, groupbyColumnCellValueKey, count, row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
780
|
+
summaryMethod,
|
|
781
|
+
summaryColumn
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
let pivot_table_total = _class.getAndUpdateTwoDimensionTotal(pivot_columns_total, pivot_columns, pivot_rows, {
|
|
787
|
+
summaryMethod,
|
|
788
|
+
summaryColumn
|
|
789
|
+
});
|
|
790
|
+
_class.sortCharts(pivot_rows, groupbyColumn, 'name');
|
|
791
|
+
_class.sortCharts(pivot_columns, columnGroupbyColumn, 'key');
|
|
792
|
+
return {
|
|
793
|
+
pivot_columns,
|
|
794
|
+
pivot_rows,
|
|
795
|
+
pivot_columns_total,
|
|
796
|
+
pivot_table_total
|
|
797
|
+
};
|
|
798
|
+
};
|
|
799
|
+
ChartUtils.basicChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
800
|
+
const {
|
|
801
|
+
config
|
|
802
|
+
} = chart;
|
|
803
|
+
const {
|
|
804
|
+
type,
|
|
805
|
+
sort_type
|
|
806
|
+
} = config;
|
|
807
|
+
const {
|
|
808
|
+
groupbyColumn
|
|
809
|
+
} = columnMap;
|
|
810
|
+
const isGroupbyColumnDataAsAnArray = MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
|
|
811
|
+
const {
|
|
812
|
+
sqlGroupbyColumnKey,
|
|
813
|
+
sqlSummaryColumnKey
|
|
814
|
+
} = chartSQLMap;
|
|
815
|
+
let result = [];
|
|
816
|
+
sqlRows.forEach(row => {
|
|
817
|
+
const cellValue = row[sqlGroupbyColumnKey];
|
|
818
|
+
const summaryValue = row[sqlSummaryColumnKey];
|
|
819
|
+
if (_class.isValidCellValue(cellValue)) {
|
|
820
|
+
const key = _class.getGroupLabelFromDB(cellValue, groupbyColumn, tables);
|
|
821
|
+
if (isGroupbyColumnDataAsAnArray) {
|
|
822
|
+
if (!Array.isArray(key) || key.length === 0) {
|
|
823
|
+
let itemIdx = result.findIndex(v => v.name === null);
|
|
824
|
+
if (itemIdx < 0) {
|
|
825
|
+
result.push({
|
|
826
|
+
color: '',
|
|
827
|
+
name: null,
|
|
828
|
+
rows: [row],
|
|
829
|
+
value: summaryValue
|
|
830
|
+
});
|
|
831
|
+
} else {
|
|
832
|
+
let itemRow = result[itemIdx];
|
|
833
|
+
itemRow.rows.push(row);
|
|
834
|
+
itemRow.value = itemRow.value + summaryValue;
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
key.forEach(item => {
|
|
838
|
+
let itemIdx = result.findIndex(v => v.name === item);
|
|
839
|
+
if (itemIdx < 0) {
|
|
840
|
+
result.push({
|
|
841
|
+
color: '',
|
|
842
|
+
name: item,
|
|
843
|
+
rows: [row],
|
|
844
|
+
value: summaryValue
|
|
845
|
+
});
|
|
846
|
+
} else {
|
|
847
|
+
let itemRow = result[itemIdx];
|
|
848
|
+
itemRow.rows.push(row);
|
|
849
|
+
itemRow.value = itemRow.value + summaryValue;
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
let itemIdx = result.findIndex(v => v.name === key);
|
|
855
|
+
if (itemIdx < 0) {
|
|
856
|
+
result.push({
|
|
857
|
+
color: '',
|
|
858
|
+
name: key,
|
|
859
|
+
rows: [row],
|
|
860
|
+
value: summaryValue
|
|
861
|
+
});
|
|
862
|
+
} else {
|
|
863
|
+
let itemRow = result[itemIdx];
|
|
864
|
+
itemRow.rows.push(row);
|
|
865
|
+
itemRow.value = itemRow.value + summaryValue;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
_class.updateTableViewList(result, groupbyColumn, 'name', 'color');
|
|
871
|
+
if (SUPPORT_DATA_SORT_CHART_TYPES.includes(type) && sort_type) {
|
|
872
|
+
_class.sortChartData(result, sort_type);
|
|
873
|
+
return result;
|
|
874
|
+
}
|
|
875
|
+
_class.sortCharts(result, groupbyColumn, 'name');
|
|
876
|
+
return result;
|
|
877
|
+
};
|
|
878
|
+
ChartUtils.basicNumberCardSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
879
|
+
if (sqlRows.length > 0) {
|
|
880
|
+
const summaryResult = sqlRows[0];
|
|
881
|
+
const key = Object.keys(summaryResult)[0];
|
|
882
|
+
return summaryResult[key];
|
|
883
|
+
}
|
|
884
|
+
return 0;
|
|
885
|
+
};
|
|
886
|
+
ChartUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
887
|
+
const {
|
|
888
|
+
config
|
|
889
|
+
} = chart;
|
|
890
|
+
const {
|
|
891
|
+
y_axis_left_group_by_multiple_numeric_column,
|
|
892
|
+
y_axis_left_summary_type,
|
|
893
|
+
y_axis_left_summary_column,
|
|
894
|
+
y_axis_left_summary_method,
|
|
895
|
+
y_axis_right_summary_type,
|
|
896
|
+
y_axis_right_summary_column,
|
|
897
|
+
table_id,
|
|
898
|
+
y_axis_left_group_by_numeric_columns
|
|
899
|
+
} = config;
|
|
900
|
+
const table = getTableById(tables, table_id);
|
|
901
|
+
const {
|
|
902
|
+
groupbyColumn
|
|
903
|
+
} = columnMap;
|
|
904
|
+
const {
|
|
905
|
+
sqlGroupbyColumnKey,
|
|
906
|
+
sqlSummaryColumnKey,
|
|
907
|
+
sqlRightSummaryColumnKey,
|
|
908
|
+
sqlLeftSummaryColumnKey
|
|
909
|
+
} = chartSQLMap;
|
|
910
|
+
const isGroupbyColumnDataAsAnArray = MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
|
|
911
|
+
let result = [];
|
|
912
|
+
if (!y_axis_left_group_by_multiple_numeric_column) {
|
|
913
|
+
let leftSummaryColumn, rightSummaryColumn;
|
|
914
|
+
if (y_axis_left_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
915
|
+
leftSummaryColumn = getTableColumnByKey(table, y_axis_left_summary_column);
|
|
916
|
+
}
|
|
917
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
918
|
+
rightSummaryColumn = getTableColumnByKey(table, y_axis_right_summary_column);
|
|
919
|
+
}
|
|
920
|
+
sqlRows.forEach(row => {
|
|
921
|
+
const cellValue = row[sqlGroupbyColumnKey];
|
|
922
|
+
const summaryValue = row[sqlSummaryColumnKey];
|
|
923
|
+
const key = _class.getGroupLabelFromDB(cellValue, groupbyColumn, tables);
|
|
924
|
+
let valueLeft = row[sqlLeftSummaryColumnKey] || 0;
|
|
925
|
+
let valueRight = row[sqlRightSummaryColumnKey] || 0;
|
|
926
|
+
if (y_axis_left_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
927
|
+
valueLeft = _class.getPrecisionNumber(valueLeft, leftSummaryColumn.data);
|
|
928
|
+
}
|
|
929
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
930
|
+
valueRight = _class.getPrecisionNumber(valueRight, rightSummaryColumn.data);
|
|
931
|
+
}
|
|
932
|
+
if (isGroupbyColumnDataAsAnArray) {
|
|
933
|
+
if (!Array.isArray(key) || key.length === 0) {
|
|
934
|
+
let itemIdx = result.findIndex(v => v.name === null);
|
|
935
|
+
if (itemIdx < 0) {
|
|
936
|
+
result.push({
|
|
937
|
+
color: '',
|
|
938
|
+
name: null,
|
|
939
|
+
rows: [row],
|
|
940
|
+
value_left: valueLeft,
|
|
941
|
+
value_right: valueRight
|
|
942
|
+
});
|
|
943
|
+
} else {
|
|
944
|
+
let itemRow = result[itemIdx];
|
|
945
|
+
itemRow.rows.push(row);
|
|
946
|
+
itemRow.value_left = itemRow.value_left + summaryValue;
|
|
947
|
+
itemRow.value_right = itemRow.value_right + summaryValue;
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
key.forEach(item => {
|
|
951
|
+
let itemIdx = result.findIndex(v => v.name === item);
|
|
952
|
+
if (itemIdx < 0) {
|
|
953
|
+
result.push({
|
|
954
|
+
color: '',
|
|
955
|
+
name: item,
|
|
956
|
+
rows: [row],
|
|
957
|
+
value_left: valueLeft,
|
|
958
|
+
value_right: valueRight
|
|
959
|
+
});
|
|
960
|
+
} else {
|
|
961
|
+
let itemRow = result[itemIdx];
|
|
962
|
+
itemRow.rows.push(row);
|
|
963
|
+
itemRow.value_left = itemRow.value_left + summaryValue;
|
|
964
|
+
itemRow.value_right = itemRow.value_right + summaryValue;
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
} else {
|
|
969
|
+
let itemIdx = result.findIndex(v => v.name === key);
|
|
970
|
+
if (itemIdx < 0) {
|
|
971
|
+
result.push({
|
|
972
|
+
color: '',
|
|
973
|
+
name: key,
|
|
974
|
+
rows: [row],
|
|
975
|
+
value_left: valueLeft,
|
|
976
|
+
value_right: valueRight
|
|
977
|
+
});
|
|
978
|
+
} else {
|
|
979
|
+
let itemRow = result[itemIdx];
|
|
980
|
+
itemRow.rows.push(row);
|
|
981
|
+
itemRow.value_left = itemRow.value_left + summaryValue;
|
|
982
|
+
itemRow.value_right = itemRow.value_right + summaryValue;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
} else {
|
|
987
|
+
let rightSummaryColumn;
|
|
988
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
989
|
+
rightSummaryColumn = getTableColumnByKey(table, y_axis_right_summary_column);
|
|
990
|
+
}
|
|
991
|
+
const groupItems = [];
|
|
992
|
+
let leftSummaryColumn = getTableColumnByKey(table, y_axis_left_summary_column);
|
|
993
|
+
const summaryMethod = y_axis_left_summary_method.toUpperCase();
|
|
994
|
+
const {
|
|
995
|
+
key: groupItem
|
|
996
|
+
} = summaryMethodColumn2SqlColumn(summaryMethod, leftSummaryColumn || {});
|
|
997
|
+
leftSummaryColumn && !groupItems.includes(groupItem) && groupItems.push(groupItem);
|
|
998
|
+
y_axis_left_group_by_numeric_columns.forEach((item, index) => {
|
|
999
|
+
const column = getTableColumnByKey(table, item.column_key);
|
|
1000
|
+
if (column) {
|
|
1001
|
+
const itemSummaryMethod = item.summary_method.toUpperCase();
|
|
1002
|
+
const {
|
|
1003
|
+
key: groupItem
|
|
1004
|
+
} = summaryMethodColumn2SqlColumn(itemSummaryMethod, column || {});
|
|
1005
|
+
!groupItems.includes(groupItem) && groupItems.push(groupItem);
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
sqlRows.forEach((item, index) => {
|
|
1009
|
+
const cellValue = item[sqlGroupbyColumnKey];
|
|
1010
|
+
const key = _class.getGroupLabelFromDB(cellValue, groupbyColumn, tables);
|
|
1011
|
+
let valueRight = item[sqlRightSummaryColumnKey] || 0;
|
|
1012
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
1013
|
+
valueRight = _class.getPrecisionNumber(valueRight, rightSummaryColumn.data);
|
|
1014
|
+
}
|
|
1015
|
+
groupItems.forEach((groupItem, index) => {
|
|
1016
|
+
let value = item[groupItem] || 0;
|
|
1017
|
+
if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
1018
|
+
value = _class.getPrecisionNumber(value, leftSummaryColumn.data);
|
|
1019
|
+
}
|
|
1020
|
+
result.push({
|
|
1021
|
+
name: key,
|
|
1022
|
+
value_left: value,
|
|
1023
|
+
value_right: valueRight,
|
|
1024
|
+
color: LABEL_COLORS[index % 12]
|
|
1025
|
+
});
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
return result;
|
|
1030
|
+
};
|
|
1031
|
+
ChartUtils.getPrecisionNumber = (value, data) => {
|
|
1032
|
+
const valueString = getPrecisionNumber(value, data);
|
|
1033
|
+
const valueNumber = parseFloat(valueString);
|
|
1034
|
+
return isNumber(valueNumber) ? valueNumber : 0;
|
|
1035
|
+
};
|
|
1036
|
+
ChartUtils.dashboardSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1037
|
+
if (sqlRows.length > 0) {
|
|
1038
|
+
const summaryResult = sqlRows[0];
|
|
1039
|
+
const {
|
|
1040
|
+
config
|
|
1041
|
+
} = chart;
|
|
1042
|
+
const {
|
|
1043
|
+
target_value_column_summary_method,
|
|
1044
|
+
total_value_column_summary_method,
|
|
1045
|
+
target_value_column_key,
|
|
1046
|
+
total_value_column_key,
|
|
1047
|
+
table_id
|
|
1048
|
+
} = config;
|
|
1049
|
+
const table = getTableById(tables, table_id);
|
|
1050
|
+
const targetColumn = getTableColumnByKey(table, target_value_column_key);
|
|
1051
|
+
const totalColumn = getTableColumnByKey(table, total_value_column_key);
|
|
1052
|
+
const targetSummaryMethod = target_value_column_summary_method.toUpperCase();
|
|
1053
|
+
const totalSummaryMethod = total_value_column_summary_method.toUpperCase();
|
|
1054
|
+
const {
|
|
1055
|
+
key: targetResultKey
|
|
1056
|
+
} = summaryMethodColumn2SqlColumn(targetSummaryMethod, targetColumn);
|
|
1057
|
+
const {
|
|
1058
|
+
key: totalResultKey
|
|
1059
|
+
} = summaryMethodColumn2SqlColumn(totalSummaryMethod, totalColumn);
|
|
1060
|
+
const targetResult = summaryResult[targetResultKey];
|
|
1061
|
+
const totalResult = summaryResult[totalResultKey];
|
|
1062
|
+
if (totalResult === 0) {
|
|
1063
|
+
return 0;
|
|
1064
|
+
}
|
|
1065
|
+
return targetResult / totalResult;
|
|
1066
|
+
}
|
|
1067
|
+
return 0;
|
|
1068
|
+
};
|
|
1069
|
+
ChartUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorKey) => {
|
|
1070
|
+
let {
|
|
1071
|
+
type: columnType,
|
|
1072
|
+
data: columnData
|
|
1073
|
+
} = column;
|
|
1074
|
+
let name = result[nameKey];
|
|
1075
|
+
if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
|
|
1076
|
+
const options = getColumnOptions(column);
|
|
1077
|
+
let selectedOption = getOption(options, name);
|
|
1078
|
+
let {
|
|
1079
|
+
name: optionName,
|
|
1080
|
+
color: optionColor
|
|
1081
|
+
} = selectedOption || {};
|
|
1082
|
+
if (selectedOption) {
|
|
1083
|
+
result[nameKey] = optionName;
|
|
1084
|
+
result[colorKey] = optionColor;
|
|
1085
|
+
} else {
|
|
1086
|
+
result[colorKey] = '#dbdbdb';
|
|
1087
|
+
}
|
|
1088
|
+
} else if (columnType === CellType.COLLABORATOR) {
|
|
1089
|
+
let collaborator = getKnownCollaboratorByEmail(name);
|
|
1090
|
+
if (collaborator) {
|
|
1091
|
+
result[nameKey] = collaborator.name;
|
|
1092
|
+
}
|
|
1093
|
+
} else if (columnType === CellType.CREATOR || columnType === CellType.LAST_MODIFIER) {
|
|
1094
|
+
if (name === 'anonymous') {
|
|
1095
|
+
result[nameKey] = name;
|
|
1096
|
+
} else {
|
|
1097
|
+
const collaborator = getKnownCollaboratorByEmail(name);
|
|
1098
|
+
const collaboratorTemplate = {
|
|
1099
|
+
loaded: false,
|
|
1100
|
+
email: name,
|
|
1101
|
+
name: name
|
|
1102
|
+
};
|
|
1103
|
+
context.updateCollaboratorsCache(name, collaboratorTemplate);
|
|
1104
|
+
if (!collaborator) {
|
|
1105
|
+
context.queryUsers([name], emailUserMap => {
|
|
1106
|
+
const collaborator = emailUserMap && emailUserMap[name] || generateDefaultUser(name);
|
|
1107
|
+
const loadedCollaborator = {
|
|
1108
|
+
...collaborator,
|
|
1109
|
+
loaded: true
|
|
1110
|
+
};
|
|
1111
|
+
context.updateCollaboratorsCache(name, loadedCollaborator);
|
|
1112
|
+
result[nameKey] = name;
|
|
1113
|
+
});
|
|
1114
|
+
} else {
|
|
1115
|
+
result[nameKey] = collaborator.name;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
} else if (columnType === CellType.NUMBER) {
|
|
1119
|
+
let valueNumber = parseFloat(name);
|
|
1120
|
+
result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
|
|
1121
|
+
} else if (columnType === CellType.DATE) {
|
|
1122
|
+
name = name + '';
|
|
1123
|
+
if (name && name.split('-').length === 3) {
|
|
1124
|
+
let format = getDateColumnFormat(column);
|
|
1125
|
+
let spaceIndex = format.indexOf(' ');
|
|
1126
|
+
if (spaceIndex > -1) {
|
|
1127
|
+
format = format.slice(0, spaceIndex);
|
|
1128
|
+
}
|
|
1129
|
+
result[nameKey] = dayjs(name).format(format);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
ChartUtils.updateTableViewList = (result, column, nameKey, colorKey) => {
|
|
1134
|
+
result.forEach(result => {
|
|
1135
|
+
_class.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey);
|
|
1136
|
+
});
|
|
1137
|
+
};
|
|
1138
|
+
ChartUtils.updateGroupingChartRow = (results, name, groupName, row, count) => {
|
|
1139
|
+
let updatedIndex = results.findIndex(result => result.name === name && result.group_name === groupName);
|
|
1140
|
+
if (updatedIndex > -1) {
|
|
1141
|
+
let updatedResult = results[updatedIndex];
|
|
1142
|
+
updatedResult.rows.push(row);
|
|
1143
|
+
updatedResult.value = updatedResult.value + count;
|
|
1144
|
+
results[updatedIndex] = updatedResult;
|
|
1145
|
+
} else {
|
|
1146
|
+
results.push({
|
|
1147
|
+
name,
|
|
1148
|
+
rows: [row],
|
|
1149
|
+
group_name: groupName,
|
|
1150
|
+
value: count
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
ChartUtils.updateGroupingChartRows = (results, name, row, count, isColumnGroupbyColumnDataAsAnArray, groupName) => {
|
|
1155
|
+
if (isColumnGroupbyColumnDataAsAnArray) {
|
|
1156
|
+
if (!Array.isArray(groupName) || groupName.length === 0) {
|
|
1157
|
+
_class.updateGroupingChartRow(results, name, null, row, count);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
groupName.forEach(v => {
|
|
1161
|
+
_class.updateGroupingChartRow(results, name, v, row, count);
|
|
1162
|
+
});
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
_class.updateGroupingChartRow(results, name, groupName, row, count);
|
|
1166
|
+
};
|
|
1167
|
+
ChartUtils.groupingTwoDimensionChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1168
|
+
const {
|
|
1169
|
+
groupbyColumn,
|
|
1170
|
+
columnGroupbyColumn
|
|
1171
|
+
} = columnMap;
|
|
1172
|
+
const {
|
|
1173
|
+
x_axis_include_empty_cells: includeEmpty
|
|
1174
|
+
} = chart.config;
|
|
1175
|
+
const {
|
|
1176
|
+
sqlGroupbyColumnKey,
|
|
1177
|
+
sqlColumnGroupbyColumnKey,
|
|
1178
|
+
sqlSummaryColumnKey
|
|
1179
|
+
} = chartSQLMap;
|
|
1180
|
+
let result = [];
|
|
1181
|
+
const isGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
|
|
1182
|
+
const isColumnGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[columnGroupbyColumn.type];
|
|
1183
|
+
sqlRows.forEach(row => {
|
|
1184
|
+
const groupbyColumnCellValue = row[sqlGroupbyColumnKey];
|
|
1185
|
+
const groupbyColumnCellValueKey = _class.getGroupLabelFromDB(groupbyColumnCellValue, groupbyColumn, tables);
|
|
1186
|
+
if (_class.isValidCellValue(groupbyColumnCellValueKey, includeEmpty)) {
|
|
1187
|
+
const columnGroupbyColumnCellValue = row[sqlColumnGroupbyColumnKey];
|
|
1188
|
+
const columnGroupbyColumnCellValueKey = _class.getGroupLabelFromDB(columnGroupbyColumnCellValue, columnGroupbyColumn, tables);
|
|
1189
|
+
const count = row[sqlSummaryColumnKey];
|
|
1190
|
+
if (isGroupbyColumnDataAsAnArray) {
|
|
1191
|
+
if (!Array.isArray(groupbyColumnCellValueKey) || groupbyColumnCellValueKey.length === 0) {
|
|
1192
|
+
_class.updateGroupingChartRows(result, null, row, count, isColumnGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey);
|
|
1193
|
+
} else {
|
|
1194
|
+
groupbyColumnCellValueKey.forEach(n => {
|
|
1195
|
+
_class.updateGroupingChartRows(result, n, row, count, isColumnGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey);
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
} else {
|
|
1199
|
+
_class.updateGroupingChartRows(result, groupbyColumnCellValueKey, row, count, isColumnGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
_class.updateTableViewList(result, groupbyColumn, 'name', 'color');
|
|
1204
|
+
_class.updateTableViewList(result, columnGroupbyColumn, 'group_name', 'group_color');
|
|
1205
|
+
_class.sortCharts(result, groupbyColumn, 'name');
|
|
1206
|
+
return result;
|
|
1207
|
+
};
|
|
1208
|
+
ChartUtils.groupingChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1209
|
+
const {
|
|
1210
|
+
column_groupby_column_key,
|
|
1211
|
+
column_groupby_multiple_numeric_column,
|
|
1212
|
+
y_axis_summary_type,
|
|
1213
|
+
x_axis_include_empty_cells: includeEmpty
|
|
1214
|
+
} = chart.config;
|
|
1215
|
+
if (!column_groupby_column_key && !column_groupby_multiple_numeric_column) {
|
|
1216
|
+
return _class.basicChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1217
|
+
}
|
|
1218
|
+
const {
|
|
1219
|
+
groupbyColumn,
|
|
1220
|
+
columnGroupbyColumn
|
|
1221
|
+
} = columnMap;
|
|
1222
|
+
if (y_axis_summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
1223
|
+
if (!columnGroupbyColumn) return _class.basicChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1224
|
+
return _class.groupingTwoDimensionChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1225
|
+
}
|
|
1226
|
+
const {
|
|
1227
|
+
sqlGroupbyColumnKey
|
|
1228
|
+
} = chartSQLMap;
|
|
1229
|
+
if (column_groupby_multiple_numeric_column) {
|
|
1230
|
+
const {
|
|
1231
|
+
summaryColumns
|
|
1232
|
+
} = chartSQLMap;
|
|
1233
|
+
let result = [];
|
|
1234
|
+
const isGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
|
|
1235
|
+
sqlRows.forEach(row => {
|
|
1236
|
+
const groupbyColumnCellValue = row[sqlGroupbyColumnKey];
|
|
1237
|
+
const groupbyColumnCellValueKey = _class.getGroupLabelFromDB(groupbyColumnCellValue, groupbyColumn, tables);
|
|
1238
|
+
if (_class.isValidCellValue(groupbyColumnCellValueKey, includeEmpty)) {
|
|
1239
|
+
Object.keys(summaryColumns).forEach(sqlSummaryColumnName => {
|
|
1240
|
+
const {
|
|
1241
|
+
sqlSummaryColumnKey,
|
|
1242
|
+
columnName
|
|
1243
|
+
} = summaryColumns[sqlSummaryColumnName];
|
|
1244
|
+
const numberColumnCellValue = row[sqlSummaryColumnKey];
|
|
1245
|
+
if (isGroupbyColumnDataAsAnArray) {
|
|
1246
|
+
if (!Array.isArray(groupbyColumnCellValueKey) || groupbyColumnCellValueKey.length === 0) {
|
|
1247
|
+
_class.updateGroupingChartRows(result, null, row, numberColumnCellValue, false, columnName);
|
|
1248
|
+
} else {
|
|
1249
|
+
groupbyColumnCellValueKey.forEach(n => {
|
|
1250
|
+
_class.updateGroupingChartRows(result, n, row, numberColumnCellValue, false, columnName);
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
} else {
|
|
1254
|
+
_class.updateGroupingChartRows(result, groupbyColumnCellValueKey, row, numberColumnCellValue, false, columnName);
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
_class.updateTableViewList(result, groupbyColumn, 'name', 'color');
|
|
1260
|
+
_class.sortCharts(result, groupbyColumn, 'name');
|
|
1261
|
+
return result;
|
|
1262
|
+
}
|
|
1263
|
+
if (!columnGroupbyColumn) {
|
|
1264
|
+
return _class.basicChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1265
|
+
}
|
|
1266
|
+
return _class.groupingTwoDimensionChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1267
|
+
};
|
|
1268
|
+
ChartUtils.sqlResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1269
|
+
const {
|
|
1270
|
+
type
|
|
1271
|
+
} = chart.config;
|
|
1272
|
+
switch (type) {
|
|
1273
|
+
case CHART_TYPE.TABLE:
|
|
1274
|
+
{
|
|
1275
|
+
const {
|
|
1276
|
+
column_groupby_column_key
|
|
1277
|
+
} = chart.config;
|
|
1278
|
+
if (!column_groupby_column_key) {
|
|
1279
|
+
return {
|
|
1280
|
+
result: _class.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
return {
|
|
1284
|
+
result: _class.twoDimensionTableSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
case CHART_TYPE.PIE:
|
|
1288
|
+
case CHART_TYPE.RING:
|
|
1289
|
+
case CHART_TYPE.TREE_MAP:
|
|
1290
|
+
{
|
|
1291
|
+
return {
|
|
1292
|
+
result: _class.basicChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
case CHART_TYPE.BASIC_NUMBER_CARD:
|
|
1296
|
+
{
|
|
1297
|
+
return {
|
|
1298
|
+
result: _class.basicNumberCardSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
case CHART_TYPE.DASHBOARD:
|
|
1302
|
+
{
|
|
1303
|
+
return {
|
|
1304
|
+
result: _class.dashboardSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
case CHART_TYPE.BAR:
|
|
1308
|
+
case CHART_TYPE.LINE:
|
|
1309
|
+
case CHART_TYPE.HORIZONTAL_BAR:
|
|
1310
|
+
case CHART_TYPE.AREA:
|
|
1311
|
+
{
|
|
1312
|
+
return {
|
|
1313
|
+
result: _class.basicChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
case CHART_TYPE.COMBINATION:
|
|
1317
|
+
{
|
|
1318
|
+
return {
|
|
1319
|
+
result: _class.combinationSQLResult2Javascript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
case CHART_TYPE.BAR_GROUP:
|
|
1323
|
+
case CHART_TYPE.LINE_GROUP:
|
|
1324
|
+
case CHART_TYPE.HORIZONTAL_GROUP_BAR:
|
|
1325
|
+
{
|
|
1326
|
+
return {
|
|
1327
|
+
result: _class.groupingChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
default:
|
|
1331
|
+
{
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
ChartUtils.convertConfig = config => {
|
|
1337
|
+
const {
|
|
1338
|
+
type
|
|
1339
|
+
} = config;
|
|
1340
|
+
if (type === CHART_TYPE.HORIZONTAL_BAR || type === CHART_TYPE.HORIZONTAL_GROUP_BAR) {
|
|
1341
|
+
const {
|
|
1342
|
+
vertical_axis_column_key,
|
|
1343
|
+
vertical_axis_date_granularity,
|
|
1344
|
+
vertical_axis_geolocation_granularity,
|
|
1345
|
+
vertical_axis_include_empty,
|
|
1346
|
+
horizontal_axis_summary_type,
|
|
1347
|
+
horizontal_axis_summary_method,
|
|
1348
|
+
horizontal_axis_column_key,
|
|
1349
|
+
show_vertical_axis_label,
|
|
1350
|
+
vertical_axis_label_position,
|
|
1351
|
+
show_horizontal_axis_label,
|
|
1352
|
+
horizontal_axis_label_position,
|
|
1353
|
+
horizontal_axis_label_color
|
|
1354
|
+
} = config;
|
|
1355
|
+
const newConfig = {
|
|
1356
|
+
x_axis_column_key: vertical_axis_column_key,
|
|
1357
|
+
x_axis_date_granularity: vertical_axis_date_granularity,
|
|
1358
|
+
x_axis_geolocation_granularity: vertical_axis_geolocation_granularity,
|
|
1359
|
+
x_axis_include_empty_cells: vertical_axis_include_empty,
|
|
1360
|
+
y_axis_summary_type: horizontal_axis_summary_type,
|
|
1361
|
+
y_axis_summary_method: horizontal_axis_summary_method,
|
|
1362
|
+
y_axis_summary_column_key: horizontal_axis_column_key,
|
|
1363
|
+
x_axis_show_label: show_vertical_axis_label,
|
|
1364
|
+
x_axis_label_position: vertical_axis_label_position,
|
|
1365
|
+
y_axis_show_label: show_horizontal_axis_label,
|
|
1366
|
+
y_axis_label_position: horizontal_axis_label_position,
|
|
1367
|
+
y_axis_label_color: horizontal_axis_label_color,
|
|
1368
|
+
y_axis_auto_range: config.horizontal_axis_auto_range,
|
|
1369
|
+
y_axis_max: config.horizontal_axis_max,
|
|
1370
|
+
y_axis_mix: config.horizontal_axis_min
|
|
1371
|
+
};
|
|
1372
|
+
return Object.assign({}, config, newConfig);
|
|
1373
|
+
}
|
|
1374
|
+
return config;
|
|
1375
|
+
};
|
|
1376
|
+
ChartUtils.imEmptyChartResult = chartResult => {
|
|
1377
|
+
return !chartResult || !chartResult.result && chartResult.result !== 0 || Array.isArray(chartResult.result) && chartResult.result.length === 0;
|
|
1378
|
+
};
|
|
1379
|
+
ChartUtils.calculateChart = (chart, tables, callback, isChartData) => {
|
|
1380
|
+
if (!_class.isValidExistChart(tables, chart)) {
|
|
1381
|
+
const tip_message = 'Please_complete_the_chart_configuration_first';
|
|
1382
|
+
return callback && callback('', tip_message, null);
|
|
1383
|
+
}
|
|
1384
|
+
const {
|
|
1385
|
+
id,
|
|
1386
|
+
config,
|
|
1387
|
+
type
|
|
1388
|
+
} = chart;
|
|
1389
|
+
const newConfig = _class.convertConfig(config);
|
|
1390
|
+
const newChart = {
|
|
1391
|
+
id,
|
|
1392
|
+
config: newConfig,
|
|
1393
|
+
type
|
|
1394
|
+
};
|
|
1395
|
+
const {
|
|
1396
|
+
table_id
|
|
1397
|
+
} = config;
|
|
1398
|
+
const table = getTableById(tables, table_id);
|
|
1399
|
+
const groupbyColumn = _class.getGroupColumn(table, newChart);
|
|
1400
|
+
const columnGroupbyColumn = _class.getColumnGroupColumn(table, newChart);
|
|
1401
|
+
const summaryColumn = _class.getSummaryColumn(table, newChart);
|
|
1402
|
+
const columnMap = {
|
|
1403
|
+
groupbyColumn,
|
|
1404
|
+
columnGroupbyColumn,
|
|
1405
|
+
summaryColumn
|
|
1406
|
+
};
|
|
1407
|
+
const chartTableColumns = table.columns;
|
|
1408
|
+
let chartSQLMap = null;
|
|
1409
|
+
try {
|
|
1410
|
+
chartSQLMap = chartColumn2SqlColumn(newChart, table);
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
const error_message = 'There_are_some_problems_with_the_filters';
|
|
1413
|
+
return callback && callback(error_message, '', null);
|
|
1414
|
+
}
|
|
1415
|
+
context.queryResultFromDB({
|
|
1416
|
+
chart,
|
|
1417
|
+
tables,
|
|
1418
|
+
onSuccess: res => {
|
|
1419
|
+
const {
|
|
1420
|
+
success,
|
|
1421
|
+
results: sqlRows,
|
|
1422
|
+
error_message
|
|
1423
|
+
} = res.data;
|
|
1424
|
+
if (success) {
|
|
1425
|
+
if (isChartData) {
|
|
1426
|
+
const tipMessage = 'There_are_no_statistic_results_yet';
|
|
1427
|
+
if (!Array.isArray(sqlRows) || sqlRows.length === 0) {
|
|
1428
|
+
callback && callback('', tipMessage, null);
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
const chartResult = _class.sqlResult2JavaScript(newChart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1432
|
+
if (_class.imEmptyChartResult(chartResult)) {
|
|
1433
|
+
callback && callback('', tipMessage, null);
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
callback && callback('', '', {
|
|
1437
|
+
...chartResult,
|
|
1438
|
+
groupbyColumn,
|
|
1439
|
+
columnGroupbyColumn,
|
|
1440
|
+
summaryColumn,
|
|
1441
|
+
chartTableColumns
|
|
1442
|
+
});
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
callback && callback(error_message, '', null);
|
|
1447
|
+
},
|
|
1448
|
+
onFail: err => {
|
|
1449
|
+
let errorMessage = 'Network_error';
|
|
1450
|
+
if (err.response) {
|
|
1451
|
+
const {
|
|
1452
|
+
status
|
|
1453
|
+
} = err.response;
|
|
1454
|
+
if (status === 500) {
|
|
1455
|
+
errorMessage = 'Internal_server_error';
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
callback && callback(errorMessage, '', null);
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
};
|
|
1462
|
+
ChartUtils.calculateStaticChart = (tables, chart, statisticalResult, callback) => {
|
|
1463
|
+
if (!_class.isValidExistChart(tables, chart)) {
|
|
1464
|
+
const tip_message = 'Please_complete_the_chart_configuration_first';
|
|
1465
|
+
return callback && callback('', tip_message, null);
|
|
1466
|
+
}
|
|
1467
|
+
if (!statisticalResult) {
|
|
1468
|
+
const tip_message = 'There_are_no_statistic_results_yet';
|
|
1469
|
+
return callback && callback('', tip_message, null);
|
|
1470
|
+
}
|
|
1471
|
+
const {
|
|
1472
|
+
id,
|
|
1473
|
+
config
|
|
1474
|
+
} = chart;
|
|
1475
|
+
const newConfig = _class.convertConfig(config);
|
|
1476
|
+
const newChart = {
|
|
1477
|
+
id,
|
|
1478
|
+
config: newConfig
|
|
1479
|
+
};
|
|
1480
|
+
const {
|
|
1481
|
+
type
|
|
1482
|
+
} = config;
|
|
1483
|
+
if (type === CHART_TYPE.TABLE) return callback && callback('', '', statisticalResult);
|
|
1484
|
+
const {
|
|
1485
|
+
table_id,
|
|
1486
|
+
sort_type
|
|
1487
|
+
} = config;
|
|
1488
|
+
const table = getTableById(tables, table_id);
|
|
1489
|
+
const groupbyColumn = _class.getGroupColumn(table, newChart);
|
|
1490
|
+
let result = statisticalResult.result;
|
|
1491
|
+
if (!result) {
|
|
1492
|
+
const tip_message = 'There_are_no_statistic_results_yet';
|
|
1493
|
+
return callback && callback('', tip_message, null);
|
|
1494
|
+
}
|
|
1495
|
+
if (SUPPORT_DATA_SORT_CHART_TYPES.includes(type) && sort_type) {
|
|
1496
|
+
_class.sortChartData(result, sort_type);
|
|
1497
|
+
const newStatisticalResult = {
|
|
1498
|
+
...statisticalResult,
|
|
1499
|
+
result
|
|
1500
|
+
};
|
|
1501
|
+
return callback && callback('', '', newStatisticalResult);
|
|
1502
|
+
}
|
|
1503
|
+
_class.sortCharts(result, groupbyColumn, 'name');
|
|
1504
|
+
const newStatisticalResult = {
|
|
1505
|
+
...statisticalResult,
|
|
1506
|
+
result
|
|
1507
|
+
};
|
|
1508
|
+
return callback && callback('', '', newStatisticalResult);
|
|
1509
|
+
};
|
|
1510
|
+
ChartUtils.getPieColorSet = (tables, chart, result) => {
|
|
1511
|
+
if (!Array.isArray(result)) return [];
|
|
1512
|
+
const {
|
|
1513
|
+
table_id,
|
|
1514
|
+
groupby_column_key: column_id
|
|
1515
|
+
} = chart.config;
|
|
1516
|
+
const column = _class.getColumn(tables, table_id, column_id);
|
|
1517
|
+
const {
|
|
1518
|
+
type: columnType
|
|
1519
|
+
} = column || {};
|
|
1520
|
+
const pieChartColorsLength = PIE_CHART_COLORS.length - 1;
|
|
1521
|
+
const backgroundColor = [];
|
|
1522
|
+
result.forEach((item, index) => {
|
|
1523
|
+
if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
|
|
1524
|
+
let {
|
|
1525
|
+
color
|
|
1526
|
+
} = item;
|
|
1527
|
+
backgroundColor.push(color);
|
|
1528
|
+
} else {
|
|
1529
|
+
if (index > pieChartColorsLength) {
|
|
1530
|
+
index = index % pieChartColorsLength;
|
|
1531
|
+
}
|
|
1532
|
+
backgroundColor.push(PIE_CHART_COLORS[index]);
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
return backgroundColor;
|
|
1536
|
+
};
|
|
1537
|
+
ChartUtils.getColumn = (tables, tableId, columnKey) => {
|
|
1538
|
+
const table = getTableById(tables, tableId);
|
|
1539
|
+
return getTableColumnByKey(table, columnKey);
|
|
1540
|
+
};
|
|
1541
|
+
ChartUtils.formatEmptyName = (dataList, column_groupby_column_key, emptyName) => {
|
|
1542
|
+
if (!Array.isArray(dataList)) return [];
|
|
1543
|
+
let updatedStatistics = [];
|
|
1544
|
+
dataList.forEach(item => {
|
|
1545
|
+
let updated = {};
|
|
1546
|
+
if (!item.name) {
|
|
1547
|
+
updated.name = emptyName;
|
|
1548
|
+
}
|
|
1549
|
+
if (column_groupby_column_key && !item.group_name) {
|
|
1550
|
+
updated.group_name = emptyName;
|
|
1551
|
+
}
|
|
1552
|
+
updatedStatistics.push(Object.assign({}, item, updated));
|
|
1553
|
+
});
|
|
1554
|
+
return updatedStatistics;
|
|
1555
|
+
};
|
|
1556
|
+
ChartUtils.getStatisticColumns = table => {
|
|
1557
|
+
let {
|
|
1558
|
+
columns
|
|
1559
|
+
} = table;
|
|
1560
|
+
let unStatisticalColumns = [CellType.LONG_TEXT, CellType.IMAGE, CellType.FILE, CellType.CHECKBOX];
|
|
1561
|
+
return columns.filter(column => {
|
|
1562
|
+
return unStatisticalColumns.indexOf(column.type) === -1;
|
|
1563
|
+
});
|
|
1564
|
+
};
|
|
1565
|
+
ChartUtils.isChartEqual = (preChartElement, curChartElement) => {
|
|
1566
|
+
const elementType = preChartElement.config.type;
|
|
1567
|
+
if (elementType !== curChartElement.config.type) return false;
|
|
1568
|
+
return shallowEqual(preChartElement.config, curChartElement.config);
|
|
1569
|
+
};
|
|
1570
|
+
ChartUtils.isChartStyleChange = (preChartElement, curChartElement) => {
|
|
1571
|
+
const elementType = preChartElement.config.type;
|
|
1572
|
+
if (elementType !== curChartElement.config.type) return false;
|
|
1573
|
+
if (preChartElement.height.value !== curChartElement.height.value) return true;
|
|
1574
|
+
if (preChartElement.left_in_unit !== curChartElement.left_in_unit) return true;
|
|
1575
|
+
if (preChartElement.width_in_unit !== curChartElement.width_in_unit) return true;
|
|
1576
|
+
if (!ObjectUtils.isSameObject(preChartElement.style_config, curChartElement.style_config)) return true;
|
|
1577
|
+
return !CHART_STYLE_SETTING_KEYS.every(key => preChartElement.config[key] === curChartElement.config[key]);
|
|
1578
|
+
};
|
|
1579
|
+
ChartUtils.isChartTypeChange = (preChartElement, curChartElement) => {
|
|
1580
|
+
const elementType = preChartElement.config.type;
|
|
1581
|
+
if (elementType !== curChartElement.config.type) return true;
|
|
1582
|
+
return false;
|
|
1583
|
+
};
|
|
1584
|
+
ChartUtils.isChartSortChange = (preChartElement, curChartElement) => {
|
|
1585
|
+
return preChartElement.config.sort_type !== curChartElement.config.sort_type;
|
|
1586
|
+
};
|
|
1587
|
+
ChartUtils.isChartStyleChanged = (prevElement, currElement) => {
|
|
1588
|
+
const prevStyleConfig = prevElement && prevElement.style_config;
|
|
1589
|
+
const currStyleConfig = currElement && currElement.style_config;
|
|
1590
|
+
if (!prevStyleConfig && !currStyleConfig) {
|
|
1591
|
+
return false;
|
|
1592
|
+
}
|
|
1593
|
+
if (!prevStyleConfig || !currStyleConfig) {
|
|
1594
|
+
return true;
|
|
1595
|
+
}
|
|
1596
|
+
const {
|
|
1597
|
+
border: prevBorder,
|
|
1598
|
+
title: prevTitle
|
|
1599
|
+
} = prevStyleConfig;
|
|
1600
|
+
const {
|
|
1601
|
+
border: currBorder,
|
|
1602
|
+
title: currTitle
|
|
1603
|
+
} = currStyleConfig;
|
|
1604
|
+
return !shallowEqual(prevBorder, currBorder) || !shallowEqual(prevTitle, currTitle);
|
|
1605
|
+
};
|
|
1606
|
+
ChartUtils._isChartDataChange = (prevProps, currentProps) => {
|
|
1607
|
+
const {
|
|
1608
|
+
result: newData,
|
|
1609
|
+
chart
|
|
1610
|
+
} = prevProps;
|
|
1611
|
+
const {
|
|
1612
|
+
result: oldData
|
|
1613
|
+
} = currentProps;
|
|
1614
|
+
if (chart.config.type === CHART_TYPE.COMBINATION) {
|
|
1615
|
+
return _class._isCombinationDataChange(newData, oldData);
|
|
1616
|
+
}
|
|
1617
|
+
if (!newData && !oldData) return false;
|
|
1618
|
+
if (!newData && oldData || newData && !oldData) return true;
|
|
1619
|
+
let dataLength = newData === null || newData === void 0 ? void 0 : newData.length;
|
|
1620
|
+
if (dataLength !== (oldData === null || oldData === void 0 ? void 0 : oldData.length)) return true;
|
|
1621
|
+
for (let i = 0; i < dataLength; i++) {
|
|
1622
|
+
let newDataItem = newData[i];
|
|
1623
|
+
let oldDataItem = oldData[i];
|
|
1624
|
+
if (newDataItem.value !== oldDataItem.value) return true; // row's length
|
|
1625
|
+
if (newDataItem.name !== oldDataItem.name) return true;
|
|
1626
|
+
}
|
|
1627
|
+
for (let i = 0; i < dataLength; i++) {
|
|
1628
|
+
let newDataItemRows = newData[i].rows;
|
|
1629
|
+
let oldDataItemRows = oldData[i].rows;
|
|
1630
|
+
for (let j = 0; j < (newDataItemRows === null || newDataItemRows === void 0 ? void 0 : newDataItemRows.length) || 0; j++) {
|
|
1631
|
+
let newDataItemRow = newDataItemRows[j];
|
|
1632
|
+
let oldDataItemRow = oldDataItemRows[j];
|
|
1633
|
+
if (!shallowEqual(newDataItemRow, oldDataItemRow)) return true;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return false;
|
|
1637
|
+
};
|
|
1638
|
+
ChartUtils.isValidValue = value => {
|
|
1639
|
+
if (value === 0) return true;
|
|
1640
|
+
return Boolean(value);
|
|
1641
|
+
};
|
|
1642
|
+
ChartUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue) {
|
|
1643
|
+
let summaryMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'count';
|
|
1644
|
+
if (!summaryColumn) return summaryValue;
|
|
1645
|
+
if (!summaryValue && summaryValue !== 0) return summaryValue;
|
|
1646
|
+
if (summaryMethod.toUpperCase() === 'DISTINCT_VALUES') return summaryValue;
|
|
1647
|
+
const {
|
|
1648
|
+
data
|
|
1649
|
+
} = summaryColumn;
|
|
1650
|
+
if (_class.isDateSummaryColumn(summaryColumn)) {
|
|
1651
|
+
if (typeof summaryValue !== 'string') return summaryValue;
|
|
1652
|
+
|
|
1653
|
+
// Compatible with previous data
|
|
1654
|
+
const {
|
|
1655
|
+
format
|
|
1656
|
+
} = data || {
|
|
1657
|
+
format: 'YYYY-HH-MM'
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
// The date returned by db carries T and Z, so that there is a time difference in data formatting
|
|
1661
|
+
return getDateDisplayString(summaryValue.replace(/[T|Z]/g, ' '), format);
|
|
1662
|
+
}
|
|
1663
|
+
if (typeof summaryValue !== 'number') return summaryValue;
|
|
1664
|
+
return getNumberDisplayString(summaryValue, data || DEFAULT_NUMBER_FORMAT_OBJECT);
|
|
1665
|
+
};
|
|
1666
|
+
ChartUtils.isNumericSummaryColumn = summaryColumn => {
|
|
1667
|
+
if (!summaryColumn) return false;
|
|
1668
|
+
const {
|
|
1669
|
+
type
|
|
1670
|
+
} = summaryColumn;
|
|
1671
|
+
return type !== CellType.LINK && isNumericColumn(summaryColumn);
|
|
1672
|
+
};
|
|
1673
|
+
ChartUtils.isDateSummaryColumn = summaryColumn => {
|
|
1674
|
+
if (!summaryColumn) return false;
|
|
1675
|
+
const {
|
|
1676
|
+
type
|
|
1677
|
+
} = summaryColumn;
|
|
1678
|
+
return type !== CellType.LINK && isDateColumn(summaryColumn);
|
|
1679
|
+
};
|
|
1680
|
+
ChartUtils.getSummaryExplanation = chart => {
|
|
1681
|
+
const {
|
|
1682
|
+
config
|
|
1683
|
+
} = chart;
|
|
1684
|
+
const {
|
|
1685
|
+
type
|
|
1686
|
+
} = config;
|
|
1687
|
+
switch (type) {
|
|
1688
|
+
case CHART_TYPE.PIE:
|
|
1689
|
+
case CHART_TYPE.LINE:
|
|
1690
|
+
case CHART_TYPE.LINE_GROUP:
|
|
1691
|
+
case CHART_TYPE.RING:
|
|
1692
|
+
{
|
|
1693
|
+
return {
|
|
1694
|
+
count: intl.get('Count_the_number_of_records_in_each_group'),
|
|
1695
|
+
advanced: intl.get('Compute_the_sum_maximum_or_minimum_value_of_records_in_each_group_by_a_field')
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
case CHART_TYPE.BAR:
|
|
1699
|
+
case CHART_TYPE.BAR_GROUP:
|
|
1700
|
+
{
|
|
1701
|
+
return {
|
|
1702
|
+
count: intl.get('Group_the_records_according_to_the_vertical_axis_and_count_the_records_in_each_group'),
|
|
1703
|
+
advanced: intl.get('Group_the_records_according_to_the_vertical_axis_and_compute_the_sum_maximum_or_minimum_of_records_in_each_group_by_a_field')
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
default:
|
|
1707
|
+
{
|
|
1708
|
+
return {
|
|
1709
|
+
count: intl.get('Count_the_records'),
|
|
1710
|
+
advanced: intl.get('Compute_sum_max_min')
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
ChartUtils.getLabelFontSize = labelFontSize => {
|
|
1716
|
+
return isNumber(labelFontSize) ? labelFontSize : DEFAULT_LABEL_FONT_SIZE;
|
|
1717
|
+
};
|
|
1718
|
+
ChartUtils.getPieColor = (column, index, data) => {
|
|
1719
|
+
let {
|
|
1720
|
+
type: columnType,
|
|
1721
|
+
data: columnData
|
|
1722
|
+
} = column;
|
|
1723
|
+
if (columnType === 'single-select' || columnType === 'multiple-select') {
|
|
1724
|
+
if (columnData && columnData.options) {
|
|
1725
|
+
const selectedItem = columnData.options.find(item => {
|
|
1726
|
+
return item.name === data.name;
|
|
1727
|
+
}) || {};
|
|
1728
|
+
return selectedItem.color || '#dbdbdb';
|
|
1729
|
+
}
|
|
1730
|
+
} else {
|
|
1731
|
+
const pieChartColorsLength = PIE_CHART_COLORS.length - 1;
|
|
1732
|
+
const newIndex = index > pieChartColorsLength ? index % pieChartColorsLength : index;
|
|
1733
|
+
return PIE_CHART_COLORS[newIndex];
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
ChartUtils.formatPieChartData = (data, chart, tables) => {
|
|
1737
|
+
if (!Array.isArray(data) || data.length === 0 || !chart) {
|
|
1738
|
+
return {
|
|
1739
|
+
data: [],
|
|
1740
|
+
total: 0,
|
|
1741
|
+
colorSet: []
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
const {
|
|
1745
|
+
table_id,
|
|
1746
|
+
groupby_column_key,
|
|
1747
|
+
minimum_slice_percent
|
|
1748
|
+
} = chart.config;
|
|
1749
|
+
const table = getTableById(tables, table_id);
|
|
1750
|
+
const column = getColumnByKey(groupby_column_key, table ? table.columns : []);
|
|
1751
|
+
let sum = data.reduce((total, currentValue) => {
|
|
1752
|
+
return total += currentValue.value;
|
|
1753
|
+
}, 0);
|
|
1754
|
+
const minimumSlicePercentage = typeof minimum_slice_percent === 'number' ? minimum_slice_percent : 1.5;
|
|
1755
|
+
const threshold = sum * (minimumSlicePercentage / 100 || 0);
|
|
1756
|
+
let filteredItems = [];
|
|
1757
|
+
let colorSet = [];
|
|
1758
|
+
let filteredData = [];
|
|
1759
|
+
let rows = [];
|
|
1760
|
+
data.forEach((item, index) => {
|
|
1761
|
+
const value = item.value;
|
|
1762
|
+
if (value >= threshold) {
|
|
1763
|
+
item.percent = String(Number.parseFloat(value / sum * 100).toFixed(1)) + '%';
|
|
1764
|
+
const color = _class.getPieColor(column, index, item);
|
|
1765
|
+
item.color = color;
|
|
1766
|
+
colorSet.push(color);
|
|
1767
|
+
filteredData.push(item);
|
|
1768
|
+
} else {
|
|
1769
|
+
rows.push(...item.rows);
|
|
1770
|
+
filteredItems.push(item);
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
1773
|
+
if (filteredItems.length > 0) {
|
|
1774
|
+
const filteredSum = filteredItems.reduce((total, currentValue) => {
|
|
1775
|
+
return total += currentValue.value;
|
|
1776
|
+
}, 0);
|
|
1777
|
+
filteredData.push({
|
|
1778
|
+
name: '_Others',
|
|
1779
|
+
value: filteredSum,
|
|
1780
|
+
color: '#dbdbdb',
|
|
1781
|
+
percent: String(Number.parseFloat(filteredSum / sum * 100).toFixed(1)) + '%',
|
|
1782
|
+
rows
|
|
1783
|
+
});
|
|
1784
|
+
colorSet.push('#dbdbdb');
|
|
1785
|
+
}
|
|
1786
|
+
return {
|
|
1787
|
+
data: filteredData,
|
|
1788
|
+
total: sum,
|
|
1789
|
+
colorSet
|
|
1790
|
+
};
|
|
1791
|
+
};
|
|
1792
|
+
ChartUtils.initTotal = summaryMethod => {
|
|
1793
|
+
if (summaryMethod === 'SUM' || summaryMethod === 'DISTINCT_VALUES') return 0;
|
|
1794
|
+
return null;
|
|
1795
|
+
};
|
|
1796
|
+
ChartUtils.getCurrentTheme = themeName => {
|
|
1797
|
+
if (themeName) {
|
|
1798
|
+
const currentColorTheme = STYLE_COLORS.find(item => item.name === themeName);
|
|
1799
|
+
return currentColorTheme;
|
|
1800
|
+
}
|
|
1801
|
+
return STYLE_COLORS[0];
|
|
1802
|
+
};
|
|
1803
|
+
export default ChartUtils;
|