@@ -5,19 +5,27 @@ import {initializer} from "../transforms/basic.js";
55import { ruleX , ruleY } from "./rule.js" ;
66import { text } from "./text.js" ;
77
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 ) ;
1110}
1211
1312export 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 ) ;
1614}
1715
1816export 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+ ) ;
2129}
2230
2331function markOptions (
@@ -55,14 +63,6 @@ function pxpy(k, i) {
5563 } ;
5664}
5765
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-
6666function ruleOptions ( k , pointerOptions , options ) {
6767 const {
6868 color = "currentColor" ,
@@ -73,14 +73,6 @@ function ruleOptions(k, pointerOptions, options) {
7373 return { ...markOptions ( k , pointerOptions , options ) , stroke, strokeOpacity, strokeWidth} ;
7474}
7575
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-
8476function textOptions ( k , pointerOptions , options ) {
8577 const {
8678 color = "currentColor" ,
0 commit comments