README
d3plusshape
Fancy SVG shapes for visualizations
Installing
If you use NPM, npm install d3plusshape
. Otherwise, download the latest release. You can also load d3plusshape as a standalone library or as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus
global is exported:
<script src="https://cdn.jsdelivr.net/npm/d3plusshape@1"></script>
<script>
console.log(d3plus);
</script>
API Reference
 largestRect  An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or 90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between 90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.
 lineIntersection  Finds the intersection point (if there is one) of the lines p1q1 and p2q2.
 path2polygon  Transforms a path string into an Array of points.
 pointDistance  Calculates the pixel distance between two points.
 pointDistanceSquared  Returns the squared euclidean distance between two points.
 pointRotate  Rotates a point around a given origin.
 polygonInside  Checks if one polygon is inside another polygon.
 polygonRayCast  Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.
 polygonRotate  Rotates a point around a given origin.
 segmentBoxContains  Checks whether a point is inside the bounding box of a line segment.
 segmentsIntersect  Checks whether the line segments p1q1 && p2q2 intersect.
 shapeEdgePoint  Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.
 largestRect  Simplifies the points of a polygon using both the RamerDouglasPeucker algorithm and basic distancebased simplification. Adapted to an ES6 module from the excellent Simplify.js.
<>
ImageThis is a global class.
# new Image()
Creates SVG images based on an array of data.
a sample row of data
var data = {"url": "file.png", "width": "100", "height": "50"};
passed to the generator
new Image().data([data]).render();
creates the following
<image class="d3plusImage" opacity="1" href="file.png" width="100" height="50" x="0" y="0"></image>
this is shorthand for the following
image().data([data])();
which also allows a postdraw callback function
image().data([data])(function() { alert("draw complete!"); })
Renders the current Image to the page. If a callback is specified, it will be called once the images are done drawing.
This is a static method of Image
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array. An tag will be drawn for each object in the array.
This is a static method of Image
, and is chainable with other methods of this Class.
If ms is specified, sets the animation duration to the specified number and returns the current class instance. If ms is not specified, returns the current animation duration.
This is a static method of Image
, and is chainable with other methods of this Class.
If value is specified, sets the height accessor to the specified function or number and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.height;
}
If value is specified, sets the id accessor to the specified function and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.id;
}
Sets the opacity of the image.
This is a static method of Image
, and is chainable with other methods of this Class.
# Image.pointerEvents([value]) <>
If value is specified, sets the pointerevents accessor to the specified function or string and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of Image
, and is chainable with other methods of this Class.
If value is specified, sets the URL accessor to the specified function and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.url;
}
If value is specified, sets the width accessor to the specified function or number and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.width;
}
If value is specified, sets the x accessor to the specified function or number and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.x  0;
}
If value is specified, sets the y accessor to the specified function or number and returns the current class instance.
This is a static method of Image
, and is chainable with other methods of this Class.
function(d) {
return d.y  0;
}
<>
AreaThis is a global class, and extends all of the methods and functionality of Shape
.
 Area ⇐
Shape
 new Area()
 .render([callback]) ↩︎
 .curve([value]) ↩︎
 .defined([value]) ↩︎
 .x([value]) ↩︎
 .x0([value]) ↩︎
 .x1([value]) ↩︎
 .y([value]) ↩︎
 .y0([value]) ↩︎
 .y1([value]) ↩︎
# new Area()
Creates SVG areas based on an array of data.
Draws the area polygons.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the area curve to the specified string and returns the current class instance. If value is not specified, returns the current area curve.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the defined accessor to the specified function and returns the current class instance. If value is not specified, returns the current defined accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the x accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current x accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the x0 accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current x0 accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the x1 accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current x1 accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the y accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current y accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the y0 accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current y0 accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
If value is specified, sets the y1 accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current y1 accessor.
This is a static method of Area
, and is chainable with other methods of this Class.
<>
BarThis is a global class, and extends all of the methods and functionality of Shape
.
 Bar ⇐
Shape
 new Bar()
 .render([callback]) ↩︎
 .height([value]) ↩︎
 .width([value]) ↩︎
 .x0([value]) ↩︎
 .x1([value]) ↩︎
 .y0([value]) ↩︎
 .y1([value]) ↩︎
# new Bar()
Creates SVG areas based on an array of data.
Draws the bars.
This is a static method of Bar
, and is chainable with other methods of this Class.
If value is specified, sets the height accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
function(d) {
return d.height;
}
If value is specified, sets the width accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
function(d) {
return d.width;
}
If value is specified, sets the x0 accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
If value is specified, sets the x1 accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
If value is specified, sets the y0 accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
If value is specified, sets the y1 accessor to the specified function or number and returns the current class instance.
This is a static method of Bar
, and is chainable with other methods of this Class.
<>
BoxThis is a global class, and extends all of the methods and functionality of BaseClass
.
 Box ⇐
BaseClass
 new Box()
 .render([callback]) ↩︎
 .active([value]) ↩︎
 .data([data]) ↩︎
 .hover([value]) ↩︎
 .medianConfig([value]) ↩︎
 .orient([value]) ↩︎
 .outlier(_) ↩︎
 .outlierConfig([value]) ↩︎
 .rectConfig([value]) ↩︎
 .rectWidth([value]) ↩︎
 .select([selector]) ↩︎
 .whiskerConfig([value]) ↩︎
 .whiskerMode([value]) ↩︎
 .x([value]) ↩︎
 .y([value]) ↩︎
# new Box()
Creates SVG box based on an array of data.
Draws the Box.
This is a static method of Box
, and is chainable with other methods of this Class.
Sets the highlight accessor to the Shape class's active function.
This is a static method of Box
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array.
This is a static method of Box
, and is chainable with other methods of this Class.
Sets the highlight accessor to the Shape class's hover function.
This is a static method of Box
, and is chainable with other methods of this Class.
# Box.medianConfig([value]) <>
If value is specified, sets the config method for median and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
If value is specified, sets the orientation to the specified value. If value is not specified, returns the current orientation.
This is a static method of Box
, and is chainable with other methods of this Class.
If value is specified, sets the outlier accessor to the specified function or string and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
# Box.outlierConfig([value]) <>
If value is specified, sets the config method for each outlier point and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
If value is specified, sets the config method for rect shape and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
If value is specified, sets the width accessor to the specified function or number and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
function(d) {
return d.width;
}
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of Box
, and is chainable with other methods of this Class.
# Box.whiskerConfig([value]) <>
If value is specified, sets the config method for whisker and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
Determines the value used for each whisker. Can be passed a single value to apply for both whiskers, or an Array of 2 values for the lower and upper whiskers (in that order). Accepted values are "tukey"
, "extent"
, or a Number representing a quantile.
This is a static method of Box
, and is chainable with other methods of this Class.
If value is specified, sets the x axis to the specified function or number and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
function(d) {
return d.x;
}
If value is specified, sets the y axis to the specified function or number and returns the current class instance.
This is a static method of Box
, and is chainable with other methods of this Class.
function(d) {
return d.y;
}
<>
CircleThis is a global class, and extends all of the methods and functionality of Shape
.
# new Circle()
Creates SVG circles based on an array of data.
# Circle.render([callback]) <>
Draws the circles.
This is a static method of Circle
, and is chainable with other methods of this Class.
If value is specified, sets the radius accessor to the specified function or number and returns the current class instance.
This is a static method of Circle
, and is chainable with other methods of this Class.
function(d) {
return d.r;
}
<>
LineThis is a global class, and extends all of the methods and functionality of Shape
.
# new Line()
Creates SVG lines based on an array of data.
Draws the lines.
This is a static method of Line
, and is chainable with other methods of this Class.
If value is specified, sets the area curve to the specified string and returns the current class instance. If value is not specified, returns the current area curve.
This is a static method of Line
, and is chainable with other methods of this Class.
If value is specified, sets the defined accessor to the specified function and returns the current class instance. If value is not specified, returns the current defined accessor.
This is a static method of Line
, and is chainable with other methods of this Class.
<>
PathThis is a global class, and extends all of the methods and functionality of Shape
.
# new Path()
Creates SVG Paths based on an array of data.
Draws the paths.
This is a static method of Path
, and is chainable with other methods of this Class.
If value is specified, sets the "d" attribute accessor to the specified function or number and returns the current class instance.
This is a static method of Path
, and is chainable with other methods of this Class.
function(d) {
return d.path;
}
<>
RectThis is a global class, and extends all of the methods and functionality of Shape
.
# new Rect()
Creates SVG rectangles based on an array of data. See this example for help getting started using the rectangle generator.
Draws the rectangles.
This is a static method of Rect
, and is chainable with other methods of this Class.
If value is specified, sets the height accessor to the specified function or number and returns the current class instance.
This is a static method of Rect
, and is chainable with other methods of this Class.
function(d) {
return d.height;
}
If value is specified, sets the width accessor to the specified function or number and returns the current class instance.
This is a static method of Rect
, and is chainable with other methods of this Class.
function(d) {
return d.width;
}
<>
ShapeThis is a global class, and extends all of the methods and functionality of BaseClass
.
 Shape ⇐
BaseClass
 new Shape()
 .render([callback]) ↩︎
 .active([value]) ↩︎
 .activeOpacity(value) ↩︎
 .activeStyle(value) ↩︎
 .ariaLabel(value) ↩︎
 .backgroundImage([value]) ↩︎
 .data([data]) ↩︎
 .discrete(value) ↩︎
 .duration([ms]) ↩︎
 .fill([value]) ↩︎
 .fillOpacity([value]) ↩︎
 .hover([value]) ↩︎
 .hoverStyle(value) ↩︎
 .hoverOpacity([value]) ↩︎
 .hitArea([bounds]) ↩︎
 .id([value]) ↩︎
 .label([value]) ↩︎
 .labelBounds([bounds]) ↩︎
 .labelConfig([value]) ↩︎
 .opacity([value]) ↩︎
 .pointerEvents([value]) ↩︎
 .role(value) ↩︎
 .rotate([value]) ↩︎
 .rx([value]) ↩︎
 .ry([value]) ↩︎
 .scale([value]) ↩︎
 .select([selector]) ↩︎
 .shapeRendering([value]) ↩︎
 .sort([value]) ↩︎
 .stroke([value]) ↩︎
 .strokeDasharray([value]) ↩︎
 .strokeLinecap([value]) ↩︎
 .strokeOpacity([value]) ↩︎
 .strokeWidth([value]) ↩︎
 .textAnchor([value]) ↩︎
 .vectorEffect([value]) ↩︎
 .verticalAlign([value]) ↩︎
 .x([value]) ↩︎
 .y([value]) ↩︎
# new Shape()
An abstracted class for generating shapes.
Renders the current Shape to the page. If a callback is specified, it will be called once the shapes are done drawing.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the highlight accessor to the specified function and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.activeOpacity(value) <>
When shapes are active, this is the opacity of any shape that is not active.
This is a static method of Shape
, and is chainable with other methods of this Class.
The style to apply to active shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the arialabel attribute to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.backgroundImage([value]) <>
If value is specified, sets the backgroundimage accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array. A shape will be drawn for each object in the array.
This is a static method of Shape
, and is chainable with other methods of this Class.
Determines if either the X or Y position is discrete along a Line, which helps in determining the nearest data point on a line for a hit area event.
This is a static method of Shape
, and is chainable with other methods of this Class.
If ms is specified, sets the animation duration to the specified number and returns the current class instance. If ms is not specified, returns the current animation duration.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the fill accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.fillOpacity([value]) <>
Defines the "fillopacity" attribute for the shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the highlight accessor to the specified function and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
The style to apply to hovered shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.hoverOpacity([value]) <>
If value is specified, sets the hover opacity to the specified function and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If bounds is specified, sets the mouse hit area to the specified function and returns the current class instance. If bounds is not specified, returns the current mouse hit area accessor.
This is a static method of Shape
, and is chainable with other methods of this Class.
function(d, i, shape) {
return {
"width": shape.width,
"height": shape.height,
"x": shape.width / 2,
"y": shape.height / 2
};
}
If value is specified, sets the id accessor to the specified function and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the label accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.labelBounds([bounds]) <>
If bounds is specified, sets the label bounds to the specified function and returns the current class instance. If bounds is not specified, returns the current inner bounds accessor.
This is a static method of Shape
, and is chainable with other methods of this Class.
function(d, i, shape) {
return {
"width": shape.width,
"height": shape.height,
"x": shape.width / 2,
"y": shape.height / 2
};
}
# Shape.labelConfig([value]) <>
A passthrough to the config method of the TextBox class used to create a shape's labels.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the opacity accessor to the specified function or number and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.pointerEvents([value]) <>
If value is specified, sets the pointerEvents accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the role attribute to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the rotate accessor to the specified function or number and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
Defines the "rx" attribute for the shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
Defines the "rx" attribute for the shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the scale accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.shapeRendering([value]) <>
If value is specified, sets the shaperendering accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
function(d) {
return d.x;
}
If value is specified, sets the sort comparator to the specified function and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the stroke accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.strokeDasharray([value]) <>
Defines the "strokedasharray" attribute for the shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.strokeLinecap([value]) <>
Defines the "strokelinecap" attribute for the shapes. Accepted values are "butt"
, "round"
, and "square"
.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.strokeOpacity([value]) <>
Defines the "strokeopacity" attribute for the shapes.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.strokeWidth([value]) <>
If value is specified, sets the strokewidth accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.textAnchor([value]) <>
If value is specified, sets the textanchor accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.vectorEffect([value]) <>
If value is specified, sets the vectoreffect accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
# Shape.verticalAlign([value]) <>
If value is specified, sets the vertical alignment accessor to the specified function or string and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
If value is specified, sets the x accessor to the specified function or number and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
function(d) {
return d.x;
}
If value is specified, sets the y accessor to the specified function or number and returns the current class instance.
This is a static method of Shape
, and is chainable with other methods of this Class.
function(d) {
return d.y;
}
<>
WhiskerThis is a global class, and extends all of the methods and functionality of BaseClass
.
 Whisker ⇐
BaseClass
# new Whisker()
Creates SVG whisker based on an array of data.
# Whisker.render([callback]) <>
Draws the whisker.
This is a static method of Whisker
, and is chainable with other methods of this Class.
Sets the highlight accessor to the Shape class's active function.
This is a static method of Whisker
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array.
This is a static method of Whisker
, and is chainable with other methods of this Class.
If value is specified, sets the endpoint accessor to the specified function or string and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
# Whisker.endpointConfig([value]) <>
If value is specified, sets the config method for each endpoint and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
Sets the highlight accessor to the Shape class's hover function.
This is a static method of Whisker
, and is chainable with other methods of this Class.
If value is specified, sets the length accessor for whisker and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
# Whisker.lineConfig([value]) <>
If value is specified, sets the config method for line shape and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
If value is specified, sets the orientation to the specified value. If value is not specified, returns the current orientation.
This is a static method of Whisker
, and is chainable with other methods of this Class.
# Whisker.select([selector]) <>
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of Whisker
, and is chainable with other methods of this Class.
If value is specified, sets the x axis to the specified function or number and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
function(d) {
return d.x;
}
If value is specified, sets the y axis to the specified function or number and returns the current class instance.
This is a static method of Whisker
, and is chainable with other methods of this Class.
function(d) {
return d.y;
}
<>
d3plus.largestRect(poly, [options])An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or 90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between 90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.
This is a global function. Author: Daniel Smilkov [dsmilkov@gmail.com]
Param  Type  Default  Description 

poly  Array 
An Array of points that represent a polygon.  
[options]  Object 
An Object that allows for overriding various parameters of the algorithm.  
[options.angle]  Number  String  Array 
d3.range(90, 95, 5) 
The allowed rotations of the final rectangle. 
[options.aspectRatio]  Number  String  Array 
The ratio between the width and height of the rectangle. The value can be a number, a string which is parsed to a number, or an array of numbers specifying the possible aspect ratios of the final rectangle.  
[options.maxAspectRatio]  Number 
15 
The maximum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided. 
[options.minAspectRatio]  Number 
1 
The minimum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided. 
[options.nTries]  Number 
20 
The number of randomly drawn points inside the polygon which the algorithm explores as possible center points of the maximal rectangle. 
[options.minHeight]  Number 
0 
The minimum height of the rectangle. 
[options.minWidth]  Number 
0 
The minimum width of the rectangle. 
[options.tolerance]  Number 
0.02 
The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification. 
[options.origin]  Array 
The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.  
[options.cache]  Boolean 
Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time. 
<>
d3plus.lineIntersection(p1, q1, p2, q2)Finds the intersection point (if there is one) of the lines p1q1 and p2q2.
This is a global function.
Param  Type  Description 

p1  Array 
The first point of the first line segment, which should always be an [x, y] formatted Array. 
q1  Array 
The second point of the first line segment, which should always be an [x, y] formatted Array. 
p2  Array 
The first point of the second line segment, which should always be an [x, y] formatted Array. 
q2  Array 
The second point of the second line segment, which should always be an [x, y] formatted Array. 
<>
d3plus.path2polygon(path, [segmentLength])Transforms a path string into an Array of points.
This is a global function.
Param  Type  Default  Description 

path  String 
An SVG string path, commonly the "d" property of a 

[segmentLength]  Number 
20 
The lenght of line segments when converting curves line segments. Higher values lower computation time, but will result in curves that are more rigid. 
<>
d3plus.pointDistance(p1, p2)Calculates the pixel distance between two points.
This is a global function.
Param  Type  Description 

p1  Array 
The first point, which should always be an [x, y] formatted Array. 
p2  Array 
The second point, which should always be an [x, y] formatted Array. 
<>
d3plus.pointDistanceSquared(p1, p2)Returns the squared euclidean distance between two points.
This is a global function.
Param  Type  Description 

p1  Array 
The first point, which should always be an [x, y] formatted Array. 
p2  Array 
The second point, which should always be an [x, y] formatted Array. 
<>
d3plus.pointRotate(p, alpha, [origin])Rotates a point around a given origin.
This is a global function.
Param  Type  Default  Description 

p  Array 
The point to be rotated, which should always be an [x, y] formatted Array. 

alpha  Number 
The angle in radians to rotate.  
[origin]  Array 
[0, 0] 
The origin point of the rotation, which should always be an [x, y] formatted Array. 
<>
d3plus.polygonInside(polyA, polyB)Checks if one polygon is inside another polygon.
This is a global function.
Param  Type  Description 

polyA  Array 
An Array of [x, y] points to be used as the inner polygon, checking if it is inside polyA. 
polyB  Array 
An Array of [x, y] points to be used as the containing polygon. 
<>
d3plus.polygonRayCast(poly, origin, [alpha])Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.
This is a global function.
Returns: Array
 An array containing two values, the closest point on the left and the closest point on the right. If either point cannot be found, that value will be null
.
Param  Type  Default  Description 

poly  Array 
The polygon to test against, which should be an [x, y] formatted Array. 

origin  Array 
The origin point of the ray to be cast, which should be an [x, y] formatted Array. 

[alpha]  Number 
0 
The angle in radians of the ray. 
<>
d3plus.polygonRotate(poly, alpha, [origin])Rotates a point around a given origin.
This is a global function.
Param  Type  Default  Description 

poly  Array 
The polygon to be rotated, which should be an Array of [x, y] values. 

alpha  Number 
The angle in radians to rotate.  
[origin]  Array 
[0, 0] 
The origin point of the rotation, which should be an [x, y] formatted Array. 
<>
d3plus.segmentBoxContains(s1, s2, p)Checks whether a point is inside the bounding box of a line segment.
This is a global function.
Param  Type  Description 

s1  Array 
The first point of the line segment to be used for the bounding box, which should always be an [x, y] formatted Array. 
s2  Array 
The second point of the line segment to be used for the bounding box, which should always be an [x, y] formatted Array. 
p  Array 
The point to be checked, which should always be an [x, y] formatted Array. 
<>
d3plus.segmentsIntersect(p1, q1, p2, q2)Checks whether the line segments p1q1 && p2q2 intersect.
This is a global function.
Param  Type  Description 

p1  Array 
The first point of the first line segment, which should always be an [x, y] formatted Array. 
q1  Array 
The second point of the first line segment, which should always be an [x, y] formatted Array. 
p2  Array 
The first point of the second line segment, which should always be an [x, y] formatted Array. 
q2  Array 
The second point of the second line segment, which should always be an [x, y] formatted Array. 
<>
d3plus.shapeEdgePoint(angle, distance)Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.
This is a global function.
Returns: String
 [shape = "circle"] The type of shape, which can be either "circle" or "square".
Param  Type  Description 

angle  Number 
The angle, in radians, of the offset point. 
distance  Number 
The pixel distance away from the origin. 
<>
d3plus.largestRect(poly, [tolerance], [highestQuality])Simplifies the points of a polygon using both the RamerDouglasPeucker algorithm and basic distancebased simpl