src/app/script.js
/**
   * Creates a line between two vertices with a given weight.
   * @param {String} key1 First vertex
   * @param {String} key2 Second vertex
   * @param {weight} w weight of the line
   */
Creates a line between two vertices with a given weight.
@param {String} key1 First vertex
@param {String} key2 Second vertex
@param {weight} w weight of the line
Creates a line between two vertices with a given weight . @param { String } key1 First vertex @param { String } key2 Second vertex @param { weight } w weight of the line
connect(key1, key2, w) {
    const k1 = parseInt(key1, 10);
    const k2 = parseInt(key2, 10);
    const vert1 = this.verticies[k1];
    const vert2 = this.verticies[k2];
    const line = new PIXI.Graphics();
    const num = new PIXI.Text(w, {
      fontWeight: 'bold',
      fontSize: 15,
      fontFamily: 'monospace',
      fill: '#ffffff',
    });
    if (this.verticies[k1].edges[k2] === undefined) {
      this.verticies[k1].edges[k2] = {
        num, line, pos: this.graph.length, edge: this.verticies[k2],
      };
      this.verticies[k2].edges[k1] = {
        num, line, pos: this.graph.length, edge: this.verticies[k1],
      };
      line.lineStyle(5, 0xd63031, 1);
      line.colour = 0xd63031;
      num.x = (vert1.x + vert2.x) / 2;
      num.y = (vert1.y + vert2.y) / 2;
      num.y += 10;
      line.moveTo(vert1.x, vert1.y);
      line.lineTo(vert2.x, vert2.y);
      this.app.stage.addChildAt(line, 0);
      this.app.stage.addChildAt(num, 1);
      this.graph.push([key1, key2, w]);
    } else {
      this.verticies[k1].edges[k2].num.text = w;
      this.graph.splice(this.verticies[k1].edges[k2].pos, 1, [key1, key2, w]);
    }
  }
connect ( key1 , key2 , w ) { const k1 = parseInt ( key1 , 10 ) ; const k2 = parseInt ( key2 , 10 ) ; const vert1 = this . verticies [ k1 ] ; const vert2 = this . verticies [ k2 ] ; const line = new PIXI . Graphics ( ) ; const num = new PIXI . Text ( w , { fontWeight : 'bold' , fontSize : 15 , fontFamily : 'monospace' , fill : '#ffffff' , } ) ; if ( this . verticies [ k1 ] . edges [ k2 ] === undefined ) { this . verticies [ k1 ] . edges [ k2 ] = { num , line , pos : this . graph . length , edge : this . verticies [ k2 ] , } ; this . verticies [ k2 ] . edges [ k1 ] = { num , line , pos : this . graph . length , edge : this . verticies [ k1 ] , } ; line . lineStyle ( 5 , 0xd63031 , 1 ) ; line . colour = 0xd63031 ; num . x = ( vert1 . x + vert2 . x ) / 2 ; num . y = ( vert1 . y + vert2 . y ) / 2 ; num . y += 10 ; line . moveTo ( vert1 . x , vert1 . y ) ; line . lineTo ( vert2 . x , vert2 . y ) ; this . app . stage . addChildAt ( line , 0 ) ; this . app . stage . addChildAt ( num , 1 ) ; this . graph . push ( [ key1 , key2 , w ] ) ; } else { this . verticies [ k1 ] . edges [ k2 ] . num . text = w ; this . graph . splice ( this . verticies [ k1 ] . edges [ k2 ] . pos , 1 , [ key1 , key2 , w ] ) ; } }
Creates a line between two vertices with a given weight.
Creates a line between two vertices with a given weight .