Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('axis-category', function (Y, NAME) {
2
 
3
/**
4
 * Provides functionality for drawing a category axis for use with a chart.
5
 *
6
 * @module charts
7
 * @submodule axis-category
8
 */
9
var Y_Lang = Y.Lang;
10
/**
11
 * CategoryAxis draws a category axis for a chart.
12
 *
13
 * @class CategoryAxis
14
 * @constructor
15
 * @extends Axis
16
 * @uses CategoryImpl
17
 * @param {Object} config (optional) Configuration parameters.
18
 * @submodule axis-category
19
 */
20
Y.CategoryAxis = Y.Base.create("categoryAxis", Y.Axis, [Y.CategoryImpl], {
21
    /**
22
     * Returns a string corresponding to the first label on an
23
     * axis.
24
     *
25
     * @method getMinimumValue
26
     * @return String
27
     */
28
    getMinimumValue: function()
29
    {
30
        var data = this.get("data"),
31
            label = data[0];
32
        return label;
33
    },
34
 
35
    /**
36
     * Returns a string corresponding to the last label on an
37
     * axis.
38
     *
39
     * @method getMaximumValue
40
     * @return String
41
     */
42
    getMaximumValue: function()
43
    {
44
        var data = this.get("data"),
45
            len = data.length - 1,
46
            label = data[len];
47
        return label;
48
    },
49
 
50
    /**
51
     * Calculates and returns a value based on the number of labels and the index of
52
     * the current label.
53
     *
54
     * @method _getLabelByIndex
55
     * @param {Number} i Index of the label.
56
     * @return String
57
     * @private
58
     */
59
    _getLabelByIndex: function(i)
60
    {
61
        var label,
62
            data = this.get("data");
63
        label = data[i];
64
        return label;
65
    },
66
 
67
    /**
68
     * Returns an object literal containing and array of label values and an array of points.
69
     *
70
     * @method _getLabelData
71
     * @param {Object} startPoint An object containing x and y values.
72
     * @param {Number} edgeOffset Distance to offset coordinates.
73
     * @param {Number} layoutLength Distance that the axis spans.
74
     * @param {Number} count Number of labels.
75
     * @param {String} direction Indicates whether the axis is horizontal or vertical.
76
     * @param {Array} Array containing values for axis labels.
77
     * @return Array
78
     * @private
79
     */
80
    _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
81
    {
82
        var labelValue,
83
            i,
84
            points = [],
85
            values = [],
86
            point,
87
            labelIndex,
88
            data = this.get("data"),
89
            offset = edgeOffset;
90
        dataValues = dataValues || data;
91
        for(i = 0; i < count; i = i + 1)
92
        {
93
            labelValue = dataValues[i];
94
            labelIndex = Y.Array.indexOf(data, labelValue);
95
            if(Y_Lang.isNumber(labelIndex) && labelIndex > -1)
96
            {
97
                point = {};
98
                point[staticCoord] = constantVal;
99
                point[dynamicCoord] = this._getCoordFromValue(
100
                    min,
101
                    max,
102
                    layoutLength,
103
                    labelIndex,
104
                    offset
105
                );
106
                points.push(point);
107
                values.push(labelValue);
108
            }
109
        }
110
        return {
111
            points: points,
112
            values: values
113
        };
114
    }
115
});
116
 
117
 
118
 
119
}, '3.18.1', {"requires": ["axis", "axis-category-base"]});