gluster-web-interface/app/assets/javascripts/js/flot/jquery.flot.tooltip.min.js

12 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-08-19 15:22:36 +00:00
/*
* jquery.flot.tooltip
*
* description: easy-to-use tooltips for Flot charts
* version: 0.6
* author: Krzysztof Urbas @krzysu [myviews.pl]
* website: https://github.com/krzysu/flot.tooltip
*
* build on 2013-01-07
* released under MIT License, 2012
*/
(function(a){var b={tooltip:!1,tooltipOpts:{content:"%s | X: %x | Y: %y",xDateFormat:null,yDateFormat:null,shifts:{x:10,y:20},defaultTheme:!0,onHover:function(a,b){}}},c=function(a){this.tipPosition={x:0,y:0},this.init(a)};c.prototype.init=function(b){var c=this;b.hooks.bindEvents.push(function(b,d){c.plotOptions=b.getOptions();if(c.plotOptions.tooltip===!1||typeof c.plotOptions.tooltip=="undefined")return;c.tooltipOptions=c.plotOptions.tooltipOpts;var e=c.getDomElement();a(b.getPlaceholder()).bind("plothover",function(a,b,d){if(d){var f;f=c.stringFormat(c.tooltipOptions.content,d),e.html(f).css({left:c.tipPosition.x+c.tooltipOptions.shifts.x,top:c.tipPosition.y+c.tooltipOptions.shifts.y}).show(),typeof c.tooltipOptions.onHover=="function"&&c.tooltipOptions.onHover(d,e)}else e.hide().html("")}),d.mousemove(function(a){var b={};b.x=a.pageX,b.y=a.pageY,c.updateTooltipPosition(b)})})},c.prototype.getDomElement=function(){var b;return a("#flotTip").length>0?b=a("#flotTip"):(b=a("<div />").attr("id","flotTip"),b.appendTo("body").hide().css({position:"absolute"}),this.tooltipOptions.defaultTheme&&b.css({background:"#fff","z-index":"100",padding:"0.4em 0.6em","border-radius":"0.5em","font-size":"0.8em",border:"1px solid #111"})),b},c.prototype.updateTooltipPosition=function(a){this.tipPosition.x=a.x,this.tipPosition.y=a.y},c.prototype.stringFormat=function(a,b){var c=/%p\.{0,1}(\d{0,})/,d=/%s/,e=/%x\.{0,1}(\d{0,})/,f=/%y\.{0,1}(\d{0,})/;return typeof a=="function"&&(a=a(b.series.data[b.dataIndex][0],b.series.data[b.dataIndex][1])),typeof b.series.percent!="undefined"&&(a=this.adjustValPrecision(c,a,b.series.percent)),typeof b.series.label!="undefined"&&(a=a.replace(d,b.series.label)),this.isTimeMode("xaxis",b)&&this.isXDateFormat(b)&&(a=a.replace(e,this.timestampToDate(b.series.data[b.dataIndex][0],this.tooltipOptions.xDateFormat))),this.isTimeMode("yaxis",b)&&this.isYDateFormat(b)&&(a=a.replace(f,this.timestampToDate(b.series.data[b.dataIndex][1],this.tooltipOptions.yDateFormat))),typeof b.series.data[b.dataIndex][0]=="number"&&(a=this.adjustValPrecision(e,a,b.series.data[b.dataIndex][0])),typeof b.series.data[b.dataIndex][1]=="number"&&(a=this.adjustValPrecision(f,a,b.series.data[b.dataIndex][1])),typeof b.series.xaxis.tickFormatter!="undefined"&&(a=a.replace(e,b.series.xaxis.tickFormatter(b.series.data[b.dataIndex][0],b.series.xaxis))),typeof b.series.yaxis.tickFormatter!="undefined"&&(a=a.replace(f,b.series.yaxis.tickFormatter(b.series.data[b.dataIndex][1],b.series.yaxis))),a},c.prototype.isTimeMode=function(a,b){return typeof b.series[a].options.mode!="undefined"&&b.series[a].options.mode==="time"},c.prototype.isXDateFormat=function(a){return typeof this.tooltipOptions.xDateFormat!="undefined"&&this.tooltipOptions.xDateFormat!==null},c.prototype.isYDateFormat=function(a){return typeof this.tooltipOptions.yDateFormat!="undefined"&&this.tooltipOptions.yDateFormat!==null},c.prototype.timestampToDate=function(b,c){var d=new Date(b);return a.plot.formatDate(d,c)},c.prototype.adjustValPrecision=function(a,b,c){var d;return b.match(a)!==null&&RegExp.$1!==""&&(d=RegExp.$1,c=c.toFixed(d),b=b.replace(a,c)),b};var d=[],e=function(a){d.push(new c(a))};a.plot.plugins.push({init:e,options:b,name:"tooltip",version:"0.6"})})(jQuery);