radiant-race_results-extension 1.4.3 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/app/controllers/admin/race_instances_controller.rb +1 -1
  2. data/app/controllers/race_instances_controller.rb +7 -1
  3. data/app/controllers/race_performances_controller.rb +8 -0
  4. data/app/models/race.rb +7 -0
  5. data/app/models/race_checkpoint.rb +27 -1
  6. data/app/models/race_checkpoint_time.rb +33 -5
  7. data/app/models/race_instance.rb +38 -9
  8. data/app/models/race_performance.rb +81 -3
  9. data/app/views/admin/races/_form.html.haml +1 -2
  10. data/app/views/race_clubs/show.html.haml +3 -3
  11. data/app/views/race_instances/_results_header.html.haml +10 -0
  12. data/app/views/race_instances/_splits_header.html.haml +9 -0
  13. data/app/views/race_instances/show.html.haml +17 -8
  14. data/app/views/race_instances/splits.html.haml +19 -14
  15. data/app/views/race_performances/_performance.html.haml +12 -2
  16. data/app/views/race_performances/_splits.html.haml +30 -8
  17. data/app/views/race_performances/show.html.haml +18 -76
  18. data/app/views/races/show.html.haml +2 -1
  19. data/config/locales/en.yml +20 -0
  20. data/config/routes.rb +1 -1
  21. data/db/migrate/20111103150827_mapping_routes.rb +22 -0
  22. data/db/migrate/20111115150827_finish_checkpoint.rb +8 -0
  23. data/lib/race_tags.rb +3 -3
  24. data/lib/radiant-race_results-extension.rb +1 -1
  25. data/public/images/race_results/sorts.png +0 -0
  26. data/public/javascripts/flot/API.txt +1201 -0
  27. data/public/javascripts/flot/FAQ.txt +76 -0
  28. data/public/javascripts/flot/LICENSE.txt +22 -0
  29. data/public/javascripts/flot/Makefile +9 -0
  30. data/public/javascripts/flot/NEWS.txt +508 -0
  31. data/public/javascripts/flot/PLUGINS.txt +137 -0
  32. data/public/javascripts/flot/README.txt +90 -0
  33. data/public/javascripts/flot/examples/ajax.html +143 -0
  34. data/public/javascripts/flot/examples/annotating.html +75 -0
  35. data/public/javascripts/flot/examples/arrow-down.gif +0 -0
  36. data/public/javascripts/flot/examples/arrow-left.gif +0 -0
  37. data/public/javascripts/flot/examples/arrow-right.gif +0 -0
  38. data/public/javascripts/flot/examples/arrow-up.gif +0 -0
  39. data/public/javascripts/flot/examples/basic.html +38 -0
  40. data/public/javascripts/flot/examples/data-eu-gdp-growth-1.json +4 -0
  41. data/public/javascripts/flot/examples/data-eu-gdp-growth-2.json +4 -0
  42. data/public/javascripts/flot/examples/data-eu-gdp-growth-3.json +4 -0
  43. data/public/javascripts/flot/examples/data-eu-gdp-growth-4.json +4 -0
  44. data/public/javascripts/flot/examples/data-eu-gdp-growth-5.json +4 -0
  45. data/public/javascripts/flot/examples/data-eu-gdp-growth.json +4 -0
  46. data/public/javascripts/flot/examples/data-japan-gdp-growth.json +4 -0
  47. data/public/javascripts/flot/examples/data-usa-gdp-growth.json +4 -0
  48. data/public/javascripts/flot/examples/graph-types.html +75 -0
  49. data/public/javascripts/flot/examples/hs-2004-27-a-large_web.jpg +0 -0
  50. data/public/javascripts/flot/examples/image.html +45 -0
  51. data/public/javascripts/flot/examples/index.html +44 -0
  52. data/public/javascripts/flot/examples/interacting-axes.html +97 -0
  53. data/public/javascripts/flot/examples/interacting.html +93 -0
  54. data/public/javascripts/flot/examples/layout.css +6 -0
  55. data/public/javascripts/flot/examples/multiple-axes.html +60 -0
  56. data/public/javascripts/flot/examples/navigate.html +118 -0
  57. data/public/javascripts/flot/examples/percentiles.html +57 -0
  58. data/public/javascripts/flot/examples/pie.html +756 -0
  59. data/public/javascripts/flot/examples/realtime.html +83 -0
  60. data/public/javascripts/flot/examples/resize.html +61 -0
  61. data/public/javascripts/flot/examples/selection.html +114 -0
  62. data/public/javascripts/flot/examples/setting-options.html +61 -0
  63. data/public/javascripts/flot/examples/stacking.html +77 -0
  64. data/public/javascripts/flot/examples/symbols.html +49 -0
  65. data/public/javascripts/flot/examples/thresholding.html +54 -0
  66. data/public/javascripts/flot/examples/time.html +71 -0
  67. data/public/javascripts/flot/examples/tracking.html +95 -0
  68. data/public/javascripts/flot/examples/turning-series.html +98 -0
  69. data/public/javascripts/flot/examples/visitors.html +90 -0
  70. data/public/javascripts/flot/examples/zooming.html +98 -0
  71. data/public/javascripts/flot/excanvas.js +1427 -0
  72. data/public/javascripts/flot/excanvas.min.js +1 -0
  73. data/public/javascripts/flot/jquery.colorhelpers.js +179 -0
  74. data/public/javascripts/flot/jquery.colorhelpers.min.js +1 -0
  75. data/public/javascripts/flot/jquery.flot.crosshair.js +167 -0
  76. data/public/javascripts/flot/jquery.flot.crosshair.min.js +1 -0
  77. data/public/javascripts/flot/jquery.flot.fillbetween.js +183 -0
  78. data/public/javascripts/flot/jquery.flot.fillbetween.min.js +1 -0
  79. data/public/javascripts/flot/jquery.flot.image.js +238 -0
  80. data/public/javascripts/flot/jquery.flot.image.min.js +1 -0
  81. data/public/javascripts/flot/jquery.flot.js +2599 -0
  82. data/public/javascripts/flot/jquery.flot.min.js +6 -0
  83. data/public/javascripts/flot/jquery.flot.navigate.js +336 -0
  84. data/public/javascripts/flot/jquery.flot.navigate.min.js +1 -0
  85. data/public/javascripts/flot/jquery.flot.pie.js +750 -0
  86. data/public/javascripts/flot/jquery.flot.pie.min.js +1 -0
  87. data/public/javascripts/flot/jquery.flot.resize.js +60 -0
  88. data/public/javascripts/flot/jquery.flot.resize.min.js +1 -0
  89. data/public/javascripts/flot/jquery.flot.selection.js +344 -0
  90. data/public/javascripts/flot/jquery.flot.selection.min.js +1 -0
  91. data/public/javascripts/flot/jquery.flot.stack.js +184 -0
  92. data/public/javascripts/flot/jquery.flot.stack.min.js +1 -0
  93. data/public/javascripts/flot/jquery.flot.symbol.js +70 -0
  94. data/public/javascripts/flot/jquery.flot.symbol.min.js +1 -0
  95. data/public/javascripts/flot/jquery.flot.threshold.js +103 -0
  96. data/public/javascripts/flot/jquery.flot.threshold.min.js +1 -0
  97. data/public/javascripts/flot/jquery.js +8316 -0
  98. data/public/javascripts/flot/jquery.min.js +23 -0
  99. data/public/javascripts/jquery.qtip.js +2675 -0
  100. data/public/javascripts/jquery.sparkline.js +1271 -0
  101. data/public/javascripts/races.js +245 -0
  102. data/public/stylesheets/sass/admin/races.sass +65 -70
  103. data/public/stylesheets/sass/jquery.flot.sass +416 -0
  104. data/public/stylesheets/sass/race_results.sass +38 -2
  105. data/radiant-race_results-extension.gemspec +1 -1
  106. metadata +95 -11
  107. data/public/javascripts/tablesorter.js +0 -3
@@ -0,0 +1 @@
1
+ (function(b){function c(D){var h=null;var L=null;var n=null;var B=null;var p=null;var M=0;var F=true;var o=10;var w=0.95;var A=0;var d=false;var z=false;var j=[];D.hooks.processOptions.push(g);D.hooks.bindEvents.push(e);function g(O,N){if(N.series.pie.show){N.grid.show=false;if(N.series.pie.label.show=="auto"){if(N.legend.show){N.series.pie.label.show=false}else{N.series.pie.label.show=true}}if(N.series.pie.radius=="auto"){if(N.series.pie.label.show){N.series.pie.radius=3/4}else{N.series.pie.radius=1}}if(N.series.pie.tilt>1){N.series.pie.tilt=1}if(N.series.pie.tilt<0){N.series.pie.tilt=0}O.hooks.processDatapoints.push(E);O.hooks.drawOverlay.push(H);O.hooks.draw.push(r)}}function e(P,N){var O=P.getOptions();if(O.series.pie.show&&O.grid.hoverable){N.unbind("mousemove").mousemove(t)}if(O.series.pie.show&&O.grid.clickable){N.unbind("click").click(l)}}function G(O){var P="";function N(S,T){if(!T){T=0}for(var R=0;R<S.length;++R){for(var Q=0;Q<T;Q++){P+="\t"}if(typeof S[R]=="object"){P+=""+R+":\n";N(S[R],T+1)}else{P+=""+R+": "+S[R]+"\n"}}}N(O);alert(P)}function q(P){for(var N=0;N<P.length;++N){var O=parseFloat(P[N].data[0][1]);if(O){M+=O}}}function E(Q,N,O,P){if(!d){d=true;h=Q.getCanvas();L=b(h).parent();a=Q.getOptions();Q.setData(K(Q.getData()))}}function I(){A=L.children().filter(".legend").children().width();n=Math.min(h.width,(h.height/a.series.pie.tilt))/2;p=(h.height/2)+a.series.pie.offset.top;B=(h.width/2);if(a.series.pie.offset.left=="auto"){if(a.legend.position.match("w")){B+=A/2}else{B-=A/2}}else{B+=a.series.pie.offset.left}if(B<n){B=n}else{if(B>h.width-n){B=h.width-n}}}function v(O){for(var N=0;N<O.length;++N){if(typeof(O[N].data)=="number"){O[N].data=[[1,O[N].data]]}else{if(typeof(O[N].data)=="undefined"||typeof(O[N].data[0])=="undefined"){if(typeof(O[N].data)!="undefined"&&typeof(O[N].data.label)!="undefined"){O[N].label=O[N].data.label}O[N].data=[[1,0]]}}}return O}function K(Q){Q=v(Q);q(Q);var P=0;var S=0;var N=a.series.pie.combine.color;var R=[];for(var O=0;O<Q.length;++O){Q[O].data[0][1]=parseFloat(Q[O].data[0][1]);if(!Q[O].data[0][1]){Q[O].data[0][1]=0}if(Q[O].data[0][1]/M<=a.series.pie.combine.threshold){P+=Q[O].data[0][1];S++;if(!N){N=Q[O].color}}else{R.push({data:[[1,Q[O].data[0][1]]],color:Q[O].color,label:Q[O].label,angle:(Q[O].data[0][1]*(Math.PI*2))/M,percent:(Q[O].data[0][1]/M*100)})}}if(S>0){R.push({data:[[1,P]],color:N,label:a.series.pie.combine.label,angle:(P*(Math.PI*2))/M,percent:(P/M*100)})}return R}function r(S,Q){if(!L){return}ctx=Q;I();var T=S.getData();var P=0;while(F&&P<o){F=false;if(P>0){n*=w}P+=1;N();if(a.series.pie.tilt<=0.8){O()}R()}if(P>=o){N();L.prepend('<div class="error">Could not draw pie with labels contained inside canvas</div>')}if(S.setSeries&&S.insertLegend){S.setSeries(T);S.insertLegend()}function N(){ctx.clearRect(0,0,h.width,h.height);L.children().filter(".pieLabel, .pieLabelBackground").remove()}function O(){var Z=5;var Y=15;var W=10;var X=0.02;if(a.series.pie.radius>1){var U=a.series.pie.radius}else{var U=n*a.series.pie.radius}if(U>=(h.width/2)-Z||U*a.series.pie.tilt>=(h.height/2)-Y||U<=W){return}ctx.save();ctx.translate(Z,Y);ctx.globalAlpha=X;ctx.fillStyle="#000";ctx.translate(B,p);ctx.scale(1,a.series.pie.tilt);for(var V=1;V<=W;V++){ctx.beginPath();ctx.arc(0,0,U,0,Math.PI*2,false);ctx.fill();U-=V}ctx.restore()}function R(){startAngle=Math.PI*a.series.pie.startAngle;if(a.series.pie.radius>1){var U=a.series.pie.radius}else{var U=n*a.series.pie.radius}ctx.save();ctx.translate(B,p);ctx.scale(1,a.series.pie.tilt);ctx.save();var Y=startAngle;for(var W=0;W<T.length;++W){T[W].startAngle=Y;X(T[W].angle,T[W].color,true)}ctx.restore();ctx.save();ctx.lineWidth=a.series.pie.stroke.width;Y=startAngle;for(var W=0;W<T.length;++W){X(T[W].angle,a.series.pie.stroke.color,false)}ctx.restore();J(ctx);if(a.series.pie.label.show){V()}ctx.restore();function X(ab,Z,aa){if(ab<=0){return}if(aa){ctx.fillStyle=Z}else{ctx.strokeStyle=Z;ctx.lineJoin="round"}ctx.beginPath();if(Math.abs(ab-Math.PI*2)>1e-9){ctx.moveTo(0,0)}else{if(b.browser.msie){ab-=0.0001}}ctx.arc(0,0,U,Y,Y+ab,false);ctx.closePath();Y+=ab;if(aa){ctx.fill()}else{ctx.stroke()}}function V(){var ac=startAngle;if(a.series.pie.label.radius>1){var Z=a.series.pie.label.radius}else{var Z=n*a.series.pie.label.radius}for(var ab=0;ab<T.length;++ab){if(T[ab].percent>=a.series.pie.label.threshold*100){aa(T[ab],ac,ab)}ac+=T[ab].angle}function aa(ap,ai,ag){if(ap.data[0][1]==0){return}var ar=a.legend.labelFormatter,aq,ae=a.series.pie.label.formatter;if(ar){aq=ar(ap.label,ap)}else{aq=ap.label}if(ae){aq=ae(aq,ap)}var aj=((ai+ap.angle)+ai)/2;var ao=B+Math.round(Math.cos(aj)*Z);var am=p+Math.round(Math.sin(aj)*Z)*a.series.pie.tilt;var af='<span class="pieLabel" id="pieLabel'+ag+'" style="position:absolute;top:'+am+"px;left:"+ao+'px;">'+aq+"</span>";L.append(af);var an=L.children("#pieLabel"+ag);var ad=(am-an.height()/2);var ah=(ao-an.width()/2);an.css("top",ad);an.css("left",ah);if(0-ad>0||0-ah>0||h.height-(ad+an.height())<0||h.width-(ah+an.width())<0){F=true}if(a.series.pie.label.background.opacity!=0){var ak=a.series.pie.label.background.color;if(ak==null){ak=ap.color}var al="top:"+ad+"px;left:"+ah+"px;";b('<div class="pieLabelBackground" style="position:absolute;width:'+an.width()+"px;height:"+an.height()+"px;"+al+"background-color:"+ak+';"> </div>').insertBefore(an).css("opacity",a.series.pie.label.background.opacity)}}}}}function J(N){if(a.series.pie.innerRadius>0){N.save();innerRadius=a.series.pie.innerRadius>1?a.series.pie.innerRadius:n*a.series.pie.innerRadius;N.globalCompositeOperation="destination-out";N.beginPath();N.fillStyle=a.series.pie.stroke.color;N.arc(0,0,innerRadius,0,Math.PI*2,false);N.fill();N.closePath();N.restore();N.save();N.beginPath();N.strokeStyle=a.series.pie.stroke.color;N.arc(0,0,innerRadius,0,Math.PI*2,false);N.stroke();N.closePath();N.restore()}}function s(Q,R){for(var S=false,P=-1,N=Q.length,O=N-1;++P<N;O=P){((Q[P][1]<=R[1]&&R[1]<Q[O][1])||(Q[O][1]<=R[1]&&R[1]<Q[P][1]))&&(R[0]<(Q[O][0]-Q[P][0])*(R[1]-Q[P][1])/(Q[O][1]-Q[P][1])+Q[P][0])&&(S=!S)}return S}function u(R,P){var T=D.getData(),O=D.getOptions(),N=O.series.pie.radius>1?O.series.pie.radius:n*O.series.pie.radius;for(var Q=0;Q<T.length;++Q){var S=T[Q];if(S.pie.show){ctx.save();ctx.beginPath();ctx.moveTo(0,0);ctx.arc(0,0,N,S.startAngle,S.startAngle+S.angle,false);ctx.closePath();x=R-B;y=P-p;if(ctx.isPointInPath){if(ctx.isPointInPath(R-B,P-p)){ctx.restore();return{datapoint:[S.percent,S.data],dataIndex:0,series:S,seriesIndex:Q}}}else{p1X=(N*Math.cos(S.startAngle));p1Y=(N*Math.sin(S.startAngle));p2X=(N*Math.cos(S.startAngle+(S.angle/4)));p2Y=(N*Math.sin(S.startAngle+(S.angle/4)));p3X=(N*Math.cos(S.startAngle+(S.angle/2)));p3Y=(N*Math.sin(S.startAngle+(S.angle/2)));p4X=(N*Math.cos(S.startAngle+(S.angle/1.5)));p4Y=(N*Math.sin(S.startAngle+(S.angle/1.5)));p5X=(N*Math.cos(S.startAngle+S.angle));p5Y=(N*Math.sin(S.startAngle+S.angle));arrPoly=[[0,0],[p1X,p1Y],[p2X,p2Y],[p3X,p3Y],[p4X,p4Y],[p5X,p5Y]];arrPoint=[x,y];if(s(arrPoly,arrPoint)){ctx.restore();return{datapoint:[S.percent,S.data],dataIndex:0,series:S,seriesIndex:Q}}}ctx.restore()}}return null}function t(N){m("plothover",N)}function l(N){m("plotclick",N)}function m(N,T){var O=D.offset(),R=parseInt(T.pageX-O.left),P=parseInt(T.pageY-O.top),V=u(R,P);if(a.grid.autoHighlight){for(var Q=0;Q<j.length;++Q){var S=j[Q];if(S.auto==N&&!(V&&S.series==V.series)){f(S.series)}}}if(V){k(V.series,N)}var U={pageX:T.pageX,pageY:T.pageY};L.trigger(N,[U,V])}function k(O,P){if(typeof O=="number"){O=series[O]}var N=C(O);if(N==-1){j.push({series:O,auto:P});D.triggerRedrawOverlay()}else{if(!P){j[N].auto=false}}}function f(O){if(O==null){j=[];D.triggerRedrawOverlay()}if(typeof O=="number"){O=series[O]}var N=C(O);if(N!=-1){j.splice(N,1);D.triggerRedrawOverlay()}}function C(P){for(var N=0;N<j.length;++N){var O=j[N];if(O.series==P){return N}}return -1}function H(Q,R){var P=Q.getOptions();var N=P.series.pie.radius>1?P.series.pie.radius:n*P.series.pie.radius;R.save();R.translate(B,p);R.scale(1,P.series.pie.tilt);for(i=0;i<j.length;++i){O(j[i].series)}J(R);R.restore();function O(S){if(S.angle<0){return}R.fillStyle="rgba(255, 255, 255, "+P.series.pie.highlight.opacity+")";R.beginPath();if(Math.abs(S.angle-Math.PI*2)>1e-9){R.moveTo(0,0)}R.arc(0,0,N,S.startAngle,S.startAngle+S.angle,false);R.closePath();R.fill()}}}var a={series:{pie:{show:false,radius:"auto",innerRadius:0,startAngle:3/2,tilt:1,offset:{top:0,left:"auto"},stroke:{color:"#FFF",width:1},label:{show:"auto",formatter:function(d,e){return'<div style="font-size:x-small;text-align:center;padding:2px;color:'+e.color+';">'+d+"<br/>"+Math.round(e.percent)+"%</div>"},radius:1,background:{color:null,opacity:0},threshold:0},combine:{threshold:-1,color:null,label:"Other"},highlight:{opacity:0.5}}}};b.plot.plugins.push({init:c,options:a,name:"pie",version:"1.0"})})(jQuery);
@@ -0,0 +1,60 @@
1
+ /*
2
+ Flot plugin for automatically redrawing plots when the placeholder
3
+ size changes, e.g. on window resizes.
4
+
5
+ It works by listening for changes on the placeholder div (through the
6
+ jQuery resize event plugin) - if the size changes, it will redraw the
7
+ plot.
8
+
9
+ There are no options. If you need to disable the plugin for some
10
+ plots, you can just fix the size of their placeholders.
11
+ */
12
+
13
+
14
+ /* Inline dependency:
15
+ * jQuery resize event - v1.1 - 3/14/2010
16
+ * http://benalman.com/projects/jquery-resize-plugin/
17
+ *
18
+ * Copyright (c) 2010 "Cowboy" Ben Alman
19
+ * Dual licensed under the MIT and GPL licenses.
20
+ * http://benalman.com/about/license/
21
+ */
22
+ (function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);
23
+
24
+
25
+ (function ($) {
26
+ var options = { }; // no options
27
+
28
+ function init(plot) {
29
+ function onResize() {
30
+ var placeholder = plot.getPlaceholder();
31
+
32
+ // somebody might have hidden us and we can't plot
33
+ // when we don't have the dimensions
34
+ if (placeholder.width() == 0 || placeholder.height() == 0)
35
+ return;
36
+
37
+ plot.resize();
38
+ plot.setupGrid();
39
+ plot.draw();
40
+ }
41
+
42
+ function bindEvents(plot, eventHolder) {
43
+ plot.getPlaceholder().resize(onResize);
44
+ }
45
+
46
+ function shutdown(plot, eventHolder) {
47
+ plot.getPlaceholder().unbind("resize", onResize);
48
+ }
49
+
50
+ plot.hooks.bindEvents.push(bindEvents);
51
+ plot.hooks.shutdown.push(shutdown);
52
+ }
53
+
54
+ $.plot.plugins.push({
55
+ init: init,
56
+ options: options,
57
+ name: 'resize',
58
+ version: '1.0'
59
+ });
60
+ })(jQuery);
@@ -0,0 +1 @@
1
+ (function(n,p,u){var w=n([]),s=n.resize=n.extend(n.resize,{}),o,l="setTimeout",m="resize",t=m+"-special-event",v="delay",r="throttleWindow";s[v]=250;s[r]=true;n.event.special[m]={setup:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.add(a);n.data(this,t,{w:a.width(),h:a.height()});if(w.length===1){q()}},teardown:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.not(a);a.removeData(t);if(!w.length){clearTimeout(o)}},add:function(b){if(!s[r]&&this[l]){return false}var c;function a(d,h,g){var f=n(this),e=n.data(this,t);e.w=h!==u?h:f.width();e.h=g!==u?g:f.height();c.apply(this,arguments)}if(n.isFunction(b)){c=b;return a}else{c=b.handler;b.handler=a}}};function q(){o=p[l](function(){w.each(function(){var d=n(this),a=d.width(),b=d.height(),c=n.data(this,t);if(a!==c.w||b!==c.h){d.trigger(m,[c.w=a,c.h=b])}});q()},s[v])}})(jQuery,this);(function(b){var a={};function c(f){function e(){var h=f.getPlaceholder();if(h.width()==0||h.height()==0){return}f.resize();f.setupGrid();f.draw()}function g(i,h){i.getPlaceholder().resize(e)}function d(i,h){i.getPlaceholder().unbind("resize",e)}f.hooks.bindEvents.push(g);f.hooks.shutdown.push(d)}b.plot.plugins.push({init:c,options:a,name:"resize",version:"1.0"})})(jQuery);
@@ -0,0 +1,344 @@
1
+ /*
2
+ Flot plugin for selecting regions.
3
+
4
+ The plugin defines the following options:
5
+
6
+ selection: {
7
+ mode: null or "x" or "y" or "xy",
8
+ color: color
9
+ }
10
+
11
+ Selection support is enabled by setting the mode to one of "x", "y" or
12
+ "xy". In "x" mode, the user will only be able to specify the x range,
13
+ similarly for "y" mode. For "xy", the selection becomes a rectangle
14
+ where both ranges can be specified. "color" is color of the selection
15
+ (if you need to change the color later on, you can get to it with
16
+ plot.getOptions().selection.color).
17
+
18
+ When selection support is enabled, a "plotselected" event will be
19
+ emitted on the DOM element you passed into the plot function. The
20
+ event handler gets a parameter with the ranges selected on the axes,
21
+ like this:
22
+
23
+ placeholder.bind("plotselected", function(event, ranges) {
24
+ alert("You selected " + ranges.xaxis.from + " to " + ranges.xaxis.to)
25
+ // similar for yaxis - with multiple axes, the extra ones are in
26
+ // x2axis, x3axis, ...
27
+ });
28
+
29
+ The "plotselected" event is only fired when the user has finished
30
+ making the selection. A "plotselecting" event is fired during the
31
+ process with the same parameters as the "plotselected" event, in case
32
+ you want to know what's happening while it's happening,
33
+
34
+ A "plotunselected" event with no arguments is emitted when the user
35
+ clicks the mouse to remove the selection.
36
+
37
+ The plugin allso adds the following methods to the plot object:
38
+
39
+ - setSelection(ranges, preventEvent)
40
+
41
+ Set the selection rectangle. The passed in ranges is on the same
42
+ form as returned in the "plotselected" event. If the selection mode
43
+ is "x", you should put in either an xaxis range, if the mode is "y"
44
+ you need to put in an yaxis range and both xaxis and yaxis if the
45
+ selection mode is "xy", like this:
46
+
47
+ setSelection({ xaxis: { from: 0, to: 10 }, yaxis: { from: 40, to: 60 } });
48
+
49
+ setSelection will trigger the "plotselected" event when called. If
50
+ you don't want that to happen, e.g. if you're inside a
51
+ "plotselected" handler, pass true as the second parameter. If you
52
+ are using multiple axes, you can specify the ranges on any of those,
53
+ e.g. as x2axis/x3axis/... instead of xaxis, the plugin picks the
54
+ first one it sees.
55
+
56
+ - clearSelection(preventEvent)
57
+
58
+ Clear the selection rectangle. Pass in true to avoid getting a
59
+ "plotunselected" event.
60
+
61
+ - getSelection()
62
+
63
+ Returns the current selection in the same format as the
64
+ "plotselected" event. If there's currently no selection, the
65
+ function returns null.
66
+
67
+ */
68
+
69
+ (function ($) {
70
+ function init(plot) {
71
+ var selection = {
72
+ first: { x: -1, y: -1}, second: { x: -1, y: -1},
73
+ show: false,
74
+ active: false
75
+ };
76
+
77
+ // FIXME: The drag handling implemented here should be
78
+ // abstracted out, there's some similar code from a library in
79
+ // the navigation plugin, this should be massaged a bit to fit
80
+ // the Flot cases here better and reused. Doing this would
81
+ // make this plugin much slimmer.
82
+ var savedhandlers = {};
83
+
84
+ var mouseUpHandler = null;
85
+
86
+ function onMouseMove(e) {
87
+ if (selection.active) {
88
+ updateSelection(e);
89
+
90
+ plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]);
91
+ }
92
+ }
93
+
94
+ function onMouseDown(e) {
95
+ if (e.which != 1) // only accept left-click
96
+ return;
97
+
98
+ // cancel out any text selections
99
+ document.body.focus();
100
+
101
+ // prevent text selection and drag in old-school browsers
102
+ if (document.onselectstart !== undefined && savedhandlers.onselectstart == null) {
103
+ savedhandlers.onselectstart = document.onselectstart;
104
+ document.onselectstart = function () { return false; };
105
+ }
106
+ if (document.ondrag !== undefined && savedhandlers.ondrag == null) {
107
+ savedhandlers.ondrag = document.ondrag;
108
+ document.ondrag = function () { return false; };
109
+ }
110
+
111
+ setSelectionPos(selection.first, e);
112
+
113
+ selection.active = true;
114
+
115
+ // this is a bit silly, but we have to use a closure to be
116
+ // able to whack the same handler again
117
+ mouseUpHandler = function (e) { onMouseUp(e); };
118
+
119
+ $(document).one("mouseup", mouseUpHandler);
120
+ }
121
+
122
+ function onMouseUp(e) {
123
+ mouseUpHandler = null;
124
+
125
+ // revert drag stuff for old-school browsers
126
+ if (document.onselectstart !== undefined)
127
+ document.onselectstart = savedhandlers.onselectstart;
128
+ if (document.ondrag !== undefined)
129
+ document.ondrag = savedhandlers.ondrag;
130
+
131
+ // no more dragging
132
+ selection.active = false;
133
+ updateSelection(e);
134
+
135
+ if (selectionIsSane())
136
+ triggerSelectedEvent();
137
+ else {
138
+ // this counts as a clear
139
+ plot.getPlaceholder().trigger("plotunselected", [ ]);
140
+ plot.getPlaceholder().trigger("plotselecting", [ null ]);
141
+ }
142
+
143
+ return false;
144
+ }
145
+
146
+ function getSelection() {
147
+ if (!selectionIsSane())
148
+ return null;
149
+
150
+ var r = {}, c1 = selection.first, c2 = selection.second;
151
+ $.each(plot.getAxes(), function (name, axis) {
152
+ if (axis.used) {
153
+ var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]);
154
+ r[name] = { from: Math.min(p1, p2), to: Math.max(p1, p2) };
155
+ }
156
+ });
157
+ return r;
158
+ }
159
+
160
+ function triggerSelectedEvent() {
161
+ var r = getSelection();
162
+
163
+ plot.getPlaceholder().trigger("plotselected", [ r ]);
164
+
165
+ // backwards-compat stuff, to be removed in future
166
+ if (r.xaxis && r.yaxis)
167
+ plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
168
+ }
169
+
170
+ function clamp(min, value, max) {
171
+ return value < min ? min: (value > max ? max: value);
172
+ }
173
+
174
+ function setSelectionPos(pos, e) {
175
+ var o = plot.getOptions();
176
+ var offset = plot.getPlaceholder().offset();
177
+ var plotOffset = plot.getPlotOffset();
178
+ pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width());
179
+ pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height());
180
+
181
+ if (o.selection.mode == "y")
182
+ pos.x = pos == selection.first ? 0 : plot.width();
183
+
184
+ if (o.selection.mode == "x")
185
+ pos.y = pos == selection.first ? 0 : plot.height();
186
+ }
187
+
188
+ function updateSelection(pos) {
189
+ if (pos.pageX == null)
190
+ return;
191
+
192
+ setSelectionPos(selection.second, pos);
193
+ if (selectionIsSane()) {
194
+ selection.show = true;
195
+ plot.triggerRedrawOverlay();
196
+ }
197
+ else
198
+ clearSelection(true);
199
+ }
200
+
201
+ function clearSelection(preventEvent) {
202
+ if (selection.show) {
203
+ selection.show = false;
204
+ plot.triggerRedrawOverlay();
205
+ if (!preventEvent)
206
+ plot.getPlaceholder().trigger("plotunselected", [ ]);
207
+ }
208
+ }
209
+
210
+ // function taken from markings support in Flot
211
+ function extractRange(ranges, coord) {
212
+ var axis, from, to, key, axes = plot.getAxes();
213
+
214
+ for (var k in axes) {
215
+ axis = axes[k];
216
+ if (axis.direction == coord) {
217
+ key = coord + axis.n + "axis";
218
+ if (!ranges[key] && axis.n == 1)
219
+ key = coord + "axis"; // support x1axis as xaxis
220
+ if (ranges[key]) {
221
+ from = ranges[key].from;
222
+ to = ranges[key].to;
223
+ break;
224
+ }
225
+ }
226
+ }
227
+
228
+ // backwards-compat stuff - to be removed in future
229
+ if (!ranges[key]) {
230
+ axis = coord == "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
231
+ from = ranges[coord + "1"];
232
+ to = ranges[coord + "2"];
233
+ }
234
+
235
+ // auto-reverse as an added bonus
236
+ if (from != null && to != null && from > to) {
237
+ var tmp = from;
238
+ from = to;
239
+ to = tmp;
240
+ }
241
+
242
+ return { from: from, to: to, axis: axis };
243
+ }
244
+
245
+ function setSelection(ranges, preventEvent) {
246
+ var axis, range, o = plot.getOptions();
247
+
248
+ if (o.selection.mode == "y") {
249
+ selection.first.x = 0;
250
+ selection.second.x = plot.width();
251
+ }
252
+ else {
253
+ range = extractRange(ranges, "x");
254
+
255
+ selection.first.x = range.axis.p2c(range.from);
256
+ selection.second.x = range.axis.p2c(range.to);
257
+ }
258
+
259
+ if (o.selection.mode == "x") {
260
+ selection.first.y = 0;
261
+ selection.second.y = plot.height();
262
+ }
263
+ else {
264
+ range = extractRange(ranges, "y");
265
+
266
+ selection.first.y = range.axis.p2c(range.from);
267
+ selection.second.y = range.axis.p2c(range.to);
268
+ }
269
+
270
+ selection.show = true;
271
+ plot.triggerRedrawOverlay();
272
+ if (!preventEvent && selectionIsSane())
273
+ triggerSelectedEvent();
274
+ }
275
+
276
+ function selectionIsSane() {
277
+ var minSize = 5;
278
+ return Math.abs(selection.second.x - selection.first.x) >= minSize &&
279
+ Math.abs(selection.second.y - selection.first.y) >= minSize;
280
+ }
281
+
282
+ plot.clearSelection = clearSelection;
283
+ plot.setSelection = setSelection;
284
+ plot.getSelection = getSelection;
285
+
286
+ plot.hooks.bindEvents.push(function(plot, eventHolder) {
287
+ var o = plot.getOptions();
288
+ if (o.selection.mode != null) {
289
+ eventHolder.mousemove(onMouseMove);
290
+ eventHolder.mousedown(onMouseDown);
291
+ }
292
+ });
293
+
294
+
295
+ plot.hooks.drawOverlay.push(function (plot, ctx) {
296
+ // draw selection
297
+ if (selection.show && selectionIsSane()) {
298
+ var plotOffset = plot.getPlotOffset();
299
+ var o = plot.getOptions();
300
+
301
+ ctx.save();
302
+ ctx.translate(plotOffset.left, plotOffset.top);
303
+
304
+ var c = $.color.parse(o.selection.color);
305
+
306
+ ctx.strokeStyle = c.scale('a', 0.8).toString();
307
+ ctx.lineWidth = 1;
308
+ ctx.lineJoin = "round";
309
+ ctx.fillStyle = c.scale('a', 0.4).toString();
310
+
311
+ var x = Math.min(selection.first.x, selection.second.x),
312
+ y = Math.min(selection.first.y, selection.second.y),
313
+ w = Math.abs(selection.second.x - selection.first.x),
314
+ h = Math.abs(selection.second.y - selection.first.y);
315
+
316
+ ctx.fillRect(x, y, w, h);
317
+ ctx.strokeRect(x, y, w, h);
318
+
319
+ ctx.restore();
320
+ }
321
+ });
322
+
323
+ plot.hooks.shutdown.push(function (plot, eventHolder) {
324
+ eventHolder.unbind("mousemove", onMouseMove);
325
+ eventHolder.unbind("mousedown", onMouseDown);
326
+
327
+ if (mouseUpHandler)
328
+ $(document).unbind("mouseup", mouseUpHandler);
329
+ });
330
+
331
+ }
332
+
333
+ $.plot.plugins.push({
334
+ init: init,
335
+ options: {
336
+ selection: {
337
+ mode: null, // one of null, "x", "y" or "xy"
338
+ color: "#e8cfac"
339
+ }
340
+ },
341
+ name: 'selection',
342
+ version: '1.1'
343
+ });
344
+ })(jQuery);
@@ -0,0 +1 @@
1
+ (function(a){function b(k){var p={first:{x:-1,y:-1},second:{x:-1,y:-1},show:false,active:false};var m={};var r=null;function e(s){if(p.active){l(s);k.getPlaceholder().trigger("plotselecting",[g()])}}function n(s){if(s.which!=1){return}document.body.focus();if(document.onselectstart!==undefined&&m.onselectstart==null){m.onselectstart=document.onselectstart;document.onselectstart=function(){return false}}if(document.ondrag!==undefined&&m.ondrag==null){m.ondrag=document.ondrag;document.ondrag=function(){return false}}d(p.first,s);p.active=true;r=function(t){j(t)};a(document).one("mouseup",r)}function j(s){r=null;if(document.onselectstart!==undefined){document.onselectstart=m.onselectstart}if(document.ondrag!==undefined){document.ondrag=m.ondrag}p.active=false;l(s);if(f()){i()}else{k.getPlaceholder().trigger("plotunselected",[]);k.getPlaceholder().trigger("plotselecting",[null])}return false}function g(){if(!f()){return null}var u={},t=p.first,s=p.second;a.each(k.getAxes(),function(v,w){if(w.used){var y=w.c2p(t[w.direction]),x=w.c2p(s[w.direction]);u[v]={from:Math.min(y,x),to:Math.max(y,x)}}});return u}function i(){var s=g();k.getPlaceholder().trigger("plotselected",[s]);if(s.xaxis&&s.yaxis){k.getPlaceholder().trigger("selected",[{x1:s.xaxis.from,y1:s.yaxis.from,x2:s.xaxis.to,y2:s.yaxis.to}])}}function h(t,u,s){return u<t?t:(u>s?s:u)}function d(w,t){var v=k.getOptions();var u=k.getPlaceholder().offset();var s=k.getPlotOffset();w.x=h(0,t.pageX-u.left-s.left,k.width());w.y=h(0,t.pageY-u.top-s.top,k.height());if(v.selection.mode=="y"){w.x=w==p.first?0:k.width()}if(v.selection.mode=="x"){w.y=w==p.first?0:k.height()}}function l(s){if(s.pageX==null){return}d(p.second,s);if(f()){p.show=true;k.triggerRedrawOverlay()}else{q(true)}}function q(s){if(p.show){p.show=false;k.triggerRedrawOverlay();if(!s){k.getPlaceholder().trigger("plotunselected",[])}}}function c(s,w){var t,y,z,A,x=k.getAxes();for(var u in x){t=x[u];if(t.direction==w){A=w+t.n+"axis";if(!s[A]&&t.n==1){A=w+"axis"}if(s[A]){y=s[A].from;z=s[A].to;break}}}if(!s[A]){t=w=="x"?k.getXAxes()[0]:k.getYAxes()[0];y=s[w+"1"];z=s[w+"2"]}if(y!=null&&z!=null&&y>z){var v=y;y=z;z=v}return{from:y,to:z,axis:t}}function o(t,s){var v,u,w=k.getOptions();if(w.selection.mode=="y"){p.first.x=0;p.second.x=k.width()}else{u=c(t,"x");p.first.x=u.axis.p2c(u.from);p.second.x=u.axis.p2c(u.to)}if(w.selection.mode=="x"){p.first.y=0;p.second.y=k.height()}else{u=c(t,"y");p.first.y=u.axis.p2c(u.from);p.second.y=u.axis.p2c(u.to)}p.show=true;k.triggerRedrawOverlay();if(!s&&f()){i()}}function f(){var s=5;return Math.abs(p.second.x-p.first.x)>=s&&Math.abs(p.second.y-p.first.y)>=s}k.clearSelection=q;k.setSelection=o;k.getSelection=g;k.hooks.bindEvents.push(function(t,s){var u=t.getOptions();if(u.selection.mode!=null){s.mousemove(e);s.mousedown(n)}});k.hooks.drawOverlay.push(function(v,D){if(p.show&&f()){var t=v.getPlotOffset();var s=v.getOptions();D.save();D.translate(t.left,t.top);var z=a.color.parse(s.selection.color);D.strokeStyle=z.scale("a",0.8).toString();D.lineWidth=1;D.lineJoin="round";D.fillStyle=z.scale("a",0.4).toString();var B=Math.min(p.first.x,p.second.x),A=Math.min(p.first.y,p.second.y),C=Math.abs(p.second.x-p.first.x),u=Math.abs(p.second.y-p.first.y);D.fillRect(B,A,C,u);D.strokeRect(B,A,C,u);D.restore()}});k.hooks.shutdown.push(function(t,s){s.unbind("mousemove",e);s.unbind("mousedown",n);if(r){a(document).unbind("mouseup",r)}})}a.plot.plugins.push({init:b,options:{selection:{mode:null,color:"#e8cfac"}},name:"selection",version:"1.1"})})(jQuery);
@@ -0,0 +1,184 @@
1
+ /*
2
+ Flot plugin for stacking data sets, i.e. putting them on top of each
3
+ other, for accumulative graphs.
4
+
5
+ The plugin assumes the data is sorted on x (or y if stacking
6
+ horizontally). For line charts, it is assumed that if a line has an
7
+ undefined gap (from a null point), then the line above it should have
8
+ the same gap - insert zeros instead of "null" if you want another
9
+ behaviour. This also holds for the start and end of the chart. Note
10
+ that stacking a mix of positive and negative values in most instances
11
+ doesn't make sense (so it looks weird).
12
+
13
+ Two or more series are stacked when their "stack" attribute is set to
14
+ the same key (which can be any number or string or just "true"). To
15
+ specify the default stack, you can set
16
+
17
+ series: {
18
+ stack: null or true or key (number/string)
19
+ }
20
+
21
+ or specify it for a specific series
22
+
23
+ $.plot($("#placeholder"), [{ data: [ ... ], stack: true }])
24
+
25
+ The stacking order is determined by the order of the data series in
26
+ the array (later series end up on top of the previous).
27
+
28
+ Internally, the plugin modifies the datapoints in each series, adding
29
+ an offset to the y value. For line series, extra data points are
30
+ inserted through interpolation. If there's a second y value, it's also
31
+ adjusted (e.g for bar charts or filled areas).
32
+ */
33
+
34
+ (function ($) {
35
+ var options = {
36
+ series: { stack: null } // or number/string
37
+ };
38
+
39
+ function init(plot) {
40
+ function findMatchingSeries(s, allseries) {
41
+ var res = null
42
+ for (var i = 0; i < allseries.length; ++i) {
43
+ if (s == allseries[i])
44
+ break;
45
+
46
+ if (allseries[i].stack == s.stack)
47
+ res = allseries[i];
48
+ }
49
+
50
+ return res;
51
+ }
52
+
53
+ function stackData(plot, s, datapoints) {
54
+ if (s.stack == null)
55
+ return;
56
+
57
+ var other = findMatchingSeries(s, plot.getData());
58
+ if (!other)
59
+ return;
60
+
61
+ var ps = datapoints.pointsize,
62
+ points = datapoints.points,
63
+ otherps = other.datapoints.pointsize,
64
+ otherpoints = other.datapoints.points,
65
+ newpoints = [],
66
+ px, py, intery, qx, qy, bottom,
67
+ withlines = s.lines.show,
68
+ horizontal = s.bars.horizontal,
69
+ withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y),
70
+ withsteps = withlines && s.lines.steps,
71
+ fromgap = true,
72
+ keyOffset = horizontal ? 1 : 0,
73
+ accumulateOffset = horizontal ? 0 : 1,
74
+ i = 0, j = 0, l;
75
+
76
+ while (true) {
77
+ if (i >= points.length)
78
+ break;
79
+
80
+ l = newpoints.length;
81
+
82
+ if (points[i] == null) {
83
+ // copy gaps
84
+ for (m = 0; m < ps; ++m)
85
+ newpoints.push(points[i + m]);
86
+ i += ps;
87
+ }
88
+ else if (j >= otherpoints.length) {
89
+ // for lines, we can't use the rest of the points
90
+ if (!withlines) {
91
+ for (m = 0; m < ps; ++m)
92
+ newpoints.push(points[i + m]);
93
+ }
94
+ i += ps;
95
+ }
96
+ else if (otherpoints[j] == null) {
97
+ // oops, got a gap
98
+ for (m = 0; m < ps; ++m)
99
+ newpoints.push(null);
100
+ fromgap = true;
101
+ j += otherps;
102
+ }
103
+ else {
104
+ // cases where we actually got two points
105
+ px = points[i + keyOffset];
106
+ py = points[i + accumulateOffset];
107
+ qx = otherpoints[j + keyOffset];
108
+ qy = otherpoints[j + accumulateOffset];
109
+ bottom = 0;
110
+
111
+ if (px == qx) {
112
+ for (m = 0; m < ps; ++m)
113
+ newpoints.push(points[i + m]);
114
+
115
+ newpoints[l + accumulateOffset] += qy;
116
+ bottom = qy;
117
+
118
+ i += ps;
119
+ j += otherps;
120
+ }
121
+ else if (px > qx) {
122
+ // we got past point below, might need to
123
+ // insert interpolated extra point
124
+ if (withlines && i > 0 && points[i - ps] != null) {
125
+ intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
126
+ newpoints.push(qx);
127
+ newpoints.push(intery + qy);
128
+ for (m = 2; m < ps; ++m)
129
+ newpoints.push(points[i + m]);
130
+ bottom = qy;
131
+ }
132
+
133
+ j += otherps;
134
+ }
135
+ else { // px < qx
136
+ if (fromgap && withlines) {
137
+ // if we come from a gap, we just skip this point
138
+ i += ps;
139
+ continue;
140
+ }
141
+
142
+ for (m = 0; m < ps; ++m)
143
+ newpoints.push(points[i + m]);
144
+
145
+ // we might be able to interpolate a point below,
146
+ // this can give us a better y
147
+ if (withlines && j > 0 && otherpoints[j - otherps] != null)
148
+ bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
149
+
150
+ newpoints[l + accumulateOffset] += bottom;
151
+
152
+ i += ps;
153
+ }
154
+
155
+ fromgap = false;
156
+
157
+ if (l != newpoints.length && withbottom)
158
+ newpoints[l + 2] += bottom;
159
+ }
160
+
161
+ // maintain the line steps invariant
162
+ if (withsteps && l != newpoints.length && l > 0
163
+ && newpoints[l] != null
164
+ && newpoints[l] != newpoints[l - ps]
165
+ && newpoints[l + 1] != newpoints[l - ps + 1]) {
166
+ for (m = 0; m < ps; ++m)
167
+ newpoints[l + ps + m] = newpoints[l + m];
168
+ newpoints[l + 1] = newpoints[l - ps + 1];
169
+ }
170
+ }
171
+
172
+ datapoints.points = newpoints;
173
+ }
174
+
175
+ plot.hooks.processDatapoints.push(stackData);
176
+ }
177
+
178
+ $.plot.plugins.push({
179
+ init: init,
180
+ options: options,
181
+ name: 'stack',
182
+ version: '1.2'
183
+ });
184
+ })(jQuery);