function determineAlignment(tooltip, size) {
	var model = tooltip._model;
	var chart = tooltip._chart;
	var chartArea = tooltip._chart.chartArea;
	var xAlign = 'center';
	var yAlign = 'center';

	if (model.y < size.height) {
		yAlign = 'top';
	} else if (model.y > (chart.height - size.height)) {
		yAlign = 'bottom';
	}

	var lf, rf; // functions to determine left, right alignment
	var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
	var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
	var midX = (chartArea.left + chartArea.right) / 2;
	var midY = (chartArea.top + chartArea.bottom) / 2;

	if (yAlign === 'center') {
		lf = function(x) {
			return x <= midX;
		};
		rf = function(x) {
			return x > midX;
		};
	} else {
		lf = function(x) {
			return x <= (size.width / 2);
		};
		rf = function(x) {
			return x >= (chart.width - (size.width / 2));
		};
	}

	olf = function(x) {
		return x + size.width + model.caretSize + model.caretPadding > chart.width;
	};
	orf = function(x) {
		return x - size.width - model.caretSize - model.caretPadding < 0;
	};
	yf = function(y) {
		return y <= midY ? 'top' : 'bottom';
	};

	if (lf(model.x)) {
		xAlign = 'left';

		// Is tooltip too wide and goes over the right side of the chart.?
		if (olf(model.x)) {
			xAlign = 'center';
			yAlign = yf(model.y);
		}
	} else if (rf(model.x)) {
		xAlign = 'right';

		// Is tooltip too wide and goes outside left edge of canvas?
		if (orf(model.x)) {
			xAlign = 'center';
			yAlign = yf(model.y);
		}
	}

	var opts = tooltip._options;
	return {
		xAlign: opts.xAlign ? opts.xAlign : xAlign,
		yAlign: opts.yAlign ? opts.yAlign : yAlign
	};
}
function determineAlignment(tooltip, size) {
	var model = tooltip._model;
	var chart = tooltip._chart;
	var chartArea = tooltip._chart.chartArea;
	var xAlign = 'center';
	var yAlign = 'center';

	if (model.y < size.height) {
		yAlign = 'top';
	} else if (model.y > (chart.height - size.height)) {
		yAlign = 'bottom';
	}

	var lf, rf; // functions to determine left, right alignment
	var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
	var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
	var midX = (chartArea.left + chartArea.right) / 2;
	var midY = (chartArea.top + chartArea.bottom) / 2;

	if (yAlign === 'center') {
		lf = function(x) {
			return x <= midX;
		};
		rf = function(x) {
			return x > midX;
		};
	} else {
		lf = function(x) {
			return x <= (size.width / 2);
		};
		rf = function(x) {
			return x >= (chart.width - (size.width / 2));
		};
	}

	olf = function(x) {
		return x + size.width + model.caretSize + model.caretPadding > chart.width;
	};
	orf = function(x) {
		return x - size.width - model.caretSize - model.caretPadding < 0;
	};
	yf = function(y) {
		return y <= midY ? 'top' : 'bottom';
	};

	if (lf(model.x)) {
		xAlign = 'left';

		// Is tooltip too wide and goes over the right side of the chart.?
		if (olf(model.x)) {
			xAlign = 'center';
			yAlign = yf(model.y);
		}
	} else if (rf(model.x)) {
		xAlign = 'right';

		// Is tooltip too wide and goes outside left edge of canvas?
		if (orf(model.x)) {
			xAlign = 'center';
			yAlign = yf(model.y);
		}
	}

	var opts = tooltip._options;
	return {
		xAlign: opts.xAlign ? opts.xAlign : xAlign,
		yAlign: opts.yAlign ? opts.yAlign : yAlign
	};
}
function determineAlignment ( tooltip , size ) { var model = tooltip . _model ; var chart = tooltip . _chart ; var chartArea = tooltip . _chart . chartArea ; var xAlign = 'center' ; var yAlign = 'center' ; if ( model . y < size . height ) { yAlign = 'top' ; } else if ( model . y > ( chart . height - size . height ) ) { yAlign = 'bottom' ; } var lf , rf ; // functions to determine left, right alignment var olf , orf ; // functions to determine if left/right alignment causes tooltip to go outside chart var yf ; // function to get the y alignment if the tooltip goes outside of the left or right edges var midX = ( chartArea . left + chartArea . right ) / 2 ; var midY = ( chartArea . top + chartArea . bottom ) / 2 ; if ( yAlign === 'center' ) { lf = function ( x ) { return x <= midX ; } ; rf = function ( x ) { return x > midX ; } ; } else { lf = function ( x ) { return x <= ( size . width / 2 ) ; } ; rf = function ( x ) { return x >= ( chart . width - ( size . width / 2 ) ) ; } ; } olf = function ( x ) { return x + size . width + model . caretSize + model . caretPadding > chart . width ; } ; orf = function ( x ) { return x - size . width - model . caretSize - model . caretPadding < 0 ; } ; yf = function ( y ) { return y <= midY ? 'top' : 'bottom' ; } ; if ( lf ( model . x ) ) { xAlign = 'left' ; // Is tooltip too wide and goes over the right side of the chart.? if ( olf ( model . x ) ) { xAlign = 'center' ; yAlign = yf ( model . y ) ; } } else if ( rf ( model . x ) ) { xAlign = 'right' ; // Is tooltip too wide and goes outside left edge of canvas? if ( orf ( model . x ) ) { xAlign = 'center' ; yAlign = yf ( model . y ) ; } } var opts = tooltip . _options ; return { xAlign : opts . xAlign ? opts . xAlign : xAlign , yAlign : opts . yAlign ? opts . yAlign : yAlign } ; }
Helper to get the alignment of a tooltip given the size
Helper to get the alignment of a tooltip given the size
Determines the alignment of the tooltip.