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,308 @@
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.MekkoRenderer
20
+ $.jqplot.MekkoRenderer = function(){
21
+ this.shapeRenderer = new $.jqplot.ShapeRenderer();
22
+ };
23
+
24
+ // called with scope of series.
25
+ $.jqplot.MekkoRenderer.prototype.init = function(options, plot) {
26
+ this.fill = false;
27
+ this.fillRect = true;
28
+ this.strokeRect = true;
29
+ this.shadow = false;
30
+ // width of bar on x axis.
31
+ this._xwidth = 0;
32
+ this._xstart = 0;
33
+ $.extend(true, this.renderer, options);
34
+ // set the shape renderer options
35
+ var opts = {lineJoin:'miter', lineCap:'butt', isarc:false, fillRect:this.fillRect, strokeRect:this.strokeRect};
36
+ this.renderer.shapeRenderer.init(opts);
37
+ plot.axes.x2axis._series.push(this);
38
+ };
39
+
40
+ // Method: setGridData
41
+ // converts the user data values to grid coordinates and stores them
42
+ // in the gridData array. Will convert user data into appropriate
43
+ // rectangles.
44
+ // Called with scope of a series.
45
+ $.jqplot.MekkoRenderer.prototype.setGridData = function(plot) {
46
+ // recalculate the grid data
47
+ var xp = this._xaxis.series_u2p;
48
+ var yp = this._yaxis.series_u2p;
49
+ var data = this._plotData;
50
+ this.gridData = [];
51
+ // figure out width on x axis.
52
+ // this._xwidth = this._sumy / plot._sumy * this.canvas.getWidth();
53
+ this._xwidth = xp(this._sumy) - xp(0);
54
+ if (this.index>0) {
55
+ this._xstart = plot.series[this.index-1]._xstart + plot.series[this.index-1]._xwidth;
56
+ }
57
+ var totheight = this.canvas.getHeight();
58
+ var sumy = 0;
59
+ var cury;
60
+ var curheight;
61
+ for (var i=0; i<data.length; i++) {
62
+ if (data[i] != null) {
63
+ sumy += data[i][1];
64
+ cury = totheight - (sumy / this._sumy * totheight);
65
+ curheight = data[i][1] / this._sumy * totheight;
66
+ this.gridData.push([this._xstart, cury, this._xwidth, curheight]);
67
+ }
68
+ }
69
+ };
70
+
71
+ // Method: makeGridData
72
+ // converts any arbitrary data values to grid coordinates and
73
+ // returns them. This method exists so that plugins can use a series'
74
+ // linerenderer to generate grid data points without overwriting the
75
+ // grid data associated with that series.
76
+ // Called with scope of a series.
77
+ $.jqplot.MekkoRenderer.prototype.makeGridData = function(data, plot) {
78
+ // recalculate the grid data
79
+ // figure out width on x axis.
80
+ var xp = this._xaxis.series_u2p;
81
+ var totheight = this.canvas.getHeight();
82
+ var sumy = 0;
83
+ var cury;
84
+ var curheight;
85
+ var gd = [];
86
+ for (var i=0; i<data.length; i++) {
87
+ if (data[i] != null) {
88
+ sumy += data[i][1];
89
+ cury = totheight - (sumy / this._sumy * totheight);
90
+ curheight = data[i][1] / this._sumy * totheight;
91
+ gd.push([this._xstart, cury, this._xwidth, curheight]);
92
+ }
93
+ }
94
+ return gd;
95
+ };
96
+
97
+
98
+ // called within scope of series.
99
+ $.jqplot.MekkoRenderer.prototype.draw = function(ctx, gd, options) {
100
+ var i;
101
+ var opts = (options != undefined) ? options : {};
102
+ var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
103
+ var colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
104
+ ctx.save();
105
+ if (gd.length) {
106
+ if (showLine) {
107
+ for (i=0; i<gd.length; i++){
108
+ opts.fillStyle = colorGenerator.next();
109
+ this.renderer.shapeRenderer.draw(ctx, gd[i], opts);
110
+ }
111
+ }
112
+ }
113
+
114
+ ctx.restore();
115
+ };
116
+
117
+ $.jqplot.MekkoRenderer.prototype.drawShadow = function(ctx, gd, options) {
118
+ // This is a no-op, no shadows on mekko charts.
119
+ };
120
+
121
+ // called with scope of legend renderer.
122
+ $.jqplot.MekkoLegendRenderer = function() {
123
+ $.jqplot.TableLegendRenderer.call(this);
124
+ };
125
+
126
+ $.jqplot.MekkoLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
127
+ $.jqplot.MekkoLegendRenderer.prototype.constructor = $.jqplot.MekkoLegendRenderer;
128
+
129
+ // called with scope of legend
130
+ $.jqplot.MekkoLegendRenderer.prototype.init = function(options) {
131
+ this.labels = [];
132
+ this.placement = "outside";
133
+ $.extend(true, this, options);
134
+ };
135
+
136
+ // called with context of legend
137
+ $.jqplot.MekkoLegendRenderer.prototype.draw = function() {
138
+ var legend = this;
139
+ if (this.show) {
140
+ var series = this._series;
141
+ // make a table. one line label per row.
142
+ var ss = 'position:absolute;';
143
+ ss += (this.background) ? 'background:'+this.background+';' : '';
144
+ ss += (this.border) ? 'border:'+this.border+';' : '';
145
+ ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
146
+ ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
147
+ ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
148
+ this._elem = $('<table class="jqplot-table-legend jqplot-mekko-legend" style="'+ss+'"></table>');
149
+
150
+ var pad = false, i, labels = [], colors = [];
151
+ var s = series[0];
152
+ var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
153
+ if (s.show) {
154
+ var pd = s.data;
155
+ for (i=0; i<pd.length; i++){
156
+ labels.push(this.labels[i] || pd[i][0].toString());
157
+ colors.push(colorGenerator.next());
158
+ }
159
+ for (i=pd.length-1; i>-1; i--) {
160
+ if (labels[i]) {
161
+ this.renderer.addrow.call(this, labels[i], colors[i], pad);
162
+ pad = true;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ return this._elem;
168
+ };
169
+
170
+ $.jqplot.MekkoLegendRenderer.prototype.pack = function(offsets) {
171
+ if (this.show) {
172
+ // fake a grid for positioning
173
+ var grid = {_top:offsets.top, _left:offsets.left, _right:offsets.right, _bottom:this._plotDimensions.height - offsets.bottom};
174
+ if (this.placement == 'inside') {
175
+ switch (this.location) {
176
+ case 'nw':
177
+ var a = grid._left + this.xoffset;
178
+ var b = grid._top + this.yoffset;
179
+ this._elem.css('left', a);
180
+ this._elem.css('top', b);
181
+ break;
182
+ case 'n':
183
+ var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
184
+ var b = grid._top + this.yoffset;
185
+ this._elem.css('left', a);
186
+ this._elem.css('top', b);
187
+ break;
188
+ case 'ne':
189
+ var a = offsets.right + this.xoffset;
190
+ var b = grid._top + this.yoffset;
191
+ this._elem.css({right:a, top:b});
192
+ break;
193
+ case 'e':
194
+ var a = offsets.right + this.xoffset;
195
+ var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
196
+ this._elem.css({right:a, top:b});
197
+ break;
198
+ case 'se':
199
+ var a = offsets.right + this.xoffset;
200
+ var b = offsets.bottom + this.yoffset;
201
+ this._elem.css({right:a, bottom:b});
202
+ break;
203
+ case 's':
204
+ var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
205
+ var b = offsets.bottom + this.yoffset;
206
+ this._elem.css({left:a, bottom:b});
207
+ break;
208
+ case 'sw':
209
+ var a = grid._left + this.xoffset;
210
+ var b = offsets.bottom + this.yoffset;
211
+ this._elem.css({left:a, bottom:b});
212
+ break;
213
+ case 'w':
214
+ var a = grid._left + this.xoffset;
215
+ var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
216
+ this._elem.css({left:a, top:b});
217
+ break;
218
+ default: // same as 'se'
219
+ var a = grid._right - this.xoffset;
220
+ var b = grid._bottom + this.yoffset;
221
+ this._elem.css({right:a, bottom:b});
222
+ break;
223
+ }
224
+
225
+ }
226
+ else {
227
+ switch (this.location) {
228
+ case 'nw':
229
+ var a = this._plotDimensions.width - grid._left + this.xoffset;
230
+ var b = grid._top + this.yoffset;
231
+ this._elem.css('right', a);
232
+ this._elem.css('top', b);
233
+ break;
234
+ case 'n':
235
+ var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
236
+ var b = this._plotDimensions.height - grid._top + this.yoffset;
237
+ this._elem.css('left', a);
238
+ this._elem.css('bottom', b);
239
+ break;
240
+ case 'ne':
241
+ var a = this._plotDimensions.width - offsets.right + this.xoffset;
242
+ var b = grid._top + this.yoffset;
243
+ this._elem.css({left:a, top:b});
244
+ break;
245
+ case 'e':
246
+ var a = this._plotDimensions.width - offsets.right + this.xoffset;
247
+ var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
248
+ this._elem.css({left:a, top:b});
249
+ break;
250
+ case 'se':
251
+ var a = this._plotDimensions.width - offsets.right + this.xoffset;
252
+ var b = offsets.bottom + this.yoffset;
253
+ this._elem.css({left:a, bottom:b});
254
+ break;
255
+ case 's':
256
+ var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
257
+ var b = this._plotDimensions.height - offsets.bottom + this.yoffset;
258
+ this._elem.css({left:a, top:b});
259
+ break;
260
+ case 'sw':
261
+ var a = this._plotDimensions.width - grid._left + this.xoffset;
262
+ var b = offsets.bottom + this.yoffset;
263
+ this._elem.css({right:a, bottom:b});
264
+ break;
265
+ case 'w':
266
+ var a = this._plotDimensions.width - grid._left + this.xoffset;
267
+ var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
268
+ this._elem.css({right:a, top:b});
269
+ break;
270
+ default: // same as 'se'
271
+ var a = grid._right - this.xoffset;
272
+ var b = grid._bottom + this.yoffset;
273
+ this._elem.css({right:a, bottom:b});
274
+ break;
275
+ }
276
+ }
277
+ }
278
+ };
279
+
280
+ // setup default renderers for axes and legend so user doesn't have to
281
+ // called with scope of plot
282
+ function preInit(target, data, options) {
283
+ options = options || {};
284
+ options.axesDefaults = options.axesDefaults || {};
285
+ options.legend = options.legend || {};
286
+ options.seriesDefaults = options.seriesDefaults || {};
287
+ var setopts = false;
288
+ if (options.seriesDefaults.renderer == $.jqplot.MekkoRenderer) {
289
+ setopts = true;
290
+ }
291
+ else if (options.series) {
292
+ for (var i=0; i < options.series.length; i++) {
293
+ if (options.series[i].renderer == $.jqplot.MekkoRenderer) {
294
+ setopts = true;
295
+ }
296
+ }
297
+ }
298
+
299
+ if (setopts) {
300
+ options.axesDefaults.renderer = $.jqplot.MekkoAxisRenderer;
301
+ options.legend.renderer = $.jqplot.MekkoLegendRenderer;
302
+ options.legend.preDraw = true;
303
+ }
304
+ }
305
+
306
+ $.jqplot.preInitHooks.push(preInit);
307
+
308
+ })(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(b){b.jqplot.MekkoRenderer=function(){this.shapeRenderer=new b.jqplot.ShapeRenderer()};b.jqplot.MekkoRenderer.prototype.init=function(c,e){this.fill=false;this.fillRect=true;this.strokeRect=true;this.shadow=false;this._xwidth=0;this._xstart=0;b.extend(true,this.renderer,c);var d={lineJoin:"miter",lineCap:"butt",isarc:false,fillRect:this.fillRect,strokeRect:this.strokeRect};this.renderer.shapeRenderer.init(d);e.axes.x2axis._series.push(this)};b.jqplot.MekkoRenderer.prototype.setGridData=function(h){var e=this._xaxis.series_u2p;var c=this._yaxis.series_u2p;var g=this._plotData;this.gridData=[];this._xwidth=e(this._sumy)-e(0);if(this.index>0){this._xstart=h.series[this.index-1]._xstart+h.series[this.index-1]._xwidth}var l=this.canvas.getHeight();var d=0;var k;var j;for(var f=0;f<g.length;f++){if(g[f]!=null){d+=g[f][1];k=l-(d/this._sumy*l);j=g[f][1]/this._sumy*l;this.gridData.push([this._xstart,k,this._xwidth,j])}}};b.jqplot.MekkoRenderer.prototype.makeGridData=function(f,g){var d=this._xaxis.series_u2p;var l=this.canvas.getHeight();var c=0;var j;var h;var k=[];for(var e=0;e<f.length;e++){if(f[e]!=null){c+=f[e][1];j=l-(c/this._sumy*l);h=f[e][1]/this._sumy*l;k.push([this._xstart,j,this._xwidth,h])}}return k};b.jqplot.MekkoRenderer.prototype.draw=function(c,h,d){var e;var g=(d!=undefined)?d:{};var f=(g.showLine!=undefined)?g.showLine:this.showLine;var j=new b.jqplot.ColorGenerator(this.seriesColors);c.save();if(h.length){if(f){for(e=0;e<h.length;e++){g.fillStyle=j.next();this.renderer.shapeRenderer.draw(c,h[e],g)}}}c.restore()};b.jqplot.MekkoRenderer.prototype.drawShadow=function(c,e,d){};b.jqplot.MekkoLegendRenderer=function(){b.jqplot.TableLegendRenderer.call(this)};b.jqplot.MekkoLegendRenderer.prototype=new b.jqplot.TableLegendRenderer();b.jqplot.MekkoLegendRenderer.prototype.constructor=b.jqplot.MekkoLegendRenderer;b.jqplot.MekkoLegendRenderer.prototype.init=function(c){this.labels=[];this.placement="outside";b.extend(true,this,c)};b.jqplot.MekkoLegendRenderer.prototype.draw=function(){var k=this;if(this.show){var e=this._series;var m="position:absolute;";m+=(this.background)?"background:"+this.background+";":"";m+=(this.border)?"border:"+this.border+";":"";m+=(this.fontSize)?"font-size:"+this.fontSize+";":"";m+=(this.fontFamily)?"font-family:"+this.fontFamily+";":"";m+=(this.textColor)?"color:"+this.textColor+";":"";this._elem=b('<table class="jqplot-table-legend jqplot-mekko-legend" style="'+m+'"></table>');var d=false,f,h=[],c=[];var l=e[0];var g=new b.jqplot.ColorGenerator(l.seriesColors);if(l.show){var j=l.data;for(f=0;f<j.length;f++){h.push(this.labels[f]||j[f][0].toString());c.push(g.next())}for(f=j.length-1;f>-1;f--){if(h[f]){this.renderer.addrow.call(this,h[f],c[f],d);d=true}}}}return this._elem};b.jqplot.MekkoLegendRenderer.prototype.pack=function(f){if(this.show){var e={_top:f.top,_left:f.left,_right:f.right,_bottom:this._plotDimensions.height-f.bottom};if(this.placement=="inside"){switch(this.location){case"nw":var d=e._left+this.xoffset;var c=e._top+this.yoffset;this._elem.css("left",d);this._elem.css("top",c);break;case"n":var d=(f.left+(this._plotDimensions.width-f.right))/2-this.getWidth()/2;var c=e._top+this.yoffset;this._elem.css("left",d);this._elem.css("top",c);break;case"ne":var d=f.right+this.xoffset;var c=e._top+this.yoffset;this._elem.css({right:d,top:c});break;case"e":var d=f.right+this.xoffset;var c=(f.top+(this._plotDimensions.height-f.bottom))/2-this.getHeight()/2;this._elem.css({right:d,top:c});break;case"se":var d=f.right+this.xoffset;var c=f.bottom+this.yoffset;this._elem.css({right:d,bottom:c});break;case"s":var d=(f.left+(this._plotDimensions.width-f.right))/2-this.getWidth()/2;var c=f.bottom+this.yoffset;this._elem.css({left:d,bottom:c});break;case"sw":var d=e._left+this.xoffset;var c=f.bottom+this.yoffset;this._elem.css({left:d,bottom:c});break;case"w":var d=e._left+this.xoffset;var c=(f.top+(this._plotDimensions.height-f.bottom))/2-this.getHeight()/2;this._elem.css({left:d,top:c});break;default:var d=e._right-this.xoffset;var c=e._bottom+this.yoffset;this._elem.css({right:d,bottom:c});break}}else{switch(this.location){case"nw":var d=this._plotDimensions.width-e._left+this.xoffset;var c=e._top+this.yoffset;this._elem.css("right",d);this._elem.css("top",c);break;case"n":var d=(f.left+(this._plotDimensions.width-f.right))/2-this.getWidth()/2;var c=this._plotDimensions.height-e._top+this.yoffset;this._elem.css("left",d);this._elem.css("bottom",c);break;case"ne":var d=this._plotDimensions.width-f.right+this.xoffset;var c=e._top+this.yoffset;this._elem.css({left:d,top:c});break;case"e":var d=this._plotDimensions.width-f.right+this.xoffset;var c=(f.top+(this._plotDimensions.height-f.bottom))/2-this.getHeight()/2;this._elem.css({left:d,top:c});break;case"se":var d=this._plotDimensions.width-f.right+this.xoffset;var c=f.bottom+this.yoffset;this._elem.css({left:d,bottom:c});break;case"s":var d=(f.left+(this._plotDimensions.width-f.right))/2-this.getWidth()/2;var c=this._plotDimensions.height-f.bottom+this.yoffset;this._elem.css({left:d,top:c});break;case"sw":var d=this._plotDimensions.width-e._left+this.xoffset;var c=f.bottom+this.yoffset;this._elem.css({right:d,bottom:c});break;case"w":var d=this._plotDimensions.width-e._left+this.xoffset;var c=(f.top+(this._plotDimensions.height-f.bottom))/2-this.getHeight()/2;this._elem.css({right:d,top:c});break;default:var d=e._right-this.xoffset;var c=e._bottom+this.yoffset;this._elem.css({right:d,bottom:c});break}}}};function a(g,f,d){d=d||{};d.axesDefaults=d.axesDefaults||{};d.legend=d.legend||{};d.seriesDefaults=d.seriesDefaults||{};var c=false;if(d.seriesDefaults.renderer==b.jqplot.MekkoRenderer){c=true}else{if(d.series){for(var e=0;e<d.series.length;e++){if(d.series[e].renderer==b.jqplot.MekkoRenderer){c=true}}}}if(c){d.axesDefaults.renderer=b.jqplot.MekkoAxisRenderer;d.legend.renderer=b.jqplot.MekkoLegendRenderer;d.legend.preDraw=true}}b.jqplot.preInitHooks.push(a)})(jQuery);
@@ -0,0 +1,343 @@
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.OHLCRenderer
21
+ * jqPlot Plugin to draw Open Hi Low Close, Candlestick and Hi Low Close charts.
22
+ *
23
+ * To use this plugin, include the renderer js file in
24
+ * your source:
25
+ *
26
+ * > <script type="text/javascript" src="plugins/jqplot.ohlcRenderer.js"></script>
27
+ *
28
+ * You will most likely want to use a date axis renderer
29
+ * for the x axis also, so include the date axis render js file also:
30
+ *
31
+ * > <script type="text/javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
32
+ *
33
+ * Then you set the renderer in the series options on your plot:
34
+ *
35
+ * > series: [{renderer:$.jqplot.OHLCRenderer}]
36
+ *
37
+ * For OHLC and candlestick charts, data should be specified
38
+ * like so:
39
+ *
40
+ * > dat = [['07/06/2009',138.7,139.68,135.18,135.4], ['06/29/2009',143.46,144.66,139.79,140.02], ...]
41
+ *
42
+ * If the data array has only 4 values per point instead of 5,
43
+ * the renderer will create a Hi Low Close chart instead. In that case,
44
+ * data should be supplied like:
45
+ *
46
+ * > dat = [['07/06/2009',139.68,135.18,135.4], ['06/29/2009',144.66,139.79,140.02], ...]
47
+ *
48
+ * To generate a candlestick chart instead of an OHLC chart,
49
+ * set the "candlestick" option to true:
50
+ *
51
+ * > series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}],
52
+ *
53
+ */
54
+ $.jqplot.OHLCRenderer = function(){
55
+ // subclass line renderer to make use of some of it's methods.
56
+ $.jqplot.LineRenderer.call(this);
57
+ // prop: candleStick
58
+ // true to render chart as candleStick.
59
+ // Must have an open price, cannot be a hlc chart.
60
+ this.candleStick = false;
61
+ // prop: tickLength
62
+ // length of the line in pixels indicating open and close price.
63
+ // Default will auto calculate based on plot width and
64
+ // number of points displayed.
65
+ this.tickLength = 'auto';
66
+ // prop: bodyWidth
67
+ // width of the candlestick body in pixels. Default will auto calculate
68
+ // based on plot width and number of candlesticks displayed.
69
+ this.bodyWidth = 'auto';
70
+ // prop: openColor
71
+ // color of the open price tick mark. Default is series color.
72
+ this.openColor = null;
73
+ // prop: closeColor
74
+ // color of the close price tick mark. Default is series color.
75
+ this.closeColor = null;
76
+ // prop: wickColor
77
+ // color of the hi-lo line thorugh the candlestick body.
78
+ // Default is the series color.
79
+ this.wickColor = null;
80
+ // prop: fillUpBody
81
+ // true to render an "up" day (close price greater than open price)
82
+ // with a filled candlestick body.
83
+ this.fillUpBody = false;
84
+ // prop: fillDownBody
85
+ // true to render a "down" day (close price lower than open price)
86
+ // with a filled candlestick body.
87
+ this.fillDownBody = true;
88
+ // prop: upBodyColor
89
+ // Color of candlestick body of an "up" day. Default is series color.
90
+ this.upBodyColor = null;
91
+ // prop: downBodyColor
92
+ // Color of candlestick body on a "down" day. Default is series color.
93
+ this.downBodyColor = null;
94
+ // prop: hlc
95
+ // true if is a hi-low-close chart (no open price).
96
+ // This is determined automatically from the series data.
97
+ this.hlc = false;
98
+ this._tickLength;
99
+ this._bodyWidth;
100
+ };
101
+
102
+ $.jqplot.OHLCRenderer.prototype = new $.jqplot.LineRenderer();
103
+ $.jqplot.OHLCRenderer.prototype.constructor = $.jqplot.OHLCRenderer;
104
+
105
+ // called with scope of series.
106
+ $.jqplot.OHLCRenderer.prototype.init = function(options) {
107
+ // prop: lineWidth
108
+ // Width of the hi-low line and open/close ticks.
109
+ this.lineWidth = 1.5;
110
+ $.jqplot.LineRenderer.prototype.init.call(this, options);
111
+ // set the yaxis data bounds here to account for hi and low values
112
+ var db = this._yaxis._dataBounds;
113
+ var d = this._plotData;
114
+ // if data points have less than 5 values, force a hlc chart.
115
+ if (d[0].length < 5) {
116
+ this.renderer.hlc = true;
117
+
118
+ for (var j=0; j<d.length; j++) {
119
+ if (d[j][2] < db.min || db.min == null) {
120
+ db.min = d[j][2];
121
+ }
122
+ if (d[j][1] > db.max || db.max == null) {
123
+ db.max = d[j][1];
124
+ }
125
+ }
126
+ }
127
+ else {
128
+ for (var j=0; j<d.length; j++) {
129
+ if (d[j][3] < db.min || db.min == null) {
130
+ db.min = d[j][3];
131
+ }
132
+ if (d[j][2] > db.max || db.max == null) {
133
+ db.max = d[j][2];
134
+ }
135
+ }
136
+ }
137
+
138
+ };
139
+
140
+ // called within scope of series.
141
+ $.jqplot.OHLCRenderer.prototype.draw = function(ctx, gd, options) {
142
+ var d = this.data;
143
+ var xmin = this._xaxis.min;
144
+ var xmax = this._xaxis.max;
145
+ // index of last value below range of plot.
146
+ var xminidx = 0;
147
+ // index of first value above range of plot.
148
+ var xmaxidx = d.length;
149
+ var xp = this._xaxis.series_u2p;
150
+ var yp = this._yaxis.series_u2p;
151
+ var i, prevColor, ops, b, h, w, a, points;
152
+ var o;
153
+ var r = this.renderer;
154
+ var opts = (options != undefined) ? options : {};
155
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
156
+ var fill = (opts.fill != undefined) ? opts.fill : this.fill;
157
+ var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
158
+ r.bodyWidth = (opts.bodyWidth != undefined) ? opts.bodyWidth : r.bodyWidth;
159
+ r.tickLength = (opts.tickLength != undefined) ? opts.tickLength : r.tickLength;
160
+ ctx.save();
161
+ if (this.show) {
162
+ var x, open, hi, low, close;
163
+ // need to get widths based on number of points shown,
164
+ // not on total number of points. Use the results
165
+ // to speed up drawing in next step.
166
+ for (var i=0; i<d.length; i++) {
167
+ if (d[i][0] < xmin) {
168
+ xminidx = i;
169
+ }
170
+ else if (d[i][0] < xmax) {
171
+ xmaxidx = i+1;
172
+ }
173
+ }
174
+
175
+ if (r.candleStick) {
176
+ if (typeof(r.bodyWidth) == 'number') {
177
+ r._bodyWidth = r.bodyWidth;
178
+ }
179
+ else {
180
+ r._bodyWidth = Math.min(20, ctx.canvas.width/(xmaxidx - xminidx)/2);
181
+ }
182
+ }
183
+ else {
184
+ if (typeof(r.tickLength) == 'number') {
185
+ r._tickLength = r.tickLength;
186
+ }
187
+ else {
188
+ r._tickLength = Math.min(10, ctx.canvas.width/(xmaxidx - xminidx)/4);
189
+ }
190
+ }
191
+
192
+ for (var i=xminidx; i<xmaxidx; i++) {
193
+ x = xp(d[i][0]);
194
+ if (r.hlc) {
195
+ open = null;
196
+ hi = yp(d[i][1]);
197
+ low = yp(d[i][2]);
198
+ close = yp(d[i][3]);
199
+ }
200
+ else {
201
+ open = yp(d[i][1]);
202
+ hi = yp(d[i][2]);
203
+ low = yp(d[i][3]);
204
+ close = yp(d[i][4]);
205
+ }
206
+ o = {};
207
+ if (r.candleStick && !r.hlc) {
208
+ w = r._bodyWidth;
209
+ a = x - w/2;
210
+ // draw candle
211
+ // determine if candle up or down
212
+ // up, remember grid coordinates increase downward
213
+ if (close < open) {
214
+ // draw wick
215
+ if (r.wickColor) {
216
+ o.color = r.wickColor;
217
+ }
218
+ else if (r.downBodyColor) {
219
+ o.color = r.upBodyColor;
220
+ }
221
+ ops = $.extend(true, {}, opts, o);
222
+ r.shapeRenderer.draw(ctx, [[x, hi], [x, close]], ops);
223
+ r.shapeRenderer.draw(ctx, [[x, open], [x, low]], ops);
224
+ o = {};
225
+ b = close;
226
+ h = open - close;
227
+ // if color specified, use it
228
+ if (r.fillUpBody) {
229
+ o.fillRect = true;
230
+ }
231
+ else {
232
+ o.strokeRect = true;
233
+ w = w - this.lineWidth;
234
+ a = x - w/2;
235
+ }
236
+ if (r.upBodyColor) {
237
+ o.color = r.upBodyColor;
238
+ o.fillStyle = r.upBodyColor;
239
+ }
240
+ points = [a, b, w, h];
241
+ }
242
+ // down
243
+ else if (close > open) {
244
+ // draw wick
245
+ if (r.wickColor) {
246
+ o.color = r.wickColor;
247
+ }
248
+ else if (r.downBodyColor) {
249
+ o.color = r.downBodyColor;
250
+ }
251
+ ops = $.extend(true, {}, opts, o);
252
+ r.shapeRenderer.draw(ctx, [[x, hi], [x, open]], ops);
253
+ r.shapeRenderer.draw(ctx, [[x, close], [x, low]], ops);
254
+
255
+ o = {};
256
+
257
+ b = open;
258
+ h = close - open;
259
+ // if color specified, use it
260
+ if (r.fillDownBody) {
261
+ o.fillRect = true;
262
+ }
263
+ else {
264
+ o.strokeRect = true;
265
+ w = w - this.lineWidth;
266
+ a = x - w/2;
267
+ }
268
+ if (r.downBodyColor) {
269
+ o.color = r.downBodyColor;
270
+ o.fillStyle = r.downBodyColor;
271
+ }
272
+ points = [a, b, w, h];
273
+ }
274
+ // even, open = close
275
+ else {
276
+ // draw wick
277
+ if (r.wickColor) {
278
+ o.color = r.wickColor;
279
+ }
280
+ ops = $.extend(true, {}, opts, o);
281
+ r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], ops);
282
+ o = {};
283
+ o.fillRect = false;
284
+ o.strokeRect = false;
285
+ a = [x - w/2, open];
286
+ b = [x + w/2, close];
287
+ w = null;
288
+ h = null;
289
+ points = [a, b];
290
+ }
291
+ ops = $.extend(true, {}, opts, o);
292
+ r.shapeRenderer.draw(ctx, points, ops);
293
+ }
294
+ else {
295
+ prevColor = opts.color;
296
+ if (r.openColor) {
297
+ opts.color = r.openColor;
298
+ }
299
+ // draw open tick
300
+ if (!r.hlc) {
301
+ r.shapeRenderer.draw(ctx, [[x-r._tickLength, open], [x, open]], opts);
302
+ }
303
+ opts.color = prevColor;
304
+ // draw wick
305
+ if (r.wickColor) {
306
+ opts.color = r.wickColor;
307
+ }
308
+ r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], opts);
309
+ opts.color = prevColor;
310
+ // draw close tick
311
+ if (r.closeColor) {
312
+ opts.color = r.closeColor;
313
+ }
314
+ r.shapeRenderer.draw(ctx, [[x, close], [x+r._tickLength, close]], opts);
315
+ opts.color = prevColor;
316
+ }
317
+ }
318
+ }
319
+
320
+ ctx.restore();
321
+ };
322
+
323
+ $.jqplot.OHLCRenderer.prototype.drawShadow = function(ctx, gd, options) {
324
+ // This is a no-op, shadows drawn with lines.
325
+ };
326
+
327
+ // called with scope of plot.
328
+ $.jqplot.OHLCRenderer.checkOptions = function(target, data, options) {
329
+ // provide some sensible highlighter options by default
330
+ // These aren't good for hlc, only for ohlc or candlestick
331
+ if (!options.highlighter) {
332
+ options.highlighter = {
333
+ showMarker:false,
334
+ tooltipAxes: 'y',
335
+ yvalues: 4,
336
+ formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'
337
+ };
338
+ }
339
+ };
340
+
341
+ //$.jqplot.preInitHooks.push($.jqplot.OHLCRenderer.checkOptions);
342
+
343
+ })(jQuery);