Skip to content

New pluck function to easily obtain an array of values from common properties #1

Closed
wants to merge 116 commits into from

6 participants

@drslump
drslump commented Dec 27, 2011

Included a new d3.pluck function to easily obtain an array of values from a common property in a list of objects or nested arrays. This is extremely useful when computing domains for example, since it avoids the need for custom map functions.

Additionally it also allows to define a default value as third argument to be returned in the case that the given property is not defined in some of the nested objects.

var data = [ {x:100, y:'Sp'}, {x:120, y:'Uk'}, {x: 60, y:'Fr'}, {y: 'Gr'} ];
xScale.domain([0, d3.max(d3.pluck(data, 'x', 0))]);
yScale.domain(d.pluck(data, 'y'));
//xScale.domain([0, d3.max(data, function(d){ return d.x; })]);
//yScale.domain(data.map(function(d){ return d.y; }));
mbostock and others added some commits Aug 27, 2011
@mbostock mbostock Inherit namespace from parent node.
This allows you to append("g") to an svg:svg, instead of append("svg:g").
a35fc55
@larskotthoff larskotthoff fix bug that causes chord layout to break in Opera
The chord layout uses an assigment like x += y to specify the end angle of a
chord segment. This seems to return the new value in most browsers, but the old
value (i.e. x - y) in Opera.
06e9ba9
@mbostock mbostock Add state names. fb07750
@jasondavies jasondavies Add configurable origin to d3.behavior.zoom.
This defaults to storing the absolute scale and transform across
multiple zooms.  However, it can be modified to retrieve state from
outside the behaviour e.g. if the offsets have been restricted in some
way, the true values should be returned in a custom offset accessor.

The offset accessor is called on "mousedown" or "touchstart", and so has
access to the current mouse position.
6830a0f
@jasondavies jasondavies Add configurable extents to d3.behavior.zoom.
The extents parameter is a 3-element array of ranges, corresponding to
the ranges allowed in pixel-space at zoom-level 0.  Each range is a
two-element array.  For example, to restrict zooming and panning to a
rectangle of width w and height h, with minimum zoom level 0, use:

    .extents([[0, w], [0, h], [0, Infinity]])
a93a371
@jasondavies jasondavies Fix bug when no extents are specified. bc2394a
@jasondavies jasondavies Fix another bug with infinite extents. 8bfa56c
@jasondavies jasondavies Simplify code. 81db54c
@mbostock mbostock Fix two sorting bugs in chord layout.
We still weren't sorting subgroups correctly. Also, we now sort chords by their
average value, rather than the source value, which works well with one-sided
chords (where either the source or target value is zero).
c0e5b96
@jasondavies jasondavies Use changedTouches instead of touches.
This is because the "touchend" event removes the touch from
event.touches on iOS, but it can still be accessed via
event.changedTouches.
bd90a2f
@jasondavies jasondavies Optional touch array argument for d3.svg.touches.
By default, we probably want to use event.touches, but for "touchend"
events it's useful to retrieve the positions of event.changedTouches.
d0d665c
@jasondavies jasondavies Better handling of "touchend".
We can't check for existence of event.touches to decide whether to use
it or not for touchend, as it always exists, just not containing the
touch that just ended.
c16417c
@jasondavies jasondavies Simplify touchend handling.
We only care about changed touches for d3.behavior.drag.
8f98f81
@mbostock mbostock Merge branch 'opera-chord' of https://github.com/larskotthoff/d3 into…
… chord
b073edf
@mbostock mbostock Add comment re. Opera bug. 9d56825
@johan Prettify tooltips on non-data calendar dates. 31d00a9
@mbostock mbostock Tiny simplification. 95a4dce
@mbostock mbostock Merge branch 'calendar' into release bb19373
@mbostock mbostock Coerce pie values to numbers.
Fixes #347.
4a0c384
@mbostock mbostock Sort by descending value by default.
Fixes #348.
d57e278
@mbostock mbostock Merge branch 'pie' into 2.5.0 6bf2071
@mbostock mbostock Add main property to package.json.
Fixes #340.
338094e
@mbostock mbostock Comment re. clipping and invalid inputs.
Fixes #235.
0ad900a
@mbostock mbostock Namespaces for d3.dispatch events.
Fixes #294. This isn't backwards-compatible, but d3.dispatch is considered an
internal API so this doesn't require a major version bump.
392ded0
@mbostock mbostock Merge branch 'touches' of https://github.com/jasondavies/d3 into 2.5.0 eda09f4
@mbostock mbostock First cut at a brush component.
The d3.svg.brush component allows one- or two-dimensional rectangular brushing.
A future commit will allow the brushed region to be resized by grabbing an edge,
and also provide some way of reporting the selection (duh)!
e3d59bd
@mbostock mbostock Add resize handles.
These aren't yet hooked up to interaction, but they show the right cursor!
c72f10a
@mbostock mbostock Resizeable brush. 42a59ac
@mbostock mbostock Query the brush selection.
You can now query the brush for its selection. This commit also includes a new
d3.random.normal for generating random numbers with a normal distribution. This
is useful for jittering points for display.
a475cd5
@mbostock mbostock Brush refinements.
The brush component now reports brushstart and brushend events at the start and
end of a brushing gesture, which is useful for some types of interaction. You
can now set the brush extent programmatically, as well. Note, however, that
you'll probably want to redraw the brush after setting the extent.
6e1cad4
@mbostock mbostock Use the altKey to preserve the brush center.
A somewhat hidden feature, but useful!
20b68c3
@mbostock mbostock The space key now lets you drag temporarily! 49c5b60
@jasondavies jasondavies Remove stray global in example. 6651c17
@mbostock mbostock Merge pull request #359 from jasondavies/brush
Remove stray global in brush example.
6ebc2fc
@mbostock mbostock Update SPLOM example to use d3.svg.brush.
This required a couple core changes. First, the brush shouldn't notify listeners
when redrawing, because this commonly causes an infinite loop if one brush
triggers a change in another brush (as in a scatterplot matrix, where only one
brush is active at a given time). I suppose an alternative implementation might
use just a single brush, and assign the axes dynmically; I might try that in a
future commit. Second, I added a clear convenience method to reset a brush.
af589a0
@mbostock mbostock Add parallel coordinates example.
This includes a d3.extent convenience method for [d3.min, d3.max], and fixes the
brush component such that the resizers are hidden when the extent is empty.
149320f
@mbostock mbostock Add .DS_Store to .gitignore. 6c8b308
@mbostock mbostock Invoke accessor once per value in d3.extent.
This allows the use of nondeterministic accessors. Also add a test.
2b42dec
@jasondavies jasondavies Use a single loop for d3.extent. a4abdc3
@jasondavies jasondavies Merge remote-tracking branch 'mbostock/brush' into extent
Conflicts:
	d3.js
	d3.min.js
	src/core/extent.js
	test/core/extent-test.js
d11b5d9
@mbostock mbostock Merge branch 'master' of github.com:mbostock/d3 98da365
@mbostock mbostock Merge pull request #363 from jasondavies/extent
Use single loop for d3.extent.
a9043b9
@mbostock mbostock Use a single brush for scatterplot matrix. 6aad8c7
@mbostock mbostock Fix range generation for ordinal scales.
Using d3.range with a floating point step is a bit sketchy, because there's a
chance that too many or too few elements could be generated. Instead, we now we
generate an integer range and scale it accordingly.
4882a64
@mbostock mbostock Merge branch 'zoom-extent' of https://github.com/jasondavies/d3 into …
…zoom
99963f0
@jasondavies jasondavies Fix silly bug.
This was due to mishandling infinities in the clamping function, so the
default extent was "backwards".
14b8d48
@jasondavies jasondavies Remove unnecessary origin accessor from zoom.
I don't think this is needed any more, as we now clamp the extent in the
behaviour itself.
60e80dc
@mbostock mbostock Merge branch 'zoom-extent' of https://github.com/jasondavies/d3 into …
…zoom
9006592
@jasondavies jasondavies More meaningful naming. a5b538b
@jasondavies jasondavies A null extent should set extent to infinities. d2c424a
@jasondavies jasondavies Merge remote-tracking branch 'mbostock/zoom' into zoom-extent
Conflicts:
	d3.js
	d3.min.js
	src/behavior/zoom.js
83f9b82
@mbostock mbostock Fix merge bug. 1637c4b
@jasondavies jasondavies Fix typo introduced in last commit. 92b010f
@jasondavies jasondavies Reuse infinite extent. 070b463
@mbostock mbostock Tiny simplification. 4cfdc94
@mbostock mbostock Merge branch 'zoom-extent' of https://github.com/jasondavies/d3 into …
…2.5.0
557abcc
@mbostock mbostock Disable sorting in donut transition example. 306d504
@mbostock mbostock Remove defunct d3_interpolateByName. 6fe70a8
@jasondavies jasondavies Fix minor bug in exponent notation interpolation. e60bc4d
@jasondavies jasondavies Slightly shorter regex.
Exactly the same speed in Chrome (probably both are optimised into the
same form): http://jsperf.com/number-matching
151f0ba
@mbostock mbostock Merge branch 'interpolate' of https://github.com/jasondavies/d3 into …
…2.5.0
e78cd68
@mbostock mbostock Add state names. ff8225b
@mbostock mbostock Add d3.transform and d3.interpolateTransform.
This is based on @jasondavies previous work on interpolating 3D matrices,
simplified to only handle 2D transforms, and using SVG to parse transforms.
e3f6f33
@mbostock mbostock Restore d3_interpolateByName for transforms. a7ff9fa
@mbostock mbostock Merge branch 'interpolate' of https://github.com/jasondavies/d3 into …
…2.5.0
8d68572
@mbostock mbostock Tolerate uninvertible matrices. d85d29e
@mbostock mbostock Add transform transition example. 9460e7f
@mbostock mbostock Merge branch 'transform' into 2.5.0 7ae28f1
@mbostock mbostock Merge branch '2.5.0' 8cba1d7
@mbostock mbostock Use inclusive bounds for brush examples. af5fccd
@jasondavies jasondavies Update JSDOM and Vows versions.
This required changing assert.length to assert.lengthOf in tests, due to
a Vows.js change to be compatible with Node.js v0.6.x.  For further
details:

    vowsjs/vows#141
4d6b5bc
@mbostock mbostock Merge pull request #371 from jasondavies/deps
Update JSDOM and Vows versions (Node.js v0.6.x compatibility).
5ae34aa
@mbostock mbostock Remove spurious rounding. da47ae8
@mbostock mbostock Fixed precision for the default log tick format.
Also add @jmarca's test case.
3de298b
@mbostock mbostock Add drag.origin accessor.
This allows you to specify how the drag behavior should infer the current
position of the targetted element, such that a fixed offset can be maintained
between the mouse position and the element position for the duration of the drag
gesture. For example, if your data is an {x, y} object, use origin(Object).
18dcad7
@mbostock mbostock Restore conservative click canceling.
See #312. The also fixes the zoom behavior so that it cleans up temporary state
when the zoom gesture is done. And, it fixes both behaviors such that the
mouseup event is always stopped from propagation if a gesture occurs (even if a
subsequent click is not prevented).
2f16227
@mbostock mbostock Improvements to collapsible force example. 98b6abd
@mbostock mbostock Merge branch 'master' of github.com:mbostock/d3 4090261
@mbostock mbostock Fix a couple bugs with transforms.
We need to check the matrix determinant for flipped coordinates. We also need to
check for invalid transforms, which are now treated as the identity transform.
7fe3ae4
@mbostock mbostock Merge branch 'master' into drag 88c6f28
@mbostock mbostock Stop propagation on drag start, too. faec4c8
@jasondavies jasondavies Fix d3.transform and add browser-based tests.
This fixes various corner cases involving negative and zero scales, as
well as proper support for skewX, which previously wasn't being computed
correctly.

Fixes #377.
204506c
@jasondavies jasondavies Bump epsilon. 0ad865f
@mbostock mbostock Slightly smaller code. 3007db2
@mbostock mbostock Merge branch 'master' into log 64c4e78
@mbostock mbostock Merge branch 'transform' into release b4c6b00
@mbostock mbostock Merge branch 'release' b04112a
@mbostock mbostock Add .npmignore. 5d57fa7
@mbostock mbostock Fix a bug when removing a shared listener.
Previously, each listener function had a private _on property which recorded
whether the listener was enabled; this was set to false when the listener was
removed. (This is necessary because of the copy-on-write semantics when the
array of listeners is modified while events are being dispatched.) If the
listener was registered for multiple event types ("foo" and "bar") then removing
the listener for any type would disable it for all types.

The fix is to wrap the listener in an object. This also has better encapsulation
since the state is kept private.
75ddc28
@mbostock mbostock dispatch.on(name) returns the current listener.
Fixes #383. This includes a non-backwards-compatible change to d3.rebind, so as
to make it easier to rebind multiple methods on subclasses.
1b3a3b3
@mbostock mbostock Merge branch 'fix-dispatch' 2df8c62
@mbostock mbostock Ordinal scales for axes. 552622d
@mbostock mbostock Brushing for ordinal scales.
Since the ordinal scale's domain is not continuous, the brush extent is reported
in the range rather than in the domain for ordinal scales. We'll leave it to the
caller to interpret this as desired.
532bf71
@mbostock mbostock Add transpose. 3d6b4cf
@mbostock mbostock Merge branch 'master' into default-namespace cc3f5da
@mbostock mbostock Infer namespaces for root element.
Now if you add an "svg" element, we automatically infer the namespace because
there is an "svg" namespace prefix. In conjunction with inheriting the namespace
from the parent element, this means that namespaces are almost optional!
11c1e7a
@mbostock mbostock Merge branch 'drag' into release 0404f35
@mbostock mbostock Merge branch 'ordinal-axis' into release ee3954c
@mbostock mbostock Merge branch 'transpose' into release 9c92666
@mbostock mbostock Merge branch 'release' 9523f94
@mbostock mbostock Namespaces are optional now! 817358a
@jasondavies jasondavies Examples: namespaces are optional as of v2.6.0. 5a87998
@jasondavies jasondavies d3.svg.*: namespaces are optional as of v2.6.0. 12711f2
@mbostock mbostock Fix #394. a752b96
@mbostock mbostock Fix #392 - interpolate string to number. 2be4efd
@mbostock mbostock Merge branch 'fix-log-precision' into release 4972113
@mbostock mbostock Merge branch 'fix-interpolate-number' into release 33ab885
@mbostock mbostock Merge branch 'release' fe671a7
@natevw natevw add GeometryCollection support to d3.geo.bounds 9ae8fee
@mbostock mbostock Add selection.order.
It's like selection.sort, except it assumes that the data is already sorted;
the elements are reordered to match the selection.
4a35d78
@mbostock mbostock Allow selectors for selection.filter.
Fixes #397.
a6f87e7
@mbostock mbostock Merge branch 'geomcollection_bounds' of https://github.com/natevw/d3
…into order
1c1cb35
@mbostock mbostock Fix minified file. b3848af
@mbostock mbostock Merge branch 'order' 05d871b
@mbostock mbostock Fix a bug in SPLOM axes.
Array.reverse does not create a copy of the array, so we must slice first.
7d2ce55
@drslump drslump Included a new 'pluck' function to easily obtain an array of values f…
…rom a common property in a list of objects or nested arrays. This is extremelly useful when computing domains for example, since it avoids the need for custom map functions.
7e3c0d6
@drslump
drslump commented Dec 27, 2011

Sorry, I sent the pull request to the wrong fork.

@drslump drslump closed this Dec 27, 2011
@johan
Owner
johan commented Dec 27, 2011

No worries; I much enjoyed seeing it; I like it too. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.