javascript - d3 selectAll 源代码

标签 javascript d3.js

我正在尝试理解 source code for d3 selectAll 我不明白下面我的评论之后的那一行。

我可以看到选择器字符串上有一个闭包,并且在调用 d3_selectAll 时 this 设置为节点,但是 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);
  };
}

最佳答案

这仅在子选择的上下文中相关,并在 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. 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.

特别是,如果选择器不是函数,这些参数将被简单地忽略(函数声明末尾没有参数)。

关于javascript - d3 selectAll 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28927790/

相关文章:

json - 如何将 Neo4j 导出的 JSON 文件导入 D3

Javascript 语法 : variable declaration with "<<" or ">>"

javascript - D3 折叠树 : Scrollable container for tree

javascript - 如何使 jquery.dynamiclist 使用较新版本的 jquery 运行?

javascript - 硬拷贝中的打印按钮

javascript - js.devexpress.com dxDataGrid 如何使用自定义标题导出到 Excel?

Javascript - 找到 TD 宽度 ="70%"并添加 CSS

javascript - 计算d3中的多边形面积

javascript - D3 SVG 无法响应调整大小

javascript - 如何为使用 Javascript 显示的内容创建过滤器?