forked from alexyoung/ico
-
Notifications
You must be signed in to change notification settings - Fork 25
/
ico-min.js
8 lines (8 loc) · 23.7 KB
/
ico-min.js
1
2
3
4
5
6
7
8
/* Ico Graph Prototype/Raphael library
*
* Copyright (c) 2009, Alex R. Young
* Copyright (c) 2009-2012 Reverse Risk
* Copyright (c) 2009-2013 Jean Vincent
*
* Licensed under the MIT license: http://github.com/uiteoi/ico/blob/master/MIT-LICENSE
*/"use strict";(function(e){var t=e.Ico={Version:"0.98.26",extend:function(e,t){for(var n in t)e[n]=t[n];return e}},n=!0,r;typeof debug=="function"?r=function(e){debug("Ico, "+e)}:typeof console=="object"&&typeof console.log=="function"?r=function(e){function n(e,t){return e="000"+e,e.substr(e.length-t)}var t=new Date;console.log(n(t.getMinutes(),2)+":"+n(t.getSeconds(),2)+"."+n(t.getMilliseconds(),3)+" - "+"Ico, "+e)}:n=!1,t.extend(t,{isArray:function(e){return typeof e=="object"&&e instanceof Array},Class:{add_methods:t.extend,create:function(e){var n=function(){this.initialize.apply(this,arguments)};n.subclasses=[];var r=-1;typeof e=="function"?(r+=1,(n.superclass=e).subclasses.push(n),n.prototype=Object.create(e.prototype)):n.superclass=null,n.prototype.constructor=n;while(++r<arguments.length)t.Class.add_methods(n.prototype,arguments[r]);return n.prototype.initialize||(n.prototype.initialize=function(){}),n}},get_style:function(e,t){var n="";return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(e,"").getPropertyValue(t):e.currentStyle&&(t=t.replace(/\-(\w)/g,function(e,t){return t.toUpperCase()}),n=e.currentStyle[t]),n},viewport_offset:Element.viewportOffset,significant_digits_round:function(e,t,n,r){if(e==0||e==Number.NEGATIVE_INFINITY||e==Number.POSITIVE_INFINITY)return e;var i=1;e<0&&(e=-e,i=-1);var s=Math.floor(Math.log(e)/Math.LN10);if(s<-14)return 0;s-=t-1,e=(n||Math.round)(i*e/Math.pow(10,s));if(r&&s<0){e*=i;while(e%10==0)s+=1,e/=10;e=""+e;var o=e.length+s;if(o<=0)return(i<0?"-":"")+"0.00000000000000".substring(0,2-o)+e;if(s<0)return(i<0?"-":"")+e.substring(0,o)+"."+e.substring(o);e*=i}return e*Math.pow(10,s)},root:function(e,t){return Math.floor(Math.log(Math.abs(e))/Math.log(t))},svg_path:function(e){var t="",n=!1;return e.forEach(function(e){typeof e=="number"?(n&&(t+=" "),t+=Math.round(e),n=!0):(t+=e,n=!1)}),t},adjust_min_max:function(e,t){n&&r("adjust_min_max(), min: "+e+", max: "+t);var i=t-e;return i===0?(e=0,t===0&&(t=1)):i<e?e-=i/2:e>0?e=0:i<-t?t+=i/2:t<0&&(t=0),[e,t]},series_min_max:function(e,i){n&&r("series_min_max: series length: "+e.length);var s,o=[],u=Array.prototype.concat.apply([],e).map(function(e){return e===s||e===null?null:(o.push(e),e)}),a=o.length;n&&r("series_min_max: no_null_values length: "+a);var f=a?[t.significant_digits_round(Math.min.apply(Math,o),2,Math.floor),t.significant_digits_round(Math.max.apply(Math,o),2,Math.ceil)]:[0,0];return i||(f=t.adjust_min_max.apply(t,f)),f.push(u),f},moving_average:function(e,n,r){var i=[],s=-1,o=-1,u;r&&t.isArray(u=r.previous_values)&&(e=u.concat(e),s+=u.length);for(var a=e.length;++s<a;){var f=0;for(var l=-1;++l<n&&s>=l;)f+=e[s-l];i[++o]=t.significant_digits_round(f/l,3,Math.round,!0)}return i}}),t.Base=t.Class.create({initialize:function(e,t,i){return n&&r("Ico.Base.initialize( "+e+", "+JSON.stringify(t)+", "+JSON.stringify(i)+" )"),typeof e=="string"&&(e=document.getElementById(e)),this.element=e,this.series=t||[[0]],this.set_defaults(),this.set_series(),this.process_options(i),this.set_raphael(i=this.options),this.calculate(i),this.draw(i),n&&r("Ico.Base.initialize(), end"),this},set_series:function(){if(t.isArray(this.series))n&&r("set_series Array, element 0 is Array:"+t.isArray(this.series[0])),t.isArray(this.series[0])||(this.series=[this.series]);else{if(typeof this.series!="number")throw"Wrong type for series";this.series=[[this.series]]}this.data_samples=Math.max.apply(Math,this.series.map(function(e){return n&&r("serie length: "+e.length),e.length})),n&&r("set_series, data samples: "+this.data_samples);var e=t.series_min_max(this.series,!0);this.max=e[1],this.min=e[0],this.all_values=e[2],this.series_shapes=[]},set_defaults:function(){var e=this.options={width:parseInt(this.element.offsetWidth)-1,height:parseInt(this.element.offsetHeight)-1,x_padding_left:0,x_padding_right:0,y_padding_top:0,y_padding_bottom:0,color:t.get_style(this.element,"color"),mouseover_attributes:{stroke:"red"},units:"",units_position:1};n&&r("options: width: "+e.width+", height: "+e.height+", color: "+e.color)},process_options:function(e){n&&r("Ico.Base.process_options()");var i=this;e&&(e=t.extend(i.options,e)),typeof e.min!="undefined"&&(i.min=Math.min(i.min,e.min)),typeof e.max!="undefined"&&(i.max=Math.max(i.max,e.max)),i.range=i.max-i.min,i.x={direction:[1,0],start_offset:0,width:e.width},i.y={direction:[0,-1],start_offset:0,width:e.height},i.x.other=i.y,i.y.other=i.x,i.x.padding=[e.x_padding_left,e.x_padding_right],i.y.padding=[e.y_padding_top,e.y_padding_bottom],i.orientation=e.orientation||i.orientation||0,i.y_direction=i.orientation?-1:1,i.graph=i.orientation?{x:i.y,y:i.x}:{x:i.x,y:i.y},i.components=[];for(var s in t.Component.components){if(!t.Component.components.hasOwnProperty(s))continue;var o=i.options[s+"_attributes"],e=i.options[s],u=t.Component.components[s];e===!0&&o&&(e=i.options[s]=o);if(e){var a=u[1];i.components[a]||(i.components[a]=[]);try{i.components[a].push(i[s]=new u[0](i,e))}catch(f){i.error=f,n&&r("process_options(), exception: "+f)}}}},get_font:function(){var e=this.options;return this.font?this.font:(this.font={"font-family":t.get_style(this.element,"font-family"),"font-size":e.font_size||t.get_style(this.element,"font-size")||10,fill:t.get_style(this.element,"color")||"#666",stroke:"none"},e&&t.extend(this.font,e),this.font)},set_raphael:function(e){if(this.paper)return;this.paper=Raphael(this.element,e.width,e.height),this.svg=!(this.vml=Raphael.vml)},clear:function(){return this.paper&&(this.components_call("clear",this.options),this.paper.remove(),this.paper=null),this},calculate:function(e){n&&r("Ico.Base.calculate()"),this.paper||this.set_raphael(e),this.components_call("calculate",e),this.calculate_graph_len(this.graph.x),this.calculate_graph_len(this.graph.y),this.scale=this.y_direction*this.graph.y.len/this.range,this.graph.x.step=this.graph.x.len/this.label_slots_count(),this.x.start=this.x.padding[0],this.x.stop=this.x.start+this.x.len,this.y.stop=this.y.padding[0],this.y.start=this.y.stop+this.y.len},calculate_graph_len:function(e){e.len=e.width-e.padding[0]-e.padding[1]},calculate_bars:function(e){this.bar_width=this.graph.x.step-e.bar_padding,this.bar_width<5&&(this.bar_width=5),this.graph.x.start_offset=this.y_direction*this.graph.x.step/2,this.bar_base=this.graph.y.start-this.scale*((this.max<=0?this.max:0)-(this.min<0?this.min:0))},format_value:function(e,n){e!=0&&typeof n!="number"&&(n=t.root(e,1e3),n&&(e/=Math.pow(1e3,n)),e=t.significant_digits_round(e,3,Math.round,!0).toString()),e=""+e,n&&(e+=["","k","M","G","T","P","E","Z","Y"][n]||"e"+3*n);var r=this.options;return r.units?r.units_position?e+r.units:r.units+e:e},draw:function(e){return n&&r("Ico.Base.draw()"),this.paper||this.set_raphael(e),this.components_call("draw",e),this.draw_series(e),this},draw_series:function(e){for(var t=-1;++t<this.series.length;)this.series_shapes[t]={shape:this.draw_serie(this.series[t],t,e),visible:!0};this.highlight&&this.draw_highlight()},get_serie:function(e){e=this.series_shapes[e];if(e)return e;throw"Undefined serie"},toggle_serie:function(e){((e=this.get_serie(e)).visible^=1)&&e.shape.show()||e.shape.hide()},show_serie:function(e){(e=this.get_serie(e)).shape.show(),e.visible=!0},hide_serie:function(e){(e=this.get_serie(e)).shape.hide(),e.visible=!1},components_call:function(e,t){for(var i=-1;++i<this.components.length;){var s=this.components[i];if(!s)continue;for(var o=-1;++o<s.length;){var u=s[o];try{u[e]&&u[e](u.options,this)}catch(a){n&&r("Ico::Base::components_call(), exception "+a),this.set_raphael(t),this.errors=(this.errors||0)+1,this.paper.text(0,12*this.errors,"Error in "+e+"(): "+(this.error=a)).attr({"text-anchor":"start","font-size":10,fill:"black",stroke:"none","font-family":"Arial"})}}}},plot:function(e){return(e-this.min)*this.scale},show_label_onmouseover:function(e,t,n,r,i,s){var o=this,u="";if(this.status_bar){if(!s){var a=this.labels,f,l=this.options.series_names;a&&(a=a.options.long_values||a.options.values)&&(f=a[i])&&(u+=f+", "),l&&(s=l[r])}s&&(u+=s+": "),u+=this.format_value(t)}e.node.onmouseout=function(){o.status_bar&&o.status_bar.shape.hide(),e.attr(n)},e.node.onmouseover=function(){o.status_bar&&o.status_bar.shape.attr({text:u}).show(),e.attr(o.options.mouseover_attributes)}}}),t.SparkLine=t.Class.create(t.Base,{process_options:function(e){t.Base.prototype.process_options.call(this,e),this.graph.y.padding[1]+=1;var n=this.options.highlight;n&&(this.highlight={index:this.data_samples-1,color:"red",radius:2},t.extend(this.highlight,n==1?{}:n),this.highlight.index==this.data_samples-1&&(this.graph.x.padding[1]+=this.highlight.radius+1))},label_slots_count:function(){return this.data_samples-1},draw_serie:function(e,n,r){var i=this,s=this.x.start+this.x.start_offset,o;return e.forEach(function(e){o=t.svg_path([o?o+"L":"M",s,i.y.start+i.y.start_offset-i.plot(e)]),s+=i.x.step}),this.paper.path(o).attr({stroke:r.color})},draw_highlight:function(){var e=this.highlight.index,t=this.x,n=this.y;this.paper.circle(Math.round(t.start+t.start_offset+e*t.step),Math.round(n.start+n.start_offset-this.plot(this.series[0][e])),this.highlight.radius).attr({stroke:"none",fill:this.highlight.color})}}),t.SparkBar=t.Class.create(t.SparkLine,{label_slots_count:function(){return this.data_samples},calculate:function(e){t.SparkLine.prototype.calculate.call(this,e),this.calculate_bars(e)},draw_serie:function(e,n,r){var i=this,s=this.x.start+this.x.start_offset,o="";return e.forEach(function(e){o+=t.svg_path(["M",s,i.bar_base,"v",-i.scale*e]),s+=i.x.step}),this.paper.path(o).attr({"stroke-width":this.graph.x.step,stroke:r.color})},draw_highlight:function(){var e=this.highlight.index,n=this.x;this.paper.path(t.svg_path(["M",n.start+n.start_offset+e*n.step,this.bar_base,"v",-this.scale*this.series[0][e]])).attr({"stroke-width":this.graph.x.step,stroke:this.highlight.color})}}),t.BulletGraph=t.Class.create(t.Base,{set_defaults:function(){t.Base.prototype.set_defaults.call(this),this.orientation=1,t.extend(this.options,{min:0,max:100,color:"#33e",graph_background:!0})},process_options:function(e){t.Base.prototype.process_options.call(this,e);var n=this.target={color:"#666",length:.8,"stroke-width":2};typeof e.target=="number"?n.value=e.target:t.extend(n,e.target||{})},label_slots_count:function(){return 1},calculate:function(e){t.Base.prototype.calculate.call(this,e),e.bar_padding||(e.bar_padding=2*this.graph.x.len/3),this.calculate_bars(e)},draw_series:function(e){var n=this.x.start+this.x.start_offset,r=this.y.start+this.y.start_offset,i=this.series[0][0],s,o=this.series_shapes[0]=this.paper.path(t.svg_path(["M",n-this.plot(i),r-this.bar_width/2,"H",this.bar_base,"v",this.bar_width,"H",n-this.plot(i),"z"])).attr(s={fill:e.color,"stroke-width":1,stroke:"none"});this.show_label_onmouseover(o,i,s,0,0);if(typeof this.target.value!="undefined"){var u=this.target,a=1-u.length,r=this.y;this.paper.path(t.svg_path(["M",n-this.plot(u.value),r.len*a/2,"v",r.len*(1-a)])).attr({stroke:u.color,"stroke-width":u["stroke-width"]})}}}),t.BaseGraph=t.Class.create(t.Base,{set_defaults:function(){t.Base.prototype.set_defaults.call(this),t.extend(this.options,{y_padding_top:15,y_padding_bottom:10,x_padding_left:10,x_padding_right:10,colors:[],series_attributes:[],value_labels:{},focus_hint:!0,axis:!0})},process_options:function(e){var n=this,r=t.adjust_min_max(this.min,this.max);this.min=r[0],this.max=r[1],t.Base.prototype.process_options.call(this,e),this.series.forEach(function(e,t){n.options.colors[t]||(n.options.colors[t]=n.options.color||Raphael.hsb2rgb(Math.random(),1,.75).hex)})},draw_serie:function(e,t,i){var s=this.graph.x.start+this.graph.x.start_offset,o=this.graph.y.start+this.graph.y.start_offset+this.scale*this.min,u=this.paper.path(),a="",f=this.paper.set();for(var l=-1;++l<e.length;){var c=e[l];c==null?this.last=null:a+=this.draw_value(l,s,o-this.scale*c,c,t,f,i),s+=this.y_direction*this.graph.x.step}return a!=""&&(n&&r("draw_serie(), path: "+a),u.attr({path:a}).attr(i.series_attributes[t]||{stroke:i.colors[t],"stroke-width":i.stroke_width||3}),f.push(u)),f}}),t.LineGraph=t.Class.create(t.BaseGraph,{set_defaults:function(){t.BaseGraph.prototype.set_defaults.call(this),t.extend(this.options,{curve_amount:5,dot_radius:3,dot_attributes:[],focus_radius:6,focus_attributes:{stroke:"none",fill:"white","fill-opacity":0}})},process_options:function(e){t.BaseGraph.prototype.process_options.call(this,e);var n=this;this.series.forEach(function(e,t){var r=n.options.colors[t];n.options.series_attributes[t]||(n.options.series_attributes[t]={stroke:r,"stroke-width":2}),n.options.dot_attributes[t]||(n.options.dot_attributes[t]={"stroke-width":1,stroke:n.background?n.background.options.color:r,fill:r})})},label_slots_count:function(){return this.data_samples-1},draw_value:function(e,n,r,i,s,o,u){var a=u.dot_radius,f=u.focus_radius,l;this.orientation&&(l=n,n=r,r=l),typeof a=="object"&&(a=a[s]),a&&o.push(this.paper.circle(n,r,a).attr(u.dot_attributes[s])),typeof f=="object"&&(f=f[s]);if(f){var c=u.focus_attributes,h=this.paper.circle(n,r,f).attr(c);o.push(h),this.show_label_onmouseover(h,i,c,s,e)}var p,d=u.curve_amount,v=this.last;if(e===0||!v)p=["M",n,r];else if(d){s=this.series[s];var m=this.scale*d/2/this.graph.x.step,g=s[e-1],y=s[e-2],b=s[e],w=s[e+1],E=[d,(y!==undefined?y-b:(g-b)*2)*m],S=[d,(w!==undefined?g-w:(g-b)*2)*m];this.orientation&&(E=[E[1],-d],S=[S[0],-d]);var x=v[0]+E[0],b=v[1]+E[1],T=n-S[0],w=r-S[1];if(u.debug&&s===this.series[0]){var N={stroke:"black"},C={stroke:"red"};this.paper.circle(x,b,1).attr(N),this.paper.path(t.svg_path(["M",v[0],v[1],"L",x,b])).attr(N),this.paper.circle(T,w,1).attr(C),this.paper.path(t.svg_path(["M",n,r,"L",T,w])).attr(C)}p=["C",x,b,T,w,n,r]}else p=["L",n,r];return this.last=[n,r],t.svg_path(p)}}),t.BarGraph=t.Class.create(t.BaseGraph,{set_defaults:function(){t.BaseGraph.prototype.set_defaults.call(this);var e=this.options;e.bar_padding=5,e.bars_overlap=.5},process_options:function(e){t.BaseGraph.prototype.process_options.call(this,e);var n=this;e=n.options,this.series.forEach(function(t,r){var i=e.series_attributes;i[r]||(i[r]={stroke:"none","stroke-width":2,gradient:""+(n.orientation?270:0)+"-"+e.colors[r]+":20-#555555"})}),e.bars_overlap>1&&(e.bars_overlap=1)},calculate:function(e){t.BaseGraph.prototype.calculate.call(this,e),this.calculate_bars(e),e=this.bars_overlap=e.bars_overlap;var n=this.series.length,r=this.bars_width=this.bar_width/(n-(n-1)*e);this.bars_step=r*(1-e)},label_slots_count:function(){return this.data_samples},draw_value:function(e,n,r,i,s,o,u){var a=u.series_attributes[s],f=this.bars_width,l=this.bar_base,c;return Math.abs(r-l)<2&&(r=l+(r>=l?2:-2)),n+=this.bars_step*s-this.bar_width/2,this.show_label_onmouseover(c=this.paper.path(t.svg_path(this.orientation?["M",r,n,"H",l,"v",f,"H",r,"z"]:["M",n,r,"V",l,"h",f,"V",r,"z"])).attr(a),i,a,s,e),o.push(c),""}}),t.HorizontalBarGraph=t.Class.create(t.BarGraph,{set_defaults:function(){t.BarGraph.prototype.set_defaults.call(this),this.orientation=1}}),t.Component=t.Class.create({initialize:function(e,i){t.extend(this,{p:e,graph:e.graph,x:e.x,y:e.y,orientation:e.orientation});if(t.isArray(i))i={values:i};else if(typeof i=="number"||typeof i=="string")i={value:i};i=this.options=this.defaults?t.extend(this.defaults(e),i):i,n&&r("Ico.Component::initialize(), o: "+JSON.stringify(i)),this.process_options&&this.process_options(i,e)}}),t.Component.components={},t.Component.Background=t.Class.create(t.Component,{defaults:function(){return{corners:!0}},process_options:function(e){e.color&&!e.attributes&&(e.attributes={stroke:"none",fill:e.color}),e.attributes&&(e.color=e.attributes.fill),e.corners===!0&&(e.corners=Math.round(this.p.options.height/20))},draw:function(e,t){var n=t.options;this.shape=t.paper.rect(0,0,n.width,n.height,e.corners).attr(e.attributes)}}),t.Component.components.background=[t.Component.Background,0],t.Component.StatusBar=t.Class.create(t.Component,{defaults:function(){return{attributes:{"text-anchor":"end"}}},draw:function(e,t){var n=t.options,r=this.y;this.shape=t.paper.text(e.x||n.width-10,e.y||(r?r.padding[0]:n.height)/2,"").hide().attr(e.attributes)}}),t.Component.components.status_bar=[t.Component.StatusBar,2],t.Component.MousePointer=t.Class.create(t.Component,{defaults:function(){return{attributes:{stroke:"#666","stroke-dasharray":"--"}}},draw:function(e,n){if(!t.viewport_offset)return;var r=this.shape=n.paper.path().attr(e.attributes).hide(),i=this.x,s=this.y,o=n.element;o.onmousemove=function(e){e=e||window.event;var n=t.viewport_offset(o),u=e.clientX-n[0],a=e.clientY-n[1];u>=i.start&&u<=i.stop&&a>=s.stop&&a<=s.start?r.attr({path:t.svg_path(["M",i.start,a,"h",i.len,"M",u,s.stop,"v",s.len])}).show():r.hide()},o.onmouseout=function(){r.hide()}}}),t.Component.components.mouse_pointer=[t.Component.MousePointer,2],t.Component.GraphBackground=t.Class.create(t.Component,{defaults:function(){return{key_colors:["#aaa","#ccc","#eee"],key_values:[50,75],colors_transition:0}},draw:function(e,t){var n=this.x,r=this.y,i=t.range,s=e.colors_transition/i,o=100/i-s,u=e.key_colors,a=u.length,f=e.key_values,l=f.length,c=this.orientation?"0":"90";a>l+1&&(a=l+1);for(var h,p=0,d=-1;++d<a;p=h){var v=d<l,m=v?h=f[d]-t.min:i,g="-"+u[d]+":";d&&(c+=g+Math.round(p*o+m*s)),v&&(c+=g+Math.round(p*s+m*o))}this.shape=t.paper.rect(n.start,r.stop,n.len,r.len).attr({gradient:c,stroke:"none"})}}),t.Component.components.graph_background=[t.Component.GraphBackground,1],t.Component.Grid=t.Class.create(t.Component,{defaults:function(){return{stroke:"#eee","stroke-width":1}}}),t.Component.components.grid=[t.Component.Grid,0],t.Component.Labels=t.Class.create(t.Component,{defaults:function(e){return{marker_size:5,angle:0,add_padding:!0,position:0,grid:e.grid?e.grid.options:undefined}},process_options:function(e,n){var r=e.title;t.extend(this.font=t.extend({},n.get_font()),e.font||{}),this.markers_attributes={stroke:this.font.fill,"stroke-width":1},t.extend(this.markers_attributes,e.markers_attributes),r&&(this.title=r.value,t.extend(this.title_font=this.font,e.title_font)),this.x.angle=0,this.y.angle=-90},calculate:function(e){this.calculate_labels_padding(this.graph.x,1,e)},calculate_labels_padding:function(e,t,n){var r=e.direction[0],i=e.direction[1],s=n.marker_size,o=[];if((e.labels=n.values)===undefined){n.values=e.labels=[];for(p=0;++p<=this.data_samples;)e.labels[p]=p}var u=e.angle+=n.angle;if(e.labels){var a=this.get_labels_bounding_boxes(e),f=e.font_size=a[1];if(u%180){u=u*Math.PI/180;var l=Math.abs(Math.sin(u)),c=Math.abs(Math.cos(u));e.f=[f*c/2,f*l/2+s],o[1]=Math.round(a[0]*l+e.f[1]+e.f[0]),r?u<0^n.position&&(e.f[0]=-e.f[0]):e.f=[-e.f[1],0];if(this.p.vml){var h=2.2;i&&(u+=Math.PI/2),e.f[0]-=h*Math.sin(u),e.f[1]+=h*Math.cos(u)}e.anchor=i?n.position?"start":"end":u>0^n.position?"start":"end"}else{var n=.6*f+s;e.f=[i*n,r*n],o[1]=a[1]*1.1+s,e.anchor="middle"}}var p=t^this.orientation^n.position;n.add_padding?e.other.padding[p]+=o[1]:e.other.padding[p]<o[1]&&(e.other.padding[p]=o[1])},get_labels_bounding_boxes:function(e){if(this.labels)return this.bbox;this.labels=[],this.bboxes=[],this.bbox=[0,0];var t=this,n=0;return e.labels.forEach(function(e){typeof e=="undefined"&&(e=""),t.labels.push(e=t.p.paper.text(10,10,e.toString()).attr(t.font)),t.bboxes.push(e=e.getBBox()),e.width>n&&(t.bbox=[n=e.width,e.height])}),this.bbox},clear:function(){this.labels=null},text_size:function(e,t){var n=this.p.paper.text(10,10,"").attr(t).attr({text:e}),r,i;return i=n.getBBox(),r=[i.width,i.height],n.remove(),r},draw:function(e){this.draw_labels_grid(this.graph.x,e)},draw_labels_grid:function(e,n){var r=this,i=e.direction[0],s=e.direction[1],o=e.step,u=r.x.start+r.x.start_offset*i,a=r.y.start-r.y.start_offset*s,f=n.marker_size,l=e.f[0],c=e.f[1],h=e.angle,p=this.p.paper,d=n.grid,v=[];if(d){var m=r[i?"y":"x"].len,g=0,y=0,b=e.labels,w=[];if(d.through){m+=e.padding[1]+10;var E=-e.padding[0]-this.bbox[0]-f-20;i?y=E:g=E}}i?(f="v"+f,m="v-"+m):(f="h-"+f,m="h"+m,h+=90),r.labels||this.get_labels_bounding_boxes(e);for(var S=-1,x=r.labels.length;++S<x;){var T=r.labels[S];f&&v.push("M",u,a,f),d&&(b[S]?w.push("M",u,a,m):w.push("M",u+g,a+y,m));var N=u+l,C=a+c;T.attr({x:N,y:C,"text-anchor":e.anchor}).toFront(),h&&T.rotate(h,N,C),i&&(u+=o),s&&(a-=o)}f&&p.path(t.svg_path(v)).attr(this.markers_attributes),d&&(i&&w.push("M",this.x.start," ",this.y.stop,"h",this.x.len,"v",this.y.len),p.path(t.svg_path(w)).attr(d))}}),t.Component.components.labels=[t.Component.Labels,3],t.Component.ValueLabels=t.Class.create(t.Component.Labels,{calculate:function(e,i){function T(e,i,s,o){n&&r("Ico.Component.ValueLabels.calculate_value_labels_params(), min: "+e+", max: "+i+", range: "+s+", space: "+o);if(e<0&&i>0){var u=Math.round(o*i/s);u==0?u=1:u==o&&(u-=1);var a=o-u,f=t.significant_digits_round(Math.max(i/u,-e/a),2,function(e){e=Math.ceil(e);if(e<=10)return e;if(e<=12)return 12;var t;return e<=54?(t=e%5)?e-t+5:e:(t=e%10)?e-t+10:e});e=-f*a,i=f*u}else{var f=t.significant_digits_round(s/o,1,Math.ceil);i<=0?e=i-f*o:e>=0&&(i=e+f*o)}return{min:e,max:i,spaces:o,step:f,waste:o*f-s}}n&&r("Ico.Component.ValueLabels.calculate()");var s=this,o=i.max,u=i.min,a=o-u,f=e.spaces,l;i.calculate_graph_len(this.graph.y);if(!f){var c=Math.abs(e.angle),h;this.orientation&&c<30||!this.orientation&&c>60?h=Math.max.apply(Math,[u,o].map(function(e){return s.text_size("0"+t.significant_digits_round(e,3,Math.round,!0)+s.p.options.units,s.font)[0]})):h=1.5*this.text_size("0",this.font)[1];if(h===0)throw new Error("Ico.Component.ValueLabels(), min_step is zero, canvas is possibly not active");f=Math.round(this.graph.y.len/h);if(f>2){var p=a,d=f;for(var v=1;++v<=d;)l=T(u,o,a,v),l.waste<=p&&(p=l.waste,f=v)}}l=T(u,o,a,f),i.range=(i.max=l.max)-(i.min=l.min);var m=t.root(l.step*l.spaces,1e3);if(m){var g=Math.pow(1e3,m);l.step/=g,l.min/=g}var y=e.values=[],b=0;for(var w=l.min,E=-1;++E<=l.spaces;w+=l.step){var S=t.significant_digits_round(w,3,Math.round,!0).toString(),x=(S+".").split(".")[1].length;x>b&&(b=x),y.push(S)}y.forEach(function(e,t){var n=(e+".").split(".")[1].length;n<b&&(n==0&&(e+="."),e+="0000".substring(0,b-n)),y[t]=s.p.format_value(e,m)}),this.graph.y.step=this.graph.y.len/l.spaces,this.calculate_labels_padding(this.graph.y,0,e)},draw:function(e){this.draw_labels_grid(this.graph.y,e)}}),t.Component.components.value_labels=[t.Component.ValueLabels,4],t.Component.Meanline=t.Class.create(t.Component,{defaults:function(){return{attributes:{stroke:"#bbb","stroke-width":2}}},calculate:function(){var e=this.p.all_values;this.mean=e.reduce(function(e,t){return e+t},0),n&&r("Ico.Component.Meanline, calculate, len: "+e.length+", mean="+this.mean),this.mean=t.significant_digits_round(this.mean/e.length,3,Math.round,!0),n&&r("Ico.Component.Meanline, calculate, len: "+e.length+", mean="+this.mean)},draw:function(e,n){var r=e.attributes;if(!r)return;var i=this.graph.y.start-n.plot(this.mean);this.graph.y.mean={start:i,stop:i},this.graph.x.mean=this.graph.x,this.shape=n.paper.path(t.svg_path(["M",this.x.mean.start,this.y.mean.start,"L",this.x.mean.stop,this.y.mean.stop])).attr(r),n.show_label_onmouseover(this.shape,this.mean,r,0,0,"Average")}}),t.Component.components.meanline=[t.Component.Meanline,3],t.Component.FocusHint=t.Class.create(t.Component,{defaults:function(){return{length:6,attributes:{"stroke-width":2,stroke:this.p.get_font().fill}}},draw:function(e,n){if(n.min==0)return;var r=e.length,i=t.svg_path(["l",r,r]);this.shape=n.paper.path(t.svg_path(this.orientation?["M",this.x.start,this.y.start-r/2,i,"m0-",r,i]:["M",this.x.start-r/2,this.y.start-2*r,i+"m-",r," 0"+i])).attr(e.attributes)}}),t.Component.components.focus_hint=[t.Component.FocusHint,5],t.Component.Axis=t.Class.create(t.Component,{defaults:function(){return{attributes:{stroke:"#666","stroke-width":1}}},draw:function(e){var n=this.x,r=this.y;this.shape=this.p.paper.path(t.svg_path(["M",n.start,r.stop,"v",r.len,"h",n.len])).attr(e.attributes)}}),t.Component.components.axis=[t.Component.Axis,4]})(this);