rhosync 2.0.9 → 2.1.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGELOG +9 -0
  2. data/Rakefile +1 -1
  3. data/bench/benchapp/sources/mock_adapter.rb +2 -2
  4. data/bench/benchapp/tmp/restart.txt +0 -0
  5. data/bench/spec/mock_adapter_spec.rb +1 -1
  6. data/lib/rhosync/api/stats.rb +21 -0
  7. data/lib/rhosync/bulk_data/bulk_data.rb +1 -1
  8. data/lib/rhosync/client.rb +10 -0
  9. data/lib/rhosync/console/app/public/home.css +9 -4
  10. data/lib/rhosync/console/app/public/images/foot_logo_rhosync.png +0 -0
  11. data/lib/rhosync/console/app/public/images/landing_header.jpg +0 -0
  12. data/lib/rhosync/console/app/public/jqplot/excanvas.min.js +35 -0
  13. data/lib/rhosync/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
  14. data/lib/rhosync/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
  15. data/lib/rhosync/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
  16. data/lib/rhosync/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
  17. data/lib/rhosync/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
  18. data/lib/rhosync/console/app/public/jqplot/jqplot.cursor.js +952 -0
  19. data/lib/rhosync/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
  20. data/lib/rhosync/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
  21. data/lib/rhosync/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
  22. data/lib/rhosync/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
  23. data/lib/rhosync/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
  24. data/lib/rhosync/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
  25. data/lib/rhosync/console/app/routes/timing.rb +223 -7
  26. data/lib/rhosync/console/app/views/content.erb +1 -1
  27. data/lib/rhosync/console/app/views/headermenu.erb +4 -4
  28. data/lib/rhosync/console/app/views/jqplot.erb +52 -0
  29. data/lib/rhosync/console/app/views/layout.erb +86 -11
  30. data/lib/rhosync/console/rhosync_api.rb +19 -0
  31. data/lib/rhosync/jobs/bulk_data_job.rb +2 -2
  32. data/lib/rhosync/stats/middleware.rb +4 -6
  33. data/lib/rhosync/stats/record.rb +51 -26
  34. data/lib/rhosync/store.rb +12 -1
  35. data/lib/rhosync/tasks.rb +4 -2
  36. data/lib/rhosync/user.rb +11 -1
  37. data/lib/rhosync/version.rb +2 -2
  38. data/lib/rhosync.rb +3 -3
  39. data/spec/api/rhosync_api_spec.rb +26 -0
  40. data/spec/api/stats_spec.rb +66 -0
  41. data/spec/client_spec.rb +40 -0
  42. data/spec/client_sync_spec.rb +14 -0
  43. data/spec/stats/middleware_spec.rb +11 -5
  44. data/spec/stats/record_spec.rb +30 -11
  45. data/spec/store_spec.rb +15 -1
  46. data/spec/user_spec.rb +44 -0
  47. metadata +32 -14
  48. data/doc/protocol.html +0 -2291
  49. data/doc/public/css/print.css +0 -29
  50. data/doc/public/css/screen.css +0 -257
  51. data/doc/public/css/style.css +0 -20
  52. data/lib/rhosync/console/app/public/images/header_halo copy.jpg +0 -0
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Copyright (c) 2009 - 2010 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 at jqplot dot com
9
+ * 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.DateAxisRenderer
21
+ * A plugin for a jqPlot to render an axis as a series of date values.
22
+ * This renderer has no options beyond those supplied by the <Axis> class.
23
+ * It supplies it's own tick formatter, so the tickOptions.formatter option
24
+ * should not be overridden.
25
+ *
26
+ * Thanks to Ken Synder for his enhanced Date instance methods which are
27
+ * included with this code <http://kendsnyder.com/sandbox/date/>.
28
+ *
29
+ * To use this renderer, include the plugin in your source
30
+ * > <script type="text/javascript" language="javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
31
+ *
32
+ * and supply the appropriate options to your plot
33
+ *
34
+ * > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}}
35
+ *
36
+ * Dates can be passed into the axis in almost any recognizable value and
37
+ * will be parsed. They will be rendered on the axis in the format
38
+ * specified by tickOptions.formatString. e.g. tickOptions.formatString = '%Y-%m-%d'.
39
+ *
40
+ * Accecptable format codes
41
+ * are:
42
+ *
43
+ * > Code Result Description
44
+ * > == Years ==
45
+ * > %Y 2008 Four-digit year
46
+ * > %y 08 Two-digit year
47
+ * > == Months ==
48
+ * > %m 09 Two-digit month
49
+ * > %#m 9 One or two-digit month
50
+ * > %B September Full month name
51
+ * > %b Sep Abbreviated month name
52
+ * > == Days ==
53
+ * > %d 05 Two-digit day of month
54
+ * > %#d 5 One or two-digit day of month
55
+ * > %e 5 One or two-digit day of month
56
+ * > %A Sunday Full name of the day of the week
57
+ * > %a Sun Abbreviated name of the day of the week
58
+ * > %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
59
+ * > %o th The ordinal suffix string following the day of the month
60
+ * > == Hours ==
61
+ * > %H 23 Hours in 24-hour format (two digits)
62
+ * > %#H 3 Hours in 24-hour integer format (one or two digits)
63
+ * > %I 11 Hours in 12-hour format (two digits)
64
+ * > %#I 3 Hours in 12-hour integer format (one or two digits)
65
+ * > %p PM AM or PM
66
+ * > == Minutes ==
67
+ * > %M 09 Minutes (two digits)
68
+ * > %#M 9 Minutes (one or two digits)
69
+ * > == Seconds ==
70
+ * > %S 02 Seconds (two digits)
71
+ * > %#S 2 Seconds (one or two digits)
72
+ * > %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
73
+ * > == Milliseconds ==
74
+ * > %N 008 Milliseconds (three digits)
75
+ * > %#N 8 Milliseconds (one to three digits)
76
+ * > == Timezone ==
77
+ * > %O 360 difference in minutes between local time and GMT
78
+ * > %Z Mountain Standard Time Name of timezone as reported by browser
79
+ * > %G -06:00 Hours and minutes between GMT
80
+ * > == Shortcuts ==
81
+ * > %F 2008-03-26 %Y-%m-%d
82
+ * > %T 05:06:30 %H:%M:%S
83
+ * > %X 05:06:30 %H:%M:%S
84
+ * > %x 03/26/08 %m/%d/%y
85
+ * > %D 03/26/08 %m/%d/%y
86
+ * > %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
87
+ * > %v 3-Sep-2008 %e-%b-%Y
88
+ * > %R 15:31 %H:%M
89
+ * > %r 3:31:00 PM %I:%M:%S %p
90
+ * > == Characters ==
91
+ * > %n \n Newline
92
+ * > %t \t Tab
93
+ * > %% % Percent Symbol
94
+ */
95
+ $.jqplot.DateAxisRenderer = function() {
96
+ $.jqplot.LinearAxisRenderer.call(this);
97
+ };
98
+
99
+ $.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
100
+ $.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer;
101
+
102
+ $.jqplot.DateTickFormatter = function(format, val) {
103
+ if (!format) {
104
+ format = '%Y/%m/%d';
105
+ }
106
+ return Date.create(val).strftime(format);
107
+ };
108
+
109
+ $.jqplot.DateAxisRenderer.prototype.init = function(options){
110
+ // prop: tickRenderer
111
+ // A class of a rendering engine for creating the ticks labels displayed on the plot,
112
+ // See <$.jqplot.AxisTickRenderer>.
113
+ // this.tickRenderer = $.jqplot.AxisTickRenderer;
114
+ // this.labelRenderer = $.jqplot.AxisLabelRenderer;
115
+ this.tickOptions.formatter = $.jqplot.DateTickFormatter;
116
+ this.daTickInterval = null;
117
+ this._daTickInterval = null;
118
+ $.extend(true, this, options);
119
+ var db = this._dataBounds;
120
+ // Go through all the series attached to this axis and find
121
+ // the min/max bounds for this axis.
122
+ for (var i=0; i<this._series.length; i++) {
123
+ var s = this._series[i];
124
+ var d = s.data;
125
+ var pd = s._plotData;
126
+ var sd = s._stackData;
127
+
128
+ for (var j=0; j<d.length; j++) {
129
+ if (this.name == 'xaxis' || this.name == 'x2axis') {
130
+ d[j][0] = Date.create(d[j][0]).getTime();
131
+ pd[j][0] = Date.create(d[j][0]).getTime();
132
+ sd[j][0] = Date.create(d[j][0]).getTime();
133
+ if (d[j][0] < db.min || db.min == null) {
134
+ db.min = d[j][0];
135
+ }
136
+ if (d[j][0] > db.max || db.max == null) {
137
+ db.max = d[j][0];
138
+ }
139
+ }
140
+ else {
141
+ d[j][1] = Date.create(d[j][1]).getTime();
142
+ pd[j][1] = Date.create(d[j][1]).getTime();
143
+ sd[j][1] = Date.create(d[j][1]).getTime();
144
+ if (d[j][1] < db.min || db.min == null) {
145
+ db.min = d[j][1];
146
+ }
147
+ if (d[j][1] > db.max || db.max == null) {
148
+ db.max = d[j][1];
149
+ }
150
+ }
151
+ }
152
+ }
153
+ };
154
+
155
+ // called with scope of an axis
156
+ $.jqplot.DateAxisRenderer.prototype.reset = function() {
157
+ this.min = this._min;
158
+ this.max = this._max;
159
+ this.tickInterval = this._tickInterval;
160
+ this.numberTicks = this._numberTicks;
161
+ this.daTickInterval = this._daTickInterval;
162
+ // this._ticks = this.__ticks;
163
+ };
164
+
165
+ $.jqplot.DateAxisRenderer.prototype.createTicks = function() {
166
+ // we're are operating on an axis here
167
+ var ticks = this._ticks;
168
+ var userTicks = this.ticks;
169
+ var name = this.name;
170
+ // databounds were set on axis initialization.
171
+ var db = this._dataBounds;
172
+ var dim, interval;
173
+ var min, max;
174
+ var pos1, pos2;
175
+ var tt, i;
176
+
177
+ // if we already have ticks, use them.
178
+ // ticks must be in order of increasing value.
179
+
180
+ if (userTicks.length) {
181
+ // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
182
+ for (i=0; i<userTicks.length; i++){
183
+ var ut = userTicks[i];
184
+ var t = new this.tickRenderer(this.tickOptions);
185
+ if (ut.constructor == Array) {
186
+ t.value = Date.create(ut[0]).getTime();
187
+ t.label = ut[1];
188
+ if (!this.showTicks) {
189
+ t.showLabel = false;
190
+ t.showMark = false;
191
+ }
192
+ else if (!this.showTickMarks) {
193
+ t.showMark = false;
194
+ }
195
+ t.setTick(t.value, this.name);
196
+ this._ticks.push(t);
197
+ }
198
+
199
+ else {
200
+ t.value = Date.create(ut).getTime();
201
+ if (!this.showTicks) {
202
+ t.showLabel = false;
203
+ t.showMark = false;
204
+ }
205
+ else if (!this.showTickMarks) {
206
+ t.showMark = false;
207
+ }
208
+ t.setTick(t.value, this.name);
209
+ this._ticks.push(t);
210
+ }
211
+ }
212
+ this.numberTicks = userTicks.length;
213
+ this.min = this._ticks[0].value;
214
+ this.max = this._ticks[this.numberTicks-1].value;
215
+ this.daTickInterval = [(this.max - this.min) / (this.numberTicks - 1)/1000, 'seconds'];
216
+ }
217
+
218
+ // we don't have any ticks yet, let's make some!
219
+ else {
220
+ if (name == 'xaxis' || name == 'x2axis') {
221
+ dim = this._plotDimensions.width;
222
+ }
223
+ else {
224
+ dim = this._plotDimensions.height;
225
+ }
226
+
227
+ // if min, max and number of ticks specified, user can't specify interval.
228
+ if (this.min != null && this.max != null && this.numberTicks != null) {
229
+ this.tickInterval = null;
230
+ }
231
+
232
+ // if user specified a tick interval, convert to usable.
233
+ if (this.tickInterval != null)
234
+ {
235
+ // if interval is a number or can be converted to one, use it.
236
+ // Assume it is in SECONDS!!!
237
+ if (Number(this.tickInterval)) {
238
+ this.daTickInterval = [Number(this.tickInterval), 'seconds'];
239
+ }
240
+ // else, parse out something we can build from.
241
+ else if (typeof this.tickInterval == "string") {
242
+ var parts = this.tickInterval.split(' ');
243
+ if (parts.length == 1) {
244
+ this.daTickInterval = [1, parts[0]];
245
+ }
246
+ else if (parts.length == 2) {
247
+ this.daTickInterval = [parts[0], parts[1]];
248
+ }
249
+ }
250
+ }
251
+
252
+ min = ((this.min != null) ? Date.create(this.min).getTime() : db.min);
253
+ max = ((this.max != null) ? Date.create(this.max).getTime() : db.max);
254
+
255
+ // if min and max are same, space them out a bit
256
+ if (min == max) {
257
+ var adj = 24*60*60*500; // 1/2 day
258
+ min -= adj;
259
+ max += adj;
260
+ }
261
+
262
+ var range = max - min;
263
+ var rmin, rmax;
264
+
265
+ rmin = (this.min != null) ? Date.create(this.min).getTime() : min - range/2*(this.padMin - 1);
266
+ rmax = (this.max != null) ? Date.create(this.max).getTime() : max + range/2*(this.padMax - 1);
267
+ this.min = rmin;
268
+ this.max = rmax;
269
+ range = this.max - this.min;
270
+
271
+ if (this.numberTicks == null){
272
+ // if tickInterval is specified by user, we will ignore computed maximum.
273
+ // max will be equal or greater to fit even # of ticks.
274
+ if (this.daTickInterval != null) {
275
+ var nc = Date.create(this.max).diff(this.min, this.daTickInterval[1], true);
276
+ this.numberTicks = Math.ceil(nc/this.daTickInterval[0]) +1;
277
+ // this.max = Date.create(this.min).add(this.numberTicks-1, this.daTickInterval[1]).getTime();
278
+ this.max = Date.create(this.min).add((this.numberTicks-1) * this.daTickInterval[0], this.daTickInterval[1]).getTime();
279
+ }
280
+ else if (dim > 200) {
281
+ this.numberTicks = parseInt(3+(dim-200)/100, 10);
282
+ }
283
+ else {
284
+ this.numberTicks = 2;
285
+ }
286
+ }
287
+
288
+ if (this.daTickInterval == null) {
289
+ this.daTickInterval = [range / (this.numberTicks-1)/1000, 'seconds'];
290
+ }
291
+ for (var i=0; i<this.numberTicks; i++){
292
+ var min = Date.create(this.min);
293
+ tt = min.add(i*this.daTickInterval[0], this.daTickInterval[1]).getTime();
294
+ var t = new this.tickRenderer(this.tickOptions);
295
+ // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
296
+ if (!this.showTicks) {
297
+ t.showLabel = false;
298
+ t.showMark = false;
299
+ }
300
+ else if (!this.showTickMarks) {
301
+ t.showMark = false;
302
+ }
303
+ t.setTick(tt, this.name);
304
+ this._ticks.push(t);
305
+ }
306
+ }
307
+ if (this._daTickInterval == null) {
308
+ this._daTickInterval = this.daTickInterval;
309
+ }
310
+ };
311
+
312
+ })(jQuery);
313
+
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2009 - 2010 Chris Leonello
3
+ * jqPlot is currently available for use in all personal or commercial projects
4
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
5
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
6
+ * choose the license that best suits your project and use it accordingly.
7
+ *
8
+ * Although not required, the author would appreciate an email letting him
9
+ * know of any substantial use of jqPlot. You can reach the author at:
10
+ * chris at jqplot or see http://www.jqplot.com/info.php .
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
+ * jqPlot includes date instance methods and printf/sprintf functions by other authors:
16
+ *
17
+ * Date instance methods contained in jqplot.dateMethods.js:
18
+ *
19
+ * author Ken Snyder (ken d snyder at gmail dot com)
20
+ * date 2008-09-10
21
+ * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
22
+ * license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
23
+ *
24
+ * JavaScript printf/sprintf functions contained in jqplot.sprintf.js:
25
+ *
26
+ * version 2007.04.27
27
+ * author Ash Searle
28
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
29
+ * http://hexmen.com/js/sprintf.js
30
+ * The author (Ash Searle) has placed this code in the public domain:
31
+ * "This code is unrestricted: you are free to use it however you like."
32
+ *
33
+ */
34
+ (function(a){a.jqplot.DateAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this)};a.jqplot.DateAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.DateAxisRenderer.prototype.constructor=a.jqplot.DateAxisRenderer;a.jqplot.DateTickFormatter=function(b,c){if(!b){b="%Y/%m/%d"}return Date.create(c).strftime(b)};a.jqplot.DateAxisRenderer.prototype.init=function(f){this.tickOptions.formatter=a.jqplot.DateTickFormatter;this.daTickInterval=null;this._daTickInterval=null;a.extend(true,this,f);var c=this._dataBounds;for(var g=0;g<this._series.length;g++){var h=this._series[g];var l=h.data;var b=h._plotData;var k=h._stackData;for(var e=0;e<l.length;e++){if(this.name=="xaxis"||this.name=="x2axis"){l[e][0]=Date.create(l[e][0]).getTime();b[e][0]=Date.create(l[e][0]).getTime();k[e][0]=Date.create(l[e][0]).getTime();if(l[e][0]<c.min||c.min==null){c.min=l[e][0]}if(l[e][0]>c.max||c.max==null){c.max=l[e][0]}}else{l[e][1]=Date.create(l[e][1]).getTime();b[e][1]=Date.create(l[e][1]).getTime();k[e][1]=Date.create(l[e][1]).getTime();if(l[e][1]<c.min||c.min==null){c.min=l[e][1]}if(l[e][1]>c.max||c.max==null){c.max=l[e][1]}}}}};a.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._min;this.max=this._max;this.tickInterval=this._tickInterval;this.numberTicks=this._numberTicks;this.daTickInterval=this._daTickInterval};a.jqplot.DateAxisRenderer.prototype.createTicks=function(){var v=this._ticks;var r=this.ticks;var w=this.name;var u=this._dataBounds;var o,s;var m,p;var d,c;var b,q;if(r.length){for(q=0;q<r.length;q++){var f=r[q];var h=new this.tickRenderer(this.tickOptions);if(f.constructor==Array){h.value=Date.create(f[0]).getTime();h.label=f[1];if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}else{h.value=Date.create(f).getTime();if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}}this.numberTicks=r.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.min)/(this.numberTicks-1)/1000,"seconds"]}else{if(w=="xaxis"||w=="x2axis"){o=this._plotDimensions.width}else{o=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.tickInterval!=null){if(Number(this.tickInterval)){this.daTickInterval=[Number(this.tickInterval),"seconds"]}else{if(typeof this.tickInterval=="string"){var k=this.tickInterval.split(" ");if(k.length==1){this.daTickInterval=[1,k[0]]}else{if(k.length==2){this.daTickInterval=[k[0],k[1]]}}}}}m=((this.min!=null)?Date.create(this.min).getTime():u.min);p=((this.max!=null)?Date.create(this.max).getTime():u.max);if(m==p){var g=24*60*60*500;m-=g;p+=g}var j=p-m;var l,n;l=(this.min!=null)?Date.create(this.min).getTime():m-j/2*(this.padMin-1);n=(this.max!=null)?Date.create(this.max).getTime():p+j/2*(this.padMax-1);this.min=l;this.max=n;j=this.max-this.min;if(this.numberTicks==null){if(this.daTickInterval!=null){var e=Date.create(this.max).diff(this.min,this.daTickInterval[1],true);this.numberTicks=Math.ceil(e/this.daTickInterval[0])+1;this.max=Date.create(this.min).add((this.numberTicks-1)*this.daTickInterval[0],this.daTickInterval[1]).getTime()}else{if(o>200){this.numberTicks=parseInt(3+(o-200)/100,10)}else{this.numberTicks=2}}}if(this.daTickInterval==null){this.daTickInterval=[j/(this.numberTicks-1)/1000,"seconds"]}for(var q=0;q<this.numberTicks;q++){var m=Date.create(this.min);b=m.add(q*this.daTickInterval[0],this.daTickInterval[1]).getTime();var h=new this.tickRenderer(this.tickOptions);if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(b,this.name);this._ticks.push(h)}}if(this._daTickInterval==null){this._daTickInterval=this.daTickInterval}}})(jQuery);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2009 - 2010 Chris Leonello
3
+ * jqPlot is currently available for use in all personal or commercial projects
4
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
5
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
6
+ * choose the license that best suits your project and use it accordingly.
7
+ *
8
+ * Although not required, the author would appreciate an email letting him
9
+ * know of any substantial use of jqPlot. You can reach the author at:
10
+ * chris at jqplot or see http://www.jqplot.com/info.php .
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
+ * jqPlot includes date instance methods and printf/sprintf functions by other authors:
16
+ *
17
+ * Date instance methods contained in jqplot.dateMethods.js:
18
+ *
19
+ * author Ken Snyder (ken d snyder at gmail dot com)
20
+ * date 2008-09-10
21
+ * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
22
+ * license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
23
+ *
24
+ * JavaScript printf/sprintf functions contained in jqplot.sprintf.js:
25
+ *
26
+ * version 2007.04.27
27
+ * author Ash Searle
28
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
29
+ * http://hexmen.com/js/sprintf.js
30
+ * The author (Ash Searle) has placed this code in the public domain:
31
+ * "This code is unrestricted: you are free to use it however you like."
32
+ *
33
+ */
34
+ (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._labels=[];this.stackedValue=false;this.ypadding=6;this.xpadding=6;this.escapeHTML=true;this.edgeTolerance=-5;this.formatter=c.jqplot.DefaultTickFormatter;this.formatString="";this.hideZeros=false;this._elems=[];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(i,h,f,g){var e=c.extend(true,{},f,g);e.pointLabels=e.pointLabels||{};if(this.renderer.constructor==c.jqplot.BarRenderer&&this.barDirection=="horizontal"&&!e.pointLabels.location){e.pointLabels.location="e"}this.plugins.pointLabels=new c.jqplot.PointLabels(e.pointLabels);this.plugins.pointLabels.setLabels.call(this)};c.jqplot.PointLabels.prototype.setLabels=function(){var f=this.plugins.pointLabels;var h;if(f.seriesLabelIndex!=null){h=f.seriesLabelIndex}else{if(this.renderer.constructor==c.jqplot.BarRenderer&&this.barDirection=="horizontal"){h=0}else{h=this._plotData[0].length-1}}f._labels=[];if(f.labels.length==0||f.labelsFromSeries){if(f.stackedValue){if(this._plotData.length&&this._plotData[0].length){for(var e=0;e<this._plotData.length;e++){f._labels.push(this._plotData[e][h])}}}else{var g=this.data;if(this.renderer.constructor==c.jqplot.BarRenderer&&this.waterfall){g=this._data}if(g.length&&g[0].length){for(var e=0;e<g.length;e++){f._labels.push(g[e][h])}}}}else{if(f.labels.length){f._labels=f.labels}}};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(t,h){var r=this.plugins.pointLabels;r.setLabels.call(this);for(var s=0;s<r._elems.length;s++){r._elems[s].remove()}if(r.show){var o="_"+this._stackAxis+"axis";if(!r.formatString){r.formatString=this[o]._ticks[0].formatString;r.formatter=this[o]._ticks[0].formatter}var z=this._plotData;var w=this._xaxis;var n=this._yaxis;for(var s=r._labels.length-1;s>=0;s--){var m=r._labels[s];if(r.hideZeros&&parseInt(r._labels[s],10)==0){m=""}if(m!=null){m=r.formatter(r.formatString,m)}var v=c('<div class="jqplot-point-label jqplot-series-'+this.index+" jqplot-point-"+s+'" style="position:absolute"></div>');v.insertAfter(t.canvas);r._elems.push(v);if(r.escapeHTML){v.text(m)}else{v.html(m)}var f=r.location;if(this.waterfall&&parseInt(m,10)<0){f=b[d[f]]}var l=w.u2p(z[s][0])+r.xOffset(v,f);var g=n.u2p(z[s][1])+r.yOffset(v,f);if(this.renderer.constructor==c.jqplot.BarRenderer){if(this.barDirection=="vertical"){l+=this._barNudge}else{g-=this._barNudge}}v.css("left",l);v.css("top",g);var j=l+c(v).width();var q=g+c(v).height();var y=r.edgeTolerance;var e=c(t.canvas).position().left;var u=c(t.canvas).position().top;var x=t.canvas.width+e;var k=t.canvas.height+u;if(l-y<e||g-y<u||j+y>x||q+y>k){c(v).detach()}}}};c.jqplot.postSeriesInitHooks.push(c.jqplot.PointLabels.init);c.jqplot.postDrawSeriesHooks.push(c.jqplot.PointLabels.draw)})(jQuery);