Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('series-range', function (Y, NAME) {
2
 
3
/**
4
 * Provides functionality for creating a range series.
5
 *
6
 * @module charts
7
 * @submodule series-range
8
 */
9
 
10
/**
11
 * An abstract class for creating range series instances.
12
 * RangeSeries is used by the following classes:
13
 * <ul>
14
 *      <li>{{#crossLink "CandlestickSeries"}}{{/crossLink}}</li>
15
 *      <li>{{#crossLink "OHLCSeries"}}{{/crossLink}}</li>
16
 *  </ul>
17
 *
18
 * @class RangeSeries
19
 * @extends CartesianSeries
20
 * @constructor
21
 * @param {Object} config (optional) Configuration parameters.
22
 * @submodule series-range
23
 */
24
function RangeSeries()
25
{
26
    RangeSeries.superclass.constructor.apply(this, arguments);
27
}
28
 
29
RangeSeries.NAME = "rangeSeries";
30
 
31
RangeSeries.ATTRS = {
32
    /**
33
     * Read-only attribute indicating the type of series.
34
     *
35
     * @attribute type
36
     * @type String
37
     * @default range
38
     */
39
    type: {
40
        value: "range"
41
    },
42
 
43
    /**
44
     * Values to be used for open, high, low and close keys.
45
     *
46
     * @attribute ohlc
47
     * @type Object
48
     */
49
    ohlckeys: {
50
        valueFn: function() {
51
            return {
52
                open: "open",
53
                high: "high",
54
                low: "low",
55
                close: "close"
56
            };
57
        }
58
    }
59
};
60
 
61
Y.extend(RangeSeries, Y.CartesianSeries, {
62
    /**
63
     * Returns the width for each marker base on the width of the series
64
     * and the length of the dataProvider.
65
     *
66
     * @method calculateMarkerWidth
67
     * @param {Number} width The width, in pixels of the series.
68
     * @param {Number} count The length of the datProvider.
69
     * @return Number
70
     * @private
71
     */
72
    _calculateMarkerWidth: function(width, count, spacing)
73
    {
74
        var val = 0;
75
        while(val < 3 && spacing > -1)
76
        {
77
            spacing = spacing - 1;
78
            val = Math.round(width/count - spacing);
79
            if(val % 2 === 0) {
80
                val = val - 1;
81
            }
82
        }
83
        return Math.max(1, val);
84
    },
85
 
86
    /**
87
     * Draws the series.
88
     *
89
     * @method drawSeries
90
     * @protected
91
     */
92
    drawSeries: function()
93
    {
94
        var xcoords = this.get("xcoords"),
95
            ycoords = this.get("ycoords"),
96
            styles = this.get("styles"),
97
            padding = styles.padding,
98
            len = xcoords.length,
99
            dataWidth = this.get("width") - (padding.left + padding.right),
100
            keys = this.get("ohlckeys"),
101
            opencoords = ycoords[keys.open],
102
            highcoords = ycoords[keys.high],
103
            lowcoords = ycoords[keys.low],
104
            closecoords = ycoords[keys.close],
105
            width = this._calculateMarkerWidth(dataWidth, len, styles.spacing),
106
            halfwidth = width/2;
107
        this._drawMarkers(xcoords, opencoords, highcoords, lowcoords, closecoords, len, width, halfwidth, styles);
108
    },
109
 
110
    /**
111
     * Gets the default value for the `styles` attribute. Overrides
112
     * base implementation.
113
     *
114
     * @method _getDefaultStyles
115
     * @return Object
116
     * @private
117
     */
118
    _getDefaultStyles: function()
119
    {
120
        var styles = {
121
            spacing: 3
122
        };
123
        return this._mergeStyles(styles, RangeSeries.superclass._getDefaultStyles());
124
    }
125
});
126
 
127
Y.RangeSeries = RangeSeries;
128
 
129
 
130
 
131
 
132
}, '3.18.1', {"requires": ["series-cartesian"]});