Rather than converting closed polygons to open polygons on input (which could
potentially be destructive), tweak the polygon methods slightly so that they
work on either input.
This commit also changes d3.geom.polygon to use a prototype, much like
d3.selection, rather than creating every method as a closure. This makes it much
faster to construct a polygon.
If you try to create a d3.geom.polygon with a closed polygon, it is now
automatically converted to an open polygon by stripping the closing coordinate.
Rather than return NaN, this change restores the previous undefined behavior
when an unorderable value is used for bisection. After discussing with Jason, I
think this is more consistent given that d3.bisect also requires that the input
array is sortable, and therefore only contains orderable values. Thus, it is the
responsibility of the caller to check that the search value is defined before
doing bisection, and so this commit fixes the threshold scale rather than the
bisect method. (Also, this is consistent with the existing quantile scale.)
In addition to NaN, which is not equal to itself, you can have objects that are
not orderable due to defined valueOf functions which return NaN. For example:
var o = new Number(NaN);
Here, o == o is true, but o <= o is false. Therefore it was possible for d3.min,
d3.max and d3.extent to observe these non-orderable values rather than ignore
them as intended. The fix is to check !(o <= o) rather than o == o.
This commit also fixes d3.bisect when the search value is non-orderable.
Previously, bisectLeft returned lo for non-orderable values, and bisectRight
returned hi. However, if the search value is non-orderable, then this return
value does not satisfy the conditions of bisection. This commit changes the
bisection methods to return NaN when the search value is non-orderable.
As a side-effect, the fix to d3.bisect now causes d3.scale.threshold to return
undefined when passed a non-orderable value, such as undefined. (Previously, a
threshold scale would return the highest value in the range, because it used
bisectRight internally.)
Fixes#857. By default, the radius of each circle in the pack layout is derived
from the square root of the node’s value, which is then scaled according to the
bounding box of all circles and the layout’s size. By specifying a radius
function, you can now explictly control the radius, disabling automatic scaling.
The radius function takes the value as input and returns the corresponding
radius. If no radius function is specified, automatic scaling is enabled; this
is the default. Conveniently, d3.scale.sqrt can be used as a radius function.
This generalises the centre of mass formula given in:
J. E. Brock, The Inertia Tensor for a Spherical Triangle,
J. Applied Mechanics 42, 239 (1975)
In addition, centroids of zero-extent features now fall back to the
centroid of the feature treated as a lower dimension, i.e. polygons →
lines → points.
Specifically, if the centroid of a polygon or multipolygon feature is
ambiguous, it will treat it as a set of lines. Similarly (but not
exactly the same), if a line or set of lines has zero length, it will be
treated as a set of points.
This also applies to d3.geo.path.centroid, except that the fallback
always occurs if the feature has zero extent (area or length). For
geographic polygons, it was simpler to fall back if the centroid was
undefined, as area is not tracked in a simple fashion.
Fixes#1011.
Optimised d3_acos, and used d3_asin and d3_acos where appropriate
instead of Math.min and Math.max.
The minimum sample interval is somewhat arbitrarily set to 16 × δ, where
δ is the Douglas–Peucker threshold. This fixes cases where resampling
stops too early due to the perpendicular distance being below the
threshold; particularly for points that are far apart and whose
great-circle arc is projected to an S-shape. The midpoint lies along a
straight line, failing the Douglas–Peucker check, but further resampling
produces an S-shape.
Ideally, resampling should also detect cases where an intermediate point
does not need to be drawn, i.e. where there truly is a straight line.
This fix causes points to be drawn at the minimum sample interval, and
thus may degrade performance slightly due to drawing redundant points.
Fixes#1162.
The performance difference seems quite small in V8, but perhaps this
will be more substantial in other browsers, and it should reduce garbage
collection at any rate, which this benchmark does not check thoroughly.
Benchmark, drawing one small circle (10,000 samples):
Old: 0.091ms.
New: 0.084ms.
Fixes#1258.
This fixes an error that would be thrown if no defined bounds were
found. It also ensures that undefined bounds are returned as
[[NaN, NaN], [NaN, NaN]], for consistency with d3.extent, which returns
[undefined, undefined] for an empty array.
Fixes#1154.
Commit d0441e6 introduced specifying the linear scale tick format as a string,
as by `axis.ticks(10, "%")`. This extends this pattern to log scales for
consistency.
This is a partial fix to #1245 whereby timer tasks are now invoked in the order
in which they were registered, rather than in the reverse order. However, a
better fix remains, which is to invoke tasks in the order of their start time
rather than their registration time.
Fixes#1263. Previously, if d3.json was used to load invalid JSON, a SyntaxError
would be thrown. Now an error is reported to the callback instead, in the same
manner as if a network error occurred. This allows the caller to handle the
invalid response, rather than throwing an asynchronous error.