acts_as_dashboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +54 -0
  5. data/Rakefile +23 -0
  6. data/VERSION +1 -0
  7. data/acts_as_dashboard.gemspec +166 -0
  8. data/generators/dashboard/USAGE +23 -0
  9. data/generators/dashboard/dashboard_generator.rb +105 -0
  10. data/generators/dashboard/templates/controller.erb +39 -0
  11. data/generators/dashboard/templates/dashboard.css +66 -0
  12. data/generators/dashboard/templates/dashboard.js +305 -0
  13. data/generators/dashboard/templates/jqplot-0.9.7/jquery.jqplot.min.js +14 -0
  14. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.js +404 -0
  15. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.min.js +14 -0
  16. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.js +200 -0
  17. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.min.js +14 -0
  18. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.js +232 -0
  19. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.min.js +14 -0
  20. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.js +408 -0
  21. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.min.js +14 -0
  22. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.js +238 -0
  23. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.min.js +14 -0
  24. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.js +812 -0
  25. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.min.js +14 -0
  26. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.js +313 -0
  27. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.min.js +14 -0
  28. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.js +203 -0
  29. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.min.js +14 -0
  30. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.js +359 -0
  31. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.min.js +14 -0
  32. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.js +434 -0
  33. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.min.js +14 -0
  34. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.js +595 -0
  35. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.min.js +14 -0
  36. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.js +308 -0
  37. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.min.js +14 -0
  38. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.js +343 -0
  39. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.min.js +14 -0
  40. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.js +333 -0
  41. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.min.js +14 -0
  42. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js +307 -0
  43. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js.orig +273 -0
  44. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.min.js +14 -0
  45. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.js +208 -0
  46. data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.min.js +14 -0
  47. data/generators/dashboard/templates/jquery.jqplot.min.css +1 -0
  48. data/generators/dashboard/templates/js.class-2.1.4/CHANGELOG +269 -0
  49. data/generators/dashboard/templates/js.class-2.1.4/MIT-LICENSE +30 -0
  50. data/generators/dashboard/templates/js.class-2.1.4/README +30 -0
  51. data/generators/dashboard/templates/js.class-2.1.4/min/command.js +1 -0
  52. data/generators/dashboard/templates/js.class-2.1.4/min/comparable.js +1 -0
  53. data/generators/dashboard/templates/js.class-2.1.4/min/constant_scope.js +1 -0
  54. data/generators/dashboard/templates/js.class-2.1.4/min/core.js +1 -0
  55. data/generators/dashboard/templates/js.class-2.1.4/min/decorator.js +1 -0
  56. data/generators/dashboard/templates/js.class-2.1.4/min/enumerable.js +1 -0
  57. data/generators/dashboard/templates/js.class-2.1.4/min/forwardable.js +1 -0
  58. data/generators/dashboard/templates/js.class-2.1.4/min/hash.js +1 -0
  59. data/generators/dashboard/templates/js.class-2.1.4/min/linked_list.js +1 -0
  60. data/generators/dashboard/templates/js.class-2.1.4/min/loader.js +1 -0
  61. data/generators/dashboard/templates/js.class-2.1.4/min/method_chain.js +1 -0
  62. data/generators/dashboard/templates/js.class-2.1.4/min/observable.js +1 -0
  63. data/generators/dashboard/templates/js.class-2.1.4/min/package.js +1 -0
  64. data/generators/dashboard/templates/js.class-2.1.4/min/proxy.js +1 -0
  65. data/generators/dashboard/templates/js.class-2.1.4/min/ruby.js +1 -0
  66. data/generators/dashboard/templates/js.class-2.1.4/min/set.js +1 -0
  67. data/generators/dashboard/templates/js.class-2.1.4/min/stack_trace.js +1 -0
  68. data/generators/dashboard/templates/js.class-2.1.4/min/state.js +1 -0
  69. data/generators/dashboard/templates/js.class-2.1.4/min/stdlib.js +16 -0
  70. data/generators/dashboard/templates/js.class-2.1.4/src/command.js +93 -0
  71. data/generators/dashboard/templates/js.class-2.1.4/src/comparable.js +37 -0
  72. data/generators/dashboard/templates/js.class-2.1.4/src/constant_scope.js +48 -0
  73. data/generators/dashboard/templates/js.class-2.1.4/src/core.js +1060 -0
  74. data/generators/dashboard/templates/js.class-2.1.4/src/decorator.js +50 -0
  75. data/generators/dashboard/templates/js.class-2.1.4/src/enumerable.js +505 -0
  76. data/generators/dashboard/templates/js.class-2.1.4/src/forwardable.js +22 -0
  77. data/generators/dashboard/templates/js.class-2.1.4/src/hash.js +334 -0
  78. data/generators/dashboard/templates/js.class-2.1.4/src/linked_list.js +114 -0
  79. data/generators/dashboard/templates/js.class-2.1.4/src/loader.js +458 -0
  80. data/generators/dashboard/templates/js.class-2.1.4/src/method_chain.js +172 -0
  81. data/generators/dashboard/templates/js.class-2.1.4/src/observable.js +55 -0
  82. data/generators/dashboard/templates/js.class-2.1.4/src/package.js +377 -0
  83. data/generators/dashboard/templates/js.class-2.1.4/src/proxy.js +58 -0
  84. data/generators/dashboard/templates/js.class-2.1.4/src/ruby.js +44 -0
  85. data/generators/dashboard/templates/js.class-2.1.4/src/set.js +332 -0
  86. data/generators/dashboard/templates/js.class-2.1.4/src/stack_trace.js +151 -0
  87. data/generators/dashboard/templates/js.class-2.1.4/src/state.js +95 -0
  88. data/generators/dashboard/templates/js.class-2.1.4/src/stdlib.js +2517 -0
  89. data/generators/dashboard/templates/show.html.erb +67 -0
  90. data/lib/acts_as_dashboard/app/views/dashboards/show.html.erb +67 -0
  91. data/lib/acts_as_dashboard/class_methods.rb +58 -0
  92. data/lib/acts_as_dashboard/config.rb +25 -0
  93. data/lib/acts_as_dashboard/instance_methods.rb +32 -0
  94. data/lib/acts_as_dashboard/line_graph_widget.rb +68 -0
  95. data/lib/acts_as_dashboard/public/javascripts/dashboard.js +305 -0
  96. data/lib/acts_as_dashboard/public/stylesheets/dashboard.css +66 -0
  97. data/lib/acts_as_dashboard/short_messages_widget.rb +25 -0
  98. data/lib/acts_as_dashboard/widget.rb +55 -0
  99. data/lib/acts_as_dashboard.rb +17 -0
  100. data/spec/acts_as_dashboard/class_method_specs.rb +188 -0
  101. data/spec/acts_as_dashboard/config_spec.rb +57 -0
  102. data/spec/acts_as_dashboard/instance_methods_spec.rb +134 -0
  103. data/spec/acts_as_dashboard/line_graph_widget_spec.rb +165 -0
  104. data/spec/acts_as_dashboard/short_messages_widget_spec.rb +69 -0
  105. data/spec/acts_as_dashboard/widget_spec.rb +6 -0
  106. data/spec/acts_as_dashboard_spec.rb +15 -0
  107. data/spec/shared/widget_behaviours.rb +171 -0
  108. data/spec/spec.opts +1 -0
  109. data/spec/spec_helper.rb +10 -0
  110. data/tasks/install.rake +8 -0
  111. data/tasks/install_javascript.rake +7 -0
  112. data/tasks/install_stylesheets.rake +7 -0
  113. metadata +209 -0
@@ -0,0 +1,434 @@
1
+ /**
2
+ * Copyright (c) 2009 Chris Leonello
3
+ * jqPlot is currently available for use in all personal or commercial projects
4
+ * under both the MIT and GPL version 2.0 licenses. This means that you can
5
+ * choose the license that best suits your project and use it accordingly.
6
+ *
7
+ * The author would appreciate an email letting him know of any substantial
8
+ * use of jqPlot. You can reach the author at: chris dot leonello at gmail
9
+ * dot com or see http://www.jqplot.com/info.php . This is, of course,
10
+ * not required.
11
+ *
12
+ * If you are feeling kind and generous, consider supporting the project by
13
+ * making a donation at: http://www.jqplot.com/donate.php .
14
+ *
15
+ * Thanks for using jqPlot!
16
+ *
17
+ */
18
+ (function($) {
19
+ /**
20
+ * class: $.jqplot.LogAxisRenderer
21
+ * A plugin for a jqPlot to render a logarithmic axis.
22
+ *
23
+ * To use this renderer, include the plugin in your source
24
+ * > <script type="text/javascript" language="javascript" src="plugins/jqplot.logAxisRenderer.js"></script>
25
+ *
26
+ * and supply the appropriate options to your plot
27
+ *
28
+ * > {axes:{xaxis:{renderer:$.jqplot.LogAxisRenderer}}}
29
+ **/
30
+ $.jqplot.LogAxisRenderer = function() {
31
+ $.jqplot.LinearAxisRenderer.call(this);
32
+ // prop: axisDefaults
33
+ // Default properties which will be applied directly to the series.
34
+ //
35
+ // Group: Properties
36
+ //
37
+ // Properties
38
+ //
39
+ /// base - the logarithmic base, commonly 2, 10 or Math.E
40
+ // tickDistribution - 'even' or 'power'. 'even' gives equal pixel
41
+ // spacing of the ticks on the plot. 'power' gives ticks in powers
42
+ // of 10.
43
+ this.axisDefaults = {
44
+ base : 10,
45
+ tickDistribution :'even'
46
+ };
47
+ };
48
+
49
+ $.jqplot.LogAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
50
+ $.jqplot.LogAxisRenderer.prototype.constructor = $.jqplot.LogAxisRenderer;
51
+
52
+ $.jqplot.LogAxisRenderer.prototype.init = function(options) {
53
+ // prop: tickRenderer
54
+ // A class of a rendering engine for creating the ticks labels displayed on the plot,
55
+ // See <$.jqplot.AxisTickRenderer>.
56
+ // this.tickRenderer = $.jqplot.AxisTickRenderer;
57
+ // this.labelRenderer = $.jqplot.AxisLabelRenderer;
58
+ $.extend(true, this.renderer, options);
59
+ for (var d in this.renderer.axisDefaults) {
60
+ if (this[d] == null) {
61
+ this[d] = this.renderer.axisDefaults[d];
62
+ }
63
+ }
64
+ var db = this._dataBounds;
65
+ // Go through all the series attached to this axis and find
66
+ // the min/max bounds for this axis.
67
+ for (var i=0; i<this._series.length; i++) {
68
+ var s = this._series[i];
69
+ var d = s.data;
70
+
71
+ for (var j=0; j<d.length; j++) {
72
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
73
+ if (d[j][0] > db.max || db.max == null) {
74
+ db.max = d[j][0];
75
+ }
76
+ if (d[j][0] > db.max || db.max == null) {
77
+ db.max = d[j][0];
78
+ }
79
+ }
80
+ else {
81
+ if (d[j][1] < db.min || db.min == null) {
82
+ db.min = d[j][1];
83
+ }
84
+ if (d[j][1] > db.max || db.max == null) {
85
+ db.max = d[j][1];
86
+ }
87
+ }
88
+ }
89
+ }
90
+ };
91
+
92
+ $.jqplot.LogAxisRenderer.prototype.createTicks = function() {
93
+ // we're are operating on an axis here
94
+ var ticks = this._ticks;
95
+ var userTicks = this.ticks;
96
+ var name = this.name;
97
+ var db = this._dataBounds;
98
+ var dim, interval;
99
+ var min, max;
100
+ var pos1, pos2;
101
+ var tt, i;
102
+
103
+ // if we already have ticks, use them.
104
+ // ticks must be in order of increasing value.
105
+ if (userTicks.length) {
106
+ // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
107
+ for (i=0; i<userTicks.length; i++){
108
+ var ut = userTicks[i];
109
+ var t = new this.tickRenderer(this.tickOptions);
110
+ if (ut.constructor == Array) {
111
+ t.value = ut[0];
112
+ t.label = ut[1];
113
+ if (!this.showTicks) {
114
+ t.showLabel = false;
115
+ t.showMark = false;
116
+ }
117
+ else if (!this.showTickMarks) {
118
+ t.showMark = false;
119
+ }
120
+ t.setTick(ut[0], this.name);
121
+ this._ticks.push(t);
122
+ }
123
+
124
+ else {
125
+ t.value = ut;
126
+ if (!this.showTicks) {
127
+ t.showLabel = false;
128
+ t.showMark = false;
129
+ }
130
+ else if (!this.showTickMarks) {
131
+ t.showMark = false;
132
+ }
133
+ t.setTick(ut, this.name);
134
+ this._ticks.push(t);
135
+ }
136
+ }
137
+ this.numberTicks = userTicks.length;
138
+ this.min = this._ticks[0].value;
139
+ this.max = this._ticks[this.numberTicks-1].value;
140
+ }
141
+
142
+ // we don't have any ticks yet, let's make some!
143
+ else {
144
+ if (name == 'xaxis' || name == 'x2axis') {
145
+ dim = this._plotDimensions.width;
146
+ }
147
+ else {
148
+ dim = this._plotDimensions.height;
149
+ }
150
+
151
+ min = ((this.min != null) ? this.min : db.min);
152
+ max = ((this.max != null) ? this.max : db.max);
153
+
154
+ // if min and max are same, space them out a bit
155
+ if (min == max) {
156
+ var adj = 0.05;
157
+ min = min*(1-adj);
158
+ max = max*(1+adj);
159
+ }
160
+
161
+ // perform some checks
162
+ if (this.min != null && this.min <= 0) {
163
+ throw('log axis minimum must be greater than 0');
164
+ }
165
+ if (this.max != null && this.max <= 0) {
166
+ throw('log axis maximum must be greater than 0');
167
+ }
168
+ // if (this.pad >1.99) this.pad = 1.99;
169
+ var range = max - min;
170
+ var rmin, rmax;
171
+
172
+ if (this.tickDistribution == 'even') {
173
+ rmin = (this.min != null) ? this.min : min - min*((this.padMin-1)/2);
174
+ rmax = (this.max != null) ? this.max : max + max*((this.padMax-1)/2);
175
+ this.min = rmin;
176
+ this.max = rmax;
177
+ range = this.max - this.min;
178
+
179
+ if (this.numberTicks == null){
180
+ if (dim > 100) {
181
+ this.numberTicks = parseInt(3+(dim-100)/75, 10);
182
+ }
183
+ else {
184
+ this.numberTicks = 2;
185
+ }
186
+ }
187
+
188
+ var u = Math.pow(this.base, (1/(this.numberTicks-1)*Math.log(this.max/this.min)/Math.log(this.base)));
189
+ for (var i=0; i<this.numberTicks; i++){
190
+ tt = this.min * Math.pow(u, i);
191
+ var t = new this.tickRenderer(this.tickOptions);
192
+ if (!this.showTicks) {
193
+ t.showLabel = false;
194
+ t.showMark = false;
195
+ }
196
+ else if (!this.showTickMarks) {
197
+ t.showMark = false;
198
+ }
199
+ t.setTick(tt, this.name);
200
+ this._ticks.push(t);
201
+ }
202
+
203
+ }
204
+
205
+ else if (this.tickDistribution == 'power'){
206
+ // for power distribution, open up range to get a nice power of axis.renderer.base.
207
+ // power distribution won't respect the user's min/max settings.
208
+ rmin = Math.pow(this.base, Math.ceil(Math.log(min*(2-this.padMin))/Math.log(this.base))-1);
209
+ rmax = Math.pow(this.base, Math.floor(Math.log(max*this.padMax)/Math.log(this.base))+1);
210
+ this.min = rmin;
211
+ this.max = rmax;
212
+ range = this.max - this.min;
213
+
214
+ var fittedTicks = 0;
215
+ var minorTicks = 0;
216
+ if (this.numberTicks == null){
217
+ if (dim > 100) {
218
+ this.numberTicks = Math.round(Math.log(this.max/this.min)/Math.log(this.base) + 1);
219
+ if (this.numberTicks < 2) {
220
+ this.numberTicks = 2;
221
+ }
222
+ fittedTicks = parseInt(3+(dim-100)/75, 10);
223
+ }
224
+ else {
225
+ this.numberTicks = 2;
226
+ fittedTicks = 2;
227
+ }
228
+ // if we don't have enough ticks, add some intermediate ticks
229
+ // how many to have between major ticks.
230
+ if (this.numberTicks < fittedTicks-1) {
231
+ minorTicks = Math.floor(fittedTicks/this.numberTicks);
232
+ }
233
+ }
234
+
235
+ for (var i=0; i<this.numberTicks; i++){
236
+ tt = Math.pow(this.base, i - this.numberTicks + 1) * this.max;
237
+ var t = new this.tickRenderer(this.tickOptions);
238
+ if (!this.showTicks) {
239
+ t.showLabel = false;
240
+ t.showMark = false;
241
+ }
242
+ else if (!this.showTickMarks) {
243
+ t.showMark = false;
244
+ }
245
+ t.setTick(tt, this.name);
246
+ this._ticks.push(t);
247
+
248
+ if (minorTicks && i<this.numberTicks-1) {
249
+ var tt1 = Math.pow(this.base, i - this.numberTicks + 2) * this.max;
250
+ var spread = tt1 - tt;
251
+ var interval = tt1 / (minorTicks+1);
252
+ for (var j=minorTicks-1; j>=0; j--) {
253
+ var val = tt1-interval*(j+1);
254
+ var t = new this.tickRenderer(this.tickOptions);
255
+ if (!this.showTicks) {
256
+ t.showLabel = false;
257
+ t.showMark = false;
258
+ }
259
+ else if (!this.showTickMarks) {
260
+ t.showMark = false;
261
+ }
262
+ t.setTick(val, this.name);
263
+ this._ticks.push(t);
264
+ }
265
+ }
266
+ }
267
+ }
268
+ }
269
+ };
270
+
271
+ $.jqplot.LogAxisRenderer.prototype.pack = function(pos, offsets) {
272
+ var lb = parseInt(this.base, 10);
273
+ var ticks = this._ticks;
274
+ var trans = function (v) { return Math.log(v)/Math.log(lb); };
275
+ var invtrans = function (v) { return Math.pow(Math.E, (Math.log(lb)*v)); };
276
+ max = trans(this.max);
277
+ min = trans(this.min);
278
+ var offmax = offsets.max;
279
+ var offmin = offsets.min;
280
+ var lshow = (this._label == null) ? false : this._label.show;
281
+
282
+ for (var p in pos) {
283
+ this._elem.css(p, pos[p]);
284
+ }
285
+
286
+ this._offsets = offsets;
287
+ // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
288
+ var pixellength = offmax - offmin;
289
+ var unitlength = max - min;
290
+
291
+ // point to unit and unit to point conversions references to Plot DOM element top left corner.
292
+ this.p2u = function(p){
293
+ return invtrans((p - offmin) * unitlength / pixellength + min);
294
+ };
295
+
296
+ this.u2p = function(u){
297
+ return (trans(u) - min) * pixellength / unitlength + offmin;
298
+ };
299
+
300
+ if (this.name == 'xaxis' || this.name == 'x2axis'){
301
+ this.series_u2p = function(u){
302
+ return (trans(u) - min) * pixellength / unitlength;
303
+ };
304
+ this.series_p2u = function(p){
305
+ return invtrans(p * unitlength / pixellength + min);
306
+ };
307
+ }
308
+ // yaxis is max at top of canvas.
309
+ else {
310
+ this.series_u2p = function(u){
311
+ return (trans(u) - max) * pixellength / unitlength;
312
+ };
313
+ this.series_p2u = function(p){
314
+ return invtrans(p * unitlength / pixellength + max);
315
+ };
316
+ }
317
+
318
+ if (this.show) {
319
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
320
+ for (i=0; i<ticks.length; i++) {
321
+ var t = ticks[i];
322
+ if (t.show && t.showLabel) {
323
+ var shim;
324
+
325
+ if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
326
+ switch (t.labelPosition) {
327
+ case 'auto':
328
+ // position at end
329
+ if (t.angle < 0) {
330
+ shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
331
+ }
332
+ // position at start
333
+ else {
334
+ shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
335
+ }
336
+ break;
337
+ case 'end':
338
+ shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
339
+ break;
340
+ case 'start':
341
+ shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
342
+ break;
343
+ case 'middle':
344
+ shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
345
+ break;
346
+ default:
347
+ shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
348
+ break;
349
+ }
350
+ }
351
+ else {
352
+ shim = -t.getWidth()/2;
353
+ }
354
+ // var shim = t.getWidth()/2;
355
+ var val = this.u2p(t.value) + shim + 'px';
356
+ t._elem.css('left', val);
357
+ t.pack();
358
+ }
359
+ }
360
+ if (lshow) {
361
+ var w = this._label._elem.outerWidth(true);
362
+ this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
363
+ if (this.name == 'xaxis') {
364
+ this._label._elem.css('bottom', '0px');
365
+ }
366
+ else {
367
+ this._label._elem.css('top', '0px');
368
+ }
369
+ this._label.pack();
370
+ }
371
+ }
372
+ else {
373
+ for (i=0; i<ticks.length; i++) {
374
+ var t = ticks[i];
375
+ if (t.show && t.showLabel) {
376
+ var shim;
377
+ if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
378
+ switch (t.labelPosition) {
379
+ case 'auto':
380
+ // position at end
381
+ case 'end':
382
+ if (t.angle < 0) {
383
+ shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
384
+ }
385
+ else {
386
+ shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
387
+ }
388
+ break;
389
+ case 'start':
390
+ if (t.angle > 0) {
391
+ shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
392
+ }
393
+ else {
394
+ shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
395
+ }
396
+ break;
397
+ case 'middle':
398
+ // if (t.angle > 0) {
399
+ // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
400
+ // }
401
+ // else {
402
+ // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
403
+ // }
404
+ shim = -t.getHeight()/2;
405
+ break;
406
+ default:
407
+ shim = -t.getHeight()/2;
408
+ break;
409
+ }
410
+ }
411
+ else {
412
+ shim = -t.getHeight()/2;
413
+ }
414
+
415
+ var val = this.u2p(t.value) + shim + 'px';
416
+ t._elem.css('top', val);
417
+ t.pack();
418
+ }
419
+ }
420
+ if (lshow) {
421
+ var h = this._label._elem.outerHeight(true);
422
+ this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
423
+ if (this.name == 'yaxis') {
424
+ this._label._elem.css('left', '0px');
425
+ }
426
+ else {
427
+ this._label._elem.css('right', '0px');
428
+ }
429
+ this._label.pack();
430
+ }
431
+ }
432
+ }
433
+ };
434
+ })(jQuery);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2009 Chris Leonello
3
+ * jqPlot is currently available for use in all personal or commercial projects
4
+ * under both the MIT and GPL version 2.0 licenses. This means that you can
5
+ * choose the license that best suits your project and use it accordingly.
6
+ *
7
+ * Although not required, the author would appreciate an email letting him
8
+ * know of any substantial use of jqPlot. You can reach the author at:
9
+ * chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
10
+ *
11
+ * If you are feeling kind and generous, consider supporting the project by
12
+ * making a donation at: http://www.jqplot.com/donate.php .
13
+ */
14
+ (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]>b.max||b.max==null){b.max=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]}}}}};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(n,j){var d=parseInt(this.base,10);var q=this._ticks;var v=function(h){return Math.log(h)/Math.log(d)};var b=function(h){return Math.pow(Math.E,(Math.log(d)*h))};max=v(this.max);min=v(this.min);var g=j.max;var u=j.min;var l=(this._label==null)?false:this._label.show;for(var c in n){this._elem.css(c,n[c])}this._offsets=j;var f=g-u;var s=max-min;this.p2u=function(h){return b((h-u)*s/f+min)};this.u2p=function(h){return(v(h)-min)*f/s+u};if(this.name=="xaxis"||this.name=="x2axis"){this.series_u2p=function(h){return(v(h)-min)*f/s};this.series_p2u=function(h){return b(h*s/f+min)}}else{this.series_u2p=function(h){return(v(h)-max)*f/s};this.series_p2u=function(h){return b(h*s/f+max)}}if(this.show){if(this.name=="xaxis"||this.name=="x2axis"){for(i=0;i<q.length;i++){var r=q[i];if(r.show&&r.showLabel){var k;if(r.constructor==a.jqplot.CanvasAxisTickRenderer&&r.angle){switch(r.labelPosition){case"auto":if(r.angle<0){k=-r.getWidth()+r._textRenderer.height*Math.sin(-r._textRenderer.angle)/2}else{k=-r._textRenderer.height*Math.sin(r._textRenderer.angle)/2}break;case"end":k=-r.getWidth()+r._textRenderer.height*Math.sin(-r._textRenderer.angle)/2;break;case"start":k=-r._textRenderer.height*Math.sin(r._textRenderer.angle)/2;break;case"middle":k=-r.getWidth()/2+r._textRenderer.height*Math.sin(-r._textRenderer.angle)/2;break;default:k=-r.getWidth()/2+r._textRenderer.height*Math.sin(-r._textRenderer.angle)/2;break}}else{k=-r.getWidth()/2}var e=this.u2p(r.value)+k+"px";r._elem.css("left",e);r.pack()}}if(l){var o=this._label._elem.outerWidth(true);this._label._elem.css("left",u+f/2-o/2+"px");if(this.name=="xaxis"){this._label._elem.css("bottom","0px")}else{this._label._elem.css("top","0px")}this._label.pack()}}else{for(i=0;i<q.length;i++){var r=q[i];if(r.show&&r.showLabel){var k;if(r.constructor==a.jqplot.CanvasAxisTickRenderer&&r.angle){switch(r.labelPosition){case"auto":case"end":if(r.angle<0){k=-r._textRenderer.height*Math.cos(-r._textRenderer.angle)/2}else{k=-r.getHeight()+r._textRenderer.height*Math.cos(r._textRenderer.angle)/2}break;case"start":if(r.angle>0){k=-r._textRenderer.height*Math.cos(-r._textRenderer.angle)/2}else{k=-r.getHeight()+r._textRenderer.height*Math.cos(r._textRenderer.angle)/2}break;case"middle":k=-r.getHeight()/2;break;default:k=-r.getHeight()/2;break}}else{k=-r.getHeight()/2}var e=this.u2p(r.value)+k+"px";r._elem.css("top",e);r.pack()}}if(l){var m=this._label._elem.outerHeight(true);this._label._elem.css("top",g-f/2-m/2+"px");if(this.name=="yaxis"){this._label._elem.css("left","0px")}else{this._label._elem.css("right","0px")}this._label.pack()}}}}})(jQuery);