@@ -48,26 +48,38 @@ export class Pointer extends Mark {
4848 . call ( applyDirectStyles , this )
4949 . node ( ) ;
5050
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+
5170 // 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
5372 // changed, and false otherwise.
5473 function render ( S ) {
5574 const SC = [ ] ;
5675 let changed = false ;
5776
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
5978 // arbitrary, with the most recently selected datum on top.
6079 S . forEach ( i => {
6180 let c = C [ i ] ;
6281 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 ) ;
7183 parent . appendChild ( c ) ;
7284 changed = true ;
7385 }
0 commit comments