Skip to content

Commit

Permalink
Fallback subject.
Browse files Browse the repository at this point in the history
Reverts most of 8b25a53. Fixes #18.
  • Loading branch information
mbostock committed May 22, 2016
1 parent 24e9583 commit 4e4855f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ If *subject* is specified, sets the subject accessor to the specified object or

```js
function subject(d) {
return d;
return d == null ? this : d;
}
```

The *subject* of a drag gesture represents *the thing being dragged*. It is computed when an initiating input event is received, such as a mousedown or touchstart, immediately before the drag gesture starts. The subject is then exposed as *event*.subject on subsequent [drag events](#drag-events) for this gesture.

The default subject is the [datum](https://github.com/d3/d3-selection#selection_datum) of the element in the originating selection (see [*drag*](#_drag)) that received the initiating input event. When dragging circle elements in SVG, the default subject is the datum of the circle being dragged; with [Canvas](https://html.spec.whatwg.org/multipage/scripting.html#the-canvas-element), the default subject is the canvas element’s datum (regardless of where on the canvas you click). In this case, a custom subject accessor would be more appropriate, such as one that picks the closest circle to the mouse within a given search *radius*:
The default subject is the [datum](https://github.com/d3/d3-selection#selection_datum) of the element in the originating selection (see [*drag*](#_drag)) that received the initiating input event; if the datum is undefined, the default subject is the element itself. When dragging circle elements in SVG, the default subject is the datum of the circle being dragged. With [Canvas](https://html.spec.whatwg.org/multipage/scripting.html#the-canvas-element), the default subject is the canvas element’s datum (regardless of where on the canvas you click). In this case, a custom subject accessor would be more appropriate, such as one that picks the closest circle to the mouse within a given search *radius*:

```js
function subject() {
Expand Down
2 changes: 1 addition & 1 deletion src/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function defaultContainer() {
}

function defaultSubject(d) {
return d;
return d == null ? this : d;
}

function defaultX() {
Expand Down

0 comments on commit 4e4855f

Please sign in to comment.