@@ -958,12 +958,14 @@ function createOrSelectGroup(root, name) {
958958
959959var intersectRect = require ( "./intersect/intersect-rect" ) ,
960960 intersectEllipse = require ( "./intersect/intersect-ellipse" ) ,
961- intersectCircle = require ( "./intersect/intersect-circle" ) ;
961+ intersectCircle = require ( "./intersect/intersect-circle" ) ,
962+ intersectPolygon = require ( "./intersect/intersect-polygon" ) ;
962963
963964module . exports = {
964965 rect : rect ,
965966 ellipse : ellipse ,
966- circle : circle
967+ circle : circle ,
968+ diamond : diamond
967969} ;
968970
969971function rect ( parent , bbox , node ) {
@@ -1012,7 +1014,29 @@ function circle(parent, bbox, node) {
10121014 return shapeSvg ;
10131015}
10141016
1015- } , { "./intersect/intersect-circle" :11 , "./intersect/intersect-ellipse" :12 , "./intersect/intersect-rect" :16 } ] , 25 :[ function ( require , module , exports ) {
1017+ // Circumscribe an ellipse for the bounding box with a diamond shape. I derived
1018+ // the function to calculate the diamond shape from:
1019+ // http://mathforum.org/kb/message.jspa?messageID=3750236
1020+ function diamond ( parent , bbox , node ) {
1021+ var w = ( bbox . width * Math . SQRT2 ) / 2 ,
1022+ h = ( bbox . height * Math . SQRT2 ) / 2 ,
1023+ points = [
1024+ { x : 0 , y : - h } ,
1025+ { x : - w , y : 0 } ,
1026+ { x : 0 , y : h } ,
1027+ { x : w , y : 0 }
1028+ ] ,
1029+ shapeSvg = parent . insert ( "polygon" , ":first-child" )
1030+ . attr ( "points" , points . map ( function ( p ) { return p . x + "," + p . y ; } ) . join ( " " ) ) ;
1031+
1032+ node . intersect = function ( p ) {
1033+ return intersectPolygon ( node , points , p ) ;
1034+ } ;
1035+
1036+ return shapeSvg ;
1037+ }
1038+
1039+ } , { "./intersect/intersect-circle" :11 , "./intersect/intersect-ellipse" :12 , "./intersect/intersect-polygon" :15 , "./intersect/intersect-rect" :16 } ] , 25 :[ function ( require , module , exports ) {
10161040var _ = require ( "./lodash" ) ;
10171041
10181042// Public utility functions
@@ -1069,7 +1093,7 @@ function applyTransition(selection, g) {
10691093}
10701094
10711095} , { "./lodash" :20 } ] , 26 :[ function ( require , module , exports ) {
1072- module . exports = "0.4.1 " ;
1096+ module . exports = "0.4.2 " ;
10731097
10741098} , { } ] , 27 :[ function ( require , module , exports ) {
10751099/*
0 commit comments