简体   繁体   English

d3 selectAll源代码

[英]d3 selectAll Source code

I'm trying to understand the source code for d3 selectAll and I don't understand the line following my comment below. 我试图理解d3 selectAll源代码 ,但我不理解下面我的评论后面的内容。

I can see how there is a closure on the selector string and that this is set to node when d3_selectAll is invoked, but how are the other three arguments in the call consumed? 我可以看到有在选择字符串关闭,并且this设置时d3_selectAll被调用到节点,但如何是其他三个参数在call消耗?

import "../core/array";
import "selection";

d3_selectionPrototype.selectAll = function(selector) {
  var subgroups = [],
      subgroup,
      node;

  selector = d3_selection_selectorAll(selector);




for (var j = -1, m = this.length; ++j < m;) {
    for (var group = this[j], i = -1, n = group.length; ++i < n;) {
      if (node = group[i]) {
        //***where are node.__data__, i, j consumed?***
        subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
        subgroup.parentNode = node;
      }
    }
  }



return d3_selection(subgroups);
};

function d3_selection_selectorAll(selector) {
  return typeof selector === "function" ? selector : function() {
    return d3_selectAll(selector, this);
  };
}

This is only relevant in the context of subselections and explained in the documentation : 这仅与子选择有关,并在文档中进行了解释:

The selector may also be specified as a function that returns an array of elements (or a NodeList), or the empty array if there are no matching elements. 选择器也可以指定为返回元素数组(或NodeList)的函数,如果没有匹配的元素,则返回空数组。 In this case, the specified selector is invoked in the same manner as other operator functions, being passed the current datum d and index i , with the this context as the current DOM element. 在这种情况下,以与其他运算符函数相同的方式调用指定的选择器,将当前的数据d和索引i传递给此选择器,并将此上下文作为当前的DOM元素。

In particular, if the selector is not a function, these arguments are simply ignored (function declaration at the end with no arguments). 特别是,如果选择器不是函数,则将忽略这些参数(在函数声明末尾不带参数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM