timeline.js/timeline.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

2014-03-31 20:42:57 +02:00
var SVG={};SVG.ns="http://www.w3.org/2000/svg";SVG.xlinkns="http://www.w3.org/1999/xlink";SVG.marginBottom=10;SVG.marginTop=15;SVG.marginLeft=10;SVG.marginRight=10;SVG.rounded=false;SVG.x_axis=false;SVG.parent_holder=false;SVG.holder=false;SVG.g=false;SVG.axis=false;SVG.raw_points=[];SVG.labels=[];SVG.x_callback=false;SVG.init=function(q){if(!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")){alert("Your browser does not support embedded SVG.")}SVG.parent_holder=document.getElementById(q.id);var o=document.createElementNS(SVG.ns,"svg:svg");o.setAttribute("width",q.width);o.setAttribute("height",q.height);o.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink",SVG.xlinkns);SVG.parent_holder.appendChild(o);SVG.holder=SVG.parent_holder.querySelector("svg");var j=document.createElementNS(SVG.ns,"defs");SVG.holder.appendChild(j);if(q.grid==="small"||q.grid==="both"){var p=document.createElementNS(SVG.ns,"pattern");p.setAttribute("id","smallGrid");p.setAttribute("width",8);p.setAttribute("height",8);p.setAttribute("patternUnits","userSpaceOnUse");var h=document.createElementNS(SVG.ns,"path");h.setAttribute("d","M 8 0 L 0 0 0 8");h.setAttribute("fill","none");h.setAttribute("stroke","gray");h.setAttribute("stroke-width","0.5");p.appendChild(h);j.appendChild(p)}if(q.grid==="big"||q.grid==="both"){var g=document.createElementNS(SVG.ns,"pattern");g.setAttribute("id","grid");g.setAttribute("width",80);g.setAttribute("height",80);g.setAttribute("patternUnits","userSpaceOnUse");if(q.grid==="both"){var f=document.createElementNS(SVG.ns,"rect");f.setAttribute("width",80);f.setAttribute("height",80);f.setAttribute("fill","url(#smallGrid)");g.appendChild(f)}var l=document.createElementNS(SVG.ns,"path");l.setAttribute("d","M 80 0 L 0 0 0 80");l.setAttribute("fill","none");l.setAttribute("stroke","gray");l.setAttribute("stroke-width","1");g.appendChild(l);j.appendChild(g)}SVG.grid=q.grid;var k=document.createElementNS(SVG.ns,"marker");k.setAttribute("id","markerArrow");k.setAttribute("markerWidth",13);k.setAttribute("markerHeight",13);k.setAttribute("refX",2);k.setAttribute("refY",6);k.setAttribute("orient","auto");var e=document.createElementNS(SVG.ns,"path");e.setAttribute("d","M2,2 L2,11 L10,6 L2,2");e.setAttribute("fill","gray");k.appendChild(e);j.appendChild(k);SVG.g=document.createElementNS(SVG.ns,"g");SVG.g.setAttribute("transform","translate(0, "+SVG.parent_holder.offsetHeight+") scale(1, -1)");SVG.holder.appendChild(SVG.g);if(q.x_axis===true){SVG.axis=document.createElementNS(SVG.ns,"line");SVG.axis.setAttribute("x1",SVG.marginLeft);SVG.axis.setAttribute("x2",SVG.parent_holder.offsetWidth-13-SVG.marginRight);SVG.axis.setAttribute("stroke","gray");SVG.axis.setAttribute("stroke-width",3);SVG.axis.setAttribute("marker-end",'url("#markerArrow")');SVG.g.appendChild(SVG.axis)}if(SVG.grid!=="none"){var d=document.createElementNS(SVG.ns,"rect");d.setAttribute("width","100%");d.setAttribute("height","100%");if(SVG.grid==="big"||SVG.grid==="both"){d.setAttribute("fill","url(#grid)")}else{d.setAttribute("fill","url(#smallGrid)")}SVG.g.appendChild(d)}SVG.rounded=q.rounded;SVG.x_axis=q.x_axis;SVG.x_callback=q.x_callback;SVG.parent_holder.addEventListener("mousemove",function(v){var s=v||window.event;var u=false;var t=SVG.holder.querySelectorAll(".over");for(u=0;u<t.length;u++){SVG.holder.getElementById(t[u].getAttribute("id").replace("over","point")).setAttribute("r","4");if(SVG.labels[graph][parseInt(t[u].getAttribute("id").replace("over_",""))]!==""){SVG.holder.getElementById(t[u].getAttribute("id").replace("over","label")).setAttribute("display","none")}}SVG.overEffect(s.clientX,s.clientY)})};SVG.hasClass=function(e,d){return(" "+e.getAttribute("class")+" ").indexOf(" "+d+" ")>-1};SVG.overEffect=function(d,f){if(!document.elementFromPoint(d,f)){return}var e=document.elementFromPoint(d,f);if(!SVG.hasClass(e,"over")){return}SVG.holder.getElementById(e.getAttribute("id").replace("over","point")).setAttribute("r","6");if(SVG.labels[graph][parseInt(e.getAttribute("id").replace("over_",""))]!==""){SVG.ho