{"size": 4393, "ext": "js", "max_stars_repo_path": "jsrf/src/js/utils/tooltip.js", "max_stars_repo_name": "victoriazakharo/framework", "max_stars_repo_stars_event_min_datetime": "2015-01-06T18:30:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-11T09:36:13.000Z", "max_issues_repo_path": "jsrf/src/js/utils/tooltip.js", "max_issues_repo_name": "victoriazakharo/framework", "max_issues_repo_issues_event_min_datetime": "2015-01-19T07:20:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-15T19:39:55.000Z", "max_forks_repo_path": "jsrf/src/js/utils/tooltip.js", "max_forks_repo_name": "victoriazakharo/framework", "max_forks_repo_forks_event_min_datetime": "2015-02-15T06:07:50.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-06T19:39:11.000Z"}
{"max_stars_count": 145, "max_issues_count": 25, "max_forks_count": 55, "avg_line_length": 34.3203125, "max_line_length": 142, "alphanum_fraction": 0.4140678352}
define(['generated/templates'], function(JST) {
    var MIN_WIDTH = 100;
    var Tooltip = function() {
        var self = this,
            options = null,
            $core = null,
            $tooltip = null;

        self.config = function(_options) {
            options = _options;
            $core = options.core || $('body');
        };

        self.renderTo = function($core) {
            options.popupType = options.popupType || 'top';
            $tooltip = $(JST.tooltip(options));
            $core.append($tooltip);
            $tooltip.hide();
        };


        self.show = function(x, y, data) {
            x = x + (options.type === 'popup' ? window.pageXOffset : 0);
            y = y + (options.type === 'popup' ? window.pageYOffset : 0);

            var mainLabel = $tooltip.find('.rfTooltipMainLabel'),
                label = $tooltip.find('.rfTooltipLabel'),
                value = $tooltip.find('.rfTooltipValue'),
                row = $tooltip.find('.rfTooltipValueRow'),
                arrow = $tooltip.find(options.popupType === 'top' ? '.downArrow' : '.leftArrow'),
                arrowBorder = $tooltip.find(options.popupType === 'top' ? '.downArrowBorder' : '.leftArrowBorder');

            if(options.type === 'popup') {
                mainLabel.text(data.label);    
            } else {
                mainLabel.hide();
                row.removeClass('rfTooltipValueRow');
                arrow.hide();
                arrowBorder.hide();
                row.css({
                    padding: '8px 0'
                });
            }
            
            label.text(data.seriesLabels[0]);
            value.text(data.data[0]);
            removeAllChartColorClasses(label);
            if(data.color === 'auto') {
                label.css({
                    color: 'none'
                });
                label.addClass('chart-color-' + data.seriesIndex[0]);    
            } else {
                label.css({
                    color: data.color
                });
            }
            
            label.css({
                background: 'none'
            });
            $tooltip.show();
            var mainLabelWidth = mainLabel.width(),
                labelWidth = label.width(),
                valueWidth = value.width(),
                maxWidth = mainLabelWidth > (labelWidth + valueWidth) ? mainLabelWidth : labelWidth + valueWidth,
                tooltipWidth = (maxWidth > MIN_WIDTH ? maxWidth : MIN_WIDTH) + 10,
                tooltipHeight = ( options.type === 'popup' ? mainLabel.height() : 0 ) + label.height() + (options.type === 'popup' ? 22 : 14);

            $tooltip.css({
                width: tooltipWidth,
                height: tooltipHeight
            });
            var left, top; 
            if(options.popupType === 'left') {
                left = x + 8,
                top = y - tooltipHeight / 2;
            } else if(options.popupType === 'top') {
                left = x - tooltipWidth / 2,
                top = y - tooltipHeight - 10;
            }
            
            $tooltip.css({
                left: left,
                top: top 
            });
            if(options.type === 'popup') {
                if(options.popupType === 'left') {
                    arrow.css({
                        left: -8,
                        top: Math.floor(tooltipHeight/ 2 - 8)
                    });
                    arrowBorder.css({
                        left: -8,
                        top: Math.floor(tooltipHeight / 2 - 8)
                    });
                } else {
                    arrow.css({
                        left: Math.floor(tooltipWidth / 2 - 8),
                        top: tooltipHeight
                    });
                    arrowBorder.css({
                        left: Math.floor(tooltipWidth / 2 - 8),
                        top: tooltipHeight
                    });
                }
            }
        };

        self.hide = function() {
            $tooltip.hide();
        };

        self.dispose = function() {
            if($tooltip) {
                $tooltip.remove();    
            }
        };

        var removeAllChartColorClasses = function($node) {
            for(var i=-1; ++i<9;) {
                $node.removeClass('chart-color-' + i);
            }
        };
    };

    return Tooltip;
});