@@ -48,26 +48,38 @@ export class Pointer extends Mark {
48
48
. call ( applyDirectStyles , this )
49
49
. node ( ) ;
50
50
51
+ // Note that point scales also expose a bandwidth function, but that always
52
+ // returns zero. SVG will not render a stroked rect with zero width or
53
+ // height, so we’ll render these as lines instead.
54
+ const bx = x ?. bandwidth ?. ( ) ;
55
+ const by = y ?. bandwidth ?. ( ) ;
56
+
57
+ // The visual representation of the logical selection depends on which
58
+ // channels are available (x, y, or both) and whether the corresponding
59
+ // scales are band scales.
60
+ const createElement = X && Y
61
+ ? ( bx && by ? i => element ( "rect" , { x : X [ i ] , y : Y [ i ] , width : bx , height : by } )
62
+ : bx ? i => element ( "line" , { x1 : X [ i ] , x2 : X [ i ] + bx , y1 : Y [ i ] , y2 : Y [ i ] } )
63
+ : by ? i => element ( "line" , { x1 : X [ i ] , x2 : X [ i ] , y1 : Y [ i ] , y2 : Y [ i ] + by } )
64
+ : i => element ( "circle" , { cx : X [ i ] , cy : Y [ i ] , r : 4 } ) )
65
+ : X ? ( bx ? i => element ( "rect" , { x : X [ i ] , y : marginTop , width : bx , height : height - marginBottom - marginTop } )
66
+ : i => element ( "line" , { x1 : X [ i ] , x2 : X [ i ] , y1 : marginTop , y2 : height - marginBottom } ) )
67
+ : ( by ? i => element ( "rect" , { x : marginLeft , y : Y [ i ] , width : width - marginRight - marginLeft , height : by } )
68
+ : i => element ( "line" , { y1 : Y [ i ] , y2 : Y [ i ] , x1 : marginLeft , x2 : width - marginRight } ) ) ;
69
+
51
70
// Renders the given logical selection S, a subset of index. Applies
52
- // copy-on-write to the array of circles C. Returns true if the selection
71
+ // copy-on-write to the array of elements C. Returns true if the selection
53
72
// changed, and false otherwise.
54
73
function render ( S ) {
55
74
const SC = [ ] ;
56
75
let changed = false ;
57
76
58
- // Enter (append) the newly-selected elements. The order of the circles is
77
+ // Enter (append) the newly-selected elements. The order of elements is
59
78
// arbitrary, with the most recently selected datum on top.
60
79
S . forEach ( i => {
61
80
let c = C [ i ] ;
62
81
if ( ! c ) {
63
- c = X && Y ? ( x . bandwidth && y . bandwidth ? element ( "rect" , { x : X [ i ] , y : Y [ i ] , width : x . bandwidth ( ) , height : y . bandwidth ( ) } )
64
- : x . bandwidth ? element ( "line" , { x1 : X [ i ] , x2 : X [ i ] + x . bandwidth ( ) , y1 : Y [ i ] , y2 : Y [ i ] } )
65
- : y . bandwidth ? element ( "line" , { x1 : X [ i ] , x2 : X [ i ] , y1 : Y [ i ] , y2 : Y [ i ] + y . bandwidth ( ) } )
66
- : element ( "circle" , { cx : X [ i ] , cy : Y [ i ] , r : 4 } ) )
67
- : X ? ( x . bandwidth ? element ( "rect" , { x : X [ i ] , y : marginTop , width : x . bandwidth ( ) , height : height - marginBottom - marginTop } )
68
- : element ( "line" , { x1 : X [ i ] , x2 : X [ i ] , y1 : marginTop , y2 : height - marginBottom } ) )
69
- : ( y . bandwidth ? element ( "rect" , { x : marginLeft , y : Y [ i ] , width : width - marginRight - marginLeft , height : y . bandwidth ( ) } )
70
- : element ( "line" , { y1 : Y [ i ] , y2 : Y [ i ] , x1 : marginLeft , x2 : width - marginRight } ) ) ;
82
+ c = createElement ( i ) ;
71
83
parent . appendChild ( c ) ;
72
84
changed = true ;
73
85
}
0 commit comments