@easyv/charts 1.8.7 → 1.8.8
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/lib/components/Chart.js
CHANGED
|
@@ -64,7 +64,6 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
64
64
|
active = _useState2[0],
|
|
65
65
|
setActive = _useState2[1];
|
|
66
66
|
var scaleRef = (0, _react.useRef)([1, 1]);
|
|
67
|
-
var domRef = (0, _react.useRef)();
|
|
68
67
|
var triggerOnRelative = (0, _react.useCallback)(function (action, data) {
|
|
69
68
|
if (!interaction) return;
|
|
70
69
|
var callbacks = interaction.callbacks,
|
|
@@ -122,16 +121,12 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
122
121
|
var data = checkData(originData);
|
|
123
122
|
return /*#__PURE__*/_react["default"].createElement(_context.chartContext.Provider, {
|
|
124
123
|
value: context
|
|
125
|
-
}, type == 'pie' ? /*#__PURE__*/_react["default"].createElement("
|
|
126
|
-
ref: domRef
|
|
127
|
-
}, /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
|
|
124
|
+
}, type == 'pie' ? /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
|
|
128
125
|
id: id,
|
|
129
126
|
config: config,
|
|
130
127
|
data: data,
|
|
131
128
|
active: active
|
|
132
|
-
}, props, {
|
|
133
|
-
domRef: domRef
|
|
134
|
-
}))) : /*#__PURE__*/_react["default"].createElement(_.CartesianChart, (0, _extends2["default"])({
|
|
129
|
+
}, props)) : /*#__PURE__*/_react["default"].createElement(_.CartesianChart, (0, _extends2["default"])({
|
|
135
130
|
id: id,
|
|
136
131
|
config: config,
|
|
137
132
|
data: data,
|
|
@@ -232,8 +232,7 @@ var getCircleScale = function getCircleScale() {
|
|
|
232
232
|
}));
|
|
233
233
|
};
|
|
234
234
|
var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
235
|
-
var
|
|
236
|
-
width = _ref5.width,
|
|
235
|
+
var width = _ref5.width,
|
|
237
236
|
height = _ref5.height,
|
|
238
237
|
_ref5$config = _ref5.config,
|
|
239
238
|
_ref5$config$chart = _ref5$config.chart,
|
|
@@ -615,8 +614,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
615
614
|
x: halfChartWidth,
|
|
616
615
|
y: maxRadius + marginTop
|
|
617
616
|
},
|
|
618
|
-
mousePos: mousePos
|
|
619
|
-
domRef: domRef
|
|
617
|
+
mousePos: mousePos
|
|
620
618
|
})), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
|
621
619
|
height: chartHeight,
|
|
622
620
|
series: _arcs.map(function (arc) {
|
|
@@ -780,8 +778,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
780
778
|
x: halfChartWidth,
|
|
781
779
|
y: maxRadius + marginTop
|
|
782
780
|
},
|
|
783
|
-
mousePos: mousePos
|
|
784
|
-
domRef: domRef
|
|
781
|
+
mousePos: mousePos
|
|
785
782
|
})), /*#__PURE__*/_react["default"].createElement(_.Legend, (0, _extends2["default"])({}, legend, {
|
|
786
783
|
height: chartHeight,
|
|
787
784
|
series: _arcs.map(function (arc) {
|
|
@@ -17,7 +17,6 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (props) {
|
|
19
19
|
var mousePos = props.mousePos,
|
|
20
|
-
domRef = props.domRef,
|
|
21
20
|
pieCenter = props.pieCenter,
|
|
22
21
|
_props$config$tip = props.config.tip,
|
|
23
22
|
_props$config$tip$dat = _props$config$tip.data,
|
|
@@ -43,7 +42,6 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
|
|
|
43
42
|
translateTip = _props$config$tip.translate,
|
|
44
43
|
data = props.data,
|
|
45
44
|
series = props.series;
|
|
46
|
-
var screenRef = domRef.current.getBoundingClientRect();
|
|
47
45
|
var Item = function Item() {
|
|
48
46
|
var _data$data = data.data,
|
|
49
47
|
s = _data$data.s,
|
|
@@ -99,84 +97,45 @@ var PieTooltip = exports.PieTooltip = /*#__PURE__*/(0, _react.memo)(function (pr
|
|
|
99
97
|
centerY = pieCenter.y;
|
|
100
98
|
var getTipPos = function getTipPos() {
|
|
101
99
|
var getBigscreenScale = function getBigscreenScale() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
if (window.getScreenScale) {
|
|
101
|
+
return window.getScreenScale();
|
|
102
|
+
} else {
|
|
103
|
+
var bigscreenDom = document.getElementById('bigscreen-container');
|
|
104
|
+
if (!bigscreenDom) return [1, 1];
|
|
105
|
+
var transform = bigscreenDom.style.transform;
|
|
106
|
+
if (!transform) return [1, 1];
|
|
107
|
+
var match = transform.match(/scale\(([^)]+)\)/);
|
|
108
|
+
if (match) {
|
|
109
|
+
var scaleMatch = match[1].split(',');
|
|
110
|
+
var _scaleX = scaleMatch[0];
|
|
111
|
+
var _scaleY = scaleMatch[1];
|
|
112
|
+
if (_scaleY) {
|
|
113
|
+
return [Number(_scaleX), Number(_scaleY)];
|
|
114
|
+
} else {
|
|
115
|
+
return [Number(_scaleX), Number(_scaleX)];
|
|
108
116
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
117
|
+
} else {
|
|
118
|
+
return [1, 1];
|
|
111
119
|
}
|
|
112
120
|
}
|
|
113
|
-
|
|
114
|
-
// 获取容器元素
|
|
115
|
-
var bigscreenDom = document.getElementById('bigscreen-container');
|
|
116
|
-
|
|
117
|
-
// 元素不存在时的处理
|
|
118
|
-
if (!bigscreenDom) {
|
|
119
|
-
console.warn('未找到 bigscreen-container 元素,使用视口尺寸');
|
|
120
|
-
return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 确保元素可见(未被隐藏)
|
|
124
|
-
var isVisible = window.getComputedStyle(bigscreenDom).display !== 'none' && window.getComputedStyle(bigscreenDom).visibility !== 'hidden';
|
|
125
|
-
if (!isVisible) {
|
|
126
|
-
console.warn('bigscreen-container 元素不可见,使用视口尺寸');
|
|
127
|
-
return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 获取元素的布局矩形(最可靠的尺寸获取方式)
|
|
131
|
-
var rect = bigscreenDom.getBoundingClientRect();
|
|
132
|
-
|
|
133
|
-
// 提取基础尺寸(从布局矩形获取,不受样式影响)
|
|
134
|
-
var screenWidth = rect.width || window.innerWidth;
|
|
135
|
-
var screenHeight = rect.height || window.innerHeight;
|
|
136
|
-
var screenLeft = rect.left || 0;
|
|
137
|
-
var screenTop = rect.top || 0;
|
|
138
|
-
|
|
139
|
-
// 处理缩放
|
|
140
|
-
var scaleX = 1;
|
|
141
|
-
var scaleY = 1;
|
|
142
|
-
try {
|
|
143
|
-
var computedStyle = window.getComputedStyle(bigscreenDom);
|
|
144
|
-
var transform = computedStyle.transform;
|
|
145
|
-
if (transform && transform !== 'none') {
|
|
146
|
-
// 解析 transform matrix
|
|
147
|
-
var matrix = new DOMMatrix(transform);
|
|
148
|
-
scaleX = matrix.a; // 缩放X因子
|
|
149
|
-
scaleY = matrix.d; // 缩放Y因子
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
console.error('解析缩放样式出错:', e);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 最终返回值(确保不会有undefined)
|
|
156
|
-
var result = [isNaN(scaleX) ? 1 : scaleX, isNaN(scaleY) ? 1 : scaleY, isNaN(screenWidth) ? window.innerWidth : screenWidth, isNaN(screenHeight) ? window.innerHeight : screenHeight, isNaN(screenLeft) ? 0 : screenLeft, isNaN(screenTop) ? 0 : screenTop];
|
|
157
|
-
return result;
|
|
158
121
|
};
|
|
159
122
|
var _getBigscreenScale = getBigscreenScale(),
|
|
160
|
-
_getBigscreenScale2 = (0, _slicedToArray2["default"])(_getBigscreenScale,
|
|
123
|
+
_getBigscreenScale2 = (0, _slicedToArray2["default"])(_getBigscreenScale, 2),
|
|
161
124
|
scaleX = _getBigscreenScale2[0],
|
|
162
|
-
scaleY = _getBigscreenScale2[1]
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
screenLeft = _getBigscreenScale2[4],
|
|
166
|
-
screenTop = _getBigscreenScale2[5];
|
|
167
|
-
// const _mouseX = mouseX / scaleX
|
|
168
|
-
// const _mouseY = mouseY / scaleY
|
|
125
|
+
scaleY = _getBigscreenScale2[1];
|
|
126
|
+
var _mouseX = mouseX / scaleX;
|
|
127
|
+
var _mouseY = mouseY / scaleY;
|
|
169
128
|
var tipPosMap = {
|
|
170
|
-
rightTop: "translate(".concat(
|
|
171
|
-
leftTop: "translate(".concat(
|
|
172
|
-
leftBottom: "translate(".concat(
|
|
173
|
-
rightBottom: "translate(".concat(
|
|
129
|
+
rightTop: "translate(".concat(_mouseX + translateTip.x, "px,").concat(_mouseY - tipHeight - translateTip.y, "px)"),
|
|
130
|
+
leftTop: "translate(".concat(_mouseX - tipWidth - translateTip.x, "px,").concat(_mouseY - tipHeight - translateTip.y, "px)"),
|
|
131
|
+
leftBottom: "translate(".concat(_mouseX - tipWidth - translateTip.x, "px,").concat(_mouseY + translateTip.y, "px)"),
|
|
132
|
+
rightBottom: "translate(".concat(_mouseX + translateTip.x, "px,").concat(_mouseY + translateTip.y, "px)")
|
|
174
133
|
};
|
|
175
|
-
if (
|
|
134
|
+
if (_mouseX < centerX && _mouseY < centerY) {
|
|
176
135
|
return tipPosMap.leftTop;
|
|
177
|
-
} else if (
|
|
136
|
+
} else if (_mouseX > centerX && _mouseY < centerY) {
|
|
178
137
|
return tipPosMap.rightTop;
|
|
179
|
-
} else if (
|
|
138
|
+
} else if (_mouseX >= centerX && _mouseY >= centerY) {
|
|
180
139
|
return tipPosMap.rightBottom;
|
|
181
140
|
} else {
|
|
182
141
|
return tipPosMap.leftBottom;
|
package/package.json
CHANGED
package/src/components/Chart.js
CHANGED
|
@@ -47,7 +47,6 @@ const Chart = memo(
|
|
|
47
47
|
const chartHeight = height - marginTop - marginBottom;
|
|
48
48
|
const [active, setActive] = useState(true);
|
|
49
49
|
const scaleRef = useRef([1,1]);
|
|
50
|
-
const domRef=useRef()
|
|
51
50
|
const triggerOnRelative = useCallback(
|
|
52
51
|
(action,data) => {
|
|
53
52
|
if (!interaction) return;
|
|
@@ -116,7 +115,7 @@ const Chart = memo(
|
|
|
116
115
|
return (
|
|
117
116
|
<chartContext.Provider value={context}>
|
|
118
117
|
{type == 'pie' ? (
|
|
119
|
-
<
|
|
118
|
+
<PieChart id={id} config={config} data={data} active={active} {...props} />
|
|
120
119
|
) : (
|
|
121
120
|
<CartesianChart id={id} config={config} data={data} active={active} {...props} />
|
|
122
121
|
)}
|
|
@@ -247,7 +247,6 @@ const getCircleScale = ({ count, color, width, length } = tick, radius) => {
|
|
|
247
247
|
|
|
248
248
|
const Component = memo(
|
|
249
249
|
({
|
|
250
|
-
domRef,
|
|
251
250
|
width,
|
|
252
251
|
height,
|
|
253
252
|
config: {
|
|
@@ -636,7 +635,6 @@ const Component = memo(
|
|
|
636
635
|
y: maxRadius + marginTop,
|
|
637
636
|
}}
|
|
638
637
|
mousePos={mousePos}
|
|
639
|
-
domRef={domRef}
|
|
640
638
|
/>
|
|
641
639
|
</div>
|
|
642
640
|
)}
|
|
@@ -898,7 +896,6 @@ const Component = memo(
|
|
|
898
896
|
y: maxRadius + marginTop,
|
|
899
897
|
}}
|
|
900
898
|
mousePos={mousePos}
|
|
901
|
-
domRef={domRef}
|
|
902
899
|
/>
|
|
903
900
|
</div>
|
|
904
901
|
)}
|
|
@@ -3,7 +3,7 @@ import { getFontStyle, getMargin, getTranslate3d, getTranslate2d, getIcon } from
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const PieTooltip = memo((props) => {
|
|
6
|
-
const { mousePos,
|
|
6
|
+
const { mousePos,
|
|
7
7
|
pieCenter,
|
|
8
8
|
config: {
|
|
9
9
|
tip: {
|
|
@@ -19,7 +19,7 @@ export const PieTooltip = memo((props) => {
|
|
|
19
19
|
},
|
|
20
20
|
data,
|
|
21
21
|
series } = props
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
const Item = () => {
|
|
24
24
|
const { data: { s, y }, percent } = data
|
|
25
25
|
const { type, icon, displayName } = [...series.values()].find(
|
|
@@ -88,88 +88,38 @@ export const PieTooltip = memo((props) => {
|
|
|
88
88
|
const getTipPos = () => {
|
|
89
89
|
|
|
90
90
|
const getBigscreenScale = () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
|
|
91
|
+
if (window.getScreenScale) {
|
|
92
|
+
return window.getScreenScale()
|
|
93
|
+
} else {
|
|
94
|
+
const bigscreenDom = document.getElementById('bigscreen-container')
|
|
95
|
+
if (!bigscreenDom) return [1, 1]
|
|
96
|
+
const transform = bigscreenDom.style.transform
|
|
97
|
+
if (!transform) return [1, 1]
|
|
98
|
+
let match = transform.match(/scale\(([^)]+)\)/)
|
|
99
|
+
if (match) {
|
|
100
|
+
const scaleMatch = match[1].split(',')
|
|
101
|
+
let scaleX = scaleMatch[0];
|
|
102
|
+
let scaleY = scaleMatch[1];
|
|
103
|
+
if (scaleY) {
|
|
104
|
+
return [Number(scaleX), Number(scaleY)]
|
|
105
|
+
} else {
|
|
106
|
+
return [Number(scaleX), Number(scaleX)]
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
return [1, 1]
|
|
97
110
|
}
|
|
98
|
-
} catch (e) {
|
|
99
|
-
console.error('调用全局 getScreenScale 出错:', e);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 获取容器元素
|
|
104
|
-
const bigscreenDom = document.getElementById('bigscreen-container');
|
|
105
|
-
|
|
106
|
-
// 元素不存在时的处理
|
|
107
|
-
if (!bigscreenDom) {
|
|
108
|
-
console.warn('未找到 bigscreen-container 元素,使用视口尺寸');
|
|
109
|
-
return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 确保元素可见(未被隐藏)
|
|
113
|
-
const isVisible = window.getComputedStyle(bigscreenDom).display !== 'none'
|
|
114
|
-
&& window.getComputedStyle(bigscreenDom).visibility !== 'hidden';
|
|
115
|
-
if (!isVisible) {
|
|
116
|
-
console.warn('bigscreen-container 元素不可见,使用视口尺寸');
|
|
117
|
-
return [1, 1, window.innerWidth, window.innerHeight, 0, 0];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 获取元素的布局矩形(最可靠的尺寸获取方式)
|
|
121
|
-
const rect = bigscreenDom.getBoundingClientRect();
|
|
122
|
-
|
|
123
|
-
// 提取基础尺寸(从布局矩形获取,不受样式影响)
|
|
124
|
-
const screenWidth = rect.width || window.innerWidth;
|
|
125
|
-
const screenHeight = rect.height || window.innerHeight;
|
|
126
|
-
const screenLeft = rect.left || 0;
|
|
127
|
-
const screenTop = rect.top || 0;
|
|
128
|
-
|
|
129
|
-
// 处理缩放
|
|
130
|
-
let scaleX = 1;
|
|
131
|
-
let scaleY = 1;
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
const computedStyle = window.getComputedStyle(bigscreenDom);
|
|
135
|
-
const transform = computedStyle.transform;
|
|
136
|
-
|
|
137
|
-
if (transform && transform !== 'none') {
|
|
138
|
-
// 解析 transform matrix
|
|
139
|
-
const matrix = new DOMMatrix(transform);
|
|
140
|
-
scaleX = matrix.a; // 缩放X因子
|
|
141
|
-
scaleY = matrix.d; // 缩放Y因子
|
|
142
|
-
}
|
|
143
|
-
} catch (e) {
|
|
144
|
-
console.error('解析缩放样式出错:', e);
|
|
145
111
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const result = [
|
|
149
|
-
isNaN(scaleX) ? 1 : scaleX,
|
|
150
|
-
isNaN(scaleY) ? 1 : scaleY,
|
|
151
|
-
isNaN(screenWidth) ? window.innerWidth : screenWidth,
|
|
152
|
-
isNaN(screenHeight) ? window.innerHeight : screenHeight,
|
|
153
|
-
isNaN(screenLeft) ? 0 : screenLeft,
|
|
154
|
-
isNaN(screenTop) ? 0 : screenTop
|
|
155
|
-
];
|
|
156
|
-
return result;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const [scaleX, scaleY,screenWidth,screenHeight,screenLeft,screenTop] = getBigscreenScale()
|
|
112
|
+
}
|
|
113
|
+
const [scaleX, scaleY] = getBigscreenScale()
|
|
160
114
|
const _mouseX = mouseX / scaleX
|
|
161
115
|
const _mouseY = mouseY / scaleY
|
|
162
116
|
const tipPosMap = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
rightBottom: `translate(${(screenRef.x+tipWidth)/scaleX+_mouseX-screenLeft+translateTip.x>screenWidth?_mouseX -tipWidth- translateTip.x:_mouseX + translateTip.x}px,
|
|
170
|
-
${(screenRef.y+tipHeight)/scaleY+_mouseY-screenTop+translateTip.y>screenHeight? _mouseY- tipHeight- translateTip.y: _mouseY + translateTip.y}px)`,
|
|
171
|
-
}
|
|
172
|
-
if (_mouseX < centerX && _mouseY < centerY) {
|
|
117
|
+
rightTop: `translate(${_mouseX + translateTip.x}px,${_mouseY - tipHeight - translateTip.y}px)`,
|
|
118
|
+
leftTop: `translate(${_mouseX - tipWidth - translateTip.x}px,${_mouseY - tipHeight - translateTip.y}px)`,
|
|
119
|
+
leftBottom: `translate(${_mouseX - tipWidth - translateTip.x}px,${_mouseY + translateTip.y}px)`,
|
|
120
|
+
rightBottom: `translate(${_mouseX + translateTip.x}px,${(_mouseY + translateTip.y)}px)`,
|
|
121
|
+
}
|
|
122
|
+
if (_mouseX < centerX && _mouseY < centerY) {
|
|
173
123
|
return tipPosMap.leftTop
|
|
174
124
|
} else if (_mouseX > centerX && _mouseY < centerY) {
|
|
175
125
|
return tipPosMap.rightTop
|