2014-04-19 18:18:01 +02:00
|
|
|
function Timeline(l){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;var d=window.onresize||function(){};var i=this;window.onresize=function(){d();if(i.g!==false){i.g.setAttribute("transform","translate(0, "+i.parent_holder.offsetHeight+") scale(1, -1)");if(i.x_axis===true){i.axis.setAttribute("x2",i.parent_holder.offsetWidth-13-i.marginRight)}[].forEach.call(i.holder.querySelectorAll(".label, .over, .point, .line, .graph, .legend_x"),function(m){m.parentNode.removeChild(m)});i.draw()}};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(l.id);this.parent_holder.style.width=l.width;this.parent_holder.style.height=l.height;var j=this.createElement("svg:svg",{width:"100%",height:"100%"});j.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink",this.xlinkns);this.parent_holder.appendChild(j);this.holder=this.parent_holder.querySelector("svg");defs=this.createElement("defs",{});this.holder.appendChild(defs);if(l.grid==="small"||l.grid==="both"){var k=this.createElement("pattern",{id:"smallGrid",width:8,height:8,patternUnits:"userSpaceOnUse"});var f=this.createElement("path",{d:"M 8 0 L 0 0 0 8",fill:"none",stroke:"gray","stroke-width":"0.5"});k.appendChild(f);defs.appendChild(k)}if(l.grid==="big"||l.grid==="both"){var e=this.createElement("pattern",{id:"grid",width:80,height:80,patternUnits:"userSpaceOnUse"});if(l.grid==="both"){var c=this.createElement("rect",{width:80,height:80,fill:"url(#smallGrid)"});e.appendChild(c)}var h=this.createElement("path",{d:"M 80 0 L 0 0 0 80",fill:"none",stroke:"gray","stroke-width":"1"});e.appendChild(h);defs.appendChild(e)}this.grid=l.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(l.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=l.rounded;this.x_axis=l.x_axis;this.line=l.line;this.fill=l.fill;this.x_callback=l.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{ret
|