sea-chart 0.0.36 → 0.0.37

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.
@@ -63,7 +63,22 @@ export const BASIC_NUMBER_CARD_CALCULATION_METHOD = 'Row_count';
63
63
  export const CHART_DATE_SUMMARY_CALCULATION_METHOD = ['Max', 'Min', 'Distinct_values'];
64
64
  export const CHART_SUPPORT_COLUMNS = [CellType.DATE, CellType.SINGLE_SELECT, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR, CellType.TEXT, CellType.NUMBER, CellType.FORMULA, CellType.LINK_FORMULA, CellType.GEOLOCATION, CellType.LINK, CellType.MTIME, CellType.CTIME, CellType.CREATOR, CellType.LAST_MODIFIER, CellType.CHECKBOX, CellType.RATE, CellType.DURATION];
65
65
  export const CHART_SUPPORT_SORT_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.SINGLE_SELECT, CellType.FORMULA, CellType.LINK_FORMULA, CellType.CTIME, CellType.MTIME, CellType.RATE, CellType.DURATION];
66
- export const LABEL_COLORS = ['#2a67d1', '#4ecccb', '#59cb74', '#fbd44a', '#f4667c', '#9860e5', '#9f8cf1', '#dc82d2', '#eaa775', '#addf84', '#85e0be', '#89d2ea'];
66
+
67
+ // export const LABEL_COLORS = [
68
+ // '#2a67d1',
69
+ // '#4ecccb',
70
+ // '#59cb74',
71
+ // '#fbd44a',
72
+ // '#f4667c',
73
+ // '#9860e5',
74
+ // '#9f8cf1',
75
+ // '#dc82d2',
76
+ // '#eaa775',
77
+ // '#addf84',
78
+ // '#85e0be',
79
+ // '#89d2ea'
80
+ // ];
81
+
67
82
  export const TIME_COLUMN_LIST = [CellType.CTIME, CellType.MTIME, CellType.DATE];
68
83
  export const DATE_GRANULATES = [CHART_SUMMARY_TYPE.DAY, CHART_SUMMARY_TYPE.WEEK, CHART_SUMMARY_TYPE.MONTH, CHART_SUMMARY_TYPE.QUARTER, CHART_SUMMARY_TYPE.YEAR];
69
84
  export const GEOLOCATION_GRANULATES = [CHART_SUMMARY_TYPE.PROVINCE, CHART_SUMMARY_TYPE.CITY, CHART_SUMMARY_TYPE.DISTRICT];
@@ -173,6 +188,10 @@ export const CHART_THEME_COLOR = {
173
188
  gridColor: '#F3F3F3',
174
189
  XAxisColor: '#CCCCCC',
175
190
  labelColor: '#999999',
191
+ ringLabelColor: '#212529',
192
+ annotationTitleFontColor: '#666666',
193
+ annotationValueFontColor: '#212529',
194
+ annotationFontSize: 18,
176
195
  cardColor: '#545454',
177
196
  legendTextColor: '#333333',
178
197
  legendFontSize: 14,
@@ -1,5 +1,5 @@
1
1
  import { isBoolean } from '../utils';
2
- import { CHART_TYPE, CHART_SUMMARY_TYPE } from '../constants';
2
+ import { CHART_TYPE, CHART_SUMMARY_TYPE, CHART_LINE_TYPES } from '../constants';
3
3
  import BaseModel from './base-model';
4
4
  class Combination extends BaseModel {
5
5
  constructor(options) {
@@ -33,6 +33,7 @@ class Combination extends BaseModel {
33
33
  this.y_axis_max_right = options.y_axis_max_right;
34
34
  this.display_data = isBoolean(options.y_axis_show_value) ? options.y_axis_show_value : false;
35
35
  this.label_font_size = options.label_font_size;
36
+ this.line_type = options.line_type || CHART_LINE_TYPES[1];
36
37
  }
37
38
  }
38
39
  export default Combination;
@@ -1,6 +1,6 @@
1
- import BaseModel from './base-model';
2
1
  import { isBoolean } from '../utils';
3
2
  import { CHART_TYPE, CHART_LABEL_POSITIONS, CHART_LABEL_FORMATS, CHART_SUMMARY_TYPE } from '../constants';
3
+ import BaseModel from './base-model';
4
4
  class Ring extends BaseModel {
5
5
  constructor(options) {
6
6
  super({
@@ -21,6 +21,7 @@ class Ring extends BaseModel {
21
21
  this.minimum_slice_percent = options.minimum_slice_percent;
22
22
  this.sort_type = options.sort_type;
23
23
  this.label_font_size = options.label_font_size;
24
+ this.show_annotation = options.show_annotation || true;
24
25
  }
25
26
  }
26
27
  export default Ring;
@@ -8,6 +8,7 @@ import DisplayValuesSettings from '../widgets/display-values-settings';
8
8
  import { eventStopPropagation } from '../../utils';
9
9
  import { X_LABEL_POSITIONS, Y_LABEL_POSITIONS, LABEL_POSITION_TYPE_SHOW } from '../../constants';
10
10
  import intl from '../../intl';
11
+ import SelectLineType from '../widgets/select-line-type';
11
12
  const StyleSettings = _ref => {
12
13
  let {
13
14
  chart,
@@ -96,12 +97,16 @@ const StyleSettings = _ref => {
96
97
  y_axis_min_right,
97
98
  y_axis_max_right,
98
99
  display_data,
99
- label_font_size
100
+ label_font_size,
101
+ line_type
100
102
  } = config;
101
103
  const xAxisLabelPosition = xAxisLabelOptions.find(option => option.value === x_axis_label_position) || xAxisLabelOptions[0];
102
104
  const yLeftAxisLabelPosition = yAxisLabelOptions.find(option => option.value === y_axis_left_label_position) || yAxisLabelOptions[0];
103
105
  const yRightAxisLabelPosition = yAxisLabelOptions.find(option => option.value === y_axis_right_label_position) || yAxisLabelOptions[0];
104
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormGroup, {
106
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SelectLineType, {
107
+ selectedLineType: line_type,
108
+ onChange: onChange
109
+ }), /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(FormGroup, {
105
110
  className: "sea-chart-parameter-item"
106
111
  }, /*#__PURE__*/React.createElement(Label, null, intl.get(xLabel)), /*#__PURE__*/React.createElement(Switch, {
107
112
  key: "x_axis_show_label",
@@ -5,7 +5,7 @@ import { CHART_LINE_TYPES } from '../../../constants';
5
5
  import intl from '../../../intl';
6
6
  function SelectLineType(_ref) {
7
7
  let {
8
- selectedLineType,
8
+ selectedLineType = CHART_LINE_TYPES[1],
9
9
  onChange
10
10
  } = _ref;
11
11
  const onChangeLineType = lineType => {
@@ -2,7 +2,7 @@ var _SQLStatisticsUtils;
2
2
  import dayjs from 'dayjs';
3
3
  import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber } from 'dtable-utils';
4
4
  import { isObject } from 'lodash';
5
- import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, LABEL_COLORS, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX } from '../../constants';
5
+ import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, LABEL_COLORS, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS } from '../../constants';
6
6
  import { chartColumn2SqlColumn, summaryMethodColumn2SqlColumn } from '../sql';
7
7
  import { getClientLinkDisplayString } from '../cell-format-utils';
8
8
  import context from '../../context';
@@ -1025,17 +1025,33 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1025
1025
  let leftSummaryColumn = getTableColumnByKey(table, y_axis_left_summary_column);
1026
1026
  const summaryMethod = y_axis_left_summary_method.toUpperCase();
1027
1027
  const {
1028
- key: groupItem
1028
+ key
1029
1029
  } = summaryMethodColumn2SqlColumn(summaryMethod, leftSummaryColumn || {});
1030
- leftSummaryColumn && !groupItems.includes(groupItem) && groupItems.push(groupItem);
1030
+ const groupItem = {
1031
+ sqlName: key,
1032
+ column: leftSummaryColumn
1033
+ };
1034
+ const exists = groupItems.find(v => v.sqlName === key);
1035
+ if (!exists && leftSummaryColumn) {
1036
+ groupItems.push(groupItem);
1037
+ }
1038
+ // leftSummaryColumn && !groupItems.includes(groupItem) && groupItems.push(groupItem);
1031
1039
  y_axis_left_group_by_numeric_columns.forEach((item, index) => {
1032
1040
  const column = getTableColumnByKey(table, item.column_key);
1033
1041
  if (column) {
1034
1042
  const itemSummaryMethod = item.summary_method.toUpperCase();
1035
1043
  const {
1036
- key: groupItem
1044
+ key
1037
1045
  } = summaryMethodColumn2SqlColumn(itemSummaryMethod, column || {});
1038
- !groupItems.includes(groupItem) && groupItems.push(groupItem);
1046
+ const groupItem = {
1047
+ sqlName: key,
1048
+ column
1049
+ };
1050
+ const exists = groupItems.find(v => v.sqlName === key);
1051
+ if (!exists) {
1052
+ groupItems.push(groupItem);
1053
+ }
1054
+ // !groupItems.includes(groupItem) && groupItems.push(groupItem);
1039
1055
  }
1040
1056
  });
1041
1057
  sqlRows.forEach((item, index) => {
@@ -1046,7 +1062,10 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1046
1062
  valueRight = BaseUtils.getPrecisionNumber(valueRight, rightSummaryColumn.data);
1047
1063
  }
1048
1064
  groupItems.forEach((groupItem, index) => {
1049
- let value = item[groupItem] || 0;
1065
+ var _groupItem$column;
1066
+ const sqlName = groupItem.sqlName;
1067
+ const groupName = (_groupItem$column = groupItem.column) === null || _groupItem$column === void 0 ? void 0 : _groupItem$column.name;
1068
+ let value = item[sqlName] || 0;
1050
1069
  if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
1051
1070
  value = BaseUtils.getPrecisionNumber(value, leftSummaryColumn.data);
1052
1071
  }
@@ -1054,7 +1073,8 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1054
1073
  name: key,
1055
1074
  value_left: value,
1056
1075
  value_right: valueRight,
1057
- color: LABEL_COLORS[index % 12]
1076
+ group_name: groupName,
1077
+ color: STYLE_COLORS[0].colors[index % 12]
1058
1078
  });
1059
1079
  });
1060
1080
  });
@@ -91,6 +91,7 @@ import ScaleTranslate from '@antv/g2/esm/interaction/action/view/scale-translate
91
91
  import ScaleZoom from '@antv/g2/esm/interaction/action/view/scale-zoom';
92
92
  import { getAngle, polarToCartesian } from '@antv/g2/esm/util/graphics';
93
93
  import { rotate, transform, translate, zoom } from '@antv/g2/esm/util/transform';
94
+ import { Action, registerShape } from '@antv/g2';
94
95
  export { getRectWithCornerRadius } from '@antv/g2/esm/geometry/shape/interval/util';
95
96
  // 注册 G 渲染引擎
96
97
  registerEngine('canvas', CanvasEngine);
@@ -208,6 +209,47 @@ registerAction('reset-button', ButtonAction, {
208
209
  name: 'reset-button',
209
210
  text: 'reset'
210
211
  });
212
+ registerShape('interval', 'withGap', {
213
+ draw(cfg, container) {
214
+ const points = cfg.points;
215
+ let path = [];
216
+ path.push(['M', points[0].x, points[0].y]);
217
+ path.push(['L', points[1].x, points[1].y - 0.0015]);
218
+ path.push(['L', points[2].x, points[2].y - 0.0015]);
219
+ path.push(['L', points[3].x, points[3].y]);
220
+ path.push('Z');
221
+ path = this.parsePath(path);
222
+ return container.addShape('path', {
223
+ attrs: {
224
+ fill: cfg.color,
225
+ path
226
+ }
227
+ });
228
+ }
229
+ });
230
+ class HighlightXOnlyBar extends Action {
231
+ highlight() {
232
+ const elements = this.context.view.geometries[0].elements;
233
+ elements.forEach(element => {
234
+ const {
235
+ data
236
+ } = element.getModel();
237
+ if (data.type === 'bar') {
238
+ element.setState('active', true);
239
+ } else {
240
+ element.hide();
241
+ }
242
+ });
243
+ }
244
+ reset() {
245
+ const elements = this.context.view.geometries[0].elements;
246
+ elements.forEach(element => {
247
+ element.setState('active', false);
248
+ element.show();
249
+ });
250
+ }
251
+ }
252
+ registerAction('highlight-x-only-bar', HighlightXOnlyBar);
211
253
 
212
254
  // 注册默认的 Interaction 交互行为
213
255
  function isPointInView(context) {
@@ -367,17 +367,15 @@ class ChartDataSQL {
367
367
  let summary_column_name = '';
368
368
  if (right_summary_type === 'COUNT') {
369
369
  summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
370
+ return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
370
371
  } else {
371
372
  const right_summary_column = this._get_column_by_key(y_axis_right_summary_column);
372
373
  if (right_summary_column) {
373
374
  const right_summary_method = y_axis_right_summary_method.toUpperCase();
374
375
  summary_column_name = this._summary_column_2_sql(right_summary_method, right_summary_column);
376
+ return "SELECT ".concat(groupby_column_name, ", COUNT(").concat(groupby_column_name, "), ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
375
377
  }
376
378
  }
377
- if (summary_column_name) {
378
- return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
379
- }
380
- return "SELECT ".concat(groupby_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
381
379
  }
382
380
  if (y_axis_left_group_by_multiple_numeric_column) {
383
381
  let column_groupby_numeric_columns = y_axis_left_group_by_numeric_columns.slice(0);
@@ -78,7 +78,7 @@ class Bar extends ChartComponent {
78
78
  this.chart.interval().label(y_axis_show_value ? 'value' : false, {
79
79
  style: {
80
80
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
81
- fill: theme.labelColor,
81
+ fill: theme.ringLabelColor,
82
82
  stroke: '#fff',
83
83
  lineWidth: 1
84
84
  }
@@ -347,12 +347,10 @@ export default class ChartComponent extends Component {
347
347
  }
348
348
  return label;
349
349
  };
350
- // set legend
351
- this.setLegend = function (legendName) {
352
- let theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHART_THEME_COLOR['light'];
353
- let legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom';
354
- if (!_this.chart) return;
355
- _this.chart.legend(legendName, {
350
+ this.getLegendConfig = function () {
351
+ let theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CHART_THEME_COLOR['light'];
352
+ let legendPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top-right';
353
+ return {
356
354
  // custom: true,
357
355
  position: legendPosition,
358
356
  itemName: {
@@ -364,6 +362,8 @@ export default class ChartComponent extends Component {
364
362
  formatter: name => {
365
363
  if (!name && typeof name !== 'number') {
366
364
  return intl.get(EMPTY_NAME);
365
+ } else if (name === '_Others') {
366
+ return intl.get('Others');
367
367
  } else {
368
368
  return intl.get(name) || name;
369
369
  }
@@ -411,7 +411,26 @@ export default class ChartComponent extends Component {
411
411
  return style;
412
412
  }
413
413
  }
414
- });
414
+ };
415
+ };
416
+ // set legend
417
+ this.setLegend = function (legendName) {
418
+ let theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHART_THEME_COLOR['light'];
419
+ let legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom';
420
+ if (!_this.chart) return;
421
+ const basicLegendConfig = _this.getLegendConfig(theme, legendPosition);
422
+ _this.chart.legend(legendName, basicLegendConfig);
423
+ };
424
+ // theta is pie or ring chart
425
+ this.setLegendForTheta = function (legendName) {
426
+ let theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CHART_THEME_COLOR['light'];
427
+ let legendPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom';
428
+ let offsetX = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
429
+ if (!_this.chart) return;
430
+ const basicLegendConfig = _this.getLegendConfig(theme, legendPosition);
431
+ basicLegendConfig.offsetX = offsetX;
432
+ basicLegendConfig.itemName.style.fontSize = theme.fontSize;
433
+ _this.chart.legend(legendName, basicLegendConfig);
415
434
  };
416
435
  this.setColorMap = data => {
417
436
  let currentIdx = 0;
@@ -465,6 +484,7 @@ export default class ChartComponent extends Component {
465
484
  textOverflow: 'ellipsis'
466
485
  },
467
486
  'g2-tooltip-list-item': {
487
+ marginTop: '8px',
468
488
  marginBottom: '8px',
469
489
  display: 'flex'
470
490
  },
@@ -553,6 +573,13 @@ export default class ChartComponent extends Component {
553
573
  ...lineToolTipSettings
554
574
  });
555
575
  };
576
+ // theta is pie or ring chart
577
+ this.setToolTipForTheta = () => {
578
+ const settings = this.getToolTipSettings();
579
+ settings.showTitle = false;
580
+ settings.containerTpl = "<div class=\"g2-tooltip\">\n <ul class=\"g2-tooltip-list\"></ul>\n </div>";
581
+ this.chart.tooltip(settings);
582
+ };
556
583
  this.isShowXAxisLabel = chart => {
557
584
  return !!(chart && chart.config && chart.config.x_axis_show_label);
558
585
  };