sea-chart 0.0.27 → 0.0.28

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/dist/intl.js CHANGED
@@ -4,15 +4,15 @@ class Intl {
4
4
  constructor(_ref) {
5
5
  var _this = this;
6
6
  let {
7
- lang: _lang = 'zh_CN'
7
+ lang: _lang = 'zh-cn'
8
8
  } = _ref;
9
9
  this.setLang = function () {
10
- let lang = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'zh_CN';
10
+ let lang = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'zh-cn';
11
11
  const validLang = lang.toLowerCase();
12
+ setLocale(validLang);
12
13
  if (validLang === _this.lang) return;
13
14
  _this.lang = validLang;
14
- _this.translation = LOCALES[_this.lang] || LOCALES['zh_CN'];
15
- setLocale(validLang);
15
+ _this.translation = LOCALES[_this.lang] || LOCALES['zh-cn'];
16
16
  };
17
17
  this.get = function (key) {
18
18
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -30,10 +30,10 @@ class Intl {
30
30
  }) || key;
31
31
  };
32
32
  this.lang = _lang.toLowerCase();
33
- this.translation = LOCALES[this.lang] || LOCALES['zh_CN'];
33
+ this.translation = LOCALES[this.lang] || LOCALES['zh-cn'];
34
34
  }
35
35
  }
36
36
  const intl = new Intl({
37
- lang: 'zh_CN'
37
+ lang: 'zh-cn'
38
38
  });
39
39
  export default intl;
@@ -165,6 +165,9 @@ const de = {
165
165
  'Target_summary_method_is_not_valid': 'Target summary method is not valid',
166
166
  'polylines': 'Polylines',
167
167
  'curves': 'Curves',
168
- 'Line_type': 'Line type'
168
+ 'Line_type': 'Line type',
169
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
170
+ 'Count_description': 'Count the number of records based on data settings',
171
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
169
172
  };
170
173
  export default de;
@@ -242,6 +242,9 @@ const en = {
242
242
  "Label_settings": "Label settings",
243
243
  'polylines': 'Polylines',
244
244
  'curves': 'Curves',
245
- 'Line_type': 'Line type'
245
+ 'Line_type': 'Line type',
246
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
247
+ 'Count_description': 'Count the number of records based on data settings',
248
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
246
249
  };
247
250
  export default en;
@@ -165,6 +165,9 @@ const es = {
165
165
  'Target_summary_method_is_not_valid': 'Target summary method is not valid',
166
166
  'polylines': 'Polylines',
167
167
  'curves': 'Curves',
168
- 'Line_type': 'Line type'
168
+ 'Line_type': 'Line type',
169
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
170
+ 'Count_description': 'Count the number of records based on data settings',
171
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
169
172
  };
170
173
  export default es;
@@ -165,6 +165,9 @@ const fr = {
165
165
  'Target_summary_method_is_not_valid': 'Target summary method is not valid',
166
166
  'polylines': 'Polylines',
167
167
  'curves': 'Curves',
168
- 'Line_type': 'Line type'
168
+ 'Line_type': 'Line type',
169
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
170
+ 'Count_description': 'Count the number of records based on data settings',
171
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
169
172
  };
170
173
  export default fr;
@@ -165,6 +165,9 @@ const pt = {
165
165
  'Target_summary_method_is_not_valid': 'Target summary method is not valid',
166
166
  'polylines': 'Polylines',
167
167
  'curves': 'Curves',
168
- 'Line_type': 'Line type'
168
+ 'Line_type': 'Line type',
169
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
170
+ 'Count_description': 'Count the number of records based on data settings',
171
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
169
172
  };
170
173
  export default pt;
@@ -165,6 +165,9 @@ const ru = {
165
165
  'Target_summary_method_is_not_valid': 'Target summary method is not valid',
166
166
  'polylines': 'Polylines',
167
167
  'curves': 'Curves',
168
- 'Line_type': 'Line type'
168
+ 'Line_type': 'Line type',
169
+ 'Summarize_description': 'Count the sum, maximum, minimum, average, or number of distinct values of records based on a field',
170
+ 'Count_description': 'Count the number of records based on data settings',
171
+ 'Display_empty_when_data_is_zero': 'Display empty when data is zero'
169
172
  };
170
173
  export default ru;
@@ -242,6 +242,9 @@ const zh_CN = {
242
242
  "Label_settings": "标签设置",
243
243
  'polylines': '折线',
244
244
  'curves': '曲线',
245
- 'Line_type': '线型'
245
+ 'Line_type': '线型',
246
+ 'Summarize_description': '按照一个字段计算记录的总和、最大值、最小值或者平均值',
247
+ 'Count_description': '根据数据设置计算记录数量',
248
+ 'Display_empty_when_data_is_zero': '数据为零时留空'
246
249
  };
247
250
  export default zh_CN;
@@ -503,7 +503,8 @@ const DataSettings = _ref => {
503
503
  column_groupby_column_key,
504
504
  column_groupby_date_granularity,
505
505
  column_groupby_geolocation_granularity,
506
- display_total = true
506
+ display_total = true,
507
+ display_empty
507
508
  } = config;
508
509
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CommonDataSettings, {
509
510
  chart: chart,
@@ -562,6 +563,20 @@ const DataSettings = _ref => {
562
563
  display_total: !display_total
563
564
  });
564
565
  }
566
+ })), /*#__PURE__*/React.createElement(Divider, {
567
+ className: "mt-4"
568
+ }), /*#__PURE__*/React.createElement(FormGroup, {
569
+ className: "sea-chart-parameter-item"
570
+ }, /*#__PURE__*/React.createElement(DTableSwitch, {
571
+ switchClassName: "display-value-settings",
572
+ checked: display_empty || false,
573
+ disabled: false,
574
+ placeholder: intl.get('Display_empty_when_data_is_zero'),
575
+ onChange: () => {
576
+ onChange({
577
+ display_empty: !display_empty
578
+ });
579
+ }
565
580
  })));
566
581
  };
567
582
  export default DataSettings;
@@ -207,8 +207,13 @@ BaseUtils.isSameGroup = (isColumnDataAsAnArray, source, target) => {
207
207
  }
208
208
  return source === null && target === null || source === undefined && target === undefined || source === target;
209
209
  };
210
- BaseUtils.isValidValue = value => {
211
- if (value === 0) return true;
210
+ BaseUtils.isValidValue = function (value) {
211
+ let display_empty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
212
+ // convert str to number
213
+ if (value === '0') {
214
+ value = +value;
215
+ }
216
+ if (value === 0 && !display_empty) return true;
212
217
  return Boolean(value);
213
218
  };
214
219
  BaseUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue) {
@@ -90,10 +90,11 @@ SQLStatisticsUtils.formatedTableSqlRows = (chart, sqlRows, chartSQLMap, columnMa
90
90
  const {
91
91
  config
92
92
  } = chart;
93
- const {
93
+ let {
94
94
  sqlGroupbyColumnKey,
95
95
  sqlSummaryColumnKey,
96
- summarySQLColumnName2ColumnKey
96
+ summarySQLColumnName2ColumnKey,
97
+ sqlColumnGroupbyColumnKey
97
98
  } = chartSQLMap;
98
99
  const newSqlRows = JSON.parse(JSON.stringify(sqlRows));
99
100
  if (config.summary_type === CHART_SUMMARY_TYPE.COUNT) {
@@ -126,7 +127,15 @@ SQLStatisticsUtils.formatedTableSqlRows = (chart, sqlRows, chartSQLMap, columnMa
126
127
  });
127
128
  }
128
129
  if (config.summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
129
- const summarySQLColumnName2ColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
130
+ let summarySQLColumnName2ColumnKeys;
131
+ if (summarySQLColumnName2ColumnKey) {
132
+ summarySQLColumnName2ColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
133
+ } else if (sqlColumnGroupbyColumnKey) {
134
+ summarySQLColumnName2ColumnKeys = [sqlColumnGroupbyColumnKey];
135
+ } else {
136
+ console.error('on formatedTableSqlRows: summarySQLColumnName2ColumnKey is null');
137
+ return [];
138
+ }
130
139
  sqlRows.forEach((item, index) => {
131
140
  const collaborators = item[sqlGroupbyColumnKey];
132
141
  // Multiple collaborators
@@ -78,7 +78,7 @@ class View extends React.PureComponent {
78
78
  tipMessage: ''
79
79
  };
80
80
  context.init(props);
81
- const lang = context.getSetting('lang') || 'zh_CN';
81
+ const lang = context.getSetting('lang') || 'zh-cn';
82
82
  intl.setLang(lang);
83
83
  }
84
84
  componentDidMount() {
@@ -101,7 +101,9 @@ class Area extends ChartComponent {
101
101
  const line = this.chart.line().label(y_axis_show_value ? 'value' : false, {
102
102
  style: {
103
103
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
104
- fill: theme.labelColor
104
+ fill: theme.labelColor,
105
+ stroke: '#fff',
106
+ lineWidth: 1
105
107
  }
106
108
  }).position('name*value').animate({
107
109
  appear: {
@@ -2,7 +2,7 @@ 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 } from 'lodash-es';
5
+ import { debounce, maxBy, throttle } from 'lodash-es';
6
6
  import classNames from 'classnames';
7
7
  import intl from '../../intl';
8
8
  import { sortDataByGroupSum } from '../../utils/column-utils';
@@ -76,23 +76,21 @@ class BarGroup extends ChartComponent {
76
76
  display_each_block_data,
77
77
  y_axis_summary_type
78
78
  } = chart.config;
79
- const isGroup = type === CHART_TYPE.BAR_GROUP ? true : false;
79
+ const isGroup = type === CHART_TYPE.BAR_GROUP;
80
80
  const chartBarColor = this.groupName;
81
81
  const newData = this.getChartGroupData(data);
82
82
  let singleBarWidth, singleBarRadius;
83
+ // y-axis label width:6 + 10
84
+ const chartWidth = this.chart.width - 6 - 10;
83
85
  if (!isGroup) {
84
- // y-axis label width:6 + 10
85
- const chartWidth = this.chart.width - 6 - 10;
86
86
  singleBarWidth = Math.round(chartWidth / (2 * newData.length));
87
- singleBarRadius = singleBarWidth / 5;
88
87
  this.markFirstOrLast(data, 'first');
89
88
  } else {
90
89
  const maxCountGroup = maxBy(newData, 'currentGroupCount');
91
90
  // y-axis label width:6 + 10
92
- const chartWidth = this.chart.width - 6 - 10;
93
91
  singleBarWidth = Math.round(chartWidth / (2 * newData.length * maxCountGroup.currentGroupCount));
94
- singleBarRadius = singleBarWidth / 5;
95
92
  }
93
+ singleBarRadius = singleBarWidth / 5;
96
94
  this.drawLabels(newData);
97
95
  // set Coord type
98
96
  this.chart.coordinate('rect');
@@ -140,16 +138,29 @@ class BarGroup extends ChartComponent {
140
138
  type: 'dodge',
141
139
  marginRatio: 0
142
140
  };
143
- this.chart.interval().label(y_axis_show_value ? 'value' : false, {
144
- formatter: value => {
145
- return value;
141
+ this.setColorMap(data);
142
+ this.chart.interval().animate({
143
+ // custom update animation
144
+ update: {
145
+ animation: 'fadeIn',
146
+ duration: 1000,
147
+ easing: 'easeLinear'
148
+ }
149
+ }).label(y_axis_show_value ? 'value' : false, {
150
+ content: data => {
151
+ if (this.currentName) {
152
+ return data.name === this.currentName ? data.value : '';
153
+ }
154
+ return data.value;
146
155
  },
147
156
  style: {
148
157
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
149
158
  fill: theme.labelColor
150
159
  },
151
160
  position: type === CHART_TYPE.BAR_STACK ? 'middle' : ''
152
- }).position('name*value').size(singleBarWidth).color(chartBarColor).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
161
+ }).position('name*value').size(singleBarWidth).color(chartBarColor, group_name => {
162
+ return this.colorMap[group_name];
163
+ }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
153
164
  return {
154
165
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
155
166
  value: BaseUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method),
@@ -179,12 +190,28 @@ class BarGroup extends ChartComponent {
179
190
  };
180
191
  }
181
192
  });
182
- this.setToolTip();
193
+ if (isGroup) {
194
+ this.formatDataByName(data);
195
+ }
196
+ this.setToolTip(isGroup, summaryColumn, y_axis_summary_method);
183
197
  isFunction(customRender) && customRender(this.chart);
184
198
  this.setNameLabelAndTooltip(theme, this.labelCount);
185
199
  this.setValueLabel(theme);
186
200
  this.setLegend(this.groupName, theme, 'top-right');
187
- this.chart.interaction('element-highlight');
201
+ this.chart.interaction('element-highlight-by-x');
202
+ if (y_axis_show_value) {
203
+ this.chart.on('element:mouseenter', throttle(e => {
204
+ const currentName = e.data.data.name;
205
+ if (this.currentName && this.currentName === currentName) return;
206
+ this.currentName = currentName;
207
+ this.chart.render(true);
208
+ }, 500));
209
+ this.chart.on('element:mouseleave', throttle(e => {
210
+ if (!this.currentName) return;
211
+ this.currentName = null;
212
+ this.chart.render(true);
213
+ }, 500));
214
+ }
188
215
  };
189
216
  this.chart = null;
190
217
  this.groupName = 'group_name';
@@ -3,7 +3,7 @@ import { getTableById, getTableColumnByKey } from 'dtable-utils';
3
3
  import { cloneDeep, debounce } from 'lodash-es';
4
4
  import { Chart } from '../../utils/custom-g2';
5
5
  import { BaseUtils } from '../../utils';
6
- import { CHART_TYPE, CHART_SUMMARY_TYPE, LABEL_POSITION_TYPE, CHART_THEME_COLOR, EMPTY_NAME, THEME_NAME_MAP } from '../../constants';
6
+ import { CHART_TYPE, CHART_SUMMARY_TYPE, LABEL_POSITION_TYPE, CHART_THEME_COLOR, EMPTY_NAME, THEME_NAME_MAP, CHART_STYLE_COLORS } from '../../constants';
7
7
  import intl from '../../intl';
8
8
  export default class ChartComponent extends Component {
9
9
  constructor() {
@@ -413,8 +413,31 @@ export default class ChartComponent extends Component {
413
413
  }
414
414
  });
415
415
  };
416
- this.getToolTipSettings = () => {
417
- return {
416
+ this.setColorMap = data => {
417
+ let currentIdx = 0;
418
+ const colorMap = data.reduce((acc, cur) => {
419
+ if (cur.group_name && !acc[cur.group_name]) {
420
+ acc[cur.group_name] = CHART_STYLE_COLORS[currentIdx++ % CHART_STYLE_COLORS.length];
421
+ }
422
+ return acc;
423
+ }, {});
424
+ this.colorMap = colorMap;
425
+ };
426
+ this.formatDataByName = data => {
427
+ const formattedItems = {};
428
+ data.forEach(item => {
429
+ const {
430
+ name
431
+ } = item;
432
+ if (!formattedItems[name]) {
433
+ formattedItems[name] = [];
434
+ }
435
+ formattedItems[name].push(item);
436
+ });
437
+ this.formatedDataByName = formattedItems;
438
+ };
439
+ this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method) => {
440
+ const obj = {
418
441
  showMarkers: false,
419
442
  containerTpl: "<div class=\"g2-tooltip\">\n <div class=\"g2-tooltip-title\">{title}</div>\n <ul class=\"g2-tooltip-list\"></ul>\n </div>",
420
443
  itemTpl: "<li class=\"g2-tooltip-list-item\">\n <span class=\"g2-tooltip-marker\" style=\"background-color:{color};display:inline-block;\"></span>\n <span class=\"g2-tooltip-name\">{name}</span>\n <span class=\"g2-tooltip-value\">{value}</span>\n </li>",
@@ -464,9 +487,25 @@ export default class ChartComponent extends Component {
464
487
  }
465
488
  }
466
489
  };
490
+ if (isGroup) {
491
+ obj.customItems = items => {
492
+ const activeItem = items[0];
493
+ const name = activeItem.data.name;
494
+ return this.formatedDataByName[name].map(item => {
495
+ return {
496
+ color: this.colorMap[item.group_name] || CHART_STYLE_COLORS[0],
497
+ data: item,
498
+ name: !item.group_name && typeof item.group_name !== 'number' ? intl.get(EMPTY_NAME) : item.group_name,
499
+ title: item.name,
500
+ value: BaseUtils.getSummaryValueDisplayString(summaryColumn, item.value, y_axis_summary_method)
501
+ };
502
+ });
503
+ };
504
+ }
505
+ return obj;
467
506
  };
468
- this.setToolTip = () => {
469
- const settings = this.getToolTipSettings();
507
+ this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method) => {
508
+ const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method);
470
509
  this.chart.tooltip(settings);
471
510
  };
472
511
  this.setToolTipForLine = () => {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce, maxBy } from 'lodash-es';
3
+ import { debounce, maxBy, throttle } from 'lodash-es';
4
4
  import classNames from 'classnames';
5
5
  import { CHART_TYPE, EMPTY_NAME } from '../../constants';
6
6
  import { BaseUtils, isFunction } from '../../utils';
@@ -62,13 +62,14 @@ class HorizontalBarGroup extends HorizontalComponent {
62
62
  label_font_size,
63
63
  type
64
64
  } = chart.config;
65
+ const isGroup = type === CHART_TYPE.HORIZONTAL_GROUP_BAR;
65
66
  const chartBarColor = this.groupName;
66
67
  const newData = this.getChartGroupData(data);
67
68
  let singleBarWidth, singleBarRadius;
68
69
  // y-axis label width:(6 + 10)
69
70
  // topPadding and legend height
70
71
  const chartHeight = this.chart.height - 6 - 10 - this.chartTopPadding - 30;
71
- if (type === CHART_TYPE.STACKED_HORIZONTAL_BAR) {
72
+ if (!isGroup) {
72
73
  singleBarWidth = Math.round(chartHeight / (2 * newData.length));
73
74
  this.markFirstOrLast(data, 'last');
74
75
  } else {
@@ -81,21 +82,34 @@ class HorizontalBarGroup extends HorizontalComponent {
81
82
  // set Coord type
82
83
  this.chart.coordinate('rect');
83
84
  this.autoAdjustDataOptions(chart, data, summaryColumn);
84
- const adjust = type === CHART_TYPE.STACKED_HORIZONTAL_BAR ? {
85
+ const adjust = !isGroup ? {
85
86
  type: 'stack'
86
87
  } : {
87
88
  type: 'dodge',
88
89
  marginRatio: 0
89
90
  };
90
- this.chart.interval().label(display_data ? 'value' : false, {
91
- formatter: value => {
92
- return value;
91
+ this.setColorMap(data);
92
+ this.chart.interval().animate({
93
+ // custom update animation
94
+ update: {
95
+ animation: 'fadeIn',
96
+ duration: 1000,
97
+ easing: 'easeLinear'
98
+ }
99
+ }).label(display_data ? 'value' : false, {
100
+ content: data => {
101
+ if (this.currentName) {
102
+ return data.name === this.currentName ? data.value : '';
103
+ }
104
+ return data.value;
93
105
  },
94
106
  style: {
95
107
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
96
108
  fill: theme.labelColor
97
109
  }
98
- }).position('name*value').size(singleBarWidth).color(chartBarColor).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
110
+ }).position('name*value').size(singleBarWidth).color(chartBarColor, group_name => {
111
+ return this.colorMap[group_name];
112
+ }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
99
113
  return {
100
114
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
101
115
  value: BaseUtils.getSummaryValueDisplayString(summaryColumn, value, horizontal_axis_summary_method),
@@ -125,12 +139,28 @@ class HorizontalBarGroup extends HorizontalComponent {
125
139
  };
126
140
  }
127
141
  });
128
- this.setToolTip();
142
+ if (isGroup) {
143
+ this.formatDataByName(data);
144
+ }
145
+ this.setToolTip(isGroup, summaryColumn, horizontal_axis_summary_method);
129
146
  this.setNameLabelAndTooltip(theme, this.labelCount);
130
147
  this.setValueLabel(theme);
131
148
  this.chart.coordinate().transpose();
132
149
  this.setLegend(this.groupName, theme, 'top-right');
133
- this.chart.interaction('element-highlight');
150
+ this.chart.interaction('element-highlight-by-x');
151
+ if (display_data) {
152
+ this.chart.on('element:mouseenter', throttle(e => {
153
+ const currentName = e.data.data.name;
154
+ if (this.currentName && this.currentName === currentName) return;
155
+ this.currentName = currentName;
156
+ this.chart.render(true);
157
+ }, 500));
158
+ this.chart.on('element:mouseleave', throttle(e => {
159
+ if (!this.currentName) return;
160
+ this.currentName = null;
161
+ this.chart.render(true);
162
+ }, 500));
163
+ }
134
164
  };
135
165
  this.chart = null;
136
166
  this.groupName = 'group_name';
@@ -71,7 +71,9 @@ class LineGroup extends ChartComponent {
71
71
  const line = this.chart.line().label(y_axis_show_value ? 'value' : false, {
72
72
  style: {
73
73
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
74
- fill: theme.labelColor
74
+ fill: theme.labelColor,
75
+ stroke: '#fff',
76
+ lineWidth: 1
75
77
  }
76
78
  }).animate({
77
79
  appear: {
@@ -71,7 +71,9 @@ class Line extends ChartComponent {
71
71
  const line = this.chart.line().label(y_axis_show_value ? 'value' : false, {
72
72
  style: {
73
73
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
74
- fill: theme.labelColor
74
+ fill: theme.labelColor,
75
+ stroke: '#fff',
76
+ lineWidth: 1
75
77
  }
76
78
  }).animate({
77
79
  appear: {
@@ -1,9 +1,9 @@
1
1
  import React, { PureComponent } from 'react';
2
+ import intl from '../../../intl';
3
+ import { eventStopPropagation } from '../../../utils';
2
4
  import TwoDimensionTable from './two-dimension-table';
3
5
  import OneDimensionTableNoNumericColumns from './one-dimension-table-no-numeric-columns';
4
6
  import OneDimensionTableWithNumericColumns from './one-dimension-table-with-numeric-columns';
5
- import intl from '../../../intl';
6
- import { eventStopPropagation } from '../../../utils';
7
7
  import './index.css';
8
8
  class Table extends PureComponent {
9
9
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
- import PivotTableDisplayName from './pivot-table-display-name';
4
3
  import { BaseUtils, ObjectUtils } from '../../../utils';
5
4
  import intl from '../../../intl';
5
+ import PivotTableDisplayName from './pivot-table-display-name';
6
6
  class OneDimensionTableNoNumericColumns extends PureComponent {
7
7
  constructor() {
8
8
  super(...arguments);
@@ -64,7 +64,8 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
64
64
  chart
65
65
  } = this.props;
66
66
  const {
67
- display_total = true
67
+ display_total = true,
68
+ display_empty
68
69
  } = chart.config;
69
70
  const {
70
71
  pivot_rows,
@@ -81,7 +82,7 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
81
82
  // eslint-disable-next-line
82
83
  const total = ObjectUtils.hasOwnProperty(pivot_columns_total, 'total') ? pivot_columns_total['total'] : 0;
83
84
  const summaryDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, total);
84
- const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue);
85
+ const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue, display_empty);
85
86
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
86
87
  const {
87
88
  name,
@@ -95,7 +96,7 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
95
96
  let isSelectedTotalCellLeft = selectRowIdx === rowIdx && selectedCellIdx === 0;
96
97
  pivotColumnCells[rowIdx] = rows;
97
98
  const totalDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, total.total);
98
- const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue);
99
+ const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue, display_empty);
99
100
  return /*#__PURE__*/React.createElement("tr", {
100
101
  key: 'table-row-' + rowIdx
101
102
  }, /*#__PURE__*/React.createElement("td", {
@@ -1,8 +1,8 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
- import PivotTableDisplayName from './pivot-table-display-name';
4
3
  import { BaseUtils } from '../../../utils';
5
4
  import intl from '../../../intl';
5
+ import PivotTableDisplayName from './pivot-table-display-name';
6
6
  class OneDimensionTableWithNumericColumns extends PureComponent {
7
7
  constructor(_props) {
8
8
  super(_props);
@@ -91,7 +91,8 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
91
91
  chart
92
92
  } = this.props;
93
93
  const {
94
- display_total = true
94
+ display_total = true,
95
+ display_empty
95
96
  } = chart.config;
96
97
  const {
97
98
  pivot_rows,
@@ -133,7 +134,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
133
134
  } = columnMap;
134
135
  const column = chartTableColumns.find(item => item.key === key);
135
136
  const displayValue = BaseUtils.getSummaryValueDisplayString(column, total[key], this.summaryColumnsMethodMap[key]);
136
- const isValidDisplayValue = BaseUtils.isValidValue(displayValue);
137
+ const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
137
138
  if (Array.isArray(rows) && rows.length > 0) {
138
139
  if (pivotColumnCells[cellIdx]) {
139
140
  pivotColumnCells[cellIdx].push(...rows);
@@ -167,7 +168,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
167
168
  const pivotColumnTotal = pivot_columns_total[c.key];
168
169
  const column = chartTableColumns.find(column => column.key === c.key);
169
170
  const totalDisplayValue = BaseUtils.getSummaryValueDisplayString(column, pivotColumnTotal, this.summaryColumnsMethodMap[c.key]);
170
- const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue);
171
+ const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue, display_empty);
171
172
  const isSelectRowTotalCell = selectRowIdx === pivot_rows.length && selectedCellIdx === index;
172
173
  const isSelectRowTotalCellLeft = selectRowIdx === pivot_rows.length && selectedCellIdx - 1 === index;
173
174
  return /*#__PURE__*/React.createElement("td", {
@@ -1,8 +1,8 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
- import PivotTableDisplayName from './pivot-table-display-name';
4
3
  import { BaseUtils } from '../../../utils';
5
4
  import intl from '../../../intl';
5
+ import PivotTableDisplayName from './pivot-table-display-name';
6
6
  class TwoDimensionTable extends PureComponent {
7
7
  constructor() {
8
8
  super(...arguments);
@@ -108,7 +108,8 @@ class TwoDimensionTable extends PureComponent {
108
108
  chart
109
109
  } = this.props;
110
110
  const {
111
- display_total = true
111
+ display_total = true,
112
+ display_empty
112
113
  } = chart.config;
113
114
  const {
114
115
  pivot_rows,
@@ -125,7 +126,7 @@ class TwoDimensionTable extends PureComponent {
125
126
  const isSelectRowTotalCellRight = selectRowIdx === pivotRowsLen && selectedCellIdx === 0;
126
127
  const isSelectTotal = selectRowIdx === pivotRowsLen && selectedCellIdx === (Array.isArray(pivot_columns) ? pivot_columns.length : 0);
127
128
  const tableTotalDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, pivot_table_total, summaryMethod);
128
- const isValidTableTotalDisplayValue = BaseUtils.isValidValue(tableTotalDisplayValue);
129
+ const isValidTableTotalDisplayValue = BaseUtils.isValidValue(tableTotalDisplayValue, display_empty);
129
130
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
130
131
  const {
131
132
  name,
@@ -141,7 +142,7 @@ class TwoDimensionTable extends PureComponent {
141
142
  pivotColumnCells[rowIdx] = rowItem.rows || [];
142
143
  }
143
144
  const summaryDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, total, summaryMethod);
144
- const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue);
145
+ const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue, display_empty);
145
146
  return /*#__PURE__*/React.createElement("tr", {
146
147
  key: 'table-row' + rowIdx
147
148
  }, /*#__PURE__*/React.createElement("td", {
@@ -160,7 +161,7 @@ class TwoDimensionTable extends PureComponent {
160
161
  total
161
162
  } = c;
162
163
  const displayValue = BaseUtils.getSummaryValueDisplayString(column, total, summaryMethod);
163
- const isValidDisplayValue = BaseUtils.isValidValue(displayValue);
164
+ const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
164
165
  if (c && Array.isArray(c.rows) && c.rows.length > 0) {
165
166
  pivotRowCells.push(...c.rows);
166
167
  if (pivotColumnCells[cellIdx]) {
@@ -210,7 +211,7 @@ class TwoDimensionTable extends PureComponent {
210
211
  const isSelectRowTotalCellLeft = selectRowIdx === pivot_rows.length && selectedCellIdx - 1 === index;
211
212
  const pivotColumnTotal = pivot_columns_total[c.key];
212
213
  const totalDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, pivotColumnTotal, summaryMethod);
213
- const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue);
214
+ const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue, display_empty);
214
215
  return /*#__PURE__*/React.createElement("td", {
215
216
  className: classnames('pivot-cell', {
216
217
  'pivot-empty-cell': !isValidTotalDisplayValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",