sea-chart 2.0.7 → 2.0.9
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/components/tooltip/index.js +92 -0
- package/dist/components/types-dialog/index.js +12 -5
- package/dist/settings/advance-bar-settings/style-settings.js +14 -14
- package/dist/settings/pie-settings/style-settings.js +7 -7
- package/dist/settings/widgets/chart-type/index.js +10 -9
- package/dist/view/wrapper/bar-compare.js +326 -0
- package/dist/view/wrapper/bar-custom-stack.js +344 -0
- package/dist/view/wrapper/bar-group.js +297 -0
- package/dist/view/wrapper/bar-stack.js +334 -0
- package/dist/view/wrapper/bar.js +35 -37
- package/dist/view/wrapper/chart-component.js +184 -70
- package/dist/view/wrapper/index.js +35 -0
- package/package.json +2 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
const ToolTip = _ref => {
|
|
10
|
+
let {
|
|
11
|
+
tooltipData,
|
|
12
|
+
toolTipPosition,
|
|
13
|
+
chart
|
|
14
|
+
} = _ref;
|
|
15
|
+
const tooltipRef = (0, _react.useRef)(null);
|
|
16
|
+
const [position, setPosition] = (0, _react.useState)({
|
|
17
|
+
offsetX: -9999,
|
|
18
|
+
offsetY: -9999
|
|
19
|
+
});
|
|
20
|
+
const {
|
|
21
|
+
title,
|
|
22
|
+
items
|
|
23
|
+
} = tooltipData || {
|
|
24
|
+
title: '',
|
|
25
|
+
items: []
|
|
26
|
+
};
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
if (!toolTipPosition) {
|
|
29
|
+
setPosition({
|
|
30
|
+
offsetX: -9999,
|
|
31
|
+
offsetY: -9999
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (chart && toolTipPosition) {
|
|
36
|
+
const width = Number(chart.node().getAttribute('width'));
|
|
37
|
+
const height = Number(chart.node().getAttribute('height'));
|
|
38
|
+
const {
|
|
39
|
+
height: tooltipHeight,
|
|
40
|
+
width: tooltipWidth
|
|
41
|
+
} = tooltipRef.current.getBoundingClientRect();
|
|
42
|
+
const {
|
|
43
|
+
offsetX,
|
|
44
|
+
offsetY
|
|
45
|
+
} = toolTipPosition;
|
|
46
|
+
const distance = 30;
|
|
47
|
+
const insertPadding = 30;
|
|
48
|
+
let translateX = offsetX + distance;
|
|
49
|
+
let translateY = offsetY;
|
|
50
|
+
const endOffsetX = offsetX + distance + tooltipWidth + insertPadding;
|
|
51
|
+
const endOffsetY = offsetY + tooltipHeight + insertPadding;
|
|
52
|
+
// Right overflow
|
|
53
|
+
if (endOffsetX > width) {
|
|
54
|
+
translateX = offsetX - distance - tooltipWidth - insertPadding;
|
|
55
|
+
}
|
|
56
|
+
// Bottom overflow
|
|
57
|
+
if (endOffsetY > height) {
|
|
58
|
+
translateY = offsetY - (endOffsetY - height);
|
|
59
|
+
}
|
|
60
|
+
setPosition({
|
|
61
|
+
offsetX: translateX,
|
|
62
|
+
offsetY: translateY
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, [chart, toolTipPosition, tooltipRef]);
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
|
+
ref: tooltipRef,
|
|
68
|
+
className: "sea-chart-d3-tooltip-container",
|
|
69
|
+
style: {
|
|
70
|
+
transform: "translate(".concat(position.offsetX, "px, ").concat(position.offsetY, "px)")
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
73
|
+
className: "sea-chart-d3-tooltip-title"
|
|
74
|
+
}, title), /*#__PURE__*/_react.default.createElement("ul", {
|
|
75
|
+
className: "sea-chart-d3-tooltip-list"
|
|
76
|
+
}, items.map((item, index) => {
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement("li", {
|
|
78
|
+
className: "sea-chart-d3-tooltip-list-item",
|
|
79
|
+
key: index
|
|
80
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
81
|
+
className: "sea-chart-d3-tooltip-marker",
|
|
82
|
+
style: {
|
|
83
|
+
backgroundColor: item.color
|
|
84
|
+
}
|
|
85
|
+
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
86
|
+
className: "sea-chart-d3-tooltip-name"
|
|
87
|
+
}, item.name), /*#__PURE__*/_react.default.createElement("span", {
|
|
88
|
+
className: "sea-chart-d3-tooltip-value"
|
|
89
|
+
}, item.value));
|
|
90
|
+
})));
|
|
91
|
+
};
|
|
92
|
+
var _default = exports.default = ToolTip;
|
|
@@ -23,7 +23,8 @@ const TypesDialog = _ref => {
|
|
|
23
23
|
lang,
|
|
24
24
|
onToggle: propsOnToggle,
|
|
25
25
|
onChange,
|
|
26
|
-
dataSources
|
|
26
|
+
dataSources,
|
|
27
|
+
hideTypeToggle
|
|
27
28
|
} = _ref;
|
|
28
29
|
const [currentCatIndex, setCurrentCatIndex] = (0, _react.useState)(0);
|
|
29
30
|
const [selectedType, setType] = (0, _react.useState)(type);
|
|
@@ -66,11 +67,17 @@ const TypesDialog = _ref => {
|
|
|
66
67
|
onChange(selectedType);
|
|
67
68
|
onToggle();
|
|
68
69
|
}, [onChange, selectedType, onToggle]);
|
|
70
|
+
const handleFilterTypes = (0, _react.useCallback)(() => {
|
|
71
|
+
if (hideTypeToggle) {
|
|
72
|
+
const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram'].includes(item.name));
|
|
73
|
+
return newChartTypes;
|
|
74
|
+
}
|
|
75
|
+
return _constants.CHART_TYPES;
|
|
76
|
+
}, [hideTypeToggle]);
|
|
69
77
|
return /*#__PURE__*/_react.default.createElement(_reactstrap.Modal, {
|
|
70
78
|
isOpen: true,
|
|
71
79
|
toggle: onToggle,
|
|
72
|
-
className: "sea-chart-types-dialog"
|
|
73
|
-
zIndex: 1048
|
|
80
|
+
className: "sea-chart-types-dialog"
|
|
74
81
|
}, /*#__PURE__*/_react.default.createElement(_DTableModalHeader2.default, {
|
|
75
82
|
toggle: onToggle
|
|
76
83
|
}, type ? _intl.default.get('Edit_type') : _intl.default.get('All_charts')), /*#__PURE__*/_react.default.createElement(_reactstrap.ModalBody, {
|
|
@@ -79,7 +86,7 @@ const TypesDialog = _ref => {
|
|
|
79
86
|
className: "sea-chart-types-container d-flex flex-column h-100"
|
|
80
87
|
}, /*#__PURE__*/_react.default.createElement("ul", {
|
|
81
88
|
className: "sea-chart-chart-categories-nav flex-shrink-0 d-flex flex-wrap align-items-center list-unstyled"
|
|
82
|
-
},
|
|
89
|
+
}, handleFilterTypes().map((item, index) => {
|
|
83
90
|
return /*#__PURE__*/_react.default.createElement("li", {
|
|
84
91
|
key: index,
|
|
85
92
|
className: "px-4 py-2 sea-chart-chart-cat-nav-item"
|
|
@@ -101,7 +108,7 @@ const TypesDialog = _ref => {
|
|
|
101
108
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
102
109
|
className: "flex-fill o-auto sea-chart-type-container",
|
|
103
110
|
ref: seaChartTypeContainerRef
|
|
104
|
-
},
|
|
111
|
+
}, handleFilterTypes().map((item, index) => {
|
|
105
112
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
106
113
|
key: "sea-chart-type-".concat(index),
|
|
107
114
|
className: "mb-7"
|
|
@@ -11,11 +11,11 @@ var _DTableRadioGroup2 = _interopRequireDefault(require("dtable-ui-component/lib
|
|
|
11
11
|
var _DTableSwitch2 = _interopRequireDefault(require("dtable-ui-component/lib/DTableSwitch"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _reactstrap = require("reactstrap");
|
|
14
|
-
var
|
|
14
|
+
var _dtableUtils = require("dtable-utils");
|
|
15
15
|
var _divider = _interopRequireDefault(require("../widgets/divider"));
|
|
16
16
|
var _minMaxSetting = _interopRequireDefault(require("../widgets/min-max-setting"));
|
|
17
17
|
var _displayValuesSettings = _interopRequireDefault(require("../widgets/display-values-settings"));
|
|
18
|
-
var
|
|
18
|
+
var _constants = require("../../constants");
|
|
19
19
|
var _intl = _interopRequireDefault(require("../../intl"));
|
|
20
20
|
var _selectLineType = _interopRequireDefault(require("../widgets/select-line-type"));
|
|
21
21
|
var _colorSelector = _interopRequireDefault(require("../../components/chart-color-selector/color-selector"));
|
|
@@ -60,20 +60,20 @@ const StyleSettings = _ref => {
|
|
|
60
60
|
} = style_config || {};
|
|
61
61
|
const table = tables.find(table => table._id === table_id);
|
|
62
62
|
const column = (0, _utils.getColumnByKey)(column_groupby_column_key, table.columns);
|
|
63
|
-
const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) ===
|
|
63
|
+
const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) === _dtableUtils.CellType.SINGLE_SELECT;
|
|
64
64
|
const defaultColorTheme = _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.DEFAULT;
|
|
65
65
|
const [currYaxisTitle, setCurrYaxisTitle] = (0, _react.useState)(title_name || '');
|
|
66
66
|
const xAxisLabelOptions = (0, _react.useMemo)(() => {
|
|
67
67
|
if (xLabel === 'Vertical_axis') {
|
|
68
|
-
return
|
|
68
|
+
return _constants.Y_LABEL_POSITIONS;
|
|
69
69
|
}
|
|
70
|
-
return
|
|
70
|
+
return _constants.X_LABEL_POSITIONS;
|
|
71
71
|
}, [xLabel]);
|
|
72
72
|
const yAxisLabelOptions = (0, _react.useMemo)(() => {
|
|
73
73
|
if (yLabel === 'Horizontal_axis') {
|
|
74
|
-
return
|
|
74
|
+
return _constants.X_LABEL_POSITIONS;
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return _constants.Y_LABEL_POSITIONS;
|
|
77
77
|
}, [yLabel]);
|
|
78
78
|
const onAxisLabelShowChange = (0, _react.useCallback)(labelKey => {
|
|
79
79
|
const {
|
|
@@ -162,12 +162,12 @@ const StyleSettings = _ref => {
|
|
|
162
162
|
}, []);
|
|
163
163
|
const xAxisLabelPosition = x_axis_label_position || xAxisLabelOptions[0];
|
|
164
164
|
const yAxisLabelPosition = y_axis_label_position || yAxisLabelOptions[0];
|
|
165
|
-
const isLineChart = [
|
|
165
|
+
const isLineChart = [_constants.CHART_TYPE.LINE, _constants.CHART_TYPE.LINE_GROUP, _constants.CHART_TYPE.AREA, _constants.CHART_TYPE.AREA_GROUP].includes(type);
|
|
166
166
|
const getLabelOptionsDisplay = options => {
|
|
167
167
|
return options.reduce((optionDisplayMap, position) => {
|
|
168
168
|
return {
|
|
169
169
|
...optionDisplayMap,
|
|
170
|
-
[position]: _intl.default.get(
|
|
170
|
+
[position]: _intl.default.get(_constants.LABEL_POSITION_TYPE_SHOW[position])
|
|
171
171
|
};
|
|
172
172
|
}, {});
|
|
173
173
|
};
|
|
@@ -196,7 +196,7 @@ const StyleSettings = _ref => {
|
|
|
196
196
|
checked: y_axis_show_label || false,
|
|
197
197
|
placeholder: _intl.default.get('Display_title'),
|
|
198
198
|
onChange: () => onAxisLabelShowChange('y_axis_show_label')
|
|
199
|
-
}), y_axis_show_label && [
|
|
199
|
+
}), y_axis_show_label && [_constants.CHART_TYPE.BAR_STACK].includes(type) && /*#__PURE__*/_react.default.createElement("div", {
|
|
200
200
|
className: "mt-3"
|
|
201
201
|
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Label, {
|
|
202
202
|
for: "y-axis-custom-title-input"
|
|
@@ -218,7 +218,7 @@ const StyleSettings = _ref => {
|
|
|
218
218
|
options: yAxisLabelOptions,
|
|
219
219
|
optionsDisplay: getLabelOptionsDisplay(yAxisLabelOptions),
|
|
220
220
|
onSelectChanged: position => onAxisLabelPositionChange(position, 'y_axis_label_position')
|
|
221
|
-
})), ![
|
|
221
|
+
})), ![_constants.CHART_TYPE.BAR_CUSTOM].includes(type) && /*#__PURE__*/_react.default.createElement(_DTableSwitch2.default, {
|
|
222
222
|
key: "y_axis_auto_range",
|
|
223
223
|
switchClassName: "mt-3",
|
|
224
224
|
checked: y_axis_auto_range,
|
|
@@ -235,18 +235,18 @@ const StyleSettings = _ref => {
|
|
|
235
235
|
}), isGroupBySingleSelectColumn && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_divider.default, null), /*#__PURE__*/_react.default.createElement(_colorSelector.default, {
|
|
236
236
|
colorTheme: color_theme || defaultColorTheme,
|
|
237
237
|
onChange: onChartColorChange
|
|
238
|
-
})), /*#__PURE__*/_react.default.createElement(_divider.default, null),
|
|
238
|
+
})), /*#__PURE__*/_react.default.createElement(_divider.default, null), _constants.SUPPORT_GOAL_LINE_CHART_TYPES.includes(type) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_goalLineSetting.default, {
|
|
239
239
|
displayGoalLine: display_goal_line,
|
|
240
240
|
goalLabel: goal_label,
|
|
241
241
|
goalValue: goal_value,
|
|
242
242
|
onChange: onStyleChange
|
|
243
|
-
}), /*#__PURE__*/_react.default.createElement(_divider.default, null)), ![
|
|
243
|
+
}), /*#__PURE__*/_react.default.createElement(_divider.default, null)), ![_constants.CHART_TYPE.BAR_CUSTOM].includes(type) && /*#__PURE__*/_react.default.createElement(_displayValuesSettings.default, {
|
|
244
244
|
isShowValueKey: "y_axis_show_value",
|
|
245
245
|
isShowValue: y_axis_show_value,
|
|
246
246
|
fontSizeKey: "label_font_size",
|
|
247
247
|
fontSize: label_font_size,
|
|
248
248
|
onChange: onDisplayValueChange
|
|
249
|
-
}),
|
|
249
|
+
}), _constants.SUPPORT_STACK_VALUE_CHART_TYPES.includes(type) && /*#__PURE__*/_react.default.createElement(_DTableSwitch2.default, {
|
|
250
250
|
switchClassName: "display-value-settings",
|
|
251
251
|
checked: display_each_block_data,
|
|
252
252
|
disabled: false,
|
|
@@ -11,12 +11,12 @@ var _DTableSelect2 = _interopRequireDefault(require("dtable-ui-component/lib/DTa
|
|
|
11
11
|
var _DTableSwitch2 = _interopRequireDefault(require("dtable-ui-component/lib/DTableSwitch"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _reactstrap = require("reactstrap");
|
|
14
|
-
var
|
|
14
|
+
var _dtableUtils = require("dtable-utils");
|
|
15
15
|
var _divider = _interopRequireDefault(require("../widgets/divider"));
|
|
16
16
|
var _mininumSlicePercent = _interopRequireDefault(require("../widgets/mininum-slice-percent"));
|
|
17
17
|
var _fontSettings = require("../widgets/font-settings");
|
|
18
18
|
var _utils = require("../../utils");
|
|
19
|
-
var
|
|
19
|
+
var _constants = require("../../constants");
|
|
20
20
|
var _intl = _interopRequireDefault(require("../../intl"));
|
|
21
21
|
var _colorRules = require("../../constants/color-rules");
|
|
22
22
|
var _colorSelector = _interopRequireDefault(require("../../components/chart-color-selector/color-selector"));
|
|
@@ -27,18 +27,18 @@ const StyleSettings = _ref => {
|
|
|
27
27
|
tables
|
|
28
28
|
} = _ref;
|
|
29
29
|
const labelPositionOptions = (0, _react.useMemo)(() => {
|
|
30
|
-
return
|
|
30
|
+
return _constants.CHART_LABEL_POSITIONS.map(item => {
|
|
31
31
|
return {
|
|
32
32
|
value: item,
|
|
33
|
-
label: _intl.default.get(
|
|
33
|
+
label: _intl.default.get(_constants.CHART_LABEL_POSITION_SHOW[item])
|
|
34
34
|
};
|
|
35
35
|
});
|
|
36
36
|
}, []);
|
|
37
37
|
const labelFormatOptions = (0, _react.useMemo)(() => {
|
|
38
|
-
return
|
|
38
|
+
return _constants.CHART_LABEL_FORMATS.map(item => {
|
|
39
39
|
return {
|
|
40
40
|
value: item,
|
|
41
|
-
label: _intl.default.get(
|
|
41
|
+
label: _intl.default.get(_constants.CHART_LABEL_FORMAT_SHOW[item])
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
44
|
}, []);
|
|
@@ -122,7 +122,7 @@ const StyleSettings = _ref => {
|
|
|
122
122
|
} = config;
|
|
123
123
|
const table = tables.find(table => table._id === table_id);
|
|
124
124
|
const column = (0, _utils.getColumnByKey)(groupby_column_key, table.columns);
|
|
125
|
-
const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) ===
|
|
125
|
+
const isGroupBySingleSelectColumn = (column === null || column === void 0 ? void 0 : column.type) === _dtableUtils.CellType.SINGLE_SELECT;
|
|
126
126
|
const defaultColorTheme = _colorRules.SUPPORT_SINGLE_SELECT_THEMES_OPTIONS.DEFAULT;
|
|
127
127
|
const selectedLabelOption = labelPositionOptions.find(item => item.value === label_position);
|
|
128
128
|
const selectedLabelFormat = labelFormatOptions.find(item => item.value === label_format) || labelFormatOptions[0];
|
|
@@ -42,10 +42,13 @@ const ChartType = _ref => {
|
|
|
42
42
|
if (type === oldType) return;
|
|
43
43
|
|
|
44
44
|
// reset these two configs to preventing new type getting into the wrong calculator
|
|
45
|
-
|
|
46
|
-
config.column_groupby_multiple_numeric_column = null;
|
|
47
|
-
const convertedChart = generateChartConfig({
|
|
45
|
+
const newConfig = {
|
|
48
46
|
...config,
|
|
47
|
+
column_groupby_column_key: null,
|
|
48
|
+
column_groupby_multiple_numeric_column: null
|
|
49
|
+
};
|
|
50
|
+
const convertedChart = generateChartConfig({
|
|
51
|
+
...newConfig,
|
|
49
52
|
type
|
|
50
53
|
});
|
|
51
54
|
onChange && onChange(convertedChart);
|
|
@@ -60,11 +63,8 @@ const ChartType = _ref => {
|
|
|
60
63
|
className: "sea-chart-parameter-item",
|
|
61
64
|
id: "sea-chart-type-container"
|
|
62
65
|
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Label, null, _intl.default.get('Chart_type')), /*#__PURE__*/_react.default.createElement("div", {
|
|
63
|
-
className: "sea-chart-selected-type-container d-flex align-items-center"
|
|
64
|
-
|
|
65
|
-
backgroundColor: hideTypeToggle ? '#f5f5f5' : '#fff'
|
|
66
|
-
}
|
|
67
|
-
}, /*#__PURE__*/_react.default.createElement("span", null, _intl.default.get(_constants.CHART_TYPE_SHOW[type])), !hideTypeToggle && /*#__PURE__*/_react.default.createElement("div", {
|
|
66
|
+
className: "sea-chart-selected-type-container d-flex align-items-center"
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, _intl.default.get(_constants.CHART_TYPE_SHOW[type])), /*#__PURE__*/_react.default.createElement("div", {
|
|
68
68
|
className: "sea-chart-type-icon-container",
|
|
69
69
|
onClick: openTypesDialog
|
|
70
70
|
}, /*#__PURE__*/_react.default.createElement(_components.Icon, {
|
|
@@ -74,7 +74,8 @@ const ChartType = _ref => {
|
|
|
74
74
|
dataSources: dataSources,
|
|
75
75
|
type: type,
|
|
76
76
|
onToggle: closeTypesDialog,
|
|
77
|
-
onChange: onTypeChange
|
|
77
|
+
onChange: onTypeChange,
|
|
78
|
+
hideTypeToggle: hideTypeToggle
|
|
78
79
|
}));
|
|
79
80
|
};
|
|
80
81
|
var _default = exports.default = ChartType;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
12
|
+
var _dtableUtils = require("dtable-utils");
|
|
13
|
+
var _constants = require("../../constants");
|
|
14
|
+
var _chartUtils = require("../../utils/chart-utils");
|
|
15
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
16
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
17
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
18
|
+
class BarCompare extends _chartComponent.default {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.createChart = () => {
|
|
22
|
+
const {
|
|
23
|
+
chart
|
|
24
|
+
} = this.props;
|
|
25
|
+
const initConfig = {
|
|
26
|
+
insertPadding: 30,
|
|
27
|
+
borderRadius: 10,
|
|
28
|
+
overflowHeight: 20 // Fillet the bottom corner beyond the axis and then cover it with a mask
|
|
29
|
+
};
|
|
30
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
31
|
+
this.initDefs();
|
|
32
|
+
};
|
|
33
|
+
this.drawChart = () => {
|
|
34
|
+
let {
|
|
35
|
+
result: data
|
|
36
|
+
} = this.props;
|
|
37
|
+
data = _chartUtils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
38
|
+
if (!Array.isArray(data)) return;
|
|
39
|
+
this.draw(data);
|
|
40
|
+
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
41
|
+
};
|
|
42
|
+
this.draw = data => {
|
|
43
|
+
const {
|
|
44
|
+
chart,
|
|
45
|
+
globalTheme,
|
|
46
|
+
chartColorTheme,
|
|
47
|
+
canvasStyle
|
|
48
|
+
} = this.props;
|
|
49
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
50
|
+
const {
|
|
51
|
+
previewType
|
|
52
|
+
} = canvasStyle || {};
|
|
53
|
+
const {
|
|
54
|
+
display_increase,
|
|
55
|
+
y_axis_auto_range,
|
|
56
|
+
y_axis_min,
|
|
57
|
+
y_axis_max
|
|
58
|
+
} = chart.config;
|
|
59
|
+
const {
|
|
60
|
+
width: chartWidth,
|
|
61
|
+
height: chartHeight,
|
|
62
|
+
insertPadding,
|
|
63
|
+
borderRadius,
|
|
64
|
+
overflowHeight
|
|
65
|
+
} = this.chartBoundingClientRect;
|
|
66
|
+
data = data.sort((a, b) => d3.ascending(a.name, b.name));
|
|
67
|
+
const fx = d3.scaleBand().domain(d3.group(data, d => d.name).keys()).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
68
|
+
const color = d3.scaleOrdinal().domain(d3.group(data, d => d.group_name).keys()).range(_chartUtils.BaseUtils.getCurrentTheme(chartColorTheme).colors).unknown('#ccc');
|
|
69
|
+
const x = d3.scaleBand().domain(d3.group(data, d => d.group_name).keys()).range([0, fx.bandwidth()]);
|
|
70
|
+
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, d3.max(data, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
|
|
71
|
+
|
|
72
|
+
// X axis
|
|
73
|
+
this.chart.append('g').attr('transform', "translate(0,".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(fx).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
74
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
75
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
76
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
77
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Y axis
|
|
81
|
+
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ",0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => {
|
|
82
|
+
g.select('.domain').remove();
|
|
83
|
+
g.selectAll('line').node() && g.selectAll('line').node().remove(); // delete the first line
|
|
84
|
+
g.selectAll('.tick line').clone().attr('x2', chartWidth - insertPadding * 2).attr('stroke', theme.gridColor).attr('stroke-dasharray', '8,3');
|
|
85
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
86
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Rect group
|
|
90
|
+
this.chart.append('g').attr('class', "rects-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id)).attr('mask', "url(#mask-wrapper-".concat(previewType, "-").concat(chart === null || chart === void 0 ? void 0 : chart.id, ")")).selectAll().data(() => d3.group(data, d => d.name)).join('g').attr('transform', _ref => {
|
|
91
|
+
let [name, dum] = _ref;
|
|
92
|
+
// Each group is horizontally centered
|
|
93
|
+
const offset = (fx.bandwidth() - dum.length * x.bandwidth()) / 2;
|
|
94
|
+
return "translate(".concat(fx(name) + offset, ",0)");
|
|
95
|
+
})
|
|
96
|
+
// rect item
|
|
97
|
+
.selectAll().data(_ref2 => {
|
|
98
|
+
let [a, d] = _ref2;
|
|
99
|
+
return d;
|
|
100
|
+
}).join('rect').attr('x', (d, index) => index * x.bandwidth()).attr('y', d => y(d.value)).attr('width', x.bandwidth()).attr('height', d => y(0) - y(d.value) === 0 ? 0 : y(0) - y(d.value) + overflowHeight).attr('rx', borderRadius).attr('fill', d => color(d.group_name)).attr('data-value', d => d.value).attr('data-groupName', d => d.name).on('click', (event, data) => {
|
|
101
|
+
this.props.toggleRecords(data);
|
|
102
|
+
}).on('mouseover', event => {
|
|
103
|
+
this.showTooltip(event, color);
|
|
104
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
105
|
+
}).on('mousemove', event => {
|
|
106
|
+
this.moveTooltip(event, color);
|
|
107
|
+
}).on('mouseleave', event => {
|
|
108
|
+
this.hiddenTooltip();
|
|
109
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
110
|
+
});
|
|
111
|
+
if (display_increase) {
|
|
112
|
+
const increaseData = this.getIncreaseData(data);
|
|
113
|
+
this.drawIncreaseLine(increaseData);
|
|
114
|
+
}
|
|
115
|
+
this.setColorMap(data, chartColorTheme);
|
|
116
|
+
this.setLegend('group_name', theme, 'top-right', data);
|
|
117
|
+
};
|
|
118
|
+
this.showTooltip = (event, colorScale, isCircle) => {
|
|
119
|
+
const {
|
|
120
|
+
y_axis_summary_type,
|
|
121
|
+
y_axis_summary_method,
|
|
122
|
+
increase_line_color
|
|
123
|
+
} = this.props.chart.config;
|
|
124
|
+
const {
|
|
125
|
+
offsetX,
|
|
126
|
+
offsetY
|
|
127
|
+
} = event;
|
|
128
|
+
let newTooltipData = {};
|
|
129
|
+
if (isCircle) {
|
|
130
|
+
const circleEl = event.target;
|
|
131
|
+
newTooltipData = {
|
|
132
|
+
title: _intl.default.get(_constants.TITLE_INCREASE),
|
|
133
|
+
items: [{
|
|
134
|
+
color: increase_line_color || '#fbd44a',
|
|
135
|
+
name: circleEl.getAttribute('data-name'),
|
|
136
|
+
value: circleEl.getAttribute('data-text')
|
|
137
|
+
}]
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
const curGroup = event.target.parentNode;
|
|
141
|
+
const [, data] = curGroup.__data__;
|
|
142
|
+
newTooltipData = {
|
|
143
|
+
title: y_axis_summary_type === 'count' ? _intl.default.get(_constants.TITLE_AMOUNT) : _intl.default.get(_constants.CHART_SUMMARY_SHOW[y_axis_summary_method]),
|
|
144
|
+
items: data.map(item => {
|
|
145
|
+
return {
|
|
146
|
+
color: colorScale(item.group_name),
|
|
147
|
+
name: item.group_name,
|
|
148
|
+
value: item.value
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
this.setState({
|
|
154
|
+
tooltipData: newTooltipData
|
|
155
|
+
});
|
|
156
|
+
this.setState({
|
|
157
|
+
toolTipPosition: {
|
|
158
|
+
offsetX,
|
|
159
|
+
offsetY
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
this.moveTooltip = event => {
|
|
164
|
+
const {
|
|
165
|
+
offsetX,
|
|
166
|
+
offsetY
|
|
167
|
+
} = event;
|
|
168
|
+
this.setState({
|
|
169
|
+
toolTipPosition: {
|
|
170
|
+
offsetX,
|
|
171
|
+
offsetY
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
this.hiddenTooltip = event => {
|
|
176
|
+
this.setState({
|
|
177
|
+
toolTipPosition: null
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
this.drawIncreaseLine = increaseData => {
|
|
181
|
+
const {
|
|
182
|
+
chart,
|
|
183
|
+
globalTheme
|
|
184
|
+
} = this.props;
|
|
185
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
186
|
+
const {
|
|
187
|
+
label_font_size,
|
|
188
|
+
y_axis_auto_range,
|
|
189
|
+
y_axis_min,
|
|
190
|
+
y_axis_max,
|
|
191
|
+
increase_line_color,
|
|
192
|
+
display_increase_percentage
|
|
193
|
+
} = chart.config;
|
|
194
|
+
const {
|
|
195
|
+
width: chartWidth,
|
|
196
|
+
height: chartHeight,
|
|
197
|
+
insertPadding
|
|
198
|
+
} = this.chartBoundingClientRect;
|
|
199
|
+
const circleData = increaseData.map(() => ({}));
|
|
200
|
+
const lineX = d3.scaleBand().domain(increaseData.map(d => d.name)).range([insertPadding, chartWidth - insertPadding]).paddingInner(0.1).paddingOuter(0.1);
|
|
201
|
+
const lineY = d3.scaleLinear().domain(y_axis_auto_range ? [d3.min(increaseData, d => d.value), d3.max(increaseData, d => d.value)] : [y_axis_min, y_axis_max]).range([chartHeight - insertPadding, insertPadding]);
|
|
202
|
+
const line = d3.line().x((d, index) => {
|
|
203
|
+
const x = lineX(d.name) + lineX.bandwidth() / 2;
|
|
204
|
+
circleData[index]['x'] = x;
|
|
205
|
+
circleData[index]['name'] = d.name;
|
|
206
|
+
return x;
|
|
207
|
+
}).y((d, index) => {
|
|
208
|
+
const y = lineY(d.value);
|
|
209
|
+
circleData[index]['y'] = y;
|
|
210
|
+
circleData[index]['value'] = d.formatValue;
|
|
211
|
+
return y;
|
|
212
|
+
}).curve(d3.curveBumpX);
|
|
213
|
+
const wrapper = this.chart.append('g').attr('class', "increase-line-wrapper-".concat(chart === null || chart === void 0 ? void 0 : chart.id));
|
|
214
|
+
|
|
215
|
+
// line
|
|
216
|
+
wrapper.append('path').attr('fill', 'none').attr('stroke', increase_line_color || '#fbd44a').attr('stroke-width', 2).attr('d', () => line(increaseData));
|
|
217
|
+
|
|
218
|
+
// circle
|
|
219
|
+
console.log('wrapper', wrapper);
|
|
220
|
+
circleData.forEach(item => {
|
|
221
|
+
wrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', increase_line_color || '#fbd44a').attr('data-text', item.value).attr('data-name', item.name).call(g => {
|
|
222
|
+
// circle label
|
|
223
|
+
if (display_increase_percentage) {
|
|
224
|
+
const curCircleEl = g.node();
|
|
225
|
+
wrapper.append('text').attr('fill', theme.labelColor).attr('font-size', _chartUtils.BaseUtils.getLabelFontSize(label_font_size)).text(curCircleEl.getAttribute('data-text')).call(g => {
|
|
226
|
+
const {
|
|
227
|
+
width
|
|
228
|
+
} = g.node().getBoundingClientRect();
|
|
229
|
+
const translateX = Number(curCircleEl.getAttribute('cx')) - width / 2;
|
|
230
|
+
const translateY = Number(curCircleEl.getAttribute('cy')) - 10;
|
|
231
|
+
g.attr('transform', "translate(".concat(translateX, ", ").concat(translateY, ")"));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}).on('mouseover', event => {
|
|
235
|
+
this.updateCircleStyle(event, 'zoomIn');
|
|
236
|
+
this.showTooltip(event, '', true);
|
|
237
|
+
}).on('mousemove', event => {
|
|
238
|
+
this.moveTooltip(event);
|
|
239
|
+
}).on('mouseleave', event => {
|
|
240
|
+
this.hiddenTooltip();
|
|
241
|
+
this.updateCircleStyle(event, 'zoomOut');
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
this.getIncreaseData = data => {
|
|
246
|
+
const increaseData = [];
|
|
247
|
+
d3.group(data, d => d.name).forEach((value, key) => {
|
|
248
|
+
var _increaseValue$, _increaseValue$2;
|
|
249
|
+
const increaseValue = value.filter(d => (d === null || d === void 0 ? void 0 : d.increase_value) !== undefined) || [{
|
|
250
|
+
increaseValue: 0
|
|
251
|
+
}];
|
|
252
|
+
const formatValue = (0, _dtableUtils.getNumberDisplayString)((_increaseValue$ = increaseValue[0]) === null || _increaseValue$ === void 0 ? void 0 : _increaseValue$.increase_value, {
|
|
253
|
+
format: 'percent'
|
|
254
|
+
});
|
|
255
|
+
const data = {
|
|
256
|
+
name: key,
|
|
257
|
+
value: ((_increaseValue$2 = increaseValue[0]) === null || _increaseValue$2 === void 0 ? void 0 : _increaseValue$2.increase_value) || 0,
|
|
258
|
+
formatValue: formatValue || '0%',
|
|
259
|
+
rowData: value
|
|
260
|
+
};
|
|
261
|
+
increaseData.push(data);
|
|
262
|
+
});
|
|
263
|
+
return increaseData;
|
|
264
|
+
};
|
|
265
|
+
this.updateCircleStyle = (event, state) => {
|
|
266
|
+
if (state === 'zoomIn') {
|
|
267
|
+
d3.select(event.currentTarget).attr('r', 5);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const circles = d3.select(event.currentTarget.parentNode).selectAll('circle').nodes();
|
|
271
|
+
circles.forEach(circle => d3.select(circle).attr('r', 3));
|
|
272
|
+
};
|
|
273
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
274
|
+
const curGroup = event.target.parentNode;
|
|
275
|
+
const allGroup = Array.from(curGroup.parentNode.children);
|
|
276
|
+
const [curGroupName] = curGroup.__data__;
|
|
277
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
278
|
+
};
|
|
279
|
+
this.chart = null;
|
|
280
|
+
this.state = {
|
|
281
|
+
tooltipData: null,
|
|
282
|
+
toolTipPosition: null
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
componentDidMount() {
|
|
286
|
+
this.createChart();
|
|
287
|
+
this.drawChart();
|
|
288
|
+
}
|
|
289
|
+
componentDidUpdate(prevProps) {
|
|
290
|
+
super.componentDidUpdate(prevProps);
|
|
291
|
+
if (_chartUtils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
292
|
+
this.createChart();
|
|
293
|
+
this.drawChart();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
componentWillUnmount() {
|
|
297
|
+
this.chart.node() && this.chart.node().remove();
|
|
298
|
+
}
|
|
299
|
+
render() {
|
|
300
|
+
const {
|
|
301
|
+
tooltipData,
|
|
302
|
+
toolTipPosition
|
|
303
|
+
} = this.state;
|
|
304
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
305
|
+
className: "sea-chart-container",
|
|
306
|
+
ref: ref => this.container = ref
|
|
307
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
308
|
+
tooltipData: tooltipData,
|
|
309
|
+
toolTipPosition: toolTipPosition,
|
|
310
|
+
chart: this.chart
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
BarCompare.propTypes = {
|
|
315
|
+
canvasStyle: _propTypes.default.object,
|
|
316
|
+
chart: _propTypes.default.object,
|
|
317
|
+
groupbyColumn: _propTypes.default.object,
|
|
318
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
319
|
+
summaryColumn: _propTypes.default.object,
|
|
320
|
+
result: _propTypes.default.array,
|
|
321
|
+
tables: _propTypes.default.array,
|
|
322
|
+
globalTheme: _propTypes.default.string,
|
|
323
|
+
chartColorTheme: _propTypes.default.string,
|
|
324
|
+
toggleRecords: _propTypes.default.func
|
|
325
|
+
};
|
|
326
|
+
var _default = exports.default = BarCompare;
|