Highcharts test tool

by salitrapraveen

HTML

<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 300px"></div>

JavaScript

/**
 * Experimental Draggable points plugin
 * Revised 2012-02-08
 *
 * On Saving this jsbin, remember to update http://jsfiddle.net/highcharts/AyUbx/
 */
(function(Highcharts) {
    var addEvent = Highcharts.addEvent,
        each = Highcharts.each;
    
    /**
     * Filter by dragMin and dragMax
     */
    function filterRange(newY, series) {
        var options = series.options,
            dragMin = options.dragMin,
            dragMax = options.dragMax;
        
        if (newY < dragMin) {
            newY = dragMin;
        } else if (newY > dragMax) {
            newY = dragMax;
        }
        return newY;
    }
    
    Highcharts.Chart.prototype.callbacks.push(function (chart) {        
        
        var container = chart.container,
            dragPoint,
            dragY,
            dragPlotY;
        
        chart.redraw(); // kill animation (why was this again?)
        
        addEvent(container, 'mousedown', function(e) {
            var hoverPoint = chart.hoverPoint;
            if (hoverPoint && hoverPoint.series.options.draggable) {
                dragPoint = hoverPoint;
                dragY = e.pageY;
                dragPlotY = dragPoint.plotY + (chart.plotHeight - (dragPoint.yBottom || chart.plotHeight));
            }
        });
        
        addEvent(container, 'mousemove', function(e) {
            if (dragPoint) {
                var deltaY = dragY - e.pageY,
                    newPlotY = chart.plotHeight - dragPlotY + deltaY,
                    newY = dragPoint.series.yAxis.translate(newPlotY, true),
                    series = dragPoint.series;
                
                newY = filterRange(newY, series);
                dragPoint.update(newY, false);
                chart.tooltip.refresh(dragPoint);
                if (series.stackKey) {
                    chart.redraw();
                } else {
                    series.redraw();
                }
            }
        });
        
        function...