From e1671102f40113dc9e33b5c4c4f8eab248efdad8 Mon Sep 17 00:00:00 2001 From: Phyks Date: Tue, 8 Apr 2014 20:09:07 +0200 Subject: [PATCH] Update README --- README.md | 1 - timeline.min.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3af158d..aadbb11 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,5 @@ Feel free to contribute ! * Y axis is not implemented, but could be implemented easily * Over effect is a bit overkill right now * Onclick events not working when there are multiple graphs. -* Choose between line / points / bars The last two points are easy to implement by refactoring the way the raw points are stored and using a single array for all the graphs. diff --git a/timeline.min.js b/timeline.min.js index f83a5b6..cbe93b4 100644 --- a/timeline.min.js +++ b/timeline.min.js @@ -1 +1 @@ -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.fill=true;SVG.line="line";SVG.dashed_style="5, 5";SVG.parent_holder=false;SVG.holder=false;SVG.g=false;SVG.axis=false;SVG.raw_points=[];SVG.labels=[];SVG.click=[];SVG.x_callback=false;SVG.createElement=function(b,a){var c=document.createElementNS(SVG.ns,b);for(attr in a){c.setAttribute(attr,a[attr])}return c};SVG.hasClass=function(b,a){return(" "+b.getAttribute("class")+" ").indexOf(" "+a+" ")>-1};SVG.addGraph=function(b,a){SVG.raw_points[b]={};SVG.raw_points[b].color=a;SVG.raw_points[b].data=new Array();SVG.labels[b]=new Array();SVG.click[b]=new Array()};SVG.hasGraph=function(a){if(SVG.raw_points[a]===undefined){return false}else{return true}};SVG.clearGraphData=function(a){if(typeof(a)==="undefined"){SVG.raw_points=[];SVG.labels=[];SVG.click=[]}else{SVG.raw_points[a].data=new Array();SVG.labels[a]=new Array();SVG.click[a]=new Array()}};SVG.addPoints=function(c,b){b.sort(function(e,d){if(e.x=0;--g){p[g]=(d[g]-j[g]*p[g+1])/k[g]}for(var g=0;gk||k===false){k=x}if(yi||i===false){i=y}}r.push(l);o.push(j);p.push(k);n.push(i)}r=Math.min.apply(null,r);o=Math.min.apply(null,o);p=Math.max.apply(null,p);n=Math.max.apply(null,n);var u=SVG.getNewXY(r,p,o,n);var q=u(Math.pow(10,Math.floor(Math.log(p-r)/Math.log(10))),Math.pow(10,Math.floor(Math.log(n-o)/Math.log(10))));var s=u(0,0);var c={x:q.x-s.x,y:q.y-s.y};if(SVG.grid==="big"||SVG.grid==="both"){var a=SVG.holder.getElementById("grid");a.setAttribute("width",c.x);a.setAttribute("height",c.y);var d=u(Math.floor(r/Math.pow(10,Math.floor(Math.log(p-r)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(p-r)/Math.log(10))),Math.floor(o/Math.pow(10,Math.floor(Math.log(n-o)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(n-o)/Math.log(10))));a.setAttribute("y",d.y);a.setAttribute("x",d.x);a.querySelector("path").setAttribute("d","M "+c.x+" 0 L 0 0 0 "+c.y);if(SVG.grid==="both"){a.querySelector("rect").setAttribute("width",c.x);a.querySelector("rect").setAttribute("height",c.y)}}if(SVG.grid==="small"||SVG.grid==="both"){c.x=c.x/10;c.y=c.y/10;var a=SVG.holder.getElementById("smallGrid");a.setAttribute("width",c.x);a.setAttribute("height",c.y);if(SVG.grid==="small"){var f=u(Math.floor(r/Math.pow(10,Math.floor(Math.log(p-r)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(p-r)/Math.log(10))),Math.floor(o/Math.pow(10,Math.floor(Math.log(n-o)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(n-o)/Math.log(10))));a.setAttribute("y",f.y);a.setAttribute("x",f.x)}a.querySelector("path").setAttribute("d","M "+c.x+" 0 L 0 0 0 "+c.y)}if(SVG.x_axis===true){y=u(0,0).y;SVG.axis.setAttribute("y1",y);SVG.axis.setAttribute("y2",y)}return u};SVG.draw=function(){var t=SVG.scale(SVG.raw_points);var h,f,m;var l,k;var d;for(var c in SVG.raw_points){h=new Array();f=new Array();m="";for(var n=0;n","").split("");for(var o=0;o]+)>)/ig,"").replace("%y",SVG.raw_points[c].data[n][1]).replace("%x",SVG.raw_points[c].data[n][0]);if(o%2==0){d.appendChild(document.createTextNode(j[o]))}else{var r=SVG.createElement("tspan",{dy:"-5"});r.appendChild(document.createTextNode(j[o]));d.appendChild(r)}}m=SVG.createElement("path",{stroke:"black","stroke-width":2,fill:"white",opacity:0.5});q.appendChild(m);q.appendChild(d);var s=h[n]-d.getBoundingClientRect().width/2;var a=SVG.parent_holder.offsetHeight-f[n]-20;var e=d.getBoundingClientRect().width;var p=d.getBoundingClientRect().height;if(h[n]-d.getBoundingClientRect().width/2<0){s=h[n]+20;a=SVG.parent_holder.offsetHeight-f[n]+5;m.setAttribute("d","M "+(s-5)+" "+(a+5)+" L "+(s-5)+" "+(a-p/2+7.5)+" L "+(s-10)+" "+(a-p/2+5)+" L "+(s-5)+" "+(a-p/2+2.5)+" L "+(s-5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a+5)+" Z")}else{if(f[n]+d.getBoundingClientRect().height+12>SVG.parent_holder.offsetHeight){s=h[n]+20;a=SVG.parent_holder.offsetHeight-f[n]+5;m.setAttribute("d","M "+(s-5)+" "+(a+5)+" L "+(s-5)+" "+(a-p/2+7.5)+" L "+(s-10)+" "+(a-p/2+5)+" L "+(s-5)+" "+(a-p/2+2.5)+" L "+(s-5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a+5)+" Z");if(s+e>SVG.parent_holder.offsetWidth){s=h[n]-e-20;a=SVG.parent_holder.offsetHeight-f[n]+5;m.setAttribute("d","M "+(s-5)+" "+(a+5)+" L "+(s-5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p/2+2.5)+" L "+(s+e+10)+" "+(a-p/2+5)+" L "+(s+e+5)+" "+(a-p/2+7.5)+" L "+(s+e+5)+" "+(a+5)+" Z")}}else{if(h[n]+e/2+12>SVG.parent_holder.offsetWidth){s=h[n]-e-20;a=SVG.parent_holder.offsetHeight-f[n]+5;m.setAttribute("d","M "+(s-5)+" "+(a+5)+" L "+(s-5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p/2+2.5)+" L "+(s+e+10)+" "+(a-p/2+5)+" L "+(s+e+5)+" "+(a-p/2+7.5)+" L "+(s+e+5)+" "+(a+5)+" Z")}else{m.setAttribute("d","M "+(s-5)+" "+(a+5)+" L "+(s-5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a-p+5)+" L "+(s+e+5)+" "+(a+5)+" L "+(s+e/2+2.5)+" "+(a+5)+" L "+(s+e/2)+" "+(a+10)+" L "+(s+e/2-2.5)+" "+(a+5)+" Z")}}}d.setAttribute("x",s);d.setAttribute("y",a);q.setAttribute("display","none")}}for(var n=0;n=-5&&z<=5&&z>=-5){SVG.holder.getElementById(this.getAttribute("id").replace("over","point")).onclick()}}})(h[n],f[n]);if(SVG.x_callback!==false){d=SVG.createElement("text",{"class":"legend_x",fill:"gray",transform:"translate(0, "+SVG.parent_holder.offsetHeight+") scale(1, -1)"});d.appendChild(document.createTextNode(SVG.x_callback(h[n])));SVG.g.appendChild(d);d.setAttribute("x",h[n]-d.getBoundingClientRect().width/2+2.5);var u=t(0,0).y;d.setAttribute("y",SVG.parent_holder.offsetHeight-SVG.marginBottom-u);d=SVG.createElement("line",{"class":"legend_x",stroke:"gray","stroke-width":2,x1:h[n],x2:h[n],y1:u-5,y2:u+5});SVG.g.appendChild(d)}}}};var old=window.onresize||function(){};window.onresize=function(){old();if(SVG.g!==false){SVG.g.setAttribute("transform","translate(0, "+SVG.parent_holder.offsetHeight+") scale(1, -1)");if(SVG.x_axis===true){SVG.axis.setAttribute("x2",SVG.parent_holder.offsetWidth-13-SVG.marginRight)}[].forEach.call(SVG.holder.querySelectorAll(".label, .over, .point, .line, .graph, .legend_x"),function(a){a.parentNode.removeChild(a)});SVG.draw()}}; \ No newline at end of file +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.fill=true;SVG.line="line";SVG.dashed_style="5, 5";SVG.parent_holder=false;SVG.holder=false;SVG.g=false;SVG.axis=false;SVG.graphs=[];SVG.raw_points=[];SVG.x_callback=false;SVG.createElement=function(b,a){var c=document.createElementNS(SVG.ns,b);for(attr in a){c.setAttribute(attr,a[attr])}return c};SVG.hasClass=function(b,a){return(" "+b.getAttribute("class")+" ").indexOf(" "+a+" ")>-1};SVG.addGraph=function(b,a){SVG.graphs[b]=a};SVG.hasGraph=function(a){if(typeof(SVG.graphs[a])==="undefined"){return false}else{return true}};SVG.clearGraph=function(b){if(typeof(b)==="undefined"){SVG.raw_points=[];SVG.graphs=[]}else{for(var a=0;a=0;--g){p[g]=(d[g]-j[g]*p[g+1])/k[g]}for(var g=0;gc||c===false){c=j[p].x}if(j[p].yb||b===false){b=j[p].y}}var f=SVG.getNewXY(g,c,e,b);var i=f(Math.pow(10,Math.floor(Math.log(c-g)/Math.log(10))),Math.pow(10,Math.floor(Math.log(b-e)/Math.log(10))));var o=f(0,0);var n={x:i.x-o.x,y:i.y-o.y};if(SVG.grid==="big"||SVG.grid==="both"){var a=SVG.holder.getElementById("grid");a.setAttribute("width",n.x);a.setAttribute("height",n.y);var h=f(Math.floor(g/Math.pow(10,Math.floor(Math.log(c-g)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(c-g)/Math.log(10))),Math.floor(e/Math.pow(10,Math.floor(Math.log(b-e)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(b-e)/Math.log(10))));a.setAttribute("y",h.y);a.setAttribute("x",h.x);a.querySelector("path").setAttribute("d","M "+n.x+" 0 L 0 0 0 "+n.y);if(SVG.grid==="both"){a.querySelector("rect").setAttribute("width",n.x);a.querySelector("rect").setAttribute("height",n.y)}}if(SVG.grid==="small"||SVG.grid==="both"){n.x=n.x/10;n.y=n.y/10;var a=SVG.holder.getElementById("smallGrid");a.setAttribute("width",n.x);a.setAttribute("height",n.y);if(SVG.grid==="small"){var m=f(Math.floor(g/Math.pow(10,Math.floor(Math.log(c-g)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(c-g)/Math.log(10))),Math.floor(e/Math.pow(10,Math.floor(Math.log(b-e)/Math.log(10))))*Math.pow(10,Math.floor(Math.log(b-e)/Math.log(10))));a.setAttribute("y",m.y);a.setAttribute("x",m.x)}a.querySelector("path").setAttribute("d","M "+n.x+" 0 L 0 0 0 "+n.y)}if(SVG.x_axis===true){y=f(0,0).y;SVG.axis.setAttribute("y1",y);SVG.axis.setAttribute("y2",y)}return f};SVG.draw=function(){var c=SVG.scale(SVG.raw_points);var p=[],s;var n,m;var f;for(var o=0;o","").split("");for(var e=0;e]+)>)/ig,"").replace("%y",b[o].y).replace("%x",b[o].x);if(e%2==0){f.appendChild(document.createTextNode(q[e]))}else{var h=SVG.createElement("tspan",{dy:"-5"});h.appendChild(document.createTextNode(q[e]));f.appendChild(h)}}s=SVG.createElement("path",{stroke:"black","stroke-width":2,fill:"white",opacity:0.5});j.appendChild(s);j.appendChild(f);var d=b[o].x-f.getBoundingClientRect().width/2;var l=SVG.parent_holder.offsetHeight-b[o].y-20;var k=f.getBoundingClientRect().width;var a=f.getBoundingClientRect().height;if(b[o].x-f.getBoundingClientRect().width/2<0){d=b[o].x+20;l=SVG.parent_holder.offsetHeight-b[o].y+5;s.setAttribute("d","M "+(d-5)+" "+(l+5)+" L "+(d-5)+" "+(l-a/2+7.5)+" L "+(d-10)+" "+(l-a/2+5)+" L "+(d-5)+" "+(l-a/2+2.5)+" L "+(d-5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l+5)+" Z")}else{if(b[o].y+f.getBoundingClientRect().height+12>SVG.parent_holder.offsetHeight){d=b[o].x+20;l=SVG.parent_holder.offsetHeight-b[o].y+5;s.setAttribute("d","M "+(d-5)+" "+(l+5)+" L "+(d-5)+" "+(l-a/2+7.5)+" L "+(d-10)+" "+(l-a/2+5)+" L "+(d-5)+" "+(l-a/2+2.5)+" L "+(d-5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l+5)+" Z");if(d+k>SVG.parent_holder.offsetWidth){d=b[o].y-k-20;l=SVG.parent_holder.offsetHeight-b[o].y+5;s.setAttribute("d","M "+(d-5)+" "+(l+5)+" L "+(d-5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a/2+2.5)+" L "+(d+k+10)+" "+(l-a/2+5)+" L "+(d+k+5)+" "+(l-a/2+7.5)+" L "+(d+k+5)+" "+(l+5)+" Z")}}else{if(b[o].x+k/2+12>SVG.parent_holder.offsetWidth){d=b[o].x-k-20;l=SVG.parent_holder.offsetHeight-b[o].y+5;s.setAttribute("d","M "+(d-5)+" "+(l+5)+" L "+(d-5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a/2+2.5)+" L "+(d+k+10)+" "+(l-a/2+5)+" L "+(d+k+5)+" "+(l-a/2+7.5)+" L "+(d+k+5)+" "+(l+5)+" Z")}else{s.setAttribute("d","M "+(d-5)+" "+(l+5)+" L "+(d-5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l-a+5)+" L "+(d+k+5)+" "+(l+5)+" L "+(d+k/2+2.5)+" "+(l+5)+" L "+(d+k/2)+" "+(l+10)+" L "+(d+k/2-2.5)+" "+(l+5)+" Z")}}}f.setAttribute("x",d);f.setAttribute("y",l);j.setAttribute("display","none")}}}};var old=window.onresize||function(){};window.onresize=function(){old();if(SVG.g!==false){SVG.g.setAttribute("transform","translate(0, "+SVG.parent_holder.offsetHeight+") scale(1, -1)");if(SVG.x_axis===true){SVG.axis.setAttribute("x2",SVG.parent_holder.offsetWidth-13-SVG.marginRight)}[].forEach.call(SVG.holder.querySelectorAll(".label, .over, .point, .line, .graph, .legend_x"),function(a){a.parentNode.removeChild(a)});SVG.draw()}}; \ No newline at end of file