Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 #210

Merged
merged 45 commits into from
Aug 23, 2020
Merged

2.0 #210

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8fc76d7
Fix #209.
mbostock Mar 18, 2019
20029cb
Fix #197 iterable selections.
mbostock Mar 18, 2019
60be25f
Use self-iteration instead of each.
mbostock Mar 18, 2019
54f6e6b
Fix #208 - strict merge.
mbostock Mar 18, 2019
263a801
Fix #204 - accept iterable in selection.data.
mbostock Mar 18, 2019
2824b06
Related d3/d3#3265.
mbostock Jul 29, 2019
f3f0e66
Remove d3.event.
mbostock Jul 29, 2019
13dbec6
Remove sourceEvent.
mbostock Jul 29, 2019
bcbf78e
Default to event.currentTarget.
mbostock Jul 29, 2019
bfee680
Rename to “target”.
mbostock Jul 29, 2019
e2b8efe
Don’t default options to false.
mbostock Jul 29, 2019
de28a3e
Rename clientPoint to pointer.
mbostock Jul 29, 2019
e9765ea
Update dependencies.
mbostock Jul 30, 2019
7cb8ad4
2.0.0-rc.1
mbostock Jul 30, 2019
4b1ba83
Explicit files.
mbostock Jul 30, 2019
772adb3
Fix d3.pointer when the target is a window.
mbostock Jul 30, 2019
65c9592
Update README.
mbostock Jul 30, 2019
9bce1bd
Handle missing targets.
mbostock Jul 30, 2019
fe2ed50
Update README.
mbostock Jul 30, 2019
f13c41a
Don’t copy arrays.
mbostock Jul 30, 2019
6666180
Standardize array conversion.
mbostock Jul 30, 2019
1ce33b5
Adopt a Map.
mbostock Nov 16, 2019
8cde069
Correctly iterate over a string.
mbostock Nov 16, 2019
4782e69
Don’t allow data to be null.
mbostock Nov 16, 2019
630e51c
Test for selection.data(null).
mbostock Nov 16, 2019
7398837
2.0.0-rc.2
mbostock Nov 17, 2019
7031dc3
Merge branch 'master' into two
mbostock Nov 17, 2019
9f3c5e8
*selection*.selection() returns itself
Fil Jun 29, 2020
e30ceae
*selection*.selection() returns itself
Fil Jul 23, 2020
5220ca0
v2.0.0-rc.3
Fil Jul 23, 2020
afef83a
link syntax
Fil Jul 24, 2020
eea6d35
Add d3.pointers.
mbostock Aug 3, 2020
14ebfe7
use sourceEvent.currentTarget
Fil Aug 3, 2020
10e738a
Update src/pointer.js
Fil Aug 3, 2020
bbc520a
Update src/pointers.js
Fil Aug 3, 2020
d03744a
document pointer, pointers
Fil Aug 4, 2020
1104d26
array
Fil Aug 4, 2020
ca02fa5
use sourceEvent.currentTarget
Fil Aug 4, 2020
f0c3a69
Add d3.pointers
Fil Aug 4, 2020
f254f64
pointer tests
Fil Aug 5, 2020
29c55b7
v2.0.0-rc.4
Fil Aug 5, 2020
248aeba
a few tests for d3.pointer d3.pointers
Fil Aug 5, 2020
04e9e75
Add selection.selectChild[ren].
mbostock Apr 25, 2020
ab4a51d
2.0.0-rc.5
mbostock Aug 12, 2020
9053829
Merge branch 'master' into two
Fil Aug 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 102 additions & 72 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-selection",
"version": "1.4.2",
"version": "2.0.0-rc.5",
"description": "Data-driven DOM manipulation: select elements and join them to data.",
"keywords": [
"d3",
Expand Down
5 changes: 5 additions & 0 deletions src/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function(x) {
return typeof x === "object" && "length" in x
? x // Array, TypedArray, NodeList, array-like
: Array.from(x); // Map, Set, iterable, string, or anything else
}
4 changes: 2 additions & 2 deletions src/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import creator from "./creator";
import select from "./select";
import creator from "./creator.js";
import select from "./select.js";

export default function(name) {
return select(creator(name).call(document.documentElement));
Expand Down
4 changes: 2 additions & 2 deletions src/creator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import namespace from "./namespace";
import {xhtml} from "./namespaces";
import namespace from "./namespace.js";
import {xhtml} from "./namespaces.js";

function creatorInherit(name) {
return function() {
Expand Down
33 changes: 15 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
export {default as create} from "./create";
export {default as creator} from "./creator";
export {default as local} from "./local";
export {default as matcher} from "./matcher";
export {default as mouse} from "./mouse";
export {default as namespace} from "./namespace";
export {default as namespaces} from "./namespaces";
export {default as clientPoint} from "./point";
export {default as select} from "./select";
export {default as selectAll} from "./selectAll";
export {default as selection} from "./selection/index";
export {default as selector} from "./selector";
export {default as selectorAll} from "./selectorAll";
export {styleValue as style} from "./selection/style";
export {default as touch} from "./touch";
export {default as touches} from "./touches";
export {default as window} from "./window";
export {event, customEvent} from "./selection/on";
export {default as create} from "./create.js";
export {default as creator} from "./creator.js";
export {default as local} from "./local.js";
export {default as matcher} from "./matcher.js";
export {default as namespace} from "./namespace.js";
export {default as namespaces} from "./namespaces.js";
export {default as pointer} from "./pointer.js";
export {default as pointers} from "./pointers.js";
export {default as select} from "./select.js";
export {default as selectAll} from "./selectAll.js";
export {default as selection} from "./selection/index.js";
export {default as selector} from "./selector.js";
export {default as selectorAll} from "./selectorAll.js";
export {styleValue as style} from "./selection/style.js";
export {default as window} from "./window.js";
7 changes: 7 additions & 0 deletions src/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ export default function(selector) {
return this.matches(selector);
};
}

export function childMatcher(selector) {
return function(node) {
return node.matches(selector);
};
}

8 changes: 0 additions & 8 deletions src/mouse.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/namespace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import namespaces from "./namespaces";
import namespaces from "./namespaces.js";

export default function(name) {
var prefix = name += "", i = prefix.indexOf(":");
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
}
13 changes: 0 additions & 13 deletions src/point.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/pointer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sourceEvent from "./sourceEvent.js";

export default function(event, node) {
event = sourceEvent(event);
if (node === undefined) node = event.currentTarget;
if (node) {
var svg = node.ownerSVGElement || node;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
point.x = event.clientX, point.y = event.clientY;
point = point.matrixTransform(node.getScreenCTM().inverse());
return [point.x, point.y];
}
if (node.getBoundingClientRect) {
var rect = node.getBoundingClientRect();
return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
}
}
return [event.pageX, event.pageY];
}
11 changes: 11 additions & 0 deletions src/pointers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pointer from "./pointer.js";
import sourceEvent from "./sourceEvent.js";

export default function(events, node) {
if (events.target) { // i.e., instanceof Event, not TouchList or iterable
events = sourceEvent(events);
if (node === undefined) node = events.currentTarget;
events = events.touches || [events];
}
return Array.from(events, event => pointer(event, node));
}
2 changes: 1 addition & 1 deletion src/select.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Selection, root} from "./selection/index";
import {Selection, root} from "./selection/index.js";

export default function(selector) {
return typeof selector === "string"
Expand Down
5 changes: 3 additions & 2 deletions src/selectAll.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Selection, root} from "./selection/index";
import array from "./array.js";
import {Selection, root} from "./selection/index.js";

export default function(selector) {
return typeof selector === "string"
? new Selection([document.querySelectorAll(selector)], [document.documentElement])
: new Selection([selector == null ? [] : selector], root);
: new Selection([selector == null ? [] : array(selector)], root);
}
2 changes: 1 addition & 1 deletion src/selection/append.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import creator from "../creator";
import creator from "../creator.js";

export default function(name) {
var create = typeof name === "function" ? name : creator(name);
Expand Down
2 changes: 1 addition & 1 deletion src/selection/attr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespace from "../namespace";
import namespace from "../namespace.js";

function attrRemove(name) {
return function() {
Expand Down
37 changes: 18 additions & 19 deletions src/selection/data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Selection} from "./index";
import {EnterNode} from "./enter";
import constant from "../constant";

var keyPrefix = "$"; // Protect against keys like “__proto__”.
import {Selection} from "./index.js";
import {EnterNode} from "./enter.js";
import array from "../array.js";
import constant from "../constant.js";

function bindIndex(parent, group, enter, update, exit, data) {
var i = 0,
Expand Down Expand Up @@ -33,7 +32,7 @@ function bindIndex(parent, group, enter, update, exit, data) {
function bindKey(parent, group, enter, update, exit, data, key) {
var i,
node,
nodeByKeyValue = {},
nodeByKeyValue = new Map,
groupLength = group.length,
dataLength = data.length,
keyValues = new Array(groupLength),
Expand All @@ -43,11 +42,11 @@ function bindKey(parent, group, enter, update, exit, data, key) {
// If multiple nodes have the same key, the duplicates are added to exit.
for (i = 0; i < groupLength; ++i) {
if (node = group[i]) {
keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
if (keyValue in nodeByKeyValue) {
keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
if (nodeByKeyValue.has(keyValue)) {
exit[i] = node;
} else {
nodeByKeyValue[keyValue] = node;
nodeByKeyValue.set(keyValue, node);
}
}
}
Expand All @@ -56,30 +55,30 @@ function bindKey(parent, group, enter, update, exit, data, key) {
// If there a node associated with this key, join and add it to update.
// If there is not (or the key is a duplicate), add it to enter.
for (i = 0; i < dataLength; ++i) {
keyValue = keyPrefix + key.call(parent, data[i], i, data);
if (node = nodeByKeyValue[keyValue]) {
keyValue = key.call(parent, data[i], i, data) + "";
if (node = nodeByKeyValue.get(keyValue)) {
update[i] = node;
node.__data__ = data[i];
nodeByKeyValue[keyValue] = null;
nodeByKeyValue.delete(keyValue);
} else {
enter[i] = new EnterNode(parent, data[i]);
}
}

// Add any remaining nodes that were not bound to data to exit.
for (i = 0; i < groupLength; ++i) {
if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
exit[i] = node;
}
}
}

function datum(node) {
return node.__data__;
}

export default function(value, key) {
if (!value) {
data = new Array(this.size()), j = -1;
this.each(function(d) { data[++j] = d; });
return data;
}
if (!arguments.length) return Array.from(this, datum);

var bind = key ? bindKey : bindIndex,
parents = this._parents,
Expand All @@ -91,7 +90,7 @@ export default function(value, key) {
var parent = parents[j],
group = groups[j],
groupLength = group.length,
data = value.call(parent, parent && parent.__data__, j, parents),
data = array(value.call(parent, parent && parent.__data__, j, parents)),
dataLength = data.length,
enterGroup = enter[j] = new Array(dataLength),
updateGroup = update[j] = new Array(dataLength),
Expand Down
2 changes: 1 addition & 1 deletion src/selection/dispatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import defaultView from "../window";
import defaultView from "../window.js";

function dispatchEvent(node, type, params) {
var window = defaultView(node),
Expand Down
4 changes: 2 additions & 2 deletions src/selection/enter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sparse from "./sparse";
import {Selection} from "./index";
import sparse from "./sparse.js";
import {Selection} from "./index.js";

export default function() {
return new Selection(this._enter || this._groups.map(sparse), this._parents);
Expand Down
4 changes: 2 additions & 2 deletions src/selection/exit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sparse from "./sparse";
import {Selection} from "./index";
import sparse from "./sparse.js";
import {Selection} from "./index.js";

export default function() {
return new Selection(this._exit || this._groups.map(sparse), this._parents);
Expand Down
4 changes: 2 additions & 2 deletions src/selection/filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Selection} from "./index";
import matcher from "../matcher";
import {Selection} from "./index.js";
import matcher from "../matcher.js";

export default function(match) {
if (typeof match !== "function") match = matcher(match);
Expand Down
75 changes: 43 additions & 32 deletions src/selection/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import selection_select from "./select";
import selection_selectAll from "./selectAll";
import selection_filter from "./filter";
import selection_data from "./data";
import selection_enter from "./enter";
import selection_exit from "./exit";
import selection_join from "./join";
import selection_merge from "./merge";
import selection_order from "./order";
import selection_sort from "./sort";
import selection_call from "./call";
import selection_nodes from "./nodes";
import selection_node from "./node";
import selection_size from "./size";
import selection_empty from "./empty";
import selection_each from "./each";
import selection_attr from "./attr";
import selection_style from "./style";
import selection_property from "./property";
import selection_classed from "./classed";
import selection_text from "./text";
import selection_html from "./html";
import selection_raise from "./raise";
import selection_lower from "./lower";
import selection_append from "./append";
import selection_insert from "./insert";
import selection_remove from "./remove";
import selection_clone from "./clone";
import selection_datum from "./datum";
import selection_on from "./on";
import selection_dispatch from "./dispatch";
import selection_select from "./select.js";
import selection_selectAll from "./selectAll.js";
import selection_selectChild from "./selectChild.js";
import selection_selectChildren from "./selectChildren.js";
import selection_filter from "./filter.js";
import selection_data from "./data.js";
import selection_enter from "./enter.js";
import selection_exit from "./exit.js";
import selection_join from "./join.js";
import selection_merge from "./merge.js";
import selection_order from "./order.js";
import selection_sort from "./sort.js";
import selection_call from "./call.js";
import selection_nodes from "./nodes.js";
import selection_node from "./node.js";
import selection_size from "./size.js";
import selection_empty from "./empty.js";
import selection_each from "./each.js";
import selection_attr from "./attr.js";
import selection_style from "./style.js";
import selection_property from "./property.js";
import selection_classed from "./classed.js";
import selection_text from "./text.js";
import selection_html from "./html.js";
import selection_raise from "./raise.js";
import selection_lower from "./lower.js";
import selection_append from "./append.js";
import selection_insert from "./insert.js";
import selection_remove from "./remove.js";
import selection_clone from "./clone.js";
import selection_datum from "./datum.js";
import selection_on from "./on.js";
import selection_dispatch from "./dispatch.js";
import selection_iterator from "./iterator.js";

export var root = [null];

Expand All @@ -41,16 +44,23 @@ function selection() {
return new Selection([[document.documentElement]], root);
}

function selection_selection() {
return this;
}

Selection.prototype = selection.prototype = {
constructor: Selection,
select: selection_select,
selectAll: selection_selectAll,
selectChild: selection_selectChild,
selectChildren: selection_selectChildren,
filter: selection_filter,
data: selection_data,
enter: selection_enter,
exit: selection_exit,
join: selection_join,
merge: selection_merge,
selection: selection_selection,
order: selection_order,
sort: selection_sort,
call: selection_call,
Expand All @@ -73,7 +83,8 @@ Selection.prototype = selection.prototype = {
clone: selection_clone,
datum: selection_datum,
on: selection_on,
dispatch: selection_dispatch
dispatch: selection_dispatch,
[Symbol.iterator]: selection_iterator
};

export default selection;
4 changes: 2 additions & 2 deletions src/selection/insert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import creator from "../creator";
import selector from "../selector";
import creator from "../creator.js";
import selector from "../selector.js";

function constantNull() {
return null;
Expand Down
Loading