Skip to content
Snippets Groups Projects
ConnectionsLayer.vue 1.32 KiB
Newer Older
<template>
  <div class="connections">
    <canvas id="pixi"></canvas>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import * as PIXI from 'pixi.js'
Adam Procter's avatar
Adam Procter committed

export default {
  name: 'ConnectionsLayer',
  computed: mapState({
Adam Procter's avatar
Adam Procter committed
    configConnections: (state) => state.configConnections,
  }),
Adam Procter's avatar
Adam Procter committed

  watch: {
    configConnections: {
      deep: true,

      handler() {
        this.drawPixi()
      },
    },
  },

Adam Procter's avatar
Adam Procter committed
  methods: {
    drawPixi() {
Adam Procter's avatar
Adam Procter committed
      var i
Adam Procter's avatar
Adam Procter committed
      var canvas = document.getElementById('pixi')
      const app = new PIXI.Application({
        width: window.innerWidth,
        height: window.innerHeight,
        antialias: true,
        transparent: true,
        view: canvas,
      })
      let graphics = new PIXI.Graphics()
Adam Procter's avatar
Adam Procter committed
      graphics.lineStyle(8, 0xcab6ff)

      for (i = 0; i < Object.keys(this.configConnections).length; i++) {
        //console.log('tock')
        //console.log(this.configConnections[i].x_pos_start)
        //start
        graphics.moveTo(
          this.configConnections[i].x_pos_start,
          this.configConnections[i].y_pos_start
        )
        //end
        graphics.lineTo(
          this.configConnections[i].x_pos_end,
          this.configConnections[i].y_pos_end
        )
      }
Adam Procter's avatar
Adam Procter committed
      app.stage.addChild(graphics)
    },
  },
  mounted() {
    this.drawPixi()
  },
}
</script>