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,273 @@
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
+ /**
21
+ * Class: $.jqplot.PointLabels
22
+ * Plugin for putting labels at the data points.
23
+ *
24
+ * To use this plugin, include the js
25
+ * file in your source:
26
+ *
27
+ * > <script type="text/javascript" src="plugins/jqplot.pointLabels.js"></script>
28
+ *
29
+ * By default, the last value in the data ponit array in the data series is used
30
+ * for the label. For most series renderers, extra data can be added to the
31
+ * data point arrays and the last value will be used as the label.
32
+ *
33
+ * For instance,
34
+ * this series:
35
+ *
36
+ * > [[1,4], [3,5], [7,2]]
37
+ *
38
+ * Would, by default, use the y values in the labels.
39
+ * Extra data can be added to the series like so:
40
+ *
41
+ * > [[1,4,'mid'], [3 5,'hi'], [7,2,'low']]
42
+ *
43
+ * And now the point labels would be 'mid', 'low', and 'hi'.
44
+ *
45
+ * Options to the point labels and a custom labels array can be passed into the
46
+ * "pointLabels" option on the series option like so:
47
+ *
48
+ * > series:[{pointLabels:{
49
+ * > labels:['mid', 'hi', 'low'],
50
+ * > location:'se',
51
+ * > ypadding: 12
52
+ * > }
53
+ * > }]
54
+ *
55
+ * A custom labels array in the options takes precendence over any labels
56
+ * in the series data. If you have a custom labels array in the options,
57
+ * but still want to use values from the series array as labels, set the
58
+ * "labelsFromSeries" option to true.
59
+ *
60
+ * By default, html entities (<, >, etc.) are escaped in point labels.
61
+ * If you want to include actual html markup in the labels,
62
+ * set the "escapeHTML" option to false.
63
+ *
64
+ */
65
+ $.jqplot.PointLabels = function(options) {
66
+ // Group: Properties
67
+ //
68
+ // prop: show
69
+ // show the labels or not.
70
+ this.show = $.jqplot.config.enablePlugins;
71
+ // prop: location
72
+ // compass location where to position the label around the point.
73
+ // 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
74
+ this.location = 'n';
75
+ // prop: labelsFromSeries
76
+ // true to use labels within data point arrays.
77
+ this.labelsFromSeries = false;
78
+ // prop: seriesLabelIndex
79
+ // array index for location of labels within data point arrays.
80
+ // if null, will use the last element of teh data point array.
81
+ this.seriesLabelIndex = null;
82
+ // prop: labels
83
+ // array of arrays of labels, one array for each series.
84
+ this.labels = [];
85
+ // prop: stackedValue
86
+ // true to display value as stacked in a stacked plot.
87
+ // no effect if labels is specified.
88
+ this.stackedValue = false;
89
+ // prop: ypadding
90
+ // vertical padding in pixels between point and label
91
+ this.ypadding = 6;
92
+ // prop: xpadding
93
+ // horizontal padding in pixels between point and label
94
+ this.xpadding = 6;
95
+ // prop: escapeHTML
96
+ // true to escape html entities in the labels.
97
+ // If you want to include markup in the labels, set to false.
98
+ this.escapeHTML = true;
99
+ // prop: edgeTolerance
100
+ // Number of pixels that the label must be away from an axis
101
+ // boundary in order to be drawn. Negative values will allow overlap
102
+ // with the grid boundaries.
103
+ this.edgeTolerance = 0;
104
+ // prop: hideZeros
105
+ // true to not show a label for a value which is 0.
106
+ this.hideZeros = false;
107
+ // prop: formatString
108
+ // format string to format label value
109
+ this.formatString = '';
110
+ // prop: formatter
111
+ // formatter function to use with format string.
112
+ this.formatter = $.jqplot.sprintf;
113
+
114
+ $.extend(true, this, options);
115
+ };
116
+
117
+ var locations = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
118
+ var locationIndicies = {'nw':0, 'n':1, 'ne':2, 'e':3, 'se':4, 's':5, 'sw':6, 'w':7};
119
+ var oppositeLocations = ['se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
120
+
121
+ // called with scope of a series
122
+ $.jqplot.PointLabels.init = function (target, data, seriesDefaults, opts){
123
+ var options = $.extend(true, {}, seriesDefaults, opts);
124
+ // add a pointLabels attribute to the series plugins
125
+ this.plugins.pointLabels = new $.jqplot.PointLabels(options.pointLabels);
126
+ var p = this.plugins.pointLabels;
127
+ if (p.labels.length == 0 || p.labelsFromSeries) {
128
+ if (p.stackedValue) {
129
+ if (this._plotData.length && this._plotData[0].length){
130
+ var idx = p.seriesLabelIndex || this._plotData[0].length -1;
131
+ for (var i=0; i<this._plotData.length; i++) {
132
+ p.labels.push(this._plotData[i][idx]);
133
+ }
134
+ }
135
+ }
136
+ else {
137
+ var d = this.data;
138
+ if (this.renderer.constructor == $.jqplot.BarRenderer && this.waterfall) {
139
+ d = this._data;
140
+ }
141
+ if (d.length && d[0].length) {
142
+ var idx = p.seriesLabelIndex || d[0].length -1;
143
+ for (var i=0; i<d.length; i++) {
144
+ p.labels.push(d[i][idx]);
145
+ }
146
+ }
147
+ }
148
+ }
149
+ };
150
+
151
+ $.jqplot.PointLabels.prototype.xOffset = function(elem, location, padding) {
152
+ location = location || this.location;
153
+ padding = padding || this.xpadding;
154
+ var offset;
155
+
156
+ switch (location) {
157
+ case 'nw':
158
+ offset = -elem.outerWidth(true) - this.xpadding;
159
+ break;
160
+ case 'n':
161
+ offset = -elem.outerWidth(true)/2;
162
+ break;
163
+ case 'ne':
164
+ offset = this.xpadding;
165
+ break;
166
+ case 'e':
167
+ offset = this.xpadding;
168
+ break;
169
+ case 'se':
170
+ offset = this.xpadding;
171
+ break;
172
+ case 's':
173
+ offset = -elem.outerWidth(true)/2;
174
+ break;
175
+ case 'sw':
176
+ offset = -elem.outerWidth(true) - this.xpadding;
177
+ break;
178
+ case 'w':
179
+ offset = -elem.outerWidth(true) - this.xpadding;
180
+ break;
181
+ default: // same as 'nw'
182
+ offset = -elem.outerWidth(true) - this.xpadding;
183
+ break;
184
+ }
185
+ return offset;
186
+ };
187
+
188
+ $.jqplot.PointLabels.prototype.yOffset = function(elem, location, padding) {
189
+ location = location || this.location;
190
+ padding = padding || this.xpadding;
191
+ var offset;
192
+
193
+ switch (location) {
194
+ case 'nw':
195
+ offset = -elem.outerHeight(true) - this.ypadding;
196
+ break;
197
+ case 'n':
198
+ offset = -elem.outerHeight(true) - this.ypadding;
199
+ break;
200
+ case 'ne':
201
+ offset = -elem.outerHeight(true) - this.ypadding;
202
+ break;
203
+ case 'e':
204
+ offset = -elem.outerHeight(true)/2;
205
+ break;
206
+ case 'se':
207
+ offset = this.ypadding;
208
+ break;
209
+ case 's':
210
+ offset = this.ypadding;
211
+ break;
212
+ case 'sw':
213
+ offset = this.ypadding;
214
+ break;
215
+ case 'w':
216
+ offset = -elem.outerHeight(true)/2;
217
+ break;
218
+ default: // same as 'nw'
219
+ offset = -elem.outerHeight(true) - this.ypadding;
220
+ break;
221
+ }
222
+ return offset;
223
+ };
224
+
225
+ // called with scope of series
226
+ $.jqplot.PointLabels.draw = function (sctx, options) {
227
+ var p = this.plugins.pointLabels;
228
+ if (p.show) {
229
+
230
+ for (var i=0; i<p.labels.length; i++) {
231
+ var pd = this._plotData;
232
+ var xax = this._xaxis;
233
+ var yax = this._yaxis;
234
+ var label = p.labels[i];
235
+
236
+ if (p.hideZeros && parseInt(p.labels[i], 10) == 0) {
237
+ label = '';
238
+ }
239
+
240
+ var elem = $('<div class="jqplot-point-label" style="position:absolute"></div>');
241
+ elem.insertAfter(sctx.canvas);
242
+ if (p.escapeHTML) {
243
+ elem.text(label);
244
+ }
245
+ else {
246
+ elem.html(label);
247
+ }
248
+ var location = p.location;
249
+ if (this.waterfall && parseInt(label, 10) < 0) {
250
+ location = oppositeLocations[locationIndicies[location]];
251
+ }
252
+ var ell = xax.u2p(pd[i][0]) + p.xOffset(elem, location);
253
+ var elt = yax.u2p(pd[i][1]) + p.yOffset(elem, location);
254
+ elem.css('left', ell);
255
+ elem.css('top', elt);
256
+ var elr = ell + $(elem).width();
257
+ var elb = elt + $(elem).height();
258
+ var et = p.edgeTolerance;
259
+ var scl = $(sctx.canvas).position().left;
260
+ var sct = $(sctx.canvas).position().top;
261
+ var scr = sctx.canvas.width + scl;
262
+ var scb = sctx.canvas.height + sct;
263
+ // if label is outside of allowed area, remove it
264
+ if (ell - et < scl || elt - et < sct || elr + et > scr || elb + et > scb) {
265
+ $(elem).remove();
266
+ }
267
+ }
268
+ }
269
+ };
270
+
271
+ $.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);
272
+ $.jqplot.postDrawSeriesHooks.push($.jqplot.PointLabels.draw);
273
+ })(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(c){c.jqplot.PointLabels=function(e){this.show=c.jqplot.config.enablePlugins;this.location="n";this.labelsFromSeries=false;this.seriesLabelIndex=null;this.labels=[];this.stackedValue=false;this.ypadding=6;this.xpadding=6;this.escapeHTML=true;this.edgeTolerance=0;this.hideZeros=false;c.extend(true,this,e)};var a=["nw","n","ne","e","se","s","sw","w"];var d={nw:0,n:1,ne:2,e:3,se:4,s:5,sw:6,w:7};var b=["se","s","sw","w","nw","n","ne","e"];c.jqplot.PointLabels.init=function(k,h,g,e){var n=c.extend(true,{},g,e);this.plugins.pointLabels=new c.jqplot.PointLabels(n.pointLabels);var f=this.plugins.pointLabels;if(f.labels.length==0||f.labelsFromSeries){if(f.stackedValue){if(this._plotData.length&&this._plotData[0].length){var m=f.seriesLabelIndex||this._plotData[0].length-1;for(var j=0;j<this._plotData.length;j++){f.labels.push(this._plotData[j][m])}}}else{var l=this.data;if(this.renderer.constructor==c.jqplot.BarRenderer&&this.waterfall){l=this._data}if(l.length&&l[0].length){var m=f.seriesLabelIndex||l[0].length-1;for(var j=0;j<l.length;j++){f.labels.push(l[j][m])}}}}};c.jqplot.PointLabels.prototype.xOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerWidth(true)-this.xpadding;break;case"n":h=-f.outerWidth(true)/2;break;case"ne":h=this.xpadding;break;case"e":h=this.xpadding;break;case"se":h=this.xpadding;break;case"s":h=-f.outerWidth(true)/2;break;case"sw":h=-f.outerWidth(true)-this.xpadding;break;case"w":h=-f.outerWidth(true)-this.xpadding;break;default:h=-f.outerWidth(true)-this.xpadding;break}return h};c.jqplot.PointLabels.prototype.yOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerHeight(true)-this.ypadding;break;case"n":h=-f.outerHeight(true)-this.ypadding;break;case"ne":h=-f.outerHeight(true)-this.ypadding;break;case"e":h=-f.outerHeight(true)/2;break;case"se":h=this.ypadding;break;case"s":h=this.ypadding;break;case"sw":h=this.ypadding;break;case"w":h=-f.outerHeight(true)/2;break;default:h=-f.outerHeight(true)-this.ypadding;break}return h};c.jqplot.PointLabels.draw=function(s,h){var q=this.plugins.pointLabels;if(q.show){for(var r=0;r<q.labels.length;r++){var y=this._plotData;var v=this._xaxis;var n=this._yaxis;var m=q.labels[r];if(q.hideZeros&&parseInt(q.labels[r],10)==0){m=""}var u=c('<div class="jqplot-point-label" style="position:absolute"></div>');u.insertAfter(s.canvas);if(q.escapeHTML){u.text(m)}else{u.html(m)}var f=q.location;if(this.waterfall&&parseInt(m,10)<0){f=b[d[f]]}var l=v.u2p(y[r][0])+q.xOffset(u,f);var g=n.u2p(y[r][1])+q.yOffset(u,f);u.css("left",l);u.css("top",g);var j=l+c(u).width();var o=g+c(u).height();var x=q.edgeTolerance;var e=c(s.canvas).position().left;var t=c(s.canvas).position().top;var w=s.canvas.width+e;var k=s.canvas.height+t;if(l-x<e||g-x<t||j+x>w||o+x>k){c(u).remove()}}}};c.jqplot.postSeriesInitHooks.push(c.jqplot.PointLabels.init);c.jqplot.postDrawSeriesHooks.push(c.jqplot.PointLabels.draw)})(jQuery);
@@ -0,0 +1,208 @@
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
+ /**
21
+ * Class: $.jqplot.Trendline
22
+ * Plugin which will automatically compute and draw trendlines for plotted data.
23
+ */
24
+ $.jqplot.Trendline = function() {
25
+ // Group: Properties
26
+
27
+ // prop: show
28
+ // Wether or not to show the trend line.
29
+ this.show = $.jqplot.config.enablePlugins;
30
+ // prop: color
31
+ // CSS color spec for the trend line.
32
+ // By default this wil be the same color as the primary line.
33
+ this.color = '#666666';
34
+ // prop: renderer
35
+ // Renderer to use to draw the trend line.
36
+ // The data series that is plotted may not be rendered as a line.
37
+ // Therefore, we use our own line renderer here to draw a trend line.
38
+ this.renderer = new $.jqplot.LineRenderer();
39
+ // prop: rendererOptions
40
+ // Options to pass to the line renderer.
41
+ // By default, markers are not shown on trend lines.
42
+ this.rendererOptions = {marker:{show:false}};
43
+ // prop: label
44
+ // Label for the trend line to use in the legend.
45
+ this.label = '';
46
+ // prop: type
47
+ // Either 'exponential', 'exp', or 'linear'.
48
+ this.type = 'linear';
49
+ // prop: shadow
50
+ // true or false, wether or not to show the shadow.
51
+ this.shadow = true;
52
+ // prop: markerRenderer
53
+ // Renderer to use to draw markers on the line.
54
+ // I think this is wrong.
55
+ this.markerRenderer = {show:false};
56
+ // prop: lineWidth
57
+ // Width of the trend line.
58
+ this.lineWidth = 1.5;
59
+ // prop: shadowAngle
60
+ // Angle of the shadow on the trend line.
61
+ this.shadowAngle = 45;
62
+ // prop: shadowOffset
63
+ // pixel offset for each stroke of the shadow.
64
+ this.shadowOffset = 1.0;
65
+ // prop: shadowAlpha
66
+ // Alpha transparency of the shadow.
67
+ this.shadowAlpha = 0.07;
68
+ // prop: shadowDepth
69
+ // number of strokes to make of the shadow.
70
+ this.shadowDepth = 3;
71
+
72
+ };
73
+
74
+ $.jqplot.postParseSeriesOptionsHooks.push(parseTrendLineOptions);
75
+ $.jqplot.postDrawSeriesHooks.push(drawTrendline);
76
+ $.jqplot.addLegendRowHooks.push(addTrendlineLegend);
77
+
78
+ // called witin scope of the legend object
79
+ // current series passed in
80
+ // must return null or an object {label:label, color:color}
81
+ function addTrendlineLegend(series) {
82
+ var lt = series.trendline.label.toString();
83
+ var ret = null;
84
+ if (this.renderer.constructor != $.jqplot.PieRenderer && series.trendline.show && lt) {
85
+ ret = {label:lt, color:series.trendline.color};
86
+ }
87
+ return ret;
88
+ }
89
+
90
+ // called within scope of a series
91
+ function parseTrendLineOptions (seriesDefaults, options) {
92
+ if (this.renderer.constructor != $.jqplot.PieRenderer) {
93
+ this.trendline = new $.jqplot.Trendline();
94
+ options = options || {};
95
+ $.extend(true, this.trendline, {color:this.color}, seriesDefaults.trendline, options.trendline);
96
+ this.trendline.renderer.init.call(this.trendline, null);
97
+ }
98
+ }
99
+
100
+ // called within scope of series object
101
+ function drawTrendline(sctx, options) {
102
+ // if we have options, merge trendline options in with precedence
103
+ options = $.extend(true, {}, this.trendline, options);
104
+
105
+ if (options.show && this.renderer.constructor != $.jqplot.PieRenderer) {
106
+ var fit;
107
+ // this.renderer.setGridData.call(this);
108
+ var data = options.data || this.data;
109
+ fit = fitData(data, this.trendline.type);
110
+ var gridData = options.gridData || this.renderer.makeGridData.call(this, fit.data);
111
+
112
+ this.trendline.renderer.draw.call(this.trendline, sctx, gridData, {showLine:true, shadow:this.trendline.shadow});
113
+ }
114
+ }
115
+
116
+ function regression(x, y, typ) {
117
+ var type = (typ == null) ? 'linear' : typ;
118
+ var N = x.length;
119
+ var slope;
120
+ var intercept;
121
+ var SX = 0;
122
+ var SY = 0;
123
+ var SXX = 0;
124
+ var SXY = 0;
125
+ var SYY = 0;
126
+ var Y = [];
127
+ var X = [];
128
+
129
+ if (type == 'linear') {
130
+ X = x;
131
+ Y = y;
132
+ }
133
+ else if (type == 'exp' || type == 'exponential') {
134
+ for ( var i=0; i<y.length; i++) {
135
+ // ignore points <= 0, log undefined.
136
+ if (y[i] <= 0) {
137
+ N--;
138
+ }
139
+ else {
140
+ X.push(x[i]);
141
+ Y.push(Math.log(y[i]));
142
+ }
143
+ }
144
+ }
145
+
146
+ for ( var i = 0; i < N; i++) {
147
+ SX = SX + X[i];
148
+ SY = SY + Y[i];
149
+ SXY = SXY + X[i]* Y[i];
150
+ SXX = SXX + X[i]* X[i];
151
+ SYY = SYY + Y[i]* Y[i];
152
+ }
153
+
154
+ slope = (N*SXY - SX*SY)/(N*SXX - SX*SX);
155
+ intercept = (SY - slope*SX)/N;
156
+
157
+ return [slope, intercept];
158
+ }
159
+
160
+ function linearRegression(X,Y) {
161
+ var ret;
162
+ ret = regression(X,Y,'linear');
163
+ return [ret[0],ret[1]];
164
+ }
165
+
166
+ function expRegression(X,Y) {
167
+ var ret;
168
+ var x = X;
169
+ var y = Y;
170
+ ret = regression(x, y,'exp');
171
+ var base = Math.exp(ret[0]);
172
+ var coeff = Math.exp(ret[1]);
173
+ return [base, coeff];
174
+ }
175
+
176
+ function fitData(data, typ) {
177
+ var type = (typ == null) ? 'linear' : typ;
178
+ var ret;
179
+ var res;
180
+ var x = [];
181
+ var y = [];
182
+ var ypred = [];
183
+
184
+ for (i=0; i<data.length; i++){
185
+ if (data[i] != null && data[i][0] != null && data[i][1] != null) {
186
+ x.push(data[i][0]);
187
+ y.push(data[i][1]);
188
+ }
189
+ }
190
+
191
+ if (type == 'linear') {
192
+ ret = linearRegression(x,y);
193
+ for ( var i=0; i<x.length; i++){
194
+ res = ret[0]*x[i] + ret[1];
195
+ ypred.push([x[i], res]);
196
+ }
197
+ }
198
+ else if (type == 'exp' || type == 'exponential') {
199
+ ret = expRegression(x,y);
200
+ for ( var i=0; i<x.length; i++){
201
+ res = ret[1]*Math.pow(ret[0],x[i]);
202
+ ypred.push([x[i], res]);
203
+ }
204
+ }
205
+ return {data: ypred, slope: ret[0], intercept: ret[1]};
206
+ }
207
+
208
+ })(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(f){f.jqplot.Trendline=function(){this.show=f.jqplot.config.enablePlugins;this.color="#666666";this.renderer=new f.jqplot.LineRenderer();this.rendererOptions={marker:{show:false}};this.label="";this.type="linear";this.shadow=true;this.markerRenderer={show:false};this.lineWidth=1.5;this.shadowAngle=45;this.shadowOffset=1;this.shadowAlpha=0.07;this.shadowDepth=3};f.jqplot.postParseSeriesOptionsHooks.push(e);f.jqplot.postDrawSeriesHooks.push(g);f.jqplot.addLegendRowHooks.push(a);function a(k){var i=k.trendline.label.toString();var j=null;if(this.renderer.constructor!=f.jqplot.PieRenderer&&k.trendline.show&&i){j={label:i,color:k.trendline.color}}return j}function e(j,i){if(this.renderer.constructor!=f.jqplot.PieRenderer){this.trendline=new f.jqplot.Trendline();i=i||{};f.extend(true,this.trendline,{color:this.color},j.trendline,i.trendline);this.trendline.renderer.init.call(this.trendline,null)}}function g(m,i){i=f.extend(true,{},this.trendline,i);if(i.show&&this.renderer.constructor!=f.jqplot.PieRenderer){var k;var l=i.data||this.data;k=c(l,this.trendline.type);var j=i.gridData||this.renderer.makeGridData.call(this,k.data);this.trendline.renderer.draw.call(this.trendline,m,j,{showLine:true,shadow:this.trendline.shadow})}}function b(w,v,n){var u=(n==null)?"linear":n;var s=w.length;var t;var z;var o=0;var m=0;var r=0;var q=0;var l=0;var j=[];var k=[];if(u=="linear"){k=w;j=v}else{if(u=="exp"||u=="exponential"){for(var p=0;p<v.length;p++){if(v[p]<=0){s--}else{k.push(w[p]);j.push(Math.log(v[p]))}}}}for(var p=0;p<s;p++){o=o+k[p];m=m+j[p];q=q+k[p]*j[p];r=r+k[p]*k[p];l=l+j[p]*j[p]}t=(s*q-o*m)/(s*r-o*o);z=(m-t*o)/s;return[t,z]}function h(k,j){var i;i=b(k,j,"linear");return[i[0],i[1]]}function d(o,m){var k;var i=o;var n=m;k=b(i,n,"exp");var l=Math.exp(k[0]);var j=Math.exp(k[1]);return[l,j]}function c(l,j){var p=(j==null)?"linear":j;var n;var o;var r=[];var q=[];var m=[];for(k=0;k<l.length;k++){if(l[k]!=null&&l[k][0]!=null&&l[k][1]!=null){r.push(l[k][0]);q.push(l[k][1])}}if(p=="linear"){n=h(r,q);for(var k=0;k<r.length;k++){o=n[0]*r[k]+n[1];m.push([r[k],o])}}else{if(p=="exp"||p=="exponential"){n=d(r,q);for(var k=0;k<r.length;k++){o=n[1]*Math.pow(n[0],r[k]);m.push([r[k],o])}}}return{data:m,slope:n[0],intercept:n[1]}}})(jQuery);
@@ -0,0 +1 @@
1
+ .jqplot-target{position:relative;color:#666;font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;font-size:1em;}.jqplot-axis{font-size:.75em;}.jqplot-xaxis{margin-top:10px;}.jqplot-x2axis{margin-bottom:10px;}.jqplot-yaxis{margin-right:10px;}.jqplot-y2axis,.jqplot-y3axis,.jqplot-y4axis,.jqplot-y5axis,.jqplot-y6axis,.jqplot-y7axis,.jqplot-y8axis,.jqplot-y9axis{margin-left:10px;margin-right:10px;}.jqplot-axis-tick,.jqplot-xaxis-tick,.jqplot-yaxis-tick,.jqplot-x2axis-tick,.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{position:absolute;}.jqplot-xaxis-tick{top:0;left:15px;vertical-align:top;}.jqplot-x2axis-tick{bottom:0;left:15px;vertical-align:bottom;}.jqplot-yaxis-tick{right:0;top:15px;text-align:right;}.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{left:0;top:15px;text-align:left;}.jqplot-xaxis-label{margin-top:10px;font-size:11pt;position:absolute;}.jqplot-x2axis-label{margin-bottom:10px;font-size:11pt;position:absolute;}.jqplot-yaxis-label{margin-right:10px;font-size:11pt;position:absolute;}.jqplot-y2axis-label,.jqplot-y3axis-label,.jqplot-y4axis-label,.jqplot-y5axis-label,.jqplot-y6axis-label,.jqplot-y7axis-label,.jqplot-y8axis-label,.jqplot-y9axis-label{font-size:11pt;position:absolute;}table.jqplot-table-legend,table.jqplot-cursor-legend{background-color:rgba(255,255,255,0.6);border:1px solid #ccc;position:absolute;font-size:.75em;}td.jqplot-table-legend{vertical-align:middle;}td.jqplot-table-legend>div{border:1px solid #ccc;padding:.2em;}div.jqplot-table-legend-swatch{width:0;height:0;border-top-width:.35em;border-bottom-width:.35em;border-left-width:.6em;border-right-width:.6em;border-top-style:solid;border-bottom-style:solid;border-left-style:solid;border-right-style:solid;}.jqplot-title{top:0;left:0;padding-bottom:.5em;font-size:1.2em;}table.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;}.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-highlighter-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-point-label{font-size:.75em;}td.jqplot-cursor-legend-swatch{vertical-align:middle;text-align:center;}div.jqplot-cursor-legend-swatch{width:1.2em;height:.7em;}