| Current File : /home/jvzmxxx/wiki1/extensions/InteractiveTimeline/chap-links-library/js/src/graph/graph-min.js |
/*
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Copyright (C) 2010-2013 Almende B.V.
@author Jos de Jong, <jos@almende.org>
@date 2013-08-20
@version 1.3.2
*/
typeof links==="undefined"&&(links={});typeof google==="undefined"&&(google=void 0);
links.Graph=function(a){this.containerElement=a;this.width="100%";this.height="300px";this.end=this.start=null;this.redrawWhileMoving=this.showTooltip=this.zoomable=this.moveable=this.autoDataStep=!0;this.legend=void 0;this.line={};this.lines=[];this.defaultColors="#3366CC,#DC3912,#FF9900,#109618,#990099,#0099C6,#DD4477,#66AA00,#B82E2E,#316395,#994499,#22AA99,#AAAA11,#6633CC,#E67300,#8B0707".split(",");this.axisMargin=800;this.mainPadding=8;this.data=[];this._create()};
links.Graph.prototype.draw=function(a,b){this._readData(a);if(b!=void 0){if(b.width!=void 0)this.width=b.width;if(b.height!=void 0)this.height=b.height;if(b.start!=void 0)this.start=b.start;if(b.end!=void 0)this.end=b.end;if(b.min!=void 0)this.min=b.min;if(b.max!=void 0)this.max=b.max;if(b.zoomMin!=void 0)this.zoomMin=b.zoomMin;if(b.zoomMax!=void 0)this.zoomMax=b.zoomMax;if(b.scale!=void 0)this.scale=b.scale;if(b.step!=void 0)this.step=b.step;if(b.autoDataStep!=void 0)this.autoDataStep=b.autoDataStep;
if(b.moveable!=void 0)this.moveable=b.moveable;if(b.zoomable!=void 0)this.zoomable=b.zoomable;if(b.line!=void 0)this.line=b.line;if(b.lines!=void 0)this.lines=b.lines;if(b.vStart!=void 0)this.vStart=b.vStart;if(b.vEnd!=void 0)this.vEnd=b.vEnd;if(b.vMin!=void 0)this.vMinFixed=b.vMin;if(b.vMax!=void 0)this.vMaxFixed=b.vMax;if(b.vStep!=void 0)this.vStepSize=b.vStep;if(b.vPrettyStep!=void 0)this.vPrettyStep=b.vPrettyStep;if(b.vAreas!=void 0)this.vAreas=b.vAreas;if(b.legend!=void 0)this.legend=b.legend;
if(b.tooltip!=void 0&&(this.showTooltip=b.tooltip!=!1,typeof b.tooltip==="function"))this.tooltipFormatter=b.tooltip;if(b.intervalMin!=void 0)this.zoomMin=b.intervalMin,console.log("WARNING: Option intervalMin is deprecated. Use zoomMin instead");if(b.intervalMax!=void 0)this.zoomMax=b.intervalMax,console.log("WARNING: Option intervalMax is deprecated. Use zoomMax instead")}this.setSize(this.width,this.height);this.setVisibleChartRange(this.start,this.end,!1);this.scale&&this.step&&this.hStep.setScale(this.scale,
this.step);this.redraw();this.trigger("ready")};links.Graph.prototype.trigger=function(a,b){links.events.trigger(this,a,b);google&&google.visualization&&google.visualization.events&&google.visualization.events.trigger(this,a,b)};
links.Graph.prototype._readData=function(a){if(google&&google.visualization&&google.visualization.DataTable&&a instanceof google.visualization.DataTable){this.data=[];for(var b=1,c=a.getNumberOfColumns();b<c;b++){for(var d=[],e=0,g=a.getNumberOfRows();e<g;e++)d.push({date:a.getValue(e,0),value:a.getValue(e,b)});d={label:a.getColumnLabel(b),type:void 0,dataRange:void 0,rowRange:void 0,visibleRowRange:void 0,data:d};this.data.push(d)}}else this.data=a||[];a=0;for(b=this.data.length;a<b;a++)d=this.data[a],
c=d.type=="area"?["start","end"]:["date"],d.dataRange=this._getDataRange(d.data),d.rowRange=this._getRowRange(d.data,c)};links.Graph.StepDate=function(a,b,c){this.current=new Date;this._start=new Date;this._end=new Date;this.autoScale=!0;this.scale=links.Graph.StepDate.SCALE.DAY;this.step=1;this.setRange(a,b,c)};links.Graph.StepDate.SCALE={MILLISECOND:1,SECOND:2,MINUTE:3,HOUR:4,DAY:5,WEEKDAY:6,MONTH:7,YEAR:8};
links.Graph.StepDate.prototype.setRange=function(a,b,c){if(a instanceof Date&&b instanceof Date)this._start=a!=void 0?new Date(a.valueOf()):new Date,this._end=b!=void 0?new Date(b.valueOf()):new Date,this.autoScale&&this.setMinimumStep(c)};links.Graph.StepDate.prototype.start=function(){this.current=new Date(this._start.valueOf());this.roundToMinor()};
links.Graph.StepDate.prototype.roundToMinor=function(){switch(this.scale){case links.Graph.StepDate.SCALE.YEAR:this.current.setFullYear(this.step*Math.floor(this.current.getFullYear()/this.step)),this.current.setMonth(0);case links.Graph.StepDate.SCALE.MONTH:this.current.setDate(1);case links.Graph.StepDate.SCALE.DAY:case links.Graph.StepDate.SCALE.WEEKDAY:this.current.setHours(0);case links.Graph.StepDate.SCALE.HOUR:this.current.setMinutes(0);case links.Graph.StepDate.SCALE.MINUTE:this.current.setSeconds(0);
case links.Graph.StepDate.SCALE.SECOND:this.current.setMilliseconds(0)}if(this.step!=1)switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:this.current.setMilliseconds(this.current.getMilliseconds()-this.current.getMilliseconds()%this.step);break;case links.Graph.StepDate.SCALE.SECOND:this.current.setSeconds(this.current.getSeconds()-this.current.getSeconds()%this.step);break;case links.Graph.StepDate.SCALE.MINUTE:this.current.setMinutes(this.current.getMinutes()-this.current.getMinutes()%
this.step);break;case links.Graph.StepDate.SCALE.HOUR:this.current.setHours(this.current.getHours()-this.current.getHours()%this.step);break;case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()-1-(this.current.getDate()-1)%this.step+1);break;case links.Graph.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()-this.current.getMonth()%this.step);break;case links.Graph.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()-
this.current.getFullYear()%this.step)}};links.Graph.StepDate.prototype.end=function(){return this.current.valueOf()>this._end.valueOf()};
links.Graph.StepDate.prototype.next=function(){var a=this.current.valueOf();if(this.current.getMonth()<6)switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:this.current=new Date(this.current.valueOf()+this.step);break;case links.Graph.StepDate.SCALE.SECOND:this.current=new Date(this.current.valueOf()+this.step*1E3);break;case links.Graph.StepDate.SCALE.MINUTE:this.current=new Date(this.current.valueOf()+this.step*6E4);break;case links.Graph.StepDate.SCALE.HOUR:this.current=new Date(this.current.valueOf()+
this.step*36E5);var b=this.current.getHours();this.current.setHours(b-b%this.step);break;case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()+this.step);break;case links.Graph.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()+this.step);break;case links.Graph.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()+this.step)}else switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:this.current=
new Date(this.current.valueOf()+this.step);break;case links.Graph.StepDate.SCALE.SECOND:this.current.setSeconds(this.current.getSeconds()+this.step);break;case links.Graph.StepDate.SCALE.MINUTE:this.current.setMinutes(this.current.getMinutes()+this.step);break;case links.Graph.StepDate.SCALE.HOUR:this.current.setHours(this.current.getHours()+this.step);break;case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()+this.step);break;case links.Graph.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()+
this.step);break;case links.Graph.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()+this.step)}if(this.step!=1)switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:this.current.getMilliseconds()<this.step&&this.current.setMilliseconds(0);break;case links.Graph.StepDate.SCALE.SECOND:this.current.getSeconds()<this.step&&this.current.setSeconds(0);break;case links.Graph.StepDate.SCALE.MINUTE:this.current.getMinutes()<this.step&&this.current.setMinutes(0);break;case links.Graph.StepDate.SCALE.HOUR:this.current.getHours()<
this.step&&this.current.setHours(0);break;case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:this.current.getDate()<this.step+1&&this.current.setDate(1);break;case links.Graph.StepDate.SCALE.MONTH:this.current.getMonth()<this.step&&this.current.setMonth(0)}if(this.current.valueOf()==a)this.current=new Date(this._end.valueOf())};links.Graph.StepDate.prototype.getCurrent=function(){return this.current};
links.Graph.StepDate.prototype.setScale=function(a,b){this.scale=a;if(b>0)this.step=b;this.autoScale=!1};links.Graph.StepDate.prototype.setAutoScale=function(a){this.autoScale=a};
links.Graph.StepDate.prototype.setMinimumStep=function(a){if(a!=void 0){if(31104E9>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=1E3;if(15552E9>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=500;if(31104E8>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=100;if(15552E8>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=50;if(31104E7>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=10;if(15552E7>a)this.scale=links.Graph.StepDate.SCALE.YEAR,this.step=5;if(31104E6>a)this.scale=
links.Graph.StepDate.SCALE.YEAR,this.step=1;if(7776E6>a)this.scale=links.Graph.StepDate.SCALE.MONTH,this.step=3;if(2592E6>a)this.scale=links.Graph.StepDate.SCALE.MONTH,this.step=1;if(432E6>a)this.scale=links.Graph.StepDate.SCALE.DAY,this.step=5;if(1728E5>a)this.scale=links.Graph.StepDate.SCALE.DAY,this.step=2;if(864E5>a)this.scale=links.Graph.StepDate.SCALE.DAY,this.step=1;if(432E5>a)this.scale=links.Graph.StepDate.SCALE.WEEKDAY,this.step=1;if(144E5>a)this.scale=links.Graph.StepDate.SCALE.HOUR,this.step=
4;if(36E5>a)this.scale=links.Graph.StepDate.SCALE.HOUR,this.step=1;if(9E5>a)this.scale=links.Graph.StepDate.SCALE.MINUTE,this.step=15;if(6E5>a)this.scale=links.Graph.StepDate.SCALE.MINUTE,this.step=10;if(3E5>a)this.scale=links.Graph.StepDate.SCALE.MINUTE,this.step=5;if(6E4>a)this.scale=links.Graph.StepDate.SCALE.MINUTE,this.step=1;if(15E3>a)this.scale=links.Graph.StepDate.SCALE.SECOND,this.step=15;if(1E4>a)this.scale=links.Graph.StepDate.SCALE.SECOND,this.step=10;if(5E3>a)this.scale=links.Graph.StepDate.SCALE.SECOND,
this.step=5;if(1E3>a)this.scale=links.Graph.StepDate.SCALE.SECOND,this.step=1;if(200>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=200;if(100>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=100;if(50>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=50;if(10>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=10;if(5>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=5;if(1>a)this.scale=links.Graph.StepDate.SCALE.MILLISECOND,this.step=
1}};
links.Graph.StepDate.prototype.snap=function(a){if(this.scale==links.Graph.StepDate.SCALE.YEAR){var b=a.getFullYear()+Math.round(a.getMonth()/12);a.setFullYear(Math.round(b/this.step)*this.step);a.setMonth(0);a.setDate(0);a.setHours(0);a.setMinutes(0);a.setSeconds(0);a.setMilliseconds(0)}else if(this.scale==links.Graph.StepDate.SCALE.MONTH)a.getDate()>15?(a.setDate(1),a.setMonth(a.getMonth()+1)):a.setDate(1),a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setMilliseconds(0);else if(this.scale==links.Graph.StepDate.SCALE.DAY||
this.scale==links.Graph.StepDate.SCALE.WEEKDAY){switch(this.step){case 5:case 2:a.setHours(Math.round(a.getHours()/24)*24);break;default:a.setHours(Math.round(a.getHours()/12)*12)}a.setMinutes(0);a.setSeconds(0);a.setMilliseconds(0)}else if(this.scale==links.Graph.StepDate.SCALE.HOUR){switch(this.step){case 4:a.setMinutes(Math.round(a.getMinutes()/60)*60);break;default:a.setMinutes(Math.round(a.getMinutes()/30)*30)}a.setSeconds(0);a.setMilliseconds(0)}else if(this.scale==links.Graph.StepDate.SCALE.MINUTE){switch(this.step){case 15:case 10:a.setMinutes(Math.round(a.getMinutes()/
5)*5);a.setSeconds(0);break;case 5:a.setSeconds(Math.round(a.getSeconds()/60)*60);break;default:a.setSeconds(Math.round(a.getSeconds()/30)*30)}a.setMilliseconds(0)}else if(this.scale==links.Graph.StepDate.SCALE.SECOND)switch(this.step){case 15:case 10:a.setSeconds(Math.round(a.getSeconds()/5)*5);a.setMilliseconds(0);break;case 5:a.setMilliseconds(Math.round(a.getMilliseconds()/1E3)*1E3);break;default:a.setMilliseconds(Math.round(a.getMilliseconds()/500)*500)}else this.scale==links.Graph.StepDate.SCALE.MILLISECOND&&
(b=this.step>5?this.step/2:1,a.setMilliseconds(Math.round(a.getMilliseconds()/b)*b))};
links.Graph.StepDate.prototype.isMajor=function(){switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:return this.current.getMilliseconds()==0;case links.Graph.StepDate.SCALE.SECOND:return this.current.getSeconds()==0;case links.Graph.StepDate.SCALE.MINUTE:return this.current.getHours()==0&&this.current.getMinutes()==0;case links.Graph.StepDate.SCALE.HOUR:return this.current.getHours()==0;case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:return this.current.getDate()==1;
case links.Graph.StepDate.SCALE.MONTH:return this.current.getMonth()==0;case links.Graph.StepDate.SCALE.YEAR:return!1;default:return!1}};
links.Graph.StepDate.prototype.getLabelMinor=function(a){var b="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),c="Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",");if(a==void 0)a=this.current;switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:return String(a.getMilliseconds());case links.Graph.StepDate.SCALE.SECOND:return String(a.getSeconds());case links.Graph.StepDate.SCALE.MINUTE:return this.addZeros(a.getHours(),2)+":"+this.addZeros(a.getMinutes(),2);case links.Graph.StepDate.SCALE.HOUR:return this.addZeros(a.getHours(),
2)+":"+this.addZeros(a.getMinutes(),2);case links.Graph.StepDate.SCALE.WEEKDAY:return c[a.getDay()]+" "+a.getDate();case links.Graph.StepDate.SCALE.DAY:return String(a.getDate());case links.Graph.StepDate.SCALE.MONTH:return b[a.getMonth()];case links.Graph.StepDate.SCALE.YEAR:return String(a.getFullYear());default:return""}};
links.Graph.StepDate.prototype.getLabelMajor=function(a){var b="January,February,March,April,May,June,July,August,September,October,November,December".split(","),c="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(",");if(a==void 0)a=this.current;switch(this.scale){case links.Graph.StepDate.SCALE.MILLISECOND:return this.addZeros(a.getHours(),2)+":"+this.addZeros(a.getMinutes(),2)+":"+this.addZeros(a.getSeconds(),2);case links.Graph.StepDate.SCALE.SECOND:return a.getDate()+" "+b[a.getMonth()]+
" "+this.addZeros(a.getHours(),2)+":"+this.addZeros(a.getMinutes(),2);case links.Graph.StepDate.SCALE.MINUTE:return c[a.getDay()]+" "+a.getDate()+" "+b[a.getMonth()]+" "+a.getFullYear();case links.Graph.StepDate.SCALE.HOUR:return c[a.getDay()]+" "+a.getDate()+" "+b[a.getMonth()]+" "+a.getFullYear();case links.Graph.StepDate.SCALE.WEEKDAY:case links.Graph.StepDate.SCALE.DAY:return b[a.getMonth()]+" "+a.getFullYear();case links.Graph.StepDate.SCALE.MONTH:return String(a.getFullYear());default:return""}};
links.Graph.StepDate.prototype.addZeros=function(a,b){for(var c=""+a;c.length<b;)c="0"+c;return c};links.Graph.StepNumber=function(a,b,c,d){this._end=this._start=0;this._step=1;this.prettyStep=!0;this.precision=5;this._current=0;this._setRange(a,b,c,d)};links.Graph.StepNumber.prototype._setRange=function(a,b,c,d){this._start=a?a:0;this._end=b?b:0;this.setStep(c,d)};
links.Graph.StepNumber.prototype.setStep=function(a,b){if(!(a==void 0||a<=0))if(this.prettyStep=b,this._step=this.prettyStep==!0?links.Graph.StepNumber._calculatePrettyStep(a):a,this._end/this._step>Math.pow(10,this.precision))this.precision=void 0};
links.Graph.StepNumber._calculatePrettyStep=function(a){log10=function(a){return Math.log(a)/Math.LN10};var b=1*Math.pow(10,Math.round(log10(a/1))),c=2*Math.pow(10,Math.round(log10(a/2))),d=5*Math.pow(10,Math.round(log10(a/5)));Math.abs(c-a)<=Math.abs(b-a)&&(b=c);Math.abs(d-a)<=Math.abs(b-a)&&(b=d);b<=0&&(b=1);return b};links.Graph.StepNumber.prototype.getCurrent=function(){return this.precision?Number(this._current.toPrecision(this.precision)):this._current};
links.Graph.StepNumber.prototype.getStep=function(){return this._step};links.Graph.StepNumber.prototype.start=function(){this._current=this.prettyStep?this._start-this._start%this._step:this._start};links.Graph.StepNumber.prototype.next=function(){this._current+=this._step};links.Graph.StepNumber.prototype.end=function(){return this._current>this._end};links.Graph.prototype.setScale=function(a,b){this.hStep.setScale(a,b);this.redraw()};
links.Graph.prototype.setAutoScale=function(a){this.hStep.setAutoScale(a);this.redraw()};links.Graph.px=function(a){return Math.round(a)+"px"};links.Graph.prototype._calcConversionFactor=function(){this.ttsOffset=this.start.valueOf();this.ttsFactor=this.frame.clientWidth/(this.end.valueOf()-this.start.valueOf())};links.Graph.prototype._screenToTime=function(a){return new Date(a/this.ttsFactor+this.ttsOffset)};
links.Graph.prototype.timeToScreen=function(a){return(a.valueOf()-this.ttsOffset)*this.ttsFactor||null};
links.Graph.prototype._create=function(){for(;this.containerElement.hasChildNodes();)this.containerElement.removeChild(this.containerElement.firstChild);this.main=document.createElement("DIV");this.main.className="graph-frame";this.main.style.position="relative";this.main.style.overflow="hidden";this.containerElement.appendChild(this.main);this.frame=document.createElement("DIV");this.frame.style.overflow="hidden";this.frame.style.position="relative";this.frame.style.height="200px";this.main.appendChild(this.frame);
this.frame.background=document.createElement("DIV");this.frame.background.className="graph-canvas";this.frame.background.style.position="relative";this.frame.background.style.left=links.Graph.px(0);this.frame.background.style.top=links.Graph.px(0);this.frame.background.style.width="100%";this.frame.appendChild(this.frame.background);this.frame.vgrid=document.createElement("DIV");this.frame.vgrid.className="graph-axis-grid";this.frame.vgrid.style.position="absolute";this.frame.vgrid.style.left=links.Graph.px(0);
this.frame.vgrid.style.top=links.Graph.px(0);this.frame.vgrid.style.width="100%";this.frame.appendChild(this.frame.vgrid);this.frame.canvas=document.createElement("DIV");this.frame.canvas.style.position="absolute";this.frame.canvas.style.left=links.Graph.px(0);this.frame.canvas.style.top=links.Graph.px(0);this.frame.appendChild(this.frame.canvas);this.frame.canvas.axis=document.createElement("DIV");this.frame.canvas.axis.style.position="relative";this.frame.canvas.axis.style.left=links.Graph.px(0);
this.frame.canvas.axis.style.top=links.Graph.px(0);this.frame.canvas.appendChild(this.frame.canvas.axis);this.majorLabels=[];this.frame.canvas.graph=document.createElement("canvas");this.frame.canvas.graph.style.position="absolute";this.frame.canvas.graph.style.left=links.Graph.px(0);this.frame.canvas.graph.style.top=links.Graph.px(0);this.frame.canvas.appendChild(this.frame.canvas.graph);if((isIE=/MSIE/.test(navigator.userAgent)&&!window.opera)&&typeof G_vmlCanvasManager!="undefined")this.frame.canvas.graph=
G_vmlCanvasManager.initElement(this.frame.canvas.graph);var a=this;if(this.showTooltip)var b=function(b){a._onMouseOut(b)},c=function(b){a._onMouseHover(b)};links.Graph.addEventListener(this.frame,"mousedown",function(b){a._onMouseDown(b)});links.Graph.addEventListener(this.frame,"mousemove",c);links.Graph.addEventListener(this.frame,"mouseout",b);links.Graph.addEventListener(this.frame,"mousewheel",function(b){a._onWheel(b)});links.Graph.addEventListener(this.frame,"touchstart",function(b){a._onTouchStart(b)});
links.Graph.addEventListener(this.frame,"mousedown",function(){a._checkSize()});this.hStep=new links.Graph.StepDate;this.vStep=new links.Graph.StepNumber;this.eventsSorted=[]};
links.Graph.prototype.setSize=function(a,b){this.containerElement.style.width=a;this.containerElement.style.height=b;this.main.style.width=a;this.main.style.height=b;this.frame.style.width=links.Graph.px(this.main.clientWidth);this.frame.style.height=links.Graph.px(this.main.clientHeight);this.frame.canvas.style.width=links.Graph.px(this.frame.clientWidth);this.frame.canvas.style.height=links.Graph.px(this.frame.clientHeight)};
links.Graph.prototype._zoom=function(a,b){b==void 0&&(b=new Date((this.start.valueOf()+this.end.valueOf())/2));a>=1&&(a=0.9);a<=-1&&(a=-0.9);a<0&&(a/=1+a);var c=parseFloat(this.start.valueOf()-b.valueOf()),d=parseFloat(this.end.valueOf()-b.valueOf()),c=new Date(this.start.valueOf()-c*a),d=new Date(this.end.valueOf()-d*a),e=d.valueOf()-c.valueOf(),g=Number(this.zoomMin)||10;g<10&&(g=10);e>=g&&(this._applyRange(c,d,b),this._redrawHorizontalAxis(),this._redrawData(),this._redrawDataTooltip())};
links.Graph.prototype._move=function(a){var b=parseFloat(this.end.valueOf()-this.start.valueOf());this._applyRange(new Date(this.start.valueOf()+b*a),new Date(this.end.valueOf()+b*a));this._redrawHorizontalAxis();this._redrawData()};
links.Graph.prototype._applyRange=function(a,b,c){var a=a.valueOf(),b=b.valueOf(),d=b-a,e=Number(this.zoomMin)||10;e<10&&(e=10);var g=Number(this.zoomMax)||31536E10;g>31536E10&&(g=31536E10);g<e&&(g=e);var h=this.min?this.min.valueOf():void 0,f=this.max?this.max.valueOf():void 0;h&&f&&(h>=f&&(f=h+864E5),g>f-h&&(g=f-h),e>f-h&&(e=f-h));a>=b&&(b+=864E5);if(d<e){e-=d;var i=c?(c.valueOf()-a)/d:0.5;a-=Math.round(e*i);b+=Math.round(e*(1-i))}d>g&&(e=d-g,i=c?(c.valueOf()-a)/d:0.5,a+=Math.round(e*i),b-=Math.round(e*
(1-i)));h&&(e=a-h,e<0&&(a-=e,b-=e));f&&(e=f-b,e<0&&(a+=e,b+=e));this.start=new Date(a);this.end=new Date(b)};links.Graph.prototype._zoomVertical=function(a,b){b==void 0&&(b=(this.vStart+this.vEnd)/2);a>=1&&(a=0.9);a<=-1&&(a=-0.9);a<0&&(a/=1+a);var c=this.vStart-(this.vStart-b)*a,d=this.vEnd-(this.vEnd-b)*a;if(!(c>=d)){if(c<this.vMin)c=this.vMin;if(d>this.vMax)d=this.vMax;this.vStart=c;this.vEnd=d;this._redrawVerticalAxis();this._redrawHorizontalAxis();this._redrawData();this._redrawDataTooltip()}};
links.Graph.prototype.redraw=function(){this._initSize();this._redrawLegend();this._redrawVerticalAxis();this._redrawHorizontalAxis();this._redrawData();this._redrawDataTooltip();this.lastMainWidth=this.main.clientWidth;this.lastMainHeight=this.main.clientHeight};
links.Graph.prototype._initSize=function(){var a=document.createTextNode("0"),b=document.createElement("DIV");b.className="graph-axis-text";b.appendChild(a);b.style.position="absolute";b.style.visibility="hidden";b.style.padding="0px";this.frame.canvas.axis.appendChild(b);this.axisCharWidth=parseInt(b.clientWidth);this.axisCharHeight=parseInt(b.clientHeight);b.style.padding="";b.className="graph-axis-text graph-axis-text-minor";this.axisTextMinorHeight=parseInt(b.offsetHeight);b.className="graph-axis-text graph-axis-text-major";
this.axisTextMajorHeight=parseInt(b.offsetHeight);this.frame.canvas.axis.removeChild(b);this.axisOffset=this.main.clientHeight-this.axisTextMinorHeight-this.axisTextMajorHeight-2*this.mainPadding;if(this.data.length>0){for(var a=null,b=0,c=this.data.length;b<c;b++){var d=this.data[b].dataRange;if(d)a?(a.min=Math.min(a.min,d.min),a.max=Math.max(a.max,d.max)):a={min:d.min,max:d.max}}this.verticalRange=a||{min:-10,max:10}}else this.verticalRange={min:-10,max:10};a=this.verticalRange.max-this.verticalRange.min;
a<=0&&(a=1);b=(this.verticalRange.max+this.verticalRange.min)/2;this.vMin=this.vMinFixed!=void 0?this.vMinFixed:b-a/2*1.05;this.vMax=this.vMaxFixed!=void 0?this.vMaxFixed:b+a/2*1.05;if(this.vMax<=this.vMin)this.vMax=this.vMin+1};
links.Graph.prototype._redrawHorizontalAxis=function(){for(;this.frame.canvas.axis.hasChildNodes();)this.frame.canvas.axis.removeChild(this.frame.canvas.axis.lastChild);this.majorLabels=[];this.frame.style.left=links.Graph.px(this.main.axisLeft.clientWidth+this.mainPadding);this.frame.style.top=links.Graph.px(this.mainPadding);this.frame.style.height=links.Graph.px(this.main.clientHeight-2*this.mainPadding);this.frame.style.width=links.Graph.px(this.main.clientWidth-this.main.axisLeft.clientWidth-
this.legendWidth-2*this.mainPadding-2);this.frame.canvas.style.width=links.Graph.px(this.frame.clientWidth);this.frame.canvas.style.height=links.Graph.px(this.axisOffset);this.frame.background.style.height=links.Graph.px(this.axisOffset);this._calcConversionFactor();var a=this._screenToTime(-this.axisMargin),b=this._screenToTime(this.frame.clientWidth+this.axisMargin),c=this.axisOffset,d=this.axisOffset+this.axisTextMinorHeight;this.minimumStep=this._screenToTime(this.axisCharWidth*6).valueOf()-this._screenToTime(0).valueOf();
this.hStep.setRange(a,b,this.minimumStep);if(this.leftMajorLabel)this.frame.canvas.removeChild(this.leftMajorLabel),this.leftMajorLabel=void 0;var e=this.hStep.getLabelMajor(this._screenToTime(0)),g=document.createTextNode(e);this.leftMajorLabel=document.createElement("DIV");this.leftMajorLabel.className="graph-axis-text graph-axis-text-major";this.leftMajorLabel.appendChild(g);this.leftMajorLabel.style.position="absolute";this.leftMajorLabel.style.left=links.Graph.px(0);this.leftMajorLabel.style.top=
links.Graph.px(d);this.leftMajorLabel.title=e;this.frame.canvas.appendChild(this.leftMajorLabel);this.hStep.start();for(e=0;!this.hStep.end()&&e<200;){e++;var h=this.timeToScreen(this.hStep.getCurrent()),g=this.hStep.isMajor()?this.frame.clientHeight:this.axisOffset+this.axisTextMinorHeight,f=document.createElement("DIV");f.className=this.hStep.isMajor()?"graph-axis-grid graph-axis-grid-major":"graph-axis-grid graph-axis-grid-minor";f.style.position="absolute";f.style.borderLeftStyle="solid";f.style.top=
links.Graph.px(0);f.style.width=links.Graph.px(0);f.style.height=links.Graph.px(g);f.style.left=links.Graph.px(h-f.offsetWidth/2);this.frame.canvas.axis.appendChild(f);if(this.hStep.isMajor())g=document.createTextNode(this.hStep.getLabelMajor()),f=document.createElement("DIV"),this.frame.canvas.axis.appendChild(f),f.className="graph-axis-text graph-axis-text-major",f.appendChild(g),f.style.position="absolute",f.style.width=links.Graph.px(f.clientWidth),f.style.left=links.Graph.px(h),f.style.top=links.Graph.px(d),
f.title=this.hStep.getCurrent(),f.x=h,this.majorLabels.push(f);g=document.createTextNode(this.hStep.getLabelMinor());f=document.createElement("DIV");f.appendChild(g);f.className="graph-axis-text graph-axis-text-minor";f.style.position="absolute";f.style.left=links.Graph.px(h);f.style.top=links.Graph.px(c);f.title=this.hStep.getCurrent();this.frame.canvas.axis.appendChild(f);this.hStep.next()}c=document.createElement("DIV");c.className="graph-axis";c.style.position="absolute";c.style.borderTopStyle=
"solid";c.style.top=links.Graph.px(0);c.style.left=links.Graph.px(this.timeToScreen(a));c.style.width=links.Graph.px(this.timeToScreen(b)-this.timeToScreen(a));c.style.height=links.Graph.px(0);this.frame.canvas.axis.appendChild(c);c=document.createElement("DIV");c.className="graph-axis";c.style.position="absolute";c.style.borderTopStyle="solid";c.style.top=links.Graph.px(this.axisOffset);c.style.left=links.Graph.px(this.timeToScreen(a));c.style.width=links.Graph.px(this.timeToScreen(b)-this.timeToScreen(a));
c.style.height=links.Graph.px(0);this.frame.canvas.axis.appendChild(c);this._redrawAxisLeftMajorLabel()};
links.Graph.prototype._redrawAxisLeftMajorLabel=function(){var a=parseFloat(this.frame.canvas.axis.style.left),b=null,c=null,d=null,e;for(e in this.majorLabels)if(this.majorLabels.hasOwnProperty(e)){var g=this.majorLabels[e];g.x+a<0&&(b=g);if(g.x+a>0&&(d==null||d+a<0))c=g;d=g.x}if(b)b.style.visibility="hidden";if(c)c.style.visibility="visible";if(c&&this.leftMajorLabel.clientWidth>c.x+a)this.leftMajorLabel.style.visibility="hidden";else if(a=this.hStep.getLabelMajor(this._screenToTime(-a)),this.leftMajorLabel.title=
a,this.leftMajorLabel.innerHTML=a,this.leftMajorLabel.style.visibility!="visible")this.leftMajorLabel.style.visibility="visible"};
links.Graph.prototype._redrawVerticalAxis=function(){var a;if(this.main.axisLeft)for(;this.main.axisLeft.hasChildNodes();)this.main.axisLeft.removeChild(this.main.axisLeft.lastChild);else this.main.axisLeft=document.createElement("DIV"),this.main.axisLeft.style.position="absolute",this.main.axisLeft.className="graph-axis graph-axis-vertical",this.main.axisLeft.style.borderRightStyle="solid",this.main.appendChild(this.main.axisLeft);if(!this.main.axisRight)this.main.axisRight=document.createElement("DIV"),
this.main.axisRight.style.position="absolute",this.main.axisRight.className="graph-axis graph-axis-vertical",this.main.axisRight.style.borderRightStyle="solid",this.main.appendChild(this.main.axisRight);if(!this.main.zoomButtons){this.main.zoomButtons=document.createElement("DIV");this.main.zoomButtons.className="graph-axis-button-menu";this.main.zoomButtons.style.position="absolute";var b=this,c=document.createElement("DIV");c.innerHTML="+";c.title="Zoom in vertically (shift + scroll wheel)";c.className=
"graph-axis-button";this.main.zoomButtons.appendChild(c);links.Graph.addEventListener(c,"mousedown",function(a){b._zoomVertical(0.2);links.Graph.preventDefault(a)});c=document.createElement("DIV");c.innerHTML="−";c.className="graph-axis-button";c.title="Zoom out vertically (shift + scroll wheel)";this.main.zoomButtons.appendChild(c);links.Graph.addEventListener(c,"mousedown",function(a){b._zoomVertical(-0.2);links.Graph.preventDefault(a)});this.main.appendChild(this.main.zoomButtons)}for(;this.frame.vgrid.hasChildNodes();)this.frame.vgrid.removeChild(this.frame.vgrid.lastChild);
this.vStart=this.vStart!=void 0&&this.vStart<this.vMax?this.vStart:this.vMin;this.vEnd=this.vEnd!=void 0&&this.vEnd>this.vMin?this.vEnd:this.vMax;this.vStart=Math.max(this.vStart,this.vMin);this.vEnd=Math.min(this.vEnd,this.vMax);c=this.vStart;a=this.vEnd;var d=parseInt(this.axisOffset/40);this.vStep._setRange(c,a,this.vStepSize||(this.vEnd-this.vStart)/d,!0);if(this.vEnd>this.vStart){var c=this.axisOffset,e=(0-c)/(this.vEnd-this.vStart),g=c-this.vStart*e;this.yToScreen=function(a){return a*e+g};
this.screenToY=function(a){return(a-g)/e}}else this.yToScreen=function(){return 0},this.screenToY=function(){return 0};if(this.vAreas&&!this.frame.background.childNodes.length)for(a=0;a<this.vAreas.length;a++){c=this.vAreas[a];d=document.createElement("DIV");d.className="graph-background-area";d.start=c.start!=null?Number(c.start):null;d.end=c.end!=null?Number(c.end):null;c.className&&(d.className+=" "+c.className);if(c.color)d.style.backgroundColor=c.color;this.frame.background.appendChild(d)}if(this.frame.background.childNodes.length){c=
this.frame.background.childNodes;for(a=0;a<c.length;a++){var d=c[a],h=this.yToScreen(d.start!=null?Math.max(d.start,this.vStart):this.vStart),f=this.yToScreen(d.end!=null?Math.min(d.end,this.vEnd):this.vEnd);d.style.top=f+"px";d.style.height=Math.max(h-f,0)+"px"}}a=c=0;this.vStep.start();for(this.yToScreen(this.vStep.getCurrent())>this.axisOffset&&this.vStep.next();!this.vStep.end()&&a<100;){a++;d=this.vStep.getCurrent();h=this.yToScreen(d);Math.abs(d)>1E6?d=d.toExponential():Math.abs(d)<1.0E-4&&
(d=Math.abs(d)>this.vStep.getStep()/2?d.toExponential():0);var i=document.createTextNode(d),f=document.createElement("DIV");f.appendChild(i);f.className="graph-axis-text graph-axis-text-vertical";f.style.position="absolute";f.style.whiteSpace="nowrap";f.style.textAlign="right";this.main.axisLeft.appendChild(f);i=document.createElement("DIV");i.className="graph-axis-grid graph-axis-grid-vertical";i.style.position="absolute";i.style.borderTopStyle="solid";i.style.width="5px";this.main.axisLeft.appendChild(i);
var m=document.createElement("DIV");m.className=d!=0?"graph-axis-grid graph-axis-grid-minor":"graph-axis-grid graph-axis-grid-major";m.style.position="absolute";m.style.left="0px";m.style.width="100%";m.style.borderTopStyle="solid";this.frame.vgrid.appendChild(m);f.style.top=links.Graph.px(h-f.offsetHeight/2);i.style.top=links.Graph.px(h);m.style.top=links.Graph.px(h);c=Math.max(c,f.offsetWidth);this.vStep.next()}c+=this.main.zoomButtons.clientWidth;for(a=0;a<this.main.axisLeft.childNodes.length;a++)this.main.axisLeft.childNodes[a].style.left=
links.Graph.px(c-this.main.axisLeft.childNodes[a].offsetWidth);this.main.axisLeft.style.left=links.Graph.px(this.mainPadding);this.main.axisLeft.style.top=links.Graph.px(this.mainPadding);this.main.axisLeft.style.height=links.Graph.px(this.axisOffset+1);this.main.axisLeft.style.width=links.Graph.px(c);this.main.axisRight.style.left=links.Graph.px(this.main.clientWidth-this.legendWidth-this.mainPadding-2);this.main.axisRight.style.top=links.Graph.px(this.mainPadding);this.main.axisRight.style.height=
links.Graph.px(this.axisOffset+1)};
links.Graph.prototype._redrawData=function(){this._calcConversionFactor();var a=this._screenToTime(-this.axisMargin),b=this._screenToTime(this.frame.clientWidth+this.axisMargin),c=this.frame.canvas.graph,d=c.getContext("2d");d.clearRect(0,0,c.height,c.width);var e=this.timeToScreen(a),g=this.timeToScreen(b)-e,h=this.axisOffset;c.style.left=links.Graph.px(e);c.width=g;c.height=h;c=parseFloat(c.style.left);e=0;for(g=this.data.length;e<g;e++){var f=this._getLineStyle(e),i=this._getLineColor(e),m=this._getTextColor(e),
j=this._getFont(e),n=this._getLineWidth(e),k=this._getLineRadius(e),l=this._getLineVisible(e),q=this.data[e].type||"line",p=this.data[e].data,o=this._getVisbleRowRange(p,a,b,q,this.data[e].visibleRowRange);this.data[e].visibleRowRange=o;var r=this._calculateRowStep(o);if(l&&o)switch(q){case "line":if(f=="line"||f=="dot-line"){d.strokeStyle=i;d.lineWidth=n;d.beginPath();for(l=o.start;l<=o.end;){for(;l<=o.end&&p[l].value==null;)l+=r;if(l<=o.end)s=p[l].value,m=this.timeToScreen(p[l].date)-c,j=this.yToScreen(s),
d.moveTo(m,j),l+=r;for(;l<=o.end&&(s=p[l].value)!=null;)m=this.timeToScreen(p[l].date)-c,j=this.yToScreen(s),d.lineTo(m,j),l+=r}d.stroke()}if(q=="line"&&(f=="dot"||f=="dot-line")){n=2*k;d.fillStyle=i;for(l=o.start;l<=o.end;l+=r){var s=p[l].value;s!=null&&(m=this.timeToScreen(p[l].date)-c,j=this.yToScreen(s),d.fillRect(m-k,j-k,n,n))}}break;case "area":for(l=o.start;l<=o.end;l+=r)if(k=p[l],d.fillStyle=k.color||i,f=this.timeToScreen(k.start)-c,n=this.timeToScreen(k.end)-c,d.fillRect(f,0,n-f,h),k.text)d.font=
k.font||j,d.textAlign="left",d.textBaseline="top",d.fillStyle=k.textColor||m,d.fillText(k.text,f+2,0);break;case "event":for(l=o.start;l<=o.end;l+=r)if(k=p[l],d.fillStyle=k.color||i,q=k.width||n,f=this.timeToScreen(k.date)-c,d.fillRect(f-q/2,0,q,h),k.text)d.font=k.font||j,d.textAlign="left",d.textBaseline="top",d.fillStyle=k.textColor||m,d.fillText(k.text,f+q/2+2,0);break;default:throw Error('Unknown type of dataset "'+q+'". Choose "line" or "area"');}}};
links.Graph.prototype._calculateRowStep=function(a){return this.autoDataStep&&a?Math.max(Math.floor((a.end-a.start)/(this.frame.clientWidth+2*this.axisMargin)),1):1};
links.Graph.prototype._redrawDataTooltip=function(){var a=this.tooltip;if(this.showTooltip&&a){var b=a.dataPoint;if(b){var c=a.dot,d=a.label,e=parseFloat(this.frame.canvas.graph.style.left)+this.axisMargin,g=b.radius||4,h=b.color||"#4d4d4d",e=this.timeToScreen(b.date)+e,f=b.value!=void 0?this.yToScreen(b.value):16;if(!c)c=document.createElement("div"),c.className="graph-tooltip-dot",a.dot=c;c.style.borderColor!=h&&c.parentNode&&c.parentNode.removeChild(c);c.parentNode||this.frame.canvas.appendChild(c);
if(!d)d=document.createElement("div"),d.className="graph-tooltip-label",a.label=d;d.parentNode||this.frame.canvas.appendChild(d);c.style.left=e+"px";c.style.top=f+"px";c.style.borderColor=h;c.style.borderRadius=g+"px";c.style.borderWidth=g+"px";c.style.marginLeft=-g+"px";c.style.marginTop=-g+"px";c.style.display=b.title?"none":"";this.tooltipFormatter?a=this.tooltipFormatter(b):(a='<table style="color: '+h+'">',b.title?a+="<tr><td>"+b.title+"</td></tr>":(a+="<tr><td>Date:</td><td>"+b.date+"</td></tr>",
b.value!=void 0&&(a+="<tr><td>Value:</td><td>"+b.value.toPrecision(4)+"</td></tr>")),a+="</table>");d.innerHTML=a;b=d.clientWidth;a=this.timeToScreen(this.end)-this.timeToScreen(this.start);c=d.clientHeight;d.style.top=(f-c-10>0?f-c-g:f+g)+"px";d.style.left=(e+b+10<a?e+g:e-b-g)+"px"}else{if(a.dot&&a.dot.parentNode)a.dot.parentNode.removeChild(a.dot),a.dot=void 0;if(a.label&&a.label.parentNode)a.label.parentNode.removeChild(a.label),a.label=void 0}}};
links.Graph.prototype._setTooltip=function(a){if(!this.tooltip)this.tooltip={};this.tooltip.dataPoint=a;this._redrawDataTooltip()};
links.Graph.prototype._findClosestDataPoint=function(a,b){for(var c=void 0,d=0,e=this.data.length;d<e;d++){var g=this._getLineVisible(d),h=this.data[d].visibleRowRange,f=this.data[d].data,i=this.data[d].type;if(g&&h)for(var g=this._calculateRowStep(h),m=h.start;m<=h.end;){var j=f[m];i=="event"?j={date:j.date,value:this.screenToY(16),text:j.text,title:j.title}:i=="area"&&(j={date:j.start,value:this.screenToY(16),text:j.text,title:j.title});if(j.value!=null){var n=Math.abs(j.date-a)*this.ttsFactor;
if(n<30){var k=Math.abs(this.yToScreen(j.value)-this.yToScreen(b));if(k<30&&j.date>=this.start&&j.date<=this.end&&j.value>=this.vStart&&j.value<=this.vEnd&&(n=Math.sqrt(n*n+k*k),!c||n<c.distance))c=this._getLineColor(d),i=="event"||i=="area"?(k=this._getLineWidth(d),c=this._getTextColor(d)):k=this._getLineStyle(d)=="line"?this._getLineWidth(d)*2:this._getLineRadius(d)*2,k=Math.max(k,4),c={distance:n,dataPoint:{date:j.date,value:j.value,title:j.title,text:j.text,color:c,radius:k,line:d}}}else if(j.date>
a)m=h.end}m+=g}}return c?c.dataPoint:void 0};links.Graph.prototype._average=function(a,b,c){for(var d=0,e=0,g=0,h=0,f=b,b=Math.min(b+c,a.length);f<b;f++)c=a[f],c.date!=void 0&&(d+=c.date.valueOf(),e+=1),c.value!=void 0&&(g+=c.value,h+=1);return{date:new Date(Math.round(d/e)),value:g/h}};
links.Graph.prototype._redrawLegend=function(){for(var a=0,b=0,c=this.data.length;b<c;b++)this._getLineLegend(b)==!0&&a++;if(a==0||this.legend&&this.legend.visible===!1){if(this.main.legend)this.main.removeChild(this.main.legend),this.main.legend=void 0;this.legendWidth=0}else{a=0;if(this.main.legend)for(a=this.main.legend.scrollTop;this.main.legend.hasChildNodes();)this.main.legend.removeChild(this.main.legend.lastChild);else this.main.legend=document.createElement("DIV"),this.main.legend.className=
"graph-legend",this.main.legend.style.position="absolute",this.main.legend.style.overflowY="auto",this.main.appendChild(this.main.legend);for(var d=0,b=0,c=this.data.length;b<c;b++)if(this._getLineLegend(b)){var e=this._getLineColor(b),g=this.data[b].label,h=document.createElement("DIV");h.className="graph-legend-item";this.main.legend.appendChild(h);if(this.legend&&this.legend.toggleVisibility){var f=document.createElement("INPUT");f.type="checkbox";f.checked=this._getLineVisible(b);f.defaultChecked=
this._getLineVisible(b);f.style.marginRight=links.Graph.px(this.mainPadding);f.col=b;var i=this;f.onmousedown=function(){i._setLineVisible(this.col,!this.checked);i._checkSize();i.redraw()};h.appendChild(f)}f=document.createElement("SPAN");f.style.backgroundColor=e;f.innerHTML=" ";h.appendChild(f);e=document.createTextNode(" "+g);h.appendChild(e);d=Math.max(d,h.clientWidth)}this.main.legend.style.top=links.Graph.px(this.mainPadding);this.main.legend.style.height=
"auto";b=!1;if(this.main.legend.clientHeight>this.axisOffset-1)this.main.legend.style.height=links.Graph.px(this.axisOffset-1),b=!0;this.legend&&this.legend.width?this.main.legend.style.width=this.legend.width:b?(this.main.legend.style.width="auto",this.main.legend.style.width=links.Graph.px(this.main.legend.clientWidth+40)):(this.main.legend.style.width="auto",this.main.legend.style.width=links.Graph.px(this.main.legend.clientWidth+5));this.legendWidth=(this.main.legend.offsetWidth?this.main.legend.offsetWidth:
this.main.legend.clientWidth)+this.mainPadding;this.main.legend.style.left=links.Graph.px(this.main.clientWidth-this.legendWidth);if(a)this.main.legend.scrollTop=a}};
links.Graph.prototype._getVisbleRowRange=function(a,b,c,d,e){a||(a=[]);var g="date",h="date";d=="area"&&(g="start",h="end");var d=a.length,f={start:0,end:d-1};if(e!=null)f.start=e.start,f.end=e.end;if(f.start>d-1&&d>0)f.start=d-1;if(f.end>d-1)f.end=d-1;for(;f.start>0&&a[f.start][g].valueOf()>b.valueOf();)f.start--;for(;f.start<d-1&&a[f.start][g].valueOf()<b.valueOf();)f.start++;for(;f.end>f.start&&a[f.end][h].valueOf()>c.valueOf();)f.end--;for(;f.end<d-1&&a[f.end][h].valueOf()<c.valueOf();)f.end++;
return f};links.Graph.prototype._getRowRange=function(a,b){a||(a=[]);b||(b=["date"]);var c=void 0,d=void 0;if(a.length>0)for(var e=0;e<b.length;e++)for(var g=b[e],c=a[0][g].valueOf(),d=a[0][g].valueOf(),h=1,f=a.length;h<f;h++){var i=a[h][g];i!=void 0&&(c=Math.min(i.valueOf(),c),d=Math.max(i.valueOf(),d))}return c!=null&&!isNaN(c)&&d!=null&&!isNaN(d)?{min:new Date(c),max:new Date(d)}:null};
links.Graph.prototype._getDataRange=function(a){a||(a=[]);for(var b=null,c=0,d=a.length;c<d;c++){var e=a[c].value;if(e!=void 0)b?(b.min=Math.min(e,b.min),b.max=Math.max(e,b.max)):b={min:e,max:e}}return b&&b.min!=null&&!isNaN(b.min)&&b.max!=null&&!isNaN(b.max)?b:null};links.Graph.prototype._getLineStyle=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.style!=void 0?a.style.toLowerCase():this.line&&this.line.style!=void 0?this.line.style.toLowerCase():"line"};
links.Graph.prototype._getLineColor=function(a){if(this.lines&&a<this.lines.length){var b=this.lines[a];if(b&&b.color!=void 0)return b.color}return this.line&&this.line.color!=void 0?this.line.color:a<this.defaultColors.length?this.defaultColors[a]:"black"};links.Graph.prototype._getTextColor=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.textColor!=void 0?a.textColor:this.line&&this.line.textColor!=void 0?this.line.textColor:"#4D4D4D"};
links.Graph.prototype._getFont=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.font!=void 0?a.font:this.line&&this.line.font!=void 0?this.line.font:"13px arial"};links.Graph.prototype._getLineWidth=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.width!=void 0?parseFloat(a.width):this.line&&this.line.width!=void 0?parseFloat(this.line.width):2};
links.Graph.prototype._getLineRadius=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.radius!=void 0?parseFloat(a.radius):this.line&&this.line.radius!=void 0?parseFloat(this.line.radius):3};links.Graph.prototype._getLineLegend=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.legend!=void 0?a.legend:this.line&&this.line.legend!=void 0?this.line.legend:!0};
links.Graph.prototype._getLineVisible=function(a){return this.lines&&a<this.lines.length&&(a=this.lines[a])&&a.visible!=void 0?a.visible:this.line&&this.line.visible!=void 0?this.line.visible:!0};links.Graph.prototype._setLineVisible=function(a,b){a=parseInt(a);if(!(a<0)){if(!this.lines)this.lines=[];this.lines[a]||(this.lines[a]={});this.lines[a].visible=b}};
links.Graph.prototype._checkSize=function(){if(this.lastMainWidth!=this.main.clientWidth||this.lastMainHeight!=this.main.clientHeight){var a=this.main.clientWidth-this.lastMainWidth;this.end=new Date((this.frame.clientWidth+a)/this.frame.clientWidth*(this.end.valueOf()-this.start.valueOf())+this.start.valueOf());if(this.startEnd)this.startEnd=new Date((this.frame.clientWidth+a)/this.frame.clientWidth*(this.startEnd.valueOf()-this.start.valueOf())+this.start.valueOf());this.redraw()}};
links.Graph.prototype._onMouseDown=function(a){a=a||window.event;if(this.moveable){if(this.leftButtonDown)this.onMouseUp(a);if((this.leftButtonDown=a.which?a.which==1:a.button==1)||this.touchDown){this._checkSize();this.startMouseX=links.Graph._getPageX(a);this.startMouseY=links.Graph._getPageY(a);this.startStart=new Date(this.start.valueOf());this.startEnd=new Date(this.end.valueOf());this.startVStart=this.vStart;this.startVEnd=this.vEnd;this.startGraphLeft=parseFloat(this.frame.canvas.graph.style.left);
this.startAxisLeft=parseFloat(this.frame.canvas.axis.style.left);this.frame.style.cursor="move";var b=this;if(!this.onmousemove)this.onmousemove=function(a){b._onMouseMove(a)},links.Graph.addEventListener(document,"mousemove",this.onmousemove);if(!this.onmouseup)this.onmouseup=function(a){b._onMouseUp(a)},links.Graph.addEventListener(document,"mouseup",this.onmouseup);links.Graph.preventDefault(a)}}};
links.Graph.prototype._onMouseMove=function(a){var a=a||window.event,b=links.Graph._getPageX(a),c=links.Graph._getPageY(a);b-=this.startMouseX;var c=this.screenToY(this.startMouseY)-this.screenToY(c),d=-b/this.frame.clientWidth*(this.startEnd.valueOf()-this.startStart.valueOf()),e=new Date(this.startStart.valueOf()+Math.round(d)),g=new Date(this.startEnd.valueOf()+Math.round(d));this._applyRange(e,g);if(e=this.start.valueOf()-e.valueOf())d+=e,b=-d*this.frame.clientWidth/(this.startEnd.valueOf()-this.startStart.valueOf());
d=this.startVStart+c;c=this.startVEnd+c;d<this.vMin&&(e=this.vMin-d,d+=e,c+=e);c>this.vMax&&(e=c-this.vMax,d-=e,c-=e);e=(this.vEnd-this.vStart)/1E6;if(e=Math.abs(d-this.vStart)>e||Math.abs(c-this.vEnd)>e)this.vStart=d,this.vEnd=c;(!this.redrawWhileMoving||Math.abs(this.startAxisLeft+b)<this.axisMargin)&&!e?(this.frame.canvas.axis.style.left=links.Graph.px(this.startAxisLeft+b),this.frame.canvas.graph.style.left=links.Graph.px(this.startGraphLeft+b)):(this._redrawVerticalAxis(),this.frame.canvas.axis.style.left=
links.Graph.px(0),this.startAxisLeft=-b,this._redrawHorizontalAxis(),this.frame.canvas.graph.style.left=links.Graph.px(0),this.startGraphLeft=-b-this.axisMargin,this._redrawData());this._redrawAxisLeftMajorLabel();this._redrawDataTooltip();this.trigger("rangechange",{start:new Date(this.start.valueOf()),end:new Date(this.end.valueOf())});links.Graph.preventDefault(a)};
links.Graph.prototype._onMouseOut=function(a){var a=a||window.event,b=this;if(a.which>0&&a.type=="mouseout"){if(!this.onmouseupoutside)this.onmouseupoutside=function(a){b._onMouseOut(a)},links.Graph.addEventListener(document,"mouseup",this.onmouseupoutside)}else{if(a.type=="mouseup"&&this.onmouseupoutside)links.Graph.removeEventListener(document,"mouseup",this.onmouseupoutside),this.onmouseupoutside=void 0;links.Graph.isOutside(a,this.frame)&&this._setTooltip(void 0)}};
links.Graph.prototype._onMouseHover=function(a){a=a||window.event;if(!this.leftButtonDown){var b=links.Graph._getPageX(a),a=links.Graph._getPageY(a),c=links.Graph._getAbsoluteLeft(this.frame.canvas),d=links.Graph._getAbsoluteTop(this.frame.canvas),b=this._screenToTime(b-c),a=this.screenToY(a-d);this._setTooltip(this._findClosestDataPoint(b,a))}};
links.Graph.prototype._onMouseUp=function(a){this.frame.style.cursor="auto";this.leftButtonDown=!1;this.frame.canvas.axis.style.left=links.Graph.px(0);this._redrawHorizontalAxis();this.frame.canvas.graph.style.left=links.Graph.px(0);this._redrawData();this.trigger("rangechanged",{start:new Date(this.start.valueOf()),end:new Date(this.end.valueOf())});if(this.onmousemove)links.Graph.removeEventListener(document,"mousemove",this.onmousemove),this.onmousemove=void 0;if(this.onmouseup)links.Graph.removeEventListener(document,
"mouseup",this.onmouseup),this.onmouseup=void 0;links.Graph.preventDefault(a)};links.Graph.prototype._onTouchStart=function(a){links.Graph.preventDefault(a);if(!this.touchDown){this.touchDown=!0;var b=this;if(!this.ontouchmove)this.ontouchmove=function(a){b._onTouchMove(a)},links.Graph.addEventListener(document,"touchmove",this.ontouchmove);if(!this.ontouchend)this.ontouchend=function(a){b._onTouchEnd(a)},links.Graph.addEventListener(document,"touchend",this.ontouchend);this._onMouseDown(a)}};
links.Graph.prototype._onTouchMove=function(a){links.Graph.preventDefault(a);this._onMouseMove(a)};links.Graph.prototype._onTouchEnd=function(a){links.Graph.preventDefault(a);this.touchDown=!1;if(this.ontouchmove)links.Graph.removeEventListener(document,"touchmove",this.ontouchmove),this.ontouchmove=void 0;if(this.ontouchend)links.Graph.removeEventListener(document,"touchend",this.ontouchend),this.ontouchend=void 0;this._onMouseUp(a)};
links.Graph.prototype._onWheel=function(a){a=a||window.event;if(this.zoomable){var b=0;a.wheelDelta?b=a.wheelDelta/120:a.detail&&(b=-a.detail/3);if(b)if(this._checkSize(),b/=5,a.shiftKey){var c;c=links.Graph._getAbsoluteTop(this.frame);c=a.clientY!=void 0&&c!=void 0?this.screenToY(a.clientY-c):void 0;this._zoomVertical(b,c)}else c=links.Graph._getAbsoluteLeft(this.frame),c=a.clientX!=void 0&&c!=void 0?this._screenToTime(a.clientX-c):void 0,this._zoom(b,c),b={start:new Date(this.start.valueOf()),end:new Date(this.end.valueOf())},
this.trigger("rangechange",b),this.trigger("rangechanged",b);a.preventDefault&&a.preventDefault();a.returnValue=!1}};links.Graph._getAbsoluteLeft=function(a){for(var b=document.documentElement,c=document.body,d=a.offsetLeft,a=a.offsetParent;a!=null&&a!=c&&a!=b;)d+=a.offsetLeft,d-=a.scrollLeft,a=a.offsetParent;return d};
links.Graph._getAbsoluteTop=function(a){for(var b=document.documentElement,c=document.body,d=a.offsetTop,a=a.offsetParent;a!=null&&a!=c&&a!=b;)d+=a.offsetTop,d-=a.scrollTop,a=a.offsetParent;return d};links.Graph._getPageY=function(a){"targetTouches"in a&&a.targetTouches.length&&(a=a.targetTouches[0]);if("pageY"in a)return a.pageY;var b=document.documentElement,c=document.body;return a.clientY+(b&&b.scrollTop||c&&c.scrollTop||0)-(b&&b.clientTop||c&&c.clientTop||0)};
links.Graph._getPageX=function(a){"targetTouches"in a&&a.targetTouches.length&&(a=a.targetTouches[0]);if("pageX"in a)return a.pageX;var b=document.documentElement,c=document.body;return a.clientX+(b&&b.scrollLeft||c&&c.scrollLeft||0)-(b&&b.clientLeft||c&&c.clientLeft||0)};
links.Graph.prototype.setVisibleChartRange=function(a,b,c){var d,e,g;if(a!=null)a=new Date(a.valueOf());else{a=null;for(d=0,e=this.data.length;d<e;d++)if(g=this.data[d].rowRange)g=g.min,g!=void 0&&(a=a!=void 0?Math.min(a,g.valueOf()):g.valueOf());a=a!=void 0?new Date(a):new Date}if(b!=null)b=new Date(b.valueOf());else{b=null;for(d=0,e=this.data.length;d<e;d++)if(g=this.data[d].rowRange)g=g.max,g!=void 0&&(b=b!=void 0?Math.max(b,g.valueOf()):g);b!=void 0?b=new Date(b):(b=new Date,b.setDate(this.end.getDate()+
20))}b.valueOf()<=a.valueOf()&&(b=new Date(a.valueOf()),b.setDate(b.getDate()+20));this._applyRange(a,b);this._calcConversionFactor();c==void 0&&(c=!0);c&&this.redraw()};links.Graph.prototype.setVisibleChartRangeAuto=function(){this.setVisibleChartRange(void 0,void 0)};links.Graph.prototype.setVisibleChartRangeNow=function(){var a=this.end.valueOf()-this.start.valueOf(),b=new Date((new Date).valueOf()-a/2);this.setVisibleChartRange(b,new Date(b.valueOf()+a))};
links.Graph.prototype.getVisibleChartRange=function(){return{start:new Date(this.start.valueOf()),end:new Date(this.end.valueOf())}};links.Graph.prototype.getValueRange=function(){return{start:this.vStart,end:this.vEnd}};links.Graph.prototype.setValueRange=function(a,b,c){this.vStart=a?Number(a):void 0;this.vEnd=b?Number(b):void 0;if(this.vEnd<=this.vStart)this.vEnd=void 0;c==void 0&&(c=!0);c&&this.redraw()};links.Graph.prototype.setValueRangeAuto=function(){this.setValueRange(void 0,void 0)};
links.events=links.events||{listeners:[],indexOf:function(a){for(var b=this.listeners,c=0,d=this.listeners.length;c<d;c++){var e=b[c];if(e&&e.object==a)return c}return-1},addListener:function(a,b,c){var d=this.listeners[this.indexOf(a)];d||(d={object:a,events:{}},this.listeners.push(d));a=d.events[b];a||(a=[],d.events[b]=a);a.indexOf(c)==-1&&a.push(c)},removeListener:function(a,b,c){var a=this.indexOf(a),d=this.listeners[a];if(d){var e=d.events[b];e&&(a=e.indexOf(c),a!=-1&&e.splice(a,1),e.length==
0&&delete d.events[b]);c=0;d=d.events;for(b in d)d.hasOwnProperty(b)&&c++;c==0&&delete this.listeners[a]}},removeAllListeners:function(){this.listeners=[]},trigger:function(a,b,c){if(a=this.listeners[this.indexOf(a)])if(b=a.events[b])for(var a=0,d=b.length;a<d;a++)b[a](c)}};links.Graph.addEventListener=function(a,b,c,d){a.addEventListener?(d==void 0&&(d=!1),b=="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll"),a.addEventListener(b,c,d)):a.attachEvent("on"+b,c)};
links.Graph.removeEventListener=function(a,b,c,d){a.removeEventListener?(d==void 0&&(d=!1),b=="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll"),a.removeEventListener(b,c,d)):a.detachEvent("on"+b,c)};links.Graph.stopPropagation=function(a){if(!a)a=window.event;a.stopPropagation?a.stopPropagation():a.cancelBubble=!0};links.Graph.preventDefault=function(a){if(!a)a=window.event;a.preventDefault?a.preventDefault():a.returnValue=!1};
links.Graph.isOutside=function(a,b){for(var c=a.relatedTarget||a.toElement||a.fromElement;c&&c!==b;)c=c.parentNode;return c!==b};