Giter VIP home page Giter VIP logo

vue-network-d3's Introduction

中文文档

D3 Force-Directed Graph as Vue Component.

Demo

Install

npm install vue-network-d3 --save

Quick Start

<template>
  <div id="app">
    <network :nodeList="nodes" :linkList="links"></network>
  </div>
</template>

<script>
import Network from "vue-network-d3";

export default {
  name: "app",
  components: {
    Network
  },
  data() {
    return {
      nodes: [
      	{"id": "Myriel", "group": 1},
      	{"id": "Napoleon", "group": 1},
        {"id": "Labarre", "group": 2},
        {"id": "Valjean", "group": 2}
      ],
      links: [
        {"source": "Napoleon", "target": "Myriel", "value": 1},
        {"source": "Valjean", "target": "Labarre", "value": 1},
        {"source": "Napoleon", "target": "Valjean", "value": 2},
      ]
    };
  },
};
</script>

<style>
body {
  margin: 0;
}
</style>

Props

Overview

props: {
    nodeList: Array,
    linkList: Array,
    // node related:
    nodeSize: {
      type: Number,
      default: 14
    },
    nodeTextKey: {
      type: String,
      default: "id"
    },
    nodeTypeKey: {
      type: String,
      default: "group"
    },
    nodeTextFontSize: {
      type: Number,
      default: 14
    },
    bodyStrength: {
      type: Number,
      default: -150
    },
    // link related:
    linkWidth: {
      type: Number,
      default: 2
    },
    showLinkText: {
      type: Boolean,
      default: false
    },
    linkTextKey: {
      type: String,
      default: "value"
    },
    linkTypeKey: {
      type: String,
      default: "type"
    },
    linkTextFrontSize: {
      type: Number,
      default: 10
    },
    linkDistance: {
      type: Number,
      default: 50
    },
    // svg raleted:
    svgSize: {
      type: Object,
      default: () => {
        return {
          width: window.innerWidth,
          height: window.innerHeight
        };
      }
    },
    svgTheme: {
      type: String,
      default: "light" // dark or light
    },
    // others:
    highlightNodes: {
      type: Array,
      default: () => {
        return [];
      }
    }
}

Detailed Design

「:star:」​ means necessary

  • ⭐ ​nodeList: Array of Node Object which has

    • id: Number or String. Node id and also node name (can be changed by nodeTextKey)
    • group: Number or String. like node type (can be changed by nodeTypeKey)
  • linkList: Array of Link Object which has

    • source: Number or String. Id of source node.
    • target: Number or String. Id of target node.
    • value: Number or String. Link name (can be changed by linkTextKey)
  • nodeSize: Number.

  • nodeTextKey: String. Key of node text/name. The default value is 'id', you need to set it to 'name' if your node object is like:

    {
      id: 1010,
      name: 'Myriel'
    }
  • nodeTypeKey: String. Key of node type. The default value is 'group', you need to set it to 'type' if your node object is like:

    {
      id: 'Myriel',
      type: 1
    }
  • nodeTextFontSize: Number.

  • linkWidth: Number.

  • showLinkText: Boolean. Show link text or not. Suggest keeping it false, link text will show when you hover on the link.

  • linkTextKey: String. Key of link text/name. The default value is 'value', you need to set it to 'name' If your link object is like:

    {
      source: 'Napoleon',
      target: "Myriel", 
      name: 'friend'
    }
  • linkTypeKey: String. Key of link type. The default value is 'type'.

  • linkTextFrontSize: Number.

  • linkDistance: Number.

  • svgSize: Object which has

    • width: Number.
    • height: Number
  • svgTheme: String. 'light' or 'dark', 'light' is default.

  • bodyStrength: Number. A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge.

  • highlightNodes: Array of node id. Stroke of nodes turn yellow.

Events

  • clickNode: emits (event, node-object)
  • clickLink: emits (event, link-object)
  • hoverNode: emits (event, node-object)
  • hoverLink: emits (event, link-object)

Classes

  • .element: all nodes and links
  • .node: all nodes
  • .link: all links
  • .[type]: nodes where node[nodeTypeKey] == type, links where link[linkTypeKey] == type
  • .selected: selected nodes (clicked node with its first layer nodes)

Reference

Repo

TODO

  • Docs: props and events
  • Learn Vue-CLI more
  • Fix: node's style when hover
  • CI

vue-network-d3's People

Contributors

yuleicul avatar

Watchers

James Cloos 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.