Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
875 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
    /**
33
     * Class: $.jqplot.ciParser
34
     * Data Renderer function which converts a custom JSON data object into jqPlot data format.
35
     * Set this as a callable on the jqplot dataRenderer plot option:
36
     *
37
     * > plot = $.jqplot('mychart', [data], { dataRenderer: $.jqplot.ciParser, ... });
38
     *
39
     * Where data is an object in JSON format or a JSON encoded string conforming to the
40
     * City Index API spec.
41
     *
42
     * Note that calling the renderer function is handled internally by jqPlot.  The
43
     * user does not have to call the function.  The parameters described below will
44
     * automatically be passed to the ciParser function.
45
     *
46
     * Parameters:
47
     * data - JSON encoded string or object.
48
     * plot - reference to jqPlot Plot object.
49
     *
50
     * Returns:
51
     * data array in jqPlot format.
52
     *
53
     */
54
    $.jqplot.ciParser = function (data, plot) {
55
        var ret = [],
56
            line,
57
            temp,
58
            i, j, k, kk;
59
 
60
         if (typeof(data) == "string") {
61
             data =  $.jqplot.JSON.parse(data, handleStrings);
62
         }
63
 
64
         else if (typeof(data) == "object") {
65
             for (k in data) {
66
                 for (i=0; i<data[k].length; i++) {
67
                     for (kk in data[k][i]) {
68
                         data[k][i][kk] = handleStrings(kk, data[k][i][kk]);
69
                     }
70
                 }
71
             }
72
         }
73
 
74
         else {
75
             return null;
76
         }
77
 
78
         // function handleStrings
79
         // Checks any JSON encoded strings to see if they are
80
         // encoded dates.  If so, pull out the timestamp.
81
         // Expects dates to be represented by js timestamps.
82
 
83
         function handleStrings(key, value) {
84
            var a;
85
            if (value != null) {
86
                if (value.toString().indexOf('Date') >= 0) {
87
                    //here we will try to extract the ticks from the Date string in the "value" fields of JSON returned data
88
                    a = /^\/Date\((-?[0-9]+)\)\/$/.exec(value);
89
                    if (a) {
90
                        return parseInt(a[1], 10);
91
                    }
92
                }
93
                return value;
94
            }
95
         }
96
 
97
        for (var prop in data) {
98
            line = [];
99
            temp = data[prop];
100
            switch (prop) {
101
                case "PriceTicks":
102
                    for (i=0; i<temp.length; i++) {
103
                        line.push([temp[i]['TickDate'], temp[i]['Price']]);
104
                    }
105
                    break;
106
                case "PriceBars":
107
                    for (i=0; i<temp.length; i++) {
108
                        line.push([temp[i]['BarDate'], temp[i]['Open'], temp[i]['High'], temp[i]['Low'], temp[i]['Close']]);
109
                    }
110
                    break;
111
            }
112
            ret.push(line);
113
        }
114
        return ret;
115
    };
116
})(jQuery);