sea-chart 2.0.19 → 2.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.
- package/dist/components/tooltip/index.js +13 -3
- package/dist/components/types-dialog/index.js +1 -1
- package/dist/view/wrapper/chart-component.js +32 -16
- package/dist/view/wrapper/index.js +7 -0
- package/dist/view/wrapper/line-group.js +25 -25
- package/dist/view/wrapper/line.js +16 -16
- package/dist/view/wrapper/pie.js +2 -2
- package/dist/view/wrapper/ring.js +3 -3
- package/dist/view/wrapper/scatter.js +335 -0
- package/package.json +2 -2
|
@@ -19,7 +19,8 @@ const ToolTip = _ref => {
|
|
|
19
19
|
});
|
|
20
20
|
const {
|
|
21
21
|
title,
|
|
22
|
-
items
|
|
22
|
+
items,
|
|
23
|
+
titleMarkColor
|
|
23
24
|
} = tooltipData || {
|
|
24
25
|
title: '',
|
|
25
26
|
items: []
|
|
@@ -71,13 +72,22 @@ const ToolTip = _ref => {
|
|
|
71
72
|
}
|
|
72
73
|
}, title && /*#__PURE__*/_react.default.createElement("div", {
|
|
73
74
|
className: "sea-chart-d3-tooltip-title"
|
|
74
|
-
},
|
|
75
|
+
}, titleMarkColor && /*#__PURE__*/_react.default.createElement("span", {
|
|
76
|
+
style: {
|
|
77
|
+
width: '8px',
|
|
78
|
+
height: '8px',
|
|
79
|
+
borderRadius: '50%',
|
|
80
|
+
backgroundColor: titleMarkColor,
|
|
81
|
+
display: 'inline-block',
|
|
82
|
+
marginRight: '12px'
|
|
83
|
+
}
|
|
84
|
+
}), title), /*#__PURE__*/_react.default.createElement("ul", {
|
|
75
85
|
className: "sea-chart-d3-tooltip-list"
|
|
76
86
|
}, items.map((item, index) => {
|
|
77
87
|
return /*#__PURE__*/_react.default.createElement("li", {
|
|
78
88
|
className: "sea-chart-d3-tooltip-list-item",
|
|
79
89
|
key: index
|
|
80
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
90
|
+
}, item.color && /*#__PURE__*/_react.default.createElement("span", {
|
|
81
91
|
className: "sea-chart-d3-tooltip-marker",
|
|
82
92
|
style: {
|
|
83
93
|
backgroundColor: item.color
|
|
@@ -69,7 +69,7 @@ const TypesDialog = _ref => {
|
|
|
69
69
|
}, [onChange, selectedType, onToggle]);
|
|
70
70
|
const handleFilterTypes = (0, _react.useCallback)(() => {
|
|
71
71
|
if (hideTypeToggle) {
|
|
72
|
-
const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram', 'Bar_chart', 'Line_chart', 'Area', 'Pie_chart'].includes(item.name));
|
|
72
|
+
const newChartTypes = _constants.CHART_TYPES.filter(item => ['Histogram', 'Bar_chart', 'Line_chart', 'Area', 'Pie_chart', 'Scatter_chart'].includes(item.name));
|
|
73
73
|
return newChartTypes;
|
|
74
74
|
}
|
|
75
75
|
return _constants.CHART_TYPES;
|
|
@@ -61,7 +61,7 @@ class ChartComponent extends _react.Component {
|
|
|
61
61
|
} = initConfig;
|
|
62
62
|
const width = containerWidth - marginLeft;
|
|
63
63
|
const height = containerHeight - marginBottom;
|
|
64
|
-
_this.chart = d3.create('svg').attr('id', id).attr('
|
|
64
|
+
_this.chart = d3.create('svg').attr('id', id).attr('width', width).attr('height', height).attr('viewBox', [0, 0, width, height]);
|
|
65
65
|
_this.container.appendChild(_this.chart.node());
|
|
66
66
|
_this.chartBoundingClientRect = {
|
|
67
67
|
...JSON.parse(JSON.stringify(_this.chart.node().getBoundingClientRect())),
|
|
@@ -585,7 +585,6 @@ class ChartComponent extends _react.Component {
|
|
|
585
585
|
};
|
|
586
586
|
// set legend
|
|
587
587
|
this.setLegend = _ref => {
|
|
588
|
-
var _this$chart$node;
|
|
589
588
|
let {
|
|
590
589
|
legendName,
|
|
591
590
|
theme = _constants.CHART_THEME_COLOR['light'],
|
|
@@ -615,11 +614,13 @@ class ChartComponent extends _react.Component {
|
|
|
615
614
|
const legendData = _utils.BaseUtils.sortDataByGroupName((0, _lodashEs.cloneDeep)(data), legendName, groupColumn, chart);
|
|
616
615
|
const {
|
|
617
616
|
width: chartWidth,
|
|
617
|
+
height: chartHeight,
|
|
618
618
|
insertPadding,
|
|
619
|
-
rightLegendSpace
|
|
619
|
+
rightLegendSpace,
|
|
620
|
+
bottomLegendSpace
|
|
620
621
|
} = this.chartBoundingClientRect;
|
|
621
622
|
const groupsData = this.getLegendDataGroups(legendData);
|
|
622
|
-
const legendWrapper = this.chart.append('g').attr('class',
|
|
623
|
+
const legendWrapper = this.chart.append('g').attr('class', 'legend-wrapper');
|
|
623
624
|
|
|
624
625
|
// Render first group legend
|
|
625
626
|
this.renderLegend({
|
|
@@ -689,7 +690,8 @@ class ChartComponent extends _react.Component {
|
|
|
689
690
|
} = g.node().parentNode.getBoundingClientRect();
|
|
690
691
|
groupTranslateY = groupTranslateY + height + legendItemMargin;
|
|
691
692
|
}
|
|
692
|
-
|
|
693
|
+
const curTranslateY = bottomLegendSpace ? chartHeight - bottomLegendSpace : groupTranslateY; // pageNavigator offset bottom
|
|
694
|
+
g.attr('transform', "translate(".concat(groupTranslateX, ", ").concat(curTranslateY, ")"));
|
|
693
695
|
});
|
|
694
696
|
}
|
|
695
697
|
};
|
|
@@ -913,15 +915,20 @@ class ChartComponent extends _react.Component {
|
|
|
913
915
|
}
|
|
914
916
|
};
|
|
915
917
|
this.setLegendItemOffset = (legendItems, end) => {
|
|
918
|
+
const {
|
|
919
|
+
height: chartHeight,
|
|
920
|
+
bottomLegendSpace
|
|
921
|
+
} = this.chartBoundingClientRect;
|
|
916
922
|
const endItem = legendItems[legendItems.length - 1];
|
|
917
923
|
const endTranslateX = Number(endItem.getAttribute('data-translateX'));
|
|
918
924
|
const {
|
|
919
925
|
width: endWidth
|
|
920
926
|
} = endItem.getBoundingClientRect();
|
|
921
927
|
const offset = end - (endTranslateX + endWidth);
|
|
928
|
+
const curTranslateY = bottomLegendSpace ? chartHeight - bottomLegendSpace : 0; // legend offset bottom
|
|
922
929
|
legendItems.forEach(legendItem => {
|
|
923
930
|
const curTranslateX = Number(legendItem.getAttribute('data-translateX')) + offset;
|
|
924
|
-
d3.select(legendItem).attr('transform', "translate(".concat(curTranslateX, ",
|
|
931
|
+
d3.select(legendItem).attr('transform', "translate(".concat(curTranslateX, ", ").concat(curTranslateY, ")")).attr('data-translateX', curTranslateX);
|
|
925
932
|
d3.select(legendItem).attr('opacity', 1);
|
|
926
933
|
});
|
|
927
934
|
};
|
|
@@ -1125,11 +1132,11 @@ class ChartComponent extends _react.Component {
|
|
|
1125
1132
|
return themeColors || _constants.CHART_THEME_COLOR[_constants.THEME_NAME_MAP.LIGHT];
|
|
1126
1133
|
};
|
|
1127
1134
|
this.setDispalyGoalLine = (goal_label, goal_value, insertPadding, yScale) => {
|
|
1128
|
-
var _this$chart$
|
|
1135
|
+
var _this$chart$node;
|
|
1129
1136
|
const {
|
|
1130
1137
|
width: chartWidth
|
|
1131
1138
|
} = this.chartBoundingClientRect;
|
|
1132
|
-
const annotationWrapper = this.chart.append('g').attr('class', "annotation-wrapper-".concat((_this$chart$
|
|
1139
|
+
const annotationWrapper = this.chart.append('g').attr('class', "annotation-wrapper-".concat((_this$chart$node = this.chart.node()) === null || _this$chart$node === void 0 ? void 0 : _this$chart$node.id));
|
|
1133
1140
|
annotationWrapper.append('line').attr('stroke', '#aaa').attr('x1', insertPadding).attr('y1', yScale(goal_value)).attr('x2', chartWidth - insertPadding).attr('y2', yScale(goal_value)).attr('stroke-dasharray', '8,3').call(g => {
|
|
1134
1141
|
annotationWrapper.append('text').attr('x', chartWidth - insertPadding - 30).attr('y', yScale(goal_value) - 10).attr('fill', '#666').text(goal_label);
|
|
1135
1142
|
});
|
|
@@ -1197,12 +1204,15 @@ class ChartComponent extends _react.Component {
|
|
|
1197
1204
|
g.attr('transform', "translate(".concat(translateX, ", ").concat(translateY, ")"));
|
|
1198
1205
|
});
|
|
1199
1206
|
};
|
|
1200
|
-
this.setActiveAndInActiveState = (state, allGroup, curGroupName) => {
|
|
1207
|
+
this.setActiveAndInActiveState = (state, allGroup, curGroupName, chartType) => {
|
|
1201
1208
|
if (state === 'active') {
|
|
1202
1209
|
allGroup.forEach(g => {
|
|
1203
1210
|
const rects = Array.from(g.children);
|
|
1204
1211
|
rects.forEach(item => {
|
|
1205
|
-
d3.select(item).transition().duration(
|
|
1212
|
+
d3.select(item).transition().duration(500).attr('opacity', 1);
|
|
1213
|
+
if ([_constants.CHART_TYPE.PIE, _constants.CHART_TYPE.RING].includes(chartType)) {
|
|
1214
|
+
d3.select(item).attr('stroke-width', 2);
|
|
1215
|
+
}
|
|
1206
1216
|
});
|
|
1207
1217
|
});
|
|
1208
1218
|
}
|
|
@@ -1211,7 +1221,11 @@ class ChartComponent extends _react.Component {
|
|
|
1211
1221
|
const rects = Array.from(g.children);
|
|
1212
1222
|
rects.forEach(item => {
|
|
1213
1223
|
if (item.getAttribute('data-groupName') !== curGroupName) {
|
|
1214
|
-
d3.
|
|
1224
|
+
d3.selectAll([item]).transition().duration(500).attr('opacity', 0.3);
|
|
1225
|
+
} else {
|
|
1226
|
+
if ([_constants.CHART_TYPE.PIE, _constants.CHART_TYPE.RING].includes(chartType)) {
|
|
1227
|
+
d3.select(item).attr('stroke-width', 0.5);
|
|
1228
|
+
}
|
|
1215
1229
|
}
|
|
1216
1230
|
});
|
|
1217
1231
|
});
|
|
@@ -1410,20 +1424,22 @@ class ChartComponent extends _react.Component {
|
|
|
1410
1424
|
const minItem = newAllData[minIndex];
|
|
1411
1425
|
return minItem;
|
|
1412
1426
|
};
|
|
1413
|
-
this.clearOldVerticalAnnotation =
|
|
1414
|
-
const oldAnnotationWrapper =
|
|
1427
|
+
this.clearOldVerticalAnnotation = contentWrapper => {
|
|
1428
|
+
const oldAnnotationWrapper = contentWrapper.selectAll('.vertical-annotation-wrapper');
|
|
1415
1429
|
oldAnnotationWrapper.node() && oldAnnotationWrapper.node().remove();
|
|
1416
1430
|
};
|
|
1417
|
-
this.addVerticalAnnotation = (
|
|
1431
|
+
this.addVerticalAnnotation = (contentWrapper, minDistanceItem, theme) => {
|
|
1418
1432
|
const {
|
|
1419
1433
|
height: chartHeight,
|
|
1420
1434
|
insertPadding,
|
|
1421
1435
|
marginTop
|
|
1422
1436
|
} = this.chartBoundingClientRect;
|
|
1423
1437
|
const {
|
|
1424
|
-
x
|
|
1438
|
+
x,
|
|
1439
|
+
y
|
|
1425
1440
|
} = minDistanceItem;
|
|
1426
|
-
|
|
1441
|
+
const annotationWrapper = contentWrapper.insert('g', ':first-child').attr('class', 'vertical-annotation-wrapper');
|
|
1442
|
+
annotationWrapper.append('line').attr('x1', x).attr('y1', insertPadding + marginTop).attr('x2', x).attr('y2', chartHeight - insertPadding).attr('stroke', theme.XAxisColor);
|
|
1427
1443
|
};
|
|
1428
1444
|
this.initLabelStroke(props === null || props === void 0 ? void 0 : props.globalTheme);
|
|
1429
1445
|
this.chartBoundingClientRect = {};
|
|
@@ -27,6 +27,7 @@ var _area = _interopRequireDefault(require("./area"));
|
|
|
27
27
|
var _areaGroup = _interopRequireDefault(require("./area-group"));
|
|
28
28
|
var _pie = _interopRequireDefault(require("./pie"));
|
|
29
29
|
var _ring = _interopRequireDefault(require("./ring"));
|
|
30
|
+
var _scatter = _interopRequireDefault(require("./scatter"));
|
|
30
31
|
var _basicNumberCard = _interopRequireDefault(require("./basic-number-card"));
|
|
31
32
|
var _trend = _interopRequireDefault(require("./trend"));
|
|
32
33
|
var _tableElement = _interopRequireDefault(require("./table-element"));
|
|
@@ -237,6 +238,12 @@ const Wrapper = _ref => {
|
|
|
237
238
|
canvasStyle: canvasStyle
|
|
238
239
|
}));
|
|
239
240
|
}
|
|
241
|
+
case _constants.CHART_TYPE.SCATTER:
|
|
242
|
+
{
|
|
243
|
+
return /*#__PURE__*/_react.default.createElement(_scatter.default, Object.assign({}, baseProps, {
|
|
244
|
+
canvasStyle: canvasStyle
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
240
247
|
case _constants.CHART_TYPE.BASIC_NUMBER_CARD:
|
|
241
248
|
{
|
|
242
249
|
return /*#__PURE__*/_react.default.createElement(_basicNumberCard.default, Object.assign({}, baseProps, {
|
|
@@ -56,7 +56,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
56
56
|
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
57
57
|
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
58
58
|
};
|
|
59
|
-
this.showTooltip = (event, data,
|
|
59
|
+
this.showTooltip = (event, data, contentWrapper) => {
|
|
60
60
|
const {
|
|
61
61
|
offsetX,
|
|
62
62
|
offsetY
|
|
@@ -64,7 +64,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
64
64
|
const {
|
|
65
65
|
title,
|
|
66
66
|
items
|
|
67
|
-
} = this.getTooltipItems(data,
|
|
67
|
+
} = this.getTooltipItems(data, contentWrapper);
|
|
68
68
|
const newTooltipData = {
|
|
69
69
|
title,
|
|
70
70
|
items
|
|
@@ -79,7 +79,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
-
this.moveTooltip = (event, data,
|
|
82
|
+
this.moveTooltip = (event, data, contentWrapper) => {
|
|
83
83
|
const {
|
|
84
84
|
offsetX,
|
|
85
85
|
offsetY
|
|
@@ -87,7 +87,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
87
87
|
const {
|
|
88
88
|
title,
|
|
89
89
|
items
|
|
90
|
-
} = this.getTooltipItems(data,
|
|
90
|
+
} = this.getTooltipItems(data, contentWrapper);
|
|
91
91
|
const newTooltipData = {
|
|
92
92
|
title,
|
|
93
93
|
items
|
|
@@ -107,8 +107,8 @@ class LineGroup extends _chartComponent.default {
|
|
|
107
107
|
toolTipPosition: null
|
|
108
108
|
});
|
|
109
109
|
};
|
|
110
|
-
this.getTooltipItems = (data,
|
|
111
|
-
var
|
|
110
|
+
this.getTooltipItems = (data, contentWrapper) => {
|
|
111
|
+
var _contentWrapper$selec;
|
|
112
112
|
const {
|
|
113
113
|
summaryColumn,
|
|
114
114
|
chart
|
|
@@ -117,7 +117,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
117
117
|
y_axis_summary_method
|
|
118
118
|
} = chart.config;
|
|
119
119
|
const title = !data.name && typeof data.name !== 'number' ? _intl.default.get(_constants.EMPTY_NAME) : data.name;
|
|
120
|
-
const circleList = (
|
|
120
|
+
const circleList = (_contentWrapper$selec = contentWrapper.selectAll('circle')) === null || _contentWrapper$selec === void 0 ? void 0 : _contentWrapper$selec.nodes();
|
|
121
121
|
const items = circleList.filter(circle => circle.getAttribute('data-name') === title).map(circle => {
|
|
122
122
|
return {
|
|
123
123
|
color: this.colorMap[circle.getAttribute('data-groupName')],
|
|
@@ -166,12 +166,12 @@ class LineGroup extends _chartComponent.default {
|
|
|
166
166
|
// Y axis
|
|
167
167
|
const niceEnd = d3.nice(0, d3.max(data, d => d.value), 5)[1];
|
|
168
168
|
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min || 0, y_axis_max || niceEnd]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
169
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
169
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
170
170
|
|
|
171
171
|
// X axis
|
|
172
172
|
const xDomain = data.map(item => item.name);
|
|
173
173
|
const x = d3.scaleBand().domain(xDomain).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
|
|
174
|
-
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
174
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
175
175
|
this.ticksAddName(g);
|
|
176
176
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
177
177
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
@@ -181,7 +181,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
// Line
|
|
184
|
-
const
|
|
184
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper');
|
|
185
185
|
const circleDatas = [];
|
|
186
186
|
const groupData = d3.groups(data, d => d.group_name);
|
|
187
187
|
groupData.forEach(item => {
|
|
@@ -199,7 +199,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
199
199
|
}).curve(line_type === _constants.CHART_LINE_TYPES[1] ? d3.curveBumpX : d3.curveLinear);
|
|
200
200
|
const group_name = item[0];
|
|
201
201
|
const data = item[1];
|
|
202
|
-
|
|
202
|
+
contentWrapper.append('path').attr('fill', 'none').attr('stroke', this.colorMap[group_name]).attr('stroke-width', 2).attr('d', () => line(data));
|
|
203
203
|
circleDatas.push({
|
|
204
204
|
group_name,
|
|
205
205
|
circleData
|
|
@@ -214,11 +214,11 @@ class LineGroup extends _chartComponent.default {
|
|
|
214
214
|
} = _ref;
|
|
215
215
|
circleData.forEach(item => {
|
|
216
216
|
if (Object.keys(item).length > 0) {
|
|
217
|
-
|
|
217
|
+
contentWrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', this.colorMap[group_name]).attr('opacity', y_axis_show_value ? 1 : 0).attr('data-groupName', group_name).attr('data-text', item.value).attr('data-name', item.name).call(g => {
|
|
218
218
|
// circle label
|
|
219
219
|
if (y_axis_show_value) {
|
|
220
220
|
const curCircleEl = g.node();
|
|
221
|
-
|
|
221
|
+
contentWrapper.append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(_utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(curCircleEl.getAttribute('data-text')), y_axis_summary_method)).call(g => {
|
|
222
222
|
const {
|
|
223
223
|
width
|
|
224
224
|
} = g.node().getBoundingClientRect();
|
|
@@ -238,7 +238,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
238
238
|
event,
|
|
239
239
|
state: 'zoomIn',
|
|
240
240
|
circleDatas,
|
|
241
|
-
|
|
241
|
+
contentWrapper,
|
|
242
242
|
eventState: 'over'
|
|
243
243
|
});
|
|
244
244
|
}).on('mousemove', event => {
|
|
@@ -246,7 +246,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
246
246
|
event,
|
|
247
247
|
state: 'zoomIn',
|
|
248
248
|
circleDatas,
|
|
249
|
-
|
|
249
|
+
contentWrapper,
|
|
250
250
|
eventState: 'move'
|
|
251
251
|
});
|
|
252
252
|
}).on('mouseleave', event => {
|
|
@@ -254,7 +254,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
254
254
|
event,
|
|
255
255
|
state: 'zoomOut',
|
|
256
256
|
circleDatas,
|
|
257
|
-
|
|
257
|
+
contentWrapper,
|
|
258
258
|
eventState: 'leave'
|
|
259
259
|
});
|
|
260
260
|
});
|
|
@@ -271,12 +271,12 @@ class LineGroup extends _chartComponent.default {
|
|
|
271
271
|
});
|
|
272
272
|
};
|
|
273
273
|
this.updateCircleAndTickStyle = _ref2 => {
|
|
274
|
-
var
|
|
274
|
+
var _contentWrapper$selec2;
|
|
275
275
|
let {
|
|
276
276
|
event,
|
|
277
277
|
state,
|
|
278
278
|
circleDatas,
|
|
279
|
-
|
|
279
|
+
contentWrapper,
|
|
280
280
|
eventState
|
|
281
281
|
} = _ref2;
|
|
282
282
|
const {
|
|
@@ -300,7 +300,7 @@ class LineGroup extends _chartComponent.default {
|
|
|
300
300
|
});
|
|
301
301
|
const minIndex = d3.minIndex(minDistanceArr, d => d.distance);
|
|
302
302
|
const minDistanceItem = minDistanceArr[minIndex];
|
|
303
|
-
const circleList = (
|
|
303
|
+
const circleList = (_contentWrapper$selec2 = contentWrapper.selectAll('circle')) === null || _contentWrapper$selec2 === void 0 ? void 0 : _contentWrapper$selec2.nodes();
|
|
304
304
|
if (state === 'zoomIn') {
|
|
305
305
|
// circle
|
|
306
306
|
circleList && circleList.forEach(circle => {
|
|
@@ -309,14 +309,14 @@ class LineGroup extends _chartComponent.default {
|
|
|
309
309
|
d3.select(circle).attr('opacity', 1);
|
|
310
310
|
d3.select(circle).attr('r', 5);
|
|
311
311
|
} else {
|
|
312
|
-
d3.select(circle).attr('opacity', 0);
|
|
312
|
+
!y_axis_show_value && d3.select(circle).attr('opacity', 0);
|
|
313
313
|
d3.select(circle).attr('r', 3);
|
|
314
314
|
}
|
|
315
315
|
});
|
|
316
316
|
// line
|
|
317
317
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
318
|
-
this.clearOldVerticalAnnotation(
|
|
319
|
-
this.addVerticalAnnotation(
|
|
318
|
+
this.clearOldVerticalAnnotation(contentWrapper);
|
|
319
|
+
this.addVerticalAnnotation(contentWrapper, minDistanceItem, theme);
|
|
320
320
|
} else {
|
|
321
321
|
// circle
|
|
322
322
|
circleList && circleList.forEach(circle => {
|
|
@@ -324,15 +324,15 @@ class LineGroup extends _chartComponent.default {
|
|
|
324
324
|
d3.select(circle).attr('r', 3);
|
|
325
325
|
});
|
|
326
326
|
// line
|
|
327
|
-
this.clearOldVerticalAnnotation(
|
|
327
|
+
this.clearOldVerticalAnnotation(contentWrapper);
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
// tooltip
|
|
331
331
|
if (eventState === 'over') {
|
|
332
|
-
this.showTooltip(event, minDistanceItem,
|
|
332
|
+
this.showTooltip(event, minDistanceItem, contentWrapper);
|
|
333
333
|
}
|
|
334
334
|
if (eventState === 'move') {
|
|
335
|
-
this.moveTooltip(event, minDistanceItem,
|
|
335
|
+
this.moveTooltip(event, minDistanceItem, contentWrapper);
|
|
336
336
|
}
|
|
337
337
|
if (eventState === 'leave') {
|
|
338
338
|
this.hiddenTooltip();
|
|
@@ -157,12 +157,12 @@ class Line extends _chartComponent.default {
|
|
|
157
157
|
// Y axis
|
|
158
158
|
const niceEnd = d3.nice(0, d3.max(data, d => d.value), 5)[1];
|
|
159
159
|
const y = d3.scaleLinear().domain(y_axis_auto_range ? [0, niceEnd] : [y_axis_min || 0, y_axis_max || niceEnd]).range([chartHeight - insertPadding, insertPadding + marginTop]);
|
|
160
|
-
this.chart.append('g').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
160
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => _utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, d, y_axis_summary_method))).call(g => this.drawYaxis(g, theme));
|
|
161
161
|
|
|
162
162
|
// X axis
|
|
163
163
|
const xDomain = data.map(item => item.name);
|
|
164
164
|
const x = d3.scaleBand().domain(xDomain).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]).paddingInner(0.4).paddingOuter(0.1);
|
|
165
|
-
this.chart.append('g').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
165
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5)).call(g => {
|
|
166
166
|
this.ticksAddName(g);
|
|
167
167
|
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
168
168
|
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
@@ -184,16 +184,16 @@ class Line extends _chartComponent.default {
|
|
|
184
184
|
circleData[index]['value'] = d.value;
|
|
185
185
|
return yVal;
|
|
186
186
|
}).curve(line_type === _constants.CHART_LINE_TYPES[1] ? d3.curveBumpX : d3.curveLinear);
|
|
187
|
-
const
|
|
188
|
-
|
|
187
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper');
|
|
188
|
+
contentWrapper.append('path').attr('fill', 'none').attr('stroke', chartBarColor).attr('stroke-width', 2).attr('d', () => line(data));
|
|
189
189
|
|
|
190
190
|
// circle
|
|
191
191
|
circleData.forEach(item => {
|
|
192
|
-
|
|
192
|
+
contentWrapper.append('circle').attr('cx', item.x).attr('cy', item.y).attr('r', 3).attr('fill', chartBarColor).attr('opacity', y_axis_show_value ? 1 : 0).attr('data-text', item.value).attr('data-name', item.name).call(g => {
|
|
193
193
|
// circle label
|
|
194
194
|
if (y_axis_show_value) {
|
|
195
195
|
const curCircleEl = g.node();
|
|
196
|
-
|
|
196
|
+
contentWrapper.append('text').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('fill', theme.labelColor).attr('font-size', _utils.BaseUtils.getLabelFontSize(label_font_size)).text(_utils.BaseUtils.getSummaryValueDisplayString(summaryColumn, Number(curCircleEl.getAttribute('data-text')), y_axis_summary_method)).call(g => {
|
|
197
197
|
const {
|
|
198
198
|
width
|
|
199
199
|
} = g.node().getBoundingClientRect();
|
|
@@ -211,7 +211,7 @@ class Line extends _chartComponent.default {
|
|
|
211
211
|
event,
|
|
212
212
|
state: 'zoomIn',
|
|
213
213
|
circleData,
|
|
214
|
-
|
|
214
|
+
contentWrapper,
|
|
215
215
|
eventState: 'over',
|
|
216
216
|
tooltipTitle
|
|
217
217
|
});
|
|
@@ -220,7 +220,7 @@ class Line extends _chartComponent.default {
|
|
|
220
220
|
event,
|
|
221
221
|
state: 'zoomIn',
|
|
222
222
|
circleData,
|
|
223
|
-
|
|
223
|
+
contentWrapper,
|
|
224
224
|
eventState: 'move',
|
|
225
225
|
tooltipTitle
|
|
226
226
|
});
|
|
@@ -229,7 +229,7 @@ class Line extends _chartComponent.default {
|
|
|
229
229
|
event,
|
|
230
230
|
state: 'zoomOut',
|
|
231
231
|
circleData,
|
|
232
|
-
|
|
232
|
+
contentWrapper,
|
|
233
233
|
eventState: 'leave',
|
|
234
234
|
tooltipTitle
|
|
235
235
|
});
|
|
@@ -239,12 +239,12 @@ class Line extends _chartComponent.default {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
this.updateCircleAndTickStyle = _ref => {
|
|
242
|
-
var
|
|
242
|
+
var _contentWrapper$selec;
|
|
243
243
|
let {
|
|
244
244
|
event,
|
|
245
245
|
state,
|
|
246
246
|
circleData,
|
|
247
|
-
|
|
247
|
+
contentWrapper,
|
|
248
248
|
eventState,
|
|
249
249
|
tooltipTitle
|
|
250
250
|
} = _ref;
|
|
@@ -259,7 +259,7 @@ class Line extends _chartComponent.default {
|
|
|
259
259
|
offsetX
|
|
260
260
|
} = event;
|
|
261
261
|
const minDistanceItem = this.getMinDistanceItem(offsetX, circleData);
|
|
262
|
-
const circleList = (
|
|
262
|
+
const circleList = (_contentWrapper$selec = contentWrapper.selectAll('circle')) === null || _contentWrapper$selec === void 0 ? void 0 : _contentWrapper$selec.nodes();
|
|
263
263
|
if (state === 'zoomIn') {
|
|
264
264
|
// circle
|
|
265
265
|
circleList && circleList.forEach(circle => {
|
|
@@ -268,14 +268,14 @@ class Line extends _chartComponent.default {
|
|
|
268
268
|
d3.select(circle).attr('opacity', 1);
|
|
269
269
|
d3.select(circle).attr('r', 5);
|
|
270
270
|
} else {
|
|
271
|
-
d3.select(circle).attr('opacity', 0);
|
|
271
|
+
!y_axis_show_value && d3.select(circle).attr('opacity', 0);
|
|
272
272
|
d3.select(circle).attr('r', 3);
|
|
273
273
|
}
|
|
274
274
|
});
|
|
275
275
|
// line
|
|
276
276
|
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
277
|
-
this.clearOldVerticalAnnotation(
|
|
278
|
-
this.addVerticalAnnotation(
|
|
277
|
+
this.clearOldVerticalAnnotation(contentWrapper);
|
|
278
|
+
this.addVerticalAnnotation(contentWrapper, minDistanceItem, theme);
|
|
279
279
|
} else {
|
|
280
280
|
// circle
|
|
281
281
|
circleList && circleList.forEach(circle => {
|
|
@@ -283,7 +283,7 @@ class Line extends _chartComponent.default {
|
|
|
283
283
|
d3.select(circle).attr('r', 3);
|
|
284
284
|
});
|
|
285
285
|
// line
|
|
286
|
-
this.clearOldVerticalAnnotation(
|
|
286
|
+
this.clearOldVerticalAnnotation(contentWrapper);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// tooltip
|
package/dist/view/wrapper/pie.js
CHANGED
|
@@ -86,7 +86,7 @@ class Pie extends _chartComponent.default {
|
|
|
86
86
|
const arc = d3.arc().innerRadius(0).outerRadius(Math.min(chartWidth, chartHeight) / 2 * 0.7);
|
|
87
87
|
|
|
88
88
|
// Draw Pie
|
|
89
|
-
this.chart.append('g').attr('
|
|
89
|
+
this.chart.append('g').attr('class', 'content-wrapper').attr('stroke', 'white').selectAll().data(arcs).join('path').attr('stroke-width', 2).attr('opacity', 1).attr('fill', d => color(d.data.name)).attr('d', arc).attr('data-groupName', d => d.data.name).call(g => {
|
|
90
90
|
var _g$node$parentNode;
|
|
91
91
|
const {
|
|
92
92
|
width,
|
|
@@ -185,7 +185,7 @@ class Pie extends _chartComponent.default {
|
|
|
185
185
|
this.handleAcitveAndInActiveState = (state, event) => {
|
|
186
186
|
const allGroup = [event.currentTarget.parentNode];
|
|
187
187
|
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
188
|
-
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
188
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName, _constants.CHART_TYPE.PIE);
|
|
189
189
|
};
|
|
190
190
|
this.getLabel = (val, percent) => {
|
|
191
191
|
const {
|
|
@@ -87,7 +87,7 @@ class Ring extends _chartComponent.default {
|
|
|
87
87
|
const arc = d3.arc().innerRadius(Math.min(chartWidth, chartHeight) / 2 * 0.7).outerRadius(Math.min(chartWidth, chartHeight) / 2 * 0.5);
|
|
88
88
|
|
|
89
89
|
// Draw Ring
|
|
90
|
-
this.chart.append('g').selectAll().data(arcs).join('path').attr('stroke', 'white').attr('stroke-width', 2).attr('fill', d => color(d.data.name)).attr('d', arc).attr('data-groupName', d => d.data.name).call(g => {
|
|
90
|
+
this.chart.append('g').attr('class', 'content-wrapper').selectAll().data(arcs).join('path').attr('stroke', 'white').attr('stroke-width', 2).attr('opacity', 1).attr('fill', d => color(d.data.name)).attr('d', arc).attr('data-groupName', d => d.data.name).call(g => {
|
|
91
91
|
var _g$node$parentNode;
|
|
92
92
|
const {
|
|
93
93
|
width,
|
|
@@ -108,7 +108,7 @@ class Ring extends _chartComponent.default {
|
|
|
108
108
|
if (display_label) {
|
|
109
109
|
const labelRadius = this.isInnerLabel ? arc.outerRadius()() * 1.2 : arc.outerRadius()() * 1.65;
|
|
110
110
|
const arcLabel = d3.arc().innerRadius(labelRadius).outerRadius(labelRadius);
|
|
111
|
-
this.chart.append('g').attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")")).attr('text-anchor', 'middle').selectAll().data(arcs).join('text').attr('class', 'label').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('transform', d => "translate(".concat(arcLabel.centroid(d), ")")).text(d => {
|
|
111
|
+
this.chart.append('g').attr('class', 'label-wrapper').attr('transform', "translate(".concat(left + offsetX, ", ").concat(top + offsetY, ")")).attr('text-anchor', 'middle').selectAll().data(arcs).join('text').attr('class', 'label').attr('stroke', '#fff').attr('stroke-width', 1).attr('paint-order', 'stroke').attr('transform', d => "translate(".concat(arcLabel.centroid(d), ")")).text(d => {
|
|
112
112
|
const {
|
|
113
113
|
value,
|
|
114
114
|
percent
|
|
@@ -199,7 +199,7 @@ class Ring extends _chartComponent.default {
|
|
|
199
199
|
this.handleAcitveAndInActiveState = (state, event) => {
|
|
200
200
|
const allGroup = [event.currentTarget.parentNode];
|
|
201
201
|
const curGroupName = event.currentTarget.getAttribute('data-groupName');
|
|
202
|
-
this.setActiveAndInActiveState(state, allGroup, curGroupName);
|
|
202
|
+
this.setActiveAndInActiveState(state, allGroup, curGroupName, _constants.CHART_TYPE.RING);
|
|
203
203
|
};
|
|
204
204
|
this.getLabel = (val, percent) => {
|
|
205
205
|
const {
|
|
@@ -0,0 +1,335 @@
|
|
|
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 _lodashEs = require("lodash-es");
|
|
12
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
13
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
|
+
var _dtableUtils = require("dtable-utils");
|
|
15
|
+
var _constants = require("../../constants");
|
|
16
|
+
var _utils = require("../../utils");
|
|
17
|
+
var _intl = _interopRequireDefault(require("../../intl"));
|
|
18
|
+
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
19
|
+
var _chartComponent = _interopRequireDefault(require("./chart-component"));
|
|
20
|
+
class Scatter extends _chartComponent.default {
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
this.handleResize = () => {
|
|
24
|
+
this.chart.node() && this.chart.node().remove();
|
|
25
|
+
this.createChart();
|
|
26
|
+
this.drawChart();
|
|
27
|
+
};
|
|
28
|
+
this.createChart = () => {
|
|
29
|
+
const {
|
|
30
|
+
chart,
|
|
31
|
+
columnGroupbyColumn
|
|
32
|
+
} = this.props;
|
|
33
|
+
const {
|
|
34
|
+
y_axis_show_label,
|
|
35
|
+
x_axis_show_label,
|
|
36
|
+
y_axis_show_value
|
|
37
|
+
} = chart.config;
|
|
38
|
+
const initConfig = {
|
|
39
|
+
insertPadding: 30,
|
|
40
|
+
marginLeft: y_axis_show_label ? 20 : 0,
|
|
41
|
+
marginBottom: x_axis_show_label ? 20 : 0,
|
|
42
|
+
marginTop: y_axis_show_value ? 15 : 0,
|
|
43
|
+
bottomLegendSpace: columnGroupbyColumn ? 20 : 0
|
|
44
|
+
};
|
|
45
|
+
this.initChart(this.container, chart === null || chart === void 0 ? void 0 : chart.id, initConfig);
|
|
46
|
+
};
|
|
47
|
+
this.drawChart = () => {
|
|
48
|
+
const {
|
|
49
|
+
customRender
|
|
50
|
+
} = this.props;
|
|
51
|
+
let {
|
|
52
|
+
result: data
|
|
53
|
+
} = this.props;
|
|
54
|
+
data = _utils.BaseUtils.formatEmptyName(data, '', _intl.default.get('Empty'));
|
|
55
|
+
if (!Array.isArray(data)) return;
|
|
56
|
+
data = this.transformStringToNumber(data);
|
|
57
|
+
this.draw(data);
|
|
58
|
+
this.renderAxisLabel(this.props.chart, this.props.tables, this.container);
|
|
59
|
+
(0, _utils.isFunction)(customRender) && customRender(this.chart);
|
|
60
|
+
};
|
|
61
|
+
this.transformStringToNumber = data => {
|
|
62
|
+
const newData = (0, _lodashEs.cloneDeep)(data);
|
|
63
|
+
newData.forEach(item => {
|
|
64
|
+
item.name = item.original_value.name;
|
|
65
|
+
item.value = item.original_value.value;
|
|
66
|
+
});
|
|
67
|
+
return newData;
|
|
68
|
+
};
|
|
69
|
+
this.getFillColor = data => {
|
|
70
|
+
const {
|
|
71
|
+
chartColorTheme
|
|
72
|
+
} = this.props;
|
|
73
|
+
let currentIdx = 0;
|
|
74
|
+
let colors = _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors;
|
|
75
|
+
const colorMap = data.reduce((acc, cur) => {
|
|
76
|
+
if (cur.groupby && !acc[cur.groupby]) {
|
|
77
|
+
acc[cur.groupby] = colors[currentIdx++ % colors.length];
|
|
78
|
+
}
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
return colorMap;
|
|
82
|
+
};
|
|
83
|
+
this.showTooltip = (event, data, selectedXAxisColumn, selectedYAxisColumn) => {
|
|
84
|
+
const {
|
|
85
|
+
groupby,
|
|
86
|
+
name,
|
|
87
|
+
value
|
|
88
|
+
} = data;
|
|
89
|
+
const {
|
|
90
|
+
offsetX,
|
|
91
|
+
offsetY
|
|
92
|
+
} = event;
|
|
93
|
+
const newTooltipData = {
|
|
94
|
+
titleMarkColor: event.currentTarget.getAttribute('fill'),
|
|
95
|
+
title: groupby || groupby === 0 ? groupby : _intl.default.get('Empty'),
|
|
96
|
+
items: [{
|
|
97
|
+
name: selectedXAxisColumn.name,
|
|
98
|
+
value: name
|
|
99
|
+
}, {
|
|
100
|
+
name: selectedYAxisColumn.name,
|
|
101
|
+
value: value
|
|
102
|
+
}]
|
|
103
|
+
};
|
|
104
|
+
this.setState({
|
|
105
|
+
tooltipData: newTooltipData
|
|
106
|
+
});
|
|
107
|
+
this.setState({
|
|
108
|
+
toolTipPosition: {
|
|
109
|
+
offsetX,
|
|
110
|
+
offsetY
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
this.moveTooltip = event => {
|
|
115
|
+
const {
|
|
116
|
+
offsetX,
|
|
117
|
+
offsetY
|
|
118
|
+
} = event;
|
|
119
|
+
this.setState({
|
|
120
|
+
toolTipPosition: {
|
|
121
|
+
offsetX,
|
|
122
|
+
offsetY
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
this.hiddenTooltip = event => {
|
|
127
|
+
this.setState({
|
|
128
|
+
toolTipPosition: null
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
this.handleAcitveAndInActiveState = (state, event) => {
|
|
132
|
+
const {
|
|
133
|
+
globalTheme
|
|
134
|
+
} = this.props;
|
|
135
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
136
|
+
const contentWrapper = event.currentTarget.parentNode;
|
|
137
|
+
|
|
138
|
+
// Remove old mark line wrapper
|
|
139
|
+
const markLineWrapper = d3.select(contentWrapper).select('.mark-line-wrapper');
|
|
140
|
+
markLineWrapper.node() && markLineWrapper.node().remove();
|
|
141
|
+
if (state === 'inActive') {
|
|
142
|
+
// Remove stroke
|
|
143
|
+
d3.select(event.currentTarget).attr('stroke', '').attr('storke-width', '');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (state === 'active') {
|
|
147
|
+
const {
|
|
148
|
+
width: chartWidth,
|
|
149
|
+
height: chartHeight,
|
|
150
|
+
insertPadding,
|
|
151
|
+
marginTop,
|
|
152
|
+
bottomLegendSpace
|
|
153
|
+
} = this.chartBoundingClientRect;
|
|
154
|
+
const x = Number(event.currentTarget.getAttribute('data-x'));
|
|
155
|
+
const y = Number(event.currentTarget.getAttribute('data-y'));
|
|
156
|
+
const r = Number(event.currentTarget.getAttribute('r'));
|
|
157
|
+
|
|
158
|
+
// Add stroke and shadow
|
|
159
|
+
d3.select(event.currentTarget).attr('stroke', 'white').attr('stroke-width', 1.5).attr('style', 'filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.1));');
|
|
160
|
+
const markLineWrapper = d3.select(contentWrapper).append('g').attr('class', 'mark-line-wrapper');
|
|
161
|
+
// X axis
|
|
162
|
+
if (x - r >= insertPadding) {
|
|
163
|
+
// The length of the line must be a positive number
|
|
164
|
+
markLineWrapper.append('line').attr('x1', insertPadding).attr('y1', y).attr('x2', x - r).attr('y2', y).attr('stroke', theme.XAxisColor);
|
|
165
|
+
}
|
|
166
|
+
if (chartWidth - insertPadding >= x + r) {
|
|
167
|
+
// The length of the line must be a positive number
|
|
168
|
+
markLineWrapper.append('line').attr('x1', x + r).attr('y1', y).attr('x2', chartWidth - insertPadding).attr('y2', y).attr('stroke', theme.XAxisColor);
|
|
169
|
+
}
|
|
170
|
+
// Y axis
|
|
171
|
+
if (y - r >= insertPadding) {
|
|
172
|
+
// The length of the line must be a positive number
|
|
173
|
+
markLineWrapper.append('line').attr('x1', x).attr('y1', insertPadding + marginTop).attr('x2', x).attr('y2', y - r).attr('stroke', theme.XAxisColor);
|
|
174
|
+
}
|
|
175
|
+
if (chartHeight - insertPadding >= y + r) {
|
|
176
|
+
// The length of the line must be a positive number
|
|
177
|
+
markLineWrapper.append('line').attr('x1', x).attr('y1', y + r).attr('x2', x).attr('y2', chartHeight - insertPadding - bottomLegendSpace).attr('stroke', theme.XAxisColor);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
this.draw = data => {
|
|
182
|
+
const {
|
|
183
|
+
chart,
|
|
184
|
+
globalTheme,
|
|
185
|
+
tables,
|
|
186
|
+
chartColorTheme
|
|
187
|
+
} = this.props;
|
|
188
|
+
const theme = _constants.CHART_THEME_COLOR[globalTheme];
|
|
189
|
+
const {
|
|
190
|
+
label_font_size,
|
|
191
|
+
x_axis_column_key,
|
|
192
|
+
y_axis_column_key,
|
|
193
|
+
table_id,
|
|
194
|
+
y_axis_show_value,
|
|
195
|
+
y_axis_max,
|
|
196
|
+
y_axis_min,
|
|
197
|
+
y_axis_auto_range
|
|
198
|
+
} = chart.config;
|
|
199
|
+
const {
|
|
200
|
+
width: chartWidth,
|
|
201
|
+
height: chartHeight,
|
|
202
|
+
insertPadding,
|
|
203
|
+
marginTop,
|
|
204
|
+
bottomLegendSpace
|
|
205
|
+
} = this.chartBoundingClientRect;
|
|
206
|
+
const colorMap = this.getFillColor(data);
|
|
207
|
+
const selectedTable = (0, _dtableUtils.getTableById)(tables, table_id);
|
|
208
|
+
const selectedXAxisColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column_key);
|
|
209
|
+
const selectedYAxisColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_column_key);
|
|
210
|
+
|
|
211
|
+
// Y axis
|
|
212
|
+
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 - bottomLegendSpace, insertPadding + marginTop]);
|
|
213
|
+
this.chart.append('g').attr('class', 'y-axis-wrapper').attr('transform', "translate(".concat(insertPadding, ", 0)")).call(d3.axisLeft(y).tickSizeInner(0).ticks(5).tickFormat(d => d)).call(g => this.drawYaxis(g, theme));
|
|
214
|
+
|
|
215
|
+
// X axis
|
|
216
|
+
const niceEnd = d3.nice(0, d3.max(data, d => d.name), 5)[1];
|
|
217
|
+
const x = d3.scaleLinear().domain([0, niceEnd]).range([insertPadding + this.horizontalOverflowOffset, chartWidth - insertPadding]);
|
|
218
|
+
this.chart.append('g').attr('class', 'x-axis-wrapper').attr('transform', "translate(0, ".concat(chartHeight - insertPadding - bottomLegendSpace, ")")).call(d3.axisBottom(x).tickSizeOuter(0).tickSizeInner(5).ticks(5).tickFormat(d => d)).call(g => {
|
|
219
|
+
g.selectAll('.domain').attr('stroke', theme.XAxisColor);
|
|
220
|
+
g.selectAll('.tick line').attr('stroke', theme.XAxisColor);
|
|
221
|
+
g.selectAll('text').attr('font-size', theme.fontSize);
|
|
222
|
+
g.selectAll('text').attr('fill', theme.textColor);
|
|
223
|
+
const allLineNode = g.selectAll('line').nodes();
|
|
224
|
+
if (Array.isArray(allLineNode)) {
|
|
225
|
+
// delete the first line and last line
|
|
226
|
+
allLineNode[0] && allLineNode[0].remove();
|
|
227
|
+
allLineNode[allLineNode.length - 1] && allLineNode[allLineNode.length - 1].remove();
|
|
228
|
+
}
|
|
229
|
+
this.checkTickOverlap(g);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Circle
|
|
233
|
+
const contentWrapper = this.chart.append('g').attr('class', 'content-wrapper');
|
|
234
|
+
contentWrapper.selectAll().data(data).join('circle').attr('fill', d => {
|
|
235
|
+
const {
|
|
236
|
+
groupby
|
|
237
|
+
} = d;
|
|
238
|
+
if (groupby && groupby[0] === 'groupby') {
|
|
239
|
+
return _utils.BaseUtils.getCurrentTheme(chartColorTheme).colors[0];
|
|
240
|
+
}
|
|
241
|
+
return colorMap[d.groupby];
|
|
242
|
+
}).attr('data-x', d => x(d.name)).attr('data-y', d => y(d.value)).attr('data-value', d => d.value).attr('data-width', 3.5).attr('data-groupName', d => d.name).attr('cx', d => x(d.name)).attr('cy', d => y(d.value)).attr('r', 3.5).attr('opacity', 0.85).call(g => {
|
|
243
|
+
g.nodes().forEach(path => {
|
|
244
|
+
// Add label
|
|
245
|
+
if (y_axis_show_value) {
|
|
246
|
+
this.addLabelToRectTop({
|
|
247
|
+
container: contentWrapper.node(),
|
|
248
|
+
xWidth: Number(path.dataset.width),
|
|
249
|
+
x: Number(path.dataset.x),
|
|
250
|
+
y: Number(path.dataset.y),
|
|
251
|
+
theme,
|
|
252
|
+
label_font_size,
|
|
253
|
+
text: path.dataset.value
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}).on('click', (event, data) => {
|
|
258
|
+
this.props.toggleRecords(data);
|
|
259
|
+
}).on('mouseover', (event, data) => {
|
|
260
|
+
this.showTooltip(event, data, selectedXAxisColumn, selectedYAxisColumn);
|
|
261
|
+
this.handleAcitveAndInActiveState('active', event);
|
|
262
|
+
}).on('mousemove', (event, data) => {
|
|
263
|
+
this.moveTooltip(event, data, selectedXAxisColumn, selectedYAxisColumn);
|
|
264
|
+
}).on('mouseleave', (event, data) => {
|
|
265
|
+
this.hiddenTooltip();
|
|
266
|
+
this.handleAcitveAndInActiveState('inActive', event);
|
|
267
|
+
});
|
|
268
|
+
this.setLegend({
|
|
269
|
+
legendName: 'groupby',
|
|
270
|
+
theme,
|
|
271
|
+
legendPosition: 'top-right',
|
|
272
|
+
data,
|
|
273
|
+
groupColumn: this.props.columnGroupbyColumn,
|
|
274
|
+
chart,
|
|
275
|
+
colorScale: key => colorMap[key]
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
this.chart = null;
|
|
279
|
+
this.state = {
|
|
280
|
+
tooltipData: null,
|
|
281
|
+
toolTipPosition: null
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
componentDidMount() {
|
|
285
|
+
this.createChart();
|
|
286
|
+
this.drawChart();
|
|
287
|
+
this.debouncedHandleResize = (0, _lodashEs.debounce)(this.handleResize, 300);
|
|
288
|
+
window.addEventListener('resize', this.debouncedHandleResize);
|
|
289
|
+
}
|
|
290
|
+
componentDidUpdate(prevProps) {
|
|
291
|
+
super.componentDidUpdate(prevProps);
|
|
292
|
+
if (_utils.BaseUtils.shouldChartComponentUpdate(prevProps, this.props)) {
|
|
293
|
+
this.createChart();
|
|
294
|
+
this.drawChart();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
componentWillUnmount() {
|
|
298
|
+
this.chart.node() && this.chart.node().remove();
|
|
299
|
+
window.removeEventListener('resize', this.debouncedHandleResize);
|
|
300
|
+
}
|
|
301
|
+
render() {
|
|
302
|
+
const {
|
|
303
|
+
chart
|
|
304
|
+
} = this.props;
|
|
305
|
+
const {
|
|
306
|
+
tooltipData,
|
|
307
|
+
toolTipPosition
|
|
308
|
+
} = this.state;
|
|
309
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
310
|
+
ref: ref => this.container = ref,
|
|
311
|
+
className: (0, _classnames.default)('sea-chart-container', {
|
|
312
|
+
'show-x-axis-label': this.isShowXAxisLabel(chart),
|
|
313
|
+
'show-y-axis-label': this.isShowYAxisLabel(chart)
|
|
314
|
+
})
|
|
315
|
+
}, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
316
|
+
tooltipData: tooltipData,
|
|
317
|
+
toolTipPosition: toolTipPosition,
|
|
318
|
+
chart: this.chart
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
Scatter.propTypes = {
|
|
323
|
+
canvasStyle: _propTypes.default.object,
|
|
324
|
+
chart: _propTypes.default.object,
|
|
325
|
+
groupbyColumn: _propTypes.default.object,
|
|
326
|
+
columnGroupbyColumn: _propTypes.default.object,
|
|
327
|
+
summaryColumn: _propTypes.default.object,
|
|
328
|
+
result: _propTypes.default.array,
|
|
329
|
+
tables: _propTypes.default.array,
|
|
330
|
+
globalTheme: _propTypes.default.string,
|
|
331
|
+
chartColorTheme: _propTypes.default.string,
|
|
332
|
+
toggleRecords: _propTypes.default.func,
|
|
333
|
+
customRender: _propTypes.default.func
|
|
334
|
+
};
|
|
335
|
+
var _default = exports.default = Scatter;
|
package/package.json
CHANGED