https://github.com/d3/d3/blob/master/API.md#selections-d3-selection
1.Selecting Elements
方法 | 描述 |
---|---|
d3.selection() | select the root document element. |
d3.select(selector) | 选择 |
d3.selectAll(selector) | 选择 |
selection.select(selector) | 后代选择 |
selection.selectAll(selector) | 后代选择 |
selection.filter(filter) | 过滤选择 |
selection.merge(other) | 合并选择 |
d3.matcher(selector) | 判断是否匹配,一般不考虑,filter 自带 |
d3.selector(selector) | 一般不考虑,select 自带 |
d3.selectorAll | select elements. |
d3.window(node) | get a node’s owner window. |
d3.style(node, name) | get a node’s current style value. |
2.Modifying Elements
方法 | 描述 |
---|---|
selection.attr(name[, value]) | 获得或设置属性 |
selection.classed(names[, value]) | get, add or remove CSS classes. |
selection.style(name[, value[, priority]]) | get or set a style property. |
selection.property(name[, value]) | get or set a (raw) property. |
selection.text([value]) | get or set the text content. |
selection.html([value]) | get or set the inner HTML. |
selection.append(type) | create, append and select new elements. |
selection.insert(type[, before]) | create, insert and select new elements. |
selection.remove() | remove elements from the document. |
selection.clone([deep]) | insert clones of selected elements. |
selection.sort(compare) | sort elements in the document based on data. |
selection.order() | reorders elements in the document to match the selection. |
selection.raise() | reorders each element as the last child of its parent. |
selection.lower() | reorders each element as the first child of its parent. |
d3.create(name) | 不常用,append 自动使用 |
d3.creator(name) | create an element by name. |
3.Joining Data
方法 | 描述 |
---|---|
selection.data | bind elements to data. |
selection.join | 整合enter exit和update |
selection.enter | get the enter selection (data missing elements). |
selection.exit | get the exit selection (elements missing data). |
selection.datum | get or set element data (without joining). |
4.Handling Events
方法 | 描述 |
---|---|
selection.on | add or remove event listeners. |
selection.dispatch | dispatch a custom event. |
d3.event | the current user event, during interaction. |
d3.customEvent | temporarily define a custom event. |
d3.mouse | get the mouse position relative to a given container. |
d3.touch | get a touch position relative to a given container. |
d3.touches | get the touch positions relative to a given container. |
d3.clientPoint | get a position relative to a given container. |
5.Control Flow
方法 | 描述 |
---|
selection.each - call a function for each element.
selection.call - call a function with this selection.
selection.empty - returns true if this selection is empty.
selection.nodes - returns an array of all selected elements.
selection.node - returns the first (non-null) element.
selection.size - returns the count of elements.
6.Local Variables
方法 | 描述 |
---|
d3.local - declares a new local variable.
local.set - set a local variable’s value.
local.get - get a local variable’s value.
local.remove - delete a local variable.
local.toString - get the property identifier of a local variable.
7.Namespaces
方法 | 描述 |
---|
d3.namespace - qualify a prefixed XML name, such as “xlink:href”.
d3.namespaces - the built-in XML namespaces.