sea-chart 0.0.79 → 0.0.80

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.
@@ -0,0 +1,27 @@
1
+ import _DTableSelect from "dtable-ui-component/lib/DTableSelect";
2
+ import React from 'react';
3
+ import { FormGroup, Label } from 'reactstrap';
4
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
5
+ import intl from '../../intl';
6
+ export default function ColorSelector(_ref) {
7
+ let {
8
+ colorTheme,
9
+ onChange
10
+ } = _ref;
11
+ const options = [{
12
+ value: STACK_AND_PIE_CHART_THEMES_OPTIONS.DEFAULT,
13
+ label: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, intl.get('Use_default_color')))
14
+ }, {
15
+ value: STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS,
16
+ label: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, intl.get('Use_colors_in_single_select_solumn')))
17
+ }];
18
+ const selectedOption = options.find(option => option.value === colorTheme);
19
+ const handleChange = selectedOption => {
20
+ onChange(selectedOption.value);
21
+ };
22
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormGroup, null, /*#__PURE__*/React.createElement(Label, null, intl.get('Color')), /*#__PURE__*/React.createElement(_DTableSelect, {
23
+ value: selectedOption,
24
+ onChange: handleChange,
25
+ options: options
26
+ })));
27
+ }
@@ -1,4 +1,8 @@
1
1
  import { CellType, FILTER_PREDICATE_TYPE } from 'dtable-utils';
2
+ export const STACK_AND_PIE_CHART_THEMES_OPTIONS = {
3
+ DEFAULT: 'default',
4
+ SINGLE_SELECT_COLUMN_COLORS: 'single_select_column_colors'
5
+ };
2
6
  export const COLOR_RULE_FILTER_TYPE_MAP = {
3
7
  NUMERIC_VALUE: 'numeric_value'
4
8
  };
@@ -247,6 +247,8 @@ const de = {
247
247
  "Line_type": "Linientyp",
248
248
  "Summarize_description": "Die Summe, das Maximum, das Minimum oder den Durchschitt der Einträge basierend auf einem Feld berechnen",
249
249
  "Count_description": "Einträge basierend auf den Dateneinstellungen zählen",
250
- "Display_empty_when_data_is_zero": "Wert 0 als leeren Wert anzeigen"
250
+ "Display_empty_when_data_is_zero": "Wert 0 als leeren Wert anzeigen",
251
+ "Use_default_color": "Standardfarbe verwenden",
252
+ "Use_colors_in_single_select_solumn": "Verwenden Sie Farben in einer einzelnen Auswahlspalte"
251
253
  };
252
254
  export default de;
@@ -247,6 +247,8 @@ const en = {
247
247
  "Line_type": "Line type",
248
248
  "Summarize_description": "Calculate the sum, maximum, minimum or average of records based on a field",
249
249
  "Count_description": "Count the number of records based on data settings",
250
- "Display_empty_when_data_is_zero": "Display empty when data is zero"
250
+ "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
+ "Use_default_color": "Use default color",
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column"
251
253
  };
252
254
  export default en;
@@ -247,6 +247,8 @@ const es = {
247
247
  "Line_type": "Line type",
248
248
  "Summarize_description": "Calculate the sum, maximum, minimum or average of records based on a field",
249
249
  "Count_description": "Count the number of records based on data settings",
250
- "Display_empty_when_data_is_zero": "Display empty when data is zero"
250
+ "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
+ "Use_default_color": "Use default color",
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column"
251
253
  };
252
254
  export default es;
@@ -247,6 +247,8 @@ const fr = {
247
247
  "Line_type": "Type de ligne",
248
248
  "Summarize_description": "Calculer la somme, le maximum, le minimum our la moyenne pour les enregistrements en fonction d'un champ",
249
249
  "Count_description": "Compter les enregistrements basé sur les paramètres de données",
250
- "Display_empty_when_data_is_zero": "Afficher la valeur 0 comme valeur vide"
250
+ "Display_empty_when_data_is_zero": "Afficher la valeur 0 comme valeur vide",
251
+ "Use_default_color": "Utiliser la couleur par défaut",
252
+ "Use_colors_in_single_select_solumn": "Utiliser les couleurs dans une colonne de sélection unique"
251
253
  };
252
254
  export default fr;
@@ -247,6 +247,8 @@ const pt = {
247
247
  "Line_type": "Line type",
248
248
  "Summarize_description": "Calculate the sum, maximum, minimum or average of records based on a field",
249
249
  "Count_description": "Count the number of records based on data settings",
250
- "Display_empty_when_data_is_zero": "Display empty when data is zero"
250
+ "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
+ "Use_default_color": "Use default color",
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column"
251
253
  };
252
254
  export default pt;
@@ -247,6 +247,8 @@ const ru = {
247
247
  "Line_type": "Line type",
248
248
  "Summarize_description": "Calculate the sum, maximum, minimum or average of records based on a field",
249
249
  "Count_description": "Count the number of records based on data settings",
250
- "Display_empty_when_data_is_zero": "Display empty when data is zero"
250
+ "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
+ "Use_default_color": "Use default color",
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column"
251
253
  };
252
254
  export default ru;
@@ -247,6 +247,8 @@ const zh_CN = {
247
247
  "Line_type": "线型",
248
248
  "Summarize_description": "按照一个字段计算记录的总和、最大值、最小值或者平均值",
249
249
  "Count_description": "根据数据设置计算记录数量",
250
- "Display_empty_when_data_is_zero": "数据为零时留空"
250
+ "Display_empty_when_data_is_zero": "数据为零时留空",
251
+ "Use_default_color": "使用默认颜色",
252
+ "Use_colors_in_single_select_solumn": "使用列中的选项颜色"
251
253
  };
252
254
  export default zh_CN;
@@ -3,18 +3,23 @@ import _DTableRadioGroup from "dtable-ui-component/lib/DTableRadioGroup";
3
3
  import _DTableSwitch from "dtable-ui-component/lib/DTableSwitch";
4
4
  import React, { useCallback, useMemo, useState } from 'react';
5
5
  import { Label, Input, Row } from 'reactstrap';
6
+ import { CellType } from 'dtable-ui-component/lib/constants';
6
7
  import Divider from '../widgets/divider';
7
8
  import MinMaxSetting from '../widgets/min-max-setting';
8
9
  import DisplayValuesSettings from '../widgets/display-values-settings';
9
10
  import { X_LABEL_POSITIONS, Y_LABEL_POSITIONS, LABEL_POSITION_TYPE_SHOW, SUPPORT_STACK_VALUE_CHART_TYPES, CHART_TYPE } from '../../constants';
10
11
  import intl from '../../intl';
11
12
  import SelectLineType from '../widgets/select-line-type';
13
+ import ColorSelector from '../../components/chart-color-selector/color-selector';
14
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
15
+ import { getColumnByKey } from '../../utils';
12
16
  const StyleSettings = _ref => {
13
17
  let {
14
18
  chart,
15
19
  xLabel,
16
20
  yLabel,
17
- onChange
21
+ onChange,
22
+ tables
18
23
  } = _ref;
19
24
  const {
20
25
  config
@@ -32,8 +37,15 @@ const StyleSettings = _ref => {
32
37
  label_font_size,
33
38
  display_each_block_data,
34
39
  line_type,
35
- title_name
40
+ title_name,
41
+ color_theme,
42
+ column_groupby_column_key,
43
+ table_id
36
44
  } = config;
45
+ const table = tables.find(table => table._id === table_id);
46
+ const column = getColumnByKey(column_groupby_column_key, table.columns);
47
+ const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) === CellType.SINGLE_SELECT;
48
+ const defaultColorTheme = STACK_AND_PIE_CHART_THEMES_OPTIONS.DEFAULT;
37
49
  const [currYaxisTitle, setCurrYaxisTitle] = useState(title_name || '');
38
50
  const xAxisLabelOptions = useMemo(() => {
39
51
  if (xLabel === 'Vertical_axis') {
@@ -120,6 +132,12 @@ const StyleSettings = _ref => {
120
132
  };
121
133
  onChange(update);
122
134
  }, [chart, onChange]);
135
+ const onChartColorChange = useCallback(value => {
136
+ const update = {
137
+ 'color_theme': value
138
+ };
139
+ onChange(update);
140
+ }, [onChange]);
123
141
  const onKeyDown = useCallback(event => {
124
142
  if (event.key === 'Enter') {
125
143
  event.preventDefault();
@@ -198,7 +216,10 @@ const StyleSettings = _ref => {
198
216
  onMinChange: onYAxisMinChange,
199
217
  onMaxChange: onYAxisMaxChange
200
218
  })))
201
- }), /*#__PURE__*/React.createElement(Divider, null), ![CHART_TYPE.BAR_CUSTOM].includes(type) && /*#__PURE__*/React.createElement(DisplayValuesSettings, {
219
+ }), isGroupBySingleSelectColumn && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(ColorSelector, {
220
+ colorTheme: color_theme || defaultColorTheme,
221
+ onChange: onChartColorChange
222
+ })), /*#__PURE__*/React.createElement(Divider, null), ![CHART_TYPE.BAR_CUSTOM].includes(type) && /*#__PURE__*/React.createElement(DisplayValuesSettings, {
202
223
  isShowValueKey: "y_axis_show_value",
203
224
  isShowValue: y_axis_show_value,
204
225
  fontSizeKey: "label_font_size",
@@ -43,7 +43,8 @@ const StyleSettings = _ref => {
43
43
  yLabel: 'Horizontal_axis',
44
44
  labelColorConfigs: labelColorConfigs,
45
45
  chart: newChart,
46
- onChange: onChange
46
+ onChange: onChange,
47
+ tables: tables
47
48
  });
48
49
  };
49
50
  export default StyleSettings;
@@ -90,6 +90,7 @@ const Settings = _ref => {
90
90
  onChange: modifyStatistic
91
91
  }), type === CHART_SETTINGS_TYPE.CHART_STYLE && /*#__PURE__*/React.createElement(StyleSettings, {
92
92
  chart: chart,
93
+ tables: tables,
93
94
  labelColorConfigs: labelColorConfigs,
94
95
  onChange: modifyStyle
95
96
  }), children && type === CHART_SETTINGS_TYPE.GENERAL_STYLE && /*#__PURE__*/React.createElement(React.Fragment, null, children)))));
@@ -3,16 +3,20 @@ import _DTableSelect from "dtable-ui-component/lib/DTableSelect";
3
3
  import _DTableSwitch from "dtable-ui-component/lib/DTableSwitch";
4
4
  import React, { useCallback, useMemo } from 'react';
5
5
  import { Label, FormGroup } from 'reactstrap';
6
+ import { CellType } from 'dtable-ui-component/lib/constants';
6
7
  import Divider from '../widgets/divider';
7
8
  import MiniNumSlicePercent from '../widgets/mininum-slice-percent';
8
9
  import { FontSizeSettings } from '../widgets/font-settings';
9
- import { eventStopPropagation } from '../../utils';
10
+ import { eventStopPropagation, getColumnByKey } from '../../utils';
10
11
  import { CHART_LABEL_POSITIONS, CHART_LABEL_POSITION_SHOW, CHART_LABEL_FORMATS, CHART_LABEL_FORMAT_SHOW } from '../../constants';
11
12
  import intl from '../../intl';
13
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
14
+ import ColorSelector from '../../components/chart-color-selector/color-selector';
12
15
  const StyleSettings = _ref => {
13
16
  let {
14
17
  chart,
15
- onChange
18
+ onChange,
19
+ tables
16
20
  } = _ref;
17
21
  const labelPositionOptions = useMemo(() => {
18
22
  return CHART_LABEL_POSITIONS.map(item => {
@@ -89,6 +93,11 @@ const StyleSettings = _ref => {
89
93
  minimum_slice_percent: value
90
94
  });
91
95
  }, [onChange]);
96
+ const onChartColorChange = useCallback(value => {
97
+ onChange && onChange({
98
+ color_theme: value
99
+ });
100
+ }, [onChange]);
92
101
  const {
93
102
  config
94
103
  } = chart;
@@ -98,8 +107,15 @@ const StyleSettings = _ref => {
98
107
  label_position,
99
108
  label_format,
100
109
  label_font_size,
101
- minimum_slice_percent
110
+ minimum_slice_percent,
111
+ table_id,
112
+ groupby_column_key,
113
+ color_theme
102
114
  } = config;
115
+ const table = tables.find(table => table._id === table_id);
116
+ const column = getColumnByKey(groupby_column_key, table.columns);
117
+ const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) === CellType.SINGLE_SELECT;
118
+ const defaultColorTheme = STACK_AND_PIE_CHART_THEMES_OPTIONS.DEFAULT;
103
119
  const selectedLabelOption = labelPositionOptions.find(item => item.value === label_position);
104
120
  const selectedLabelFormat = labelFormatOptions.find(item => item.value === label_format) || labelFormatOptions[0];
105
121
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormGroup, {
@@ -108,6 +124,9 @@ const StyleSettings = _ref => {
108
124
  checked: show_legend || false,
109
125
  placeholder: intl.get('Display_legend'),
110
126
  onChange: onDisplayLegendChange
127
+ })), isGroupBySingleSelectColumn && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(ColorSelector, {
128
+ colorTheme: color_theme || defaultColorTheme,
129
+ onChange: onChartColorChange
111
130
  })), /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(_CollapsibleSettingLayout, {
112
131
  title: intl.get('Label'),
113
132
  children: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_DTableSwitch, {
@@ -485,7 +485,7 @@ BaseUtils.getPieColorSet = (tables, chart, result) => {
485
485
  });
486
486
  return backgroundColor;
487
487
  };
488
- BaseUtils.getPieColor = (column, index, data, currentTheme) => {
488
+ BaseUtils.getPieColor = (column, index, data, currentTheme, useColumnColor) => {
489
489
  let {
490
490
  type: columnType,
491
491
  data: columnData
@@ -493,7 +493,7 @@ BaseUtils.getPieColor = (column, index, data, currentTheme) => {
493
493
  const {
494
494
  colors
495
495
  } = currentTheme;
496
- if (columnType === 'single-select' || columnType === 'multiple-select') {
496
+ if ((columnType === 'single-select' || columnType === 'multiple-select') && useColumnColor) {
497
497
  if (columnData && columnData.options) {
498
498
  const selectedItem = columnData.options.find(item => {
499
499
  return item.name === data.name.trim();
@@ -506,7 +506,7 @@ BaseUtils.getPieColor = (column, index, data, currentTheme) => {
506
506
  return colors[newIndex];
507
507
  }
508
508
  };
509
- BaseUtils.formatPieChartData = (data, chart, tables, currentTheme) => {
509
+ BaseUtils.formatPieChartData = (data, chart, tables, currentTheme, useColumnColor) => {
510
510
  if (!Array.isArray(data) || data.length === 0 || !chart) {
511
511
  return {
512
512
  data: [],
@@ -527,7 +527,7 @@ BaseUtils.formatPieChartData = (data, chart, tables, currentTheme) => {
527
527
  const minimumSlicePercentage = typeof minimum_slice_percent === 'number' ? minimum_slice_percent : 1.5;
528
528
  const threshold = sum * (minimumSlicePercentage / 100 || 0);
529
529
  let filteredItems = [];
530
- let colorSet = [];
530
+ let colorMap = {};
531
531
  let filteredData = [];
532
532
  let rows = [];
533
533
  data.forEach((item, index) => {
@@ -535,9 +535,9 @@ BaseUtils.formatPieChartData = (data, chart, tables, currentTheme) => {
535
535
  item.name = item.name + ' ';
536
536
  if (value >= threshold) {
537
537
  item.percent = String(Number.parseFloat(value / sum * 100).toFixed(1)) + '%';
538
- const color = _BaseUtils.getPieColor(column, index, item, currentTheme);
538
+ const color = _BaseUtils.getPieColor(column, index, item, currentTheme, useColumnColor);
539
539
  item.color = color;
540
- colorSet.push(color);
540
+ colorMap[item.name.trim()] = color;
541
541
  filteredData.push(item);
542
542
  } else {
543
543
  rows.push(...item.rows);
@@ -555,23 +555,21 @@ BaseUtils.formatPieChartData = (data, chart, tables, currentTheme) => {
555
555
  percent: String(Number.parseFloat(filteredSum / sum * 100).toFixed(1)) + '%',
556
556
  rows
557
557
  });
558
- colorSet.push('#dbdbdb');
558
+ colorMap['_Others'] = '#dbdbdb';
559
559
  }
560
560
  return {
561
561
  data: filteredData,
562
562
  total: sum,
563
- colorSet
563
+ colorMap
564
564
  };
565
565
  };
566
566
  // table
567
567
  // format SINGLE_SELECT, LAST_MODIFIER, CREATOR, COLLABORATOR, DATE, NUMBER
568
- // need to be optimized
569
568
  BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorKey) => {
570
569
  let {
571
570
  type: columnType,
572
571
  data: columnData
573
572
  } = column;
574
- // name is nameKey's value here
575
573
  let name = result[nameKey];
576
574
  if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
577
575
  const options = getColumnOptions(column);
@@ -611,28 +609,6 @@ BaseUtils.updateTableViewListItemNameAndColor = (result, column, nameKey, colorK
611
609
  }
612
610
  result[nameKey] = users.map(user => user.name).join(', ');
613
611
  });
614
-
615
- // if (name === 'anonymous') {
616
- // result[nameKey] = name;
617
- // } else {
618
- // const collaborator = getKnownCollaboratorByEmail(name);
619
- // const collaboratorTemplate = {
620
- // loaded: false,
621
- // email: name,
622
- // name: name,
623
- // };
624
- // context.updateCollaboratorsCache(name, collaboratorTemplate);
625
- // if (!collaborator) {
626
- // context.queryUsers([name], (emailUserMap) => {
627
- // const collaborator = (emailUserMap && emailUserMap[name]) || generateDefaultUser(name);
628
- // const loadedCollaborator = { ...collaborator, loaded: true };
629
- // context.updateCollaboratorsCache(name, loadedCollaborator);
630
- // result[nameKey] = name;
631
- // });
632
- // } else {
633
- // result[nameKey] = collaborator.name;
634
- // }
635
- // }
636
612
  } else if (columnType === CellType.NUMBER) {
637
613
  let valueNumber = parseFloat(name);
638
614
  result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
@@ -1,4 +1,6 @@
1
1
  import context from '../../context';
2
+ import { getErrorMessage } from '..';
3
+ import intl from '../../intl';
2
4
  import BaseUtils from './base-utils';
3
5
  import SQLStatisticsUtils from './sql-statistics-utils';
4
6
  import OriginalDataUtils from './original-data-utils';
@@ -19,7 +21,8 @@ ChartUtils.calculateChart = (chart, value, callback) => {
19
21
  error_message
20
22
  } = res.data;
21
23
  if (!success) {
22
- callback && callback(error_message, '', null);
24
+ const errMsg = intl.get(error_message);
25
+ callback && callback(errMsg, '', null);
23
26
  return;
24
27
  }
25
28
  if (dataSources === OriginalDataUtils.dataSources) {
@@ -29,15 +32,7 @@ ChartUtils.calculateChart = (chart, value, callback) => {
29
32
  SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
30
33
  },
31
34
  onFail: err => {
32
- let errorMessage = String(err) || 'Network_error';
33
- if (err.response) {
34
- const {
35
- status
36
- } = err.response;
37
- if (status === 500) {
38
- errorMessage = 'Internal_server_error';
39
- }
40
- }
35
+ let errorMessage = getErrorMessage(err);
41
36
  callback && callback(errorMessage, '', null);
42
37
  }
43
38
  });
@@ -75,7 +75,7 @@ export function getUsers(emails, cb) {
75
75
  return;
76
76
  }
77
77
 
78
- // if any user is not fetched, fetch them
78
+ // if any user not fetched, fetch them
79
79
  context.queryUsers(unFetchedUsers, emailUserMap => {
80
80
  // add them to cache
81
81
  updateKnownUsers(emailUserMap);
@@ -182,7 +182,7 @@ class View extends React.PureComponent {
182
182
  if (errorMessage) {
183
183
  return /*#__PURE__*/React.createElement("div", {
184
184
  className: classnames('error', validClassName, tipBackgroundColorClassName)
185
- }, /*#__PURE__*/React.createElement("span", null, intl.get(errorMessage)));
185
+ }, /*#__PURE__*/React.createElement("span", null, errorMessage));
186
186
  }
187
187
  if (tipMessage) {
188
188
  return /*#__PURE__*/React.createElement("div", {
@@ -2,12 +2,14 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import DataSet from '@antv/data-set';
4
4
  import { getNumberDisplayString } from 'dtable-utils';
5
- import { debounce, maxBy, throttle } from 'lodash-es';
5
+ import { debounce, maxBy } from 'lodash-es';
6
6
  import classNames from 'classnames';
7
+ import { CellType } from 'dtable-ui-component/lib/constants';
7
8
  import intl from '../../intl';
8
9
  import { sortDataByGroupSum } from '../../utils/column-utils';
9
10
  import { EMPTY_NAME, CHART_TYPE, CHART_SUMMARY_TYPE, DEFAULT_NUMBER_FORMAT_OBJECT, CHART_THEME_COLOR } from '../../constants';
10
11
  import { BaseUtils, isFunction } from '../../utils';
12
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
11
13
  import ChartComponent from './chart-component';
12
14
  class BarGroup extends ChartComponent {
13
15
  constructor(props) {
@@ -66,7 +68,8 @@ class BarGroup extends ChartComponent {
66
68
  summaryColumn,
67
69
  globalTheme,
68
70
  chartColorTheme,
69
- customRender
71
+ customRender,
72
+ tables
70
73
  } = this.props;
71
74
  const {
72
75
  type,
@@ -74,12 +77,17 @@ class BarGroup extends ChartComponent {
74
77
  y_axis_show_value,
75
78
  label_font_size,
76
79
  display_each_block_data,
77
- y_axis_summary_type
80
+ y_axis_summary_type,
81
+ table_id,
82
+ column_groupby_column_key,
83
+ color_theme
78
84
  } = chart.config;
79
85
  const theme = CHART_THEME_COLOR[globalTheme];
80
86
  const isGroup = type === CHART_TYPE.BAR_GROUP;
81
- const chartBarColor = this.groupName;
87
+ const isStack = type === CHART_TYPE.BAR_STACK;
82
88
  const newData = this.getChartGroupData(data);
89
+ const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
90
+ const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === CellType.SINGLE_SELECT && isStack && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
83
91
  let singleBarWidth, singleBarRadius;
84
92
  // y-axis label width:6 + 10
85
93
  const chartWidth = this.chart.width - 6 - 10;
@@ -158,8 +166,8 @@ class BarGroup extends ChartComponent {
158
166
  lineWidth: 1
159
167
  },
160
168
  position: type === CHART_TYPE.BAR_STACK ? 'middle' : ''
161
- }).position('name*value').size(singleBarWidth).color(chartBarColor, group_name => {
162
- return this.colorMap[group_name];
169
+ }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
170
+ return useSingleSelectColumnColor ? group_color : this.colorMap[group_name];
163
171
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
164
172
  return {
165
173
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -185,7 +193,6 @@ class BarGroup extends ChartComponent {
185
193
  }
186
194
  } else {
187
195
  return {
188
- // fill: chartBarColor,
189
196
  radius: [singleBarRadius, singleBarRadius, 0, 0]
190
197
  };
191
198
  }
@@ -197,11 +204,10 @@ class BarGroup extends ChartComponent {
197
204
  isFunction(customRender) && customRender(this.chart);
198
205
  this.setNameLabelAndTooltip(theme, this.labelCount);
199
206
  this.setValueLabel(theme);
200
- this.setLegend(this.groupName, theme, 'top-right');
207
+ this.setLegend('group_name', theme, 'top-right');
201
208
  this.chart.interaction('element-highlight-by-x');
202
209
  };
203
210
  this.chart = null;
204
- this.groupName = 'group_name';
205
211
  }
206
212
  componentDidMount() {
207
213
  this.createChart();
@@ -22,9 +22,13 @@ export default class ChartComponent extends Component {
22
22
  this.getTitle = (tables, table_id, yAxisType, yAxisKey) => {
23
23
  return yAxisType === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : this.getAxisLabel(tables, table_id, yAxisKey);
24
24
  };
25
- this.getAxisLabel = (tables, tableId, columnKey) => {
26
- const table = getTableById(tables, tableId);
25
+ this.getColumn = (tables, table_id, columnKey) => {
26
+ const table = getTableById(tables, table_id);
27
27
  const column = getTableColumnByKey(table, columnKey) || {};
28
+ return column;
29
+ };
30
+ this.getAxisLabel = (tables, tableId, columnKey) => {
31
+ const column = this.getColumn(tables, tableId, columnKey);
28
32
  return column.name || '';
29
33
  };
30
34
  this.initChart = (container, _ref) => {
@@ -448,7 +452,8 @@ export default class ChartComponent extends Component {
448
452
  };
449
453
  this.setColorMap = (data, chartColorTheme) => {
450
454
  let currentIdx = 0;
451
- let colors = CHART_STYLE_COLORS;
455
+ const defaultColors = CHART_STYLE_COLORS;
456
+ let colors = defaultColors;
452
457
  if (chartColorTheme) {
453
458
  colors = BaseUtils.getCurrentTheme(chartColorTheme).colors;
454
459
  }
@@ -2,9 +2,11 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { debounce, maxBy, throttle } from 'lodash-es';
4
4
  import classNames from 'classnames';
5
+ import { CellType } from 'dtable-ui-component/lib/constants';
5
6
  import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR } from '../../constants';
6
7
  import { BaseUtils, isFunction } from '../../utils';
7
8
  import intl from '../../intl';
9
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
8
10
  import HorizontalComponent from './horizontal-component';
9
11
  class HorizontalBarGroup extends HorizontalComponent {
10
12
  constructor(props) {
@@ -55,17 +57,23 @@ class HorizontalBarGroup extends HorizontalComponent {
55
57
  chart,
56
58
  summaryColumn,
57
59
  globalTheme,
58
- chartColorTheme
60
+ chartColorTheme,
61
+ tables
59
62
  } = this.props;
60
63
  const theme = CHART_THEME_COLOR[globalTheme];
61
64
  const {
62
65
  horizontal_axis_summary_method,
63
66
  display_data,
64
67
  label_font_size,
65
- type
68
+ type,
69
+ column_groupby_column_key,
70
+ table_id,
71
+ color_theme
66
72
  } = chart.config;
67
73
  const isGroup = type === CHART_TYPE.HORIZONTAL_GROUP_BAR;
68
- const chartBarColor = this.groupName;
74
+ const isStack = type === CHART_TYPE.STACKED_HORIZONTAL_BAR;
75
+ const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
76
+ const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === CellType.SINGLE_SELECT && isStack && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
69
77
  const newData = this.getChartGroupData(data);
70
78
  let singleBarWidth, singleBarRadius;
71
79
  // y-axis label width:(6 + 10)
@@ -75,6 +83,7 @@ class HorizontalBarGroup extends HorizontalComponent {
75
83
  singleBarWidth = Math.round(chartHeight / (2 * newData.length));
76
84
  this.markFirstOrLast(data, 'last');
77
85
  } else {
86
+ // stacked chart
78
87
  const maxCountGroup = maxBy(newData, 'currentGroupCount');
79
88
  // calculate the width of each bar in a mostCommonCountGroup
80
89
  singleBarWidth = Math.round(chartHeight / (2 * newData.length * maxCountGroup.currentGroupCount));
@@ -108,8 +117,8 @@ class HorizontalBarGroup extends HorizontalComponent {
108
117
  stroke: '#fff',
109
118
  lineWidth: 1
110
119
  }
111
- }).position('name*value').size(singleBarWidth).color(chartBarColor, group_name => {
112
- return this.colorMap[group_name];
120
+ }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
121
+ return useSingleSelectColumnColor ? group_color : this.colorMap[group_name];
113
122
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
114
123
  return {
115
124
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -135,7 +144,6 @@ class HorizontalBarGroup extends HorizontalComponent {
135
144
  }
136
145
  } else {
137
146
  return {
138
- // fill: chartBarColor,
139
147
  radius: [singleBarRadius, singleBarRadius, 0, 0]
140
148
  };
141
149
  }
@@ -147,11 +155,10 @@ class HorizontalBarGroup extends HorizontalComponent {
147
155
  this.setNameLabelAndTooltip(theme, this.labelCount);
148
156
  this.setValueLabel(theme);
149
157
  this.chart.coordinate().transpose();
150
- this.setLegend(this.groupName, theme, 'top-right');
158
+ this.setLegend('group_name', theme, 'top-right');
151
159
  this.chart.interaction('element-highlight-by-x');
152
160
  };
153
161
  this.chart = null;
154
- this.groupName = 'group_name';
155
162
  }
156
163
  componentDidMount() {
157
164
  this.createChart();
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import { CellType } from 'dtable-ui-component/lib/constants';
3
4
  import { CHART_LABEL_POSITIONS, CHART_LABEL_FORMATS, CHART_THEME_COLOR } from '../../constants';
4
5
  import { BaseUtils, isFunction } from '../../utils';
5
6
  import intl from '../../intl';
7
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
6
8
  import ChartComponent from './chart-component';
7
9
  class Pie extends ChartComponent {
8
10
  constructor(props) {
@@ -46,13 +48,15 @@ class Pie extends ChartComponent {
46
48
  display_label,
47
49
  label_position,
48
50
  label_font_size,
49
- summary_method
51
+ summary_method,
52
+ color_theme
50
53
  } = chart.config;
51
54
  const currentTheme = BaseUtils.getCurrentTheme(chartColorTheme);
55
+ const useSingleSelectColumnColor = color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
52
56
  const {
53
57
  data: newData,
54
- colorSet
55
- } = BaseUtils.formatPieChartData(data, chart, tables, currentTheme);
58
+ colorMap
59
+ } = BaseUtils.formatPieChartData(data, chart, tables, currentTheme, useSingleSelectColumnColor);
56
60
  if (!Array.isArray(newData)) return;
57
61
  this.loadData(newData);
58
62
  this.chart.on('interval:click', e => {
@@ -73,7 +77,9 @@ class Pie extends ChartComponent {
73
77
  this.isInnerLabel = !label_position || label_position === CHART_LABEL_POSITIONS[0];
74
78
  this.innerLabelOffset = '-25%';
75
79
  this.outerLabelOffset = 20;
76
- this.currentChart = this.chart.interval().adjust('stack').position('value').color('name', colorSet).label('value*percent', (value, percent) => {
80
+ this.currentChart = this.chart.interval().adjust('stack').position('value').color('name', name => {
81
+ return colorMap[name.trim()];
82
+ }).label('value*percent', (value, percent) => {
77
83
  const displayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, value, summary_method);
78
84
  return {
79
85
  content: this.getLabel(displayValue, percent)
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { CHART_LABEL_POSITIONS, CHART_LABEL_FORMATS, CHART_THEME_COLOR } from '../../constants';
4
4
  import { BaseUtils, isFunction } from '../../utils';
5
5
  import intl from '../../intl';
6
+ import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
6
7
  import ChartComponent from './chart-component';
7
8
  class Ring extends ChartComponent {
8
9
  constructor(props) {
@@ -48,14 +49,16 @@ class Ring extends ChartComponent {
48
49
  label_position,
49
50
  label_font_size,
50
51
  summary_method,
51
- label_format
52
+ label_format,
53
+ color_theme
52
54
  } = chart.config;
53
55
  const colorTheme = BaseUtils.getCurrentTheme(chartColorTheme);
56
+ const useSingleSelectColumnColor = color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
54
57
  const {
55
58
  data: newData,
56
- colorSet,
59
+ colorMap,
57
60
  total
58
- } = BaseUtils.formatPieChartData(data, chart, tables, colorTheme);
61
+ } = BaseUtils.formatPieChartData(data, chart, tables, colorTheme, useSingleSelectColumnColor);
59
62
  if (!Array.isArray(newData)) return;
60
63
  this.sum = total;
61
64
  this.loadData(newData);
@@ -93,7 +96,9 @@ class Ring extends ChartComponent {
93
96
  }
94
97
  this.innerLabelOffset = innerLabelOffset;
95
98
  this.outerLabelOffset = outerLabelOffset;
96
- this.currentChart = this.chart.interval().adjust('stack').position('value').color('name', colorSet).label('value*percent', (value, percent) => {
99
+ this.currentChart = this.chart.interval().adjust('stack').position('value').color('name', name => {
100
+ return colorMap[name.trim()];
101
+ }).label('value*percent', (value, percent) => {
97
102
  const displayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, value, summary_method);
98
103
  return {
99
104
  content: this.getLabel(displayValue, percent)
@@ -43,6 +43,7 @@ class Treemap extends ChartComponent {
43
43
  this.chart.clear(true);
44
44
  };
45
45
  this.drawChart = () => {
46
+ debugger;
46
47
  let {
47
48
  result: data,
48
49
  chart,
@@ -58,7 +59,7 @@ class Treemap extends ChartComponent {
58
59
  let colorsTheme = BaseUtils.getCurrentTheme(chartColorTheme);
59
60
  const {
60
61
  data: newData,
61
- colorSet
62
+ colorMap
62
63
  } = BaseUtils.formatPieChartData(data, chart, tables, colorsTheme);
63
64
  if (!Array.isArray(newData)) return;
64
65
  const {
@@ -130,7 +131,9 @@ class Treemap extends ChartComponent {
130
131
  }
131
132
  }
132
133
  });
133
- this.chart.polygon().position('x*y').color('name', colorSet).tooltip('name*value*percent', (name, value, percent) => {
134
+ this.chart.polygon().position('x*y').color('name', name => {
135
+ return colorMap[name.trim()];
136
+ }).tooltip('name*value*percent', (name, value, percent) => {
134
137
  const displayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, value, summary_method);
135
138
  return {
136
139
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",