sunrise-votes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/Gemfile +5 -0
  2. data/README.rdoc +14 -0
  3. data/Rakefile +46 -0
  4. data/app/controllers/manage/ballot_box/votes_controller.rb +36 -0
  5. data/app/views/manage/ballot_box/votes/_model_filter.html.erb +34 -0
  6. data/app/views/manage/ballot_box/votes/_vote.html.erb +48 -0
  7. data/app/views/manage/ballot_box/votes/index.html.erb +29 -0
  8. data/app/views/manage/ballot_box/votes/show.html.erb +112 -0
  9. data/config/locales/ru.yml +5 -0
  10. data/config/locales/uk.yml +5 -0
  11. data/config/routes.rb +8 -0
  12. data/lib/generators/sunrise/votes/USAGE +5 -0
  13. data/lib/generators/sunrise/votes/install_generator.rb +16 -0
  14. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/excanvas.min.js +35 -0
  15. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/jquery.jqplot.css +226 -0
  16. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/jquery.jqplot.min.js +30 -0
  17. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.BezierCurveRenderer.js +312 -0
  18. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.BezierCurveRenderer.min.js +30 -0
  19. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.barRenderer.js +702 -0
  20. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.barRenderer.min.js +30 -0
  21. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.blockRenderer.js +234 -0
  22. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.blockRenderer.min.js +30 -0
  23. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.bubbleRenderer.js +748 -0
  24. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.bubbleRenderer.min.js +30 -0
  25. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisLabelRenderer.js +199 -0
  26. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisLabelRenderer.min.js +30 -0
  27. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisTickRenderer.js +238 -0
  28. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasAxisTickRenderer.min.js +30 -0
  29. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasOverlay.js +614 -0
  30. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasOverlay.min.js +30 -0
  31. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasTextRenderer.js +420 -0
  32. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.canvasTextRenderer.min.js +30 -0
  33. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.categoryAxisRenderer.js +634 -0
  34. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.categoryAxisRenderer.min.js +30 -0
  35. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ciParser.js +115 -0
  36. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ciParser.min.js +30 -0
  37. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.cursor.js +1002 -0
  38. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.cursor.min.js +30 -0
  39. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dateAxisRenderer.js +439 -0
  40. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dateAxisRenderer.min.js +30 -0
  41. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.donutRenderer.js +904 -0
  42. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.donutRenderer.min.js +30 -0
  43. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dragable.js +218 -0
  44. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.dragable.min.js +30 -0
  45. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.enhancedLegendRenderer.js +199 -0
  46. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.enhancedLegendRenderer.min.js +30 -0
  47. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.funnelRenderer.js +932 -0
  48. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.funnelRenderer.min.js +30 -0
  49. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.highlighter.js +406 -0
  50. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.highlighter.min.js +30 -0
  51. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.json2.js +475 -0
  52. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.json2.min.js +30 -0
  53. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.logAxisRenderer.js +446 -0
  54. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.logAxisRenderer.min.js +30 -0
  55. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoAxisRenderer.js +607 -0
  56. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoAxisRenderer.min.js +30 -0
  57. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoRenderer.js +432 -0
  58. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.mekkoRenderer.min.js +30 -0
  59. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.meterGaugeRenderer.js +1142 -0
  60. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.meterGaugeRenderer.min.js +30 -0
  61. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ohlcRenderer.js +372 -0
  62. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.ohlcRenderer.min.js +30 -0
  63. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pieRenderer.js +797 -0
  64. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pieRenderer.min.js +30 -0
  65. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pointLabels.js +337 -0
  66. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.pointLabels.min.js +30 -0
  67. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.trendline.js +220 -0
  68. data/lib/generators/sunrise/votes/templates/javascripts/ballot_box/plugins/jqplot.trendline.min.js +30 -0
  69. data/lib/sunrise-votes.rb +2 -0
  70. data/lib/sunrise/votes.rb +12 -0
  71. data/lib/sunrise/votes/engine.rb +18 -0
  72. data/lib/sunrise/votes/version.rb +5 -0
  73. metadata +164 -0
@@ -0,0 +1,30 @@
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.LogAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this);this.axisDefaults={base:10,tickDistribution:"even"}};a.jqplot.LogAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.LogAxisRenderer.prototype.constructor=a.jqplot.LogAxisRenderer;a.jqplot.LogAxisRenderer.prototype.init=function(e){a.extend(true,this.renderer,e);for(var h in this.renderer.axisDefaults){if(this[h]==null){this[h]=this.renderer.axisDefaults[h]}}var b=this._dataBounds;for(var f=0;f<this._series.length;f++){var g=this._series[f];var h=g.data;for(var c=0;c<h.length;c++){if(this.name=="xaxis"||this.name=="x2axis"){if((h[c][0]!=null&&h[c][0]<b.min)||b.min==null){b.min=h[c][0]}if((h[c][0]!=null&&h[c][0]>b.max)||b.max==null){b.max=h[c][0]}}else{if((h[c][1]!=null&&h[c][1]<b.min)||b.min==null){b.min=h[c][1]}if((h[c][1]!=null&&h[c][1]>b.max)||b.max==null){b.max=h[c][1]}}}}};a.jqplot.LogAxisRenderer.prototype.createTicks=function(){var A=this._ticks;var x=this.ticks;var D=this.name;var z=this._dataBounds;var s,y;var o,v;var e,d;var b,w;if(x.length){for(w=0;w<x.length;w++){var f=x[w];var k=new this.tickRenderer(this.tickOptions);if(f.constructor==Array){k.value=f[0];k.label=f[1];if(!this.showTicks){k.showLabel=false;k.showMark=false}else{if(!this.showTickMarks){k.showMark=false}}k.setTick(f[0],this.name);this._ticks.push(k)}else{k.value=f;if(!this.showTicks){k.showLabel=false;k.showMark=false}else{if(!this.showTickMarks){k.showMark=false}}k.setTick(f,this.name);this._ticks.push(k)}}this.numberTicks=x.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value}else{if(D=="xaxis"||D=="x2axis"){s=this._plotDimensions.width}else{s=this._plotDimensions.height}o=((this.min!=null)?this.min:z.min);v=((this.max!=null)?this.max:z.max);if(o==v){var g=0.05;o=o*(1-g);v=v*(1+g)}if(this.min!=null&&this.min<=0){throw ("log axis minimum must be greater than 0")}if(this.max!=null&&this.max<=0){throw ("log axis maximum must be greater than 0")}var l=v-o;var n,r;if(this.tickDistribution=="even"){n=(this.min!=null)?this.min:o-o*((this.padMin-1)/2);r=(this.max!=null)?this.max:v+v*((this.padMax-1)/2);this.min=n;this.max=r;l=this.max-this.min;if(this.numberTicks==null){if(s>100){this.numberTicks=parseInt(3+(s-100)/75,10)}else{this.numberTicks=2}}var h=Math.pow(this.base,(1/(this.numberTicks-1)*Math.log(this.max/this.min)/Math.log(this.base)));for(var w=0;w<this.numberTicks;w++){b=this.min*Math.pow(h,w);var k=new this.tickRenderer(this.tickOptions);if(!this.showTicks){k.showLabel=false;k.showMark=false}else{if(!this.showTickMarks){k.showMark=false}}k.setTick(b,this.name);this._ticks.push(k)}}else{if(this.tickDistribution=="power"){n=Math.pow(this.base,Math.ceil(Math.log(o*(2-this.padMin))/Math.log(this.base))-1);r=Math.pow(this.base,Math.floor(Math.log(v*this.padMax)/Math.log(this.base))+1);this.min=n;this.max=r;l=this.max-this.min;var q=0;var c=0;if(this.numberTicks==null){if(s>100){this.numberTicks=Math.round(Math.log(this.max/this.min)/Math.log(this.base)+1);if(this.numberTicks<2){this.numberTicks=2}q=parseInt(3+(s-100)/75,10)}else{this.numberTicks=2;q=2}if(this.numberTicks<q-1){c=Math.floor(q/this.numberTicks)}}for(var w=0;w<this.numberTicks;w++){b=Math.pow(this.base,w-this.numberTicks+1)*this.max;var k=new this.tickRenderer(this.tickOptions);if(!this.showTicks){k.showLabel=false;k.showMark=false}else{if(!this.showTickMarks){k.showMark=false}}k.setTick(b,this.name);this._ticks.push(k);if(c&&w<this.numberTicks-1){var m=Math.pow(this.base,w-this.numberTicks+2)*this.max;var B=m-b;var y=m/(c+1);for(var p=c-1;p>=0;p--){var C=m-y*(p+1);var k=new this.tickRenderer(this.tickOptions);if(!this.showTicks){k.showLabel=false;k.showMark=false}else{if(!this.showTickMarks){k.showMark=false}}k.setTick(C,this.name);this._ticks.push(k)}}}}}}};a.jqplot.LogAxisRenderer.prototype.pack=function(f,e){var r=parseInt(this.base,10);var y=this._ticks;var d=function(h){return Math.log(h)/Math.log(r)};var b=function(h){return Math.pow(Math.E,(Math.log(r)*h))};var u=d(this.max);var s=d(this.min);var m=e.max;var k=e.min;var o=(this._label==null)?false:this._label.show;for(var q in f){this._elem.css(q,f[q])}this._offsets=e;var g=m-k;var j=u-s;this.p2u=function(h){return b((h-k)*j/g+s)};this.u2p=function(h){return(d(h)-s)*g/j+k};if(this.name=="xaxis"||this.name=="x2axis"){this.series_u2p=function(h){return(d(h)-s)*g/j};this.series_p2u=function(h){return b(h*j/g+s)}}else{this.series_u2p=function(h){return(d(h)-u)*g/j};this.series_p2u=function(h){return b(h*j/g+u)}}if(this.show){if(this.name=="xaxis"||this.name=="x2axis"){for(var v=0;v<y.length;v++){var n=y[v];if(n.show&&n.showLabel){var c;if(n.constructor==a.jqplot.CanvasAxisTickRenderer&&n.angle){switch(n.labelPosition){case"auto":if(n.angle<0){c=-n.getWidth()+n._textRenderer.height*Math.sin(-n._textRenderer.angle)/2}else{c=-n._textRenderer.height*Math.sin(n._textRenderer.angle)/2}break;case"end":c=-n.getWidth()+n._textRenderer.height*Math.sin(-n._textRenderer.angle)/2;break;case"start":c=-n._textRenderer.height*Math.sin(n._textRenderer.angle)/2;break;case"middle":c=-n.getWidth()/2+n._textRenderer.height*Math.sin(-n._textRenderer.angle)/2;break;default:c=-n.getWidth()/2+n._textRenderer.height*Math.sin(-n._textRenderer.angle)/2;break}}else{c=-n.getWidth()/2}var z=this.u2p(n.value)+c+"px";n._elem.css("left",z);n.pack()}}if(o){var l=this._label._elem.outerWidth(true);this._label._elem.css("left",k+g/2-l/2+"px");if(this.name=="xaxis"){this._label._elem.css("bottom","0px")}else{this._label._elem.css("top","0px")}this._label.pack()}}else{for(var v=0;v<y.length;v++){var n=y[v];if(n.show&&n.showLabel){var c;if(n.constructor==a.jqplot.CanvasAxisTickRenderer&&n.angle){switch(n.labelPosition){case"auto":case"end":if(n.angle<0){c=-n._textRenderer.height*Math.cos(-n._textRenderer.angle)/2}else{c=-n.getHeight()+n._textRenderer.height*Math.cos(n._textRenderer.angle)/2}break;case"start":if(n.angle>0){c=-n._textRenderer.height*Math.cos(-n._textRenderer.angle)/2}else{c=-n.getHeight()+n._textRenderer.height*Math.cos(n._textRenderer.angle)/2}break;case"middle":c=-n.getHeight()/2;break;default:c=-n.getHeight()/2;break}}else{c=-n.getHeight()/2}var z=this.u2p(n.value)+c+"px";n._elem.css("top",z);n.pack()}}if(o){var x=this._label._elem.outerHeight(true);this._label._elem.css("top",m-g/2-x/2+"px");if(this.name=="yaxis"){this._label._elem.css("left","0px")}else{this._label._elem.css("right","0px")}this._label.pack()}}}}})(jQuery);
@@ -0,0 +1,607 @@
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
+ // class: $.jqplot.MekkoAxisRenderer
32
+ // An axis renderer for a Mekko chart.
33
+ // Should be used with a Mekko chart where the mekkoRenderer is used on the series.
34
+ // Displays the Y axis as a range from 0 to 1 (0 to 100%) and the x axis with a tick
35
+ // for each series scaled to the sum of all the y values.
36
+ $.jqplot.MekkoAxisRenderer = function() {
37
+ };
38
+
39
+ // called with scope of axis object.
40
+ $.jqplot.MekkoAxisRenderer.prototype.init = function(options){
41
+ // prop: tickMode
42
+ // How to space the ticks on the axis.
43
+ // 'bar' will place a tick at the width of each bar.
44
+ // This is the default for the x axis.
45
+ // 'even' will place ticks at even intervals. This is
46
+ // the default for x2 axis and y axis. y axis cannot be changed.
47
+ this.tickMode;
48
+ // prop: barLabelRenderer
49
+ // renderer to use to draw labels under each bar.
50
+ this.barLabelRenderer = $.jqplot.AxisLabelRenderer;
51
+ // prop: barLabels
52
+ // array of labels to put under each bar.
53
+ this.barLabels = this.barLabels || [];
54
+ // prop: barLabelOptions
55
+ // options object to pass to the bar label renderer.
56
+ this.barLabelOptions = {};
57
+ this.tickOptions = $.extend(true, {showGridline:false}, this.tickOptions);
58
+ this._barLabels = [];
59
+ $.extend(true, this, options);
60
+ if (this.name == 'yaxis') {
61
+ this.tickOptions.formatString = this.tickOptions.formatString || "%d\%";
62
+ }
63
+ var db = this._dataBounds;
64
+ db.min = 0;
65
+ // for y axes, scale always go from 0 to 1 (0 to 100%)
66
+ if (this.name == 'yaxis' || this.name == 'y2axis') {
67
+ db.max = 100;
68
+ this.tickMode = 'even';
69
+ }
70
+ // For x axes, scale goes from 0 to sum of all y values.
71
+ else if (this.name == 'xaxis'){
72
+ this.tickMode = (this.tickMode == null) ? 'bar' : this.tickMode;
73
+ for (var i=0; i<this._series.length; i++) {
74
+ db.max += this._series[i]._sumy;
75
+ }
76
+ }
77
+ else if (this.name == 'x2axis'){
78
+ this.tickMode = (this.tickMode == null) ? 'even' : this.tickMode;
79
+ for (var i=0; i<this._series.length; i++) {
80
+ db.max += this._series[i]._sumy;
81
+ }
82
+ }
83
+ };
84
+
85
+ // called with scope of axis
86
+ $.jqplot.MekkoAxisRenderer.prototype.draw = function(ctx) {
87
+ if (this.show) {
88
+ // populate the axis label and value properties.
89
+ // createTicks is a method on the renderer, but
90
+ // call it within the scope of the axis.
91
+ this.renderer.createTicks.call(this);
92
+ // fill a div with axes labels in the right direction.
93
+ // Need to pregenerate each axis to get it's bounds and
94
+ // position it and the labels correctly on the plot.
95
+ var dim=0;
96
+ var temp;
97
+
98
+ this._elem = $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
99
+
100
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
101
+ this._elem.width(this._plotDimensions.width);
102
+ }
103
+ else {
104
+ this._elem.height(this._plotDimensions.height);
105
+ }
106
+
107
+ // draw the axis label
108
+ // create a _label object.
109
+ this.labelOptions.axis = this.name;
110
+ this._label = new this.labelRenderer(this.labelOptions);
111
+ if (this._label.show) {
112
+ var elem = this._label.draw(ctx);
113
+ elem.appendTo(this._elem);
114
+ }
115
+
116
+ var t, tick, elem;
117
+ if (this.showTicks) {
118
+ t = this._ticks;
119
+ for (var i=0; i<t.length; i++) {
120
+ tick = t[i];
121
+ if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
122
+ elem = tick.draw(ctx);
123
+ elem.appendTo(this._elem);
124
+ }
125
+ }
126
+ }
127
+
128
+ // draw the series labels
129
+ for (i=0; i<this.barLabels.length; i++) {
130
+ this.barLabelOptions.axis = this.name;
131
+ this.barLabelOptions.label = this.barLabels[i];
132
+ this._barLabels.push(new this.barLabelRenderer(this.barLabelOptions));
133
+ if (this.tickMode != 'bar') {
134
+ this._barLabels[i].show = false;
135
+ }
136
+ if (this._barLabels[i].show) {
137
+ var elem = this._barLabels[i].draw(ctx);
138
+ elem.removeClass('jqplot-'+this.name+'-label');
139
+ elem.addClass('jqplot-'+this.name+'-tick');
140
+ elem.addClass('jqplot-mekko-barLabel');
141
+ elem.appendTo(this._elem);
142
+ }
143
+ }
144
+
145
+ }
146
+ return this._elem;
147
+ };
148
+
149
+ // called with scope of an axis
150
+ $.jqplot.MekkoAxisRenderer.prototype.reset = function() {
151
+ this.min = this._min;
152
+ this.max = this._max;
153
+ this.tickInterval = this._tickInterval;
154
+ this.numberTicks = this._numberTicks;
155
+ // this._ticks = this.__ticks;
156
+ };
157
+
158
+ // called with scope of axis
159
+ $.jqplot.MekkoAxisRenderer.prototype.set = function() {
160
+ var dim = 0;
161
+ var temp;
162
+ var w = 0;
163
+ var h = 0;
164
+ var lshow = (this._label == null) ? false : this._label.show;
165
+ if (this.show && this.showTicks) {
166
+ var t = this._ticks;
167
+ for (var i=0; i<t.length; i++) {
168
+ var tick = t[i];
169
+ if (tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
170
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
171
+ temp = tick._elem.outerHeight(true);
172
+ }
173
+ else {
174
+ temp = tick._elem.outerWidth(true);
175
+ }
176
+ if (temp > dim) {
177
+ dim = temp;
178
+ }
179
+ }
180
+ }
181
+
182
+ if (lshow) {
183
+ w = this._label._elem.outerWidth(true);
184
+ h = this._label._elem.outerHeight(true);
185
+ }
186
+ if (this.name == 'xaxis') {
187
+ dim = dim + h;
188
+ this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
189
+ }
190
+ else if (this.name == 'x2axis') {
191
+ dim = dim + h;
192
+ this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
193
+ }
194
+ else if (this.name == 'yaxis') {
195
+ dim = dim + w;
196
+ this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
197
+ if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
198
+ this._label._elem.css('width', w+'px');
199
+ }
200
+ }
201
+ else {
202
+ dim = dim + w;
203
+ this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
204
+ if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
205
+ this._label._elem.css('width', w+'px');
206
+ }
207
+ }
208
+ }
209
+ };
210
+
211
+ // called with scope of axis
212
+ $.jqplot.MekkoAxisRenderer.prototype.createTicks = function() {
213
+ // we're are operating on an axis here
214
+ var ticks = this._ticks;
215
+ var userTicks = this.ticks;
216
+ var name = this.name;
217
+ // databounds were set on axis initialization.
218
+ var db = this._dataBounds;
219
+ var dim, interval;
220
+ var min, max;
221
+ var pos1, pos2;
222
+ var t, tt, i, j;
223
+
224
+ // if we already have ticks, use them.
225
+ // ticks must be in order of increasing value.
226
+
227
+ if (userTicks.length) {
228
+ // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
229
+ for (i=0; i<userTicks.length; i++){
230
+ var ut = userTicks[i];
231
+ var t = new this.tickRenderer(this.tickOptions);
232
+ if (ut.constructor == Array) {
233
+ t.value = ut[0];
234
+ t.label = ut[1];
235
+ if (!this.showTicks) {
236
+ t.showLabel = false;
237
+ t.showMark = false;
238
+ }
239
+ else if (!this.showTickMarks) {
240
+ t.showMark = false;
241
+ }
242
+ t.setTick(ut[0], this.name);
243
+ this._ticks.push(t);
244
+ }
245
+
246
+ else {
247
+ t.value = ut;
248
+ if (!this.showTicks) {
249
+ t.showLabel = false;
250
+ t.showMark = false;
251
+ }
252
+ else if (!this.showTickMarks) {
253
+ t.showMark = false;
254
+ }
255
+ t.setTick(ut, this.name);
256
+ this._ticks.push(t);
257
+ }
258
+ }
259
+ this.numberTicks = userTicks.length;
260
+ this.min = this._ticks[0].value;
261
+ this.max = this._ticks[this.numberTicks-1].value;
262
+ this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
263
+ }
264
+
265
+ // we don't have any ticks yet, let's make some!
266
+ else {
267
+ if (name == 'xaxis' || name == 'x2axis') {
268
+ dim = this._plotDimensions.width;
269
+ }
270
+ else {
271
+ dim = this._plotDimensions.height;
272
+ }
273
+
274
+ // if min, max and number of ticks specified, user can't specify interval.
275
+ if (this.min != null && this.max != null && this.numberTicks != null) {
276
+ this.tickInterval = null;
277
+ }
278
+
279
+ min = (this.min != null) ? this.min : db.min;
280
+ max = (this.max != null) ? this.max : db.max;
281
+
282
+ // if min and max are same, space them out a bit.+
283
+ if (min == max) {
284
+ var adj = 0.05;
285
+ if (min > 0) {
286
+ adj = Math.max(Math.log(min)/Math.LN10, 0.05);
287
+ }
288
+ min -= adj;
289
+ max += adj;
290
+ }
291
+
292
+ var range = max - min;
293
+ var rmin, rmax;
294
+ var temp, prev, curr;
295
+ var ynumticks = [3,5,6,11,21];
296
+
297
+ // yaxis divide ticks in nice intervals from 0 to 1.
298
+ if (this.name == 'yaxis' || this.name == 'y2axis') {
299
+ this.min = 0;
300
+ this.max = 100;
301
+ // user didn't specify number of ticks.
302
+ if (!this.numberTicks){
303
+ if (this.tickInterval) {
304
+ this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
305
+ }
306
+ else {
307
+ temp = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
308
+ for (i=0; i<ynumticks.length; i++) {
309
+ curr = temp/ynumticks[i];
310
+ if (curr == 1) {
311
+ this.numberTicks = ynumticks[i];
312
+ break;
313
+ }
314
+ else if (curr > 1) {
315
+ prev = curr;
316
+ continue;
317
+ }
318
+ else if (curr < 1) {
319
+ // was prev or is curr closer to one?
320
+ if (Math.abs(prev - 1) < Math.abs(curr - 1)) {
321
+ this.numberTicks = ynumticks[i-1];
322
+ break;
323
+ }
324
+ else {
325
+ this.numberTicks = ynumticks[i];
326
+ break;
327
+ }
328
+ }
329
+ else if (i == ynumticks.length -1) {
330
+ this.numberTicks = ynumticks[i];
331
+ }
332
+ }
333
+ this.tickInterval = range / (this.numberTicks - 1);
334
+ }
335
+ }
336
+
337
+ // user did specify number of ticks.
338
+ else {
339
+ this.tickInterval = range / (this.numberTicks - 1);
340
+ }
341
+
342
+ for (var i=0; i<this.numberTicks; i++){
343
+ tt = this.min + i * this.tickInterval;
344
+ t = new this.tickRenderer(this.tickOptions);
345
+ // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
346
+ if (!this.showTicks) {
347
+ t.showLabel = false;
348
+ t.showMark = false;
349
+ }
350
+ else if (!this.showTickMarks) {
351
+ t.showMark = false;
352
+ }
353
+ t.setTick(tt, this.name);
354
+ this._ticks.push(t);
355
+ }
356
+ }
357
+
358
+ // for x axes, have number ot ticks equal to number of series and ticks placed
359
+ // at sum of y values for each series.
360
+ else if (this.tickMode == 'bar') {
361
+ this.min = 0;
362
+ this.numberTicks = this._series.length + 1;
363
+ t = new this.tickRenderer(this.tickOptions);
364
+ if (!this.showTicks) {
365
+ t.showLabel = false;
366
+ t.showMark = false;
367
+ }
368
+ else if (!this.showTickMarks) {
369
+ t.showMark = false;
370
+ }
371
+ t.setTick(0, this.name);
372
+ this._ticks.push(t);
373
+
374
+ temp = 0;
375
+
376
+ for (i=1; i<this.numberTicks; i++){
377
+ temp += this._series[i-1]._sumy;
378
+ t = new this.tickRenderer(this.tickOptions);
379
+ if (!this.showTicks) {
380
+ t.showLabel = false;
381
+ t.showMark = false;
382
+ }
383
+ else if (!this.showTickMarks) {
384
+ t.showMark = false;
385
+ }
386
+ t.setTick(temp, this.name);
387
+ this._ticks.push(t);
388
+ }
389
+ this.max = this.max || temp;
390
+
391
+ // if user specified a max and it is greater than sum, add a tick
392
+ if (this.max > temp) {
393
+ t = new this.tickRenderer(this.tickOptions);
394
+ if (!this.showTicks) {
395
+ t.showLabel = false;
396
+ t.showMark = false;
397
+ }
398
+ else if (!this.showTickMarks) {
399
+ t.showMark = false;
400
+ }
401
+ t.setTick(this.max, this.name);
402
+ this._ticks.push(t);
403
+
404
+ }
405
+ }
406
+
407
+ else if (this.tickMode == 'even') {
408
+ this.min = 0;
409
+ this.max = this.max || db.max;
410
+ // get a desired number of ticks
411
+ var nt = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
412
+ range = this.max - this.min;
413
+ this.numberTicks = nt;
414
+ this.tickInterval = range / (this.numberTicks - 1);
415
+
416
+ for (i=0; i<this.numberTicks; i++){
417
+ tt = this.min + i * this.tickInterval;
418
+ t = new this.tickRenderer(this.tickOptions);
419
+ // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
420
+ if (!this.showTicks) {
421
+ t.showLabel = false;
422
+ t.showMark = false;
423
+ }
424
+ else if (!this.showTickMarks) {
425
+ t.showMark = false;
426
+ }
427
+ t.setTick(tt, this.name);
428
+ this._ticks.push(t);
429
+ }
430
+
431
+ }
432
+ }
433
+ };
434
+
435
+ // called with scope of axis
436
+ $.jqplot.MekkoAxisRenderer.prototype.pack = function(pos, offsets) {
437
+ var ticks = this._ticks;
438
+ var max = this.max;
439
+ var min = this.min;
440
+ var offmax = offsets.max;
441
+ var offmin = offsets.min;
442
+ var lshow = (this._label == null) ? false : this._label.show;
443
+
444
+ for (var p in pos) {
445
+ this._elem.css(p, pos[p]);
446
+ }
447
+
448
+ this._offsets = offsets;
449
+ // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
450
+ var pixellength = offmax - offmin;
451
+ var unitlength = max - min;
452
+
453
+ // point to unit and unit to point conversions references to Plot DOM element top left corner.
454
+ this.p2u = function(p){
455
+ return (p - offmin) * unitlength / pixellength + min;
456
+ };
457
+
458
+ this.u2p = function(u){
459
+ return (u - min) * pixellength / unitlength + offmin;
460
+ };
461
+
462
+ if (this.name == 'xaxis' || this.name == 'x2axis'){
463
+ this.series_u2p = function(u){
464
+ return (u - min) * pixellength / unitlength;
465
+ };
466
+ this.series_p2u = function(p){
467
+ return p * unitlength / pixellength + min;
468
+ };
469
+ }
470
+
471
+ else {
472
+ this.series_u2p = function(u){
473
+ return (u - max) * pixellength / unitlength;
474
+ };
475
+ this.series_p2u = function(p){
476
+ return p * unitlength / pixellength + max;
477
+ };
478
+ }
479
+
480
+ if (this.show) {
481
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
482
+ for (var i=0; i<ticks.length; i++) {
483
+ var t = ticks[i];
484
+ if (t.show && t.showLabel) {
485
+ var shim;
486
+
487
+ if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
488
+ // will need to adjust auto positioning based on which axis this is.
489
+ var temp = (this.name == 'xaxis') ? 1 : -1;
490
+ switch (t.labelPosition) {
491
+ case 'auto':
492
+ // position at end
493
+ if (temp * t.angle < 0) {
494
+ shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
495
+ }
496
+ // position at start
497
+ else {
498
+ shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
499
+ }
500
+ break;
501
+ case 'end':
502
+ shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
503
+ break;
504
+ case 'start':
505
+ shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
506
+ break;
507
+ case 'middle':
508
+ shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
509
+ break;
510
+ default:
511
+ shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
512
+ break;
513
+ }
514
+ }
515
+ else {
516
+ shim = -t.getWidth()/2;
517
+ }
518
+ var val = this.u2p(t.value) + shim + 'px';
519
+ t._elem.css('left', val);
520
+ t.pack();
521
+ }
522
+ }
523
+ var w;
524
+ if (lshow) {
525
+ w = this._label._elem.outerWidth(true);
526
+ this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
527
+ if (this.name == 'xaxis') {
528
+ this._label._elem.css('bottom', '0px');
529
+ }
530
+ else {
531
+ this._label._elem.css('top', '0px');
532
+ }
533
+ this._label.pack();
534
+ }
535
+ // now show the labels under the bars.
536
+ var b, l, r;
537
+ for (var i=0; i<this.barLabels.length; i++) {
538
+ b = this._barLabels[i];
539
+ if (b.show) {
540
+ w = b.getWidth();
541
+ l = this._ticks[i].getLeft() + this._ticks[i].getWidth();
542
+ r = this._ticks[i+1].getLeft();
543
+ b._elem.css('left', (r+l-w)/2+'px');
544
+ b._elem.css('top', this._ticks[i]._elem.css('top'));
545
+ b.pack();
546
+ }
547
+ }
548
+ }
549
+ else {
550
+ for (var i=0; i<ticks.length; i++) {
551
+ var t = ticks[i];
552
+ if (t.show && t.showLabel) {
553
+ var shim;
554
+ if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
555
+ // will need to adjust auto positioning based on which axis this is.
556
+ var temp = (this.name == 'yaxis') ? 1 : -1;
557
+ switch (t.labelPosition) {
558
+ case 'auto':
559
+ // position at end
560
+ case 'end':
561
+ if (temp * t.angle < 0) {
562
+ shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
563
+ }
564
+ else {
565
+ shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
566
+ }
567
+ break;
568
+ case 'start':
569
+ if (t.angle > 0) {
570
+ shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
571
+ }
572
+ else {
573
+ shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
574
+ }
575
+ break;
576
+ case 'middle':
577
+ shim = -t.getHeight()/2;
578
+ break;
579
+ default:
580
+ shim = -t.getHeight()/2;
581
+ break;
582
+ }
583
+ }
584
+ else {
585
+ shim = -t.getHeight()/2;
586
+ }
587
+
588
+ var val = this.u2p(t.value) + shim + 'px';
589
+ t._elem.css('top', val);
590
+ t.pack();
591
+ }
592
+ }
593
+ if (lshow) {
594
+ var h = this._label._elem.outerHeight(true);
595
+ this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
596
+ if (this.name == 'yaxis') {
597
+ this._label._elem.css('left', '0px');
598
+ }
599
+ else {
600
+ this._label._elem.css('right', '0px');
601
+ }
602
+ this._label.pack();
603
+ }
604
+ }
605
+ }
606
+ };
607
+ })(jQuery);