var Graphics; if(!Graphics){ (function(){ SVG={}; SVG.ns="http://www.w3.org/2000/svg"; SVG.xlinkns="http://www.w3.org/1999/xlink"; function setX(x){ this.g.setAttribute("x",x); } function setY(y){ this.g.setAttribute("y",y); } function setWidth(x){ this.g.setAttribute("width",x); } function setHeight(x){ this.g.setAttribute("height",x); } function setPath(_5){ this.g.setAttribute("d",_5); } function setPoints(_6){ var _7=""; for(var i=0;i<_6.length;++i){ if(i>0){ _7+=" "; } _7+=_6[i][0]+","+_6[i][1]; } this.g.setAttribute("points",_6); } function setThickness(w){ if(w==0){ this.g.setAttribute("stroke","none"); }else{ this.g.setAttribute("stroke-width",w); } } function setColor(_a){ this.g.setAttribute("stroke",_a); } function setStrokeOpacity(_b){ this.g.setAttribute("stroke-opacity",_b); } function setFill(_c){ this.g.setAttribute("fill",_c); } function setFillOpacity(_d){ this.g.setAttribute("fill-opacity",_d); } function setAnchor(y){ this.g.setAttribute("text-anchor",y); } function setVisibility(_f){ this.g.style.display=_f?"inline":"none"; } function add(_10){ this.g.appendChild(_10.g); } function remove(_11){ this.g.removeChild(_11.g); } function setTransform(obj,x,y){ obj.setAttribute("transform","translate("+x+","+y+")"); } function mapDashStyle(num){ styleNum=num%5; switch(num){ case 0: str="1,0"; break; case 1: str="5,2"; break; case 2: str="5,2,1,2"; break; case 3: str="10,2"; break; case 4: str="10,2,1,2"; break; } return str; } Graphics=function(id,_17,_18){ if(typeof (id)=="string"){ this.e=document.getElementById(id); }else{ this.e=id; } if(_17<=0){ _17=-_17; if(this.e){ var _19=this.e.offsetWidth; if(!_19){ alert("Graphics: Element has zero width"); return; } if(_17>0&&_18<0){ _18=Math.ceil((_19/_17)*-_18); } _17=_19; } } this.g=document.createElementNS(SVG.ns,"svg:svg"); if(_17){ this.g.setAttribute("width",_17); } if(_18){ this.g.setAttribute("height",_18); } this.g.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink",SVG.xlinkns); if(this.e){ this.e.appendChild(this.g); } var w=this.g.width.baseVal; w.convertToSpecifiedUnits(w.SVG_LENGTHTYPE_PX); this.width=w.valueInSpecifiedUnits; var h=this.g.height.baseVal; h.convertToSpecifiedUnits(h.SVG_LENGTHTYPE_PX); this.height=h.valueInSpecifiedUnits; }; Graphics.prototype.add=add; Graphics.prototype.remove=remove; Graphics.prototype.del=function(){ this.e.removeChild(this.g); }; Graphics.Context=function(){ this.attr={}; }; Graphics.Context.prototype.set=function(_1c,_1d){ this.attr[_1c]=_1d; }; Graphics.Context.prototype.get=function(_1e){ return this.attr[_1e]; }; Graphics.Group=function(_1f){ this.g=document.createElementNS(SVG.ns,"g"); this.x=0; this.y=0; if(_1f){ var _20=""; for(var _21 in _1f.attr){ var _22=_1f.attr[_21]; var n; switch(_21){ case "color": _20+="stroke:"+_22+";"; break; case "thickness": if(_22==0){ _20+="stroke:none;"; }else{ _20+="stroke-width:"+_22+";"; } break; case "dash-style": _20+="stroke-dasharray:"+mapDashStyle(_22)+";"; break; case "fill": case "fill-opacity": case "stroke-opacity": case "font-family": case "font-size": case "font-weight": case "text-anchor": _20+=_21+":"+_22+";"; break; default: throw new Error("Attribute `"+_21+"' unknown"); } } this.g.setAttribute("style",_20); } }; Graphics.Group.prototype.add=add; Graphics.Group.prototype.remove=remove; Graphics.Group.prototype.setX=function(x){ this.x=x; setTransform(this.g,this.x,this.y); }; Graphics.Group.prototype.setY=function(y){ this.y=y; setTransform(this.g,this.x,this.y); }; Graphics.Group.prototype.setVisibility=setVisibility; Graphics.PolyLine=function(){ this.g=document.createElementNS(SVG.ns,"polyline"); }; Graphics.PolyLine.prototype.setPoints=setPoints; Graphics.PolyLine.prototype.setThickness=setThickness; Graphics.PolyLine.prototype.setColor=setColor; Graphics.PolyLine.prototype.setFill=setFill; Graphics.Rectangle=function(){ this.g=document.createElementNS(SVG.ns,"rect"); }; Graphics.Rectangle.prototype.setX=setX; Graphics.Rectangle.prototype.setY=setY; Graphics.Rectangle.prototype.setWidth=setWidth; Graphics.Rectangle.prototype.setHeight=setHeight; Graphics.Rectangle.prototype.setFill=setFill; Graphics.Rectangle.prototype.setFillOpacity=setFillOpacity; Graphics.Rectangle.prototype.setStrokeOpacity=setStrokeOpacity; Graphics.Rectangle.prototype.setColor=setColor; Graphics.Path=function(){ this.g=document.createElementNS(SVG.ns,"path"); }; Graphics.Path.prototype.setPath=setPath; Graphics.Path.prototype.setFill=setFill; Graphics.Path.prototype.setFillOpacity=setFillOpacity; Graphics.Path.prototype.setColor=setColor; Graphics.Path.prototype.setStrokeOpacity=setStrokeOpacity; Graphics.Path.prototype.setThickness=setThickness; Graphics.Path.prototype.setVisibility=setVisibility; Graphics.Path.prototype.setDashStyle=function(_26){ this.g.setAttribute("stroke-dasharray",mapDashStyle(_26)); }; Graphics.Text=function(){ this.g=document.createElementNS(SVG.ns,"text"); this.g.setAttribute("stroke","none"); }; Graphics.Text.prototype.setFontSize=function(_27){ this.g.style.fontSize=_27; }; Graphics.Text.prototype.setX=setX; Graphics.Text.prototype.setY=setY; Graphics.Text.prototype.setAnchor=setAnchor; Graphics.Text.prototype.setColor=function(_28){ this.g.setAttribute("fill",_28); }; Graphics.Text.prototype.setText=function(_29){ var _2a=document.createTextNode(_29); if(this.g.firstChild){ this.g.replaceChild(_2a,this.g.firstChild); }else{ this.g.appendChild(_2a); } }; Graphics.Text.prototype.setStyle=function(_2b){ this.g.setAttribute("font-style",_2b); }; })(); } (function () { TIMER_INTERVAL = 1000; Timer = {}; var list = []; var nextTick; function tick () { for (var i = 0; i < list.length; ++i) { var t = list[i]; t.ticks += TIMER_INTERVAL; if (t.ticks >= t.interval) { t.ticks = 0; t.callback (t.arg); } } var now = new Date ().getTime (); if (!nextTick) nextTick = now + TIMER_INTERVAL; else nextTick += TIMER_INTERVAL; // if we missed a tick already, find the next tick in the future: if (nextTick < now) { nextTick += (Math.ceil ((now - nextTick) / TIMER_INTERVAL) * TIMER_INTERVAL); while (nextTick <= now) nextTick += TIMER_INTERVAL; } var sleepTime = nextTick - now; window.setTimeout (tick, sleepTime); } Timer.add = function (interval, func, argument) { var t = {}; t.ticks = 0; t.interval = interval; t.callback = func; t.arg = argument; list[list.length] = t; if (!nextTick) tick(); } })(); EG_TOTAL=0; EG_SOLAR=1; EG_OTHER=2; EG_X=0; EG_Y=1; EG_LINEAR=0; EG_LOGARITHMIC=1; EG_NON_RENEWABLE_PATTERN=/^(grid|subpanel)/i; (function(){ MIXED=EG_SOLAR+1; TOT=EG_TOTAL; SOL=EG_SOLAR; X=EG_X; Y=EG_Y; DIR={}; DIR[X]=1; DIR[Y]=-1; TICK_LINE_COLOR="#e0e0e0"; TICK_LINE_THICKNESS=1; TICK_MARK_COLOR="#00f"; MAJ_TICK_LENGTH=5; MAJ_TICK_THICKNESS=2; MIN_TICK_LENGTH=3; MIN_TICK_THICKNESS=1; SUP_LABEL_SHADE_COLOR=[]; SUP_LABEL_SHADE_COLOR[0]="#e0e0f0"; SUP_LABEL_SHADE_COLOR[1]="#f0f0f8"; SUP_LABEL_OFFSET=4; function resizeArray(a,_2,_3,_4){ if(_2==a.length){ return a; } if(_20){ _14+=" "; } _14+=("M"+t0s[X]+" "+t0s[Y]+"L"+t0e[X]+" "+t0e[Y]+"M"+t1s[X]+" "+t1s[Y]+"L"+t1e[X]+" "+t1e[Y]); if(_c){ _15+=("M"+t0e[X]+" "+t0e[Y]+"L"+t1e[X]+" "+t1e[Y]); } } _9.g.majTicks[t].setPath(_14); if(_c){ _9.g.majTickLines[t].setPath(_15); } var _14=""; for(var i=0;i0){ _14+=" "; } _14+=("M"+t0s[X]+" "+t0s[Y]+"L"+t0e[X]+" "+t0e[Y]+"M"+t1s[X]+" "+t1s[Y]+"L"+t1e[X]+" "+t1e[Y]); } _9.g.minTicks[t].setPath(_14); } function renderCurves(obj,s,_19,_1a){ if(!obj.g.curve){ obj.g.curve=[]; obj.g.shade=[]; for(var i=0;is.t.max){ continue; } } p=EMapper.map.power(_1a[i]); if(p[SOL]<0){ p[SOL]=0; } x=(ts-s.t.min)*_1f; for(var j=TOT;j<=SOL;++j){ y[j]=obj.pixels[Y]-(p[j]-s.p.min)*_20; } if(i>0){ var _2b=(p[SOL]>p[TOT]); var _2c=(p1[SOL]>p1[TOT]); var xR=Math.round(x); var x1R=Math.round(x1); yR[TOT]=Math.round(y[TOT]); yR[SOL]=Math.round(y[SOL]); y1R[TOT]=Math.round(y1[TOT]); y1R[SOL]=Math.round(y1[SOL]); if(x1R-xR>5){ for(var j=TOT;j<=SOL;++j){ if(i==1){ _27[j]+="M"+x1R+" "+y1R[j]; } _27[j]+=("L"+xR+" "+y1R[j]+"L"+xR+" "+yR[j]); } if(_2c){ _28[SOL]+=("M"+xR+" "+y1R[TOT]+"L"+xR+" "+y1R[SOL]+"L"+x1R+" "+y1R[SOL]+"L"+x1R+" "+y1R[TOT]+"Z"); }else{ _28[TOT]+=("M"+xR+" "+y1R[SOL]+"L"+xR+" "+y1R[TOT]+"L"+x1R+" "+y1R[TOT]+"L"+x1R+" "+y1R[SOL]+"Z"); } }else{ for(var j=TOT;j<=SOL;++j){ if(i==1){ _27[j]+="M"+x1R+" "+y1R[j]; } _27[j]+="L"+xR+" "+yR[j]; } var _2f=MIXED; if(_2b&&_2c){ _2f=SOL; }else{ if(_2b&&!_2c){ left=SOL; right=TOT; }else{ if(!_2b&&_2c){ left=TOT; right=SOL; }else{ _2f=TOT; } } } if(_2f==MIXED){ var yD=y[TOT]-y[SOL]; var yD1=y1[TOT]-y1[SOL]; var xc=x+yD*(x1-x)/(yD-yD1); var yc=y[SOL]+yD*(y1[SOL]-y[SOL])/(yD-yD1); var xcR=Math.round(xc); var ycR=Math.round(yc); _28[left]+=("M"+xR+" "+yR[SOL]+"L"+xcR+" "+ycR+"L"+xR+" "+yR[TOT]); _28[right]+=("M"+x1R+" "+y1R[TOT]+"L"+xcR+" "+ycR+"L"+x1R+" "+y1R[SOL]); }else{ _28[_2f]+=("M"+xR+" "+yR[TOT]+"L"+x1R+" "+y1R[TOT]+"L"+x1R+" "+y1R[SOL]+"L"+xR+" "+yR[SOL]); } } } x1=x; for(var j=TOT;j<=SOL;++j){ p1[j]=p[j]; y1[j]=y[j]; } } for(var j=TOT;j<=SOL;++j){ obj.g.curve[j].setPath(_27[j]); obj.g.shade[j].setPath(_28[j]); } } function renderCompCurves(obj,s,_38,_39){ if(!obj.g.compLine){ obj.g.compLine={}; } if(!obj.compUseCtx){ return; } var _3a={}; var _3b={}; var _3c=obj.pixels[X]/(s.t.max-s.t.min); var _3d=obj.pixels[Y]/(s.p.max-s.p.min); var x,xR; var x1,x1R; var y1; var p1; var y0=obj.pixels[Y]+s.p.min*_3d; var y0R=Math.round(y0); for(var i=0;i<_39.length;++i){ var p={}; var y={}; var ts=_38[i]; if(tss.t.max){ continue; } } x=(ts-s.t.min)*_3c; xR=Math.round(x); for(src in _39[i]){ if(EG_NON_RENEWABLE_PATTERN.exec(src)){ continue; } if(!obj.g.compLine[src]){ obj.g.compLine[src]=[]; var idx=obj.compId[src]; if(!idx){ continue; } idx%=obj.compUseCtx.length; var g=new Graphics.Group(obj.compUseCtx[idx]); var l=new Graphics.Path(); l.setVisibility(false); g.add(l); obj.g.topGroup.add(g); obj.g.compLine[src][TOT]=l; var g=new Graphics.Group(obj.compGenCtx[idx]); var l=new Graphics.Path(); l.setVisibility(false); g.add(l); obj.g.topGroup.add(g); obj.g.compLine[src][SOL]=l; } p[src]=_39[i][src]; var pos=(p[src]>=0); var _4f=(pos?p[src]:-p[src]); y[src]=obj.pixels[Y]-(_4f-s.p.min)*_3d; if(i>0){ var _50=(p1[src]>=0); var _51=(_50?_3b:_3a)[src]; var _52=(_50?_3a:_3b)[src]; var yR=Math.round(y[src]); var y1R=Math.round(y1[src]); if(!_51){ _51=""; } if(!_52){ _52=""; } if(_51==""||pos!=_50){ _51+="M"+x1R+" "+y1R; } if(x1R-xR>5){ if(pos==_50){ _51+=("L"+xR+" "+y1R+"L"+xR+" "+yR); }else{ _51+=("L"+xR+" "+y1R+"L"+xR+" "+y0R); _52+=("M"+xR+" "+y0R+"L"+xR+" "+yR); } }else{ if(pos==_50){ _51+="L"+xR+" "+yR; }else{ var xc=x+(x1-x)*(y0-y[src])/(2*y0-y[src]-y1[src]); var xcR=Math.round(xc); _51+="L"+xcR+" "+y0R; _52+=("M"+xcR+" "+y0R+"L"+xR+" "+yR); } } (_50?_3b:_3a)[src]=_51; (_50?_3a:_3b)[src]=_52; } } x1=x; x1R=Math.round(x1); p1=p; y1=y; } for(var src in _3a){ obj.g.compLine[src][TOT].setPath(_3a[src]); } for(var src in _3b){ obj.g.compLine[src][SOL].setPath(_3b[src]); } } function renderBars(obj,s,_59){ if(!obj.g.label){ obj.g.rectGroup=[]; obj.g.group=[]; obj.g.label=[]; obj.g.line=[]; obj.g.rect=[]; for(var i=0;ip[SOL]){ t=TOT; }else{ t=SOL; } o=1-t; for(var i=TOT;i<=SOL;++i){ y[i]=obj.origin[Y]-_64*(p[i]-s.min); l[i].setPath("M0 "+Math.round(y[i])+"L"+w+" "+Math.round(y[i])); str=Math.round(p[i])+" W"; _61[i].setText(str); var _65=str.length*obj.fontPixels[X]; if(EG_BROKEN_TEXT_ANCHOR){ _61[i].setX(Math.round((w-_65)/2)); }else{ _61[i].setX(Math.round(w-1.8*MAJ_TICK_LENGTH)); } } r[t].setX(0); r[t].setY(Math.round(y[t])); r[t].setWidth(w); r[t].setHeight(Math.round(y[o]-y[t])); r[o].setHeight(0); _61[t].setY(Math.round(y[t]-obj.fontPixels[Y])); if(obj.origin[Y]-y[o]>=2.6*obj.fontPixels[Y]){ _61[o].setY(Math.round(y[o]+2.2*obj.fontPixels[Y])); }else{ if(y[o]-y[t]>=3*obj.fontPixels[Y]){ _61[o].setY(Math.round(y[o]-obj.fontPixels[Y])); }else{ _61[o].setText(""); } } } function renderCompBars(obj,s,_68){ if(!obj.g.compLine){ obj.g.compLine={}; } if(!obj.compUseCtx){ return; } var w=obj.pixels[X]; var p=[]; p[TOT]=0; p[SOL]=0; for(var src in _68){ if(EG_NON_RENEWABLE_PATTERN.exec(src)){ continue; } if(!obj.g.compLine[src]){ obj.g.compLine[src]=[]; var i=obj.compId[src]; if(!i){ continue; } i%=obj.compUseCtx.length; var g=new Graphics.Group(obj.compUseCtx[i]); var l=new Graphics.Path(); l.setVisibility(false); g.add(l); obj.g.topGroup.add(g); obj.g.compLine[src][TOT]=l; var g=new Graphics.Group(obj.compGenCtx[i]); var l=new Graphics.Path(); l.setVisibility(false); g.add(l); obj.g.topGroup.add(g); obj.g.compLine[src][SOL]=l; } var pc=_68[src]; if(pc<0){ pc=-pc; l=obj.g.compLine[src][TOT]; o=obj.g.compLine[src][SOL]; }else{ pc=+pc; l=obj.g.compLine[src][SOL]; o=obj.g.compLine[src][TOT]; } var y=(obj.origin[Y]-(pc-s.min)/(s.max-s.min)*obj.pixels[Y]); l.setPath("M0 "+Math.round(y)+"L"+w+" "+Math.round(y)); o.setPath("M0 0"); } } EGraph=function(_71,_72,_73,_74,_75){ this.g={}; this.origin=[]; this.origin[X]=0; this.origin[Y]=_73; this.pixels=[]; this.pixels[X]=_72; this.pixels[Y]=_73; this.g.topGroup=_71; this.curveCtx=_74; this.shadeCtx=_75; this.compId=null; this.compUseCtx=null; this.compGenCtx=null; }; EGraph.prototype.draw=function(s,_77,_78){ if(this.g.loading){ this.g.loading.setText(""); } renderTicks(this,Y,s.p,true); renderTicks(this,X,s.t,true); renderCurves(this,s,_77,_78); renderCompCurves(this,s,_77,_78); renderAxes(this); }; EGraph.prototype.setLoading=function(s){ this.draw(s,[],[]); if(!this.g.loading){ var t=new Graphics.Text(); t.setColor("blue"); t.setStyle("italic"); t.setX(this.pixels[X]/2); t.setY(this.pixels[Y]/2); this.g.loading=t; this.g.topGroup.add(this.g.loading); } this.g.loading.setText("Loading..."); if(!this.g.curve){ return; } for(j=TOT;j<=SOL;++j){ this.g.shade[j].setPath("M0 0"); this.g.curve[j].setPath("M0 0"); } for(src in this.g.compLine){ var g=this.g.compLine[src]; g[TOT].setPath("M0 0"); g[SOL].setPath("M0 0"); } }; EGraph.prototype.setCompMapAndCtx=function(_7c,_7d,_7e){ this.compId=_7c; this.compUseCtx=_7d; this.compGenCtx=_7e; }; EGraph.prototype.setVisibility=function(_7f,_80){ var g; switch(_7f){ case ".power": g=this.g.curve; break; case ".energy": g=this.g.shade; break; default: g=this.g.compLine[_7f]; break; } if(g){ g[TOT].setVisibility(_80); g[SOL].setVisibility(_80); } }; EBar=function(_82,_83,_84,_85,_86,_87,_88){ this.g={}; this.origin=[]; this.origin[X]=0; this.origin[Y]=_84; this.pixels=[]; this.pixels[X]=_83; this.pixels[Y]=_84; this.fontPixels=[]; this.fontPixels[X]=_85; this.fontPixels[Y]=_86; this.g.topGroup=_82; this.curveCtx=_87; this.shadeCtx=_88; this.compId=null; this.compUseCtx=null; this.compGenCtx=null; }; EBar.prototype.draw=function(_89,_8a){ renderTicks(this,Y,_89,true); renderBars(this,_89,_8a); renderCompBars(this,_89,_8a); renderAxes(this); }; EBar.prototype.setLabel=function(_8b,ctx){ if(!this.g.xAxislabel){ var g=new Graphics.Group(ctx); this.g.xAxisLabel=new Graphics.Text(); g.add(this.g.xAxisLabel); this.g.topGroup.add(g); } var txt=this.g.xAxisLabel; txt.setText(_8b); txt.setX(5); txt.setY(this.origin[Y]+2.5*this.fontPixels[Y]); }; EBar.prototype.setCompMapAndCtx=function(_8f,_90,_91){ this.compId=_8f; this.compUseCtx=_90; this.compGenCtx=_91; }; EBar.prototype.setVisibility=function(_92,_93){ var g; switch(_92){ case ".power": g=this.g.group; break; case ".energy": g=this.g.rectGroup; break; default: g=this.g.compLine[_92]; break; } if(g){ g[TOT].setVisibility(_93); g[SOL].setVisibility(_93); } }; ELabel=function(_95,_96,_97,_98,_99,_9a,_9b){ this.g={}; this.axis=_96; this.align=_97; this.origin=[]; this.origin[X]=0; this.origin[Y]=_99; this.pixels=[]; this.pixels[X]=_98; this.pixels[Y]=_99; this.fontPixels=[]; this.fontPixels[X]=_9a; this.fontPixels[Y]=_9b; this.g.topGroup=_95; this.g.labels=[]; this.g.supLabels=[]; }; ELabel.prototype.draw=function(_9c){ var obj=this; var s=_9c; var t=this.axis; var o=1-t; var _a1=DIR[t]*this.pixels[t]/(s.max-s.min); var sup=s.ticks.sup; var maj=s.ticks.major; if(sup){ if(!this.g.box){ this.g.box=[]; for(var i=0;i<2;++i){ var l=new Graphics.Path; l.setThickness(1); l.setFill(SUP_LABEL_SHADE_COLOR[i]); this.g.topGroup.add(l); this.g.box[i]=l; } } this.g.supLabels=resizeArray(this.g.supLabels,sup.length,function(o){ obj.g.topGroup.remove(o); },function(){ var l=new Graphics.Text(); l.setAnchor("start"); obj.g.topGroup.add(l); return l; }); var pS=[]; var pE=[]; var _aa=true; var _ab=[]; _ab[0]=""; _ab[1]=""; var p=this.origin[o]+DIR[o]*this.pixels[o]; pS[o]=Math.round(p); pE[o]=Math.round(p+DIR[t]*16); pE[t]=Math.round(this.origin[t]+DIR[t]*this.pixels[t]); for(var i=0;i=60&&isMultiple(_2,60)){ if(_1.getMinutes()>0){ return false; } return isStartOfHourMultiple(_1,_2/60); } return isMultiple(_1.getMinutes(),_2); } function isStartOfHourMultiple(_3,_4){ var _5=new Date(_3); _5.setDate(0); var dy=_3.getDate()+_5.getDay(); return isMultiple(24*dy+_3.getHours(),_4); } function isStartOfMonthMultiple(_7,_8){ return isMultiple(_7.getMonth(),_8); } function isStartOfYearMultiple(_9,_a){ return isMultiple(_9.getFullYear(),_a); } function isStartOfHour(_b){ return _b.getMinutes()==0; } function isStartOfDay(_c){ if(_c.getHours()>0){ return false; } return isStartOfHour(_c); } function isStartOfMonth(_d){ if(_d.getDate()>1){ return false; } return isStartOfDay(_d); } function isStartOfYear(_e){ if(_e.getMonth()>0){ return false; } return isStartOfMonth(_e); } function isStartOfDecade(_f){ if(!isMultiple(_f.getFullYear(),10)){ return false; } return isStartOfYear(_f); } function formatDt(_10){ return formatDate(_10,"E NNN d"); } function formatDayOfMonth(_11){ return _11.getDate(); } function formatWeekday(_12){ var hr=_12.getHours(); if(hr!=0){ return formatTime(_12); }else{ return formatDate(_12,"d (E)"); } } function formatMonth(_14){ return formatDate(_14,"NNN"); } function formatMonthAndYear(_15){ return formatDate(_15,"NNN yyyy"); } function formatYear(_16){ return formatDate(_16,"yyyy"); } function formatYearOfDecade(_17){ var yr=_17.getFullYear(); var y=yr%10; var dec=Math.floor(yr/10)%10; return "'"+dec+y; } function formatDecade(_1b){ var yr=_1b.getFullYear(); return roundDown(yr,10).toFixed(0); } function formatTime(_1d){ var hr=_1d.getHours(); var mn=_1d.getMinutes(); var _20="am"; if(hr==0){ hr=12; }else{ if(hr>=12){ if(hr>12){ hr-=12; } _20="pm"; } } var l=hr; if(mn!=0){ l+=":"+((mn>9)?"":"0")+mn.toFixed(0); } return l+_20; } function alignTimeToYearMultiple(ts,_23){ var _24=new Date(1000*ts); var yr=roundDown(_24.getFullYear(),_23); _24.setFullYear(yr); _24.setMonth(0); _24.setDate(1); _24.setHours(0,0,0,0); return _24.getTime()/1000; } function alignTimeToMonthMultiple(ts,_27){ var _28=new Date(1000*ts); var mn=roundDown(_28.getMonth(),_27); _28.setMonth(mn); _28.setDate(1); _28.setHours(0,0,0,0); return _28.getTime()/1000; } function alignTimeToDayMultiple(ts,_2b){ var _2c=new Date(1000*ts); var dy=roundDown(_2c.getDate(),_2b); _2c.setDate(dy); _2c.setHours(0,0,0,0); return _2c.getTime()/1000; } function alignTimeToHourMultiple(ts,_2f){ var _30=new Date(1000*ts); var _31=_30.getHours(); var _32=roundDown(_31,_2f); ts-=(_31-_32)*3600; var _33,_34; while(1){ _30=new Date(1000*ts); _33=_30.getMinutes(); _34=_30.getSeconds(); if(_33==0&&_34==0){ break; } ts-=60*_33+_34; } return ts; } function alignTimeToMinuteMultiple(ts,_36){ if(_36>=60&&isMultiple(_36,60)){ return alignTimeToHourMultiple(ts,_36/60); } return roundDown(ts,_36*60); } var t=0; TIME_TICK=[]; TIME_TICK[t]={}; TIME_TICK[t].span=10*365*EM_SECS_PER_DY; TIME_TICK[t].supLabel=formatDecade; TIME_TICK[t].isSup=isStartOfDecade; TIME_TICK[t].isMaj=isStartOfYearMultiple; TIME_TICK[t].majLabel=formatYearOfDecade; TIME_TICK[t].majMaxLabelLen=3; TIME_TICK[t].majMult=[1,2,5,10,20]; TIME_TICK[t].minMult=[1,2,5,10]; TIME_TICK[t].alignTime=alignTimeToYearMultiple; TIME_TICK[t].multGran=365*EM_SECS_PER_DY; ++t; TIME_TICK[t]={}; TIME_TICK[t].span=365*EM_SECS_PER_DY; TIME_TICK[t].supLabel=formatYear; TIME_TICK[t].isSup=isStartOfYear; TIME_TICK[t].isMaj=isStartOfMonthMultiple; TIME_TICK[t].majLabel=formatMonth; TIME_TICK[t].majMaxLabelLen=3; TIME_TICK[t].majMult=[1,2,4,12,24,48]; TIME_TICK[t].minMult=[1,2,4]; TIME_TICK[t].alignTime=alignTimeToMonthMultiple; TIME_TICK[t].multGran=30*EM_SECS_PER_DY; ++t; TIME_TICK[t]={}; TIME_TICK[t].span=30*EM_SECS_PER_DY; TIME_TICK[t].supLabel=formatMonthAndYear; TIME_TICK[t].isSup=isStartOfMonth; TIME_TICK[t].isMaj=isStartOfHourMultiple; TIME_TICK[t].majLabel=formatDayOfMonth; TIME_TICK[t].majMaxLabelLen=2; TIME_TICK[t].majMult=[24,2*24,7*24,14*24]; TIME_TICK[t].minMult=[8,12,24]; TIME_TICK[t].alignTime=alignTimeToHourMultiple; TIME_TICK[t].multGran=EM_SECS_PER_HR; ++t; TIME_TICK[t]={}; TIME_TICK[t].span=7*EM_SECS_PER_DY; TIME_TICK[t].supLabel=formatMonthAndYear; TIME_TICK[t].isSup=isStartOfMonth; TIME_TICK[t].isMaj=isStartOfHourMultiple; TIME_TICK[t].majLabel=formatWeekday; TIME_TICK[t].majMaxLabelLen=8; TIME_TICK[t].majMult=[12,24,2*24,7*24,14*24]; TIME_TICK[t].minMult=[1,2,6,12]; TIME_TICK[t].alignTime=alignTimeToHourMultiple; TIME_TICK[t].multGran=EM_SECS_PER_HR; ++t; TIME_TICK[t]={}; TIME_TICK[t].span=EM_SECS_PER_HR; TIME_TICK[t].supLabel=formatDt; TIME_TICK[t].isSup=isStartOfDay; TIME_TICK[t].isMaj=isStartOfMinuteMultiple; TIME_TICK[t].majLabel=formatTime; TIME_TICK[t].majMaxLabelLen=7; TIME_TICK[t].majMult=[5,15,30,60,3*60,6*60,12*60]; TIME_TICK[t].minMult=[1,5,15,30,60,120]; TIME_TICK[t].alignTime=alignTimeToMinuteMultiple; TIME_TICK[t].multGran=EM_SECS_PER_MN; var _38=0; var _39=[]; function roundDown(x,y){ return Math.floor(x/y)*y; } function isMultiple(x,y){ return ((x/y)-Math.floor(x/y))==0; } function updateSources(obj,_3f){ var _40=false; for(var i=0;i<_3f.length;++i){ var src=_3f[i]; if(!obj.sourceId[src]){ var idx=obj.sourceName.length; obj.sourceId[src]=idx; obj.sourceName[idx]=src; _40=true; } } var c=obj.callback["sourcesChanged"]; if(_40&&c){ c.func(_3f,c.arg); } } function processInstResponse(obj,xml){ if(!xml){ return; } var _47=[]; var E={}; var P={}; var ts=xml.getElementsByTagName("timestamp"); if(ts.length!=1){ return; } var _4b=parseInt(HTTP.getText(ts[0])); var _4c=xml.getElementsByTagName("meter"); for(i=0;i<_4c.length;++i){ var _4d=_4c[i].getAttribute("title"); var _4e=_4c[i].getElementsByTagName("energyWs"); if(_4e.length!=1){ alert("processInstResponse: not exactly one energy!"); continue; } E[_4d]=new Int64(HTTP.getText(_4e[0])); _47[i]=_4d; } updateSources(obj,_47); var _4f=obj.instLastTimeStamp; var _50=obj.instLastEnergy; obj.instLastTimeStamp=_4b; obj.instLastEnergy=E; if(_4f&&_4b>_4f){ var _51=_4b-_4f; for(var src in E){ var t=new Int64(E[src]); t.sub(_50[src]); t.div(_51); P[src]=t.get54bitValue(); } }else{ return; } obj.instPower=P; var c=obj.callback["currentChanged"]; if(c){ c.func(_4b,obj.instLastEnergy,obj.instPower,c.arg); } var p=EMapper.map.power(obj.instPower); var s=obj.mainScale.p; var max=p[EG_TOTAL]; if(p[EG_SOLAR]>max){ max=p[EG_SOLAR]; } if(s.userMax<=0&&max>s.max){ s.max=1.07*max; setPowerTicks(s,obj.mainHeight); obj.mainGraph.draw(obj.mainScale,obj.time,obj.power); obj.mainPowerLabels.draw(s); } obj.instBar.draw(obj.mainScale.p,obj.instPower); } function updateMain(obj){ autoScale(obj,obj.mainTimespan,obj.mainScale,obj.mainWidth); setTicks(obj.mainScale,obj.time,obj.mainWidth,obj.mainHeight); obj.mainGraph.draw(obj.mainScale,obj.time,obj.power); obj.mainTimeLabels.draw(obj.mainScale.t); obj.mainPowerLabels.draw(obj.mainScale.p); var c=obj.callback["timeRangeChanged"]; if(c){ var _5a,end=0; var s=obj.mainScale.t; for(var _5a=0;_5a0){ for(var i=obj.time.length-1;i>=0;--i){ obj.time[i+_63]=obj.time[i]; } for(var i=obj.power.length-1;i>=0;--i){ obj.power[i+_63]=obj.power[i]; } for(var i=obj.energy.length-1;i>=0;--i){ obj.energy[i+_63]=obj.energy[i]; } } for(var k=0;k<_5f.length;++k){ var _6d=parseInt(_5f[k].getAttribute("time_stamp")); var _6e=parseInt(_5f[k].getAttribute("time_delta")); var row=_5f[k].getElementsByTagName("r"); if(row.length<1){ return; } for(var i=0;i=obj.energy.length){ break; } var _72=obj.time[i]-obj.time[i+1]; obj.power[i]={}; for(var j=0;j<_60;++j){ var t=new Int64(obj.energy[i][src[j]]); t.sub(obj.energy[i+1][src[j]]); t.div(_72); obj.power[i][src[j]]=t.get54bitValue(); } } updateMain(obj); } function processEnergyResponse(arg,xml){ if(!xml){ return; } var obj=arg.obj; var _77=arg.callback; var _78=xml.getElementsByTagName("data"); if(_78.length!=1){ alert("processEnergyResponse: XML response contained "+_78.length+" instead of exactly 1 element!"); return; } var _79=_78[0].getAttribute("columns"); var _7a=parseInt(_78[0].getAttribute("time_stamp")); var _7b=_78[0].getAttribute("epoch"); var _7c=_78[0].getElementsByTagName("cname"); var row=_78[0].getElementsByTagName("r"); if(row.length!=1){ return; } if(_7b){ obj.epoch=_7b; } var src=[]; for(i=0;i<_7c.length;++i){ src[i]=HTTP.getText(_7c[i]); } updateSources(obj,src); var E={}; var col=row[0].getElementsByTagName("c"); for(var j=0;j<_79;++j){ E[src[j]]=new Int64(HTTP.getText(col[j])); } if(_77){ _77(_7a,E); } } function fetchInstPower(obj){ obj.instReq.send("GET",obj.egaugeURL,processInstResponse,obj); } function fetchMainEnergies(obj){ if(obj.waitTime){ var now=new Date(); if(now.getTime()0){ url+="&w="+obj.time[0]; } if(obj.mainEndTime){ url+="&f="+obj.mainEndTime; } obj.mainReq.send("GET",url,processMainResponse,obj); } function fetchEnergies(obj,ts,_88){ var url=(obj.showURL+"m&n=1"+"&f="+ts); var arg={}; arg.obj=obj; arg.callback=_88; obj.currReq.send("GET",url,processEnergyResponse,arg); } function setTimeTicks(s,_8c,_8d){ s.ticks.sup=[]; s.ticks.supLabel=[]; s.ticks.major=[]; s.ticks.majorLabel=[]; s.ticks.minor=[]; if(_8c.length<1){ return; } var _8e=0; var _8f=0; var _90=0; var _91=s.max-s.min; for(var i=0;i=TIME_TICK[i].span){ break; } } if(i>=TIME_TICK.length){ i=TIME_TICK.length-1; } var tt=TIME_TICK[i]; var w=1.2*tt.majMaxLabelLen*LABEL_FONT_WIDTH+MAJ_TICK_MIN_DIST; for(var i=0;i=w){ break; } } for(var i=0;i=MIN_TICK_MIN_DIST){ break; } } var _9b=_8c[0]-(s.max-s.min); var _9c=new Date(0); for(var ts=_8c[0];ts>=_9b;--ts){ ts=tt.alignTime(ts,_98); _9c.setTime(1000*ts); if(ts<_9b){ break; } if(tt.isSup(_9c)){ s.ticks.supLabel[_8e]=tt.supLabel(_9c); s.ticks.sup[_8e++]=ts; } if(tt.isMaj(_9c,_95)){ s.ticks.majorLabel[_8f]=tt.majLabel(_9c); s.ticks.major[_8f++]=ts; }else{ s.ticks.minor[_90++]=ts; } } while(ts>=_9b){ } _9c.setTime(1000*_9b); l=tt.supLabel(_9c); if(_8e<1||s.ticks.supLabel[_8e-1]!=l){ s.ticks.supLabel[_8e]=l; s.ticks.sup[_8e++]=_9b; } } function setPowerTicks(s,_9f){ if(s.max-s.min>=2000){ s.unit="kW"; s.unitScale=0.001; }else{ s.unit="W"; s.unitScale=1; } var _a0=0; var _a1=0; s.ticks.major=[]; s.ticks.minor=[]; if(s.max==s.min){ return; }else{ if(s.maxMAJ_TICK_MIN_DIST){ _a3=_a2/5; }else{ if(_a5/2>MAJ_TICK_MIN_DIST){ _a3=_a2/2; }else{ _a3=_a2; } } var t=Math.ceil(s.min/_a3)*_a3; while(t<=s.max){ var f=t/_a2; if(Math.abs(f-Math.round(f))<0.005){ s.ticks.major[_a1++]=t; }else{ s.ticks.minor[_a0++]=t; } t+=_a3; } } function setTicks(_a8,_a9,_aa,_ab){ setTimeTicks(_a8.t,_a9,_aa); setPowerTicks(_a8.p,_ab); } function autoScale(obj,_ad,_ae,_af,_b0){ if(!EMapper.map){ return; } if(obj.time.length>0){ _ae.t.max=obj.time[0]; }else{ if(obj.mainEndTime){ _ae.t.max=obj.mainEndTime; }else{ _ae.t.max=0; } } _ae.t.min=_ae.t.max-_ad; _ae.p.min=0; _ae.p.max=5000; if(_ae.p.userMax>0){ _ae.p.max=_ae.p.userMax; }else{ var max=0; if(obj.power.length>0){ for(var i=0;imax){ max=p[j]; } } } } if(obj.instPower){ var p=EMapper.map.power(obj.instPower); for(var j=EG_TOTAL;j<=EG_SOLAR;++j){ if(p[j]>max){ max=p[j]; } } } if(max>0){ _ae.p.max=1.07*max; } } var _b5=_ad/_b0; if(_b5>=EM_SECS_PER_DY){ _af.granularity=EM_SECS_PER_DY; _af.granularityCode="d"; }else{ if(_b5>=EM_SECS_PER_HR){ _af.granularity=EM_SECS_PER_HR; _af.granularityCode="h"; }else{ _af.granularity=EM_SECS_PER_MN; _af.granularityCode="m"; } } _af.skipCount=Math.floor(1.5*_b5/_af.granularity); _af.secsPerSample=(_af.skipCount+1)*_af.granularity; _af.sampleCount=Math.ceil(_ad/_af.secsPerSample)+2; } EMonitor=function(id,_b7,_b8){ var _b9=this; this.id=id; this.epoch=0; this.sourceId={}; this.sourceName=[]; this.sourceVisible=[]; this.callback=[]; var loc=location.protocol+"//"+location.host; this.egaugeURL=loc+"/cgi-bin/egauge?"; this.showURL=loc+"/cgi-bin/egauge-show?"; this.waitTime=null; this.time=[]; this.power=[]; this.energy=[]; this.instReq=new HTTPRequest(); this.instLastTimeStamp=0; this.instLastEnergy=[]; this.instPower={}; this.reqWidth=_b7; this.reqHeight=_b8; this.mainReq=new HTTPRequest(); this.mainTimespan=2*EM_SECS_PER_DY; this.mainFetch={}; this.mainScale={}; this.mainScale.t={}; this.mainScale.t.min=0; this.mainScale.t.max=3600; this.mainScale.t.unit="s"; this.mainScale.t.unitScale=1; this.mainScale.t.ticks={}; this.mainScale.t.ticks.major=[]; this.mainScale.t.ticks.majorLabel=[]; this.mainScale.t.ticks.minor=[]; this.mainScale.p={}; this.mainScale.p.min=0; this.mainScale.p.max=0; this.mainScale.p.ticks={}; this.mainScale.p.userMax=-1; this.currReq=new HTTPRequest(); this.histScale={}; this.histScale.t={}; this.histScale.t.min=0; this.histScale.t.max=40*365*24*3600; this.histScale.t.unit="W"; this.histScale.t.unitScale=1; this.histScale.t.ticks={}; this.histScale.p={}; this.histScale.p.min=0; this.histScale.p.max=10000; this.histScale.p.ticks={}; this.histGraph=null; this.instGraph=null; this.avgGraph=null; this.histGraph=null; var ctx=new Graphics.Context(); ctx.set("thickness",1); ctx.set("color","#000"); ctx.set("fill","none"); ctx.set("text-anchor","middle"); this.graphContext=ctx; this.curveContext=[]; this.shadeContext=[]; this.compUseContext=[]; this.compGenContext=[]; var ctx=new Graphics.Context(); ctx.set("font-family",GAUGE_VALUE_FONTS); ctx.set("font-size",GAUGE_VALUE_FONT_SIZE+"px"); ctx.set("text-anchor","end"); ctx.set("color","red"); ctx.set("thickness",2); ctx.set("fill","none"); this.curveContext[0]=ctx; var ctx=new Graphics.Context(); ctx.set("font-family",GAUGE_VALUE_FONTS); ctx.set("font-size",GAUGE_VALUE_FONT_SIZE+"px"); ctx.set("text-anchor","end"); ctx.set("color","green"); ctx.set("thickness",2); ctx.set("fill","none"); this.curveContext[1]=ctx; var ctx=new Graphics.Context(); ctx.set("thickness",0); ctx.set("fill","red"); ctx.set("fill-opacity",SHADE_OPACITY); this.shadeContext[0]=ctx; var ctx=new Graphics.Context(); ctx.set("thickness",0); ctx.set("fill","green"); ctx.set("fill-opacity",SHADE_OPACITY); this.shadeContext[1]=ctx; for(var i=0;i<4;++i){ var ctx=new Graphics.Context(); ctx.set("color","red"); ctx.set("thickness","1"); ctx.set("dash-style",i+1); ctx.set("fill","none"); this.compUseContext[i]=ctx; var ctx=new Graphics.Context(); ctx.set("color","green"); ctx.set("thickness","1"); ctx.set("dash-style",i+1); ctx.set("fill","none"); this.compGenContext[i]=ctx; } var ctx=new Graphics.Context(); ctx.set("color","#000"); ctx.set("font-family",LABEL_FONTS); ctx.set("font-size",LABEL_FONT_SIZE+"px"); ctx.set("font-weight","bold"); this.labelContext=ctx; var ctx=new Graphics.Context(); ctx.set("fill","black"); ctx.set("font-family",BAR_LABEL_FONTS); ctx.set("font-size",BAR_LABEL_FONT_SIZE+"px"); ctx.set("font-weight","bold"); ctx.set("text-anchor","start"); this.barLabelContext=ctx; if(DEBUG){ this.time[0]=125000; this.time[1]=120000; this.time[2]=115000; this.time[3]=110000; this.time[4]=105000; this.time[5]=100000; this.time[6]=95000; this.time[7]=80000; this.power[0]={}; this.power[1]={}; this.power[2]={}; this.power[3]={}; this.power[4]={}; this.power[5]={}; this.power[6]={}; this.power[7]={}; this.power[0].Grid=1000; this.power[0].Solar0=-100; this.power[0].Solar1=-150; this.power[0].Geopump=-350; this.power[1].Grid=1000; this.power[1].Solar0=100; this.power[1].Solar1=-50; this.power[1].Geopump=-500; this.power[2].Grid=-400; this.power[2].Solar0=1500; this.power[2].Solar1=500; this.power[2].Geopump=-1000; this.power[3].Grid=-600; this.power[3].Solar0=2000; this.power[3].Solar1=1000; this.power[3].Geopump=-1200; this.power[4].Grid=1100; this.power[4].Solar0=1500; this.power[4].Solar1=2000; this.power[4].Geopump=50; this.power[5].Grid=800; this.power[5].Solar0=-200; this.power[5].Solar1=-250; this.power[5].Geopump=100; this.power[6].Grid=1500; this.power[6].Solar0=-350; this.power[6].Solar1=-700; this.power[6].Geopump=-350; this.power[7].Grid=1500; this.power[7].Solar0=-500; this.power[7].Solar1=-750; this.power[7].Geopump=-350; this.instPower.Grid=-1000; this.instPower.Geopump=-600; this.instPower.Solar0=6000; this.instPower.Solar1=-100; this.instPower.Solar2=-125; this.instPower.Solar3=300; this.instPower.Solar4=350; Timer.add(TIMER_INTERVAL,function(obj){ sources=[]; for(var src in obj.instPower){ sources[sources.length]=src; } updateSources(obj,sources); },this); } EMapper.fetchMap(function(){ _b9.resize(); Timer.add(TIMER_INTERVAL,fetchInstPower,_b9); Timer.add(TIMER_INTERVAL,fetchMainEnergies,_b9); }); }; EMonitor.prototype.resize=function(_bf,_c0){ if(!_bf){ _bf=this.reqWidth; } if(!_c0){ _c0=this.reqHeight; } if(this.canvas){ this.canvas.del(); } this.canvas=new Graphics(this.id,_bf,_c0); _bf=this.canvas.width; _c0=this.canvas.height; var _c1=(INST_WIDTH+AVG_WIDTH+POWER_LABEL_WIDTH+3*HORIZ_MARGIN); var _c2=_bf-_c1; if(_c2<200){ _c2=200; _bf=_c2+_c1; } this.mainWidth=_c2; var _c3=(TOP_MARGIN+TIME_LABEL_HEIGHT+HIST_METER_HEIGHT+HIST_SCROLLER_HEIGHT+BOTTOM_MARGIN); var _c4=_c0-_c3; if(_c4<100){ _c4=100; _c0=_c4+_c3; } this.mainHeight=_c4; var g=new Graphics.Group(this.graphContext); g.setX(0.5); g.setY(TOP_MARGIN+0.5); this.mainGraph=new EGraph(g,_c2,_c4,this.curveContext,this.shadeContext); this.mainGraph.setCompMapAndCtx(this.sourceId,this.compUseContext,this.compGenContext); this.canvas.add(g); var g=new Graphics.Group(this.graphContext); g.setX(0.5+_c2+POWER_LABEL_WIDTH+2*HORIZ_MARGIN); g.setY(TOP_MARGIN+0.5); this.instBar=new EBar(g,INST_WIDTH,_c4,GAUGE_VALUE_FONT_WIDTH,GAUGE_VALUE_FONT_HEIGHT,this.curveContext,this.shadeContext); this.instBar.setLabel("Current",this.barLabelContext); this.instBar.setCompMapAndCtx(this.sourceId,this.compUseContext,this.compGenContext); this.canvas.add(g); autoScale(this,this.mainTimespan,this.mainScale,this.mainFetch,_c2); setTicks(this.mainScale,this.time,_c2,_c4); var g=new Graphics.Group(this.labelContext); g.setX(0.5+_c2+HORIZ_MARGIN); g.setY(TOP_MARGIN+0.5); this.mainPowerLabels=new ELabel(g,EG_Y,"middle",POWER_LABEL_WIDTH,_c4,LABEL_FONT_WIDTH,LABEL_FONT_HEIGHT); this.canvas.add(g); var g=new Graphics.Group(this.labelContext); g.setX(0.5); g.setY(TOP_MARGIN+_c4+0.5); this.mainTimeLabels=new ELabel(g,EG_X,"start",_c2,TIME_LABEL_HEIGHT,LABEL_FONT_WIDTH,LABEL_FONT_HEIGHT); this.canvas.add(g); if(this.time.length>0){ this.mainGraph.draw(this.mainScale,this.time,this.power); }else{ this.mainGraph.setLoading(this.mainScale); } this.instBar.draw(this.mainScale.p,this.instPower); this.mainPowerLabels.draw(this.mainScale.p); this.mainTimeLabels.draw(this.mainScale.t); for(var i=0;i0){ end=this.time[0]; }else{ if(this.mainEndTime){ end=this.mainEndTime; } } if(!end||!this.mainTimespan){ return null; } return [end-this.mainTimespan,end]; }; EMonitor.prototype.setTimespan=function(_e6){ this.mainEndTime=null; if(_e6==this.mainTimespan){ return; } this.mainTimespan=_e6; this.mainReq.abort(); reload(this); }; EMonitor.prototype.setMaxPower=function(_e7){ if(_e7==this.mainScale.p.userMax){ return; } this.mainScale.p.userMax=_e7; autoScale(this,this.mainTimespan,this.mainScale,this.mainFetch,this.mainWidth); setPowerTicks(this.mainScale.p,this,this.mainHeight); this.mainGraph.draw(this.mainScale,this.time,this.power); this.mainPowerLabels.draw(this.mainScale.p); }; EMonitor.prototype.setStartOfAverage=function(val,_e9,_ea){ if(!this.instLastTimeStamp){ return null; } var _eb=new Date(1000*this.instLastTimeStamp); MS_PER_HR=60*60*1000; switch(val){ case "date": break; case "hour": _eb.setTime(_eb.getTime()-MS_PER_HR); break; case "day": _eb.setTime(_eb.getTime()-24*MS_PER_HR); break; case "week": _eb.setTime(_eb.getTime()-7*24*MS_PER_HR); break; case "month": _eb.setTime(_eb.getTime()-30*24*MS_PER_HR); break; case "year": _eb.setTime(_eb.getTime()-365*24*MS_PER_HR); break; case "now": break; case "startOfHour": _eb.setMinutes(0,0,0); break; case "startOfDay": _eb.setHours(0,0,0,0); break; case "startOfWeek": _eb.setTime(_eb.getTime()-_eb.getDay()*24*MS_PER_HR); _eb.setHours(0,0,0,0); break; case "startOfMonth": _eb.setDate(1); _eb.setHours(0,0,0,0); break; case "startOfYear": _eb.setMonth(0,1); _eb.setHours(0,0,0,0); break; case "epoch": _eb=new Date(1000*this.epoch); break; } var ts=_eb.getTime()/1000; fetchEnergies(this,ts,_ea); return _eb; }; EMonitor.prototype.exportGraph=function(_ed,_ee,to,_f0){ if(_ed!="csv"){ throw Error("Export format "+_ed+" unsupported"); } var _f1=(to-_ee)/_f0+1; var _f2="m"; var _f3=60; if(_f0%3600==0){ _f3=3600; _f2="h"; }else{ if(_f0%24*3600==0){ _f3=24*3600; _f2="d"; } } var n=(_f0/_f3); var _f5=(n-1); if(_f5<=0){ _f5=0; } var url=(this.showURL+"c&"+_f2+"&s="+_f5+"&n="+_f1+"&f="+to); location.href=url; }; })();