Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jkutianski/d3-clone

D3js plugin for clone nodes from selections.
https://github.com/jkutianski/d3-clone

clone d3-module d3js node node-js node-module nodejs

Last synced: 2 months ago
JSON representation

D3js plugin for clone nodes from selections.

Awesome Lists containing this project

README

        

d3-clone
========
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f424dd4911324201a86c9543e192c4e6)](https://www.codacy.com/app/jkutianski/d3-clone?utm_source=github.com&utm_medium=referral&utm_content=jkutianski/d3-clone&utm_campaign=Badge_Grade)

[![dependencies Status](https://david-dm.org/jkutianski/d3-clone/status.svg)](https://david-dm.org/jkutianski/d3-clone)
[![devDependencies Status](https://david-dm.org/jkutianski/d3-clone/dev-status.svg)](https://david-dm.org/jkutianski/d3-clone?type=dev)

[![Known Vulnerabilities](https://snyk.io/test/github/jkutianski/d3-clone/badge.svg?targetFile=package.json)](https://snyk.io/test/github/jkutianski/d3-clone?targetFile=package.json)

D3js plugin for clone nodes from selections.

The d3-clone add methods to append and insert a duplicate of the selection on which this method was called.
This methods copy all of its attributes and their values, including intrinsic (in–line) listeners. It does not copy the data of the original selection.

You can see the running [example](https://github.com/jkutianski/d3-clone/tree/master/examples) on this [link](https://cdn.rawgit.com/jkutianski/d3-clone/5f755227/examples/cityscape.html)

Install
-------
To install via NPM use `npm install d3-clone`. You can also load directly from [unpkg.com](https://unpkg.com/d3-clone/build/d3-clone.min.js).

```html

```

How to use it
-------------

*Append clone*

```selection.appendClone(source)```

This example append the node selected by `svg.select('#source')` to each node selected from `svg.selectAll('.node')`.

```javascript
var nodes = svg.selectAll('.node')
.exit().remove()
.data(data).enter()
.appendClone(svg.select('#source'));
```
if you've start with this HTML structure
```html











```
after run the code you'll have
```html













```

*Insert clone*

```selection.insertClone(source, before)```

This example insert the node selected by `svg.select('#source')` to each node selected from `svg.selectAll('.node')` before the `svg.select('#existing_node')`.

```javascript
var nodes = svg.selectAll('.node')
.exit().remove()
.data(data).enter()
.insertClone(svg.select('#source'), svg.select('#existing_node'));
```
if you've start with this HTML structure
```html











```
after run the code you'll have
```html













```