src/data-canvas.js
function getDataContext(ctxOrCanvas) {
  if (ctxOrCanvas instanceof HTMLCanvasElement) {
    return getDataContext(ctxOrCanvas.getContext('2d'));
  }

  var ctx = ctxOrCanvas;
  if (stubGetDataContext) {
    return stubGetDataContext(ctx);
  } else {
    for (var i = 0; i < getDataContext.cache.length; i++) {
      var pair = getDataContext.cache[i];
      if (pair[0] == ctx) return pair[1];
    }
    var dtx = new DataContext(ctx);
    getDataContext.cache.push([ctx, dtx]);
    return dtx;
  }
}
function getDataContext(ctxOrCanvas) {
  if (ctxOrCanvas instanceof HTMLCanvasElement) {
    return getDataContext(ctxOrCanvas.getContext('2d'));
  }

  var ctx = ctxOrCanvas;
  if (stubGetDataContext) {
    return stubGetDataContext(ctx);
  } else {
    for (var i = 0; i < getDataContext.cache.length; i++) {
      var pair = getDataContext.cache[i];
      if (pair[0] == ctx) return pair[1];
    }
    var dtx = new DataContext(ctx);
    getDataContext.cache.push([ctx, dtx]);
    return dtx;
  }
}
function getDataContext ( ctxOrCanvas ) { if ( ctxOrCanvas instanceof HTMLCanvasElement ) { return getDataContext ( ctxOrCanvas . getContext ( '2d' ) ) ; } var ctx = ctxOrCanvas ; if ( stubGetDataContext ) { return stubGetDataContext ( ctx ) ; } else { for ( var i = 0 ; i < getDataContext . cache . length ; i ++ ) { var pair = getDataContext . cache [ i ] ; if ( pair [ 0 ] == ctx ) return pair [ 1 ] ; } var dtx = new DataContext ( ctx ) ; getDataContext . cache . push ( [ ctx , dtx ] ) ; return dtx ; } }
Get a DataContext for the built-in CanvasRenderingContext2D.

This caches DataContexts and facilitates stubbing in tests.

As a convenience, you may pass in a Canvas element instead of a
CanvasRenderingContext2D. data-canvas will call getContext('2d') for you.
Get a DataContext for the built - in CanvasRenderingContext2D .