acts_as_dashboard 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/acts_as_dashboard.gemspec +166 -0
- data/generators/dashboard/USAGE +23 -0
- data/generators/dashboard/dashboard_generator.rb +105 -0
- data/generators/dashboard/templates/controller.erb +39 -0
- data/generators/dashboard/templates/dashboard.css +66 -0
- data/generators/dashboard/templates/dashboard.js +305 -0
- data/generators/dashboard/templates/jqplot-0.9.7/jquery.jqplot.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.js +404 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.js +200 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.js +232 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.js +408 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.js +238 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.js +812 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.js +313 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.js +203 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.js +359 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.js +434 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.js +595 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.js +308 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.js +343 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.js +333 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js +307 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js.orig +273 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.js +208 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.min.js +14 -0
- data/generators/dashboard/templates/jquery.jqplot.min.css +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/CHANGELOG +269 -0
- data/generators/dashboard/templates/js.class-2.1.4/MIT-LICENSE +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/README +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/command.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/comparable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/constant_scope.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/core.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/decorator.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/enumerable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/forwardable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/hash.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/linked_list.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/loader.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/method_chain.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/observable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/package.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/proxy.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/ruby.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/set.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stack_trace.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/state.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stdlib.js +16 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/command.js +93 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/comparable.js +37 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/constant_scope.js +48 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/core.js +1060 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/decorator.js +50 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/enumerable.js +505 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/forwardable.js +22 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/hash.js +334 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/linked_list.js +114 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/loader.js +458 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/method_chain.js +172 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/observable.js +55 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/package.js +377 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/proxy.js +58 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/ruby.js +44 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/set.js +332 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stack_trace.js +151 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/state.js +95 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stdlib.js +2517 -0
- data/generators/dashboard/templates/show.html.erb +67 -0
- data/lib/acts_as_dashboard/app/views/dashboards/show.html.erb +67 -0
- data/lib/acts_as_dashboard/class_methods.rb +58 -0
- data/lib/acts_as_dashboard/config.rb +25 -0
- data/lib/acts_as_dashboard/instance_methods.rb +32 -0
- data/lib/acts_as_dashboard/line_graph_widget.rb +68 -0
- data/lib/acts_as_dashboard/public/javascripts/dashboard.js +305 -0
- data/lib/acts_as_dashboard/public/stylesheets/dashboard.css +66 -0
- data/lib/acts_as_dashboard/short_messages_widget.rb +25 -0
- data/lib/acts_as_dashboard/widget.rb +55 -0
- data/lib/acts_as_dashboard.rb +17 -0
- data/spec/acts_as_dashboard/class_method_specs.rb +188 -0
- data/spec/acts_as_dashboard/config_spec.rb +57 -0
- data/spec/acts_as_dashboard/instance_methods_spec.rb +134 -0
- data/spec/acts_as_dashboard/line_graph_widget_spec.rb +165 -0
- data/spec/acts_as_dashboard/short_messages_widget_spec.rb +69 -0
- data/spec/acts_as_dashboard/widget_spec.rb +6 -0
- data/spec/acts_as_dashboard_spec.rb +15 -0
- data/spec/shared/widget_behaviours.rb +171 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/install.rake +8 -0
- data/tasks/install_javascript.rake +7 -0
- data/tasks/install_stylesheets.rake +7 -0
- metadata +209 -0
@@ -0,0 +1,404 @@
|
|
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.BarRenderer
|
21
|
+
// A plugin renderer for jqPlot to draw a bar plot.
|
22
|
+
// Draws series as a line.
|
23
|
+
|
24
|
+
$.jqplot.BarRenderer = function(){
|
25
|
+
$.jqplot.LineRenderer.call(this);
|
26
|
+
};
|
27
|
+
|
28
|
+
$.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();
|
29
|
+
$.jqplot.BarRenderer.prototype.constructor = $.jqplot.BarRenderer;
|
30
|
+
|
31
|
+
// called with scope of series.
|
32
|
+
$.jqplot.BarRenderer.prototype.init = function(options) {
|
33
|
+
// Group: Properties
|
34
|
+
//
|
35
|
+
// prop: barPadding
|
36
|
+
// Number of pixels between adjacent bars at the same axis value.
|
37
|
+
this.barPadding = 8;
|
38
|
+
// prop: barMargin
|
39
|
+
// Number of pixels between groups of bars at adjacent axis values.
|
40
|
+
this.barMargin = 10;
|
41
|
+
// prop: barDirection
|
42
|
+
// 'vertical' = up and down bars, 'horizontal' = side to side bars
|
43
|
+
this.barDirection = 'vertical';
|
44
|
+
// prop: barWidth
|
45
|
+
// Width of the bar in pixels (auto by devaul). null = calculated automatically.
|
46
|
+
this.barWidth = null;
|
47
|
+
// prop: shadowOffset
|
48
|
+
// offset of the shadow from the slice and offset of
|
49
|
+
// each succesive stroke of the shadow from the last.
|
50
|
+
this.shadowOffset = 2;
|
51
|
+
// prop: shadowDepth
|
52
|
+
// number of strokes to apply to the shadow,
|
53
|
+
// each stroke offset shadowOffset from the last.
|
54
|
+
this.shadowDepth = 5;
|
55
|
+
// prop: shadowAlpha
|
56
|
+
// transparency of the shadow (0 = transparent, 1 = opaque)
|
57
|
+
this.shadowAlpha = 0.08;
|
58
|
+
// prop: waterfall
|
59
|
+
// true to enable waterfall plot.
|
60
|
+
this.waterfall = false;
|
61
|
+
// prop: varyBarColor
|
62
|
+
// true to color each bar separately.
|
63
|
+
this.varyBarColor = false;
|
64
|
+
$.extend(true, this, options);
|
65
|
+
// fill is still needed to properly draw the legend.
|
66
|
+
// bars have to be filled.
|
67
|
+
this.fill = true;
|
68
|
+
|
69
|
+
if (this.waterfall) {
|
70
|
+
this.fillToZero = false;
|
71
|
+
this.disableStack = true;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (this.barDirection == 'vertical' ) {
|
75
|
+
this._primaryAxis = '_xaxis';
|
76
|
+
this._stackAxis = 'y';
|
77
|
+
this.fillAxis = 'y';
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
this._primaryAxis = '_yaxis';
|
81
|
+
this._stackAxis = 'x';
|
82
|
+
this.fillAxis = 'x';
|
83
|
+
}
|
84
|
+
// set the shape renderer options
|
85
|
+
var opts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, strokeStyle:this.color, fillStyle:this.color, closePath:this.fill};
|
86
|
+
this.renderer.shapeRenderer.init(opts);
|
87
|
+
// set the shadow renderer options
|
88
|
+
var sopts = {lineJoin:'miter', lineCap:'round', fill:true, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, closePath:this.fill};
|
89
|
+
this.renderer.shadowRenderer.init(sopts);
|
90
|
+
};
|
91
|
+
|
92
|
+
// called with scope of series
|
93
|
+
function barPreInit(target, data, seriesDefaults, options) {
|
94
|
+
if (this.rendererOptions.barDirection == 'horizontal') {
|
95
|
+
this._stackAxis = 'x';
|
96
|
+
this._primaryAxis = '_yaxis';
|
97
|
+
}
|
98
|
+
if (this.rendererOptions.waterfall == true) {
|
99
|
+
this._data = $.extend(true, [], this.data);
|
100
|
+
var sum = 0;
|
101
|
+
var pos = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection == 'vertical') ? 1 : 0;
|
102
|
+
for(var i=0; i<this.data.length; i++) {
|
103
|
+
sum += this.data[i][pos];
|
104
|
+
if (i>0) {
|
105
|
+
this.data[i][pos] += this.data[i-1][pos];
|
106
|
+
}
|
107
|
+
}
|
108
|
+
this.data[this.data.length] = (pos == 1) ? [this.data.length+1, sum] : [sum, this.data.length+1];
|
109
|
+
this._data[this._data.length] = (pos == 1) ? [this._data.length+1, sum] : [sum, this._data.length+1];
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
$.jqplot.preSeriesInitHooks.push(barPreInit);
|
114
|
+
|
115
|
+
// needs to be called with scope of series, not renderer.
|
116
|
+
$.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() {
|
117
|
+
var nvals = 0;
|
118
|
+
var nseries = 0;
|
119
|
+
var paxis = this[this._primaryAxis];
|
120
|
+
var s, series, pos;
|
121
|
+
// loop through all series on this axis
|
122
|
+
for (var i=0; i < paxis._series.length; i++) {
|
123
|
+
series = paxis._series[i];
|
124
|
+
if (series === this) {
|
125
|
+
pos = i;
|
126
|
+
}
|
127
|
+
// is the series rendered as a bar?
|
128
|
+
if (series.renderer.constructor == $.jqplot.BarRenderer) {
|
129
|
+
// gridData may not be computed yet, use data length insted
|
130
|
+
nvals += series.data.length;
|
131
|
+
nseries += 1;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
return [nvals, nseries, pos];
|
135
|
+
};
|
136
|
+
|
137
|
+
$.jqplot.BarRenderer.prototype.setBarWidth = function() {
|
138
|
+
// need to know how many data values we have on the approprate axis and figure it out.
|
139
|
+
var i;
|
140
|
+
var nvals = 0;
|
141
|
+
var nseries = 0;
|
142
|
+
var paxis = this[this._primaryAxis];
|
143
|
+
var s, series, pos;
|
144
|
+
var temp = this.renderer.calcSeriesNumbers.call(this);
|
145
|
+
nvals = temp[0];
|
146
|
+
nseries = temp[1];
|
147
|
+
var nticks = paxis.numberTicks;
|
148
|
+
var nbins = (nticks-1)/2;
|
149
|
+
// so, now we have total number of axis values.
|
150
|
+
if (paxis.name == 'xaxis' || paxis.name == 'x2axis') {
|
151
|
+
if (this._stack) {
|
152
|
+
this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals * nseries - this.barMargin;
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
this.barWidth = ((paxis._offsets.max - paxis._offsets.min)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
156
|
+
// this.barWidth = (paxis._offsets.max - paxis._offsets.min) / nvals - this.barPadding - this.barMargin/nseries;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
if (this._stack) {
|
161
|
+
this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals * nseries - this.barMargin;
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
this.barWidth = ((paxis._offsets.min - paxis._offsets.max)/nbins - this.barPadding * (nseries-1) - this.barMargin*2)/nseries;
|
165
|
+
// this.barWidth = (paxis._offsets.min - paxis._offsets.max) / nvals - this.barPadding - this.barMargin/nseries;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
return [nvals, nseries];
|
169
|
+
};
|
170
|
+
|
171
|
+
$.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options) {
|
172
|
+
var i;
|
173
|
+
var opts = (options != undefined) ? options : {};
|
174
|
+
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
175
|
+
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
176
|
+
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
177
|
+
var xaxis = this.xaxis;
|
178
|
+
var yaxis = this.yaxis;
|
179
|
+
var xp = this._xaxis.series_u2p;
|
180
|
+
var yp = this._yaxis.series_u2p;
|
181
|
+
var pointx, pointy, nvals, nseries, pos;
|
182
|
+
|
183
|
+
if (this.barWidth == null) {
|
184
|
+
this.renderer.setBarWidth.call(this);
|
185
|
+
}
|
186
|
+
|
187
|
+
var temp = this.renderer.calcSeriesNumbers.call(this);
|
188
|
+
nvals = temp[0];
|
189
|
+
nseries = temp[1];
|
190
|
+
pos = temp[2];
|
191
|
+
|
192
|
+
if (this._stack) {
|
193
|
+
this._barNudge = 0;
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
197
|
+
}
|
198
|
+
if (showLine) {
|
199
|
+
var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
|
200
|
+
var positiveColors = new $.jqplot.ColorGenerator(this.seriesColors);
|
201
|
+
var negativeColor = negativeColors.get(this.index);
|
202
|
+
if (! this.useNegativeColors) {
|
203
|
+
negativeColor = opts.fillStyle;
|
204
|
+
}
|
205
|
+
var positiveColor = opts.fillStyle;
|
206
|
+
|
207
|
+
if (this.barDirection == 'vertical') {
|
208
|
+
for (var i=0; i<gridData.length; i++) {
|
209
|
+
points = [];
|
210
|
+
var base = gridData[i][0] + this._barNudge;
|
211
|
+
var ystart;
|
212
|
+
|
213
|
+
// stacked
|
214
|
+
if (this._stack && this._prevGridData.length) {
|
215
|
+
ystart = this._prevGridData[i][1];
|
216
|
+
}
|
217
|
+
// not stacked and first series in stack
|
218
|
+
else {
|
219
|
+
if (this.fillToZero) {
|
220
|
+
ystart = this._yaxis.series_u2p(0);
|
221
|
+
}
|
222
|
+
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
223
|
+
ystart = this.gridData[i-1][1];
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
ystart = ctx.canvas.height;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
230
|
+
if (this.varyBarColor) {
|
231
|
+
if (this.useNegativeColors) {
|
232
|
+
opts.fillStyle = negativeColors.next();
|
233
|
+
}
|
234
|
+
else {
|
235
|
+
opts.fillStyle = positiveColors.next();
|
236
|
+
}
|
237
|
+
}
|
238
|
+
else {
|
239
|
+
opts.fillStyle = negativeColor;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
else {
|
243
|
+
if (this.varyBarColor) {
|
244
|
+
opts.fillStyle = positiveColors.next();
|
245
|
+
}
|
246
|
+
else {
|
247
|
+
opts.fillStyle = positiveColor;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
points.push([base-this.barWidth/2, ystart]);
|
252
|
+
points.push([base-this.barWidth/2, gridData[i][1]]);
|
253
|
+
points.push([base+this.barWidth/2, gridData[i][1]]);
|
254
|
+
points.push([base+this.barWidth/2, ystart]);
|
255
|
+
// now draw the shadows if not stacked.
|
256
|
+
// for stacked plots, they are predrawn by drawShadow
|
257
|
+
if (shadow && !this._stack) {
|
258
|
+
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
259
|
+
}
|
260
|
+
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
else if (this.barDirection == 'horizontal'){
|
265
|
+
for (var i=0; i<gridData.length; i++) {
|
266
|
+
points = [];
|
267
|
+
var base = gridData[i][1] - this._barNudge;
|
268
|
+
var xstart;
|
269
|
+
|
270
|
+
if (this._stack && this._prevGridData.length) {
|
271
|
+
xstart = this._prevGridData[i][0];
|
272
|
+
}
|
273
|
+
// not stacked and first series in stack
|
274
|
+
else {
|
275
|
+
if (this.fillToZero) {
|
276
|
+
xstart = this._xaxis.series_u2p(0);
|
277
|
+
}
|
278
|
+
else if (this.waterfall && i > 0 && i < this.gridData.length-1) {
|
279
|
+
xstart = this.gridData[i-1][1];
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
xstart = 0;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
if ((this.fillToZero && this._plotData[i][1] < 0) || (this.waterfall && this._data[i][1] < 0)) {
|
286
|
+
if (this.varyBarColor) {
|
287
|
+
if (this.useNegativeColors) {
|
288
|
+
opts.fillStyle = negativeColors.next();
|
289
|
+
}
|
290
|
+
else {
|
291
|
+
opts.fillStyle = positiveColors.next();
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
if (this.varyBarColor) {
|
297
|
+
opts.fillStyle = positiveColors.next();
|
298
|
+
}
|
299
|
+
else {
|
300
|
+
opts.fillStyle = positiveColor;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
points.push([xstart, base+this.barWidth/2]);
|
305
|
+
points.push([gridData[i][0], base+this.barWidth/2]);
|
306
|
+
points.push([gridData[i][0], base-this.barWidth/2]);
|
307
|
+
points.push([xstart, base-this.barWidth/2]);
|
308
|
+
// now draw the shadows if not stacked.
|
309
|
+
// for stacked plots, they are predrawn by drawShadow
|
310
|
+
if (shadow && !this._stack) {
|
311
|
+
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
312
|
+
}
|
313
|
+
this.renderer.shapeRenderer.draw(ctx, points, opts);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
};
|
319
|
+
|
320
|
+
|
321
|
+
// for stacked plots, shadows will be pre drawn by drawShadow.
|
322
|
+
$.jqplot.BarRenderer.prototype.drawShadow = function(ctx, gridData, options) {
|
323
|
+
var i;
|
324
|
+
var opts = (options != undefined) ? options : {};
|
325
|
+
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
326
|
+
var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
|
327
|
+
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
328
|
+
var xaxis = this.xaxis;
|
329
|
+
var yaxis = this.yaxis;
|
330
|
+
var xp = this._xaxis.series_u2p;
|
331
|
+
var yp = this._yaxis.series_u2p;
|
332
|
+
var pointx, pointy, nvals, nseries, pos;
|
333
|
+
|
334
|
+
if (this._stack && this.shadow) {
|
335
|
+
if (this.barWidth == null) {
|
336
|
+
this.renderer.setBarWidth.call(this);
|
337
|
+
}
|
338
|
+
|
339
|
+
var temp = this.renderer.calcSeriesNumbers.call(this);
|
340
|
+
nvals = temp[0];
|
341
|
+
nseries = temp[1];
|
342
|
+
pos = temp[2];
|
343
|
+
|
344
|
+
if (this._stack) {
|
345
|
+
this._barNudge = 0;
|
346
|
+
}
|
347
|
+
else {
|
348
|
+
this._barNudge = (-Math.abs(nseries/2 - 0.5) + pos) * (this.barWidth + this.barPadding);
|
349
|
+
}
|
350
|
+
if (showLine) {
|
351
|
+
|
352
|
+
if (this.barDirection == 'vertical') {
|
353
|
+
for (var i=0; i<gridData.length; i++) {
|
354
|
+
points = [];
|
355
|
+
var base = gridData[i][0] + this._barNudge;
|
356
|
+
var ystart;
|
357
|
+
|
358
|
+
if (this._stack && this._prevGridData.length) {
|
359
|
+
ystart = this._prevGridData[i][1];
|
360
|
+
}
|
361
|
+
else {
|
362
|
+
if (this.fillToZero) {
|
363
|
+
ystart = this._yaxis.series_u2p(0);
|
364
|
+
}
|
365
|
+
else {
|
366
|
+
ystart = ctx.canvas.height;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
points.push([base-this.barWidth/2, ystart]);
|
371
|
+
points.push([base-this.barWidth/2, gridData[i][1]]);
|
372
|
+
points.push([base+this.barWidth/2, gridData[i][1]]);
|
373
|
+
points.push([base+this.barWidth/2, ystart]);
|
374
|
+
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
else if (this.barDirection == 'horizontal'){
|
379
|
+
for (var i=0; i<gridData.length; i++) {
|
380
|
+
points = [];
|
381
|
+
var base = gridData[i][1] - this._barNudge;
|
382
|
+
var xstart;
|
383
|
+
|
384
|
+
if (this._stack && this._prevGridData.length) {
|
385
|
+
xstart = this._prevGridData[i][0];
|
386
|
+
}
|
387
|
+
else {
|
388
|
+
xstart = 0;
|
389
|
+
}
|
390
|
+
|
391
|
+
points.push([xstart, base+this.barWidth/2]);
|
392
|
+
points.push([gridData[i][0], base+this.barWidth/2]);
|
393
|
+
points.push([gridData[i][0], base-this.barWidth/2]);
|
394
|
+
points.push([xstart, base-this.barWidth/2]);
|
395
|
+
this.renderer.shadowRenderer.draw(ctx, points, opts);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
}
|
399
|
+
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
};
|
404
|
+
})(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.BarRenderer=function(){b.jqplot.LineRenderer.call(this)};b.jqplot.BarRenderer.prototype=new b.jqplot.LineRenderer();b.jqplot.BarRenderer.prototype.constructor=b.jqplot.BarRenderer;b.jqplot.BarRenderer.prototype.init=function(d){this.barPadding=8;this.barMargin=10;this.barDirection="vertical";this.barWidth=null;this.shadowOffset=2;this.shadowDepth=5;this.shadowAlpha=0.08;this.waterfall=false;this.varyBarColor=false;b.extend(true,this,d);this.fill=true;if(this.waterfall){this.fillToZero=false;this.disableStack=true}if(this.barDirection=="vertical"){this._primaryAxis="_xaxis";this._stackAxis="y";this.fillAxis="y"}else{this._primaryAxis="_yaxis";this._stackAxis="x";this.fillAxis="x"}var e={lineJoin:"miter",lineCap:"round",fill:true,isarc:false,strokeStyle:this.color,fillStyle:this.color,closePath:this.fill};this.renderer.shapeRenderer.init(e);var c={lineJoin:"miter",lineCap:"round",fill:true,isarc:false,angle:this.shadowAngle,offset:this.shadowOffset,alpha:this.shadowAlpha,depth:this.shadowDepth,closePath:this.fill};this.renderer.shadowRenderer.init(c)};function a(h,g,f,c){if(this.rendererOptions.barDirection=="horizontal"){this._stackAxis="x";this._primaryAxis="_yaxis"}if(this.rendererOptions.waterfall==true){this._data=b.extend(true,[],this.data);var e=0;var j=(!this.rendererOptions.barDirection||this.rendererOptions.barDirection=="vertical")?1:0;for(var d=0;d<this.data.length;d++){e+=this.data[d][j];if(d>0){this.data[d][j]+=this.data[d-1][j]}}this.data[this.data.length]=(j==1)?[this.data.length+1,e]:[e,this.data.length+1];this._data[this._data.length]=(j==1)?[this._data.length+1,e]:[e,this._data.length+1]}}b.jqplot.preSeriesInitHooks.push(a);b.jqplot.BarRenderer.prototype.calcSeriesNumbers=function(){var g=0;var h=0;var f=this[this._primaryAxis];var e,d,j;for(var c=0;c<f._series.length;c++){d=f._series[c];if(d===this){j=c}if(d.renderer.constructor==b.jqplot.BarRenderer){g+=d.data.length;h+=1}}return[g,h,j]};b.jqplot.BarRenderer.prototype.setBarWidth=function(){var f;var c=0;var d=0;var h=this[this._primaryAxis];var m,g,k;var l=this.renderer.calcSeriesNumbers.call(this);c=l[0];d=l[1];var j=h.numberTicks;var e=(j-1)/2;if(h.name=="xaxis"||h.name=="x2axis"){if(this._stack){this.barWidth=(h._offsets.max-h._offsets.min)/c*d-this.barMargin}else{this.barWidth=((h._offsets.max-h._offsets.min)/e-this.barPadding*(d-1)-this.barMargin*2)/d}}else{if(this._stack){this.barWidth=(h._offsets.min-h._offsets.max)/c*d-this.barMargin}else{this.barWidth=((h._offsets.min-h._offsets.max)/e-this.barPadding*(d-1)-this.barMargin*2)/d}}return[c,d]};b.jqplot.BarRenderer.prototype.draw=function(s,x,e){var u;var o=(e!=undefined)?e:{};var k=(o.shadow!=undefined)?o.shadow:this.shadow;var A=(o.showLine!=undefined)?o.showLine:this.showLine;var t=(o.fill!=undefined)?o.fill:this.fill;var d=this.xaxis;var v=this.yaxis;var n=this._xaxis.series_u2p;var w=this._yaxis.series_u2p;var r,q,m,l,g;if(this.barWidth==null){this.renderer.setBarWidth.call(this)}var z=this.renderer.calcSeriesNumbers.call(this);m=z[0];l=z[1];g=z[2];if(this._stack){this._barNudge=0}else{this._barNudge=(-Math.abs(l/2-0.5)+g)*(this.barWidth+this.barPadding)}if(A){var j=new b.jqplot.ColorGenerator(this.negativeSeriesColors);var p=new b.jqplot.ColorGenerator(this.seriesColors);var y=j.get(this.index);if(!this.useNegativeColors){y=o.fillStyle}var h=o.fillStyle;if(this.barDirection=="vertical"){for(var u=0;u<x.length;u++){points=[];var f=x[u][0]+this._barNudge;var c;if(this._stack&&this._prevGridData.length){c=this._prevGridData[u][1]}else{if(this.fillToZero){c=this._yaxis.series_u2p(0)}else{if(this.waterfall&&u>0&&u<this.gridData.length-1){c=this.gridData[u-1][1]}else{c=s.canvas.height}}}if((this.fillToZero&&this._plotData[u][1]<0)||(this.waterfall&&this._data[u][1]<0)){if(this.varyBarColor){if(this.useNegativeColors){o.fillStyle=j.next()}else{o.fillStyle=p.next()}}else{o.fillStyle=y}}else{if(this.varyBarColor){o.fillStyle=p.next()}else{o.fillStyle=h}}points.push([f-this.barWidth/2,c]);points.push([f-this.barWidth/2,x[u][1]]);points.push([f+this.barWidth/2,x[u][1]]);points.push([f+this.barWidth/2,c]);if(k&&!this._stack){this.renderer.shadowRenderer.draw(s,points,o)}this.renderer.shapeRenderer.draw(s,points,o)}}else{if(this.barDirection=="horizontal"){for(var u=0;u<x.length;u++){points=[];var f=x[u][1]-this._barNudge;var B;if(this._stack&&this._prevGridData.length){B=this._prevGridData[u][0]}else{if(this.fillToZero){B=this._xaxis.series_u2p(0)}else{if(this.waterfall&&u>0&&u<this.gridData.length-1){B=this.gridData[u-1][1]}else{B=0}}}if((this.fillToZero&&this._plotData[u][1]<0)||(this.waterfall&&this._data[u][1]<0)){if(this.varyBarColor){if(this.useNegativeColors){o.fillStyle=j.next()}else{o.fillStyle=p.next()}}}else{if(this.varyBarColor){o.fillStyle=p.next()}else{o.fillStyle=h}}points.push([B,f+this.barWidth/2]);points.push([x[u][0],f+this.barWidth/2]);points.push([x[u][0],f-this.barWidth/2]);points.push([B,f-this.barWidth/2]);if(k&&!this._stack){this.renderer.shadowRenderer.draw(s,points,o)}this.renderer.shapeRenderer.draw(s,points,o)}}}}};b.jqplot.BarRenderer.prototype.drawShadow=function(p,u,e){var r;var m=(e!=undefined)?e:{};var h=(m.shadow!=undefined)?m.shadow:this.shadow;var w=(m.showLine!=undefined)?m.showLine:this.showLine;var q=(m.fill!=undefined)?m.fill:this.fill;var d=this.xaxis;var s=this.yaxis;var l=this._xaxis.series_u2p;var t=this._yaxis.series_u2p;var o,n,k,j,g;if(this._stack&&this.shadow){if(this.barWidth==null){this.renderer.setBarWidth.call(this)}var v=this.renderer.calcSeriesNumbers.call(this);k=v[0];j=v[1];g=v[2];if(this._stack){this._barNudge=0}else{this._barNudge=(-Math.abs(j/2-0.5)+g)*(this.barWidth+this.barPadding)}if(w){if(this.barDirection=="vertical"){for(var r=0;r<u.length;r++){points=[];var f=u[r][0]+this._barNudge;var c;if(this._stack&&this._prevGridData.length){c=this._prevGridData[r][1]}else{if(this.fillToZero){c=this._yaxis.series_u2p(0)}else{c=p.canvas.height}}points.push([f-this.barWidth/2,c]);points.push([f-this.barWidth/2,u[r][1]]);points.push([f+this.barWidth/2,u[r][1]]);points.push([f+this.barWidth/2,c]);this.renderer.shadowRenderer.draw(p,points,m)}}else{if(this.barDirection=="horizontal"){for(var r=0;r<u.length;r++){points=[];var f=u[r][1]-this._barNudge;var x;if(this._stack&&this._prevGridData.length){x=this._prevGridData[r][0]}else{x=0}points.push([x,f+this.barWidth/2]);points.push([u[r][0],f+this.barWidth/2]);points.push([u[r][0],f-this.barWidth/2]);points.push([x,f-this.barWidth/2]);this.renderer.shadowRenderer.draw(p,points,m)}}}}}}})(jQuery);
|
@@ -0,0 +1,200 @@
|
|
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.CanvasAxisLabelRenderer
|
21
|
+
* Renderer to draw axis labels with a canvas element to support advanced
|
22
|
+
* featrues such as rotated text. This renderer uses a separate rendering engine
|
23
|
+
* to draw the text on the canvas. Two modes of rendering the text are available.
|
24
|
+
* If the browser has native font support for canvas fonts (currently Mozila 3.5
|
25
|
+
* and Safari 4), you can enable text rendering with the canvas fillText method.
|
26
|
+
* You do so by setting the "enableFontSupport" option to true.
|
27
|
+
*
|
28
|
+
* Browsers lacking native font support will have the text drawn on the canvas
|
29
|
+
* using the Hershey font metrics. Even if the "enableFontSupport" option is true
|
30
|
+
* non-supporting browsers will still render with the Hershey font.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
$.jqplot.CanvasAxisLabelRenderer = function(options) {
|
34
|
+
// Group: Properties
|
35
|
+
|
36
|
+
// prop: angle
|
37
|
+
// angle of text, measured clockwise from x axis.
|
38
|
+
this.angle = 0;
|
39
|
+
// name of the axis associated with this tick
|
40
|
+
this.axis;
|
41
|
+
// prop: show
|
42
|
+
// wether or not to show the tick (mark and label).
|
43
|
+
this.show = true;
|
44
|
+
// prop: showLabel
|
45
|
+
// wether or not to show the label.
|
46
|
+
this.showLabel = true;
|
47
|
+
// prop: label
|
48
|
+
// label for the axis.
|
49
|
+
this.label = '';
|
50
|
+
// prop: fontFamily
|
51
|
+
// CSS spec for the font-family css attribute.
|
52
|
+
// Applies only to browsers supporting native font rendering in the
|
53
|
+
// canvas tag. Currently Mozilla 3.5 and Safari 4.
|
54
|
+
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
|
55
|
+
// prop: fontSize
|
56
|
+
// CSS spec for font size.
|
57
|
+
this.fontSize = '11pt';
|
58
|
+
// prop: fontWeight
|
59
|
+
// CSS spec for fontWeight: normal, bold, bolder, lighter or a number 100 - 900
|
60
|
+
this.fontWeight = 'normal';
|
61
|
+
// prop: fontStretch
|
62
|
+
// Multiplier to condense or expand font width.
|
63
|
+
// Applies only to browsers which don't support canvas native font rendering.
|
64
|
+
this.fontStretch = 1.0;
|
65
|
+
// prop: textColor
|
66
|
+
// css spec for the color attribute.
|
67
|
+
this.textColor = '#666666';
|
68
|
+
// prop: enableFontSupport
|
69
|
+
// true to turn on native canvas font support in Mozilla 3.5+ and Safari 4+.
|
70
|
+
// If true, label will be drawn with canvas tag native support for fonts.
|
71
|
+
// If false, label will be drawn with Hershey font metrics.
|
72
|
+
this.enableFontSupport = false;
|
73
|
+
// prop: pt2px
|
74
|
+
// Point to pixel scaling factor, used for computing height of bounding box
|
75
|
+
// around a label. The labels text renderer has a default setting of 1.4, which
|
76
|
+
// should be suitable for most fonts. Leave as null to use default. If tops of
|
77
|
+
// letters appear clipped, increase this. If bounding box seems too big, decrease.
|
78
|
+
// This is an issue only with the native font renderering capabilities of Mozilla
|
79
|
+
// 3.5 and Safari 4 since they do not provide a method to determine the font height.
|
80
|
+
this.pt2px = null;
|
81
|
+
|
82
|
+
this._elem;
|
83
|
+
this._ctx;
|
84
|
+
this._plotWidth;
|
85
|
+
this._plotHeight;
|
86
|
+
this._plotDimensions = {height:null, width:null};
|
87
|
+
|
88
|
+
$.extend(true, this, options);
|
89
|
+
|
90
|
+
if (options.angle == null && this.axis != 'xaxis' && this.axis != 'x2axis') {
|
91
|
+
this.angle = -90;
|
92
|
+
}
|
93
|
+
|
94
|
+
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
|
95
|
+
if (this.pt2px) {
|
96
|
+
ropts.pt2px = this.pt2px;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (this.enableFontSupport) {
|
100
|
+
if ($.browser.safari) {
|
101
|
+
var p = $.browser.version.split('.');
|
102
|
+
for (var i=0; i<p.length; i++) { p[i] = Number(p[i]); }
|
103
|
+
if (p[0] > 528 || (p[0] == 528 && p[1] >= 16)) {
|
104
|
+
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
else if ($.browser.mozilla) {
|
108
|
+
var p = $.browser.version.split(".");
|
109
|
+
if (p[0] > 1 || (p[0] == 1 && p[1] >= 9 && p[2] > 0) ) {
|
110
|
+
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
// TODO: test and enable this
|
118
|
+
// else if ($.browser.msie) {
|
119
|
+
// this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
|
120
|
+
// }
|
121
|
+
|
122
|
+
else {
|
123
|
+
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
else {
|
127
|
+
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
131
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.init = function(options) {
|
132
|
+
$.extend(true, this, options);
|
133
|
+
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
|
134
|
+
};
|
135
|
+
|
136
|
+
// return width along the x axis
|
137
|
+
// will check first to see if an element exists.
|
138
|
+
// if not, will return the computed text box width.
|
139
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.getWidth = function(ctx) {
|
140
|
+
if (this._elem) {
|
141
|
+
return this._elem.outerWidth(true);
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
var tr = this._textRenderer;
|
145
|
+
var l = tr.getWidth(ctx);
|
146
|
+
var h = tr.getHeight(ctx);
|
147
|
+
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
|
148
|
+
return w;
|
149
|
+
}
|
150
|
+
};
|
151
|
+
|
152
|
+
// return height along the y axis.
|
153
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.getHeight = function(ctx) {
|
154
|
+
if (this._elem) {
|
155
|
+
return this._elem.outerHeight(true);
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
var tr = this._textRenderer;
|
159
|
+
var l = tr.getWidth(ctx);
|
160
|
+
var h = tr.getHeight(ctx);
|
161
|
+
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
|
162
|
+
return w;
|
163
|
+
}
|
164
|
+
};
|
165
|
+
|
166
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad = function() {
|
167
|
+
var a = this.angle * Math.PI/180;
|
168
|
+
return a;
|
169
|
+
};
|
170
|
+
|
171
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx) {
|
172
|
+
// create a canvas here, but can't draw on it untill it is appended
|
173
|
+
// to dom for IE compatability.
|
174
|
+
var domelem = document.createElement('canvas');
|
175
|
+
this._textRenderer.setText(this.label, ctx);
|
176
|
+
var w = this.getWidth(ctx);
|
177
|
+
var h = this.getHeight(ctx);
|
178
|
+
domelem.width = w;
|
179
|
+
domelem.height = h;
|
180
|
+
domelem.style.width = w;
|
181
|
+
domelem.style.height = h;
|
182
|
+
// domelem.style.textAlign = 'center';
|
183
|
+
domelem.style.position = 'absolute';
|
184
|
+
this._domelem = domelem;
|
185
|
+
this._elem = $(domelem);
|
186
|
+
this._elem.addClass('jqplot-'+this.axis+'-label');
|
187
|
+
|
188
|
+
return this._elem;
|
189
|
+
};
|
190
|
+
|
191
|
+
$.jqplot.CanvasAxisLabelRenderer.prototype.pack = function() {
|
192
|
+
if ($.browser.msie) {
|
193
|
+
window.G_vmlCanvasManager.init_(document);
|
194
|
+
this._domelem = window.G_vmlCanvasManager.initElement(this._domelem);
|
195
|
+
}
|
196
|
+
var ctx = this._elem.get(0).getContext("2d");
|
197
|
+
this._textRenderer.draw(ctx, this.label);
|
198
|
+
};
|
199
|
+
|
200
|
+
})(jQuery);
|
data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.min.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* Although not required, the author would appreciate an email letting him
|
8
|
+
* know of any substantial use of jqPlot. You can reach the author at:
|
9
|
+
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
10
|
+
*
|
11
|
+
* If you are feeling kind and generous, consider supporting the project by
|
12
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
13
|
+
*/
|
14
|
+
(function(a){a.jqplot.CanvasAxisLabelRenderer=function(b){this.angle=0;this.axis;this.show=true;this.showLabel=true;this.label="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="11pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=false;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);if(b.angle==null&&this.axis!="xaxis"&&this.axis!="x2axis"){this.angle=-90}var e={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){e.pt2px=this.pt2px}if(this.enableFontSupport){if(a.browser.safari){var d=a.browser.version.split(".");for(var c=0;c<d.length;c++){d[c]=Number(d[c])}if(d[0]>528||(d[0]==528&&d[1]>=16)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}}else{if(a.browser.mozilla){var d=a.browser.version.split(".");if(d[0]>1||(d[0]==1&&d[1]>=9&&d[2]>0)){this._textRenderer=new a.jqplot.CanvasFontRenderer(e)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(e)}};a.jqplot.CanvasAxisLabelRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisLabelRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisLabelRenderer.prototype.draw=function(c){var e=document.createElement("canvas");this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.position="absolute";this._domelem=e;this._elem=a(e);this._elem.addClass("jqplot-"+this.axis+"-label");return this._elem};a.jqplot.CanvasAxisLabelRenderer.prototype.pack=function(){if(a.browser.msie){window.G_vmlCanvasManager.init_(document);this._domelem=window.G_vmlCanvasManager.initElement(this._domelem)}var b=this._elem.get(0).getContext("2d");this._textRenderer.draw(b,this.label)}})(jQuery);
|