@easyv/charts 1.2.2 → 1.2.3
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.
|
@@ -72,8 +72,9 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (props) {
|
|
|
72
72
|
}
|
|
73
73
|
}, []);
|
|
74
74
|
return /*#__PURE__*/React.createElement("span", {
|
|
75
|
-
style: _objectSpread(_objectSpread({
|
|
76
|
-
width: "100%"
|
|
75
|
+
style: _objectSpread(_objectSpread({
|
|
76
|
+
width: "100%"
|
|
77
|
+
}, style), {}, {
|
|
77
78
|
display: "flex",
|
|
78
79
|
whiteSpace: "nowrap",
|
|
79
80
|
overflow: "hidden"
|
package/lib/components/index.js
CHANGED
|
@@ -143,6 +143,12 @@ Object.defineProperty(exports, "PieChart", {
|
|
|
143
143
|
return _PieChart["default"];
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
|
+
Object.defineProperty(exports, "Marquee", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function get() {
|
|
149
|
+
return _Marquee["default"];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
146
152
|
exports.Area = void 0;
|
|
147
153
|
|
|
148
154
|
var _Mapping = _interopRequireDefault(require("./Mapping"));
|
|
@@ -191,5 +197,7 @@ var _CartesianChart = _interopRequireDefault(require("./CartesianChart"));
|
|
|
191
197
|
|
|
192
198
|
var _PieChart = _interopRequireDefault(require("./PieChart"));
|
|
193
199
|
|
|
200
|
+
var _Marquee = _interopRequireDefault(require("./Marquee"));
|
|
201
|
+
|
|
194
202
|
var Area = _Line["default"];
|
|
195
203
|
exports.Area = Area;
|
package/package.json
CHANGED
|
@@ -1,74 +1,93 @@
|
|
|
1
|
-
import { useState, useEffect, memo, useRef } from
|
|
1
|
+
import { useState, useEffect, memo, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 文字跑马灯组件
|
|
5
5
|
* eg: <Marquee value={文本内容} speed={跑马灯速度} style={额外样式}></Marquee>
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export default memo((props)=>{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export default memo((props) => {
|
|
9
|
+
const {
|
|
10
|
+
value, // 文本
|
|
11
|
+
style, // 样式
|
|
12
|
+
speed = 5, // 动画速度
|
|
13
|
+
} = props;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const dom = useRef(null);
|
|
16
|
+
const content = useRef(null);
|
|
17
|
+
const duration = useRef(1);
|
|
18
|
+
//dom和content盒子对象,避免speed变化时重新获取盒子对象
|
|
19
|
+
const domRect = useRef(null);
|
|
20
|
+
const contentRect = useRef(null);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const [textList, setTextList] = useState([value]);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
//文本变化时,需要重新计算dom和content的宽高
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const dom_ = dom.current;
|
|
27
|
+
domRect.current = dom_.getBoundingClientRect();
|
|
28
|
+
let content_ = content.current;
|
|
29
|
+
contentRect.current = content_.getBoundingClientRect();
|
|
30
|
+
if (domRect.current.width < contentRect.current.width) {
|
|
31
|
+
setTextList([value, value]);
|
|
32
|
+
}
|
|
33
|
+
}, [value]);
|
|
34
|
+
//value和speed变化时,直接更新duration
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (domRect.current.width < contentRect.current.width) {
|
|
37
|
+
duration.current =
|
|
38
|
+
(contentRect.current.width / domRect.current.width / speed) * 10;
|
|
39
|
+
}
|
|
40
|
+
}, [speed]);
|
|
41
|
+
//在head标签中注入keyframes动画
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
let md_marquee = document.getElementById('md_marquee'); //先查找是否已经存在md_marquee
|
|
44
|
+
if (!md_marquee) {
|
|
45
|
+
//不存在时再注入style标签
|
|
46
|
+
const keyframes = `@keyframes md_marquee {0%{
|
|
45
47
|
transform: translate(0,0);
|
|
46
48
|
}
|
|
47
49
|
100%{
|
|
48
50
|
transform: translate(-100%,0);
|
|
49
51
|
}}`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const style = document.createElement('style');
|
|
53
|
+
style.id = 'md_marquee';
|
|
54
|
+
style.innerHTML = keyframes;
|
|
55
|
+
// 将style样式存放到head标签
|
|
56
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
return (
|
|
60
|
+
<span
|
|
61
|
+
style={{
|
|
62
|
+
width: '100%',
|
|
63
|
+
...style,
|
|
64
|
+
display: 'flex',
|
|
65
|
+
whiteSpace: 'nowrap',
|
|
66
|
+
overflow: 'hidden',
|
|
67
|
+
}}
|
|
68
|
+
ref={dom}
|
|
69
|
+
>
|
|
70
|
+
{textList.map((item, itemIndex) => {
|
|
60
71
|
return (
|
|
61
|
-
<span
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
<span
|
|
73
|
+
key={itemIndex}
|
|
74
|
+
style={
|
|
75
|
+
textList.length == 2
|
|
76
|
+
? {
|
|
77
|
+
//如果文本数量为2,则需要滚动
|
|
78
|
+
animationName: 'md_marquee',
|
|
79
|
+
animationTimingFunction: 'linear',
|
|
80
|
+
animationIterationCount: 'infinite',
|
|
81
|
+
animationDuration: duration.current + 's',
|
|
82
|
+
}
|
|
83
|
+
: {}
|
|
84
|
+
}
|
|
85
|
+
ref={itemIndex == 0 ? content : null}
|
|
86
|
+
>
|
|
69
87
|
{item}
|
|
70
|
-
</span>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
})}
|
|
91
|
+
</span>
|
|
92
|
+
);
|
|
93
|
+
});
|
package/src/components/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import Chart from './Chart';
|
|
|
21
21
|
import ConicalGradient from './ConicalGradient';
|
|
22
22
|
import CartesianChart from './CartesianChart';
|
|
23
23
|
import PieChart from './PieChart';
|
|
24
|
+
import Marquee from './Marquee';
|
|
24
25
|
|
|
25
26
|
const Area = Line;
|
|
26
27
|
export {
|
|
@@ -46,6 +47,7 @@ export {
|
|
|
46
47
|
Carousel,
|
|
47
48
|
CartesianChart,
|
|
48
49
|
PieChart,
|
|
50
|
+
Marquee,
|
|
49
51
|
Chart,
|
|
50
52
|
ConicalGradient,
|
|
51
53
|
};
|