1
- import React from 'react'
1
+ import React from 'react' ;
2
2
//
3
- import { translate } from '../utils/Utils'
3
+ import { translate } from '../utils/Utils' ;
4
4
5
- import useChartContext from '../hooks/useChartContext'
6
- import useLatest from '../hooks/useLatest'
5
+ import useChartContext from '../hooks/useChartContext' ;
6
+ import useLatest from '../hooks/useLatest' ;
7
7
8
8
const getLineBackgroundColor = dark =>
9
- dark ? 'rgba(255,255,255,.3)' : 'rgba(0, 26, 39, 0.3)'
9
+ dark ? 'rgba(255,255,255,.3)' : 'rgba(0, 26, 39, 0.3)' ;
10
10
11
11
const getBackgroundColor = dark =>
12
- dark ? 'rgba(255,255,255,.9)' : 'rgba(0, 26, 39, 0.9)'
12
+ dark ? 'rgba(255,255,255,.9)' : 'rgba(0, 26, 39, 0.9)' ;
13
13
14
14
export default function Cursor ( { primary } ) {
15
15
const {
@@ -20,10 +20,10 @@ export default function Cursor({ primary }) {
20
20
gridX,
21
21
gridY,
22
22
dark,
23
- } = useChartContext ( )
23
+ } = useChartContext ( ) ;
24
24
25
- const resolvedFocused = focused || latestFocused
26
- const cursor = primary ? primaryCursor : secondaryCursor
25
+ const resolvedFocused = focused || latestFocused ;
26
+ const cursor = primary ? primaryCursor : secondaryCursor ;
27
27
28
28
const {
29
29
showLine,
@@ -34,67 +34,71 @@ export default function Cursor({ primary }) {
34
34
axis,
35
35
siblingAxis,
36
36
resolvedShow,
37
- } = cursor || { }
37
+ } = cursor || { } ;
38
38
39
39
const latestValue = useLatest (
40
40
resolvedValue ,
41
41
typeof resolvedValue !== 'undefined'
42
- )
42
+ ) ;
43
43
44
- const previousShowRef = React . useRef ( )
44
+ const previousShowRef = React . useRef ( ) ;
45
45
React . useEffect ( ( ) => {
46
- previousShowRef . current = resolvedShow
47
- } , [ resolvedShow ] )
46
+ previousShowRef . current = resolvedShow ;
47
+ } , [ resolvedShow ] ) ;
48
48
49
49
if ( ! cursor ) {
50
- return null
50
+ return null ;
51
51
}
52
52
53
53
// Should we animate?
54
- const animated = snap || axis . type === 'ordinal'
54
+ const animated = snap || axis . type === 'ordinal' ;
55
55
56
56
// Get the sibling range
57
- const siblingRange = siblingAxis . scale . range ( )
57
+ const siblingRange = siblingAxis . scale . range ( ) ;
58
58
59
- let x
60
- let y
61
- let x1
62
- let x2
63
- let y1
64
- let y2
65
- let alignPctX
66
- let alignPctY
59
+ let x ;
60
+ let y ;
61
+ let x1 ;
62
+ let x2 ;
63
+ let y1 ;
64
+ let y2 ;
65
+ let alignPctX ;
66
+ let alignPctY ;
67
67
68
68
// Vertical alignment
69
69
if ( axis . vertical ) {
70
- y = axis . scale ( latestValue )
71
- x1 = siblingRange [ 0 ]
72
- x2 = siblingRange [ 1 ]
73
- y1 = y - 1
74
- y2 = y + axis . cursorSize + 1
70
+ y = axis . scale ( latestValue ) ;
71
+ y1 = y - 1 ;
72
+ y2 = y + axis . cursorSize + 1 ;
75
73
if ( axis . position === 'left' ) {
76
- alignPctX = - 100
77
- alignPctY = - 50
74
+ x1 = siblingRange [ 0 ] ;
75
+ x2 = siblingRange [ 1 ] ;
76
+ alignPctX = - 100 ;
77
+ alignPctY = - 50 ;
78
78
} else {
79
- alignPctX = 0
80
- alignPctY = - 50
79
+ x1 = siblingRange [ 1 ] ;
80
+ x2 = siblingRange [ 0 ] ;
81
+ alignPctX = 0 ;
82
+ alignPctY = - 50 ;
81
83
}
82
84
} else {
83
- x = axis . scale ( latestValue )
84
- x1 = x - 1
85
- x2 = x + axis . cursorSize + 1
86
- y1 = siblingRange [ 0 ]
87
- y2 = siblingRange [ 1 ]
85
+ x = axis . scale ( latestValue ) ;
86
+ x1 = x - 1 ;
87
+ x2 = x + axis . cursorSize + 1 ;
88
88
if ( axis . position === 'top' ) {
89
- alignPctX = - 500
90
- alignPctY = - 100
89
+ y1 = siblingRange [ 0 ] ;
90
+ y2 = siblingRange [ 1 ] ;
91
+ alignPctX = - 500 ;
92
+ alignPctY = - 100 ;
91
93
} else {
92
- alignPctX = - 50
93
- alignPctY = 0
94
+ y1 = siblingRange [ 1 ] ;
95
+ y2 = siblingRange [ 0 ] ;
96
+ alignPctX = - 50 ;
97
+ alignPctY = 0 ;
94
98
}
95
99
}
96
100
97
- const renderProps = { ...cursor }
101
+ const renderProps = { ...cursor } ;
98
102
99
103
renderProps . formattedValue = String (
100
104
axis . vertical
@@ -112,30 +116,34 @@ export default function Cursor({ primary }) {
112
116
: latestValue
113
117
)
114
118
: ''
115
- )
119
+ ) ;
116
120
117
- const lineStartX = Math . min ( x1 , x2 )
118
- const lineStartY = Math . min ( y1 , y2 )
119
- const lineEndX = Math . max ( x1 , x2 )
120
- const lineEndY = Math . max ( y1 , y2 )
121
+ const lineStartX = Math . min ( x1 , x2 ) ;
122
+ const lineStartY = Math . min ( y1 , y2 ) ;
123
+ const lineEndX = Math . max ( x1 , x2 ) ;
124
+ const lineEndY = Math . max ( y1 , y2 ) ;
121
125
const bubbleX =
122
126
axis . vertical && axis . RTL
123
127
? lineEndX
124
- : x1 + ( ! axis . vertical ? ( x2 - x1 ) / 2 : 0 ) + ( ! axis . vertical ? 1 : 0 )
128
+ : x1 + ( ! axis . vertical ? ( x2 - x1 ) / 2 : 0 ) + ( ! axis . vertical ? 1 : 0 ) ;
125
129
const bubbleY =
126
130
! axis . vertical && axis . RTL
127
131
? lineStartY
128
- : y1 + ( axis . vertical ? ( y2 - y1 ) / 2 : 0 ) + ( axis . vertical ? 1 : 0 )
132
+ : y1 + ( axis . vertical ? ( y2 - y1 ) / 2 : 0 ) + ( axis . vertical ? 1 : 0 ) ;
129
133
130
- const lineHeight = Math . max ( lineEndY - lineStartY , 0 )
131
- const lineWidth = Math . max ( lineEndX - lineStartX , 0 )
134
+ // if (!axis.vertical) {
135
+ // console.log({ bubbleX, bubbleY });
136
+ // }
132
137
133
- let animateCoords
138
+ const lineHeight = Math . max ( lineEndY - lineStartY , 0 ) ;
139
+ const lineWidth = Math . max ( lineEndX - lineStartX , 0 ) ;
140
+
141
+ let animateCoords ;
134
142
if ( previousShowRef . current === resolvedShow ) {
135
- animateCoords = true
143
+ animateCoords = true ;
136
144
}
137
145
138
- let renderedChildren = render ( renderProps )
146
+ let renderedChildren = render ( renderProps ) ;
139
147
140
148
return (
141
149
< div
@@ -196,5 +204,5 @@ export default function Cursor({ primary }) {
196
204
</ div >
197
205
) : null }
198
206
</ div >
199
- )
207
+ ) ;
200
208
}
0 commit comments