@easyv/charts 1.4.24 → 1.4.26

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.
@@ -0,0 +1,134 @@
1
+ import React, { memo } from 'react'
2
+ import { getFontStyle, getMargin, getTranslate3d, getTranslate2d, getIcon } from '../utils';
3
+
4
+
5
+ export const PieTooltip = memo((props) => {
6
+ const { mousePos,
7
+ pieCenter,
8
+ config: {
9
+ tip: {
10
+ data: { lineHeight, iconSize, name,
11
+ value: { show: valueIsShow, fontStyle: valueFont, suffix: valueSuffix,suffix:{show:valueSuffixIsShow} },
12
+ percentage: { show: percentageIsShow, fontStyle: percentageFont, suffix: percentageSuffix,suffix:{show:percentageSuffixIsShow} },
13
+ },
14
+ image,
15
+ margin,
16
+ size: { width: tipWidth, height: tipHeight },
17
+ translate: translateTip,
18
+ },
19
+ },
20
+ data,
21
+ series } = props
22
+
23
+ const Item = () => {
24
+ const { data: { s, y }, percent } = data
25
+ const { type, icon, displayName } = [...series.values()].find(
26
+ (series) => series.name == s
27
+ );
28
+
29
+ const renderSuffix = (suffix) =>{
30
+ const {
31
+ content,
32
+ font: suffiixFont,
33
+ translate: suffixTranslate,
34
+ } = suffix;
35
+ return (
36
+ <span
37
+ style={{
38
+ ...getFontStyle(suffiixFont),
39
+ display: "inline-block",
40
+ transform: getTranslate3d(suffixTranslate),
41
+ }}
42
+ >
43
+ {content}
44
+ </span>
45
+ )
46
+ }
47
+
48
+ const _icon = getIcon(type, icon);
49
+ return (
50
+ <dd
51
+ style={{
52
+ display: 'flex',
53
+ justifyContent: 'space-between',
54
+ lineHeight: lineHeight + 'px',
55
+ }}
56
+
57
+ >
58
+ <span
59
+ style={{
60
+ // border: '1px solid red',
61
+ display: 'flex',
62
+ alignItems: 'center',
63
+ gap: icon.iconGap,
64
+ }}
65
+ >
66
+ <span
67
+ style={{
68
+ ..._icon,
69
+ width: iconSize + 'px',
70
+ height: iconSize + 'px',
71
+ }}
72
+ />
73
+ <span style={getFontStyle(name)}>{displayName || s}</span>
74
+ </span>
75
+ {valueIsShow && <span style={getFontStyle(valueFont)}>
76
+ {y}
77
+ {valueSuffixIsShow && renderSuffix(valueSuffix)}
78
+ </span>}
79
+ {percentageIsShow && <span style={getFontStyle(percentageFont)}>
80
+ {percent}
81
+ {percentageSuffixIsShow && renderSuffix(percentageSuffix)}
82
+ </span>}
83
+ </dd>
84
+ );
85
+ }
86
+ const { x: mouseX, y: mouseY } = mousePos
87
+ const { x: centerX, y: centerY } = pieCenter
88
+ const getTipPos = () => {
89
+ const tipPosMap = {
90
+ rightTop: `translate(${mouseX + translateTip.x}px,${mouseY - tipHeight - translateTip.y}px)`,
91
+ leftTop: `translate(${mouseX - tipWidth - translateTip.x}px,${mouseY - tipHeight - translateTip.y}px)`,
92
+ leftBottom: `translate(${mouseX - tipWidth - translateTip.x}px,${mouseY + translateTip.y}px)`,
93
+ rightBottom: `translate(${mouseX + translateTip.x}px,${mouseY + translateTip.y}px)`,
94
+ }
95
+ if (mouseX < centerX && mouseY < centerY) {
96
+ return tipPosMap.leftTop
97
+ } else if (mouseX > centerX && mouseY < centerY) {
98
+ return tipPosMap.rightTop
99
+ } else if (mouseX >= centerX && mouseY >= centerY) {
100
+ return tipPosMap.rightBottom
101
+ } else {
102
+ return tipPosMap.leftBottom
103
+ }
104
+ }
105
+
106
+ return <div
107
+ className='__easyv-tooltip'
108
+ style={{
109
+ pointerEvents: 'none',
110
+ transform: getTipPos(mousePos, pieCenter),
111
+ width: tipWidth,
112
+ height: tipHeight,
113
+ padding: getMargin(margin),
114
+ background: image
115
+ ? '50% 50% / 100% 100% no-repeat url(' +
116
+ window.appConfig.ASSETS_URL +
117
+ image +
118
+ ')'
119
+ : 'rgba(48, 55, 66, 0.85)',
120
+ }}
121
+ >
122
+ <dl
123
+ style={{
124
+ display: 'flex',
125
+ flexDirection: 'column',
126
+ justifyContent: 'space-between',
127
+ height: '100%',
128
+ }}
129
+ >
130
+ {Item()}
131
+ </dl>
132
+
133
+ </div>
134
+ })
@@ -24,6 +24,7 @@ import PieChart from './PieChart';
24
24
  import TextOverflow from './TextOverflow';
25
25
  import BaseLine from './BaseLine';
26
26
  import Control from './Control';
27
+ import { PieTooltip } from './PieTooltip';
27
28
 
28
29
  const Area = Line;
29
30
  export {
@@ -54,4 +55,5 @@ export {
54
55
  Chart,
55
56
  ConicalGradient,
56
57
  BaseLine,
58
+ PieTooltip
57
59
  };