sea-chart 0.0.82 → 0.0.83

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/context.js CHANGED
@@ -11,7 +11,7 @@ class Context {
11
11
  onSuccess,
12
12
  onFail
13
13
  } = _ref;
14
- // used custom api to get chart result data
14
+ // use custom api to get chart result data
15
15
  if (this.api.queryChartResult) {
16
16
  return this.api.queryChartResult({
17
17
  chart,
@@ -20,12 +20,12 @@ class Context {
20
20
  });
21
21
  }
22
22
  const table = getTableById(tables, chart.config.table_id);
23
-
24
- // use default view here
23
+ const currentView = table.views.find(view => view._id === chart.config.view_id);
24
+ // use default view
25
25
  const defaultView = table.views.find(view => view._id === '0000');
26
26
  const chartDataSQL = new ChartDataSQL({
27
27
  table,
28
- view: defaultView,
28
+ view: currentView || defaultView,
29
29
  chart
30
30
  });
31
31
  const {
@@ -7,7 +7,8 @@ class ChartModel {
7
7
  const {
8
8
  id,
9
9
  _id,
10
- style_config
10
+ style_config,
11
+ table_id
11
12
  } = options;
12
13
  this.id = id;
13
14
  this.type = 'statistic';
@@ -20,6 +21,11 @@ class ChartModel {
20
21
  font_weight: DEFAULT_CHART_FONT_WEIGHT,
21
22
  horizontal_align: HORIZONTAL_ALIGN.LEFT
22
23
  };
24
+ if (options.view_id) {
25
+ const table = tables.find(table => table._id === table_id);
26
+ const currentView = table === null || table === void 0 ? void 0 : table.views.find(view => view._id === options.view_id);
27
+ this.config.view_id = currentView._id || '0000';
28
+ }
23
29
  }
24
30
  }
25
31
  export default ChartModel;
package/dist/model/map.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { getTableById, getTableColumnByKey } from 'dtable-utils';
2
- import BaseModel from './base-model';
3
2
  import { isStatisticMapColumn } from '../utils';
4
3
  import { CHART_TYPE, MAP_LEVEL, regions } from '../constants';
4
+ import BaseModel from './base-model';
5
5
  class Map extends BaseModel {
6
6
  constructor(options, tables) {
7
7
  super({
@@ -1,7 +1,7 @@
1
1
  import { getTableById, getTableColumnByKey } from 'dtable-utils';
2
- import BaseModel from './base-model';
3
2
  import { isBoolean, isStatisticMirrorColumn } from '../utils';
4
3
  import { CHART_TYPE, CHART_SUMMARY_TYPE } from '../constants';
4
+ import BaseModel from './base-model';
5
5
  class Mirror extends BaseModel {
6
6
  constructor(options, tables) {
7
7
  super({
@@ -1,15 +1,16 @@
1
- import { getTableColumnByKey, isDateColumn } from 'dtable-utils';
1
+ import { getTableById, getTableColumnByKey, isDateColumn } from 'dtable-utils';
2
2
  import { CHART_TYPE, HORIZONTAL_ALIGN } from '../constants';
3
3
  import BaseModel from './base-model';
4
4
  class Trend extends BaseModel {
5
- constructor(options, table) {
5
+ constructor(options, tables) {
6
6
  super({
7
7
  ...options,
8
8
  type: CHART_TYPE.TREND
9
9
  });
10
10
  this.date_column_key = options.x_axis_column_key;
11
11
  this.date_granularity = options.x_axis_date_granularity;
12
- if (this.date_column_key) {
12
+ if (this.date_column_key && this.table_id) {
13
+ const table = getTableById(tables, this.table_id);
13
14
  const column = getTableColumnByKey(table, this.date_column_key);
14
15
  if (!column || !isDateColumn(column)) {
15
16
  this.date_column_key = null;
@@ -1,7 +1,7 @@
1
1
  import { getTableById, getTableColumnByKey } from 'dtable-utils';
2
- import BaseModel from './base-model';
3
2
  import { isStatisticWorldMapColumn } from '../utils';
4
3
  import { CHART_TYPE, CHART_SUMMARY_TYPE } from '../constants';
4
+ import BaseModel from './base-model';
5
5
  class WorldMapBubble extends BaseModel {
6
6
  constructor(options, tables) {
7
7
  super({
@@ -1,7 +1,7 @@
1
1
  import { getTableById, getTableColumnByKey } from 'dtable-utils';
2
- import BaseModel from './base-model';
3
2
  import { isStatisticWorldMapColumn } from '../utils';
4
3
  import { CHART_TYPE, CHART_SUMMARY_TYPE } from '../constants';
4
+ import BaseModel from './base-model';
5
5
  class WorldMap extends BaseModel {
6
6
  constructor(options, tables) {
7
7
  super({
@@ -38,12 +38,12 @@ export default function ScatterDataSettings(_ref) {
38
38
  };
39
39
  return update;
40
40
  };
41
- const onXAxisColumnChange = e => {
41
+ const onXAxisColumnChange = column => {
42
42
  const update = getNewUpdate(column, 'x_axis_column_key');
43
43
  if (!update) return;
44
44
  onChange && onChange(update);
45
45
  };
46
- const onYAxisColumnChange = e => {
46
+ const onYAxisColumnChange = column => {
47
47
  const update = getNewUpdate(column, 'y_axis_column_key');
48
48
  if (!update) return;
49
49
  onChange && onChange(update);
@@ -53,14 +53,13 @@ export default function ScatterDataSettings(_ref) {
53
53
  x_axis_include_empty_cells: !x_axis_include_empty_cells
54
54
  });
55
55
  };
56
- const onColumnGroupbyColumnChange = e => {
56
+ const onColumnGroupbyColumnChange = column => {
57
57
  const update = getNewUpdate(column, 'column_groupby_column_key');
58
58
  if (!update) return;
59
59
  if (!update['column_groupby_column_key']) {
60
60
  update['date_granularity'] = null;
61
61
  update['geolocation_granularity'] = null;
62
62
  } else {
63
- const column = e.value;
64
63
  const type = column.type;
65
64
  if (DATE_COLUMN_OPTIONS.includes(type)) {
66
65
  update['date_granularity'] = CHART_SUMMARY_TYPE.MONTH;
@@ -31,7 +31,11 @@ const BasicSummary = _ref => {
31
31
  const {
32
32
  columns
33
33
  } = selectedTable;
34
- return columns.filter(column => supportColumnTypes.includes(CellType.NUMBER) && BaseUtils.isNumericSummaryColumn(column) || supportColumnTypes.includes(CellType.DATE) && BaseUtils.isDateSummaryColumn(column));
34
+ return columns.filter(column => {
35
+ const supportNum = supportColumnTypes.includes(CellType.NUMBER) && BaseUtils.isNumericSummaryColumn(column) && column.type !== CellType.DURATION;
36
+ const supportDate = supportColumnTypes.includes(CellType.DATE) && BaseUtils.isDateSummaryColumn(column);
37
+ return supportNum || supportDate;
38
+ });
35
39
  }, [selectedTable, supportColumnTypes]);
36
40
  const numericColumnOptions = useMemo(() => {
37
41
  return numericColumns.map(column => {
@@ -1692,9 +1692,9 @@ SQLStatisticsUtils.scatterSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, c
1692
1692
  if (sqlColumnGroupbyColumnKey) BaseUtils.updateTableViewList(sqlRows, columnGroupbyColumn, sqlColumnGroupbyColumnKey, 'color');
1693
1693
  const res = [];
1694
1694
  sqlRows.forEach(row => {
1695
- const xValue = row[sqlXColumnKey];
1696
- const yValue = row[sqlYColumnKey];
1697
- const groupby = row[sqlColumnGroupbyColumnKey];
1695
+ const xValue = '' + row[sqlXColumnKey] || intl.get('Empty');
1696
+ const yValue = '' + row[sqlYColumnKey] || intl.get('Empty');
1697
+ const groupby = '' + row[sqlColumnGroupbyColumnKey] || intl.get('Empty');
1698
1698
  res.push({
1699
1699
  name: xValue,
1700
1700
  value: yValue,
@@ -7,7 +7,7 @@ import classNames from 'classnames';
7
7
  import { CellType } from 'dtable-ui-component/lib/constants';
8
8
  import intl from '../../intl';
9
9
  import { sortDataByGroupSum } from '../../utils/column-utils';
10
- import { EMPTY_NAME, CHART_TYPE, CHART_SUMMARY_TYPE, DEFAULT_NUMBER_FORMAT_OBJECT, CHART_THEME_COLOR } from '../../constants';
10
+ import { EMPTY_NAME, CHART_TYPE, CHART_SUMMARY_TYPE, DEFAULT_NUMBER_FORMAT_OBJECT, CHART_THEME_COLOR, CHART_STYLE_COLORS } from '../../constants';
11
11
  import { BaseUtils, isFunction } from '../../utils';
12
12
  import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
13
13
  import ChartComponent from './chart-component';
@@ -167,7 +167,7 @@ class BarGroup extends ChartComponent {
167
167
  },
168
168
  position: type === CHART_TYPE.BAR_STACK ? 'middle' : ''
169
169
  }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
170
- return useSingleSelectColumnColor ? group_color : this.colorMap[group_name];
170
+ return useSingleSelectColumnColor ? group_color : this.colorMap[group_name] || CHART_STYLE_COLORS[0];
171
171
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
172
172
  return {
173
173
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { debounce, maxBy, throttle } from 'lodash-es';
4
4
  import classNames from 'classnames';
5
5
  import { CellType } from 'dtable-ui-component/lib/constants';
6
- import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR } from '../../constants';
6
+ import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR, CHART_STYLE_COLORS } from '../../constants';
7
7
  import { BaseUtils, isFunction } from '../../utils';
8
8
  import intl from '../../intl';
9
9
  import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
@@ -118,7 +118,7 @@ class HorizontalBarGroup extends HorizontalComponent {
118
118
  lineWidth: 1
119
119
  }
120
120
  }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
121
- return useSingleSelectColumnColor ? group_color : this.colorMap[group_name];
121
+ return useSingleSelectColumnColor ? group_color : this.colorMap[group_name] || CHART_STYLE_COLORS[0];
122
122
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
123
123
  return {
124
124
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -262,10 +262,15 @@ export default function Map(props) {
262
262
  // used to fetch mapJson data
263
263
  useEffect(() => {
264
264
  (async () => {
265
- const mediaUrl = context.getSetting('mediaUrl');
266
- const mapJson = await fetchMapJson(mapLevel, mapLocation, mediaUrl);
267
- setMapData(mapJson);
268
- setIsLoading(false);
265
+ try {
266
+ const mediaUrl = context.getSetting('mediaUrl');
267
+ const mapJson = await fetchMapJson(mapLevel, mapLocation, mediaUrl);
268
+ setMapData(mapJson);
269
+ setIsLoading(false);
270
+ } catch (error) {
271
+ console.error(error);
272
+ setIsLoading(false);
273
+ }
269
274
  })();
270
275
  }, [mapLevel, mapLocation]);
271
276
 
@@ -6,11 +6,20 @@ import intl from '../../intl';
6
6
  import { CHART_THEME_COLOR } from '../../constants';
7
7
  import ChartComponent from './chart-component';
8
8
  const chartComponent = new ChartComponent();
9
- export function Scatter(props) {
9
+ export function Scatter(_ref) {
10
+ let {
11
+ toggleRecords,
12
+ result: data,
13
+ chart,
14
+ tables,
15
+ globalTheme,
16
+ chartColorTheme
17
+ } = _ref;
10
18
  const chartRef = useRef(chartComponent);
11
19
  const chartContainerRef = useRef(null);
12
20
  useEffect(() => {
13
21
  const currentChart = chartRef.current;
22
+ currentChart.isDestoryed = false;
14
23
 
15
24
  // avoid closure trap
16
25
  function createChart() {
@@ -19,29 +28,18 @@ export function Scatter(props) {
19
28
  appendPadding
20
29
  });
21
30
  currentChart.chart.on('element:click', e => {
22
- props.toggleRecords(e.data.data);
31
+ toggleRecords(e.data.data);
23
32
  });
24
33
  }
25
34
  function drawChart() {
26
- let {
27
- result: data,
28
- chart,
29
- tables
30
- } = props;
31
- data = BaseUtils.formatEmptyName(data, '', intl.get('Empty'));
32
- if (!Array.isArray(data)) return;
33
- currentChart.loadData(data);
34
- draw(data);
35
+ const newData = BaseUtils.formatEmptyName(data, '', intl.get('Empty'));
36
+ if (!Array.isArray(newData)) return;
37
+ currentChart.loadData(newData);
38
+ draw(newData);
35
39
  currentChart.chart.render();
36
40
  currentChart.renderAxisLabel(chart, tables);
37
41
  }
38
42
  function draw(data) {
39
- const {
40
- chart,
41
- globalTheme,
42
- chartColorTheme,
43
- tables
44
- } = props;
45
43
  const theme = CHART_THEME_COLOR[globalTheme];
46
44
  const {
47
45
  label_font_size,
@@ -117,12 +115,11 @@ export function Scatter(props) {
117
115
  createChart();
118
116
  drawChart();
119
117
  return () => {
118
+ if (currentChart.isDestoryed) return;
120
119
  currentChart.chart.destroy();
120
+ currentChart.isDestoryed = true;
121
121
  };
122
- }, [props]);
123
- const {
124
- chart
125
- } = props;
122
+ }, [chart, chartColorTheme, data, globalTheme, tables, toggleRecords]);
126
123
  const showXLabel = chartRef.current.isShowXAxisLabel(chart);
127
124
  const showYLabel = chartRef.current.isShowYAxisLabel(chart);
128
125
  return /*#__PURE__*/React.createElement("div", {
@@ -132,7 +132,7 @@ class TwoDimensionTable extends PureComponent {
132
132
  };
133
133
  this.renderEmpty = (summaryColumns, cellIdx) => {
134
134
  if (summaryColumns && (summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.length) !== 0) {
135
- return summaryColumns.map(() => {
135
+ return summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.map(() => {
136
136
  return /*#__PURE__*/React.createElement("div", {
137
137
  key: "table-cell-".concat(cellIdx),
138
138
  className: classnames('pivot-cell', {
@@ -22,15 +22,20 @@ class WorldMap extends ChartComponent {
22
22
  };
23
23
  this.queryMapJson = async () => {
24
24
  const mediaUrl = context.getSetting('mediaUrl');
25
- const mapJson = await fetchMapJson(MAP_LEVEL.WORLD, '', mediaUrl);
26
- this.geoData = mapJson;
27
- this.geoData.features.forEach(item => {
28
- this.countryMap.set(item.properties.name, item.properties.name_cn);
29
- this.countryMap.set(item.properties.name_cn, item.properties.name);
30
- });
31
- this.mapFormattedData = this.fixData(this.props.result);
32
- this.createChart();
33
- this.drawChart();
25
+ try {
26
+ const mapJson = await fetchMapJson(MAP_LEVEL.WORLD, '', mediaUrl);
27
+ this.geoData = mapJson;
28
+ this.geoData.features.forEach(item => {
29
+ this.countryMap.set(item.properties.name, item.properties.name_cn);
30
+ this.countryMap.set(item.properties.name_cn, item.properties.name);
31
+ });
32
+ } catch (error) {
33
+ console.error(error);
34
+ } finally {
35
+ this.mapFormattedData = this.fixData(this.props.result);
36
+ this.createChart();
37
+ this.drawChart();
38
+ }
34
39
  };
35
40
  this.fixData = statisticData => {
36
41
  if (!statisticData) return [];
@@ -128,6 +133,7 @@ class WorldMap extends ChartComponent {
128
133
  });
129
134
  this.chart.axis(false);
130
135
  this.dataSet = new DataSet();
136
+ if (!this.geoData) return;
131
137
 
132
138
  // transform map data
133
139
  const mapData = this.dataSet.createView('mapDataModel').source(this.geoData, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.82",
3
+ "version": "0.0.83",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",