Giter Club home page Giter Club logo

vue-vis-network's Introduction

vue-vis-network

!!! NOTE !!! Hi developer. Please contribute to the project if you find a bug or suggest an improvement / feature. Because I’m very, very busy these days, and it won’t end in the next 2-4 months. Hope you can do it faster than me )

Vue2 component to integrate with Vis-Network views

Build Status Coverage Status Software License Packagist Latest Version Issues

Best reagrds to the https://github.com/alexcode/vue2vis which is the base for this component. This project might have some issues from https://github.com/alexcode/vue2vis

Installation

npm install --save vis-util vis-data vis-network vue-vis-network

or

yarn add vis-util vis-data vis-network vue-vis-network

Usage

Declare the component

import { Network } from "vue-vis-network";
Vue.component('network', Network);

Add the component in the template.

<body>
  <div id="app">
    <network ref="network"
    :nodes="nodes"
    :edges="edges"
    :options="options">
    </network>
  </div>
</body>

Add groups, items and options in your observed data or computed.

new Vue({
  el: '#app',
  data() {
    return {
      nodes: [
        {id: 1,  label: 'circle',  shape: 'circle' },
        {id: 2,  label: 'ellipse', shape: 'ellipse'},
        {id: 3,  label: 'database',shape: 'database'},
        {id: 4,  label: 'box',     shape: 'box'    },
        {id: 5,  label: 'diamond', shape: 'diamond'},
        {id: 6,  label: 'dot',     shape: 'dot'},
        {id: 7,  label: 'square',  shape: 'square'},
        {id: 8,  label: 'triangle',shape: 'triangle'},
      ],
      edges: [
        {from: 1, to: 2},
        {from: 2, to: 3},
        {from: 2, to: 4},
        {from: 2, to: 5}, 
        {from: 5, to: 6},
        {from: 5, to: 7},
        {from: 6, to: 8}
      ],
      options: {
         nodes: {
          borderWidth: 4
         },
         edges: {
          color: 'lightgray'
        }
      }
    }
  },
});

Add Visjs CSS

import "vue-vis-network/node_modules/vis-network/dist/vis-network.css";

Here is a basic working demo

Events

Component Events

By default all Vis-network events are emitted by your component. You can subscribe to a subset by passing an array in the prop events Vis-network event.

<body>
  <div id="app">
    <network ref="network"
    :nodes="nodes"
    :edges="edges"
    :options="options"
    :events="['selectNode', 'hoverNode']"
    @select-node="onNodeSelected"
    @hover-node="onNodeHovered">
    </network>
  </div>
</body>

Data Events

When you pass an Array of data object, it is converted internally as a DataSet. An event with the DataSet object will be fired at mounted. It's name will be prepend with the prop name (Ex: items-mounted, groups-mounted). You could use it to interact with the DataSet.

All the Visjs DataSet event will be prepened the same fashion (items-add, items-remove, items-update). For example, pushing a new object to the items prop will fire a items-add event with the following payload:

{
  event: 'add',
  properties: {
    items: [7],
  },
  senderId: null,
}

Advanced

You can also manage your own data bindings by passing your own DataSet or DataView instead of an Array.

import { DataSet } from 'vue-vis-network';

new Vue({
  el: '#app',
  data() {
    return {
      nodes: new DataSet([
        {id: 1,  label: 'circle',  shape: 'circle' },
        {id: 2,  label: 'ellipse', shape: 'ellipse'},
        {id: 3,  label: 'database',shape: 'database'}
      ]),
      edges: new DataSet([
        {from: 1, to: 2},
        {from: 1, to: 3}
      ]),
      options: {
        nodes: {
          borderWidth: 4
         }
      }
    }
  },
});

Vis-network documentation

For the full reference see:

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ npm run test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Build Setup

# Once you have cloned this repo, install dependencies
$ npm install

# Build for development and production with minification
$ npm run build

Build for production

# Linux
NODE_ENV=production npm run build
# Windows
set NODE_ENV=production && npm run build
# Prepare for NPM
set NODE_ENV=production && npm run build:bundle

Run demo locally

# install vue-vis-network local module  
cd ..  
npm link       
# prepare example
cd example
# install the example dependencies
npm install 
# add local vue-vis-network module to node_modules
npm link vue-vis-network
# run demo server
npm run serve

Go to http://localhost:8080/ to see running examples

NOTE: If you make changes to the library you should run npm run build again in the root folder. The dev server should detect modification and reload the demo

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

vue-vis-network's People

Contributors

alexcode avatar dependabot[bot] avatar m-hoogie avatar menighin avatar r3code avatar scenaristeur avatar skystar-p avatar uier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-vis-network's Issues

5.4.1 is a bad version

on

"version": "5.4.1",

due to https://github.com/visjs/vis-network/blob/f75cebf544eccd1ad37588e654ad546cf3228a5f/examples/network/version_migration/5.4.1_to_6.0.0/manipulationEditEdgeNoDrag.html#L54

could you please publish your package to npm at it seems that it always load

 "dependencies": {
    "vis-network": "^5.4.1"
  },

i've tried to install my fork, with updated packages https://github.com/scenaristeur/vue-vis-network/blob/master/package.json but it says that vue-vis-network is not installed.
Why is vue-vis-network a peer dependency of itself ???

using vis-network events

Hello, i'm new to vue.js and vis network.
I created nodes and edges, and wanting to get the node or edge info (such as id) when i select it.
so i made like this
<network ref="network" :nodes="nodes" :edges="edges" :options="options" :events="['selectNode', 'selectEdge']" @select-node="onNodeSelected" @select-edge="onEdgeSelected" />
i understand that @select-node brings vis events 'selectNode' but how can i get the values of the selected node or edge?
data () { onNodeSelected : [] }
i added onNodeSelected as empty array but when i print it after selecting it, it's still empty..

Setting Node_Env to Production causes page to become unresponsive

Hi r3code team. I am fairly new to VUE and JS in general, and it is very possible that this issue is something that I have done wrong, but it seems to have something to do with having vue-vis-network component and setting the node_env environment variable to production. That being said, when I run my app with node_env set to development, everything seems to work perfectly fine. I would greatly appreciate if someone could give me a hand with this issue.

Also, I am currently using Webpack and vue-cli-service build to minify the app and serve it in production

This is how my app is set up:

//main.js

import { Network } from 'vue-vis-network';
import App from '@/App.vue';
import router from '@/router';
import store from '@/store';

Vue.component('network', Network);

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app');
//MulticastFlows.vue

<template>
  <div>
    <v-container fluid grid-list-xs>
      <v-layout row class="multicastFlowsLayout">
        <v-flex d-flex xs8 class="mr-1">
          <MulticastFlowGraph
                  :loadingElements="loadingElements"
                  :nodes="nodes"
                  :edges="edges"
                  :options="options"
          />
        </v-flex>
      </v-layout>
    </v-container>
  </div>
</template>

<script>
export default {
  name: 'MulticastFlows',
  components: {
    MulticastFlowGraph,
  },
  data() {
    return {
      loadingElements: false,
      nodes: [
        {
          id: '1',
          label: '1',
        },
        {
          id: '2',
          label: '2',
        },
      ],
      edges: [{ from: '1', to: '2', label: '1122' }],
      options: {
        layout: {
          hierarchical: {
            nodeSpacing: 200,
            levelSeparation: 100,
            edgeMinimization: false,
            blockShifting: false,
            direction: 'UD',
            sortMethod: 'directed',
          },
        },
        edges: {
          shadow: { enabled: true },
          arrows: 'to',
          arrowStrikethrough: false,
          smooth: {
            type: 'continuous',
          },
        },
        nodes: {
          physics: false,
          shape: 'box',
          shadow: { enabled: true },
        },
        physics: {
          enabled: false,
        },
      },
    };
  },
};
</script>

<style scoped>
  .multicastFlowsLayout {
    position: absolute;
    width: 98%;
    height: 95%;
  }
</style>
//MulticastFlowGraph.vue

<template>
    <v-card class="pa-2 mx-2 networkCard elevation-5">
        <network class="network"
                 ref="network"
                 :nodes="nodes"
                 :edges="edges"
                 :options="options"/>
    </v-card>
</template>

<script>
export default {
  name: 'MulticastFlowGraph',
  props: [
    'nodes',
    'edges',
    'options',
  ],
  data() {
    return {
    };
  },
};
</script>

<style scoped>
    .network {
        position: absolute;
        top: 0px;
        right: 0px;
        bottom: 0px;
        left: 0px;

    }
</style>

Nuxt.js : ReferenceError

Not really an issue. Just a question because I am a newbie.

Does anyone have experience using with Nuxt.js as SSR? I keep getting "ReferenceError
document is not defined".

My guess is vue-vis-network needs to be setup as a plugin [https://nuxtjs.org/guide/plugins] but I'm not exactly sure how to do that. Any advice or direction would be greatly appreciated!

TIA

Labels are not being displayed in nodes

Here's the example in a CodePen: https://codepen.io/luiscarbonell/pen/xxGMdMM

<!DOCTYPE html>
<html>

<head>
  <title>Vue.js & Vis.js</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/vis-network.min.css">

  <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/vueVisNetwork.umd.js"></script>
  <style>
    * {
      height: 100%;
      width: 100%;
    }
  </style>
</head>

<body>
  <div id="main">
    <div class="columns">
      <div class="column is-6">
        <div class="box">
          <div class="container">
            <input class="input" type="text" placeholder="ID" v-model="form.node.id">
            <input class="input" type="text" placeholder="Label" v-model="form.node.label">

            <div class="field has-addons">
              <p class="control">
                <button class="button is-success" @click="addNode">Create Node</button>
              </p>
              <p class="control">
                <button class="button is-info" @click="editNode">Edit Node</button>
              </p>
              <p class="control">
                <button class="button is-danger" @click="deleteNode">Delete Node</button>
              </p>
            </div>
          </div>
        </div>
      </div>
      <div class="column is-6">
        <div class="box">
          <div class="container">
            <network ref="network" :nodes="network.nodes" :edges="network.edges" :options="network.options" />
          </div>
        </div>
      </div>
    </div>
  </div>

  <script>
    Vue.component('network', vueVisNetwork.Network);

    new Vue({
      el: '#main',
      data() {
        return {
          network: {
            nodes: [{
              id: 1,
              label: "1",
              title: "1"
            }],
            edges: [],
            options: {
              edges: {
                smooth: {
                  type: "cubicBezier",
                  forceDirection: "horizontal",
                  roundness: 0.4
                }
              },
              layout: {
                hierarchical: {
                  direction: "LR"
                }
              },
              nodes: {
                font: "14px sans-serif"
              },
              physics: false
            }
          },
          form: {
            node: {
              id: "",
              label: ""
            },
            edge: {
              id: "",
              from: "",
              to: ""
            }
          }
        }
      },
      methods: {
        addNode() {
          const self = this;
          try {
            const node = { ...self.form.node };
            self.network.nodes.push(node);
          } catch(error) {
            console.log(error)
          }
        },
        editNode() {
          const self = this;
          try {
            const node = { ...self.form.node }; console.log(node);
            const index = self.network.nodes.findIndex(n => n.id == node.id); console.log(index);
            self.network.nodes[index] = {
              ...self.network.nodes[index],
              ...node
            }; console.log(self.network.nodes[index]);
            console.log(self.visData);
          } catch(error) {
            console.log(error);
          }
        },
        deleteNode() {
          
        }
      },
      created() {
      }
    })
  </script>
</body>

</html>

DevTools failed to load SourceMap

nuxt 2.14.5
"vue-vis-network": "^1.0.2"

DevTools failed to load SourceMap: Could not load content for webpack://vueVisNetwork/node_modules/vis-network/dist/vis-network.esm.min.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
``

Wrong mapping for the "on()", "off()" and "once()" methods of "network"

In Network.vue, please correct the following method mappings (probably a bad copy-and-paste) for the on(), off() and once() methods.
Currently they are all mapped to the moveTo() method, which is a mistake:

on(event, callback) {
      this.network.moveTo(event, callback);
    },
    off(event, callback) {
      this.network.moveTo(event, callback);
    },
    once(event, callback) {
      this.network.moveTo(event, callback);
    },

should be:

on(event, callback) {
      this.network.on(event, callback);
    },
    off(event, callback) {
      this.network.off(event, callback);
    },
    once(event, callback) {
      this.network.once(event, callback);
    },

These methods are very useful, I have a project currently blocked because of this issue.
Please fix it!

Thank you in advance.

Unexpected token "*"

I am trying to use vue-vis-network with Parcel.
But I am getting error:
изображение

Does it mean that vue-vis-network do not compatible with Parcel?

Constructor must be called with the new operator

When I am trying to add vis-network not in main component I am getting error: Constructor must be called with the new operator

<template>
    <el-container >
            <el-main>

                <network ref="network" :nodes="nodes" :edges="edges" :options="options"> </network>                        

                 <button @click="get_data">GetData</button>

            </el-main>
	</el-container>
</template>

<script>
    export default {
    	components: { Notification },
        data () {
            return {
              nodes: [],
              edges: [],
              options: []
            }
        },

        methods:
        {
          get_data()
          {

            axios.get(base_url + '/graph')
               .then((response) => {
                this.nodes = response.data.nodes;
                this.edges = response.data.edges;
                }).catch((error) => {
                          console.log(error);
                        });  
          
          }

        },
    }
</script>

index.js:

import vueVisNetwork from 'vis-network'

import locale from 'element-ui/lib/locale/lang/ru-RU'
window.axios = require('axios');
Vue.use(ElementUI, { locale })
Vue.use(Router)
Vue.component('network', vueVisNetwork.Network);

window.base_url = "http://127.0.0.1:8000"

new Vue({
  el: '#app',
  locale: 'ru',
  render: h => h(App)
});

Event code on the readme does not work

The code on the readme that demonstrates events calls the events: selectNode, hoverNode. I tried it and it does not work, it only works if I call them select-node and hover-node, like in the 'examples' folder.
Maybe I'm wrong but my guess is someone updated the library but forgot to update the readme.
I would be happy to do so.
It's a really nice project by the way, keep the good work!

No css file found on dist folder

The github page instructs to use the style in the dist folder, but there is no css file there. I builded and example and it was not showing properly.

Dist files are too havy

Dist UMD is too heavy because it includes vis-network which adds 700kb and if removed the UMD becomes ~30kb.

  1. make vis-network a peer dependency.
  2. change vis.config to externalize dependencies
  3. update readme install command, should include peer dependencies now

vueVisNetwork.css file missing in dist folder

The README says:

Add Visjs CSS

@import "vue-vis-network/dist/vueVisNetwork.css";

However, once vue-vis-network is npm-installed, the node_modules\vue-vis-network\dist folder does not contain the expected CSS file.

It is needed for proper display of the interaction and manipulation features of vis-network.

Vue 3

Has anybody tried to upgrade to Vue 3? I tried and failed. I get argument errors in most function call related to strict mode. If someone is willing to work with me, I will provide more details. Thanks. Gordon. @r3code @skystar-p @Menighin @scenaristeur

Not Found - GET https://registry.npmjs.org/vue-vis-network - Not found

$ npm install --save vue-vis-network
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/vue-vis-network - Not found
npm ERR! 404
npm ERR! 404  'vue-vis-network@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

How to fix it?

Infinite loop warning when using edges.smooth and layout.hierarchical together in options

I am using vue-vis-network 1.0.2 and I see following warning in Chrome DevTools

[Vue warn]: You may have an infinite update loop in watcher with expression "options"

found in

---> <Network> at src/components/Network.vue
       ...

when using the following options together

options: {
    ...
    layout: {
          hierarchical: {
            enabled: true,
            sortMethod: 'directed'
          }
    },
    ...
    edges: {
         ...
          smooth: {
            type: 'cubicBezier',
            forceDirection: 'horizontal',
            roundness: 0.5
          }
    }
}

The warning will disappear if I remove either of them. I don't find information on any restrictions using these two options. Any ideas?

double click event not working

The @doubleclick event is not fired

Here is my code:

  <network
        ref="network"
        :nodes="nodes"
        :edges="edges"
        :options="options"
        :events="['doubleClick', 'oncontext']"
        @doubleClick="onNodeClick"
        @oncontext="onContextClick"
      ></network>
...


 onNodeClick: function (params) {
      console.log("Clicked double");
      //console.log("HALLOHALLO");
      if (params.nodes.length == 1) {
        if (this.$refs.network.isCluster(params.nodes[0]) == true) {
          this.$refs.network.openCluster(params.nodes[0]);
        }
      }
    }

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.