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

Make .data() binding work with iterable protocol #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions src/selection/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import constant from "../constant.js";
function bindIndex(parent, group, enter, update, exit, data) {
var i = 0,
node,
groupLength = group.length,
dataLength = data.length;
groupLength = group.length;

// Put any non-null nodes that fit into update.
// Put any null nodes into enter.
// Put any remaining data into enter.
for (; i < dataLength; ++i) {
for (const datum of data) {
if (node = group[i]) {
node.__data__ = data[i];
node.__data__ = datum;
update[i] = node;
} else {
enter[i] = new EnterNode(parent, data[i]);
enter[i] = new EnterNode(parent, datum);
}
i += 1;
}

// Put any non-null nodes that don’t fit into exit.
Expand All @@ -33,7 +33,6 @@ function bindKey(parent, group, enter, update, exit, data, key) {
node,
nodeByKeyValue = new Map,
groupLength = group.length,
dataLength = data.length,
keyValues = new Array(groupLength),
keyValue;

Expand All @@ -53,15 +52,17 @@ function bindKey(parent, group, enter, update, exit, data, key) {
// Compute the key for each datum.
// 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 = key.call(parent, data[i], i, data) + "";
i = 0;
for (const datum of data) {
keyValue = key.call(parent, datum, i, data) + "";
if (node = nodeByKeyValue.get(keyValue)) {
update[i] = node;
node.__data__ = data[i];
node.__data__ = datum;
nodeByKeyValue.delete(keyValue);
} else {
enter[i] = new EnterNode(parent, data[i]);
enter[i] = new EnterNode(parent, datum);
}
i += 1;
}

// Add any remaining nodes that were not bound to data to exit.
Expand Down