All files / lib/renderer wireframe-renderer.js

0% Statements 0/11
100% Branches 0/0
0% Functions 0/3
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
import { forEach } from 'lodash'
 
import Renderer from './renderer'
 
/**
 * A Renderer subclass for drawing a simplified representation of the graph
 * itself, i.e. just the edges and vertices.
 *
 * @param {Object} the main Transitive object
 */
 
export default class WireframeRenderer extends Renderer {
  render() {
    super.render()
 
    const { display } = this.transitive
    const { graph } = this.transitive.network
 
    // Draw the edges
    forEach(graph.edges, (edge) => {
      // Get a basic, non-offset edge renderData array
      const renderData = edge.getRenderCoords(0, 0, display, true)
 
      display.drawPath(renderData, {
        fill: 'none',
        stroke: '#000',
        'stroke-dasharray': '4,2',
        'stroke-width': 2
      })
    })
 
    // Draw the vertices
    forEach(graph.vertices, (vertex) => {
      display.drawCircle(
        {
          x: display.xScale.compute(vertex.x),
          y: display.yScale.compute(vertex.y)
        },
        {
          fill: '#000',
          r: 4
        }
      )
    })
  }
}