<commit_before>'use strict';

var is = require( '../../../is' );

var CRp = {};

CRp.drawCachedNode = function( context, node ){
  var r = this;
  var _p = node._private;
  var caches = _p.rscratch.imgCaches = _p.rscratch.imgCaches || {};
  var lvl = 0;
  var bb = node.boundingBox();

  if( !caches[lvl] ){
    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');

    canvas.width = bb.w;
    canvas.height = bb.h;

    r.drawNode( context, node, true );

    caches[lvl] = { canvas: canvas, context: context };
  }

  context.drawImage( caches[lvl].canvas, bb.x1, bb.y1 );
};

CRp.drawNode = function( context, node, shiftToOrigin ){
  var r = this;
  var nodeWidth, nodeHeight;
  var rs = node._private.rscratch;
  var _p = node._private;
  var pos = pos || _p.position;

  if( !is.number( pos.x ) || !is.number( pos.y ) ){
    return; // can't draw node with undefined position
  }

  var usePaths = this.usePaths();
  var canvasContext = context;
  var path;
  var pathCacheHit = false;<commit_msg>canvas cache drawing properly on init<commit_after>'use strict';

var is = require( '../../../is' );

var CRp = {};

CRp.drawCachedNode = function( context, node ){
  var r = this;
  var _p = node._private;
  var rs = _p.rscratch;
  var caches = rs.imgCaches = rs.imgCaches || {};
  var lvl = 0;
  var bb = node.boundingBox();
  var cache = caches[lvl];

  if( !cache ){
    var lvlCanvas = document.createElement('canvas');
    var lvlContext = lvlCanvas.getContext('2d');

    lvlCanvas.width = bb.w;
    lvlCanvas.height = bb.h;

    r.drawNode( lvlContext, node, true );

    cache = caches[lvl] = { canvas: lvlCanvas, context: lvlContext };
  }

  context.drawImage( cache.canvas, bb.x1, bb.y1 );
};

CRp.drawNode = function( context, node, shiftToOrigin ){
  var r = this;
  var nodeWidth, nodeHeight;
  var rs = node._private.rscratch;
  var _p = node._private;
  var pos = pos || _p.position;

  if( !is.number( pos.x ) || !is.number( pos.y ) ){
    return; // can't draw node with undefined position
  }

  var usePaths = this.usePaths();
  var canvasContext = context;
  var path;
  var pathCacheHit = false;
{'fraction_non_alphanumeric': 0.15284854099119963, 'fraction_numerical': 0.0037054191755442334, 'mean_word_length': 3.098671726755218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2228210', 'n_tokens_mistral': 792, 'n_tokens_neox': 766, 'n_words': 205}