d3 vs. svg When Dealing with Element

Dan K.

Is there a preference between using

d3.selectAll()

and

svg.selectAll()

when

var svg = d3.select("#someChart")
            .append("svg")
            .attr("width", w)
            .attr("height", h);

when dealing with(creating, removing) elements in the svg tag?

meetamit

As AJ_91 pointed out, d3.selectAll(...) searches the entire document, whereas svg.selectAll(...) limits the search to the SVG in the selection. The latter is expectedly more performant for large documents.

However, there's another important difference: If the var svg references a d3 selection that contains more than a single element then a subselection like svg.selectAll('path') will select all <path>s within each <svg> as expected, but the resulting selection will also maintain "awareness" of the "cousin" relationship between <path>s that have different <svg> parents.

This is called nested selections as bostock explains here. Nested selections are used for constructing tables, since tables imply a 2-level hierarchy (n rows then m columns per row). The nested-svg-selection analog to tables would be if you have a multi-level dataset from which you wanted to create multiple SVG's, each of which contains multiple trendline paths (or multiple barchart <rect>s, etc).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

D3 geometric zoom when there is no SVG element under the cursor

From Dev

SVG path element created by d3 (d3.svg.arc) disappearing when mask is applied

From Dev

SVG path element created by d3 (d3.svg.arc) disappearing when mask is applied

From Dev

How to change properties of elements in a SVG when I mouseover an element of a second SVG using D3

From Dev

Alternative to eval() when dealing with d3 animation queues

From Dev

d3: key function choice when appending element to an existing svg

From Dev

cx, cy vs transform in svg and D3, what is the difference?

From Dev

D3 Force layout DIV vs SVG

From Dev

cx, cy vs transform in svg and D3, what is the difference?

From Dev

D3 multi-line tooltip for SVG element

From Dev

D3 append (insert) existing SVG string (or element) to a DIV

From Dev

D3: How to select every thing under svg element

From Dev

d3 doesn't append namespace attributes to svg element

From Dev

D3 events firing on a hidden svg element

From Dev

Bind Bootstrap tooltip to dynamically created SVG element with d3

From Dev

D3 - Positioning tooltip on SVG element not working

From Dev

Get class of selected svg element in d3

From Dev

d3 mouseover on element conflicts with svg mousemove

From Dev

Enlarge svg group element on mouseenter (D3)

From Dev

d3 - rendering an html table on top of an svg element

From Dev

D3: add filter as background to SVG element

From Dev

d3 Trying to select text within a svg text element

From Dev

D3: change data based on svg element manipulation

From Dev

svg rendering order of lines and shapes when using d3

From Dev

When to use duration vs delay in d3

From Dev

D3 how to select element by ID when there is a dot in ID

From Dev

Dealing with element Id conflicts when displying multiple grids

From Dev

How can I get the dom svg element from d3 node data?

From Dev

how to assign unique id to SVG text element in d3 javascript

Related Related

  1. 1

    D3 geometric zoom when there is no SVG element under the cursor

  2. 2

    SVG path element created by d3 (d3.svg.arc) disappearing when mask is applied

  3. 3

    SVG path element created by d3 (d3.svg.arc) disappearing when mask is applied

  4. 4

    How to change properties of elements in a SVG when I mouseover an element of a second SVG using D3

  5. 5

    Alternative to eval() when dealing with d3 animation queues

  6. 6

    d3: key function choice when appending element to an existing svg

  7. 7

    cx, cy vs transform in svg and D3, what is the difference?

  8. 8

    D3 Force layout DIV vs SVG

  9. 9

    cx, cy vs transform in svg and D3, what is the difference?

  10. 10

    D3 multi-line tooltip for SVG element

  11. 11

    D3 append (insert) existing SVG string (or element) to a DIV

  12. 12

    D3: How to select every thing under svg element

  13. 13

    d3 doesn't append namespace attributes to svg element

  14. 14

    D3 events firing on a hidden svg element

  15. 15

    Bind Bootstrap tooltip to dynamically created SVG element with d3

  16. 16

    D3 - Positioning tooltip on SVG element not working

  17. 17

    Get class of selected svg element in d3

  18. 18

    d3 mouseover on element conflicts with svg mousemove

  19. 19

    Enlarge svg group element on mouseenter (D3)

  20. 20

    d3 - rendering an html table on top of an svg element

  21. 21

    D3: add filter as background to SVG element

  22. 22

    d3 Trying to select text within a svg text element

  23. 23

    D3: change data based on svg element manipulation

  24. 24

    svg rendering order of lines and shapes when using d3

  25. 25

    When to use duration vs delay in d3

  26. 26

    D3 how to select element by ID when there is a dot in ID

  27. 27

    Dealing with element Id conflicts when displying multiple grids

  28. 28

    How can I get the dom svg element from d3 node data?

  29. 29

    how to assign unique id to SVG text element in d3 javascript

HotTag

Archive