Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
/**
2
 * jqPlot
3
 * Pure JavaScript plotting plugin using jQuery
4
 *
5
 * Version: 1.0.8
6
 * Revision: 1250
7
 *
8
 * Copyright (c) 2009-2013 Chris Leonello
9
 * jqPlot is currently available for use in all personal or commercial projects
10
 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
11
 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
12
 * choose the license that best suits your project and use it accordingly.
13
 *
14
 * Although not required, the author would appreciate an email letting him
15
 * know of any substantial use of jqPlot.  You can reach the author at:
16
 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
17
 *
18
 * If you are feeling kind and generous, consider supporting the project by
19
 * making a donation at: http://www.jqplot.com/donate.php .
20
 *
21
 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
22
 *
23
 *     version 2007.04.27
24
 *     author Ash Searle
25
 *     http://hexmen.com/blog/2007/03/printf-sprintf/
26
 *     http://hexmen.com/js/sprintf.js
27
 *     The author (Ash Searle) has placed this code in the public domain:
28
 *     "This code is unrestricted: you are free to use it however you like."
29
 *
30
 */
31
(function($) {
32
    // Class: $.jqplot.BezierCurveRenderer.js
33
    // Renderer which draws lines as stacked bezier curves.
34
    // Data for the line will not be specified as an array of
35
    // [x, y] data point values, but as a an array of [start piont, bezier curve]
36
    // So, the line is specified as: [[xstart, ystart], [cp1x, cp1y, cp2x, cp2y, xend, yend]].
37
    $.jqplot.BezierCurveRenderer = function(){
38
        $.jqplot.LineRenderer.call(this);
39
    };
40
 
41
    $.jqplot.BezierCurveRenderer.prototype = new $.jqplot.LineRenderer();
42
    $.jqplot.BezierCurveRenderer.prototype.constructor = $.jqplot.BezierCurveRenderer;
43
 
44
 
45
    // Method: setGridData
46
    // converts the user data values to grid coordinates and stores them
47
    // in the gridData array.
48
    // Called with scope of a series.
49
    $.jqplot.BezierCurveRenderer.prototype.setGridData = function(plot) {
50
        // recalculate the grid data
51
        var xp = this._xaxis.series_u2p;
52
        var yp = this._yaxis.series_u2p;
53
        // this._plotData should be same as this.data
54
        var data = this.data;
55
        this.gridData = [];
56
        this._prevGridData = [];
57
        // if seriesIndex = 0, fill to x axis.
58
        // if seriesIndex > 0, fill to previous series data.
59
        var idx = this.index;
60
        if (data.length == 2) {
61
            if (idx == 0) {
62
                this.gridData = [
63
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
64
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
65
                        xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
66
                        xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
67
                    [xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
68
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
69
                ];
70
            }
71
            else {
72
                var psd = plot.series[idx-1].data;
73
                this.gridData = [
74
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
75
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
76
                        xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
77
                        xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
78
                    [xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
79
                    [xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
80
                        xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
81
                        xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
82
                ];
83
            }
84
        }
85
        else {
86
            if (idx == 0) {
87
                this.gridData = [
88
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
89
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
90
                        xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
91
                        xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
92
                    [xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
93
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
94
                ];
95
            }
96
            else {
97
                var psd = plot.series[idx-1].data;
98
                this.gridData = [
99
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
100
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
101
                        xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
102
                        xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
103
                    [xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
104
                    [xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
105
                        xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
106
                        xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
107
                ];
108
            }
109
        }
110
    };
111
 
112
    // Method: makeGridData
113
    // converts any arbitrary data values to grid coordinates and
114
    // returns them.  This method exists so that plugins can use a series'
115
    // linerenderer to generate grid data points without overwriting the
116
    // grid data associated with that series.
117
    // Called with scope of a series.
118
    $.jqplot.BezierCurveRenderer.prototype.makeGridData = function(data, plot) {
119
        // recalculate the grid data
120
        var xp = this._xaxis.series_u2p;
121
        var yp = this._yaxis.series_u2p;
122
        var gd = [];
123
        var pgd = [];
124
        // if seriesIndex = 0, fill to x axis.
125
        // if seriesIndex > 0, fill to previous series data.
126
        var idx = this.index;
127
        if (data.length == 2) {
128
            if (idx == 0) {
129
                gd = [
130
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
131
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
132
                        xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
133
                        xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
134
                    [xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, this._yaxis.min)],
135
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
136
                ];
137
            }
138
            else {
139
                var psd = plot.series[idx-1].data;
140
                gd = [
141
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
142
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
143
                        xp.call(this._xaxis, data[1][2]), yp.call(this._yaxis, data[1][3]),
144
                        xp.call(this._xaxis, data[1][4]), yp.call(this._yaxis, data[1][5])],
145
                    [xp.call(this._xaxis, psd[1][4]), yp.call(this._yaxis, psd[1][5])],
146
                    [xp.call(this._xaxis, psd[1][2]), yp.call(this._yaxis, psd[1][3]),
147
                        xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
148
                        xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
149
                ];
150
            }
151
        }
152
        else {
153
            if (idx == 0) {
154
                gd = [
155
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
156
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
157
                        xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
158
                        xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
159
                    [xp.call(this._xaxis, data[3][1]), yp.call(this._yaxis, this._yaxis.min)],
160
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, this._yaxis.min)]
161
                ];
162
            }
163
            else {
164
                var psd = plot.series[idx-1].data;
165
                gd = [
166
                    [xp.call(this._xaxis, data[0][0]), yp.call(this._yaxis, data[0][1])],
167
                    [xp.call(this._xaxis, data[1][0]), yp.call(this._yaxis, data[1][1]),
168
                        xp.call(this._xaxis, data[2][0]), yp.call(this._yaxis, data[2][1]),
169
                        xp.call(this._xaxis, data[3][0]), yp.call(this._yaxis, data[3][1])],
170
                    [xp.call(this._xaxis, psd[3][0]), yp.call(this._yaxis, psd[3][1])],
171
                    [xp.call(this._xaxis, psd[2][0]), yp.call(this._yaxis, psd[2][1]),
172
                        xp.call(this._xaxis, psd[1][0]), yp.call(this._yaxis, psd[1][1]),
173
                        xp.call(this._xaxis, psd[0][0]), yp.call(this._yaxis, psd[0][1])]
174
                ];
175
            }
176
        }
177
        return gd;
178
    };
179
 
180
 
181
    // called within scope of series.
182
    $.jqplot.BezierCurveRenderer.prototype.draw = function(ctx, gd, options) {
183
        var i;
184
        ctx.save();
185
        if (gd.length) {
186
            if (this.showLine) {
187
                ctx.save();
188
                var opts = (options != null) ? options : {};
189
                ctx.fillStyle = opts.fillStyle || this.color;
190
                ctx.beginPath();
191
                ctx.moveTo(gd[0][0], gd[0][1]);
192
                ctx.bezierCurveTo(gd[1][0], gd[1][1], gd[1][2], gd[1][3], gd[1][4], gd[1][5]);
193
                ctx.lineTo(gd[2][0], gd[2][1]);
194
                if (gd[3].length == 2) {
195
                    ctx.lineTo(gd[3][0], gd[3][1]);
196
                }
197
                else {
198
                    ctx.bezierCurveTo(gd[3][0], gd[3][1], gd[3][2], gd[3][3], gd[3][4], gd[3][5]);
199
                }
200
                ctx.closePath();
201
                ctx.fill();
202
                ctx.restore();
203
            }
204
        }
205
 
206
        ctx.restore();
207
    };
208
 
209
    $.jqplot.BezierCurveRenderer.prototype.drawShadow = function(ctx, gd, options) {
210
        // This is a no-op, shadows drawn with lines.
211
    };
212
 
213
    $.jqplot.BezierAxisRenderer = function() {
214
        $.jqplot.LinearAxisRenderer.call(this);
215
    };
216
 
217
    $.jqplot.BezierAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
218
    $.jqplot.BezierAxisRenderer.prototype.constructor = $.jqplot.BezierAxisRenderer;
219
 
220
 
221
    // Axes on a plot with Bezier Curves
222
    $.jqplot.BezierAxisRenderer.prototype.init = function(options){
223
        $.extend(true, this, options);
224
        var db = this._dataBounds;
225
        // Go through all the series attached to this axis and find
226
        // the min/max bounds for this axis.
227
        for (var i=0; i<this._series.length; i++) {
228
            var s = this._series[i];
229
            var d = s.data;
230
            if (d.length == 4) {
231
                for (var j=0; j<d.length; j++) {
232
                    if (this.name == 'xaxis' || this.name == 'x2axis') {
233
                        if (d[j][0] < db.min || db.min == null) {
234
                            db.min = d[j][0];
235
                        }
236
                        if (d[j][0] > db.max || db.max == null) {
237
                            db.max = d[j][0];
238
                        }
239
                    }
240
                    else {
241
                        if (d[j][1] < db.min || db.min == null) {
242
                            db.min = d[j][1];
243
                        }
244
                        if (d[j][1] > db.max || db.max == null) {
245
                            db.max = d[j][1];
246
                        }
247
                    }
248
                }
249
            }
250
            else {
251
                if (this.name == 'xaxis' || this.name == 'x2axis') {
252
                    if (d[0][0] < db.min || db.min == null) {
253
                        db.min = d[0][0];
254
                    }
255
                    if (d[0][0] > db.max || db.max == null) {
256
                        db.max = d[0][0];
257
                    }
258
                    for (var j=0; j<5; j+=2) {
259
                        if (d[1][j] < db.min || db.min == null) {
260
                            db.min = d[1][j];
261
                        }
262
                        if (d[1][j] > db.max || db.max == null) {
263
                            db.max = d[1][j];
264
                        }
265
                    }
266
                }
267
                else {
268
                    if (d[0][1] < db.min || db.min == null) {
269
                        db.min = d[0][1];
270
                    }
271
                    if (d[0][1] > db.max || db.max == null) {
272
                        db.max = d[0][1];
273
                    }
274
                    for (var j=1; j<6; j+=2) {
275
                        if (d[1][j] < db.min || db.min == null) {
276
                            db.min = d[1][j];
277
                        }
278
                        if (d[1][j] > db.max || db.max == null) {
279
                            db.max = d[1][j];
280
                        }
281
                    }
282
                }
283
            }
284
        }
285
    };
286
 
287
    // setup default renderers for axes and legend so user doesn't have to
288
    // called with scope of plot
289
    function preInit(target, data, options) {
290
        options = options || {};
291
        options.axesDefaults = $.extend(true, {pad:0}, options.axesDefaults);
292
        options.seriesDefaults = options.seriesDefaults || {};
293
        options.legend = $.extend(true, {placement:'outside'}, options.legend);
294
        // only set these if there is a pie series
295
        var setopts = false;
296
        if (options.seriesDefaults.renderer == $.jqplot.BezierCurveRenderer) {
297
            setopts = true;
298
        }
299
        else if (options.series) {
300
            for (var i=0; i < options.series.length; i++) {
301
                if (options.series[i].renderer == $.jqplot.BezierCurveRenderer) {
302
                    setopts = true;
303
                }
304
            }
305
        }
306
 
307
        if (setopts) {
308
            options.axesDefaults.renderer = $.jqplot.BezierAxisRenderer;
309
        }
310
    }
311
 
312
    $.jqplot.preInitHooks.push(preInit);
313
 
314
})(jQuery);