sunrise-votes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README.rdoc +2 -4
  2. data/Rakefile +0 -22
  3. data/app/controllers/manage/ballot_box/votes_controller.rb +4 -0
  4. data/app/views/manage/ballot_box/votes/show.html.erb +211 -81
  5. data/lib/generators/sunrise/votes/install_generator.rb +1 -1
  6. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/highcharts.js +170 -0
  7. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/highcharts.src.js +11428 -0
  8. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/modules/exporting.js +22 -0
  9. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/modules/exporting.src.js +711 -0
  10. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/themes/dark-blue.js +263 -0
  11. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/themes/dark-green.js +263 -0
  12. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/themes/gray.js +262 -0
  13. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/themes/grid.js +96 -0
  14. data/lib/generators/sunrise/votes/templates/javascripts/highcharts/themes/skies.js +89 -0
  15. data/lib/sunrise/votes/version.rb +1 -1
  16. metadata +33 -79
  17. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/excanvas.min.js +0 -35
  18. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/jquery.jqplot.css +0 -226
  19. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/jquery.jqplot.min.js +0 -30
  20. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.BezierCurveRenderer.js +0 -312
  21. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.BezierCurveRenderer.min.js +0 -30
  22. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.barRenderer.js +0 -702
  23. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.barRenderer.min.js +0 -30
  24. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.blockRenderer.js +0 -234
  25. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.blockRenderer.min.js +0 -30
  26. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.bubbleRenderer.js +0 -748
  27. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.bubbleRenderer.min.js +0 -30
  28. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisLabelRenderer.js +0 -199
  29. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisLabelRenderer.min.js +0 -30
  30. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisTickRenderer.js +0 -238
  31. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisTickRenderer.min.js +0 -30
  32. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasOverlay.js +0 -614
  33. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasOverlay.min.js +0 -30
  34. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasTextRenderer.js +0 -420
  35. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasTextRenderer.min.js +0 -30
  36. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.categoryAxisRenderer.js +0 -634
  37. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.categoryAxisRenderer.min.js +0 -30
  38. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ciParser.js +0 -115
  39. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ciParser.min.js +0 -30
  40. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.cursor.js +0 -1002
  41. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.cursor.min.js +0 -30
  42. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dateAxisRenderer.js +0 -439
  43. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dateAxisRenderer.min.js +0 -30
  44. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.donutRenderer.js +0 -904
  45. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.donutRenderer.min.js +0 -30
  46. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dragable.js +0 -218
  47. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dragable.min.js +0 -30
  48. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.enhancedLegendRenderer.js +0 -199
  49. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.enhancedLegendRenderer.min.js +0 -30
  50. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.funnelRenderer.js +0 -932
  51. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.funnelRenderer.min.js +0 -30
  52. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.highlighter.js +0 -406
  53. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.highlighter.min.js +0 -30
  54. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.json2.js +0 -475
  55. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.json2.min.js +0 -30
  56. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.logAxisRenderer.js +0 -446
  57. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.logAxisRenderer.min.js +0 -30
  58. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoAxisRenderer.js +0 -607
  59. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoAxisRenderer.min.js +0 -30
  60. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoRenderer.js +0 -432
  61. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoRenderer.min.js +0 -30
  62. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.meterGaugeRenderer.js +0 -1142
  63. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.meterGaugeRenderer.min.js +0 -30
  64. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ohlcRenderer.js +0 -372
  65. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ohlcRenderer.min.js +0 -30
  66. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pieRenderer.js +0 -797
  67. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pieRenderer.min.js +0 -30
  68. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pointLabels.js +0 -337
  69. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pointLabels.min.js +0 -30
  70. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.trendline.js +0 -220
  71. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.trendline.min.js +0 -30
@@ -1,30 +0,0 @@
1
- /**
2
- * jqPlot
3
- * Pure JavaScript plotting plugin using jQuery
4
- *
5
- * Version: 1.0.0b1_r746
6
- *
7
- * Copyright (c) 2009-2011 Chris Leonello
8
- * jqPlot is currently available for use in all personal or commercial projects
9
- * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
- * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
- * choose the license that best suits your project and use it accordingly.
12
- *
13
- * Although not required, the author would appreciate an email letting him
14
- * know of any substantial use of jqPlot. You can reach the author at:
15
- * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
- *
17
- * If you are feeling kind and generous, consider supporting the project by
18
- * making a donation at: http://www.jqplot.com/donate.php .
19
- *
20
- * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
- *
22
- * version 2007.04.27
23
- * author Ash Searle
24
- * http://hexmen.com/blog/2007/03/printf-sprintf/
25
- * http://hexmen.com/js/sprintf.js
26
- * The author (Ash Searle) has placed this code in the public domain:
27
- * "This code is unrestricted: you are free to use it however you like."
28
- *
29
- */
30
- (function(a){a.jqplot.CategoryAxisRenderer=function(b){a.jqplot.LinearAxisRenderer.call(this);this.sortMergedLabels=false};a.jqplot.CategoryAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.CategoryAxisRenderer.prototype.constructor=a.jqplot.CategoryAxisRenderer;a.jqplot.CategoryAxisRenderer.prototype.init=function(e){this.groups=1;this.groupLabels=[];this._groupLabels=[];this._grouped=false;this._barsPerGroup=null;a.extend(true,this,{tickOptions:{formatString:"%d"}},e);var b=this._dataBounds;for(var f=0;f<this._series.length;f++){var g=this._series[f];if(g.groups){this.groups=g.groups}var h=g.data;for(var c=0;c<h.length;c++){if(this.name=="xaxis"||this.name=="x2axis"){if(h[c][0]<b.min||b.min==null){b.min=h[c][0]}if(h[c][0]>b.max||b.max==null){b.max=h[c][0]}}else{if(h[c][1]<b.min||b.min==null){b.min=h[c][1]}if(h[c][1]>b.max||b.max==null){b.max=h[c][1]}}}}if(this.groupLabels.length){this.groups=this.groupLabels.length}};a.jqplot.CategoryAxisRenderer.prototype.createTicks=function(){var D=this._ticks;var z=this.ticks;var F=this.name;var C=this._dataBounds;var v,A;var q,w;var d,c;var b,x;if(z.length){if(this.groups>1&&!this._grouped){var r=z.length;var p=parseInt(r/this.groups,10);var e=0;for(var x=p;x<r;x+=p){z.splice(x+e,0," ");e++}this._grouped=true}this.min=0.5;this.max=z.length+0.5;var m=this.max-this.min;this.numberTicks=2*z.length+1;for(x=0;x<z.length;x++){b=this.min+2*x*m/(this.numberTicks-1);var h=new this.tickRenderer(this.tickOptions);h.showLabel=false;h.setTick(b,this.name);this._ticks.push(h);var h=new this.tickRenderer(this.tickOptions);h.label=z[x];h.showMark=false;h.showGridline=false;h.setTick(b+0.5,this.name);this._ticks.push(h)}var h=new this.tickRenderer(this.tickOptions);h.showLabel=false;h.setTick(b+1,this.name);this._ticks.push(h)}else{if(F=="xaxis"||F=="x2axis"){v=this._plotDimensions.width}else{v=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.min!=null&&this.max!=null&&this.tickInterval!=null){if(parseInt((this.max-this.min)/this.tickInterval,10)!=(this.max-this.min)/this.tickInterval){this.tickInterval=null}}var y=[];var B=0;var q=0.5;var w,E;var f=false;for(var x=0;x<this._series.length;x++){var k=this._series[x];for(var u=0;u<k.data.length;u++){if(this.name=="xaxis"||this.name=="x2axis"){E=k.data[u][0]}else{E=k.data[u][1]}if(a.inArray(E,y)==-1){f=true;B+=1;y.push(E)}}}if(f&&this.sortMergedLabels){y.sort(function(j,i){return j-i})}this.ticks=y;for(var x=0;x<this._series.length;x++){var k=this._series[x];for(var u=0;u<k.data.length;u++){if(this.name=="xaxis"||this.name=="x2axis"){E=k.data[u][0]}else{E=k.data[u][1]}var n=a.inArray(E,y)+1;if(this.name=="xaxis"||this.name=="x2axis"){k.data[u][0]=n}else{k.data[u][1]=n}}}if(this.groups>1&&!this._grouped){var r=y.length;var p=parseInt(r/this.groups,10);var e=0;for(var x=p;x<r;x+=p+1){y[x]=" "}this._grouped=true}w=B+0.5;if(this.numberTicks==null){this.numberTicks=2*B+1}var m=w-q;this.min=q;this.max=w;var o=0;var g=parseInt(3+v/20,10);var p=parseInt(B/g,10);if(this.tickInterval==null){this.tickInterval=m/(this.numberTicks-1)}for(var x=0;x<this.numberTicks;x++){b=this.min+x*this.tickInterval;var h=new this.tickRenderer(this.tickOptions);if(x/2==parseInt(x/2,10)){h.showLabel=false;h.showMark=true}else{if(p>0&&o<p){h.showLabel=false;o+=1}else{h.showLabel=true;o=0}h.label=h.formatter(h.formatString,y[(x-1)/2]);h.showMark=false;h.showGridline=false}h.setTick(b,this.name);this._ticks.push(h)}}};a.jqplot.CategoryAxisRenderer.prototype.draw=function(b){if(this.show){this.renderer.createTicks.call(this);var h=0;var c;if(this._elem){this._elem.empty()}this._elem=this._elem||a('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');if(this.name=="xaxis"||this.name=="x2axis"){this._elem.width(this._plotDimensions.width)}else{this._elem.height(this._plotDimensions.height)}this.labelOptions.axis=this.name;this._label=new this.labelRenderer(this.labelOptions);if(this._label.show){var g=this._label.draw(b);g.appendTo(this._elem)}var f=this._ticks;for(var e=0;e<f.length;e++){var d=f[e];if(d.showLabel&&(!d.isMinorTick||this.showMinorTicks)){var g=d.draw(b);g.appendTo(this._elem)}}this._groupLabels=[];for(var e=0;e<this.groupLabels.length;e++){var g=a('<div style="position:absolute;" class="jqplot-'+this.name+'-groupLabel"></div>');g.html(this.groupLabels[e]);this._groupLabels.push(g);g.appendTo(this._elem)}}return this._elem};a.jqplot.CategoryAxisRenderer.prototype.set=function(){var e=0;var m;var k=0;var f=0;var d=(this._label==null)?false:this._label.show;if(this.show){var n=this._ticks;for(var c=0;c<n.length;c++){var g=n[c];if(g.showLabel&&(!g.isMinorTick||this.showMinorTicks)){if(this.name=="xaxis"||this.name=="x2axis"){m=g._elem.outerHeight(true)}else{m=g._elem.outerWidth(true)}if(m>e){e=m}}}var j=0;for(var c=0;c<this._groupLabels.length;c++){var b=this._groupLabels[c];if(this.name=="xaxis"||this.name=="x2axis"){m=b.outerHeight(true)}else{m=b.outerWidth(true)}if(m>j){j=m}}if(d){k=this._label._elem.outerWidth(true);f=this._label._elem.outerHeight(true)}if(this.name=="xaxis"){e+=j+f;this._elem.css({height:e+"px",left:"0px",bottom:"0px"})}else{if(this.name=="x2axis"){e+=j+f;this._elem.css({height:e+"px",left:"0px",top:"0px"})}else{if(this.name=="yaxis"){e+=j+k;this._elem.css({width:e+"px",left:"0px",top:"0px"});if(d&&this._label.constructor==a.jqplot.AxisLabelRenderer){this._label._elem.css("width",k+"px")}}else{e+=j+k;this._elem.css({width:e+"px",right:"0px",top:"0px"});if(d&&this._label.constructor==a.jqplot.AxisLabelRenderer){this._label._elem.css("width",k+"px")}}}}}};a.jqplot.CategoryAxisRenderer.prototype.pack=function(e,c){var C=this._ticks;var v=this.max;var s=this.min;var n=c.max;var l=c.min;var q=(this._label==null)?false:this._label.show;var x;for(var r in e){this._elem.css(r,e[r])}this._offsets=c;var g=n-l;var k=v-s;this.p2u=function(h){return(h-l)*k/g+s};this.u2p=function(h){return(h-s)*g/k+l};if(this.name=="xaxis"||this.name=="x2axis"){this.series_u2p=function(h){return(h-s)*g/k};this.series_p2u=function(h){return h*k/g+s}}else{this.series_u2p=function(h){return(h-v)*g/k};this.series_p2u=function(h){return h*k/g+v}}if(this.show){if(this.name=="xaxis"||this.name=="x2axis"){for(x=0;x<C.length;x++){var o=C[x];if(o.show&&o.showLabel){var b;if(o.constructor==a.jqplot.CanvasAxisTickRenderer&&o.angle){var A=(this.name=="xaxis")?1:-1;switch(o.labelPosition){case"auto":if(A*o.angle<0){b=-o.getWidth()+o._textRenderer.height*Math.sin(-o._textRenderer.angle)/2}else{b=-o._textRenderer.height*Math.sin(o._textRenderer.angle)/2}break;case"end":b=-o.getWidth()+o._textRenderer.height*Math.sin(-o._textRenderer.angle)/2;break;case"start":b=-o._textRenderer.height*Math.sin(o._textRenderer.angle)/2;break;case"middle":b=-o.getWidth()/2+o._textRenderer.height*Math.sin(-o._textRenderer.angle)/2;break;default:b=-o.getWidth()/2+o._textRenderer.height*Math.sin(-o._textRenderer.angle)/2;break}}else{b=-o.getWidth()/2}var D=this.u2p(o.value)+b+"px";o._elem.css("left",D);o.pack()}}var z=["bottom",0];if(q){var m=this._label._elem.outerWidth(true);this._label._elem.css("left",l+g/2-m/2+"px");if(this.name=="xaxis"){this._label._elem.css("bottom","0px");z=["bottom",this._label._elem.outerHeight(true)]}else{this._label._elem.css("top","0px");z=["top",this._label._elem.outerHeight(true)]}this._label.pack()}var d=parseInt(this._ticks.length/this.groups,10);for(x=0;x<this._groupLabels.length;x++){var B=0;var f=0;for(var u=x*d;u<=(x+1)*d;u++){if(this._ticks[u]._elem&&this._ticks[u].label!=" "){var o=this._ticks[u]._elem;var r=o.position();B+=r.left+o.outerWidth(true)/2;f++}}B=B/f;this._groupLabels[x].css({left:(B-this._groupLabels[x].outerWidth(true)/2)});this._groupLabels[x].css(z[0],z[1])}}else{for(x=0;x<C.length;x++){var o=C[x];if(o.show&&o.showLabel){var b;if(o.constructor==a.jqplot.CanvasAxisTickRenderer&&o.angle){var A=(this.name=="yaxis")?1:-1;switch(o.labelPosition){case"auto":case"end":if(A*o.angle<0){b=-o._textRenderer.height*Math.cos(-o._textRenderer.angle)/2}else{b=-o.getHeight()+o._textRenderer.height*Math.cos(o._textRenderer.angle)/2}break;case"start":if(o.angle>0){b=-o._textRenderer.height*Math.cos(-o._textRenderer.angle)/2}else{b=-o.getHeight()+o._textRenderer.height*Math.cos(o._textRenderer.angle)/2}break;case"middle":b=-o.getHeight()/2;break;default:b=-o.getHeight()/2;break}}else{b=-o.getHeight()/2}var D=this.u2p(o.value)+b+"px";o._elem.css("top",D);o.pack()}}var z=["left",0];if(q){var y=this._label._elem.outerHeight(true);this._label._elem.css("top",n-g/2-y/2+"px");if(this.name=="yaxis"){this._label._elem.css("left","0px");z=["left",this._label._elem.outerWidth(true)]}else{this._label._elem.css("right","0px");z=["right",this._label._elem.outerWidth(true)]}this._label.pack()}var d=parseInt(this._ticks.length/this.groups,10);for(x=0;x<this._groupLabels.length;x++){var B=0;var f=0;for(var u=x*d;u<=(x+1)*d;u++){if(this._ticks[u]._elem&&this._ticks[u].label!=" "){var o=this._ticks[u]._elem;var r=o.position();B+=r.top+o.outerHeight()/2;f++}}B=B/f;this._groupLabels[x].css({top:B-this._groupLabels[x].outerHeight()/2});this._groupLabels[x].css(z[0],z[1])}}}}})(jQuery);
@@ -1,115 +0,0 @@
1
- /**
2
- * jqPlot
3
- * Pure JavaScript plotting plugin using jQuery
4
- *
5
- * Version: 1.0.0b1_r746
6
- *
7
- * Copyright (c) 2009-2011 Chris Leonello
8
- * jqPlot is currently available for use in all personal or commercial projects
9
- * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
- * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
- * choose the license that best suits your project and use it accordingly.
12
- *
13
- * Although not required, the author would appreciate an email letting him
14
- * know of any substantial use of jqPlot. You can reach the author at:
15
- * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
- *
17
- * If you are feeling kind and generous, consider supporting the project by
18
- * making a donation at: http://www.jqplot.com/donate.php .
19
- *
20
- * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
- *
22
- * version 2007.04.27
23
- * author Ash Searle
24
- * http://hexmen.com/blog/2007/03/printf-sprintf/
25
- * http://hexmen.com/js/sprintf.js
26
- * The author (Ash Searle) has placed this code in the public domain:
27
- * "This code is unrestricted: you are free to use it however you like."
28
- *
29
- */
30
- (function($) {
31
- /**
32
- * Class: $.jqplot.ciParser
33
- * Data Renderer function which converts a custom JSON data object into jqPlot data format.
34
- * Set this as a callable on the jqplot dataRenderer plot option:
35
- *
36
- * > plot = $.jqplot('mychart', [data], { dataRenderer: $.jqplot.ciParser, ... });
37
- *
38
- * Where data is an object in JSON format or a JSON encoded string conforming to the
39
- * City Index API spec.
40
- *
41
- * Note that calling the renderer function is handled internally by jqPlot. The
42
- * user does not have to call the function. The parameters described below will
43
- * automatically be passed to the ciParser function.
44
- *
45
- * Parameters:
46
- * data - JSON encoded string or object.
47
- * plot - reference to jqPlot Plot object.
48
- *
49
- * Returns:
50
- * data array in jqPlot format.
51
- *
52
- */
53
- $.jqplot.ciParser = function (data, plot) {
54
- var ret = [],
55
- line,
56
- temp,
57
- i, j, k, kk;
58
-
59
- if (typeof(data) == "string") {
60
- data = $.jqplot.JSON.parse(data, handleStrings);
61
- }
62
-
63
- else if (typeof(data) == "object") {
64
- for (k in data) {
65
- for (i=0; i<data[k].length; i++) {
66
- for (kk in data[k][i]) {
67
- data[k][i][kk] = handleStrings(kk, data[k][i][kk]);
68
- }
69
- }
70
- }
71
- }
72
-
73
- else {
74
- return null;
75
- }
76
-
77
- // function handleStrings
78
- // Checks any JSON encoded strings to see if they are
79
- // encoded dates. If so, pull out the timestamp.
80
- // Expects dates to be represented by js timestamps.
81
-
82
- function handleStrings(key, value) {
83
- var a;
84
- if (value != null) {
85
- if (value.toString().indexOf('Date') >= 0) {
86
- //here we will try to extract the ticks from the Date string in the "value" fields of JSON returned data
87
- a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
88
- if (a) {
89
- return parseInt(a[1], 10);
90
- }
91
- }
92
- return value;
93
- }
94
- }
95
-
96
- for (var prop in data) {
97
- line = [];
98
- temp = data[prop];
99
- switch (prop) {
100
- case "PriceTicks":
101
- for (i=0; i<temp.length; i++) {
102
- line.push([temp[i]['TickDate'], temp[i]['Price']]);
103
- }
104
- break;
105
- case "PriceBars":
106
- for (i=0; i<temp.length; i++) {
107
- line.push([temp[i]['BarDate'], temp[i]['Open'], temp[i]['High'], temp[i]['Low'], temp[i]['Close']]);
108
- }
109
- break;
110
- }
111
- ret.push(line);
112
- }
113
- return ret;
114
- };
115
- })(jQuery);
@@ -1,30 +0,0 @@
1
- /**
2
- * jqPlot
3
- * Pure JavaScript plotting plugin using jQuery
4
- *
5
- * Version: 1.0.0b1_r746
6
- *
7
- * Copyright (c) 2009-2011 Chris Leonello
8
- * jqPlot is currently available for use in all personal or commercial projects
9
- * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
- * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
- * choose the license that best suits your project and use it accordingly.
12
- *
13
- * Although not required, the author would appreciate an email letting him
14
- * know of any substantial use of jqPlot. You can reach the author at:
15
- * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
- *
17
- * If you are feeling kind and generous, consider supporting the project by
18
- * making a donation at: http://www.jqplot.com/donate.php .
19
- *
20
- * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
- *
22
- * version 2007.04.27
23
- * author Ash Searle
24
- * http://hexmen.com/blog/2007/03/printf-sprintf/
25
- * http://hexmen.com/js/sprintf.js
26
- * The author (Ash Searle) has placed this code in the public domain:
27
- * "This code is unrestricted: you are free to use it however you like."
28
- *
29
- */
30
- (function(a){a.jqplot.ciParser=function(g,l){var m=[],o,n,h,f,e,c;if(typeof(g)=="string"){g=a.jqplot.JSON.parse(g,d)}else{if(typeof(g)=="object"){for(e in g){for(h=0;h<g[e].length;h++){for(c in g[e][h]){g[e][h][c]=d(c,g[e][h][c])}}}}else{return null}}function d(j,k){var i;if(k!=null){if(k.toString().indexOf("Date")>=0){i=/^\/Date\((-?[0-9]+)\)\/$/.exec(k);if(i){return parseInt(i[1],10)}}return k}}for(var b in g){o=[];n=g[b];switch(b){case"PriceTicks":for(h=0;h<n.length;h++){o.push([n[h]["TickDate"],n[h]["Price"]])}break;case"PriceBars":for(h=0;h<n.length;h++){o.push([n[h]["BarDate"],n[h]["Open"],n[h]["High"],n[h]["Low"],n[h]["Close"]])}break}m.push(o)}return m}})(jQuery);
@@ -1,1002 +0,0 @@
1
- /**
2
- * jqPlot
3
- * Pure JavaScript plotting plugin using jQuery
4
- *
5
- * Version: 1.0.0b1_r746
6
- *
7
- * Copyright (c) 2009-2011 Chris Leonello
8
- * jqPlot is currently available for use in all personal or commercial projects
9
- * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
- * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
- * choose the license that best suits your project and use it accordingly.
12
- *
13
- * Although not required, the author would appreciate an email letting him
14
- * know of any substantial use of jqPlot. You can reach the author at:
15
- * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
- *
17
- * If you are feeling kind and generous, consider supporting the project by
18
- * making a donation at: http://www.jqplot.com/donate.php .
19
- *
20
- * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
- *
22
- * version 2007.04.27
23
- * author Ash Searle
24
- * http://hexmen.com/blog/2007/03/printf-sprintf/
25
- * http://hexmen.com/js/sprintf.js
26
- * The author (Ash Searle) has placed this code in the public domain:
27
- * "This code is unrestricted: you are free to use it however you like."
28
- *
29
- */
30
- (function($) {
31
-
32
- /**
33
- * Class: $.jqplot.Cursor
34
- * Plugin class representing the cursor as displayed on the plot.
35
- */
36
- $.jqplot.Cursor = function(options) {
37
- // Group: Properties
38
- //
39
- // prop: style
40
- // CSS spec for cursor style
41
- this.style = 'crosshair';
42
- this.previousCursor = 'auto';
43
- // prop: show
44
- // wether to show the cursor or not.
45
- this.show = $.jqplot.config.enablePlugins;
46
- // prop: showTooltip
47
- // show a cursor position tooltip. Location of the tooltip
48
- // will be controlled by followMouse and tooltipLocation.
49
- this.showTooltip = true;
50
- // prop: followMouse
51
- // Tooltip follows the mouse, it is not at a fixed location.
52
- // Tooltip will show on the grid at the location given by
53
- // tooltipLocation, offset from the grid edge by tooltipOffset.
54
- this.followMouse = false;
55
- // prop: tooltipLocation
56
- // Where to position tooltip. If followMouse is true, this is
57
- // relative to the cursor, otherwise, it is relative to the grid.
58
- // One of 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
59
- this.tooltipLocation = 'se';
60
- // prop: tooltipOffset
61
- // Pixel offset of tooltip from the grid boudaries or cursor center.
62
- this.tooltipOffset = 6;
63
- // prop: showTooltipGridPosition
64
- // show the grid pixel coordinates of the mouse.
65
- this.showTooltipGridPosition = false;
66
- // prop: showTooltipUnitPosition
67
- // show the unit (data) coordinates of the mouse.
68
- this.showTooltipUnitPosition = true;
69
- // prop: showTooltipDataPosition
70
- // Used with showVerticalLine to show intersecting data points in the tooltip.
71
- this.showTooltipDataPosition = false;
72
- // prop: tooltipFormatString
73
- // sprintf format string for the tooltip.
74
- // Uses Ash Searle's javascript sprintf implementation
75
- // found here: http://hexmen.com/blog/2007/03/printf-sprintf/
76
- // See http://perldoc.perl.org/functions/sprintf.html for reference
77
- // Note, if showTooltipDataPosition is true, the default tooltipFormatString
78
- // will be set to the cursorLegendFormatString, not the default given here.
79
- this.tooltipFormatString = '%.4P, %.4P';
80
- // prop: useAxesFormatters
81
- // Use the x and y axes formatters to format the text in the tooltip.
82
- this.useAxesFormatters = true;
83
- // prop: tooltipAxisGroups
84
- // Show position for the specified axes.
85
- // This is an array like [['xaxis', 'yaxis'], ['xaxis', 'y2axis']]
86
- // Default is to compute automatically for all visible axes.
87
- this.tooltipAxisGroups = [];
88
- // prop: zoom
89
- // Enable plot zooming.
90
- this.zoom = false;
91
- // zoomProxy and zoomTarget properties are not directly set by user.
92
- // They Will be set through call to zoomProxy method.
93
- this.zoomProxy = false;
94
- this.zoomTarget = false;
95
- // prop: looseZoom
96
- // Will expand zoom range to provide more rounded tick values.
97
- // Works only with linear axes and date axes.
98
- this.looseZoom = false;
99
- // prop: clickReset
100
- // Will reset plot zoom if single click on plot without drag.
101
- this.clickReset = false;
102
- // prop: dblClickReset
103
- // Will reset plot zoom if double click on plot without drag.
104
- this.dblClickReset = true;
105
- // prop: showVerticalLine
106
- // draw a vertical line across the plot which follows the cursor.
107
- // When the line is near a data point, a special legend and/or tooltip can
108
- // be updated with the data values.
109
- this.showVerticalLine = false;
110
- // prop: showHorizontalLine
111
- // draw a horizontal line across the plot which follows the cursor.
112
- this.showHorizontalLine = false;
113
- // prop: constrainZoomTo
114
- // 'none', 'x' or 'y'
115
- this.constrainZoomTo = 'none';
116
- // // prop: autoscaleConstraint
117
- // // when a constrained axis is specified, true will
118
- // // auatoscale the adjacent axis.
119
- // this.autoscaleConstraint = true;
120
- this.shapeRenderer = new $.jqplot.ShapeRenderer();
121
- this._zoom = {start:[], end:[], started: false, zooming:false, isZoomed:false, axes:{start:{}, end:{}}, gridpos:{}, datapos:{}};
122
- this._tooltipElem;
123
- this.zoomCanvas;
124
- this.cursorCanvas;
125
- // prop: intersectionThreshold
126
- // pixel distance from data point or marker to consider cursor lines intersecting with point.
127
- // If data point markers are not shown, this should be >= 1 or will often miss point intersections.
128
- this.intersectionThreshold = 2;
129
- // prop: showCursorLegend
130
- // Replace the plot legend with an enhanced legend displaying intersection information.
131
- this.showCursorLegend = false;
132
- // prop: cursorLegendFormatString
133
- // Format string used in the cursor legend. If showTooltipDataPosition is true,
134
- // this will also be the default format string used by tooltipFormatString.
135
- this.cursorLegendFormatString = $.jqplot.Cursor.cursorLegendFormatString;
136
- // whether the cursor is over the grid or not.
137
- this._oldHandlers = {onselectstart: null, ondrag: null, onmousedown: null};
138
- // prop: constrainOutsideZoom
139
- // True to limit actual zoom area to edges of grid, even when zooming
140
- // outside of plot area. That is, can't zoom out by mousing outside plot.
141
- this.constrainOutsideZoom = true;
142
- // prop: showTooltipOutsideZoom
143
- // True will keep updating the tooltip when zooming of the grid.
144
- this.showTooltipOutsideZoom = false;
145
- // true if mouse is over grid, false if not.
146
- this.onGrid = false;
147
- $.extend(true, this, options);
148
- };
149
-
150
- $.jqplot.Cursor.cursorLegendFormatString = '%s x:%s, y:%s';
151
-
152
- // called with scope of plot
153
- $.jqplot.Cursor.init = function (target, data, opts){
154
- // add a cursor attribute to the plot
155
- var options = opts || {};
156
- this.plugins.cursor = new $.jqplot.Cursor(options.cursor);
157
- var c = this.plugins.cursor;
158
-
159
- if (c.show) {
160
- $.jqplot.eventListenerHooks.push(['jqplotMouseEnter', handleMouseEnter]);
161
- $.jqplot.eventListenerHooks.push(['jqplotMouseLeave', handleMouseLeave]);
162
- $.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMouseMove]);
163
-
164
- if (c.showCursorLegend) {
165
- opts.legend = opts.legend || {};
166
- opts.legend.renderer = $.jqplot.CursorLegendRenderer;
167
- opts.legend.formatString = this.plugins.cursor.cursorLegendFormatString;
168
- opts.legend.show = true;
169
- }
170
-
171
- if (c.zoom) {
172
- $.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleMouseDown]);
173
-
174
- if (c.clickReset) {
175
- $.jqplot.eventListenerHooks.push(['jqplotClick', handleClick]);
176
- }
177
-
178
- if (c.dblClickReset) {
179
- $.jqplot.eventListenerHooks.push(['jqplotDblClick', handleDblClick]);
180
- }
181
- }
182
-
183
- this.resetZoom = function() {
184
- var axes = this.axes;
185
- if (!c.zoomProxy) {
186
- for (var ax in axes) {
187
- axes[ax].reset();
188
- }
189
- this.redraw();
190
- }
191
- else {
192
- var ctx = this.plugins.cursor.zoomCanvas._ctx;
193
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
194
- ctx = null;
195
- }
196
- this.plugins.cursor._zoom.isZoomed = false;
197
- this.target.trigger('jqplotResetZoom', [this, this.plugins.cursor]);
198
- };
199
-
200
-
201
- if (c.showTooltipDataPosition) {
202
- c.showTooltipUnitPosition = false;
203
- c.showTooltipGridPosition = false;
204
- if (options.cursor.tooltipFormatString == undefined) {
205
- c.tooltipFormatString = $.jqplot.Cursor.cursorLegendFormatString;
206
- }
207
- }
208
- }
209
- };
210
-
211
- // called with context of plot
212
- $.jqplot.Cursor.postDraw = function() {
213
- var c = this.plugins.cursor;
214
- // if (c.zoom) {
215
- c.zoomCanvas = new $.jqplot.GenericCanvas();
216
- this.eventCanvas._elem.before(c.zoomCanvas.createElement(this._gridPadding, 'jqplot-zoom-canvas', this._plotDimensions));
217
- c.zoomCanvas.setContext();
218
- // }
219
- c._tooltipElem = $('<div class="jqplot-cursor-tooltip" style="position:absolute;display:none"></div>');
220
- c.zoomCanvas._elem.before(c._tooltipElem);
221
- if (c.showVerticalLine || c.showHorizontalLine) {
222
- c.cursorCanvas = new $.jqplot.GenericCanvas();
223
- this.eventCanvas._elem.before(c.cursorCanvas.createElement(this._gridPadding, 'jqplot-cursor-canvas', this._plotDimensions));
224
- c.cursorCanvas.setContext();
225
- }
226
-
227
- // if we are showing the positions in unit coordinates, and no axes groups
228
- // were specified, create a default set.
229
- if (c.showTooltipUnitPosition){
230
- if (c.tooltipAxisGroups.length === 0) {
231
- var series = this.series;
232
- var s;
233
- var temp = [];
234
- for (var i=0; i<series.length; i++) {
235
- s = series[i];
236
- var ax = s.xaxis+','+s.yaxis;
237
- if ($.inArray(ax, temp) == -1) {
238
- temp.push(ax);
239
- }
240
- }
241
- for (var i=0; i<temp.length; i++) {
242
- c.tooltipAxisGroups.push(temp[i].split(','));
243
- }
244
- }
245
- }
246
- };
247
-
248
- // Group: methods
249
- //
250
- // method: $.jqplot.Cursor.zoomProxy
251
- // links targetPlot to controllerPlot so that plot zooming of
252
- // targetPlot will be controlled by zooming on the controllerPlot.
253
- // controllerPlot will not actually zoom, but acts as an
254
- // overview plot. Note, the zoom options must be set to true for
255
- // zoomProxy to work.
256
- $.jqplot.Cursor.zoomProxy = function(targetPlot, controllerPlot) {
257
- var tc = targetPlot.plugins.cursor;
258
- var cc = controllerPlot.plugins.cursor;
259
- tc.zoomTarget = true;
260
- tc.zoom = true;
261
- tc.style = 'auto';
262
- tc.dblClickReset = false;
263
- cc.zoom = true;
264
- cc.zoomProxy = true;
265
-
266
- controllerPlot.target.bind('jqplotZoom', plotZoom);
267
- controllerPlot.target.bind('jqplotResetZoom', plotReset);
268
-
269
- function plotZoom(ev, gridpos, datapos, plot, cursor) {
270
- tc.doZoom(gridpos, datapos, targetPlot, cursor);
271
- }
272
-
273
- function plotReset(ev, plot, cursor) {
274
- targetPlot.resetZoom();
275
- }
276
- };
277
-
278
- $.jqplot.Cursor.prototype.resetZoom = function(plot, cursor) {
279
- var axes = plot.axes;
280
- var cax = cursor._zoom.axes;
281
- if (!plot.plugins.cursor.zoomProxy && cursor._zoom.isZoomed) {
282
- for (var ax in axes) {
283
- axes[ax]._ticks = [];
284
- axes[ax].min = cax[ax].min;
285
- axes[ax].max = cax[ax].max;
286
- axes[ax].numberTicks = cax[ax].numberTicks;
287
- axes[ax].tickInterval = cax[ax].tickInterval;
288
- // for date axes
289
- axes[ax].daTickInterval = cax[ax].daTickInterval;
290
- }
291
- plot.redraw();
292
- cursor._zoom.isZoomed = false;
293
- }
294
- else {
295
- var ctx = cursor.zoomCanvas._ctx;
296
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
297
- ctx = null;
298
- }
299
- plot.target.trigger('jqplotResetZoom', [plot, cursor]);
300
- };
301
-
302
- $.jqplot.Cursor.resetZoom = function(plot) {
303
- plot.resetZoom();
304
- };
305
-
306
- $.jqplot.Cursor.prototype.doZoom = function (gridpos, datapos, plot, cursor) {
307
- var c = cursor;
308
- var axes = plot.axes;
309
- var zaxes = c._zoom.axes;
310
- var start = zaxes.start;
311
- var end = zaxes.end;
312
- var min, max, dp, span;
313
- var ctx = plot.plugins.cursor.zoomCanvas._ctx;
314
- // don't zoom if zoom area is too small (in pixels)
315
- if ((c.constrainZoomTo == 'none' && Math.abs(gridpos.x - c._zoom.start[0]) > 6 && Math.abs(gridpos.y - c._zoom.start[1]) > 6) || (c.constrainZoomTo == 'x' && Math.abs(gridpos.x - c._zoom.start[0]) > 6) || (c.constrainZoomTo == 'y' && Math.abs(gridpos.y - c._zoom.start[1]) > 6)) {
316
- if (!plot.plugins.cursor.zoomProxy) {
317
- for (var ax in datapos) {
318
- // make a copy of the original axes to revert back.
319
- if (c._zoom.axes[ax] == undefined) {
320
- c._zoom.axes[ax] = {};
321
- c._zoom.axes[ax].numberTicks = axes[ax].numberTicks;
322
- c._zoom.axes[ax].tickInterval = axes[ax].tickInterval;
323
- // for date axes...
324
- c._zoom.axes[ax].daTickInterval = axes[ax].daTickInterval;
325
- c._zoom.axes[ax].min = axes[ax].min;
326
- c._zoom.axes[ax].max = axes[ax].max;
327
- }
328
-
329
-
330
- if ((c.constrainZoomTo == 'none') || (c.constrainZoomTo == 'x' && ax.charAt(0) == 'x') || (c.constrainZoomTo == 'y' && ax.charAt(0) == 'y')) {
331
- dp = datapos[ax];
332
- if (dp != null) {
333
- var newmin, newmax;
334
- if (dp > start[ax]) {
335
- newmin = start[ax];
336
- newmax = dp;
337
- }
338
- else {
339
- span = start[ax] - dp;
340
- newmin = dp;
341
- newmax = start[ax];
342
- }
343
-
344
- if (this.looseZoom && (axes[ax].renderer.constructor === $.jqplot.LinearAxisRenderer || axes[ax].renderer.constructor === $.jqplot.DateAxisRenderer)) {
345
- var ret = $.jqplot.LinearTickGenerator(newmin, newmax);
346
- axes[ax].min = ret[0];
347
- axes[ax].max = ret[1];
348
- axes[ax].numberTicks = ret[2];
349
- axes[ax].tickInterval = ret[4];
350
- // for date axes...
351
- axes[ax].daTickInterval = [ret[4]/1000, 'seconds'];
352
- }
353
- else {
354
- axes[ax].min = newmin;
355
- axes[ax].max = newmax;
356
- axes[ax].tickInterval = null;
357
- // for date axes...
358
- axes[ax].daTickInterval = null;
359
- }
360
-
361
- axes[ax]._ticks = [];
362
- }
363
- }
364
-
365
- // if ((c.constrainZoomTo == 'x' && ax.charAt(0) == 'y' && c.autoscaleConstraint) || (c.constrainZoomTo == 'y' && ax.charAt(0) == 'x' && c.autoscaleConstraint)) {
366
- // dp = datapos[ax];
367
- // if (dp != null) {
368
- // axes[ax].max == null;
369
- // axes[ax].min = null;
370
- // }
371
- // }
372
- }
373
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
374
- plot.redraw();
375
- c._zoom.isZoomed = true;
376
- ctx = null;
377
- }
378
- plot.target.trigger('jqplotZoom', [gridpos, datapos, plot, cursor]);
379
- }
380
- };
381
-
382
- $.jqplot.preInitHooks.push($.jqplot.Cursor.init);
383
- $.jqplot.postDrawHooks.push($.jqplot.Cursor.postDraw);
384
-
385
- function updateTooltip(gridpos, datapos, plot) {
386
- var c = plot.plugins.cursor;
387
- var s = '';
388
- var addbr = false;
389
- if (c.showTooltipGridPosition) {
390
- s = gridpos.x+', '+gridpos.y;
391
- addbr = true;
392
- }
393
- if (c.showTooltipUnitPosition) {
394
- var g;
395
- for (var i=0; i<c.tooltipAxisGroups.length; i++) {
396
- g = c.tooltipAxisGroups[i];
397
- if (addbr) {
398
- s += '<br />';
399
- }
400
- if (c.useAxesFormatters) {
401
- var xf = plot.axes[g[0]]._ticks[0].formatter;
402
- var yf = plot.axes[g[1]]._ticks[0].formatter;
403
- var xfstr = plot.axes[g[0]]._ticks[0].formatString;
404
- var yfstr = plot.axes[g[1]]._ticks[0].formatString;
405
- s += xf(xfstr, datapos[g[0]]) + ', '+ yf(yfstr, datapos[g[1]]);
406
- }
407
- else {
408
- s += $.jqplot.sprintf(c.tooltipFormatString, datapos[g[0]], datapos[g[1]]);
409
- }
410
- addbr = true;
411
- }
412
- }
413
-
414
- if (c.showTooltipDataPosition) {
415
- var series = plot.series;
416
- var ret = getIntersectingPoints(plot, gridpos.x, gridpos.y);
417
- var addbr = false;
418
-
419
- for (var i = 0; i< series.length; i++) {
420
- if (series[i].show) {
421
- var idx = series[i].index;
422
- var label = series[i].label.toString();
423
- var cellid = $.inArray(idx, ret.indices);
424
- var sx = undefined;
425
- var sy = undefined;
426
- if (cellid != -1) {
427
- var data = ret.data[cellid].data;
428
- if (c.useAxesFormatters) {
429
- var xf = series[i]._xaxis._ticks[0].formatter;
430
- var yf = series[i]._yaxis._ticks[0].formatter;
431
- var xfstr = series[i]._xaxis._ticks[0].formatString;
432
- var yfstr = series[i]._yaxis._ticks[0].formatString;
433
- sx = xf(xfstr, data[0]);
434
- sy = yf(yfstr, data[1]);
435
- }
436
- else {
437
- sx = data[0];
438
- sy = data[1];
439
- }
440
- if (addbr) {
441
- s += '<br />';
442
- }
443
- s += $.jqplot.sprintf(c.tooltipFormatString, label, sx, sy);
444
- addbr = true;
445
- }
446
- }
447
- }
448
-
449
- }
450
- c._tooltipElem.html(s);
451
- }
452
-
453
- function moveLine(gridpos, plot) {
454
- var c = plot.plugins.cursor;
455
- var ctx = c.cursorCanvas._ctx;
456
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
457
- if (c.showVerticalLine) {
458
- c.shapeRenderer.draw(ctx, [[gridpos.x, 0], [gridpos.x, ctx.canvas.height]]);
459
- }
460
- if (c.showHorizontalLine) {
461
- c.shapeRenderer.draw(ctx, [[0, gridpos.y], [ctx.canvas.width, gridpos.y]]);
462
- }
463
- var ret = getIntersectingPoints(plot, gridpos.x, gridpos.y);
464
- if (c.showCursorLegend) {
465
- var cells = $(plot.targetId + ' td.jqplot-cursor-legend-label');
466
- for (var i=0; i<cells.length; i++) {
467
- var idx = $(cells[i]).data('seriesIndex');
468
- var series = plot.series[idx];
469
- var label = series.label.toString();
470
- var cellid = $.inArray(idx, ret.indices);
471
- var sx = undefined;
472
- var sy = undefined;
473
- if (cellid != -1) {
474
- var data = ret.data[cellid].data;
475
- if (c.useAxesFormatters) {
476
- var xf = series._xaxis._ticks[0].formatter;
477
- var yf = series._yaxis._ticks[0].formatter;
478
- var xfstr = series._xaxis._ticks[0].formatString;
479
- var yfstr = series._yaxis._ticks[0].formatString;
480
- sx = xf(xfstr, data[0]);
481
- sy = yf(yfstr, data[1]);
482
- }
483
- else {
484
- sx = data[0];
485
- sy = data[1];
486
- }
487
- }
488
- if (plot.legend.escapeHtml) {
489
- $(cells[i]).text($.jqplot.sprintf(c.cursorLegendFormatString, label, sx, sy));
490
- }
491
- else {
492
- $(cells[i]).html($.jqplot.sprintf(c.cursorLegendFormatString, label, sx, sy));
493
- }
494
- }
495
- }
496
- ctx = null;
497
- }
498
-
499
- function getIntersectingPoints(plot, x, y) {
500
- var ret = {indices:[], data:[]};
501
- var s, i, d0, d, j, r, p;
502
- var threshold;
503
- var c = plot.plugins.cursor;
504
- for (var i=0; i<plot.series.length; i++) {
505
- s = plot.series[i];
506
- r = s.renderer;
507
- if (s.show) {
508
- threshold = c.intersectionThreshold;
509
- if (s.showMarker) {
510
- threshold += s.markerRenderer.size/2;
511
- }
512
- for (var j=0; j<s.gridData.length; j++) {
513
- p = s.gridData[j];
514
- // check vertical line
515
- if (c.showVerticalLine) {
516
- if (Math.abs(x-p[0]) <= threshold) {
517
- ret.indices.push(i);
518
- ret.data.push({seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]});
519
- }
520
- }
521
- }
522
- }
523
- }
524
- return ret;
525
- }
526
-
527
- function moveTooltip(gridpos, plot) {
528
- var c = plot.plugins.cursor;
529
- var elem = c._tooltipElem;
530
- switch (c.tooltipLocation) {
531
- case 'nw':
532
- var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
533
- var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
534
- break;
535
- case 'n':
536
- var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
537
- var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
538
- break;
539
- case 'ne':
540
- var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
541
- var y = gridpos.y + plot._gridPadding.top - c.tooltipOffset - elem.outerHeight(true);
542
- break;
543
- case 'e':
544
- var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
545
- var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
546
- break;
547
- case 'se':
548
- var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
549
- var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
550
- break;
551
- case 's':
552
- var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
553
- var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
554
- break;
555
- case 'sw':
556
- var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
557
- var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
558
- break;
559
- case 'w':
560
- var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - c.tooltipOffset;
561
- var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
562
- break;
563
- default:
564
- var x = gridpos.x + plot._gridPadding.left + c.tooltipOffset;
565
- var y = gridpos.y + plot._gridPadding.top + c.tooltipOffset;
566
- break;
567
- }
568
-
569
- elem.css('left', x);
570
- elem.css('top', y);
571
- elem = null;
572
- }
573
-
574
- function positionTooltip(plot) {
575
- // fake a grid for positioning
576
- var grid = plot._gridPadding;
577
- var c = plot.plugins.cursor;
578
- var elem = c._tooltipElem;
579
- switch (c.tooltipLocation) {
580
- case 'nw':
581
- var a = grid.left + c.tooltipOffset;
582
- var b = grid.top + c.tooltipOffset;
583
- elem.css('left', a);
584
- elem.css('top', b);
585
- break;
586
- case 'n':
587
- var a = (grid.left + (plot._plotDimensions.width - grid.right))/2 - elem.outerWidth(true)/2;
588
- var b = grid.top + c.tooltipOffset;
589
- elem.css('left', a);
590
- elem.css('top', b);
591
- break;
592
- case 'ne':
593
- var a = grid.right + c.tooltipOffset;
594
- var b = grid.top + c.tooltipOffset;
595
- elem.css({right:a, top:b});
596
- break;
597
- case 'e':
598
- var a = grid.right + c.tooltipOffset;
599
- var b = (grid.top + (plot._plotDimensions.height - grid.bottom))/2 - elem.outerHeight(true)/2;
600
- elem.css({right:a, top:b});
601
- break;
602
- case 'se':
603
- var a = grid.right + c.tooltipOffset;
604
- var b = grid.bottom + c.tooltipOffset;
605
- elem.css({right:a, bottom:b});
606
- break;
607
- case 's':
608
- var a = (grid.left + (plot._plotDimensions.width - grid.right))/2 - elem.outerWidth(true)/2;
609
- var b = grid.bottom + c.tooltipOffset;
610
- elem.css({left:a, bottom:b});
611
- break;
612
- case 'sw':
613
- var a = grid.left + c.tooltipOffset;
614
- var b = grid.bottom + c.tooltipOffset;
615
- elem.css({left:a, bottom:b});
616
- break;
617
- case 'w':
618
- var a = grid.left + c.tooltipOffset;
619
- var b = (grid.top + (plot._plotDimensions.height - grid.bottom))/2 - elem.outerHeight(true)/2;
620
- elem.css({left:a, top:b});
621
- break;
622
- default: // same as 'se'
623
- var a = grid.right - c.tooltipOffset;
624
- var b = grid.bottom + c.tooltipOffset;
625
- elem.css({right:a, bottom:b});
626
- break;
627
- }
628
- elem = null;
629
- }
630
-
631
- function handleClick (ev, gridpos, datapos, neighbor, plot) {
632
- ev.preventDefault();
633
- ev.stopImmediatePropagation();
634
- var c = plot.plugins.cursor;
635
- if (c.clickReset) {
636
- c.resetZoom(plot, c);
637
- }
638
- var sel = window.getSelection;
639
- if (document.selection && document.selection.empty)
640
- {
641
- document.selection.empty();
642
- }
643
- else if (sel && !sel().isCollapsed) {
644
- sel().collapse();
645
- }
646
- return false;
647
- }
648
-
649
- function handleDblClick (ev, gridpos, datapos, neighbor, plot) {
650
- ev.preventDefault();
651
- ev.stopImmediatePropagation();
652
- var c = plot.plugins.cursor;
653
- if (c.dblClickReset) {
654
- c.resetZoom(plot, c);
655
- }
656
- var sel = window.getSelection;
657
- if (document.selection && document.selection.empty)
658
- {
659
- document.selection.empty();
660
- }
661
- else if (sel && !sel().isCollapsed) {
662
- sel().collapse();
663
- }
664
- return false;
665
- }
666
-
667
- function handleMouseLeave(ev, gridpos, datapos, neighbor, plot) {
668
- var c = plot.plugins.cursor;
669
- c.onGrid = false;
670
- if (c.show) {
671
- $(ev.target).css('cursor', c.previousCursor);
672
- if (c.showTooltip && !(c._zoom.zooming && c.showTooltipOutsideZoom && !c.constrainOutsideZoom)) {
673
- c._tooltipElem.hide();
674
- }
675
- if (c.zoom) {
676
- c._zoom.gridpos = gridpos;
677
- c._zoom.datapos = datapos;
678
- }
679
- if (c.showVerticalLine || c.showHorizontalLine) {
680
- var ctx = c.cursorCanvas._ctx;
681
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
682
- ctx = null;
683
- }
684
- if (c.showCursorLegend) {
685
- var cells = $(plot.targetId + ' td.jqplot-cursor-legend-label');
686
- for (var i=0; i<cells.length; i++) {
687
- var idx = $(cells[i]).data('seriesIndex');
688
- var series = plot.series[idx];
689
- var label = series.label.toString();
690
- if (plot.legend.escapeHtml) {
691
- $(cells[i]).text($.jqplot.sprintf(c.cursorLegendFormatString, label, undefined, undefined));
692
- }
693
- else {
694
- $(cells[i]).html($.jqplot.sprintf(c.cursorLegendFormatString, label, undefined, undefined));
695
- }
696
-
697
- }
698
- }
699
- }
700
- }
701
-
702
- function handleMouseEnter(ev, gridpos, datapos, neighbor, plot) {
703
- var c = plot.plugins.cursor;
704
- c.onGrid = true;
705
- if (c.show) {
706
- c.previousCursor = ev.target.style.cursor;
707
- ev.target.style.cursor = c.style;
708
- if (c.showTooltip) {
709
- updateTooltip(gridpos, datapos, plot);
710
- if (c.followMouse) {
711
- moveTooltip(gridpos, plot);
712
- }
713
- else {
714
- positionTooltip(plot);
715
- }
716
- c._tooltipElem.show();
717
- }
718
- if (c.showVerticalLine || c.showHorizontalLine) {
719
- moveLine(gridpos, plot);
720
- }
721
- }
722
-
723
- }
724
-
725
- function handleMouseMove(ev, gridpos, datapos, neighbor, plot) {
726
- var c = plot.plugins.cursor;
727
- var ctx = c.zoomCanvas._ctx;
728
- if (c.show) {
729
- if (c.showTooltip) {
730
- updateTooltip(gridpos, datapos, plot);
731
- if (c.followMouse) {
732
- moveTooltip(gridpos, plot);
733
- }
734
- }
735
- if (c.showVerticalLine || c.showHorizontalLine) {
736
- moveLine(gridpos, plot);
737
- }
738
- }
739
- ctx = null;
740
- }
741
-
742
- function getEventPosition(ev) {
743
- var plot = ev.data.plot;
744
- var go = plot.eventCanvas._elem.offset();
745
- var gridPos = {x:ev.pageX - go.left, y:ev.pageY - go.top};
746
- var dataPos = {xaxis:null, yaxis:null, x2axis:null, y2axis:null, y3axis:null, y4axis:null, y5axis:null, y6axis:null, y7axis:null, y8axis:null, y9axis:null};
747
- var an = ['xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
748
- var ax = plot.axes;
749
- var n, axis;
750
- for (n=11; n>0; n--) {
751
- axis = an[n-1];
752
- if (ax[axis].show) {
753
- dataPos[axis] = ax[axis].series_p2u(gridPos[axis.charAt(0)]);
754
- }
755
- }
756
-
757
- return {offsets:go, gridPos:gridPos, dataPos:dataPos};
758
- }
759
-
760
- function handleZoomMove(ev) {
761
- var plot = ev.data.plot;
762
- var c = plot.plugins.cursor;
763
- // don't do anything if not on grid.
764
- if (c.show && c.zoom && c._zoom.started && !c.zoomTarget) {
765
- var ctx = c.zoomCanvas._ctx;
766
- var positions = getEventPosition(ev);
767
- var gridpos = positions.gridPos;
768
- var datapos = positions.dataPos;
769
- c._zoom.gridpos = gridpos;
770
- c._zoom.datapos = datapos;
771
- c._zoom.zooming = true;
772
- var xpos = gridpos.x;
773
- var ypos = gridpos.y;
774
- var height = ctx.canvas.height;
775
- var width = ctx.canvas.width;
776
- if (c.showTooltip && !c.onGrid && c.showTooltipOutsideZoom) {
777
- updateTooltip(gridpos, datapos, plot);
778
- if (c.followMouse) {
779
- moveTooltip(gridpos, plot);
780
- }
781
- }
782
- if (c.constrainZoomTo == 'x') {
783
- c._zoom.end = [xpos, height];
784
- }
785
- else if (c.constrainZoomTo == 'y') {
786
- c._zoom.end = [width, ypos];
787
- }
788
- else {
789
- c._zoom.end = [xpos, ypos];
790
- }
791
- var sel = window.getSelection;
792
- if (document.selection && document.selection.empty)
793
- {
794
- document.selection.empty();
795
- }
796
- else if (sel && !sel().isCollapsed) {
797
- sel().collapse();
798
- }
799
- drawZoomBox.call(c);
800
- ctx = null;
801
- }
802
- }
803
-
804
- function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
805
- var c = plot.plugins.cursor;
806
- $(document).one('mouseup.jqplot_cursor', {plot:plot}, handleMouseUp);
807
- var axes = plot.axes;
808
- if (document.onselectstart != undefined) {
809
- c._oldHandlers.onselectstart = document.onselectstart;
810
- document.onselectstart = function () { return false; };
811
- }
812
- if (document.ondrag != undefined) {
813
- c._oldHandlers.ondrag = document.ondrag;
814
- document.ondrag = function () { return false; };
815
- }
816
- if (document.onmousedown != undefined) {
817
- c._oldHandlers.onmousedown = document.onmousedown;
818
- document.onmousedown = function () { return false; };
819
- }
820
- if (c.zoom) {
821
- if (!c.zoomProxy) {
822
- var ctx = c.zoomCanvas._ctx;
823
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
824
- ctx = null;
825
- }
826
- if (c.constrainZoomTo == 'x') {
827
- c._zoom.start = [gridpos.x, 0];
828
- }
829
- else if (c.constrainZoomTo == 'y') {
830
- c._zoom.start = [0, gridpos.y];
831
- }
832
- else {
833
- c._zoom.start = [gridpos.x, gridpos.y];
834
- }
835
- c._zoom.started = true;
836
- for (var ax in datapos) {
837
- // get zoom starting position.
838
- c._zoom.axes.start[ax] = datapos[ax];
839
- }
840
- $(document).bind('mousemove.jqplotCursor', {plot:plot}, handleZoomMove);
841
- }
842
- }
843
-
844
- function handleMouseUp(ev) {
845
- var plot = ev.data.plot;
846
- var c = plot.plugins.cursor;
847
- if (c.zoom && c._zoom.zooming && !c.zoomTarget) {
848
- var xpos = c._zoom.gridpos.x;
849
- var ypos = c._zoom.gridpos.y;
850
- var datapos = c._zoom.datapos;
851
- var height = c.zoomCanvas._ctx.canvas.height;
852
- var width = c.zoomCanvas._ctx.canvas.width;
853
- var axes = plot.axes;
854
-
855
- if (c.constrainOutsideZoom && !c.onGrid) {
856
- if (xpos < 0) { xpos = 0; }
857
- else if (xpos > width) { xpos = width; }
858
- if (ypos < 0) { ypos = 0; }
859
- else if (ypos > height) { ypos = height; }
860
-
861
- for (var axis in datapos) {
862
- if (datapos[axis]) {
863
- if (axis.charAt(0) == 'x') {
864
- datapos[axis] = axes[axis].series_p2u(xpos);
865
- }
866
- else {
867
- datapos[axis] = axes[axis].series_p2u(ypos);
868
- }
869
- }
870
- }
871
- }
872
-
873
- if (c.constrainZoomTo == 'x') {
874
- ypos = height;
875
- }
876
- else if (c.constrainZoomTo == 'y') {
877
- xpos = width;
878
- }
879
- c._zoom.end = [xpos, ypos];
880
- c._zoom.gridpos = {x:xpos, y:ypos};
881
-
882
- c.doZoom(c._zoom.gridpos, datapos, plot, c);
883
- }
884
- c._zoom.started = false;
885
- c._zoom.zooming = false;
886
-
887
- $(document).unbind('mousemove.jqplotCursor', handleZoomMove);
888
-
889
- if (document.onselectstart != undefined && c._oldHandlers.onselectstart != null){
890
- document.onselectstart = c._oldHandlers.onselectstart;
891
- c._oldHandlers.onselectstart = null;
892
- }
893
- if (document.ondrag != undefined && c._oldHandlers.ondrag != null){
894
- document.ondrag = c._oldHandlers.ondrag;
895
- c._oldHandlers.ondrag = null;
896
- }
897
- if (document.onmousedown != undefined && c._oldHandlers.onmousedown != null){
898
- document.onmousedown = c._oldHandlers.onmousedown;
899
- c._oldHandlers.onmousedown = null;
900
- }
901
-
902
- }
903
-
904
- function drawZoomBox() {
905
- var start = this._zoom.start;
906
- var end = this._zoom.end;
907
- var ctx = this.zoomCanvas._ctx;
908
- var l, t, h, w;
909
- if (end[0] > start[0]) {
910
- l = start[0];
911
- w = end[0] - start[0];
912
- }
913
- else {
914
- l = end[0];
915
- w = start[0] - end[0];
916
- }
917
- if (end[1] > start[1]) {
918
- t = start[1];
919
- h = end[1] - start[1];
920
- }
921
- else {
922
- t = end[1];
923
- h = start[1] - end[1];
924
- }
925
- ctx.fillStyle = 'rgba(0,0,0,0.2)';
926
- ctx.strokeStyle = '#999999';
927
- ctx.lineWidth = 1.0;
928
- ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height);
929
- ctx.fillRect(0,0,ctx.canvas.width, ctx.canvas.height);
930
- ctx.clearRect(l, t, w, h);
931
- // IE won't show transparent fill rect, so stroke a rect also.
932
- ctx.strokeRect(l,t,w,h);
933
- ctx = null;
934
- }
935
-
936
- $.jqplot.CursorLegendRenderer = function(options) {
937
- $.jqplot.TableLegendRenderer.call(this, options);
938
- this.formatString = '%s';
939
- };
940
-
941
- $.jqplot.CursorLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
942
- $.jqplot.CursorLegendRenderer.prototype.constructor = $.jqplot.CursorLegendRenderer;
943
-
944
- // called in context of a Legend
945
- $.jqplot.CursorLegendRenderer.prototype.draw = function() {
946
- if (this.show) {
947
- var series = this._series, s;
948
- // make a table. one line label per row.
949
- this._elem = $('<table class="jqplot-legend jqplot-cursor-legend" style="position:absolute"></table>');
950
-
951
- var pad = false;
952
- for (var i = 0; i< series.length; i++) {
953
- s = series[i];
954
- if (s.show && s.showLabel) {
955
- var lt = $.jqplot.sprintf(this.formatString, s.label.toString());
956
- if (lt) {
957
- var color = s.color;
958
- if (s._stack && !s.fill) {
959
- color = '';
960
- }
961
- addrow.call(this, lt, color, pad, i);
962
- pad = true;
963
- }
964
- // let plugins add more rows to legend. Used by trend line plugin.
965
- for (var j=0; j<$.jqplot.addLegendRowHooks.length; j++) {
966
- var item = $.jqplot.addLegendRowHooks[j].call(this, s);
967
- if (item) {
968
- addrow.call(this, item.label, item.color, pad);
969
- pad = true;
970
- }
971
- }
972
- }
973
- }
974
- series = s = null;
975
- delete series;
976
- delete s;
977
- }
978
-
979
- function addrow(label, color, pad, idx) {
980
- var rs = (pad) ? this.rowSpacing : '0';
981
- var tr = $('<tr class="jqplot-legend jqplot-cursor-legend"></tr>').appendTo(this._elem);
982
- tr.data('seriesIndex', idx);
983
- $('<td class="jqplot-legend jqplot-cursor-legend-swatch" style="padding-top:'+rs+';">'+
984
- '<div style="border:1px solid #cccccc;padding:0.2em;">'+
985
- '<div class="jqplot-cursor-legend-swatch" style="background-color:'+color+';"></div>'+
986
- '</div></td>').appendTo(tr);
987
- var td = $('<td class="jqplot-legend jqplot-cursor-legend-label" style="vertical-align:middle;padding-top:'+rs+';"></td>');
988
- td.appendTo(tr);
989
- td.data('seriesIndex', idx);
990
- if (this.escapeHtml) {
991
- td.text(label);
992
- }
993
- else {
994
- td.html(label);
995
- }
996
- tr = null;
997
- td = null;
998
- }
999
- return this._elem;
1000
- };
1001
-
1002
- })(jQuery);