You can now specify the domain of the quadtree upon construction, such that you
can add points to the quadtree dynamically later. The quadtree example now also
shows how to do a quick rectangular search using the quadtree.
This commit adds a new static function for computing the extent (min and max) of
a scale's domain, simplifying the logic in the ticks functions and ensuring
standard behavior (such as repeated values). Also, the linear ticks function is
extracted for reuse by the pow scale.
I opted not to reverse the tick order for descending domains; this might be nice
but it doesn't seem required, so we might as well keep the code small.
There's already a tension parameter, and it seems reasonable to overload this
parameter (originally intended for cardinal splines) to also apply to bundle
splines. The new "bundle" interpolation is identical to "basis" interpolation;
the only difference is that the tension parameter is used to straighten the
basis spline.
The input to the layout is now an array of edges to bundle, rather than nodes.
This eliminates the need for an `outgoing` accessor, since the links are passed
to the bundle layout directly.
The svg line generator now supports a beta (straightening; bundle strength)
parameter. I haven't decided if this is the right place or the right name for
it, but it seems like a reasonable starting point. I'm not happy with the cos &
sin needed to produce radial lines (both here and for the diagonal projection in
other examples), but I don't have a good alternative yet.
This commit also tries to make the construction of the links from the layout
nodes a bit easier to follow. The previous code was used another intermediate
representation, and I think it's cleaner to construct the default format
expected by the layouts. However, there's still a good chunk of code required to
massage the JSON format into a node hierarchy and array of dependencies, so I'd
like to find a way to simplify that, too.
Previously, if you instantiated the enter selection via append or insert, you'd
have to re-select to unify the enter and update selection (the post-transform
nodes). Now, simply by appending or inserting the entering nodes, the update
selection automatically refreshes, obviating the need for a reselect. If you
still want to perform actions only on the updating nodes, you can do so by
performing these actions before instantiating the enter selection.
This way, people can play with superformulas if they want them, but we keep the
core library small. If we want to replace the default symbol implementation with
superformulas in the future, we can do that too. For now, be conservative.
This is useful when other modules want to register interpolators for
d3.interpolate without adding an explicit dependency to d3.core. The
interpolators are applied in reverse order, and the first one that returns
a function is used.
(This commit was authored by @jasondavies and cherry picked.)
If the tween function returns null, then no tween will be applied for the
specified element. The default tween function now returns null if the start and
end value are the same, thus avoiding redundant interpolation.
We can't just rebind the internal linear scale's nice function because the
linear scale's domain is the exponentiated pow domain, so the actual pow domain
would most likely be fractional as the linear scale will round to the nearest
integer exponentiation.
Based on the Protovis implementation. Includes tests. I'm not sure [10.9, 1.1]
should be "niced" to [10, 10] but this is also the behaviour in Protovis at the
moment.
Unlike Math.min and Math.max, it doesn't make sense to return negative or
positive infinity for d3.min and d3.max; the D3 functions return the minimum
value according to an arbitrary ordering, not by numeric value. Instead, the
minimum or maximum of an empty array, or an array that contains only degenerate
values, should always be undefined.
* The returned array should be truncated to the length of the shortest argument.
* With no arguments it should return an empty array.
I've updated the unit tests to be more verbose to detect the array of
single-element arrays returned for a single argument.
I removed the `F`, `G` and `E` types, since these are redundant and we don't
have to be slavishly-compatible with Python. Also, I simplified the
implementation of `g`, `e` and `f` so that they use JavaScript's built-in
`toPrecision`, `toExponential` and `toFixed`, respectively. The existing
implementations weren't exactly compatible with Python, anyway, so we might as
well default to using JavaScript's built-ins.
This is similar to pv.search, but more closely modeled after Python's bisect
methods to provide the desired flexibility in searching slices of arrays. This
includes good tests for bisect, and better tests for polylinear and quantile
scales (both of which now use bisect).
`F` is an alias for `f`. `r` is a new format type that rounds the input number,
treating the precision field as the desired number of significant digits. This
is similar to `g`, except it never uses exponent notation. `p` is equivalent to
`r`, except it outputs a percentage, as with `%`.
* "e": exponent notation.
* "E": same as "e", except uses "E" as a separator.
* "g": precision is interpreted as signficant digits.
* "G": same as "g" but uses "E" instead of "e".
* "n": equivalent to ",g".
* "%": percentages.
Fixes#149.
This doesn't quite seem like the right place for it, but it seems to work when
using "touchstart", "touchmove" and "touchend" handlers without any adverse
effects on "true" mouse event handlers.
See <http://www.jasondavies.com/apollonian-gasket/> to see an example of
combined touch/mouse handlers working with this change.
This commit adds a d3_uninterpolate method (private, for now), which is
essentially the inverse of d3.interpolate. It's used to map a value in the
domain to the unit range [0,1], which can then be passed to an interpolator.
Mainly, I fixed a bug where the coordinates could get set to NaN if two
successive points have the same x-coordinate. But I also cleaned up the
implementation slightly, and compute the initial tangents using finite
differences.
We can take advantage of JavaScript's invisible hoisting of variables to set
them before they are defined. This simplifies the code for the various special
cases in the `classed` operator, such as for SVG elements and browsers that
support the tokenized class list.
This turns out to be slightly faster than using structs (`{}`) and is bit
cleaner. You can now also do:
d3.rgb(r, g, b).hsl()
and:
d3.hsl(h, s, l).rgb()
to convert between RGB and HSL.
Specifically, removal of a class wasn't working because the `className` property
for SVG elements is an SVGAnimatedString, which has no `replace` method.
It would be nice to have a unit test for this, but env-js doesn't use
SVGAnimatedString for this property.
Previously, we were computing the node position relative to the node, which is
dangerous is the node is transformed. Computing it relative to the parent allows
nodes to be positioned using the "transform" attribute.
We don't actually need the separate `fx` and `fy` attributes on each node;
instead we can modify the `x` and `y` attributes directly, since we're using
position Verlet! This commit also adds the layout's `alpha` parameter to the
tick event, such that normalized external forces can be applied.
This applies any queued zero-delay d3.timer callbacks immediately. This is
useful in situations where zero-duration transitions are used e.g. in generic
visualisations that have a configurable transition duration.
It's often desirable to have zero-duration transitions for the initial setup
phase (so that the visualisation displays immediately). Immediate application
(rather than waiting for the setTimeout callback to fire) avoids a delay of some
milliseconds as well as an extra redraw.
See issue #48.
Previously, rescheduling an immediate timer would cause it to be postponed again
by a minimum of 24ms. This is undesirable if the timer is being scheduled in
response to user events, such as mousemoves, that can occur very frequently. Now
we schedule an early callback once, and don't touch it if it's rescheduled. In
addition, the timer loop is now smarter about switching between short and long
callbacks. If there's a short delay (< 24ms) until the next timer fires, the
timer will use requestAnimationFrame. For longer delays, setTimeout is used.
This is a utility for creating a Bézier curve between opposite corners of a
rectangle. This is commonly used to draw smooth curves connecting parent and
child nodes in a hierarchical node-link diagram. A projection may be specified
which allows the curve to be transformed from polar coordinates.
This commit also changes the semantics of the recently-added `links` method,
such that the objects have `source` and `target` properties that match the
default diagonal format.
You can now use the `text` operator on transitions, which has the same effect as
setting the text value at the start of the transition. This is nice if you have
a delayed transition, and avoids a common gotcha.
This commit also simplifies the implementation of the `text` operator using the
standard `textContent` property. This isn't supported on IE8-, but we could
potentially add support in the future using `innerText`.