@@ -5,19 +5,27 @@ import {initializer} from "../transforms/basic.js";
5
5
import { ruleX , ruleY } from "./rule.js" ;
6
6
import { text } from "./text.js" ;
7
7
8
- export function crosshair ( data , options = { } ) {
9
- const p = pointer ( { px : options . x , py : options . y } ) ;
10
- return marks ( pruleX ( data , p , options ) , pruleY ( data , p , options ) , ptextX ( data , p , options ) , ptextY ( data , p , options ) ) ;
8
+ export function crosshair ( data , options ) {
9
+ return crosshairK ( pointer , data , options ) ;
11
10
}
12
11
13
12
export function crosshairX ( data , options = { } ) {
14
- const p = pointerX ( { px : options . x } ) ;
15
- return marks ( pruleX ( data , p , options ) , ptextX ( data , p , options ) ) ;
13
+ return crosshairK ( pointerX , data , options ) ;
16
14
}
17
15
18
16
export function crosshairY ( data , options = { } ) {
19
- const p = pointerY ( { py : options . y } ) ;
20
- return marks ( pruleY ( data , p , options ) , ptextY ( data , p , options ) ) ;
17
+ return crosshairK ( pointerY , data , options ) ;
18
+ }
19
+
20
+ function crosshairK ( pointer , data , options = { } ) {
21
+ const { x, y, maxRadius} = options ;
22
+ const p = pointer ( { px : x , py : y , maxRadius} ) ;
23
+ return marks (
24
+ x == null ? null : ruleX ( data , ruleOptions ( "x" , p , options ) ) ,
25
+ y == null ? null : ruleY ( data , ruleOptions ( "y" , p , options ) ) ,
26
+ x == null ? null : text ( data , textOptions ( "x" , { ...p , dy : 9 , frameAnchor : "bottom" , lineAnchor : "top" } , options ) ) ,
27
+ y == null ? null : text ( data , textOptions ( "y" , { ...p , dx : - 9 , frameAnchor : "left" , textAnchor : "end" } , options ) )
28
+ ) ;
21
29
}
22
30
23
31
function markOptions (
@@ -55,14 +63,6 @@ function pxpy(k, i) {
55
63
} ;
56
64
}
57
65
58
- function pruleX ( data , pointerOptions , options ) {
59
- return ruleX ( data , ruleOptions ( "x" , pointerOptions , options ) ) ;
60
- }
61
-
62
- function pruleY ( data , pointerOptions , options ) {
63
- return ruleY ( data , ruleOptions ( "y" , pointerOptions , options ) ) ;
64
- }
65
-
66
66
function ruleOptions ( k , pointerOptions , options ) {
67
67
const {
68
68
color = "currentColor" ,
@@ -73,14 +73,6 @@ function ruleOptions(k, pointerOptions, options) {
73
73
return { ...markOptions ( k , pointerOptions , options ) , stroke, strokeOpacity, strokeWidth} ;
74
74
}
75
75
76
- function ptextX ( data , pointerOptions , options ) {
77
- return text ( data , textOptions ( "x" , { ...pointerOptions , dy : 9 , frameAnchor : "bottom" , lineAnchor : "top" } , options ) ) ;
78
- }
79
-
80
- function ptextY ( data , pointerOptions , options ) {
81
- return text ( data , textOptions ( "y" , { ...pointerOptions , dx : - 9 , frameAnchor : "left" , textAnchor : "end" } , options ) ) ;
82
- }
83
-
84
76
function textOptions ( k , pointerOptions , options ) {
85
77
const {
86
78
color = "currentColor" ,
0 commit comments