sea-chart 1.1.53-alpha.3 → 1.1.54

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.
@@ -110,7 +110,7 @@ class RowCard extends Component {
110
110
  componentDidMount() {
111
111
  this.currentDisplayRowMaxIndex = Math.floor((0 + this.recordsList.offsetHeight) / CARD_RECORD_ITEM_HEIGHT);
112
112
  }
113
- UNSAFE_componentWillReceiveProps(nextProps) {
113
+ componentDidUpdate(nextProps) {
114
114
  let {
115
115
  rows,
116
116
  highlightRowIndex
@@ -1,5 +1,6 @@
1
+ import _DTableModalHeader from "dtable-ui-component/lib/DTableModalHeader";
1
2
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { Modal, ModalHeader, ModalBody, ModalFooter, UncontrolledTooltip, Button } from 'reactstrap';
3
+ import { Modal, ModalBody, ModalFooter, UncontrolledTooltip, Button } from 'reactstrap';
3
4
  import classnames from 'classnames';
4
5
  import { CHART_TYPE, CHART_TYPES, CHART_TYPE_SHOW, ZH_CN_SUPPORT_CHARTS } from '../../constants';
5
6
  import { eventStopPropagation } from '../../utils';
@@ -62,7 +63,7 @@ const TypesDialog = _ref => {
62
63
  toggle: onToggle,
63
64
  className: "sea-chart-types-dialog",
64
65
  zIndex: 1048
65
- }, /*#__PURE__*/React.createElement(ModalHeader, {
66
+ }, /*#__PURE__*/React.createElement(_DTableModalHeader, {
66
67
  toggle: onToggle
67
68
  }, type ? intl.get('Edit_type') : intl.get('All_charts')), /*#__PURE__*/React.createElement(ModalBody, {
68
69
  className: "sea-chart-types-body"
@@ -14,7 +14,7 @@ export { getDateColumnFormat, isCheckboxColumn, getColumnByKey, isStatisticMapCo
14
14
  export { generatorKey } from './key-generator';
15
15
  export { translateCalendar } from './date-translate';
16
16
  export { isFunction } from './common-utils';
17
- export function formatXAxisLabel(label) {
17
+ const splitLabelWithoutEnglish = label => {
18
18
  let newLabel = '';
19
19
  while (label.length > 0) {
20
20
  if (label.length > 12) {
@@ -26,6 +26,48 @@ export function formatXAxisLabel(label) {
26
26
  }
27
27
  }
28
28
  return newLabel;
29
+ };
30
+ export function formatXAxisLabel(label) {
31
+ let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
32
+ const regex = /\b[a-zA-Z0-9'.,-]+\b/g;
33
+ const words = label.match(regex);
34
+ if (!words || words.length === 0) {
35
+ return splitLabelWithoutEnglish(label);
36
+ }
37
+ let currentLine = '';
38
+ let result = [];
39
+ for (let i = 0; i < words.length; i++) {
40
+ const word = words[i];
41
+ const index = label.indexOf(word);
42
+ if (!currentLine) {
43
+ currentLine = label.slice(0, index);
44
+ label = label.slice(index + word.length);
45
+ } else {
46
+ currentLine = currentLine + label.slice(0, index);
47
+ label = label.slice(index + word.length);
48
+ }
49
+ if (currentLine.length > maxLength) {
50
+ while (currentLine.length > maxLength) {
51
+ result.push(currentLine.slice(0, maxLength));
52
+ currentLine = currentLine.slice(maxLength);
53
+ }
54
+ }
55
+ currentLine = currentLine + word;
56
+ if (currentLine.length > maxLength) {
57
+ while (currentLine.length > maxLength) {
58
+ result.push(currentLine.slice(0, maxLength) + '-');
59
+ currentLine = currentLine.slice(maxLength);
60
+ }
61
+ }
62
+ if (currentLine.length === maxLength || currentLine.length + 1 === maxLength) {
63
+ result.push(currentLine.slice(0, maxLength));
64
+ currentLine = '';
65
+ }
66
+ if (i === words.length - 1 && currentLine) {
67
+ result.push(currentLine);
68
+ }
69
+ }
70
+ return result.join('\n');
29
71
  }
30
72
  export function formatRowTotal(rowTotal) {
31
73
  const rowTotalNum = parseFloat(rowTotal);
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classnames from 'classnames';
4
- import { isEqual } from 'lodash-es';
5
4
  import shallowEqual from 'shallowequal';
6
5
  import context from '../context';
7
6
  import intl from '../intl';
@@ -169,7 +168,7 @@ class View extends React.PureComponent {
169
168
  this.unsubscribeReFreshChart();
170
169
  this.refreshTimer && clearInterval(this.refreshTimer);
171
170
  }
172
- UNSAFE_componentWillReceiveProps(nextProps) {
171
+ componentDidUpdate(nextProps) {
173
172
  const {
174
173
  chart: oldChart,
175
174
  hasUnSaved,
@@ -306,6 +305,7 @@ class View extends React.PureComponent {
306
305
  }, !hideTitle && /*#__PURE__*/React.createElement(Title, {
307
306
  chart: chart
308
307
  }), /*#__PURE__*/React.createElement("div", {
308
+ id: "sea-chart-cavans-container-".concat(chart.id),
309
309
  className: classnames('sea-chart-cavans-container', {
310
310
  'has-title': hasTitle
311
311
  })
@@ -1,6 +1,8 @@
1
1
  import _ButtonFormatter from "dtable-ui-component/lib/ButtonFormatter";
2
2
  import _RateFormatter from "dtable-ui-component/lib/RateFormatter";
3
3
  import _DurationFormatter from "dtable-ui-component/lib/DurationFormatter";
4
+ import _EmailFormatter from "dtable-ui-component/lib/EmailFormatter";
5
+ import _UrlFormatter from "dtable-ui-component/lib/UrlFormatter";
4
6
  import _AutoNumberFormatter from "dtable-ui-component/lib/AutoNumberFormatter";
5
7
  import _LastModifierFormatter from "dtable-ui-component/lib/LastModifierFormatter";
6
8
  import _CreatorFormatter from "dtable-ui-component/lib/CreatorFormatter";
@@ -24,8 +26,8 @@ import intl from '../../../../intl';
24
26
  import DtableFormulaFormatter from './formatters/formula-formatter';
25
27
  import LinkFormatter from './formatters/link-formatter';
26
28
  import FileFormatter from './formatters/FileFormatter/index';
27
- import UrlFormatter from './formatters/UrlFormatter/index';
28
- import EmailFormatter from './formatters/EmailFormatter/index';
29
+ // import UrlFormatter from './formatters/UrlFormatter/index';
30
+ // import EmailFormatter from './formatters/EmailFormatter/index';
29
31
  import { getTrimmedString, getValidUrl, openUrlLink } from './utils';
30
32
  class Formatter extends React.Component {
31
33
  constructor() {
@@ -247,20 +249,22 @@ class Formatter extends React.Component {
247
249
  case CellType.URL:
248
250
  {
249
251
  if (!cellValue) return this.renderEmptyFormatter();
250
- return /*#__PURE__*/React.createElement(UrlFormatter, {
251
- onClick: () => this.onUrlClick(cellValue),
252
+ return /*#__PURE__*/React.createElement("div", {
253
+ onClick: () => this.onUrlClick(cellValue)
254
+ }, /*#__PURE__*/React.createElement(_UrlFormatter, {
252
255
  value: cellValue,
253
256
  containerClassName: containerClassName
254
- });
257
+ }), ";");
255
258
  }
256
259
  case CellType.EMAIL:
257
260
  {
258
261
  if (!cellValue) return this.renderEmptyFormatter();
259
- return /*#__PURE__*/React.createElement(EmailFormatter, {
260
- onClick: () => this.onEmailClick(cellValue),
262
+ return /*#__PURE__*/React.createElement("div", {
263
+ onClick: () => this.onEmailClick(cellValue)
264
+ }, /*#__PURE__*/React.createElement(_EmailFormatter, {
261
265
  value: cellValue,
262
266
  containerClassName: containerClassName
263
- });
267
+ }), ";");
264
268
  }
265
269
  case CellType.DURATION:
266
270
  {
@@ -1,4 +1,8 @@
1
- @import url('../css/cell-formatter.css');
1
+ .dtable-ui.cell-formatter-container {
2
+ overflow: hidden;
3
+ line-height: 1;
4
+ width: 100%;
5
+ }
2
6
 
3
7
  .dtable-ui.file-formatter {
4
8
  display: flex;
@@ -30,4 +34,4 @@
30
34
  background-color: #999;
31
35
  -webkit-transform: translate(-50%, 8px) scale(.8);
32
36
  transform: translate(-50%, 8px) scale(.8);
33
- }
37
+ }
@@ -1,11 +1,10 @@
1
+ import _ImagePreviewerLightbox from "dtable-ui-component/lib/ImagePreviewerLightbox";
1
2
  import _FileItemFormatter from "dtable-ui-component/lib/FileItemFormatter";
2
3
  import React, { Fragment } from 'react';
3
4
  import classnames from 'classnames';
4
5
  import { imageCheck } from '../../../../../../utils/common-utils';
5
- import ImagePreviewerLightbox from './image-previewer-lightbox';
6
+ import context from '../../../../../../context';
6
7
  import './index.css';
7
- // import FileItemFormatter from '../FileItemFormatter';
8
-
9
8
  export default class FileFormatter extends React.PureComponent {
10
9
  constructor(props) {
11
10
  super(props);
@@ -72,6 +71,9 @@ export default class FileFormatter extends React.PureComponent {
72
71
  largeImageIndex: -1
73
72
  });
74
73
  };
74
+ this.server = context.getSetting('server');
75
+ this.workspaceID = context.getSetting('workspaceID');
76
+ this.dtableUuid = context.getSetting('dtableUuid');
75
77
  this.state = {
76
78
  isShowLargeImage: false,
77
79
  largeImageIndex: -1,
@@ -81,7 +83,7 @@ export default class FileFormatter extends React.PureComponent {
81
83
  componentDidMount() {
82
84
  this.getFileItemImageUrlList(this.props.value);
83
85
  }
84
- UNSAFE_componentWillReceiveProps(nextProps) {
86
+ componentDidUpdate(nextProps) {
85
87
  if (JSON.stringify(this.props.value) !== JSON.stringify(nextProps.value)) {
86
88
  this.getFileItemImageUrlList(nextProps.value);
87
89
  }
@@ -116,7 +118,10 @@ export default class FileFormatter extends React.PureComponent {
116
118
  }, /*#__PURE__*/React.createElement(_FileItemFormatter, {
117
119
  file: item
118
120
  })));
119
- }), this.state.isShowLargeImage && /*#__PURE__*/React.createElement(ImagePreviewerLightbox, {
121
+ }), this.state.isShowLargeImage && /*#__PURE__*/React.createElement(_ImagePreviewerLightbox, {
122
+ server: this.server,
123
+ workspaceID: this.workspaceID,
124
+ dtableUuid: this.dtableUuid,
120
125
  readOnly: true,
121
126
  imageItems: this.state.fileImageUrlList,
122
127
  imageIndex: this.state.largeImageIndex,
@@ -8,11 +8,50 @@ import VerticalScrollbar from './vertical-scrollbar';
8
8
  class Records extends Component {
9
9
  constructor(props) {
10
10
  super(props);
11
+ this.resizeColumnWidthToFitContainer = () => {
12
+ const {
13
+ chart
14
+ } = this.props;
15
+ const displayColumns = this.calcuteDisplayColumns(this.props.shownColumns);
16
+ const container = document.querySelector("#sea-chart-cavans-container-".concat(chart.id));
17
+ let resultTotalwidth = displayColumns.reduce((cur, nextItem) => {
18
+ return cur + nextItem.width;
19
+ }, 0);
20
+ // padding 15px for vertical scrollbar
21
+ const containerWidth = container.clientWidth - 15;
22
+ if (!container || resultTotalwidth >= containerWidth) {
23
+ this.setState({
24
+ displayColumns,
25
+ headerDisplayColumns: displayColumns
26
+ });
27
+ return;
28
+ }
29
+ // enlarge the column width to fit the container
30
+ let i = 0;
31
+ while (resultTotalwidth < containerWidth) {
32
+ displayColumns[i % displayColumns.length].width += 1;
33
+ i++;
34
+ resultTotalwidth = displayColumns.reduce((cur, nextItem) => {
35
+ return cur + nextItem.width;
36
+ }, 0);
37
+ }
38
+ this.setState({
39
+ displayColumns,
40
+ headerDisplayColumns: displayColumns
41
+ });
42
+ };
11
43
  this.calcuteDisplayColumns = shownColumns => {
12
- return shownColumns.filter(column => !DATASET_NOT_SUPPORT_COLUMN_TYPES.includes(column.type)).map(column => {
44
+ const {
45
+ chart
46
+ } = this.props;
47
+ const columnsWidthDataStr = localStorage.getItem("statistic_".concat(chart.id, "_columns_width"));
48
+ const columnsWidthData = columnsWidthDataStr ? JSON.parse(columnsWidthDataStr) : [];
49
+ const columns = shownColumns.filter(column => !DATASET_NOT_SUPPORT_COLUMN_TYPES.includes(column.type)).map(column => {
13
50
  const {
14
51
  type
15
52
  } = column;
53
+ const columnWidthData = columnsWidthData.find(item => item.key === column.key);
54
+ const previousWidth = typeof (columnWidthData === null || columnWidthData === void 0 ? void 0 : columnWidthData.width) === 'number' && columnWidthData.width;
16
55
  if (type === CellType.LINK) {
17
56
  const {
18
57
  data
@@ -29,7 +68,7 @@ class Records extends Component {
29
68
  };
30
69
  return {
31
70
  ...column,
32
- width: getCellRecordWidth(column),
71
+ width: previousWidth || getCellRecordWidth(column),
33
72
  data: {
34
73
  ...data,
35
74
  display_column
@@ -38,9 +77,18 @@ class Records extends Component {
38
77
  }
39
78
  return {
40
79
  ...column,
41
- width: getCellRecordWidth(column)
80
+ width: previousWidth || getCellRecordWidth(column)
81
+ };
82
+ });
83
+ const newColumnsWidthData = columns.map(column => {
84
+ return {
85
+ key: column.key,
86
+ width: column.width
42
87
  };
43
88
  });
89
+ // clear old data if there are new columns and not matched with the old data
90
+ localStorage.setItem("statistic_".concat(chart.id, "_columns_width"), JSON.stringify(newColumnsWidthData));
91
+ return columns;
44
92
  };
45
93
  this.resizeColumnWidth = (column, width) => {
46
94
  const {
@@ -51,10 +99,20 @@ class Records extends Component {
51
99
  headerDisplayColumns: newDisplayColumns
52
100
  });
53
101
  };
54
- this.resizeColumnWidthEnd = (column, width) => {
102
+ this.resizeColumnWidthEnd = () => {
55
103
  this.setState({
56
104
  displayColumns: this.state.headerDisplayColumns
57
105
  });
106
+ const columnsWidthData = this.state.headerDisplayColumns.map(column => {
107
+ return {
108
+ key: column.key,
109
+ width: column.width
110
+ };
111
+ });
112
+ const {
113
+ chart
114
+ } = this.props;
115
+ localStorage.setItem("statistic_".concat(chart.id, "_columns_width"), JSON.stringify(columnsWidthData));
58
116
  };
59
117
  this.setVerticalScrollbarTop = scrollTop => {
60
118
  if (this.verticalScrollbar) {
@@ -68,12 +126,19 @@ class Records extends Component {
68
126
  scrollLeft: 0
69
127
  };
70
128
  this.resultContainerRef = null;
71
- const _displayColumns = this.calcuteDisplayColumns(props.shownColumns);
72
129
  this.state = {
73
- displayColumns: _displayColumns,
74
- headerDisplayColumns: _displayColumns
130
+ displayColumns: [],
131
+ headerDisplayColumns: []
75
132
  };
76
133
  }
134
+ componentDidUpdate(prevProps) {
135
+ if (prevProps.shownColumns !== this.props.shownColumns) {
136
+ this.resizeColumnWidthToFitContainer();
137
+ }
138
+ }
139
+ componentDidMount() {
140
+ this.resizeColumnWidthToFitContainer();
141
+ }
77
142
  render() {
78
143
  const {
79
144
  records,
@@ -1,12 +1,19 @@
1
1
  .vertical-scrollbar {
2
2
  width: 15px;
3
- overflow: auto;
4
3
  position: absolute;
5
4
  top: 33px;
6
5
  right: 5px;
7
6
  height: calc(100% - 33px - 6px);
8
7
  }
9
8
 
9
+ .table-element-container .vertical-scrollbar {
10
+ overflow: hidden;
11
+ }
12
+
13
+ .table-element-container:hover .vertical-scrollbar {
14
+ overflow: auto;
15
+ }
16
+
10
17
  .vertical-scrollbar-inner {
11
18
  width: 1px;
12
19
  }
@@ -12,6 +12,13 @@
12
12
  .table-element-result-container {
13
13
  height: 100%;
14
14
  width: 100%;
15
+ }
16
+
17
+ .table-element-container .table-element-result-container {
18
+ overflow: hidden;
19
+ }
20
+
21
+ .table-element-container:hover .table-element-result-container {
15
22
  overflow: auto;
16
23
  }
17
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "1.1.53-alpha.3",
3
+ "version": "1.1.54",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@antv/scale": "0.3.14",
30
- "dtable-ui-component": "^5.1.10",
30
+ "dtable-ui-component": "^5.2.13",
31
31
  "dtable-utils": "~5.0.*",
32
32
  "prop-types": "15.8.1",
33
33
  "react": "^17.0.0",
@@ -165,4 +165,4 @@
165
165
  "publishConfig": {
166
166
  "access": "public"
167
167
  }
168
- }
168
+ }
@@ -1,6 +0,0 @@
1
- @import url('../css/cell-formatter.css');
2
-
3
- .dtable-ui.email-formatter {
4
- text-decoration: underline;
5
- cursor: pointer;
6
- }
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import classnames from 'classnames';
3
- import './index.css';
4
- class EmailFormatter extends React.Component {
5
- render() {
6
- const {
7
- containerClassName,
8
- value,
9
- onClick
10
- } = this.props;
11
- let classname = classnames('dtable-ui cell-formatter-container email-formatter', containerClassName);
12
- const props = {
13
- title: value
14
- };
15
- if (onClick) {
16
- props.onClick = onClick;
17
- }
18
- return /*#__PURE__*/React.createElement("div", Object.assign({}, props, {
19
- className: classname
20
- }), value);
21
- }
22
- }
23
- export default EmailFormatter;
@@ -1,14 +0,0 @@
1
- import _ImagePreviewerLightbox from "dtable-ui-component/lib/ImagePreviewerLightbox";
2
- import React from 'react';
3
- import context from '../../../../../../context';
4
- function ImagePreviewerLightbox(props) {
5
- const server = context.getSetting('server');
6
- const workspaceID = context.getSetting('workspaceID');
7
- const dtableUuid = context.getSetting('dtableUuid');
8
- return /*#__PURE__*/React.createElement(_ImagePreviewerLightbox, Object.assign({}, props, {
9
- server: server,
10
- workspaceID: workspaceID,
11
- dtableUuid: dtableUuid
12
- }));
13
- }
14
- export default ImagePreviewerLightbox;
@@ -1,6 +0,0 @@
1
- @import url('../css/cell-formatter.css');
2
-
3
- .dtable-ui.url-formatter {
4
- text-decoration: underline;
5
- cursor: pointer;
6
- }
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import classnames from 'classnames';
3
- import './index.css';
4
- class UrlFormatter extends React.Component {
5
- render() {
6
- const {
7
- containerClassName,
8
- value,
9
- onClick
10
- } = this.props;
11
- let classname = classnames('dtable-ui cell-formatter-container url-formatter', containerClassName);
12
- const props = {
13
- title: value
14
- };
15
- if (onClick) {
16
- props.onClick = onClick;
17
- }
18
- return /*#__PURE__*/React.createElement("div", Object.assign({}, props, {
19
- className: classname
20
- }), value);
21
- }
22
- }
23
- export default UrlFormatter;
@@ -1,5 +0,0 @@
1
- .dtable-ui.cell-formatter-container {
2
- overflow: hidden;
3
- line-height: 1;
4
- width: 100%;
5
- }