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