sea-chart 0.0.19 → 0.0.21

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.
Files changed (41) hide show
  1. package/dist/constants/index.js +4 -1
  2. package/dist/locale/lang/de.js +4 -1
  3. package/dist/locale/lang/en.js +6 -1
  4. package/dist/locale/lang/es.js +4 -1
  5. package/dist/locale/lang/fr.js +4 -1
  6. package/dist/locale/lang/pt.js +4 -1
  7. package/dist/locale/lang/ru.js +4 -1
  8. package/dist/locale/lang/zh_CN.js +9 -4
  9. package/dist/model/area-group.js +4 -2
  10. package/dist/model/area.js +3 -2
  11. package/dist/model/basic-number-card.js +5 -1
  12. package/dist/model/line-group.js +3 -2
  13. package/dist/model/line.js +3 -2
  14. package/dist/settings/advance-bar-settings/style-settings.js +8 -2
  15. package/dist/settings/bar-settings/style-settings.js +10 -3
  16. package/dist/settings/basic-number-card/style-settings.js +48 -3
  17. package/dist/settings/widgets/select-line-type/index.css +0 -0
  18. package/dist/settings/widgets/select-line-type/index.js +27 -0
  19. package/dist/view/index.css +16 -6
  20. package/dist/view/index.js +7 -5
  21. package/dist/view/wrapper/area.js +77 -41
  22. package/dist/view/wrapper/bar-custom.js +2 -2
  23. package/dist/view/wrapper/bar-group.js +2 -2
  24. package/dist/view/wrapper/bar.js +2 -2
  25. package/dist/view/wrapper/basic-number-card.js +6 -33
  26. package/dist/view/wrapper/chart-component.js +49 -3
  27. package/dist/view/wrapper/combination.js +1 -1
  28. package/dist/view/wrapper/compare.js +1 -1
  29. package/dist/view/wrapper/completeness.js +2 -2
  30. package/dist/view/wrapper/dashboard.js +1 -1
  31. package/dist/view/wrapper/horizontal-bar-group.js +2 -2
  32. package/dist/view/wrapper/horizontal-bar.js +4 -10
  33. package/dist/view/wrapper/line-group.js +64 -48
  34. package/dist/view/wrapper/line.js +69 -64
  35. package/dist/view/wrapper/map.js +1 -1
  36. package/dist/view/wrapper/pie.js +1 -1
  37. package/dist/view/wrapper/ring.js +2 -2
  38. package/dist/view/wrapper/scatter.js +1 -1
  39. package/dist/view/wrapper/treemap.js +1 -1
  40. package/dist/view/wrapper/world-map.js +1 -1
  41. package/package.json +1 -1
@@ -21,7 +21,7 @@ class BarCustom extends ChartComponent {
21
21
  const {
22
22
  y_axis_show_value
23
23
  } = chart.config;
24
- const appendPadding = [y_axis_show_value ? 47 : 30, 0, 0, 0]; // used to display value on the top
24
+ const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0]; // used to display value on the top
25
25
  this.initChart(this.container, {
26
26
  appendPadding
27
27
  });
@@ -192,7 +192,7 @@ class BarCustom extends ChartComponent {
192
192
  }
193
193
  render() {
194
194
  return /*#__PURE__*/React.createElement("div", {
195
- className: 'sea-chart-container w-100',
195
+ className: 'sea-chart-container ',
196
196
  ref: ref => this.container = ref
197
197
  });
198
198
  }
@@ -24,7 +24,7 @@ class BarGroup extends ChartComponent {
24
24
  const {
25
25
  y_axis_show_value
26
26
  } = chart.config;
27
- const appendPadding = [y_axis_show_value ? 47 : 30, 0, 0, 0];
27
+ const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0];
28
28
  this.initChart(this.container, {
29
29
  appendPadding
30
30
  });
@@ -209,7 +209,7 @@ class BarGroup extends ChartComponent {
209
209
  }
210
210
  render() {
211
211
  return /*#__PURE__*/React.createElement("div", {
212
- className: 'sea-chart-container w-100',
212
+ className: 'sea-chart-container',
213
213
  ref: ref => this.container = ref
214
214
  });
215
215
  }
@@ -21,7 +21,7 @@ class Bar extends ChartComponent {
21
21
  const {
22
22
  y_axis_show_value
23
23
  } = chart.config;
24
- const appendPadding = [y_axis_show_value ? 47 : 30, 0, 0, 0]; // used to display value on the top
24
+ const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0]; // used to display value on the top
25
25
  this.initChart(this.container, {
26
26
  appendPadding
27
27
  });
@@ -132,7 +132,7 @@ class Bar extends ChartComponent {
132
132
  }
133
133
  render() {
134
134
  return /*#__PURE__*/React.createElement("div", {
135
- className: 'sea-chart-container w-100',
135
+ className: 'sea-chart-container ',
136
136
  ref: ref => this.container = ref
137
137
  });
138
138
  }
@@ -28,7 +28,11 @@ class BasicNumericCard extends Component {
28
28
  } = chart;
29
29
  const {
30
30
  summary_method,
31
- name
31
+ name,
32
+ font_size,
33
+ font_color,
34
+ label_font_size,
35
+ label_font_color
32
36
  } = config;
33
37
  let content = null;
34
38
  if (summary_method === 'Distinct_values') {
@@ -36,17 +40,9 @@ class BasicNumericCard extends Component {
36
40
  } else {
37
41
  content = this.formatData(result);
38
42
  }
39
- const fontSize = this.getFontSize(content);
40
- let labelFontSize = fontSize - 35;
41
- if (labelFontSize > 20) {
42
- labelFontSize = 20;
43
- }
44
- if (labelFontSize < 12) {
45
- labelFontSize = 12;
46
- }
47
43
  this.chart.annotation().html({
48
44
  position: ['50%', '50%'],
49
- html: "\n <div style=\"color: ".concat(theme.cardColor, "; text-align: center;\">\n <p class=\"text-content\" style=\"font-size: ").concat(fontSize, "px; margin: -15px 0 2px 0;\">").concat(content, "</p>\n <p style=\"font-size: ").concat(labelFontSize, "px;margin: 0;overflow: hidden;text-overflow: ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;\">").concat(name, "</p>\n </div>\n ")
45
+ html: "\n <div style=\"color: ".concat(theme.cardColor, "; text-align: center;\">\n <p class=\"text-content\" style=\"font-size: ").concat(font_size, "px; color: ").concat(font_color, "; margin: -15px 0 2px 0;\">").concat(content, "</p>\n <p style=\"font-size: ").concat(label_font_size, "px; color: ").concat(label_font_color, "; margin: 0;overflow: hidden;text-overflow: ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;\">").concat(name, "</p>\n </div>\n ")
50
46
  });
51
47
  isFunction(customRender) && customRender(this.chart);
52
48
  this.chart.render();
@@ -89,29 +85,6 @@ class BasicNumericCard extends Component {
89
85
  }
90
86
  return content;
91
87
  };
92
- this.getFontSize = content => {
93
- let canvas = document.createElement('canvas');
94
- const context = canvas.getContext('2d');
95
- const {
96
- width
97
- } = this.chart;
98
- let font = context.font;
99
- let initFontSize = 50;
100
- const fontStyle = font.slice(font.indexOf('px'));
101
- font = initFontSize + fontStyle;
102
- context.font = font;
103
- context.fontSize = initFontSize;
104
- while (context.measureText(content).width >= width - 40) {
105
- initFontSize -= 1;
106
- context.font = initFontSize + fontStyle;
107
- context.fontSize = initFontSize;
108
- }
109
- canvas = null;
110
- if (initFontSize < 16) {
111
- initFontSize = 16;
112
- }
113
- return initFontSize;
114
- };
115
88
  }
116
89
  componentDidUpdate(prevProps) {
117
90
  if (BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
@@ -1,6 +1,6 @@
1
1
  import { Component } from 'react';
2
2
  import { getTableById, getTableColumnByKey } from 'dtable-utils';
3
- import { cloneDeep } from 'lodash-es';
3
+ import { cloneDeep, debounce } from 'lodash-es';
4
4
  import { Chart } from '../../utils/custom-g2';
5
5
  import { BaseUtils } from '../../utils';
6
6
  import { CHART_TYPE, CHART_SUMMARY_TYPE, LABEL_POSITION_TYPE, CHART_THEME_COLOR, EMPTY_NAME, THEME_NAME_MAP } from '../../constants';
@@ -10,6 +10,15 @@ export default class ChartComponent extends Component {
10
10
  var _this;
11
11
  super(...arguments);
12
12
  _this = this;
13
+ this.handleResize = debounce(() => {
14
+ if (!this.createChart || !this.drawChart) return;
15
+ this.chart && this.chart.destroy();
16
+ this.createChart();
17
+ this.drawChart();
18
+ if (this.needRenderAxisLabel) {
19
+ this.renderAxisLabel(this.props.chart, this.props.tables);
20
+ }
21
+ }, 300);
13
22
  this.initChart = (container, _ref) => {
14
23
  let {
15
24
  appendPadding,
@@ -389,12 +398,17 @@ export default class ChartComponent extends Component {
389
398
  // Draw the bottom line back to the right edge of the left semi-circle
390
399
  ['A', r, r, 0, 0, 1, x - rectWidth / 2 - 3, y - r - 1] // Draw the left semi-circle
391
400
  ];
401
+ },
402
+ style: style => {
403
+ // fill legend with stroke color
404
+ style.fill = style.stroke;
405
+ return style;
392
406
  }
393
407
  }
394
408
  });
395
409
  };
396
- this.setToolTip = () => {
397
- this.chart.tooltip({
410
+ this.getToolSettings = () => {
411
+ return {
398
412
  showMarkers: false,
399
413
  domStyles: {
400
414
  'g2-tooltip': {
@@ -431,6 +445,32 @@ export default class ChartComponent extends Component {
431
445
  fontSize: '12px'
432
446
  }
433
447
  }
448
+ };
449
+ };
450
+ this.setToolTip = () => {
451
+ const settings = this.getToolSettings();
452
+ this.chart.tooltip(settings);
453
+ };
454
+ this.setToolTipForLine = () => {
455
+ const settings = this.getToolSettings();
456
+ const lineToolTipSettings = {
457
+ showCrosshairs: true,
458
+ showTitle: true,
459
+ shared: true,
460
+ showMarkers: true,
461
+ marker: {
462
+ strokeOpacity: 0,
463
+ r: 6
464
+ },
465
+ crosshairs: {
466
+ line: {
467
+ fill: '#e2e2e2'
468
+ }
469
+ }
470
+ };
471
+ this.chart.tooltip({
472
+ ...settings,
473
+ ...lineToolTipSettings
434
474
  });
435
475
  };
436
476
  this.isShowXAxisLabel = chart => {
@@ -449,4 +489,10 @@ export default class ChartComponent extends Component {
449
489
  return themeColors || CHART_THEME_COLOR[THEME_NAME_MAP.LIGHT];
450
490
  };
451
491
  }
492
+ componentDidMount() {
493
+ window.addEventListener('resize', this.handleResize);
494
+ }
495
+ componentWillUnmount() {
496
+ window.removeEventListener('resize', this.handleResize);
497
+ }
452
498
  }
@@ -389,7 +389,7 @@ class Combination extends React.Component {
389
389
  chart
390
390
  } = this.props;
391
391
  return /*#__PURE__*/React.createElement("div", {
392
- className: classnames('sea-chart-container w-100', {
392
+ className: classnames('sea-chart-container ', {
393
393
  'show-x-axis-label': this.isShowXAxisLabel(chart),
394
394
  'show-y-axis-left-label': this.isShowYAxisLeftLabel(chart),
395
395
  'show-y-axis-right-label': this.isShowYAxisRightLabel(chart)
@@ -250,7 +250,7 @@ class Compare extends ChartComponent {
250
250
  chart
251
251
  } = this.props;
252
252
  return /*#__PURE__*/React.createElement("div", {
253
- className: classnames('sea-chart-container w-100', {
253
+ className: classnames('sea-chart-container ', {
254
254
  'show-x-axis-label': this.isShowXAxisLabel(chart),
255
255
  'show-y-axis-label': this.isShowYAxisLabel(chart)
256
256
  }),
@@ -29,7 +29,7 @@ export default function Completeness(props) {
29
29
  style_config
30
30
  }
31
31
  } = props;
32
- chartPaddingTop = ((_style_config$title = style_config.title) === null || _style_config$title === void 0 ? void 0 : _style_config$title.text) ? 47 : 30;
32
+ chartPaddingTop = ((_style_config$title = style_config.title) === null || _style_config$title === void 0 ? void 0 : _style_config$title.text) ? 17 : 0;
33
33
  const appendPadding = [chartPaddingTop, 30, 0, 0];
34
34
  currentChart.initChart(chartContainerRef.current, {
35
35
  appendPadding
@@ -157,7 +157,7 @@ export default function Completeness(props) {
157
157
  };
158
158
  }, [props]);
159
159
  return /*#__PURE__*/React.createElement("div", {
160
- className: classnames('sea-chart-completeness-chart sea-chart-container w-100'),
160
+ className: classnames('sea-chart-completeness-chart sea-chart-container '),
161
161
  ref: chartContainerRef
162
162
  });
163
163
  }
@@ -159,7 +159,7 @@ class Dashboard extends Component {
159
159
  render() {
160
160
  return /*#__PURE__*/React.createElement("div", {
161
161
  ref: ref => this.container = ref,
162
- className: "sea-chart-container w-100"
162
+ className: "sea-chart-container "
163
163
  });
164
164
  }
165
165
  }
@@ -21,7 +21,7 @@ class HorizontalBarGroup extends HorizontalComponent {
21
21
  const {
22
22
  display_data
23
23
  } = chart.config;
24
- this.chartTopPadding = display_data ? 47 : 30;
24
+ this.chartTopPadding = display_data ? 17 : 0;
25
25
  const appendPadding = [this.chartTopPadding, 0, 0, 0];
26
26
  this.initChart(this.container, {
27
27
  appendPadding
@@ -154,7 +154,7 @@ class HorizontalBarGroup extends HorizontalComponent {
154
154
  }
155
155
  render() {
156
156
  return /*#__PURE__*/React.createElement("div", {
157
- className: 'sea-chart-container w-100',
157
+ className: 'sea-chart-container ',
158
158
  ref: ref => this.container = ref
159
159
  });
160
160
  }
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classnames from 'classnames';
4
3
  import { debounce } from 'lodash-es';
5
4
  import { CHART_SUMMARY_TYPE, CHART_SUMMARY_SHOW } from '../../constants';
6
5
  import { BaseUtils, isFunction } from '../../utils';
@@ -9,11 +8,6 @@ import HorizontalComponent from './horizontal-component';
9
8
  class HorizontalBar extends HorizontalComponent {
10
9
  constructor(props) {
11
10
  super(props);
12
- this.handleResize = debounce(() => {
13
- this.chart && this.chart.destroy();
14
- this.createChart();
15
- this.drawChart();
16
- }, 300);
17
11
  this.createChart = () => {
18
12
  const {
19
13
  chart
@@ -21,7 +15,7 @@ class HorizontalBar extends HorizontalComponent {
21
15
  const {
22
16
  display_data
23
17
  } = chart.config;
24
- const appendPadding = [0, display_data ? 47 : 30, 0, 0]; // used to display value on the right
18
+ const appendPadding = [0, display_data ? 17 : 0, 0, 0]; // used to display value on the right
25
19
  this.initChart(this.container, {
26
20
  appendPadding
27
21
  });
@@ -117,7 +111,7 @@ class HorizontalBar extends HorizontalComponent {
117
111
  componentDidMount() {
118
112
  this.createChart();
119
113
  this.drawChart();
120
- window.addEventListener('resize', this.handleResize);
114
+ super.componentDidMount();
121
115
  }
122
116
  componentDidUpdate(prevProps) {
123
117
  if (BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
@@ -128,11 +122,11 @@ class HorizontalBar extends HorizontalComponent {
128
122
  }
129
123
  componentWillUnmount() {
130
124
  this.chart && this.chart.destroy();
131
- window.removeEventListener('resize', this.handleResize);
125
+ super.componentWillUnmount();
132
126
  }
133
127
  render() {
134
128
  return /*#__PURE__*/React.createElement("div", {
135
- className: classnames('sea-chart-container w-100'),
129
+ className: 'sea-chart-container',
136
130
  ref: ref => this.container = ref
137
131
  });
138
132
  }
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import classnames from 'classnames';
4
4
  import { BaseUtils, isFunction } from '../../utils';
5
5
  import intl from '../../intl';
6
+ import { CHART_LINE_TYPES, CHART_SUMMARY_SHOW, CHART_SUMMARY_TYPE } from '../../constants';
6
7
  import ChartComponent from './chart-component';
7
8
  class LineGroup extends ChartComponent {
8
9
  constructor(props) {
@@ -14,7 +15,7 @@ class LineGroup extends ChartComponent {
14
15
  const {
15
16
  y_axis_show_value
16
17
  } = chart.config;
17
- const appendPadding = [y_axis_show_value ? 47 : 30, 0, 0, 0];
18
+ const appendPadding = [y_axis_show_value ? 17 : 0, 0, 0, 0];
18
19
  this.initChart(this.container, {
19
20
  appendPadding
20
21
  });
@@ -49,11 +50,15 @@ class LineGroup extends ChartComponent {
49
50
  } = this.props;
50
51
  const {
51
52
  y_axis_show_value,
52
- label_font_size
53
+ label_font_size,
54
+ line_type,
55
+ y_axis_summary_type,
56
+ y_axis_summary_method
53
57
  } = chart.config;
54
58
  const chartBarColor = this.groupName;
55
59
  const newData = this.getChartGroupData(data);
56
60
  this.drawLabels(newData);
61
+ const isSmooth = line_type === CHART_LINE_TYPES[1];
57
62
 
58
63
  // set Coord type
59
64
  this.chart.coordinate('rect');
@@ -63,68 +68,78 @@ class LineGroup extends ChartComponent {
63
68
  type: 'cat'
64
69
  }
65
70
  });
66
- this.chart.line().label(y_axis_show_value ? 'value' : false, {
71
+ const line = this.chart.line().label(y_axis_show_value ? 'value' : false, {
67
72
  style: {
68
73
  fontSize: BaseUtils.getLabelFontSize(label_font_size),
69
74
  fill: theme.textColor
70
75
  }
71
- }).position('name*value').color(chartBarColor);
72
- this.chart.point().position('name*value').color(chartBarColor).shape('circle').size(3).style({
73
- lineWidth: 1,
74
- stroke: '#fff'
76
+ }).animate({
77
+ appear: {
78
+ animation: 'fadeIn',
79
+ duration: 1000,
80
+ easing: 'easeLinear'
81
+ }
82
+ }).position('name*value').color(chartBarColor).shape(isSmooth ? 'smooth' : 'line').style({
83
+ lineWidth: 3,
84
+ opacity: 1
85
+ }).tooltip('group_name*name*value', (group_name, name, value) => {
86
+ return {
87
+ title: y_axis_summary_type === CHART_SUMMARY_TYPE.COUNT ? intl.get('Amount') : intl.get(CHART_SUMMARY_SHOW[y_axis_summary_method]),
88
+ value: BaseUtils.getSummaryValueDisplayString(summaryColumn, value, y_axis_summary_method),
89
+ name: group_name
90
+ };
75
91
  });
76
- this.chart.tooltip({
77
- showCrosshairs: true,
78
- showTitle: true,
79
- containerTpl: '<div class="g2-tooltip"> <div class="g2-tooltip-title"></div> <div class="g2-tooltip-list"></div></div>',
80
- itemTpl: '<li class="tooltip-item"> <span>{value}</span> <span class="tooltip-item-left"><span class="tooltip-item-rect" style="background-color:{color}"></span> <span>{name}</span></span> </li>',
81
- domStyles: {
82
- 'g2-tooltip': {
83
- borderRadius: '3px',
84
- backgroundColor: '#fff',
85
- padding: '16px',
86
- width: '180px',
87
- border: '1px solid #E2E2E2'
88
- },
89
- 'g2-tooltip-title': {
90
- color: '#333333',
91
- fontSize: '14px',
92
- marginTop: '-1px'
93
- },
94
- 'tooltip-item': {
95
- display: 'flex',
96
- width: '100%',
97
- justifyContent: 'space-between',
98
- marginTop: '8px',
99
- color: '#333333',
100
- fontSize: '12px'
101
- },
102
- 'tooltip-item-left': {
103
- display: 'flex',
104
- justifyContent: 'space-between',
105
- alignItem: 'center'
106
- },
107
- 'tooltip-item-rect': {
108
- display: 'inline-block',
109
- width: '12px',
110
- height: '12px',
111
- borderRadius: '2px',
112
- marginRight: '8px'
92
+ let point;
93
+ if (y_axis_show_value) {
94
+ point = this.chart.point().position('name*value').color(chartBarColor).animate({
95
+ appear: {
96
+ animation: 'fadeIn',
97
+ duration: 1000,
98
+ easing: 'easeLinear'
113
99
  }
114
- },
115
- shared: true
100
+ }).shape('circle').size(4).style({
101
+ stroke: 0,
102
+ fillOpacity: 1
103
+ });
104
+ }
105
+ this.chart.on('tooltip:show', () => {
106
+ if (line.styleOption.cfg.opacity === 0.3) return;
107
+ line.style({
108
+ opacity: 0.3,
109
+ lineWidth: 3
110
+ });
111
+ if (point) point.style({
112
+ fillOpacity: 0.3,
113
+ stroke: 0
114
+ });
115
+ this.chart.render();
116
+ });
117
+ this.chart.on('tooltip:hide', () => {
118
+ if (line.styleOption.cfg.opacity === 1) return;
119
+ line.style({
120
+ opacity: 1,
121
+ lineWidth: 3
122
+ });
123
+ if (point) point.style({
124
+ fillOpacity: 1,
125
+ stroke: 0
126
+ });
127
+ this.chart.render();
116
128
  });
129
+ this.setToolTipForLine();
117
130
  this.setNameLabelAndTooltip(theme, this.labelCount);
118
131
  this.setValueLabel(theme);
119
- this.setLegend(this.groupName, theme, 'bottom');
132
+ this.setLegend(this.groupName, theme, 'top-right');
120
133
  };
121
134
  this.chart = null;
122
135
  this.groupName = 'group_name';
136
+ this.needRenderAxisLabel = true;
123
137
  }
124
138
  componentDidMount() {
125
139
  this.createChart();
126
140
  this.drawChart();
127
141
  this.renderAxisLabel(this.props.chart, this.props.tables);
142
+ super.componentDidMount();
128
143
  }
129
144
  componentDidUpdate(prevProps) {
130
145
  if (BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
@@ -136,13 +151,14 @@ class LineGroup extends ChartComponent {
136
151
  }
137
152
  componentWillUnmount() {
138
153
  this.chart && this.chart.destroy();
154
+ super.componentWillUnmount();
139
155
  }
140
156
  render() {
141
157
  const {
142
158
  chart
143
159
  } = this.props;
144
160
  return /*#__PURE__*/React.createElement("div", {
145
- className: classnames('sea-chart-container w-100', {
161
+ className: classnames('sea-chart-container ', {
146
162
  'show-x-axis-label': this.isShowXAxisLabel(chart),
147
163
  'show-y-axis-label': this.isShowYAxisLabel(chart)
148
164
  }),