Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to pin nodes after simulation #92

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- **Canvas** render
- Links and nodes selection
- **svg <-> canvas** shared styles via css
- **Screenshots**, *export as svg or png (svg renderer), export as png (canvas renderer)*
- **Screenshots**, *export as svg or png (svg renderer), export as png (canvas renderer)*
- **Touch support**

## Installation
Expand All @@ -38,7 +38,7 @@ npm install vue-d3-network --save

```

``` javascript
``` javascript
import D3Network from 'vue-d3-network'
components: {
D3Network
Expand Down Expand Up @@ -83,7 +83,7 @@ import D3Network from 'vue-d3-network'
- **w**: Number
- **h**: Number

- **offset**: Object, *graph center offset*
- **offset**: Object, *graph center offset*
- **x**: Number
- **y**: Number

Expand All @@ -95,15 +95,16 @@ import D3Network from 'vue-d3-network'
- **ManyBody**: *Boolean*, use d3.forceManyBody, *takes the negative value of 'force' option*
- **Link**: *Boolean*, use d3.forceLink

- **nodeSize**: Number, *node radius | size in px*
- **nodeSize**: Number, *node radius | size in px*
- **linkWidth**: Number, *link thickness in px*
- **nodeLabels**: Boolean, *show nodes names*
- **linkLabels**: Boolean, *show links names*
- **fontSize**: Number, *for node labels, px*
- **strLinks**: Boolean, *draw links as rect lines*
- **strLinks**: Boolean, *draw links as rect lines*
- **resizeListener**:Boolean, defaults: true ,add listener to window.resize event
- **noNodes**: Boolean, *no render nodes*
- **canvasStyles**: Object
- **pinNodes**: Boolean, *After dragging any node, fix all other nodes without rerunning the simulation*
- ****: Object

## Events

Expand Down
32 changes: 16 additions & 16 deletions dist/vue-d3-network.common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/example/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const methodCall = (vm, action, args) => {
if (args) method(...args)
else method()
} else {
// eslint-disable-next-line
console.error('Call to undefined method:', action)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/vue-d3-network.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default {
if (this.simulation) this.simulation.stop()
if (this.forces.Link !== false) this.simulation = this.simulate(this.nodes, this.links)
else this.simulation = this.simulate(this.nodes)
this.simulation.tick(300)
this.simulation.restart()
},
reset () {
Expand All @@ -326,7 +327,7 @@ export default {
if (this.dragging !== false) {
if (this.nodes[this.dragging]) {
this.simulation.restart()
this.simulation.alpha(0.5)
this.simulation.alpha(0)
this.nodes[this.dragging].fx = pos.x - this.mouseOfst.x
this.nodes[this.dragging].fy = pos.y - this.mouseOfst.y
}
Expand All @@ -343,14 +344,14 @@ export default {
this.dragging = (nodeKey === false) ? false : nodeKey
this.setMouseOffset(event, this.nodes[nodeKey])
if (this.dragging === false) {
this.simulation.alpha(0.1)
this.simulation.alpha(0)
this.simulation.restart()
this.setMouseOffset()
}
},
dragEnd () {
let node = this.nodes[this.dragging]
if (node && !node.pinned) {
if (!this.options.pinNodes && node && !node.pinned) {
// unfix node position
node.fx = null
node.fy = null
Expand Down