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,359 @@
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
+ $.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
20
+
21
+ /**
22
+ * Class: $.jqplot.Highlighter
23
+ * Plugin which will highlight data points when they are moused over.
24
+ *
25
+ * To use this plugin, include the js
26
+ * file in your source:
27
+ *
28
+ * > <script type="text/javascript" src="plugins/jqplot.highlighter.js"></script>
29
+ *
30
+ * A tooltip providing information about the data point is enabled by default.
31
+ * To disable the tooltip, set "showTooltip" to false.
32
+ *
33
+ * You can control what data is displayed in the tooltip with various
34
+ * options. The "tooltipAxes" option controls wether the x, y or both
35
+ * data values are displayed.
36
+ *
37
+ * Some chart types (e.g. hi-low-close) have more than one y value per
38
+ * data point. To display the additional values in the tooltip, set the
39
+ * "yvalues" option to the desired number of y values present (3 for a hlc chart).
40
+ *
41
+ * By default, data values will be formatted with the same formatting
42
+ * specifiers as used to format the axis ticks. A custom format code
43
+ * can be supplied with the tooltipFormatString option. This will apply
44
+ * to all values in the tooltip.
45
+ *
46
+ * For more complete control, the "formatString" option can be set. This
47
+ * Allows conplete control over tooltip formatting. Values are passed to
48
+ * the format string in an order determined by the "tooltipAxes" and "yvalues"
49
+ * options. So, if you have a hi-low-close chart and you just want to display
50
+ * the hi-low-close values in the tooltip, you could set a formatString like:
51
+ *
52
+ * > highlighter: {
53
+ * > tooltipAxes: 'y',
54
+ * > yvalues: 3,
55
+ * > formatString:'<table class="jqplot-highlighter">
56
+ * > <tr><td>hi:</td><td>%s</td></tr>
57
+ * > <tr><td>low:</td><td>%s</td></tr>
58
+ * > <tr><td>close:</td><td>%s</td></tr></table>'
59
+ * > }
60
+ *
61
+ */
62
+ $.jqplot.Highlighter = function(options) {
63
+ // Group: Properties
64
+ //
65
+ //prop: show
66
+ // true to show the highlight.
67
+ this.show = $.jqplot.config.enablePlugins;
68
+ // prop: markerRenderer
69
+ // Renderer used to draw the marker of the highlighted point.
70
+ // Renderer will assimilate attributes from the data point being highlighted,
71
+ // so no attributes need set on the renderer directly.
72
+ // Default is to turn off shadow drawing on the highlighted point.
73
+ this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
74
+ // prop: showMarker
75
+ // true to show the marker
76
+ this.showMarker = true;
77
+ // prop: lineWidthAdjust
78
+ // Pixels to add to the lineWidth of the highlight.
79
+ this.lineWidthAdjust = 2.5;
80
+ // prop: sizeAdjust
81
+ // Pixels to add to the overall size of the highlight.
82
+ this.sizeAdjust = 5;
83
+ // prop: showTooltip
84
+ // Show a tooltip with data point values.
85
+ this.showTooltip = true;
86
+ // prop: tooltipLocation
87
+ // Where to position tooltip, 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
88
+ this.tooltipLocation = 'nw';
89
+ // prop: tooltipFade
90
+ // true = fade in/out tooltip, flase = show/hide tooltip
91
+ this.fadeTooltip = true;
92
+ // prop: tooltipFadeSpeed
93
+ // 'slow', 'def', 'fast', or number of milliseconds.
94
+ this.tooltipFadeSpeed = "fast";
95
+ // prop: tooltipOffset
96
+ // Pixel offset of tooltip from the highlight.
97
+ this.tooltipOffset = 2;
98
+ // prop: tooltipAxes
99
+ // Which axes to display in tooltip, 'x', 'y' or 'both', 'xy' or 'yx'
100
+ // 'both' and 'xy' are equivalent, 'yx' reverses order of labels.
101
+ this.tooltipAxes = 'both';
102
+ // prop; tooltipSeparator
103
+ // String to use to separate x and y axes in tooltip.
104
+ this.tooltipSeparator = ', ';
105
+ // prop: useAxesFormatters
106
+ // Use the x and y axes formatters to format the text in the tooltip.
107
+ this.useAxesFormatters = true;
108
+ // prop: tooltipFormatString
109
+ // sprintf format string for the tooltip.
110
+ // Uses Ash Searle's javascript sprintf implementation
111
+ // found here: http://hexmen.com/blog/2007/03/printf-sprintf/
112
+ // See http://perldoc.perl.org/functions/sprintf.html for reference.
113
+ // Additional "p" and "P" format specifiers added by Chris Leonello.
114
+ this.tooltipFormatString = '%.5P';
115
+ // prop: formatString
116
+ // alternative to tooltipFormatString
117
+ // will format the whole tooltip text, populating with x, y values as
118
+ // indicated by tooltipAxes option. So, you could have a tooltip like:
119
+ // 'Date: %s, number of cats: %d' to format the whole tooltip at one go.
120
+ // If useAxesFormatters is true, values will be formatted according to
121
+ // Axes formatters and you can populate your tooltip string with
122
+ // %s placeholders.
123
+ this.formatString = null;
124
+ // prop: yvalues
125
+ // Number of y values to expect in the data point array.
126
+ // Typically this is 1. Certain plots, like OHLC, will
127
+ // have more y values in each data point array.
128
+ this.yvalues = 1;
129
+ this._tooltipElem;
130
+ this.isHighlighting = false;
131
+
132
+ $.extend(true, this, options);
133
+ };
134
+
135
+ // axis.renderer.tickrenderer.formatter
136
+
137
+ // called with scope of plot
138
+ $.jqplot.Highlighter.init = function (target, data, opts){
139
+ var options = opts || {};
140
+ // add a highlighter attribute to the plot
141
+ this.plugins.highlighter = new $.jqplot.Highlighter(options.highlighter);
142
+ };
143
+
144
+ // called within scope of series
145
+ $.jqplot.Highlighter.parseOptions = function (defaults, options) {
146
+ this.showHighlight = true;
147
+ };
148
+
149
+ // called within context of plot
150
+ // create a canvas which we can draw on.
151
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
152
+ $.jqplot.Highlighter.postPlotDraw = function() {
153
+ this.plugins.highlighter.highlightCanvas = new $.jqplot.GenericCanvas();
154
+
155
+ this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding, 'jqplot-highlight-canvas', this._plotDimensions));
156
+ var hctx = this.plugins.highlighter.highlightCanvas.setContext();
157
+
158
+ var p = this.plugins.highlighter;
159
+ p._tooltipElem = $('<div class="jqplot-highlighter-tooltip" style="position:absolute;display:none"></div>');
160
+ this.target.append(p._tooltipElem);
161
+ };
162
+
163
+ $.jqplot.preInitHooks.push($.jqplot.Highlighter.init);
164
+ $.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Highlighter.parseOptions);
165
+ $.jqplot.postDrawHooks.push($.jqplot.Highlighter.postPlotDraw);
166
+
167
+ function draw(plot, neighbor) {
168
+ var hl = plot.plugins.highlighter;
169
+ var s = plot.series[neighbor.seriesIndex];
170
+ var smr = s.markerRenderer;
171
+ var mr = hl.markerRenderer;
172
+ mr.style = smr.style;
173
+ mr.lineWidth = smr.lineWidth + hl.lineWidthAdjust;
174
+ mr.size = smr.size + hl.sizeAdjust;
175
+ var rgba = $.jqplot.getColorComponents(smr.color);
176
+ var newrgb = [rgba[0], rgba[1], rgba[2]];
177
+ var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
178
+ mr.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
179
+ mr.init();
180
+ mr.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], hl.highlightCanvas._ctx);
181
+ }
182
+
183
+ function showTooltip(plot, series, neighbor) {
184
+ // neighbor looks like: {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]}
185
+ // gridData should be x,y pixel coords on the grid.
186
+ // add the plot._gridPadding to that to get x,y in the target.
187
+ var hl = plot.plugins.highlighter;
188
+ var elem = hl._tooltipElem;
189
+ if (hl.useAxesFormatters) {
190
+ var xf = series._xaxis._ticks[0].formatter;
191
+ var yf = series._yaxis._ticks[0].formatter;
192
+ var xfstr = series._xaxis._ticks[0].formatString;
193
+ var yfstr = series._yaxis._ticks[0].formatString;
194
+ var str;
195
+ var xstr = xf(xfstr, neighbor.data[0]);
196
+ var ystrs = [];
197
+ for (var i=1; i<hl.yvalues+1; i++) {
198
+ ystrs.push(yf(yfstr, neighbor.data[i]));
199
+ }
200
+ if (hl.formatString) {
201
+ switch (hl.tooltipAxes) {
202
+ case 'both':
203
+ case 'xy':
204
+ ystrs.unshift(xstr);
205
+ ystrs.unshift(hl.formatString);
206
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
207
+ break;
208
+ case 'yx':
209
+ ystrs.push(xstr);
210
+ ystrs.unshift(hl.formatString);
211
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
212
+ break;
213
+ case 'x':
214
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, [hl.formatString, xstr]);
215
+ break;
216
+ case 'y':
217
+ ystrs.unshift(hl.formatString);
218
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
219
+ break;
220
+ default: // same as xy
221
+ ystrs.unshift(xstr);
222
+ ystrs.unshift(hl.formatString);
223
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
224
+ break;
225
+ }
226
+ }
227
+ else {
228
+ switch (hl.tooltipAxes) {
229
+ case 'both':
230
+ case 'xy':
231
+ str = xstr;
232
+ for (var i=0; i<ystrs.length; i++) {
233
+ str += hl.tooltipSeparator + ystrs[i];
234
+ }
235
+ break;
236
+ case 'yx':
237
+ str = '';
238
+ for (var i=0; i<ystrs.length; i++) {
239
+ str += ystrs[i] + hl.tooltipSeparator;
240
+ }
241
+ str += xstr;
242
+ break;
243
+ case 'x':
244
+ str = xstr;
245
+ break;
246
+ case 'y':
247
+ str = '';
248
+ for (var i=0; i<ystrs.length; i++) {
249
+ str += ystrs[i] + hl.tooltipSeparator;
250
+ }
251
+ break;
252
+ default: // same as 'xy'
253
+ str = xstr;
254
+ for (var i=0; i<ystrs.length; i++) {
255
+ str += hl.tooltipSeparator + ystrs[i];
256
+ }
257
+ break;
258
+
259
+ }
260
+ }
261
+ }
262
+ else {
263
+ var str;
264
+ if (hl.tooltipAxes == 'both' || hl.tooltipAxes == 'xy') {
265
+ str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]) + hl.tooltipSeparator + $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]);
266
+ }
267
+ else if (hl.tooltipAxes == 'yx') {
268
+ str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]) + hl.tooltipSeparator + $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]);
269
+ }
270
+ else if (hl.tooltipAxes == 'x') {
271
+ str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[0]);
272
+ }
273
+ else if (hl.tooltipAxes == 'y') {
274
+ str = $.jqplot.sprintf(hl.tooltipFormatString, neighbor.data[1]);
275
+ }
276
+ }
277
+ elem.html(str);
278
+ var gridpos = {x:neighbor.gridData[0], y:neighbor.gridData[1]};
279
+ var ms = 0;
280
+ var fact = 0.707;
281
+ if (series.markerRenderer.show == true) {
282
+ ms = (series.markerRenderer.size + hl.sizeAdjust)/2;
283
+ }
284
+ switch (hl.tooltipLocation) {
285
+ case 'nw':
286
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
287
+ var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
288
+ break;
289
+ case 'n':
290
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
291
+ var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - ms;
292
+ break;
293
+ case 'ne':
294
+ var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + fact * ms;
295
+ var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
296
+ break;
297
+ case 'e':
298
+ var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + ms;
299
+ var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
300
+ break;
301
+ case 'se':
302
+ var x = gridpos.x + plot._gridPadding.left + hl.tooltipOffset + fact * ms;
303
+ var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + fact * ms;
304
+ break;
305
+ case 's':
306
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
307
+ var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + ms;
308
+ break;
309
+ case 'sw':
310
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
311
+ var y = gridpos.y + plot._gridPadding.top + hl.tooltipOffset + fact * ms;
312
+ break;
313
+ case 'w':
314
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - ms;
315
+ var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
316
+ break;
317
+ default: // same as 'nw'
318
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - hl.tooltipOffset - fact * ms;
319
+ var y = gridpos.y + plot._gridPadding.top - hl.tooltipOffset - elem.outerHeight(true) - fact * ms;
320
+ break;
321
+ }
322
+ elem.css('left', x);
323
+ elem.css('top', y);
324
+ if (hl.fadeTooltip) {
325
+ elem.fadeIn(hl.tooltipFadeSpeed);
326
+ }
327
+ else {
328
+ elem.show();
329
+ }
330
+
331
+ }
332
+
333
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
334
+ var hl = plot.plugins.highlighter;
335
+ if (hl.show) {
336
+ if (neighbor == null && hl.isHighlighting) {
337
+ var ctx = hl.highlightCanvas._ctx;
338
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
339
+ if (hl.fadeTooltip) {
340
+ hl._tooltipElem.fadeOut(hl.tooltipFadeSpeed);
341
+ }
342
+ else {
343
+ hl._tooltipElem.hide();
344
+ }
345
+ hl.isHighlighting = false;
346
+
347
+ }
348
+ if (neighbor != null && plot.series[neighbor.seriesIndex].showHighlight && !hl.isHighlighting) {
349
+ hl.isHighlighting = true;
350
+ if (hl.showMarker) {
351
+ draw(plot, neighbor);
352
+ }
353
+ if (hl.showTooltip) {
354
+ showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
355
+ }
356
+ }
357
+ }
358
+ }
359
+ })(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.eventListenerHooks.push(["jqplotMouseMove",c]);b.jqplot.Highlighter=function(e){this.show=b.jqplot.config.enablePlugins;this.markerRenderer=new b.jqplot.MarkerRenderer({shadow:false});this.showMarker=true;this.lineWidthAdjust=2.5;this.sizeAdjust=5;this.showTooltip=true;this.tooltipLocation="nw";this.fadeTooltip=true;this.tooltipFadeSpeed="fast";this.tooltipOffset=2;this.tooltipAxes="both";this.tooltipSeparator=", ";this.useAxesFormatters=true;this.tooltipFormatString="%.5P";this.formatString=null;this.yvalues=1;this._tooltipElem;this.isHighlighting=false;b.extend(true,this,e)};b.jqplot.Highlighter.init=function(h,g,f){var e=f||{};this.plugins.highlighter=new b.jqplot.Highlighter(e.highlighter)};b.jqplot.Highlighter.parseOptions=function(f,e){this.showHighlight=true};b.jqplot.Highlighter.postPlotDraw=function(){this.plugins.highlighter.highlightCanvas=new b.jqplot.GenericCanvas();this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding,"jqplot-highlight-canvas",this._plotDimensions));var f=this.plugins.highlighter.highlightCanvas.setContext();var e=this.plugins.highlighter;e._tooltipElem=b('<div class="jqplot-highlighter-tooltip" style="position:absolute;display:none"></div>');this.target.append(e._tooltipElem)};b.jqplot.preInitHooks.push(b.jqplot.Highlighter.init);b.jqplot.preParseSeriesOptionsHooks.push(b.jqplot.Highlighter.parseOptions);b.jqplot.postDrawHooks.push(b.jqplot.Highlighter.postPlotDraw);function a(j,l){var g=j.plugins.highlighter;var m=j.series[l.seriesIndex];var e=m.markerRenderer;var f=g.markerRenderer;f.style=e.style;f.lineWidth=e.lineWidth+g.lineWidthAdjust;f.size=e.size+g.sizeAdjust;var i=b.jqplot.getColorComponents(e.color);var k=[i[0],i[1],i[2]];var h=(i[3]>=0.6)?i[3]*0.6:i[3]*(2-i[3]);f.color="rgba("+k[0]+","+k[1]+","+k[2]+","+h+")";f.init();f.draw(m.gridData[l.pointIndex][0],m.gridData[l.pointIndex][1],g.highlightCanvas._ctx)}function d(s,m,j){var g=s.plugins.highlighter;var v=g._tooltipElem;if(g.useAxesFormatters){var q=m._xaxis._ticks[0].formatter;var e=m._yaxis._ticks[0].formatter;var w=m._xaxis._ticks[0].formatString;var n=m._yaxis._ticks[0].formatString;var r;var o=q(w,j.data[0]);var h=[];for(var t=1;t<g.yvalues+1;t++){h.push(e(n,j.data[t]))}if(g.formatString){switch(g.tooltipAxes){case"both":case"xy":h.unshift(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;case"yx":h.push(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;case"x":r=b.jqplot.sprintf.apply(b.jqplot.sprintf,[g.formatString,o]);break;case"y":h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break;default:h.unshift(o);h.unshift(g.formatString);r=b.jqplot.sprintf.apply(b.jqplot.sprintf,h);break}}else{switch(g.tooltipAxes){case"both":case"xy":r=o;for(var t=0;t<h.length;t++){r+=g.tooltipSeparator+h[t]}break;case"yx":r="";for(var t=0;t<h.length;t++){r+=h[t]+g.tooltipSeparator}r+=o;break;case"x":r=o;break;case"y":r="";for(var t=0;t<h.length;t++){r+=h[t]+g.tooltipSeparator}break;default:r=o;for(var t=0;t<h.length;t++){r+=g.tooltipSeparator+h[t]}break}}}else{var r;if(g.tooltipAxes=="both"||g.tooltipAxes=="xy"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[0])+g.tooltipSeparator+b.jqplot.sprintf(g.tooltipFormatString,j.data[1])}else{if(g.tooltipAxes=="yx"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[1])+g.tooltipSeparator+b.jqplot.sprintf(g.tooltipFormatString,j.data[0])}else{if(g.tooltipAxes=="x"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[0])}else{if(g.tooltipAxes=="y"){r=b.jqplot.sprintf(g.tooltipFormatString,j.data[1])}}}}}v.html(r);var u={x:j.gridData[0],y:j.gridData[1]};var p=0;var f=0.707;if(m.markerRenderer.show==true){p=(m.markerRenderer.size+g.sizeAdjust)/2}switch(g.tooltipLocation){case"nw":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break;case"n":var l=u.x+s._gridPadding.left-v.outerWidth(true)/2;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-p;break;case"ne":var l=u.x+s._gridPadding.left+g.tooltipOffset+f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break;case"e":var l=u.x+s._gridPadding.left+g.tooltipOffset+p;var k=u.y+s._gridPadding.top-v.outerHeight(true)/2;break;case"se":var l=u.x+s._gridPadding.left+g.tooltipOffset+f*p;var k=u.y+s._gridPadding.top+g.tooltipOffset+f*p;break;case"s":var l=u.x+s._gridPadding.left-v.outerWidth(true)/2;var k=u.y+s._gridPadding.top+g.tooltipOffset+p;break;case"sw":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top+g.tooltipOffset+f*p;break;case"w":var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-p;var k=u.y+s._gridPadding.top-v.outerHeight(true)/2;break;default:var l=u.x+s._gridPadding.left-v.outerWidth(true)-g.tooltipOffset-f*p;var k=u.y+s._gridPadding.top-g.tooltipOffset-v.outerHeight(true)-f*p;break}v.css("left",l);v.css("top",k);if(g.fadeTooltip){v.fadeIn(g.tooltipFadeSpeed)}else{v.show()}}function c(h,g,k,j,i){var e=i.plugins.highlighter;if(e.show){if(j==null&&e.isHighlighting){var f=e.highlightCanvas._ctx;f.clearRect(0,0,f.canvas.width,f.canvas.height);if(e.fadeTooltip){e._tooltipElem.fadeOut(e.tooltipFadeSpeed)}else{e._tooltipElem.hide()}e.isHighlighting=false}if(j!=null&&i.series[j.seriesIndex].showHighlight&&!e.isHighlighting){e.isHighlighting=true;if(e.showMarker){a(i,j)}if(e.showTooltip){d(i,i.series[j.seriesIndex],j)}}}}})(jQuery);