sea-chart 1.1.13 → 1.1.15

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.
@@ -50,6 +50,9 @@ class StatisticRecordDialog extends React.Component {
50
50
  const detailFilterConditions = {
51
51
  filters: getFilterConditions(statisticRecord, chart, this.table.columns)
52
52
  };
53
+ if ((statisticRecord === null || statisticRecord === void 0 ? void 0 : statisticRecord.name) === '_Others') {
54
+ detailFilterConditions.filter_conjunction = 'Or';
55
+ }
53
56
  context.api.customQueryRows(currentElementId, detailFilterConditions).then(res => {
54
57
  const {
55
58
  results: rows
@@ -10,16 +10,17 @@ import ObjectUtils from '../object-utils';
10
10
  import intl from '../../intl';
11
11
  import context from '../../context';
12
12
  import { isValidCollaboratorEmail } from '../collaborator';
13
+ import { formatRowTotal } from '../index';
13
14
  export function findIfColumnDataIsArray(column) {
14
15
  // link-formula may also be an array type column
15
16
  let isGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[column.type];
16
17
  if (column.type === CellType.LINK_FORMULA) {
17
18
  const {
18
- array_type,
19
19
  result_type
20
20
  } = column.data || {};
21
- // collaborator, creator or last-modifier
22
- if (COLLABORATOR_COLUMN_TYPES.includes(array_type) && result_type === 'array') {
21
+ // linked date need to be handled separately, cause it has dateGranularity
22
+ // it's no longer an array after "getLabelFromDB" processing
23
+ if (result_type === 'array' && column.data.array_type !== 'date') {
23
24
  isGroupbyColumnDataAsAnArray = true;
24
25
  }
25
26
  }
@@ -307,7 +308,7 @@ BaseUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue)
307
308
  // The date returned by db carries T and Z, so that there is a time difference in data formatting
308
309
  return getDateDisplayString(summaryValue.replace(/[T|Z]/g, ' '), format);
309
310
  }
310
- if (typeof summaryValue !== 'number') return summaryValue;
311
+ if (typeof summaryValue !== 'number') return formatRowTotal(summaryValue);
311
312
  return getNumberDisplayString(summaryValue, data || DEFAULT_NUMBER_FORMAT_OBJECT);
312
313
  };
313
314
  BaseUtils.isNumericSummaryColumn = summaryColumn => {
@@ -615,7 +616,7 @@ BaseUtils.formatPieChartData = (data, chart, tables, currentTheme, useColumnColo
615
616
  };
616
617
  // table
617
618
  // format SINGLE_SELECT, LAST_MODIFIER, CREATOR, COLLABORATOR, DATE, NUMBER
618
- BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorKey, isScatterChart) => {
619
+ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorKey, isScatterChart, isNameField) => {
619
620
  let {
620
621
  type: columnType,
621
622
  data: columnData
@@ -626,11 +627,13 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
626
627
  let selectedOption = getOption(options, name);
627
628
  let {
628
629
  name: optionName,
629
- color: optionColor
630
+ color: optionColor,
631
+ id
630
632
  } = selectedOption || {};
631
633
  if (selectedOption) {
632
634
  result[nameKey] = optionName;
633
635
  result[colorKey] = optionColor;
636
+ isNameField && (result.original_name = id);
634
637
  } else {
635
638
  result[colorKey] = '#dbdbdb';
636
639
  }
@@ -645,6 +648,7 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
645
648
  return;
646
649
  }
647
650
  result[nameKey] = users.map(user => user.name).join(', ');
651
+ isNameField && (result.original_name = users.map(user => user.email).join(', '));
648
652
  });
649
653
  } else if (columnType === CellType.CREATOR || columnType === CellType.LAST_MODIFIER) {
650
654
  // move collaborators logic to collaborator-utils.js
@@ -658,10 +662,12 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
658
662
  return;
659
663
  }
660
664
  result[nameKey] = users.map(user => user.name).join(', ');
665
+ isNameField && (result.original_name = users.map(user => user.email).join(', '));
661
666
  });
662
667
  } else if (columnType === CellType.NUMBER) {
663
668
  let valueNumber = parseFloat(name);
664
669
  result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
670
+ isNameField && (result.original_name = name);
665
671
  } else if (columnType === CellType.DATE) {
666
672
  name = name + '';
667
673
  if (name && name.split('-').length === 3) {
@@ -679,11 +685,21 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
679
685
  let valueNumber = parseFloat(name);
680
686
  result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
681
687
  }
688
+ const {
689
+ array_data,
690
+ array_type
691
+ } = columnData;
692
+ const linkedColumn = {
693
+ ...column,
694
+ type: array_type,
695
+ data: array_data
696
+ };
697
+ return _BaseUtils.updateTableViewListItemNameAndColor(result, linkedColumn, nameKey, colorKey, isScatterChart);
682
698
  }
683
699
  };
684
- BaseUtils.updateTableViewList = (result, column, nameKey, colorKey, isScatterChart) => {
700
+ BaseUtils.updateTableViewList = (result, column, nameKey, colorKey, isScatterChart, isNameField) => {
685
701
  result.forEach(result => {
686
- _BaseUtils.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey, isScatterChart);
702
+ _BaseUtils.updateTableViewListItemNameAndColor(result, column, nameKey, colorKey, isScatterChart, isNameField);
687
703
  });
688
704
  };
689
705
  // sort chart
@@ -1,16 +1,15 @@
1
1
  var _SQLStatisticsUtils;
2
2
  import dayjs from 'dayjs';
3
- import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber, DateUtils, COLLABORATOR_COLUMN_TYPES } from 'dtable-utils';
3
+ import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber, DateUtils } from 'dtable-utils';
4
4
  import { isObject } from 'lodash';
5
5
  import { cloneDeep } from 'lodash-es';
6
- import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS, TREND_TYPES } from '../../constants';
6
+ import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS, TREND_TYPES, CHART_STYLE_COLORS } from '../../constants';
7
7
  import { chartColumn2SqlColumn, summaryMethodColumn2SqlColumn } from '../sql';
8
8
  import { getClientLinkDisplayString } from '../cell-format-utils';
9
9
  import { column2SqlColumn } from '../sql/column-2-sql-column';
10
10
  import { formatNumericValue, getFormattedValue, getSummaryResult } from '../column-utils';
11
11
  import { getCompareDate } from '../trend-utils';
12
12
  import intl from '../../intl';
13
- import { getUsers } from '../collaborator-utils';
14
13
  import BaseUtils, { findIfColumnDataIsArray } from './base-utils';
15
14
  class SQLStatisticsUtils {}
16
15
  _SQLStatisticsUtils = SQLStatisticsUtils;
@@ -30,14 +29,8 @@ SQLStatisticsUtils.getGroupLabelFromDB = async (cellValue, column, chart, isPivo
30
29
  case CellType.CTIME:
31
30
  case CellType.MTIME:
32
31
  {
33
- if (!dateGranularity) {
34
- return cellValue || null;
35
- }
36
- if (dateGranularity.toUpperCase() === 'QUARTER') {
37
- // TODO: fix the unknown word 'QUARTAR'
38
- return DateUtils.getDateByGranularity(cellValue, 'QUARTAR');
39
- }
40
- return DateUtils.getDateByGranularity(cellValue, dateGranularity);
32
+ // handled in sql query result
33
+ return cellValue;
41
34
  }
42
35
  case CellType.NUMBER:
43
36
  {
@@ -84,14 +77,13 @@ SQLStatisticsUtils.getGroupLabelFromDB = async (cellValue, column, chart, isPivo
84
77
  return DateUtils.getDateByGranularity(validValue, dateGranularity);
85
78
  }
86
79
 
87
- // collaborator, creator or last-modifier
88
- if (COLLABORATOR_COLUMN_TYPES.includes(array_type) && result_type === 'array' && !isPivot) {
89
- const users = await getUsers(validValue);
90
- return users.map(user => user.name);
91
- } else if (result_type === 'array' && isPivot) {
80
+ // handles mutiple select
81
+ if (result_type === 'array') {
92
82
  return cellValue;
93
83
  }
94
- if (!validValue && validValue !== 0) return null;
84
+ if (!validValue && validValue !== 0) {
85
+ return null;
86
+ }
95
87
  return validValue;
96
88
  }
97
89
  case CellType.LINK:
@@ -371,14 +363,32 @@ SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript = async (chart, sqlRows
371
363
  for (const row of newSqlRows) {
372
364
  const total = row[sqlSummaryColumnKey] || 0;
373
365
  allTotal += total;
366
+ const name = await _SQLStatisticsUtils.getGroupLabelFromDB(row[sqlGroupbyColumnKey], groupbyColumn, chart.config, true);
374
367
  pivot_rows.push({
375
- name: await _SQLStatisticsUtils.getGroupLabelFromDB(row[sqlGroupbyColumnKey], groupbyColumn, chart.config, true),
368
+ name,
376
369
  rows: [],
377
370
  total: {
378
371
  total
379
372
  }
380
373
  });
381
374
  }
375
+ if (groupbyColumn.type === CellType.LINK_FORMULA && groupbyColumn.data.array_type === 'date') {
376
+ pivot_rows = pivot_rows.reduce((acc, item) => {
377
+ const {
378
+ name,
379
+ total: {
380
+ total
381
+ }
382
+ } = item;
383
+ const index = acc.findIndex(r => r.name === name);
384
+ if (index < 0) {
385
+ acc.push(item);
386
+ } else {
387
+ acc[index].total.total += total;
388
+ }
389
+ return acc;
390
+ }, []);
391
+ }
382
392
  BaseUtils.sortCharts(pivot_rows, groupbyColumn, 'name', true);
383
393
  return {
384
394
  pivot_columns,
@@ -432,6 +442,23 @@ SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript = async (chart, sqlRows
432
442
  total: rowTotal
433
443
  });
434
444
  }
445
+ if (groupbyColumn.type === CellType.LINK_FORMULA && groupbyColumn.data.array_type === 'date') {
446
+ pivot_rows = pivot_rows.reduce((acc, item) => {
447
+ const {
448
+ name,
449
+ total: {
450
+ total
451
+ }
452
+ } = item;
453
+ const index = acc.findIndex(r => r.name === name);
454
+ if (index < 0) {
455
+ acc.push(item);
456
+ } else {
457
+ acc[index].total.total += total;
458
+ }
459
+ return acc;
460
+ }, []);
461
+ }
435
462
  if (pivot_columns.length < 2) {
436
463
  const pivot_column = pivot_columns[0];
437
464
  const {
@@ -486,14 +513,15 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = async (chart, sqlRows
486
513
  let isRowGroupbyColumnDataAsAnArray, isGroupbyColumnDataAsAnArray;
487
514
 
488
515
  // Group by column
489
- if (isGroupByColumnLinkFormula) {
516
+ // linked date need to be handled separately, cause it has dateGranularity and no longer an array after processed by "getLabelFromDB"
517
+ if (isGroupByColumnLinkFormula && groupbyColumn.data.array_type !== 'date') {
490
518
  isGroupbyColumnDataAsAnArray = true;
491
519
  } else {
492
520
  isGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
493
521
  }
494
522
 
495
523
  // column group by column
496
- if (isColumnGroupByColumnLinkFormula) {
524
+ if (isColumnGroupByColumnLinkFormula && groupbyColumn.data.array_type !== 'date') {
497
525
  isRowGroupbyColumnDataAsAnArray = true;
498
526
  } else {
499
527
  isRowGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[columnGroupbyColumn.type];
@@ -653,7 +681,8 @@ SQLStatisticsUtils.basicChartSQLResult2JavaScript = async (chart, sqlRows, chart
653
681
  itemRow.value = itemRow.value + summaryValue;
654
682
  }
655
683
  } else {
656
- key.forEach(item => {
684
+ // in case of multiple values, The index of the raw value array correspond one-to-one with the index of the formatted array
685
+ key.forEach((item, index) => {
657
686
  let itemIdx = result.findIndex(v => v.name === item);
658
687
  if (itemIdx < 0) {
659
688
  result.push({
@@ -691,7 +720,7 @@ SQLStatisticsUtils.basicChartSQLResult2JavaScript = async (chart, sqlRows, chart
691
720
  }
692
721
  }
693
722
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
694
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
723
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color', false, true);
695
724
  if (SUPPORT_DATA_SORT_CHART_TYPES.includes(type) && sort_type) {
696
725
  BaseUtils.sortChartData(result, sort_type);
697
726
  return result;
@@ -781,8 +810,7 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = async (chart, sqlRows, char
781
810
  names.forEach(name => {
782
811
  takenApart.push({
783
812
  ...item,
784
- name,
785
- original_name: name
813
+ name
786
814
  });
787
815
  });
788
816
  });
@@ -804,7 +832,7 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = async (chart, sqlRows, char
804
832
  result = assembled;
805
833
  }
806
834
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
807
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
835
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '', false, true);
808
836
  return result;
809
837
  };
810
838
  SQLStatisticsUtils.compareSQLResult2Javascript = async (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -1114,7 +1142,7 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = async (chart, sqlRows, char
1114
1142
  }
1115
1143
  }
1116
1144
  }
1117
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
1145
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '', false, true);
1118
1146
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
1119
1147
  return result;
1120
1148
  };
@@ -1218,8 +1246,8 @@ SQLStatisticsUtils.groupingTwoDimensionChartSQLResult2JavaScript = async (chart,
1218
1246
  }
1219
1247
  }
1220
1248
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
1221
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
1222
- BaseUtils.updateTableViewList(result, columnGroupbyColumn, 'group_name', 'group_color');
1249
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color', false, true);
1250
+ BaseUtils.updateTableViewList(result, columnGroupbyColumn, 'group_name', 'group_color', false, false);
1223
1251
  return result;
1224
1252
  };
1225
1253
  SQLStatisticsUtils.groupingChartSQLResult2JavaScript = async (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -1274,7 +1302,7 @@ SQLStatisticsUtils.groupingChartSQLResult2JavaScript = async (chart, sqlRows, ch
1274
1302
  }
1275
1303
  }
1276
1304
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
1277
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
1305
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color', false, true);
1278
1306
  return result;
1279
1307
  }
1280
1308
  if (!columnGroupbyColumn) {
@@ -1374,14 +1402,16 @@ SQLStatisticsUtils.mirrorMapChartSQLResult2JavaScript = async (chart, sqlRows, c
1374
1402
  value: equal2GroupData0 ? value : 0,
1375
1403
  formatted_value: equal2GroupData0 ? formattedValue : 0,
1376
1404
  group_name: groupData[0].name,
1377
- color: groupData[0].color
1405
+ color: groupData[0].color,
1406
+ rows: [item]
1378
1407
  }, {
1379
1408
  name: label,
1380
1409
  original_name: item[column_key],
1381
1410
  value: equal2GroupData1 ? value : 0,
1382
1411
  formatted_value: equal2GroupData1 ? formattedValue : 0,
1383
1412
  group_name: groupData[1].name,
1384
- color: groupData[1].color
1413
+ color: groupData[1].color,
1414
+ rows: [item]
1385
1415
  });
1386
1416
  }
1387
1417
  }
@@ -1625,48 +1655,94 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, chartSQLMap, tables)
1625
1655
  target_column,
1626
1656
  column_groupby_column
1627
1657
  } = sqlColumns;
1628
-
1629
- // format the fetched value
1630
- BaseUtils.updateTableViewList(sqlRows, name_column, name_column.key, 'color');
1631
- if (sqlColumnGroupByColumnKey) BaseUtils.updateTableViewList(sqlRows, column_groupby_column, sqlColumnGroupByColumnKey, 'color');
1632
1658
  const res = [];
1633
1659
  let summedSqlRows;
1660
+ const nameColumnDataAsAnArray = findIfColumnDataIsArray(name_column);
1634
1661
  if (!isGroup) {
1635
- const sumSqlRows = sqlRows.reduce((acc, row) => {
1636
- const nameValue = _SQLStatisticsUtils._get_completeness_name(row, name_column);
1637
- if (!acc[nameValue]) {
1638
- acc[nameValue] = row;
1639
- } else {
1640
- const accRow = acc[nameValue];
1641
- Object.keys(row).forEach(key => {
1642
- if (key === name_column.key) return;
1643
- accRow[key] = accRow[key] + row[key];
1662
+ if (nameColumnDataAsAnArray) {
1663
+ const sumSqlRows = sqlRows.reduce((acc, row) => {
1664
+ const names = row[name_column.key];
1665
+ names.forEach(name => {
1666
+ if (!acc[name]) {
1667
+ row[name_column.key] = name;
1668
+ acc[name] = row;
1669
+ } else {
1670
+ const accRow = acc[name];
1671
+ Object.keys(row).forEach(key => {
1672
+ if (key === completed_column.key || key === target_column.key) {
1673
+ accRow[key] = accRow[key] + row[key];
1674
+ }
1675
+ });
1676
+ }
1644
1677
  });
1645
- }
1646
- return acc;
1647
- }, {});
1648
- summedSqlRows = Object.values(sumSqlRows);
1678
+ return acc;
1679
+ }, {});
1680
+ summedSqlRows = Object.values(sumSqlRows);
1681
+ } else {
1682
+ const sumSqlRows = sqlRows.reduce((acc, row) => {
1683
+ const nameValue = row[name_column.key];
1684
+ if (!acc[nameValue]) {
1685
+ acc[nameValue] = row;
1686
+ } else {
1687
+ const accRow = acc[nameValue];
1688
+ Object.keys(row).forEach(key => {
1689
+ if (key === completed_column.key || key === target_column.key) {
1690
+ accRow[key] = accRow[key] + row[key];
1691
+ }
1692
+ });
1693
+ }
1694
+ return acc;
1695
+ }, {});
1696
+ summedSqlRows = Object.values(sumSqlRows);
1697
+ }
1649
1698
  } else {
1650
- const sumSqlRowsWithGroupBy = sqlRows.reduce((acc, row) => {
1651
- const nameValue = _SQLStatisticsUtils._get_completeness_name(row, name_column);
1652
- const groupby = row[sqlColumnGroupByColumnKey];
1653
- const key = "".concat(nameValue, "_").concat(groupby);
1654
- if (!acc[key]) {
1655
- acc[key] = row;
1656
- } else {
1657
- const accRow = acc[key];
1658
- Object.keys(row).forEach(key => {
1659
- if (key === completed_column.key || key === target_column.key) {
1660
- accRow[key] = accRow[key] + row[key];
1699
+ if (nameColumnDataAsAnArray) {
1700
+ const sumSqlRows = sqlRows.reduce((acc, row) => {
1701
+ const names = row[name_column.key];
1702
+ const groupby = row[sqlColumnGroupByColumnKey];
1703
+ names.forEach(name => {
1704
+ const key = "".concat(name, "_").concat(groupby);
1705
+ if (!acc[key]) {
1706
+ row[name_column.key] = name;
1707
+ acc[key] = row;
1708
+ } else {
1709
+ const accRow = acc[key];
1710
+ Object.keys(row).forEach(k => {
1711
+ if (key === completed_column.key || key === target_column.key) {
1712
+ accRow[key] = accRow[key] + row[key];
1713
+ }
1714
+ });
1661
1715
  }
1662
1716
  });
1663
- }
1664
- return acc;
1665
- }, {});
1666
- summedSqlRows = Object.values(sumSqlRowsWithGroupBy);
1717
+ return acc;
1718
+ }, {});
1719
+ summedSqlRows = Object.values(sumSqlRows);
1720
+ } else {
1721
+ const sumSqlRows = sqlRows.reduce((acc, row) => {
1722
+ const nameValue = row[name_column.key];
1723
+ const groupby = row[sqlColumnGroupByColumnKey];
1724
+ const key = "".concat(nameValue, "_").concat(groupby);
1725
+ if (!acc[key]) {
1726
+ acc[key] = row;
1727
+ } else {
1728
+ const accRow = acc[key];
1729
+ Object.keys(row).forEach(key => {
1730
+ if (key === completed_column.key || key === target_column.key) {
1731
+ accRow[key] = accRow[key] + row[key];
1732
+ }
1733
+ });
1734
+ }
1735
+ return acc;
1736
+ }, {});
1737
+ summedSqlRows = Object.values(sumSqlRows);
1738
+ }
1667
1739
  }
1740
+
1741
+ // format the fetched value
1742
+ BaseUtils.updateTableViewList(sqlRows, name_column, name_column.key, 'color', false, true);
1743
+ if (sqlColumnGroupByColumnKey) BaseUtils.updateTableViewList(sqlRows, column_groupby_column, sqlColumnGroupByColumnKey, 'color', false, false);
1668
1744
  summedSqlRows.forEach(row => {
1669
- const nameValue = _SQLStatisticsUtils._get_completeness_name(row, name_column);
1745
+ const nameValue = row[name_column.key];
1670
1746
  let targetValue;
1671
1747
  let completedValue;
1672
1748
  let groupby;
@@ -1686,15 +1762,20 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, chartSQLMap, tables)
1686
1762
  } else {
1687
1763
  completedRate = (completedValue / targetValue * 100).toFixed(0);
1688
1764
  }
1765
+ const {
1766
+ original_name
1767
+ } = row;
1689
1768
  res.push({
1690
1769
  name: nameValue,
1770
+ original_name,
1691
1771
  group_name: 'completed',
1692
1772
  groupby,
1693
- color: row.color,
1773
+ color: row.color || CHART_STYLE_COLORS[0],
1694
1774
  value: completedValue
1695
1775
  });
1696
1776
  res.push({
1697
1777
  name: nameValue,
1778
+ original_name,
1698
1779
  group_name: 'rest',
1699
1780
  value: Math.max(targetValue - completedValue, 0),
1700
1781
  groupby,
@@ -1727,9 +1808,9 @@ SQLStatisticsUtils.scatterSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, c
1727
1808
  // format sql rows
1728
1809
  const originalSqlRows = cloneDeep(sqlRows);
1729
1810
  const isScatter = true;
1730
- BaseUtils.updateTableViewList(sqlRows, groupbyColumn, groupbyColumn.key, 'color', isScatter);
1731
- BaseUtils.updateTableViewList(sqlRows, summaryColumn, summaryColumn.key, 'color', isScatter);
1732
- if (sqlColumnGroupbyColumnKey) BaseUtils.updateTableViewList(sqlRows, columnGroupbyColumn, sqlColumnGroupbyColumnKey, 'color');
1811
+ BaseUtils.updateTableViewList(sqlRows, groupbyColumn, groupbyColumn.key, 'color', isScatter, true);
1812
+ BaseUtils.updateTableViewList(sqlRows, summaryColumn, summaryColumn.key, 'color', isScatter, true);
1813
+ if (sqlColumnGroupbyColumnKey) BaseUtils.updateTableViewList(sqlRows, columnGroupbyColumn, sqlColumnGroupbyColumnKey, 'color', isScatter, false);
1733
1814
  const res = [];
1734
1815
  sqlRows.forEach((row, index) => {
1735
1816
  const xValue = row[sqlXColumnKey] ? '' + row[sqlXColumnKey] : intl.get('Empty');
@@ -1744,6 +1825,7 @@ SQLStatisticsUtils.scatterSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, c
1744
1825
  value: yValue,
1745
1826
  groupby,
1746
1827
  original_value: {
1828
+ rows: [originalSqlRow],
1747
1829
  name: originalXValue,
1748
1830
  value: originalYValue,
1749
1831
  groupby: originalGroupby
@@ -14,6 +14,13 @@ export { getDateColumnFormat, isCheckboxColumn, getColumnByKey, isStatisticMapCo
14
14
  export { generatorKey } from './key-generator';
15
15
  export { translateCalendar } from './date-translate';
16
16
  export { isFunction } from './common-utils';
17
+ export function formatRowTotal(rowTotal) {
18
+ if (rowTotal % 1 !== 0) {
19
+ return rowTotal.toFixed(2);
20
+ } else {
21
+ return rowTotal;
22
+ }
23
+ }
17
24
 
18
25
  /**
19
26
  * return a deep cloned list sorted by the given list
@@ -12,7 +12,7 @@ import Highlighter from '../components/highlighter/highlighter';
12
12
  import DigitalSignUtils from '../utils/digital-sign-utils';
13
13
  import { getColumnByKey } from '../utils/column-utils';
14
14
  import context from '../context';
15
- import { xAxisMap, groupAxisMap } from '../constants';
15
+ import { xAxisMap, groupAxisMap, COMPLTETELESS_CHART_TYPES } from '../constants';
16
16
  export const UNSHOW_COLUMN_TYPE = [CellType.LINK, CellType.LONG_TEXT, CellType.FORMULA, CellType.LINK_FORMULA];
17
17
  export const getCellRecordWidth = column => {
18
18
  let {
@@ -502,19 +502,41 @@ const filterPredicateMap = {
502
502
  [CellType.BOOL]: 'is'
503
503
  };
504
504
  const USE_OPTION_ID_CELL_TYPES = [CellType.SINGLE_SELECT, CellType.MULTIPLE_SELECT];
505
- const getFilterByColumnType = (columnKey, columns, value) => {
505
+ const getFilterByColumnType = (columnKey, columns, value, rows) => {
506
+ if (!rows) rows = [];
506
507
  const filter = {
507
508
  column_key: columnKey || ''
508
509
  };
509
510
  const column = getColumnByKey(columnKey, columns);
510
- if (column && (isDateColumn(column) || (column === null || column === void 0 ? void 0 : column.type) === CellType.GEOLOCATION)) {
511
+ if (!column) {
512
+ return filter;
513
+ }
514
+ let type = column.type;
515
+ if (type === CellType.LINK_FORMULA) {
516
+ type = column.data.array_type;
517
+ const correctRow = rows.find(r => columnKey in r);
518
+ value = correctRow && correctRow[columnKey];
519
+ Array.isArray(value) && (value = value[0]);
520
+ }
521
+ if (type === CellType.FORMULA) {
522
+ type = column.data.result_type;
523
+ const correctRow = rows.find(r => columnKey in r);
524
+ value = correctRow && correctRow[columnKey];
525
+ }
526
+
527
+ // pie chart and ring chart
528
+ if (value === '_Others') {
529
+ const correctRow = rows.find(r => columnKey in r);
530
+ value = correctRow && correctRow[columnKey];
531
+ }
532
+ if (column && [CellType.GEOLOCATION, CellType.DATE].includes(type)) {
511
533
  filter['value'] = value;
512
534
  return filter;
513
535
  }
514
536
  if (typeof value === 'string') {
515
537
  value = value.trim();
516
538
  }
517
- if (USE_OPTION_ID_CELL_TYPES.includes(column === null || column === void 0 ? void 0 : column.type)) {
539
+ if (USE_OPTION_ID_CELL_TYPES.includes(column.type)) {
518
540
  const options = getColumnOptions(column);
519
541
  // name may contains spaces
520
542
  // value maybe id or name, find option by name or id
@@ -524,12 +546,13 @@ const getFilterByColumnType = (columnKey, columns, value) => {
524
546
  // value may contains spaces
525
547
  filter['filter_term'] = value;
526
548
  }
527
- filter['filter_predicate'] = filterPredicateMap[column === null || column === void 0 ? void 0 : column.type];
549
+ filter['filter_predicate'] = filterPredicateMap[type];
528
550
  return filter;
529
551
  };
530
552
  export const getFilterConditions = function (statisticRecord, chart) {
531
553
  let columns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
532
554
  const {
555
+ original_name = '',
533
556
  name = '',
534
557
  group_name = '',
535
558
  groupby = '',
@@ -559,18 +582,28 @@ export const getFilterConditions = function (statisticRecord, chart) {
559
582
  }
560
583
  });
561
584
  if (xValueList.length === 1) {
562
- const columnFilter = getFilterByColumnType(config[columnKey], columns, xValueList[0]);
585
+ const columnFilter = getFilterByColumnType(config[columnKey], columns, xValueList[0], rows);
563
586
  filters.push(columnFilter);
564
587
  }
565
588
  if (yValueList.length === 1) {
566
- const columnFilter = getFilterByColumnType(config[groupColumnKey], columns, yValueList[0]);
589
+ const columnFilter = getFilterByColumnType(config[groupColumnKey], columns, yValueList[0], rows);
567
590
  filters.push(columnFilter);
568
591
  }
569
592
  } else {
570
- const columnFilter = getFilterByColumnType(config[columnKey], columns, name);
571
- filters.push(columnFilter);
593
+ // pie and ring chart
594
+ if (name === '_Others') {
595
+ const columnFilters = rows.map(r => getFilterByColumnType(config[columnKey], columns, name, [r]));
596
+ filters.push(...columnFilters);
597
+ } else {
598
+ const columnFilter = getFilterByColumnType(config[columnKey], columns, original_name || name, rows);
599
+ filters.push(columnFilter);
600
+ }
572
601
  if (groupColumnKey && config[groupColumnKey]) {
573
- const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, group_name || groupby);
602
+ let groupNameFiled = group_name || groupby;
603
+ if (COMPLTETELESS_CHART_TYPES.includes(type)) {
604
+ groupNameFiled = groupby;
605
+ }
606
+ const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, groupNameFiled);
574
607
  filters.push(groupColumnFilter);
575
608
  }
576
609
  }
@@ -152,7 +152,8 @@ export default function Completeness(_ref) {
152
152
  return () => {
153
153
  currentChart.chart.destroy();
154
154
  };
155
- }, [chart, chartColorTheme, data, globalTheme, summaryColumn, tables, toggleRecords]);
155
+ // eslint-disable-next-line react-hooks/exhaustive-deps
156
+ }, [chart, chartColorTheme, data, globalTheme, summaryColumn, tables]);
156
157
  return /*#__PURE__*/React.createElement("div", {
157
158
  className: classnames('sea-chart-completeness-chart sea-chart-container', {
158
159
  'show-x-axis-label': (_chartRef$current = chartRef.current) === null || _chartRef$current === void 0 ? void 0 : _chartRef$current.isShowXAxisLabel(chart),
@@ -142,7 +142,6 @@ class Pie extends ChartComponent {
142
142
  globalTheme
143
143
  } = this.props;
144
144
  const theme = CHART_THEME_COLOR[globalTheme];
145
- const item = evt.data.data;
146
145
  this.currentChart.label('name*value*percent', (name, value, percent) => {
147
146
  let displayValue;
148
147
  displayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, value, summaryMethod);
@@ -8,6 +8,7 @@ class Table extends PureComponent {
8
8
  constructor() {
9
9
  super(...arguments);
10
10
  this.toggleRecords = (cell, selectedCell) => {
11
+ if (!cell.rows || !cell.rows.length) return;
11
12
  cell && (cell.isPivot = true);
12
13
  this.props.toggleRecords(cell, selectedCell);
13
14
  };
@@ -1,7 +1,7 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import { isNumber } from 'dtable-utils';
4
- import { BaseUtils } from '../../../utils';
4
+ import { BaseUtils, formatRowTotal } from '../../../utils';
5
5
  import intl from '../../../intl';
6
6
  import { CHART_THEME_COLOR } from '../../../constants';
7
7
  import PivotTableDisplayName from './pivot-table-display-name';
@@ -195,8 +195,8 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
195
195
  })
196
196
  // onClick={() => this.toggleRecords({ rows, name: rowItem?.name, total: rowTotal }, { rowIdx })}
197
197
  ,
198
- title: rowTotal ? rowTotal : 0
199
- }, rowTotal ? rowTotal : /*#__PURE__*/React.createElement("i", null, "0"), /*#__PURE__*/React.createElement("span", {
198
+ title: rowTotal ? formatRowTotal(rowTotal) : 0
199
+ }, rowTotal ? formatRowTotal(rowTotal) : /*#__PURE__*/React.createElement("i", null, "0"), /*#__PURE__*/React.createElement("span", {
200
200
  className: classnames({
201
201
  'selected-pivot-cell-border': isSelectedTotalCell
202
202
  })
@@ -206,7 +206,6 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
206
206
  'selected-pivot-cell-left': isSelectRowTotalCellRight
207
207
  })
208
208
  }, /*#__PURE__*/React.createElement("div", null, intl.get('Total'))), Array.isArray(pivot_columns) && pivot_columns.map((c, index) => {
209
- const pivotColumnCell = pivotColumnCells[index];
210
209
  const pivotColumnTotal = pivot_columns_total[c.key];
211
210
  const column = chartTableColumns.find(column => column.key === c.key);
212
211
  const totalDisplayValue = BaseUtils.getSummaryValueDisplayString(column, pivotColumnTotal, this.summaryColumnsMethodMap[c.key]);
@@ -235,8 +234,8 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
235
234
  })
236
235
  // onClick={() => this.toggleRecords({ rows: lastRows, total: lastRowTotal }, { rowIdx: pivot_rows.length, cellIdx: pivot_columns?.length })}
237
236
  ,
238
- title: lastRowTotal
239
- }, BaseUtils.isValidValue(lastRowTotal, display_empty) ? lastRowTotal : /*#__PURE__*/React.createElement("i", null))));
237
+ title: formatRowTotal(lastRowTotal)
238
+ }, BaseUtils.isValidValue(lastRowTotal, display_empty) ? formatRowTotal(lastRowTotal) : /*#__PURE__*/React.createElement("i", null))));
240
239
  };
241
240
  this.init(_props);
242
241
  }
@@ -1,7 +1,7 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import { CellType, isNumber } from 'dtable-utils';
4
- import { BaseUtils } from '../../../utils';
4
+ import { BaseUtils, formatRowTotal } from '../../../utils';
5
5
  import intl from '../../../intl';
6
6
  import { CHART_SUMMARY_TYPE, CHART_THEME_COLOR } from '../../../constants';
7
7
  import PivotTableDisplayName from './pivot-table-display-name';
@@ -298,7 +298,7 @@ class TwoDimensionTable extends PureComponent {
298
298
  cellIdx: cells.length
299
299
  }),
300
300
  title: rowTotal
301
- }, BaseUtils.isValidValue(rowTotal, display_empty) ? rowTotal : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
301
+ }, BaseUtils.isValidValue(rowTotal, display_empty) ? formatRowTotal(rowTotal) : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
302
302
  className: classnames({
303
303
  'selected-pivot-cell-border': isSelectedTotalCell
304
304
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",