d3-moveto works with D3 selections to let you move SVG elements to the front or back of their parent SVG.
npm install d3-movetod3-moveto works with D3 selections to let you move SVG elements to the front or back of their parent SVG.
In interactive data visualizations, it is often necessary to bring elements to the front or back. But it is not easy to do this with SVG.
Unlike HTML elements, SVG elements have no z-index attribute, so it is impossible to make a younger sibling appear on top of an older one. Therefore, in SVG, elements which are appended to the DOM first will always appear on top of elements appended later.
If you use NPM, npm install d3-moveto. Otherwise, download the latest release. You can also load directly from unpkg. You may use the entire D3.js library or, at a minimum, d3-selection.
``html
``
# selection.moveToBack()
Moves a selected SVG element to the back of the SVG.
# selection.moveToFront()
Moves a selected SVG element to the front of the SVG.