2014-04-19 09:25:40 +02:00
|
|
|
function Timeline(j){this.ns="http://www.w3.org/2000/svg";this.xlinkns="http://www.w3.org/1999/xlink";this.marginBottom=10;this.marginTop=15;this.marginLeft=10;this.marginRight=10;this.rounded=false;this.x_axis=false;this.fill=true;this.line="line";this.dashed_style="5, 5";this.parent_holder=false;this.holder=false;this.g=false;this.axis=false;this.graphs=[];this.raw_points=[];this.x_callback=false;if(!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")){alert("ERROR : Your browser does not support embedded SVG.")}this.parent_holder=document.getElementById(j.id);var h=this.createElement("svg:svg",{width:j.width,height:j.height});h.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink",this.xlinkns);this.parent_holder.appendChild(h);this.holder=this.parent_holder.querySelector("svg");defs=this.createElement("defs",{});this.holder.appendChild(defs);if(j.grid==="small"||j.grid==="both"){var i=this.createElement("pattern",{id:"smallGrid",width:8,height:8,patternUnits:"userSpaceOnUse"});var e=this.createElement("path",{d:"M 8 0 L 0 0 0 8",fill:"none",stroke:"gray","stroke-width":"0.5"});i.appendChild(e);defs.appendChild(i)}if(j.grid==="big"||j.grid==="both"){var d=this.createElement("pattern",{id:"grid",width:80,height:80,patternUnits:"userSpaceOnUse"});if(j.grid==="both"){var c=this.createElement("rect",{width:80,height:80,fill:"url(#smallGrid)"});d.appendChild(c)}var f=this.createElement("path",{d:"M 80 0 L 0 0 0 80",fill:"none",stroke:"gray","stroke-width":"1"});d.appendChild(f);defs.appendChild(d)}this.grid=j.grid;var g=this.createElement("marker",{id:"markerArrow",markerWidth:13,markerHeight:13,refX:2,refY:6,orient:"auto"});var b=this.createElement("path",{d:"M2,2 L2,11 L10,6 L2,2",fill:"gray"});g.appendChild(b);defs.appendChild(g);this.g=this.createElement("g",{transform:"translate(0, "+this.parent_holder.offsetHeight+") scale(1, -1)"});this.holder.appendChild(this.g);if(j.x_axis===true){this.axis=this.createElement("line",{x1:this.marginLeft,y1:this.parent_holder.offsetHeight/2+1.5,x2:this.parent_holder.offsetWidth-13-this.marginRight,y2:this.parent_holder.offsetHeight/2+1.5,stroke:"gray","stroke-width":3,"marker-end":'url("#markerArrow")'});this.g.appendChild(this.axis)}if(this.grid!=="none"){var a=this.createElement("rect",{width:"100%",height:"100%"});if(this.grid==="big"||this.grid==="both"){a.setAttribute("fill","url(#grid)")}else{a.setAttribute("fill","url(#smallGrid)")}this.g.appendChild(a)}this.rounded=j.rounded;this.x_axis=j.x_axis;this.line=j.line;this.fill=j.fill;this.x_callback=j.x_callback}Timeline.prototype.createElement=function(b,a){var c=document.createElementNS(this.ns,b);for(attr in a){c.setAttribute(attr,a[attr])}return c};Timeline.prototype.hasClass=function(b,a){return(" "+b.getAttribute("class")+" ").indexOf(" "+a+" ")>-1};Timeline.prototype.addGraph=function(b,a){this.graphs[b]=a};Timeline.prototype.hasGraph=function(a){if(typeof(this.graphs[a])==="undefined"){return false}else{return true}};Timeline.prototype.clearGraph=function(b){if(typeof(b)==="undefined"){this.raw_points=[];this.graphs=[]}else{for(var a=0;a<this.raw_points.length;a++){if(this.raw_points[a].graph===b){this.raw_points[a]=undefined}}}};Timeline.prototype.addPoints=function(d,c){for(var a=0;a<c.length;a++){var b={graph:d,x:c[a].x,y:c[a].y};if(typeof(c[a].label)!=="undefined"){b.label=c[a].label}else{b.label=""}if(typeof(c[a].click)!=="undefined"){b.click=c[a].click}else{b.click=false}this.raw_points.push(b)}this.raw_points.sort(function(f,e){if(f.x<e.x){return -1}else{if(f.x==e.x){return 0}else{return 1}}})};Timeline.prototype.newCoordinate=function(f,d,b,e,g){var c=(g-e)/(b-d);return c*(f-d)+e};Timeline.prototype.getNewXY=function(a,d,e,b){var c=this;return function(f,g){return{x:c.newCoordinate(f,a,d,c.marginLeft,c.parent_holder.offsetWidth-c.marginRight),y:c.newCoordinate(g,e,b,2*c.marginBottom,c.parent_holder.offsetHeight-c.marginTop)}}};Timeline.prototype.getControlPoints=function(h){var p=new Array();var o=new Array();var e=h.length-1;var l=new Array();var k=new Array();var j=new Ar
|