function() {
		var me = this;
		var opts = me.options;
		var labelOpts = opts.labels;
		var globalDefaults = core_defaults.global;
		var defaultColor = globalDefaults.defaultColor;
		var lineDefault = globalDefaults.elements.line;
		var legendWidth = me.width;
		var lineWidths = me.lineWidths;

		if (opts.display) {
			var ctx = me.ctx;
			var fontColor = valueOrDefault$d(labelOpts.fontColor, globalDefaults.defaultFontColor);
			var labelFont = helpers$1.options._parseFont(labelOpts);
			var fontSize = labelFont.size;
			var cursor;

			// Canvas setup
			ctx.textAlign = 'left';
			ctx.textBaseline = 'middle';
			ctx.lineWidth = 0.5;
			ctx.strokeStyle = fontColor; // for strikethrough effect
			ctx.fillStyle = fontColor; // render in correct colour
			ctx.font = labelFont.string;

			var boxWidth = getBoxWidth(labelOpts, fontSize);
			var hitboxes = me.legendHitBoxes;

			// current position
			var drawLegendBox = function(x, y, legendItem) {
				if (isNaN(boxWidth) || boxWidth <= 0) {
					return;
				}

				// Set the ctx for the box
				ctx.save();

				var lineWidth = valueOrDefault$d(legendItem.lineWidth, lineDefault.borderWidth);
				ctx.fillStyle = valueOrDefault$d(legendItem.fillStyle, defaultColor);
				ctx.lineCap = valueOrDefault$d(legendItem.lineCap, lineDefault.borderCapStyle);
				ctx.lineDashOffset = valueOrDefault$d(legendItem.lineDashOffset, lineDefault.borderDashOffset);
				ctx.lineJoin = valueOrDefault$d(legendItem.lineJoin, lineDefault.borderJoinStyle);
				ctx.lineWidth = lineWidth;
				ctx.strokeStyle = valueOrDefault$d(legendItem.strokeStyle, defaultColor);

				if (ctx.setLineDash) {
					// IE 9 and 10 do not support line dash
					ctx.setLineDash(valueOrDefault$d(legendItem.lineDash, lineDefault.borderDash));
				}

				if (opts.labels && opts.labels.usePointStyle) {
					// Recalculate x and y for drawPoint() because its expecting
					// x and y to be center of figure (instead of top left)
					var radius = boxWidth * Math.SQRT2 / 2;
					var centerX = x + boxWidth / 2;
					var centerY = y + fontSize / 2;

					// Draw pointStyle as legend symbol
					helpers$1.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
				} else {
					// Draw box as legend symbol
					if (lineWidth !== 0) {
						ctx.strokeRect(x, y, boxWidth, fontSize);
					}
					ctx.fillRect(x, y, boxWidth, fontSize);
				}

				ctx.restore();
			};
			var fillText = function(x, y, legendItem, textWidth) {
				var halfFontSize = fontSize / 2;
				var xLeft = boxWidth + halfFontSize + x;
				var yMiddle = y + halfFontSize;

				ctx.fillText(legendItem.text, xLeft, yMiddle);

				if (legendItem.hidden) {
					// Strikethrough the text if hidden
					ctx.beginPath();
					ctx.lineWidth = 2;
					ctx.moveTo(xLeft, yMiddle);
					ctx.lineTo(xLeft + textWidth, yMiddle);
					ctx.stroke();
				}
			};

			// Horizontal
			var isHorizontal = me.isHorizontal();
			if (isHorizontal) {
				cursor = {
					x: me.left + ((legendWidth - lineWidths[0]) / 2) + labelOpts.padding,
					y: me.top + labelOpts.padding,
					line: 0
				};
			} else {
				cursor = {
					x: me.left + labelOpts.padding,
					y: me.top + labelOpts.padding,
					line: 0
				};
			}

			var itemHeight = fontSize + labelOpts.padding;
			helpers$1.each(me.legendItems, function(legendItem, i) {
				var textWidth = ctx.measureText(legendItem.text).width;
				var width = boxWidth + (fontSize / 2) + textWidth;
				var x = cursor.x;
				var y = cursor.y;

				// Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
				// instead of me.right and me.bottom because me.width and me.height
				// may have been changed since me.minSize was calculated
				if (isHorizontal) {
					if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
						y = cursor.y += itemHeight;
						cursor.line++;
						x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2) + labelOpts.padding;
					}
				} else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
					x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
					y = cursor.y = me.top + labelOpts.padding;
					cursor.line++;
				}

				drawLegendBox(x, y, legendItem);

				hitboxes[i].left = x;
				hitboxes[i].top = y;

				// Fill the actual label
				fillText(x, y, legendItem, textWidth);

				if (isHorizontal) {
					cursor.x += width + labelOpts.padding;
				} else {
					cursor.y += itemHeight;
				}

			});
		}
	}
function() {
		var me = this;
		var opts = me.options;
		var labelOpts = opts.labels;
		var globalDefaults = core_defaults.global;
		var defaultColor = globalDefaults.defaultColor;
		var lineDefault = globalDefaults.elements.line;
		var legendWidth = me.width;
		var lineWidths = me.lineWidths;

		if (opts.display) {
			var ctx = me.ctx;
			var fontColor = valueOrDefault$d(labelOpts.fontColor, globalDefaults.defaultFontColor);
			var labelFont = helpers$1.options._parseFont(labelOpts);
			var fontSize = labelFont.size;
			var cursor;

			// Canvas setup
			ctx.textAlign = 'left';
			ctx.textBaseline = 'middle';
			ctx.lineWidth = 0.5;
			ctx.strokeStyle = fontColor; // for strikethrough effect
			ctx.fillStyle = fontColor; // render in correct colour
			ctx.font = labelFont.string;

			var boxWidth = getBoxWidth(labelOpts, fontSize);
			var hitboxes = me.legendHitBoxes;

			// current position
			var drawLegendBox = function(x, y, legendItem) {
				if (isNaN(boxWidth) || boxWidth <= 0) {
					return;
				}

				// Set the ctx for the box
				ctx.save();

				var lineWidth = valueOrDefault$d(legendItem.lineWidth, lineDefault.borderWidth);
				ctx.fillStyle = valueOrDefault$d(legendItem.fillStyle, defaultColor);
				ctx.lineCap = valueOrDefault$d(legendItem.lineCap, lineDefault.borderCapStyle);
				ctx.lineDashOffset = valueOrDefault$d(legendItem.lineDashOffset, lineDefault.borderDashOffset);
				ctx.lineJoin = valueOrDefault$d(legendItem.lineJoin, lineDefault.borderJoinStyle);
				ctx.lineWidth = lineWidth;
				ctx.strokeStyle = valueOrDefault$d(legendItem.strokeStyle, defaultColor);

				if (ctx.setLineDash) {
					// IE 9 and 10 do not support line dash
					ctx.setLineDash(valueOrDefault$d(legendItem.lineDash, lineDefault.borderDash));
				}

				if (opts.labels && opts.labels.usePointStyle) {
					// Recalculate x and y for drawPoint() because its expecting
					// x and y to be center of figure (instead of top left)
					var radius = boxWidth * Math.SQRT2 / 2;
					var centerX = x + boxWidth / 2;
					var centerY = y + fontSize / 2;

					// Draw pointStyle as legend symbol
					helpers$1.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
				} else {
					// Draw box as legend symbol
					if (lineWidth !== 0) {
						ctx.strokeRect(x, y, boxWidth, fontSize);
					}
					ctx.fillRect(x, y, boxWidth, fontSize);
				}

				ctx.restore();
			};
			var fillText = function(x, y, legendItem, textWidth) {
				var halfFontSize = fontSize / 2;
				var xLeft = boxWidth + halfFontSize + x;
				var yMiddle = y + halfFontSize;

				ctx.fillText(legendItem.text, xLeft, yMiddle);

				if (legendItem.hidden) {
					// Strikethrough the text if hidden
					ctx.beginPath();
					ctx.lineWidth = 2;
					ctx.moveTo(xLeft, yMiddle);
					ctx.lineTo(xLeft + textWidth, yMiddle);
					ctx.stroke();
				}
			};

			// Horizontal
			var isHorizontal = me.isHorizontal();
			if (isHorizontal) {
				cursor = {
					x: me.left + ((legendWidth - lineWidths[0]) / 2) + labelOpts.padding,
					y: me.top + labelOpts.padding,
					line: 0
				};
			} else {
				cursor = {
					x: me.left + labelOpts.padding,
					y: me.top + labelOpts.padding,
					line: 0
				};
			}

			var itemHeight = fontSize + labelOpts.padding;
			helpers$1.each(me.legendItems, function(legendItem, i) {
				var textWidth = ctx.measureText(legendItem.text).width;
				var width = boxWidth + (fontSize / 2) + textWidth;
				var x = cursor.x;
				var y = cursor.y;

				// Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
				// instead of me.right and me.bottom because me.width and me.height
				// may have been changed since me.minSize was calculated
				if (isHorizontal) {
					if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
						y = cursor.y += itemHeight;
						cursor.line++;
						x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2) + labelOpts.padding;
					}
				} else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
					x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
					y = cursor.y = me.top + labelOpts.padding;
					cursor.line++;
				}

				drawLegendBox(x, y, legendItem);

				hitboxes[i].left = x;
				hitboxes[i].top = y;

				// Fill the actual label
				fillText(x, y, legendItem, textWidth);

				if (isHorizontal) {
					cursor.x += width + labelOpts.padding;
				} else {
					cursor.y += itemHeight;
				}

			});
		}
	}
function ( ) { var me = this ; var opts = me . options ; var labelOpts = opts . labels ; var globalDefaults = core_defaults . global ; var defaultColor = globalDefaults . defaultColor ; var lineDefault = globalDefaults . elements . line ; var legendWidth = me . width ; var lineWidths = me . lineWidths ; if ( opts . display ) { var ctx = me . ctx ; var fontColor = valueOrDefault$d ( labelOpts . fontColor , globalDefaults . defaultFontColor ) ; var labelFont = helpers$1 . options . _parseFont ( labelOpts ) ; var fontSize = labelFont . size ; var cursor ; // Canvas setup ctx . textAlign = 'left' ; ctx . textBaseline = 'middle' ; ctx . lineWidth = 0.5 ; ctx . strokeStyle = fontColor ; // for strikethrough effect ctx . fillStyle = fontColor ; // render in correct colour ctx . font = labelFont . string ; var boxWidth = getBoxWidth ( labelOpts , fontSize ) ; var hitboxes = me . legendHitBoxes ; // current position var drawLegendBox = function ( x , y , legendItem ) { if ( isNaN ( boxWidth ) || boxWidth <= 0 ) { return ; } // Set the ctx for the box ctx . save ( ) ; var lineWidth = valueOrDefault$d ( legendItem . lineWidth , lineDefault . borderWidth ) ; ctx . fillStyle = valueOrDefault$d ( legendItem . fillStyle , defaultColor ) ; ctx . lineCap = valueOrDefault$d ( legendItem . lineCap , lineDefault . borderCapStyle ) ; ctx . lineDashOffset = valueOrDefault$d ( legendItem . lineDashOffset , lineDefault . borderDashOffset ) ; ctx . lineJoin = valueOrDefault$d ( legendItem . lineJoin , lineDefault . borderJoinStyle ) ; ctx . lineWidth = lineWidth ; ctx . strokeStyle = valueOrDefault$d ( legendItem . strokeStyle , defaultColor ) ; if ( ctx . setLineDash ) { // IE 9 and 10 do not support line dash ctx . setLineDash ( valueOrDefault$d ( legendItem . lineDash , lineDefault . borderDash ) ) ; } if ( opts . labels && opts . labels . usePointStyle ) { // Recalculate x and y for drawPoint() because its expecting // x and y to be center of figure (instead of top left) var radius = boxWidth * Math . SQRT2 / 2 ; var centerX = x + boxWidth / 2 ; var centerY = y + fontSize / 2 ; // Draw pointStyle as legend symbol helpers$1 . canvas . drawPoint ( ctx , legendItem . pointStyle , radius , centerX , centerY ) ; } else { // Draw box as legend symbol if ( lineWidth !== 0 ) { ctx . strokeRect ( x , y , boxWidth , fontSize ) ; } ctx . fillRect ( x , y , boxWidth , fontSize ) ; } ctx . restore ( ) ; } ; var fillText = function ( x , y , legendItem , textWidth ) { var halfFontSize = fontSize / 2 ; var xLeft = boxWidth + halfFontSize + x ; var yMiddle = y + halfFontSize ; ctx . fillText ( legendItem . text , xLeft , yMiddle ) ; if ( legendItem . hidden ) { // Strikethrough the text if hidden ctx . beginPath ( ) ; ctx . lineWidth = 2 ; ctx . moveTo ( xLeft , yMiddle ) ; ctx . lineTo ( xLeft + textWidth , yMiddle ) ; ctx . stroke ( ) ; } } ; // Horizontal var isHorizontal = me . isHorizontal ( ) ; if ( isHorizontal ) { cursor = { x : me . left + ( ( legendWidth - lineWidths [ 0 ] ) / 2 ) + labelOpts . padding , y : me . top + labelOpts . padding , line : 0 } ; } else { cursor = { x : me . left + labelOpts . padding , y : me . top + labelOpts . padding , line : 0 } ; } var itemHeight = fontSize + labelOpts . padding ; helpers$1 . each ( me . legendItems , function ( legendItem , i ) { var textWidth = ctx . measureText ( legendItem . text ) . width ; var width = boxWidth + ( fontSize / 2 ) + textWidth ; var x = cursor . x ; var y = cursor . y ; // Use (me.left + me.minSize.width) and (me.top + me.minSize.height) // instead of me.right and me.bottom because me.width and me.height // may have been changed since me.minSize was calculated if ( isHorizontal ) { if ( i > 0 && x + width + labelOpts . padding > me . left + me . minSize . width ) { y = cursor . y += itemHeight ; cursor . line ++ ; x = cursor . x = me . left + ( ( legendWidth - lineWidths [ cursor . line ] ) / 2 ) + labelOpts . padding ; } } else if ( i > 0 && y + itemHeight > me . top + me . minSize . height ) { x = cursor . x = x + me . columnWidths [ cursor . line ] + labelOpts . padding ; y = cursor . y = me . top + labelOpts . padding ; cursor . line ++ ; } drawLegendBox ( x , y , legendItem ) ; hitboxes [ i ] . left = x ; hitboxes [ i ] . top = y ; // Fill the actual label fillText ( x , y , legendItem , textWidth ) ; if ( isHorizontal ) { cursor . x += width + labelOpts . padding ; } else { cursor . y += itemHeight ; } } ) ; } }
Actually draw the legend on the canvas
Actually draw the legend on the canvas
draw the legend box