1
- import React from 'react'
1
+ import React from 'react' ;
2
2
//
3
3
//
4
4
import {
5
5
groupingSeries ,
6
6
groupingPrimary ,
7
7
groupingSecondary ,
8
- } from '../utils/Constants'
8
+ } from '../utils/Constants' ;
9
9
10
- const showCount = 10
10
+ const showCount = 10 ;
11
11
12
12
function getSecondaryFormatter ( datum , formatSecondary ) {
13
13
return (
14
14
formatSecondary ||
15
15
datum . secondaryAxis . format ||
16
16
( val => ( Math . floor ( val ) < val ? Math . round ( val * 100 ) / 100 : val ) )
17
- )
17
+ ) ;
18
18
}
19
19
20
20
export default function TooltipRenderer ( props ) {
@@ -28,69 +28,69 @@ export default function TooltipRenderer(props) {
28
28
getStyle,
29
29
dark,
30
30
tooltip,
31
- } = props
31
+ } = props ;
32
32
33
33
if ( ! datum ) {
34
- return null
34
+ return null ;
35
35
}
36
36
37
37
const resolvedFormatTertiary =
38
38
formatTertiary ||
39
- ( val => ( Math . floor ( val ) < val ? Math . round ( val * 100 ) / 100 : val ) )
39
+ ( val => ( Math . floor ( val ) < val ? Math . round ( val * 100 ) / 100 : val ) ) ;
40
40
41
41
const sortedGroupDatums = [ ...datum . group ] . sort ( ( a , b ) => {
42
42
if (
43
43
( ! primaryAxis . stacked && grouping === groupingSeries ) ||
44
44
grouping === groupingSecondary
45
45
) {
46
46
if ( a . primaryCoord > b . primaryCoord ) {
47
- return - 1
47
+ return - 1 ;
48
48
} else if ( a . primaryCoord < b . primaryCoord ) {
49
- return 1
49
+ return 1 ;
50
50
}
51
51
} else if ( ! secondaryAxis . stacked ) {
52
52
if ( a . secondaryCoord > b . secondaryCoord ) {
53
- return - 1
53
+ return - 1 ;
54
54
} else if ( a . secondaryCoord < b . secondaryCoord ) {
55
- return 1
55
+ return 1 ;
56
56
}
57
57
}
58
- return a . seriesIndex > b . seriesIndex ? 1 : - 1
59
- } )
58
+ return a . seriesIndex > b . seriesIndex ? 1 : - 1 ;
59
+ } ) ;
60
60
61
61
if ( grouping === groupingPrimary ) {
62
- sortedGroupDatums . reverse ( )
62
+ sortedGroupDatums . reverse ( ) ;
63
63
}
64
64
65
65
if ( secondaryAxis . invert ) {
66
- sortedGroupDatums . reverse ( )
66
+ sortedGroupDatums . reverse ( ) ;
67
67
}
68
68
69
69
if ( tooltip . invert ) {
70
- sortedGroupDatums . reverse ( )
70
+ sortedGroupDatums . reverse ( ) ;
71
71
}
72
72
73
- const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1
74
- const length = sortedGroupDatums . length
73
+ const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1 ;
74
+ const length = sortedGroupDatums . length ;
75
75
76
76
// Get the focused series' index
77
- const activeIndex = sortedGroupDatums . findIndex ( d => d === datum )
77
+ const activeIndex = sortedGroupDatums . findIndex ( d => d === datum ) ;
78
78
// Get the start by going back half of the showCount
79
- let start = activeIndex > - 1 ? activeIndex - resolvedShowCount / 2 : 0
79
+ let start = activeIndex > - 1 ? activeIndex - resolvedShowCount / 2 : 0 ;
80
80
// Make sure it's at least 0
81
- start = Math . max ( start , 0 )
81
+ start = Math . max ( start , 0 ) ;
82
82
// Use the start and add the showCount to get the end
83
- let end = activeIndex > - 1 ? start + resolvedShowCount : length
83
+ let end = activeIndex > - 1 ? start + resolvedShowCount : length ;
84
84
// Don't let the end go passed the length
85
- end = Math . min ( end , length )
85
+ end = Math . min ( end , length ) ;
86
86
// Double check we aren't clipping the start
87
- start = Math . max ( end - resolvedShowCount , 0 )
87
+ start = Math . max ( end - resolvedShowCount , 0 ) ;
88
88
// Slice the datums by start and end
89
- const visibleSortedGroupDatums = sortedGroupDatums . slice ( start , end )
89
+ const visibleSortedGroupDatums = sortedGroupDatums . slice ( start , end ) ;
90
90
// Detect if we have previous items
91
- const hasPrevious = start > 0
91
+ const hasPrevious = start > 0 ;
92
92
// Or next items
93
- const hasNext = end < length
93
+ const hasNext = end < length ;
94
94
95
95
return (
96
96
< div >
@@ -126,11 +126,11 @@ export default function TooltipRenderer(props) {
126
126
</ tr >
127
127
) : null }
128
128
{ visibleSortedGroupDatums . map ( ( sortedDatum , i ) => {
129
- const active = sortedDatum === datum
129
+ const active = sortedDatum === datum ;
130
130
const resolvedSecondaryFormat = getSecondaryFormatter (
131
131
sortedDatum ,
132
132
formatSecondary
133
- )
133
+ ) ;
134
134
135
135
return (
136
136
< tr
@@ -169,7 +169,10 @@ export default function TooltipRenderer(props) {
169
169
textAlign : 'right' ,
170
170
} }
171
171
>
172
- { resolvedSecondaryFormat ( sortedDatum . secondary ) }
172
+ { resolvedSecondaryFormat (
173
+ sortedDatum . secondary ,
174
+ sortedDatum
175
+ ) }
173
176
{ sortedDatum . r
174
177
? ` (${ resolvedFormatTertiary ( sortedDatum . r ) } )`
175
178
: null }
@@ -197,15 +200,18 @@ export default function TooltipRenderer(props) {
197
200
textAlign : 'right' ,
198
201
} }
199
202
>
200
- { resolvedSecondaryFormat ( sortedDatum . secondary ) }
203
+ { resolvedSecondaryFormat (
204
+ sortedDatum . secondary ,
205
+ sortedDatum
206
+ ) }
201
207
{ sortedDatum . r
202
208
? ` (${ resolvedFormatTertiary ( sortedDatum . r ) } )`
203
209
: null }
204
210
</ td >
205
211
</ React . Fragment >
206
212
) }
207
213
</ tr >
208
- )
214
+ ) ;
209
215
} ) }
210
216
{ hasNext ? (
211
217
< tr
@@ -255,5 +261,5 @@ export default function TooltipRenderer(props) {
255
261
</ tbody >
256
262
</ table >
257
263
</ div >
258
- )
264
+ ) ;
259
265
}
0 commit comments