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

Labels are not being displayed in nodes #9

Open
luiscarbonell opened this issue Mar 30, 2020 · 0 comments
Open

Labels are not being displayed in nodes #9

luiscarbonell opened this issue Mar 30, 2020 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@luiscarbonell
Copy link

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/bulma@0.8.1/css/bulma.min.css">
  <link rel="stylesheet" href="https://unpkg.com/vis-network@7.4.0/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/vue-vis-network@1.0.2/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>
@r3code r3code added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants