******************** Canvas ********************************************
557453
private void drawTime() {
        ctx.clearRect(0, 0, width, height);

        // draw hours
        drawMatrix(0, 0, hl, hourGradient, hourOffGradient);
        drawMatrix(digitWidth + digitSpacer, 0, hr, hourGradient, hourOffGradient);

        // draw colon

        // draw minutes
        drawMatrix(2 * digitWidth + 3 * digitSpacer, 0, ml, minuteGradient, minuteOffGradient);
        drawMatrix(3 * digitWidth + 4 * digitSpacer, 0, mr, minuteGradient, minuteOffGradient);

        // draw colon

        // draw seconds
        drawMatrix(4 * digitWidth + 6 * digitSpacer, 0, sl, secondGradient, secondOffGradient);
        drawMatrix(5 * digitWidth + 7 * digitSpacer, 0, sr, secondGradient, secondOffGradient);
    }
411793
function(){
    this.width = this.container.width();
    this.height = this.container.height();
    this.resize();
    this.canvas.setSize(this.width, this.height);
    this.applyTransform();
  }
77370
protected function canvasSpacingY()
    {
        $this->canvas['spacing']['y'] = 0;

        if ($this->intermediate['height'] < $this->canvas['height']) {

            $difference = $this->canvas['height'] - $this->intermediate['height'];

            if ($difference % 2 === 0) {
                $this->canvas['spacing']['y'] = $difference / 2;
            } else {
                if ($difference > 1) {
                    $this->canvas['spacing']['y'] = ($difference - 1) / 2 + 1;
                } else {
                    $this->canvas['spacing']['y'] = 1;
                }
            }
        }
    }
554954
protected void onDrawFrame( SurfaceView view , Canvas canvas ) {

		// Code below is usefull when debugging display issues
//		Paint paintFill = new Paint();
//		paintFill.setColor(Color.RED);
//		paintFill.setStyle(Paint.Style.FILL);
//		Paint paintBorder = new Paint();
//		paintBorder.setColor(Color.BLUE);
//		paintBorder.setStyle(Paint.Style.STROKE);
//		paintBorder.setStrokeWidth(6*displayMetrics.density);
//
//		Rect r = new Rect(0,0,view.getWidth(),view.getHeight());
//		canvas.drawRect(r,paintFill);
//		canvas.drawRect(r,paintBorder);
		switch( bitmapMode) {
			case UNSAFE:
				canvas.drawBitmap(this.bitmap, imageToView, null);
				break;

			case DOUBLE_BUFFER:
				bitmapLock.lock();
				try{
					canvas.drawBitmap(this.bitmap, imageToView, null);
				} finally {
					bitmapLock.unlock();
				}
				break;
		}
	}
767660
private void drawRipple(Canvas canvas) {
		canvas.save();
		canvas.clipPath(getCircleClipPath(), Region.Op.INTERSECT);
		TouchPoint point = getActionButton().getTouchPoint();
		canvas.drawCircle(point.getLastX(), point.getLastY(), currentRadius, getPreparedPaint());
		canvas.restore();
	}
305766
function drawChart(canvas, data) {
        var ctx = canvas.getContext('2d'),
            color = 'rgba(0, 0, 0, 0.75)',
            height = canvas.height - 2,
            width = canvas.width,
            total = data.length,
            max = Math.max.apply(Math, data),
            xstep = 1,
            ystep = max / height,
            x = 0,
            y = height - data[0] / ystep;

        ctx.clearRect(0, 0, width, height);
        ctx.beginPath();
        ctx.strokeStyle = color;
        ctx.moveTo(x, y);

        for (var i = 1; i < total; i++) {
            x += xstep;
            y = height - data[i] / ystep + 1;
            ctx.moveTo(x, height);
            ctx.lineTo(x, y);
        }

        ctx.stroke();
    }
1058488
function() {
        for ( var i = 0; i < this._items.length; i++ ) {
            this._items[i].draw();
        }

        this._needsDraw = false;
    }
1307634
@Override
	public void draw(float x,float y, Color filter) {
		draw(x,y,getWidth(),getHeight(), filter);
	}
1054068
public void draw(Canvas canvas) {
    for (int i = 0; i < mHolders.size(); ++i) {
      Drawable drawable = get(i).getTopLevelDrawable();
      if (drawable != null) {
        drawable.draw(canvas);
      }
    }
  }
88230
function Canvas(width, height, gmsmith) {
  // Ignore width/height
  // DEV: Our canvas dimensions are dynamically defined by x/y of each image
  var canvas = gmsmith.gm(1, 1, 'transparent');

  // Override the -size options (won't work otherwise)
  canvas._in = ['-background', 'transparent'];

  // Save the canvas
  this.canvas = canvas;
}
820671
function Canvas(htmlElement) {
	/*
	 * initialization
	 */
	this.id = htmlElement.id;
	this.htmlElement = htmlElement;
	this.blocks = new Array();
	this.connectors = new Array();
	this.offsetLeft = calculateOffsetLeft(this.htmlElement);
	this.offsetTop = calculateOffsetTop(this.htmlElement);	
	
	this.width;
	this.height;

	// create the inner div element
	this.innerDiv = document.createElement ("div");
	
	this.initCanvas = function() {
		// setup the inner div
		var children = this.htmlElement.childNodes;
		var el;
		var n = children.length;
		for(var i = 0; i < n; i++) {
			el = children[0];
			this.htmlElement.removeChild(el);
			this.innerDiv.appendChild(el);
			if(el.style)
				el.style.zIndex = "2";
		}
		this.htmlElement.appendChild(this.innerDiv);

		this.htmlElement.style.overflow = "auto";
		this.htmlElement.style.position = "relative";
		this.innerDiv.id = this.id + "_innerDiv";
		this.innerDiv.style.border = "none";
		this.innerDiv.style.padding = "0px";
		this.innerDiv.style.margin = "0px";
		this.innerDiv.style.position = "absolute";
		this.innerDiv.style.top = "0px";
		this.innerDiv.style.left = "0px";
		this.width = 0;
		this.height = 0;
		this.offsetLeft = calculateOffsetLeft(this.innerDiv);
		this.offsetTop = calculateOffsetTop(this.innerDiv);

		// inspect canvas children to identify first level blocks
		new DocumentScanner(this, true).scan(this.htmlElement);
		
		// now this.width and this.height are populated with minimum values needed for the inner
		// blocks to fit, add 2 to avoid border overlap;
		this.height += 2;
		this.width += 2;
		
		var visibleWidth = this.htmlElement.offsetWidth - 2; // - 2 is to avoid border overlap
		var visibleHeight = this.htmlElement.offsetHeight - 2; // - 2 is to avoid border overlap
		
		// consider the scrollbars width calculating the inner div size
		if(this.height > visibleHeight)
			visibleWidth -= SCROLLBARS_WIDTH;
		if(this.width > visibleWidth)
			visibleHeight -= SCROLLBARS_WIDTH;
			
		this.height = Math.max(this.height, visibleHeight);
		this.width = Math.max(this.width, visibleWidth);
		
		this.innerDiv.style.width = this.width + "px";
		this.innerDiv.style.height = this.height + "px";
		
		// init connectors
		for(i = 0; i < this.connectors.length; i++) {
			this.connectors[i].initConnector();
		}
	}
	
	this.visit = function(element) {
		if (element == this.htmlElement)
			return true;
	
		// check the element dimensions against the acutal size of the canvas
		this.width = Math.max(this.width, calculateOffsetLeft(element) - this.offsetLeft + element.offsetWidth);
		this.height = Math.max(this.height, calculateOffsetTop(element) - this.offsetTop + element.offsetHeight);
		
		if(isBlock(element)) {
			// block found initialize it
			var newBlock = new Block(element, this);
			newBlock.initBlock();
			this.blocks.push(newBlock);
			return false;
		} else if(isConnector(element)) {
			// connector found, just create it, source or destination blocks may not 
			// have been initialized yet
			var newConnector = new Connector(element, this);
			this.connectors.push(newConnector);
			return false;
		} else {
			// continue searching nested elements
			return true;
		}
	}
	
	/*
	 * methods
	 */	
	this.print = function()
	{
		var output = '<ul><legend>canvas: ' + this.id + '</legend>';
		var i;
		for(i = 0; i < this.blocks.length; i++)
		{
			output += '<li>';
			output += this.blocks[i].print();
			output += '</li>';
		}
		output += '</ul>';
		return output;
	}
	
	this.alignBlocks = function() {
		var i;
		var roof = 0;
		// TODO: implement proper layout
		for (i = 0; i < this.blocks.length ; i++) {
			var b = this.blocks[i]; //.findBlock(blockId);
			b.onMove();
			b.htmlElement.style.top =roof;
			roof += b.htmlElement.style.height+20;
			// TODO: alert ("align "+b);
		}
		for (i = 0; i < this.connectors.length; i++) {
			this.connectors[i].repaint();
			console.log( this.connectors[i]);
		}
	}

	this.fitBlocks = function() {
		for (var i = 0; i < this.blocks.length ; i++) {
			var b = this.blocks[i]; //.findBlock(blockId);
			this.blocks[i].fit ();
		}
	}
	/*
	 * This function searches for a nested block with a given id
	 */
	this.findBlock = function(blockId) {
		var result;
		for(var i = 0; i < this.blocks.length && !result; i++)
			result = this.blocks[i].findBlock(blockId);
		return result;
	}
	
	this.toString = function() {
		return 'canvas: ' + this.id;		
	}
}
1014190
function (size) {
        this.canvasContext.canvas.width = size.w;
        this.canvasContext.canvas.height = size.h;

        this.size = size;
    }
575588
function () {
                var _this = this;
                /** @type {?} */
                var canvas = this.canvas.nativeElement;
                /** @type {?} */
                var ctx = canvas.getContext('2d');
                ctx.lineWidth = this.weight;
                ctx.strokeStyle = this.color;
                ctx.beginPath();
                this._sortedPoints.forEach(function (point, index) {
                    if (index === 0) {
                        ctx.moveTo(point.x, point.y);
                    }
                    if (index !== _this._sortedPoints.length - 1) {
                        /** @type {?} */
                        var nextPoint = _this._sortedPoints[index + 1];
                        ctx.lineTo(nextPoint.x, nextPoint.y);
                    }
                    else {
                        ctx.closePath();
                    }
                });
                ctx.stroke();
            }
1268977
@Override
	protected void onDraw(Canvas canvas) {

		if (adaptedImage != null)
			canvas.drawBitmap(adaptedImage, 0, 0, paint);

	}
840939
public Canvas draw (Drawable image, float x, float y) {
    return draw(image, x, y, image.width(), image.height());
  }
905234
function CanvasControl(canvas, elements, callbackFunc) {
  this._canvas = canvas;
  this._elements = elements;
  this._callbackFunc = callbackFunc;

  this._context = this._canvas.getContext('2d');
  this._cursorDown = false;

  this._selected = {
    index: -1,
    xOffset: 0,
    yOffset: 0,
  };

  this._lastMoveEventTime = 0;
  this._minimumThreshold = 16;
  let that = this;
  canvas.addEventListener('touchstart', function(event) {
    that._cursorDownFunc(event);
  });

  canvas.addEventListener('mousedown', function(event) {
    that._cursorDownFunc(event);
  });

  canvas.addEventListener('touchmove', function(event) {
    let currentEventTime = Date.now();
    if (currentEventTime - that._lastMoveEventTime > that._minimumThreshold) {
      that._lastMoveEventTime = currentEventTime;
      if (that._cursorMoveFunc(event)) {
        event.preventDefault();
      }
    }
  }, true);

  canvas.addEventListener('mousemove', function(event) {
    let currentEventTime = Date.now();
    if (currentEventTime - that._lastMoveEventTime > that._minimumThreshold) {
      that._lastMoveEventTime = currentEventTime;
      that._cursorMoveFunc(event);
    }
  });

  document.addEventListener('touchend', function(event) {
    that._cursorUpFunc(event);
  });

  document.addEventListener('mouseup', function(event) {
    that._cursorUpFunc(event);
  });

  window.addEventListener('resize', function(event) {
    that.resize();
    that.draw();
  }, false);

  this.invokeCallback();
  this.resize();
  this.draw();
}
454121
function Canvas(width, height, buffer) {
    width  = _.defaults(width , 640)|0;
    height = _.defaults(height, 400)|0;

    if (Canvas.isCanvasRGB(width, height, buffer)) {
      return new CanvasRGB(width, height, buffer);
    }
    if (Canvas.isCanvasRGBA(width, height, buffer)) {
      return new CanvasRGBA(width, height, buffer);
    }

    var $ = dollar(width, height, 1, buffer);

    $.putPixel = function(x, y, color) {
      var index = y * width + x;

      if ($.mask && $.mask[index] === 0) {
        return;
      }

      var colorIndex = color.valueOf(x, y);

      if (colorIndex !== -1) {
        $.data[index] = colorIndex & 15;
      }
    };

    this.$ = $;
  }