@easyv/charts 1.3.3 → 1.3.6
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/Label.js +10 -11
- package/lib/components/Marquee.js +65 -46
- package/package.json +2 -2
- package/src/components/Label.js +9 -6
- package/src/components/Marquee.js +63 -55
package/lib/components/Label.js
CHANGED
|
@@ -49,18 +49,17 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
49
49
|
|
|
50
50
|
var _useContext = (0, _react.useContext)(_context.chartContext),
|
|
51
51
|
width = _useContext.width,
|
|
52
|
-
height = _useContext.height;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
paddingOuter: paddingOuter
|
|
59
|
-
}),
|
|
60
|
-
seriesStep = _getSeriesInfo.seriesStep,
|
|
61
|
-
seriesWidth = _getSeriesInfo.seriesWidth,
|
|
62
|
-
seriesStart = _getSeriesInfo.seriesStart;
|
|
52
|
+
height = _useContext.height; // const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
|
|
53
|
+
// step,
|
|
54
|
+
// bandLength,
|
|
55
|
+
// paddingInner,
|
|
56
|
+
// paddingOuter,
|
|
57
|
+
// });
|
|
63
58
|
|
|
59
|
+
|
|
60
|
+
var seriesStep = (1 + paddingInner) * step,
|
|
61
|
+
seriesWidth = step,
|
|
62
|
+
seriesStart = paddingOuter * step;
|
|
64
63
|
var isVertical = direction === 'vertical';
|
|
65
64
|
var _position = label.position;
|
|
66
65
|
return /*#__PURE__*/React.createElement("g", {
|
|
@@ -27,66 +27,85 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (props) {
|
|
|
27
27
|
_props$speed = props.speed,
|
|
28
28
|
speed = _props$speed === void 0 ? 5 : _props$speed;
|
|
29
29
|
var dom = (0, _react.useRef)(null);
|
|
30
|
-
var
|
|
30
|
+
var target = (0, _react.useRef)(null);
|
|
31
|
+
var observe = (0, _react.useRef)(null);
|
|
32
|
+
var speed_ = (0, _react.useRef)(0); //这里必须用一个ref绑定speed,否则animation中获取不到最新的speed
|
|
33
|
+
|
|
34
|
+
var timer = (0, _react.useRef)();
|
|
31
35
|
|
|
32
36
|
var _useState = (0, _react.useState)(false),
|
|
33
37
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
overflow = _useState2[0],
|
|
39
|
+
setOverflow = _useState2[1];
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
var duration = (0, _react.useRef)(10 / speed);
|
|
39
|
-
(0, _react.useEffect)(function () {
|
|
40
|
-
if (dom.current && content.current) {
|
|
41
|
-
var domRectWidth = dom.current.getBoundingClientRect().width;
|
|
42
|
-
var contentRectWidth = content.current.getBoundingClientRect().width;
|
|
43
|
-
|
|
44
|
-
if (domRectWidth < contentRectWidth) {
|
|
45
|
-
textList.current = [value, value];
|
|
46
|
-
duration.current = contentRectWidth / domRectWidth / speed * 10;
|
|
47
|
-
setFresh(!fresh);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [value, speed]); //在head标签中注入keyframes动画
|
|
51
|
-
|
|
52
|
-
(0, _react.useEffect)(function () {
|
|
53
|
-
var md_marquee = document.getElementById('md_marquee'); //先查找是否已经存在md_marquee
|
|
41
|
+
speed_.current = speed;
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var
|
|
43
|
+
var startAnimation = function startAnimation(lineWidth) {
|
|
44
|
+
var animation = function animation(timestamp) {
|
|
45
|
+
var frame = Math.round(timestamp * speed_.current % (lineWidth * 100) / 100);
|
|
46
|
+
target.current.style.transform = "translate(-".concat(frame, "px,0px)");
|
|
47
|
+
target.current.nextSibling.style.transform = "translate(-".concat(frame, "px,0px)");
|
|
48
|
+
timer.current = requestAnimationFrame(animation);
|
|
49
|
+
};
|
|
58
50
|
|
|
59
|
-
|
|
51
|
+
timer.current = requestAnimationFrame(animation);
|
|
52
|
+
};
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
(0, _react.useEffect)(function () {
|
|
55
|
+
//初始化观察器,利用观察器来监视组件可视区域变化
|
|
56
|
+
observe.current = new IntersectionObserver(function (entries) {
|
|
57
|
+
var entrie = entries[0];
|
|
58
|
+
|
|
59
|
+
if (entrie.boundingClientRect.width < entrie.rootBounds.width >= 1) {
|
|
60
|
+
//表示文字全部可视
|
|
61
|
+
cancelAnimationFrame(timer.current);
|
|
62
|
+
target.current.style.transform = "translate(0px,0px)"; //重置偏移
|
|
63
|
+
|
|
64
|
+
setOverflow(false);
|
|
65
|
+
return;
|
|
66
|
+
} else {
|
|
67
|
+
//否则文本溢出
|
|
68
|
+
if (!overflow) {
|
|
69
|
+
cancelAnimationFrame(timer.current);
|
|
70
|
+
startAnimation(entrie.boundingClientRect.width);
|
|
71
|
+
setOverflow(true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
root: dom.current,
|
|
76
|
+
rootMargin: "0px 0px 0px 0px",
|
|
77
|
+
threshold: new Array(101).fill(0).map(function (d, i) {
|
|
78
|
+
return i / 100;
|
|
79
|
+
}) //这里设置了[0-1]之间所有的阈值,保证每一帧的变化都能被观察到
|
|
80
|
+
|
|
81
|
+
}); // start observing
|
|
82
|
+
|
|
83
|
+
observe.current.observe(target.current);
|
|
84
|
+
return function () {
|
|
85
|
+
cancelAnimationFrame(timer.current);
|
|
86
|
+
observe.current.unobserve(target.current);
|
|
87
|
+
observe.current.disconnect();
|
|
88
|
+
};
|
|
66
89
|
}, []);
|
|
67
|
-
var
|
|
68
|
-
return /*#__PURE__*/React.createElement("
|
|
90
|
+
var textList = [value, value];
|
|
91
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
69
92
|
style: _objectSpread(_objectSpread({
|
|
70
|
-
width:
|
|
93
|
+
width: "100%"
|
|
71
94
|
}, style), {}, {
|
|
72
|
-
display:
|
|
73
|
-
whiteSpace:
|
|
74
|
-
overflow:
|
|
95
|
+
display: "flex",
|
|
96
|
+
whiteSpace: "nowrap",
|
|
97
|
+
overflow: "hidden",
|
|
75
98
|
justifyContent: overflow ? "start" : style.justifyContent || ""
|
|
76
99
|
}),
|
|
77
100
|
ref: dom
|
|
78
|
-
}, textList.
|
|
101
|
+
}, textList.map(function (item, i) {
|
|
79
102
|
return /*#__PURE__*/React.createElement("span", {
|
|
80
|
-
key:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
animationDuration: duration.current + 's'
|
|
87
|
-
} : {},
|
|
88
|
-
ref: itemIndex == 0 ? content : null
|
|
89
|
-
}, "\xA0", item);
|
|
103
|
+
key: i,
|
|
104
|
+
ref: i == 0 ? target : null,
|
|
105
|
+
style: {
|
|
106
|
+
display: i == 1 && !overflow ? "none" : "inline"
|
|
107
|
+
}
|
|
108
|
+
}, item, "\xA0");
|
|
90
109
|
}));
|
|
91
110
|
});
|
|
92
111
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyv/charts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@babel/preset-env": "^7.17.10",
|
|
20
20
|
"@babel/preset-react": "^7.16.7",
|
|
21
21
|
"@babel/preset-typescript": "^7.16.7",
|
|
22
|
-
"@commitlint/cli": "^
|
|
22
|
+
"@commitlint/cli": "^17.0.3",
|
|
23
23
|
"@commitlint/config-conventional": "^16.2.4",
|
|
24
24
|
"@types/d3": "^7.0.0",
|
|
25
25
|
"@types/react": "^18.0.12",
|
package/src/components/Label.js
CHANGED
|
@@ -26,13 +26,16 @@ export default memo(
|
|
|
26
26
|
|
|
27
27
|
if (!(data.length && (showIcon || showLabel))) return null;
|
|
28
28
|
const { width, height } = useContext(chartContext);
|
|
29
|
-
const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
|
|
30
|
-
step,
|
|
31
|
-
bandLength,
|
|
32
|
-
paddingInner,
|
|
33
|
-
paddingOuter,
|
|
34
|
-
});
|
|
35
29
|
|
|
30
|
+
// const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
|
|
31
|
+
// step,
|
|
32
|
+
// bandLength,
|
|
33
|
+
// paddingInner,
|
|
34
|
+
// paddingOuter,
|
|
35
|
+
// });
|
|
36
|
+
|
|
37
|
+
const seriesStep = (1 + paddingInner) * step,
|
|
38
|
+
seriesWidth = step, seriesStart = paddingOuter * step;
|
|
36
39
|
const isVertical = direction === 'vertical';
|
|
37
40
|
const _position = label.position;
|
|
38
41
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, memo, useRef, useState } from
|
|
1
|
+
import { useEffect, memo, useRef, useState, useCallback } from "react";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 文字跑马灯组件
|
|
@@ -13,76 +13,84 @@ export default memo((props) => {
|
|
|
13
13
|
} = props;
|
|
14
14
|
|
|
15
15
|
const dom = useRef(null);
|
|
16
|
-
const
|
|
16
|
+
const target = useRef(null);
|
|
17
|
+
const observe = useRef(null);
|
|
18
|
+
const speed_ = useRef(0); //这里必须用一个ref绑定speed,否则animation中获取不到最新的speed
|
|
19
|
+
const timer = useRef();
|
|
20
|
+
const [overflow, setOverflow] = useState(false);
|
|
21
|
+
speed_.current = speed;
|
|
17
22
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const startAnimation = (lineWidth)=>{
|
|
24
|
+
const animation = (timestamp) => {
|
|
25
|
+
let frame = Math.round(((timestamp*speed_.current)%(lineWidth*100))/100);
|
|
26
|
+
target.current.style.transform = `translate(-${frame}px,0px)`;
|
|
27
|
+
target.current.nextSibling.style.transform = `translate(-${frame}px,0px)`;
|
|
28
|
+
timer.current = requestAnimationFrame(animation);
|
|
29
|
+
};
|
|
30
|
+
timer.current = requestAnimationFrame(animation);
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
|
|
22
34
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
//初始化观察器,利用观察器来监视组件可视区域变化
|
|
36
|
+
observe.current = new IntersectionObserver(
|
|
37
|
+
function (entries) {
|
|
38
|
+
let entrie = entries[0];
|
|
39
|
+
|
|
40
|
+
if (entrie.boundingClientRect.width < entrie.rootBounds.width >= 1) {
|
|
41
|
+
//表示文字全部可视
|
|
42
|
+
cancelAnimationFrame(timer.current);
|
|
43
|
+
target.current.style.transform = "translate(0px,0px)"; //重置偏移
|
|
44
|
+
setOverflow(false);
|
|
45
|
+
return;
|
|
46
|
+
} else {
|
|
47
|
+
//否则文本溢出
|
|
48
|
+
if (!overflow) {
|
|
49
|
+
cancelAnimationFrame(timer.current);
|
|
50
|
+
startAnimation(entrie.boundingClientRect.width);
|
|
51
|
+
setOverflow(true);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
root: dom.current,
|
|
57
|
+
rootMargin: "0px 0px 0px 0px",
|
|
58
|
+
threshold: new Array(101).fill(0).map((d, i) => i / 100), //这里设置了[0-1]之间所有的阈值,保证每一帧的变化都能被观察到
|
|
30
59
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const keyframes = `@keyframes md_marquee {0%{
|
|
40
|
-
transform: translate(0,0);
|
|
41
|
-
}
|
|
42
|
-
100%{
|
|
43
|
-
transform: translate(-100%,0);
|
|
44
|
-
}}`;
|
|
45
|
-
const style = document.createElement('style');
|
|
46
|
-
style.id = 'md_marquee';
|
|
47
|
-
style.innerHTML = keyframes;
|
|
48
|
-
// 将style样式存放到head标签
|
|
49
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
50
|
-
}
|
|
60
|
+
);
|
|
61
|
+
// start observing
|
|
62
|
+
observe.current.observe(target.current);
|
|
63
|
+
return () => {
|
|
64
|
+
cancelAnimationFrame(timer.current);
|
|
65
|
+
observe.current.unobserve(target.current);
|
|
66
|
+
observe.current.disconnect();
|
|
67
|
+
};
|
|
51
68
|
}, []);
|
|
52
|
-
|
|
69
|
+
|
|
70
|
+
let textList = [value, value];
|
|
53
71
|
return (
|
|
54
|
-
<
|
|
72
|
+
<div
|
|
55
73
|
style={{
|
|
56
|
-
width:
|
|
74
|
+
width: "100%",
|
|
57
75
|
...style,
|
|
58
|
-
display:
|
|
59
|
-
whiteSpace:
|
|
60
|
-
overflow:
|
|
61
|
-
justifyContent:overflow?"start":
|
|
76
|
+
display: "flex",
|
|
77
|
+
whiteSpace: "nowrap",
|
|
78
|
+
overflow: "hidden",
|
|
79
|
+
justifyContent: overflow ? "start" : style.justifyContent || "",
|
|
62
80
|
}}
|
|
63
81
|
ref={dom}
|
|
64
82
|
>
|
|
65
|
-
{textList.
|
|
83
|
+
{textList.map((item, i) => {
|
|
66
84
|
return (
|
|
67
85
|
<span
|
|
68
|
-
key={
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
? {
|
|
72
|
-
//如果文本数量为2,则需要滚动
|
|
73
|
-
animationName: 'md_marquee',
|
|
74
|
-
animationTimingFunction: 'linear',
|
|
75
|
-
animationIterationCount: 'infinite',
|
|
76
|
-
animationDuration: duration.current + 's',
|
|
77
|
-
}
|
|
78
|
-
: {}
|
|
79
|
-
}
|
|
80
|
-
ref={itemIndex == 0 ? content : null}
|
|
86
|
+
key={i}
|
|
87
|
+
ref={i == 0 ? target : null}
|
|
88
|
+
style={{ display: i == 1 && !overflow ? "none" : "inline" }}
|
|
81
89
|
>
|
|
82
|
-
|
|
90
|
+
{item}
|
|
83
91
|
</span>
|
|
84
92
|
);
|
|
85
93
|
})}
|
|
86
|
-
</
|
|
94
|
+
</div>
|
|
87
95
|
);
|
|
88
96
|
});
|