Giter Club home page Giter Club logo

vue-d3-network's Introduction

GitHub issues GitHub license npm

vue-d3-network

Vue component to graph networks using d3-force

vue d3 network

Demo

Demo

Features

  • SVG render
  • 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)
  • Touch support

Installation

npm install vue-d3-network --save

Usage

  ...  
  <d3-network :net-nodes="nodes" :net-links="links" :options="options" />
  ...
import D3Network from 'vue-d3-network'
...
  components: {
    D3Network
  },
....
<style src="vue-d3-network/dist/vue-d3-network.css"></style>

Or: import source component from: 'vue-d3-network/src/vue-d3-network.vue' And install devDependencies. (d3-force, stylus and pug) See: package.json)

Props

net-nodes: Array of nodes objects:

  • id: node id. If not provided uses array index
  • name: node name. If not provided uses: 'node [node_id]'
  • _color: node color, e.g. red, #aa00bb,
  • _cssClass: node css class name
  • _labelClass: node label css class name
  • svgSym: node icon, svg document (only works in svg renderer)
  • -_size : node size (svg renderer only)
  • _width: node width (svg renderer only)
  • _height: node height (svg renderer only)
  • _svgAttrs: Object, svg node attributes

net-links: Array of links objects:

  • id: link id. If not provided uses array index
  • name: node name. If not provided uses: 'link [link_id]'
  • tid: id of target node
  • sid: id of source node
  • _color: link color, e.g. red, #aa00bb,
  • _svgAttrs: Object, svg line attributes

selection : Object, links and nodes selected

  • links: Object with node.ids as keys, node objects as values
  • nodes: Object with link.ids as keys, links objects as values

nodeSym: String, node sprite svg doc

nodeCb: Function(node) -> node, node formatter

linkCb: Function(link) -> link, node link formatter

simCb: Function(sim) -> sim, d3 simulation formatter

customForces: Object: { [d3Function]:args }

options:

  • canvas: Boolean, render as canvas, false = svg

  • size: Object, graph size. Default: container size

    • w: Number
    • h: Number
  • offset: Object, graph center offset

    • x: Number
    • y: Number
  • force: Number

  • forces Object:

    • Center: Boolean, use d3.forceCenter
    • X: strength, use d3.forceX
    • Y: strength, use d3.forceY
    • ManyBody: Boolean, use d3.forceManyBody, takes the negative value of 'force' option
    • Link: Boolean, use d3.forceLink
  • 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
    • resizeListener:Boolean, defaults: true ,add listener to window.resize event
    • noNodes: Boolean, no render nodes
  • canvasStyles: Object

Events

  • node-click: fired when click on node, emits (event,node-object)
  • link-click: fired when click on link, emits (event, link-object)
  • screen-shot: fired when screenshot creation is done, emits (error)

Methods

  • screenShot (name, bgColor, toSVG, svgAllCss), all arguments are optional
    • name: file name -** bgColor:** CSS color, png background color
    • toSVG: Boolean, (svg renderer) true: export as svg, false : export as png
    • svgAllCss: Boolean (svg renderer) true: include all styles in svg false: include only matched styles. This option is useful, for example to include hover actions on exported svg file

Css style and canvas style

SVG css classes:

  • .node: nodes symbol
  • .link: link line
  • .node-label: nodes names
  • .node .selected: node selected
  • .link .selected link selected
  • node pinned: node pinned

To use this css styles in canvas we create 'ghosts' svg elements to pick up values from computed css properties. If you want, you can stylize the canvas elements directly, setting: options.canvasStyles, but these styles will not be applied to the svg graph.

see: src/canvasStyles.js

TODO

  • Touch support
  • [] Optimization
  • [] Zoom
  • Canvas Render
  • Nodes sprites

More Examples

vue-d3-network's People

Contributors

emiliorizzo avatar jannesiera avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.