Вход Регистрация
Файл: protected/extensions/widgets/highcharts/assets/modules/annotations.src.js
Строк: 470
<?php
(function (HighchartsHighchartsAdapter) {

var 
UNDEFINED,
    
ALIGN_FACTOR,
    
ALLOWED_SHAPES,
    
Chart Highcharts.Chart,
    
extend Highcharts.extend,
    
each Highcharts.each;

ALLOWED_SHAPES = ["path""rect""circle"];

ALIGN_FACTOR = {
    
top0,
    
left0,
    
center0.5,
    
middle0.5,
    
bottom1,
    
right1
};


// Highcharts helper methods
var inArray HighchartsAdapter.inArray,
    
merge Highcharts.merge;

function 
defaultOptions(shapeType) {
    var 
shapeOptions,
        
options;

    
options = {
        
xAxis0,
        
yAxis0,
        
title: {
            
style: {},
            
text"",
            
x0,
            
y0
        
},
        
shape: {
            
params: {
                
stroke"#000000",
                
fill"transparent",
                
strokeWidth2
            
}
        }
    };

    
shapeOptions = {
        
circle: {
            
params: {
                
x0,
                
y0
            
}
        }
    };

    if (
shapeOptions[shapeType]) {
        
options.shape merge(options.shapeshapeOptions[shapeType]);
    }

    return 
options;
}

function 
isArray(obj) {
    return 
Object.prototype.toString.call(obj) === '[object Array]';
}

function 
isNumber(n) {
    return 
typeof n === 'number';
}

function 
defined(obj) {
    return 
obj !== UNDEFINED && obj !== null;
}

function 
translatePath(dxAxisyAxisxOffsetyOffset) {
    var 
len d.length,
        
0;

    while (
len) {
        if (
typeof d[i] === 'number' && typeof d[1] === 'number') {
            
d[i] = xAxis.toPixels(d[i]) - xOffset;
            
d[1] = yAxis.toPixels(d[1]) - yOffset;
            
+= 2;
        } else {
            
+= 1;
        }
    }

    return 
d;
}


// Define annotation prototype
var Annotation = function () {
    
this.init.apply(thisarguments);
};
Annotation.prototype = {
    
/* 
     * Initialize the annotation
     */
    
init: function (chartoptions) {
        var 
shapeType options.shape && options.shape.type;

        
this.chart chart;
        
this.options merge({}, defaultOptions(shapeType), options);
    },

    
/*
     * Render the annotation
     */
    
render: function (redraw) {
        var 
annotation this,
            
chart this.chart,
            
renderer annotation.chart.renderer,
            
group annotation.group,
            
title annotation.title,
            
shape annotation.shape,
            
options annotation.options,
            
titleOptions options.title,
            
shapeOptions options.shape;

        if (!
group) {
            
group annotation.group renderer.g();
        }


        if (!
shape && shapeOptions && inArray(shapeOptions.typeALLOWED_SHAPES) !== -1) {
            
shape annotation.shape renderer[options.shape.type](shapeOptions.params);
            
shape.add(group);
        }

        if (!
title && titleOptions) {
            
title annotation.title renderer.label(titleOptions);
            
title.add(group);
        }

        
group.add(chart.annotations.group);

        
// link annotations to point or series
        
annotation.linkObjects();

        if (
redraw !== false) {
            
annotation.redraw();
        }
    },

    
/*
     * Redraw the annotation title or shape after options update
     */
    
redraw: function () {
        var 
options this.options,
            
chart this.chart,
            
group this.group,
            
title this.title,
            
shape this.shape,
            
linkedTo this.linkedObject,
            
xAxis chart.xAxis[options.xAxis],
            
yAxis chart.yAxis[options.yAxis],
            
width options.width,
            
height options.height,
            
anchorY ALIGN_FACTOR[options.anchorY],
            
anchorX ALIGN_FACTOR[options.anchorX],
            
resetBBox false,
            
shapeParams,
            
linkType,
            
series,
            
param,
            
bbox,
            
x,
            
y;

        if (
linkedTo) {
            
linkType = (linkedTo instanceof Highcharts.Point) ? 'point' :
                        (
linkedTo instanceof Highcharts.Series) ? 'series' null;

            if (
linkType === 'point') {
                
options.xValue linkedTo.x;
                
options.yValue linkedTo.y;
                
series linkedTo.series;
            } else if (
linkType === 'series') {
                
series linkedTo;
            }

            if (
group.visibility !== series.group.visibility) {
                
group.attr({
                    
visibilityseries.group.visibility
                
});
            }
        }


        
// Based on given options find annotation pixel position
        
= (defined(options.xValue) ? xAxis.toPixels(options.xValue xAxis.minPointOffset) - xAxis.minPixelPadding options.x);
        
defined(options.yValue) ? yAxis.toPixels(options.yValue) : options.y;

        if (
isNaN(x) || isNaN(y) || !isNumber(x) || !isNumber(y)) {
            return;
        }


        if (
title) {
            
title.attr(options.title);
            
title.css(options.title.style);
            
resetBBox true;
        }

        if (
shape) {
            
shapeParams extend({}, options.shape.params);

            if (
options.units === 'values') {
                for (
param in shapeParams) {
                    if (
inArray(param, ['width''x']) > -1) {
                        
shapeParams[param] = xAxis.translate(shapeParams[param]);
                    } else if (
inArray(param, ['height''y']) > -1) {
                        
shapeParams[param] = yAxis.translate(shapeParams[param]);
                    }
                }

                if (
shapeParams.width) {
                    
shapeParams.width -= xAxis.toPixels(0) - xAxis.left;
                }

                if (
shapeParams.x) {
                    
shapeParams.+= xAxis.minPixelPadding;
                }

                if (
options.shape.type === 'path') {
                    
translatePath(shapeParams.dxAxisyAxisxy);
                }
            }

            
// move the center of the circle to shape x/y
            
if (options.shape.type === 'circle') {
                
shapeParams.+= shapeParams.r;
                
shapeParams.+= shapeParams.r;
            }

            
resetBBox true;
            
shape.attr(shapeParams);
        }

        
group.bBox null;

        
// If annotation width or height is not defined in options use bounding box size
        
if (!isNumber(width)) {
            
bbox group.getBBox();
            
width bbox.width;
        }

        if (!
isNumber(height)) {
            
// get bbox only if it wasn't set before
            
if (!bbox) {
                
bbox group.getBBox();
            }

            
height bbox.height;
        }

        
// Calculate anchor point
        
if (!isNumber(anchorX)) {
            
anchorX ALIGN_FACTOR.center;
        }

        if (!
isNumber(anchorY)) {
            
anchorY ALIGN_FACTOR.center;
        }

        
// Translate group according to its dimension and anchor point
        
width anchorX;
        
height anchorY;

        if (
chart.animation && defined(group.translateX) && defined(group.translateY)) {
            
group.animate({
                
translateXx,
                
translateYy
            
});
        } else {
            
group.translate(xy);
        }
    },

    
/*
     * Destroy the annotation
     */
    
destroy: function () {
        var 
annotation this,
            
chart this.chart,
            
allItems chart.annotations.allItems,
            
index allItems.indexOf(annotation);

        if (
index > -1) {
            
allItems.splice(index1);
        }

        
each(['title''shape''group'], function (element) {
            if (
annotation[element]) {
                
annotation[element].destroy();
                
annotation[element] = null;
            }
        });

        
annotation.group annotation.title annotation.shape annotation.chart annotation.options null;
    },

    
/*
     * Update the annotation with a given options
     */
    
update: function (optionsredraw) {
        
extend(this.optionsoptions);

        
// update link to point or series
        
this.linkObjects();

        
this.render(redraw);
    },

    
linkObjects: function () {
        var 
annotation this,
            
chart annotation.chart,
            
linkedTo annotation.linkedObject,
            
linkedId linkedTo && (linkedTo.id || linkedTo.options.id),
            
options annotation.options,
            
id options.linkedTo;

        if (!
defined(id)) {
            
annotation.linkedObject null;
        } else if (!
defined(linkedTo) || id !== linkedId) {
            
annotation.linkedObject chart.get(id);
        }
    }
};


// Add annotations methods to chart prototype
extend(Chart.prototype, {
    
annotations: {
        
/*
         * Unified method for adding annotations to the chart
         */
        
add: function (optionsredraw) {
            var 
annotations this.allItems,
                
chart this.chart,
                
item,
                
len;

            if (!
isArray(options)) {
                
options = [options];
            }

            
len options.length;

            while (
len--) {
                
item = new Annotation(chartoptions[len]);
                
annotations.push(item);
                
item.render(redraw);
            }
        },

        
/**
         * Redraw all annotations, method used in chart events
         */
        
redraw: function () {
            
each(this.allItems, function (annotation) {
                
annotation.redraw();
            });
        }
    }
});


// Initialize on chart load
Chart.prototype.callbacks.push(function (chart) {
    var 
options chart.options.annotations,
        
group;

    
group chart.renderer.g("annotations");
    
group.attr({
        
zIndex7
    
});
    
group.add();

    
// initialize empty array for annotations
    
chart.annotations.allItems = [];

    
// link chart object to annotations
    
chart.annotations.chart chart;

    
// link annotations group element to the chart
    
chart.annotations.group group;

    if (
isArray(options) && options.length 0) {
        
chart.annotations.add(chart.options.annotations);
    }

    
// update annotations after chart redraw
    
Highcharts.addEvent(chart'redraw', function () {
        
chart.annotations.redraw();
    });
});
}(
HighchartsHighchartsAdapter));
?>
Онлайн: 1
Реклама