Jugal | Position tooltip to right | Highchart & Highstock

http://stackoverflow.com/questions/11966286/highcharts-tooltip-always-on-right-side-of-cursor/11975793#11975793 Jugal Thakkar http://jugal.me/

by Jugal Thakkar

HTML

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="http://code.jugal.me/js/jugalsLib.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/highstock.src.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/modules/exporting.src.js" ></script>

<div id="container"></div>

CSS

#container{
    min-width:500px;
}

JavaScript

var chartingOptions = {
    tooltip: {
        positioner: function(boxWidth, boxHeight, point) {
            return {
                x: point.plotX + 20,
                y: point.plotY
            };
        }
/*      positioner: function(boxWidth, boxHeight, point) {
            // Set up the variables
            var chart = this.chart,
                plotLeft = chart.plotLeft,
                plotTop = chart.plotTop,
                plotWidth = chart.plotWidth,
                plotHeight = chart.plotHeight,
                distance = 5,
                pointX = point.plotX,
                pointY = point.plotY,
                x = pointX + plotLeft + (chart.inverted ? distance : -boxWidth - distance),
                y = pointY - boxHeight + plotTop + 15,
                // 15 means the point is 15 pixels up from the bottom of the tooltip
                alignedRight;
            // It is too far to the left, adjust it
            if (x < 7) {
                x = plotLeft + pointX + distance;
            }
            // Test to see if the tooltip is too far to the right,
            // if it is, move it back to be inside and then up to not cover the point.
            if ((x + boxWidth) > (plotLeft + plotWidth)) {
                x -= (x + boxWidth) - (plotLeft + plotWidth);
                y = pointY - boxHeight + plotTop - distance;
                alignedRight = true;
            }
            // If it is now above the plot area, align it to the top of the plot area
            if (y < plotTop + 5) {
                y = plotTop + 5;
                // If the tooltip is still covering the point, move it below instead
                if (alignedRight && pointY >= y && pointY <= (y + boxHeight)) {
                    y = pointY + plotTop + distance; // below
                }
            }
            // Now if the tooltip is below the chart, move it up. It's better to cover the
            // point than to disappear outside the chart. #834.
            if...