function render(options) {
  console.log('render', options);

  const cy = this.cy;
  const { context } = this.data;
  const zoom = cy.zoom();
  const pan = cy.pan();

  context.fillStyle = 'red';
  context.strokeStyle = 'blue';

  context.setTransform(1, 0, 0, 1, 0, 0);
  context.clearRect(-99999, -99999, 99999999, 99999999);

  context.translate(pan.x, pan.y);
  context.scale(zoom, zoom);

  cy.edges().forEach(e => {
    const p1 = e.source().position();
    const p2 = e.target().position();

    context.beginPath();
    context.moveTo(p1.x, p1.y);
    context.lineTo(p2.x, p2.y);
    context.closePath();

    context.stroke();
  });

  cy.nodes().forEach(n => {
    const w = n.width();
    const h = n.height();
    const pos = n.position();
    const x = pos.x - w/2;
    const y = pos.y - h/2;

    context.fillRect(x, y, w, h);
  });
}
// focus on this function if you're rendering imperatively
focus on this function if you're rendering imperatively
focus on this function if you ' re rendering imperatively
function render(options) {
  console.log('render', options);
  const cy = this.cy;
  const { context } = this.data;
  const zoom = cy.zoom();
  const pan = cy.pan();
  context.fillStyle = 'red';
  context.strokeStyle = 'blue';
  context.setTransform(1, 0, 0, 1, 0, 0);
  context.clearRect(-99999, -99999, 99999999, 99999999);
  context.translate(pan.x, pan.y);
  context.scale(zoom, zoom);
  cy.edges().forEach(e => {
    const p1 = e.source().position();
    const p2 = e.target().position();
    context.beginPath();
    context.moveTo(p1.x, p1.y);
    context.lineTo(p2.x, p2.y);
    context.closePath();
    context.stroke();
  });
  cy.nodes().forEach(n => {
    const w = n.width();
    const h = n.height();
    const pos = n.position();
    const x = pos.x - w/2;
    const y = pos.y - h/2;
    context.fillRect(x, y, w, h);
  });
}
function render ( options ) { console . log ( 'render' , options ) ; const cy = this . cy ; const { context } = this . data ; const zoom = cy . zoom ( ) ; const pan = cy . pan ( ) ; context . fillStyle = 'red' ; context . strokeStyle = 'blue' ; context . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ; context . clearRect ( - 99999 , - 99999 , 99999999 , 99999999 ) ; context . translate ( pan . x , pan . y ) ; context . scale ( zoom , zoom ) ; cy . edges ( ) . forEach ( e => { const p1 = e . source ( ) . position ( ) ; const p2 = e . target ( ) . position ( ) ; context . beginPath ( ) ; context . moveTo ( p1 . x , p1 . y ) ; context . lineTo ( p2 . x , p2 . y ) ; context . closePath ( ) ; context . stroke ( ) ; } ) ; cy . nodes ( ) . forEach ( n => { const w = n . width ( ) ; const h = n . height ( ) ; const pos = n . position ( ) ; const x = pos . x - w / 2 ; const y = pos . y - h / 2 ; context . fillRect ( x , y , w , h ) ; } ) ; }
focus on this function if you're rendering imperatively
focus on this function if you ' re rendering imperatively