sea-chart 0.0.41-beta.0 → 0.0.41-beta.1
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/index.js
CHANGED
|
@@ -7,5 +7,7 @@ import Settings, { StyleSettings, Divider } from './settings';
|
|
|
7
7
|
import TypesDialog from './components/types-dialog';
|
|
8
8
|
import { ChartDataSQL } from './utils';
|
|
9
9
|
import Context from './context';
|
|
10
|
+
import EventBus from './utils/event-bus';
|
|
11
|
+
import { EXTERNAL_EVENT } from './constants/common-constants';
|
|
10
12
|
export default View;
|
|
11
|
-
export { SeaChartAPI, CHART_TYPE, CHART_TYPES, View, Editor, Settings, TypesDialog, StyleSettings, Divider, Context, ChartModel, ChartDataSQL };
|
|
13
|
+
export { SeaChartAPI, CHART_TYPE, CHART_TYPES, View, Editor, Settings, TypesDialog, StyleSettings, Divider, Context, ChartModel, ChartDataSQL, EventBus, EXTERNAL_EVENT };
|
package/dist/settings/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useState, useEffect } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { eventStopPropagation } from '../utils';
|
|
4
|
-
import { BaseUtils } from '../utils';
|
|
5
|
-
import
|
|
6
|
-
import StyleSettings from './style-settings';
|
|
7
|
-
import { CHART_SETTINGS_TYPE, CHART_SETTINGS } from '../constants';
|
|
4
|
+
import { BaseUtils, generateChartConfig } from '../utils';
|
|
5
|
+
import TypesDialog from '../components/types-dialog';
|
|
8
6
|
import intl from '../intl';
|
|
7
|
+
import { CHART_SETTINGS_TYPE, CHART_SETTINGS } from '../constants';
|
|
8
|
+
import EventBus from '../utils/event-bus';
|
|
9
|
+
import { EXTERNAL_EVENT } from '../constants/common-constants';
|
|
10
|
+
import StyleSettings from './style-settings';
|
|
11
|
+
import DataSettings from './data-settings';
|
|
9
12
|
import Divider from './widgets/divider';
|
|
10
13
|
import './index.css';
|
|
11
14
|
const Settings = _ref => {
|
|
@@ -19,6 +22,10 @@ const Settings = _ref => {
|
|
|
19
22
|
} = _ref;
|
|
20
23
|
const [type, setType] = useState(CHART_SETTINGS_TYPE.DATA);
|
|
21
24
|
const [labelColorConfigs, setLabelColorConfigs] = useState([]);
|
|
25
|
+
const [isDialogShow, setDialogShow] = useState(false);
|
|
26
|
+
const showTypesDialog = () => {
|
|
27
|
+
setDialogShow(true);
|
|
28
|
+
};
|
|
22
29
|
useEffect(() => {
|
|
23
30
|
var _window$dtable;
|
|
24
31
|
const systemCustomColors = ((_window$dtable = window.dtable) === null || _window$dtable === void 0 ? void 0 : _window$dtable.customColors) || [];
|
|
@@ -30,6 +37,10 @@ const Settings = _ref => {
|
|
|
30
37
|
color: customColor.color.toUpperCase()
|
|
31
38
|
}))];
|
|
32
39
|
setLabelColorConfigs(colorConfigs);
|
|
40
|
+
const unsubscribeShowTypesDialog = EventBus.subscribe(EXTERNAL_EVENT.SHOW_TYPES_DIALOG, showTypesDialog);
|
|
41
|
+
return () => {
|
|
42
|
+
unsubscribeShowTypesDialog();
|
|
43
|
+
};
|
|
33
44
|
}, []);
|
|
34
45
|
const onChartSettingsTypeChange = useCallback(event => {
|
|
35
46
|
eventStopPropagation(event);
|
|
@@ -57,6 +68,23 @@ const Settings = _ref => {
|
|
|
57
68
|
const validTitle = useMemo(() => {
|
|
58
69
|
return title || {};
|
|
59
70
|
}, [title]);
|
|
71
|
+
const closeTypesDialog = useCallback(() => {
|
|
72
|
+
setDialogShow(false);
|
|
73
|
+
}, []);
|
|
74
|
+
const onTypeChange = useCallback(type => {
|
|
75
|
+
const {
|
|
76
|
+
config
|
|
77
|
+
} = chart;
|
|
78
|
+
const {
|
|
79
|
+
type: oldType
|
|
80
|
+
} = config;
|
|
81
|
+
if (type === oldType) return;
|
|
82
|
+
const convertedChart = generateChartConfig({
|
|
83
|
+
...config,
|
|
84
|
+
type
|
|
85
|
+
}, tables);
|
|
86
|
+
onChange && onChange(convertedChart);
|
|
87
|
+
}, [chart, onChange, tables]);
|
|
60
88
|
return /*#__PURE__*/React.createElement("div", {
|
|
61
89
|
className: "sea-chart-settings"
|
|
62
90
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -84,7 +112,11 @@ const Settings = _ref => {
|
|
|
84
112
|
chart: chart,
|
|
85
113
|
labelColorConfigs: labelColorConfigs,
|
|
86
114
|
onChange: modifyStyle
|
|
87
|
-
}), children && type === CHART_SETTINGS_TYPE.GENERAL_STYLE && /*#__PURE__*/React.createElement(React.Fragment, null, children)))
|
|
115
|
+
}), children && type === CHART_SETTINGS_TYPE.GENERAL_STYLE && /*#__PURE__*/React.createElement(React.Fragment, null, children))), isDialogShow && /*#__PURE__*/React.createElement(TypesDialog, {
|
|
116
|
+
type: chart.config.type,
|
|
117
|
+
onToggle: closeTypesDialog,
|
|
118
|
+
onChange: onTypeChange
|
|
119
|
+
}));
|
|
88
120
|
};
|
|
89
121
|
Settings.defaultProps = {
|
|
90
122
|
dataSources: 'filter'
|
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
import React, { useCallback
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { Label, FormGroup } from 'reactstrap';
|
|
3
3
|
import { CHART_TYPE_SHOW } from '../../../constants';
|
|
4
4
|
import { eventStopPropagation } from '../../../utils';
|
|
5
5
|
import intl from '../../../intl';
|
|
6
|
-
import { Icon
|
|
6
|
+
import { Icon } from '../../../components';
|
|
7
|
+
import EventBus from '../../../utils/event-bus';
|
|
8
|
+
import { EXTERNAL_EVENT } from '../../../constants/common-constants';
|
|
7
9
|
import './index.css';
|
|
8
10
|
const ChartType = _ref => {
|
|
9
11
|
let {
|
|
10
|
-
chart
|
|
11
|
-
generateChartConfig,
|
|
12
|
-
onChange
|
|
12
|
+
chart
|
|
13
13
|
} = _ref;
|
|
14
|
-
const [isDialogShow, setDialogShow] = useState(false);
|
|
15
14
|
const openTypesDialog = useCallback(event => {
|
|
16
15
|
eventStopPropagation(event);
|
|
17
|
-
|
|
16
|
+
EventBus.dispatch(EXTERNAL_EVENT.SHOW_TYPES_DIALOG);
|
|
18
17
|
}, []);
|
|
19
|
-
const closeTypesDialog = useCallback(() => {
|
|
20
|
-
setDialogShow(false);
|
|
21
|
-
}, []);
|
|
22
|
-
const onTypeChange = useCallback(type => {
|
|
23
|
-
const {
|
|
24
|
-
config
|
|
25
|
-
} = chart;
|
|
26
|
-
const {
|
|
27
|
-
type: oldType
|
|
28
|
-
} = config;
|
|
29
|
-
if (type === oldType) return;
|
|
30
|
-
const convertedChart = generateChartConfig({
|
|
31
|
-
...config,
|
|
32
|
-
type
|
|
33
|
-
});
|
|
34
|
-
onChange && onChange(convertedChart);
|
|
35
|
-
}, [chart, generateChartConfig, onChange]);
|
|
36
18
|
const {
|
|
37
19
|
config
|
|
38
20
|
} = chart;
|
|
@@ -50,10 +32,6 @@ const ChartType = _ref => {
|
|
|
50
32
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
51
33
|
symbol: "type-change",
|
|
52
34
|
className: "sea-chart-type-icon"
|
|
53
|
-
}))))
|
|
54
|
-
type: type,
|
|
55
|
-
onToggle: closeTypesDialog,
|
|
56
|
-
onChange: onTypeChange
|
|
57
|
-
}));
|
|
35
|
+
})))));
|
|
58
36
|
};
|
|
59
37
|
export default ChartType;
|
|
@@ -4,7 +4,6 @@ import SelectTable from './select-table';
|
|
|
4
4
|
import SelectView from './select-view';
|
|
5
5
|
import DataFilter from './data-filter';
|
|
6
6
|
import Divider from './divider';
|
|
7
|
-
import { generateChartConfig } from '../../utils';
|
|
8
7
|
const CommonDataSettings = _ref => {
|
|
9
8
|
let {
|
|
10
9
|
chart,
|
|
@@ -40,16 +39,11 @@ const CommonDataSettings = _ref => {
|
|
|
40
39
|
view_id: selectedViewId
|
|
41
40
|
});
|
|
42
41
|
}, [chart, onChange]);
|
|
43
|
-
const generateConfig = useCallback(config => {
|
|
44
|
-
return generateChartConfig(config, tables);
|
|
45
|
-
}, [tables]);
|
|
46
42
|
const {
|
|
47
43
|
table_id
|
|
48
44
|
} = chart.config;
|
|
49
45
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StatisticType, {
|
|
50
|
-
chart: chart
|
|
51
|
-
generateChartConfig: generateConfig,
|
|
52
|
-
onChange: onChange
|
|
46
|
+
chart: chart
|
|
53
47
|
}), /*#__PURE__*/React.createElement(SelectTable, {
|
|
54
48
|
tables: tables,
|
|
55
49
|
selectedTableId: table_id,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class EventBus {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.subscribers = {};
|
|
4
|
+
}
|
|
5
|
+
subscribe(type, handler) {
|
|
6
|
+
if (!this.subscribers[type]) {
|
|
7
|
+
this.subscribers[type] = [];
|
|
8
|
+
}
|
|
9
|
+
const handlers = this.subscribers[type];
|
|
10
|
+
handlers.push(handler);
|
|
11
|
+
return () => {
|
|
12
|
+
const index = handlers.indexOf(handler);
|
|
13
|
+
if (index > -1) {
|
|
14
|
+
handlers.splice(index, 1);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
dispatch(type) {
|
|
19
|
+
for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
20
|
+
data[_key - 1] = arguments[_key];
|
|
21
|
+
}
|
|
22
|
+
const handlers = this.subscribers[type];
|
|
23
|
+
if (Array.isArray(handlers)) {
|
|
24
|
+
handlers.forEach(handler => handler(...data));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export default new EventBus();
|