All files / lib/renderer renderer.js

0% Statements 0/19
0% Branches 0/6
0% Functions 0/8
0% Lines 0/18

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
import { forEach } from 'lodash'
 
/**
 * A superclass for a Transitive network rendering engine.
 */
 
export default class Renderer {
  /**
   * Renderer constructor
   * @param {Object} transitive the main Transitive object
   */
 
  constructor(transitive) {
    this.transitive = transitive
  }
 
  render() {
    const display = this.transitive.display
    const graph = this.transitive.network.graph
 
    display.styler = this.transitive.styler
 
    graph.vertices.forEach((vertex) => {
      vertex.point.clearRenderData()
    })
    graph.edges.forEach((edge) => {
      edge.clearRenderData()
    })
 
    // Clear the display
    display.clear()
  }
 
  /**
   * Does not need to be implemented by subclass
   */
  // eslint-disable-next-line @typescript-eslint/no-empty-function
  sortElements() {}
 
  /**
   * Does not need to be implemented by subclass
   */
  // eslint-disable-next-line @typescript-eslint/no-empty-function
  focusPath(path) {}
 
  isDraggable(point) {
    const draggableTypes = this.transitive.options.draggableTypes
    if (!draggableTypes) return false
 
    let retval = false
    forEach(draggableTypes, (type) => {
      if (type === point.getType()) {
        // Return true in ether of the following cases:
        // 1. No ID array is provided for this point type (i.e. entire type is draggable)
        // 2. An ID array is provided and it includes this Point's ID
        retval =
          !draggableTypes[type] ||
          draggableTypes[type].indexOf(point.getId()) !== -1
      }
    })
    return retval
  }
}