~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.13.0/series-base/series-base-debug.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.13.0 (build 508226d)
 
3
Copyright 2013 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
 
 
8
YUI.add('series-base', function (Y, NAME) {
 
9
 
 
10
/**
 
11
 * Provides functionality for creating a chart series.
 
12
 *
 
13
 * @module charts
 
14
 * @submodule series-base
 
15
 */
 
16
 
 
17
/**
 
18
 * An abstract class for creating series instances.
 
19
 * SeriesBase is used by the following classes:
 
20
 * <ul>
 
21
 *      <li>{{#crossLink "CartesianSeries"}}{{/crossLink}}</li>
 
22
 *      <li>{{#crossLink "PieSeries"}}{{/crossLink}}</li>
 
23
 *  </ul>
 
24
 *
 
25
 * @class SeriesBase
 
26
 * @extends Base
 
27
 * @uses Renderer
 
28
 * @constructor
 
29
 * @param {Object} config (optional) Configuration parameters.
 
30
 * @submodule series-base
 
31
 */
 
32
Y.SeriesBase = Y.Base.create("seriesBase", Y.Base, [Y.Renderer], {
 
33
    /**
 
34
     * @method render
 
35
     * @private
 
36
     */
 
37
    render: function()
 
38
    {
 
39
        this._setCanvas();
 
40
        this.addListeners();
 
41
        this.validate();
 
42
    },
 
43
 
 
44
    /**
 
45
     * Creates a `Graphic` instance.
 
46
     *
 
47
     * @method _setCanvas
 
48
     * @protected
 
49
     */
 
50
    _setCanvas: function()
 
51
    {
 
52
        var graph = this.get("graph"),
 
53
            graphic = graph.get("graphic");
 
54
        this.set("graphic", graphic);
 
55
    },
 
56
 
 
57
    /**
 
58
     * Returns a reference to the parent container to which all chart elements are contained.
 
59
     * When the series is bound to a `Chart` instance, the `Chart` instance is the reference.
 
60
     * If nothing is set as the `chart` attribute, the `_getChart` method will return a reference
 
61
     * to the `graphic` attribute.
 
62
     *
 
63
     * @method _getChart
 
64
     * @return {Object}
 
65
     * @private
 
66
     */
 
67
    _getChart:function() {
 
68
        var chart,
 
69
            graph = this.get("graph");
 
70
        if(graph)
 
71
        {
 
72
            chart = graph.get("chart");
 
73
        }
 
74
        if(!chart)
 
75
        {
 
76
            chart = this.get("graphic");
 
77
        }
 
78
        return chart;
 
79
    },
 
80
 
 
81
    /**
 
82
     * Returns the sum of all values for the series.
 
83
     *
 
84
     * @method getTotalValues
 
85
     * @return Number
 
86
     */
 
87
    getTotalValues: function()
 
88
    {
 
89
        var valueCoord = this.get("direction") === "vertical" ? "x" : "y",
 
90
            total = this.get(valueCoord + "Axis").getTotalByKey(this.get(valueCoord + "Key"));
 
91
        return total;
 
92
    },
 
93
 
 
94
    /**
 
95
     * Gets the default value for the `styles` attribute. Overrides
 
96
     * base implementation.
 
97
     *
 
98
     * @method _getDefaultStyles
 
99
     * @return Object
 
100
     * @protected
 
101
     */
 
102
    _getDefaultStyles: function()
 
103
    {
 
104
        return {padding:{
 
105
                top: 0,
 
106
                left: 0,
 
107
                right: 0,
 
108
                bottom: 0
 
109
            }};
 
110
    },
 
111
 
 
112
    /**
 
113
     * Shows/hides contents of the series.
 
114
     *
 
115
     * @method _handleVisibleChange
 
116
     * @param {Object} e Event object.
 
117
     * @protected
 
118
     */
 
119
    _handleVisibleChange: function()
 
120
    {
 
121
        this._toggleVisible(this.get("visible"));
 
122
    },
 
123
 
 
124
    /**
 
125
     * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances.
 
126
     *
 
127
     * @method destructor
 
128
     * @protected
 
129
     */
 
130
    destructor: function()
 
131
    {
 
132
        var marker,
 
133
            markers = this.get("markers");
 
134
        if(this.get("rendered"))
 
135
        {
 
136
            this._stylesChangeHandle.detach();
 
137
            this._widthChangeHandle.detach();
 
138
            this._heightChangeHandle.detach();
 
139
            this._visibleChangeHandle.detach();
 
140
        }
 
141
        while(markers && markers.length > 0)
 
142
        {
 
143
            marker = markers.shift();
 
144
            if(marker && marker instanceof Y.Shape)
 
145
            {
 
146
                marker.destroy();
 
147
            }
 
148
        }
 
149
        if(this._path)
 
150
        {
 
151
            this._path.destroy();
 
152
            this._path = null;
 
153
        }
 
154
        if(this._lineGraphic)
 
155
        {
 
156
            this._lineGraphic.destroy();
 
157
            this._lineGraphic = null;
 
158
        }
 
159
        if(this._groupMarker)
 
160
        {
 
161
            this._groupMarker.destroy();
 
162
            this._groupMarker = null;
 
163
        }
 
164
    },
 
165
 
 
166
    /**
 
167
     * Collection of default colors used for lines in a series when not specified by user.
 
168
     *
 
169
     * @property _defaultLineColors
 
170
     * @type Array
 
171
     * @protected
 
172
     */
 
173
    _defaultLineColors:[
 
174
        "#426ab3",
 
175
        "#d09b2c",
 
176
        "#000000",
 
177
        "#b82837",
 
178
        "#b384b5",
 
179
        "#ff7200",
 
180
        "#779de3",
 
181
        "#cbc8ba",
 
182
        "#7ed7a6",
 
183
        "#007a6c"
 
184
    ],
 
185
 
 
186
    /**
 
187
     * Collection of default colors used for marker fills in a series when not specified by user.
 
188
     *
 
189
     * @property _defaultFillColors
 
190
     * @type Array
 
191
     * @protected
 
192
     */
 
193
    _defaultFillColors:[
 
194
        "#6084d0",
 
195
        "#eeb647",
 
196
        "#6c6b5f",
 
197
        "#d6484f",
 
198
        "#ce9ed1",
 
199
        "#ff9f3b",
 
200
        "#93b7ff",
 
201
        "#e0ddd0",
 
202
        "#94ecba",
 
203
        "#309687"
 
204
    ],
 
205
 
 
206
    /**
 
207
     * Collection of default colors used for marker borders in a series when not specified by user.
 
208
     *
 
209
     * @property _defaultBorderColors
 
210
     * @type Array
 
211
     * @protected
 
212
     */
 
213
    _defaultBorderColors:[
 
214
        "#205096",
 
215
        "#b38206",
 
216
        "#000000",
 
217
        "#94001e",
 
218
        "#9d6fa0",
 
219
        "#e55b00",
 
220
        "#5e85c9",
 
221
        "#adab9e",
 
222
        "#6ac291",
 
223
        "#006457"
 
224
    ],
 
225
 
 
226
    /**
 
227
     * Collection of default colors used for area fills, histogram fills and pie fills in a series when not specified by user.
 
228
     *
 
229
     * @property _defaultSliceColors
 
230
     * @type Array
 
231
     * @protected
 
232
     */
 
233
    _defaultSliceColors: [
 
234
        "#66007f",
 
235
        "#a86f41",
 
236
        "#295454",
 
237
        "#996ab2",
 
238
        "#e8cdb7",
 
239
        "#90bdbd",
 
240
        "#000000",
 
241
        "#c3b8ca",
 
242
        "#968373",
 
243
        "#678585"
 
244
    ],
 
245
 
 
246
    /**
 
247
     * Parses a color based on a series order and type.
 
248
     *
 
249
     * @method _getDefaultColor
 
250
     * @param {Number} index Index indicating the series order.
 
251
     * @param {String} type Indicates which type of object needs the color.
 
252
     * @return String
 
253
     * @protected
 
254
     */
 
255
    _getDefaultColor: function(index, type)
 
256
    {
 
257
        var colors = {
 
258
                line: this._defaultLineColors,
 
259
                fill: this._defaultFillColors,
 
260
                border: this._defaultBorderColors,
 
261
                slice: this._defaultSliceColors
 
262
            },
 
263
            col = colors[type] || colors.fill,
 
264
            l = col.length;
 
265
        index = index || 0;
 
266
        if(index >= l)
 
267
        {
 
268
            index = index % l;
 
269
        }
 
270
        type = type || "fill";
 
271
        return colors[type][index];
 
272
    }
 
273
}, {
 
274
    ATTRS: {
 
275
        /*
 
276
         * Returns the width of the parent graph
 
277
         *
 
278
         * @attribute width
 
279
         * @type Number
 
280
         */
 
281
        width: {
 
282
            readOnly: true,
 
283
 
 
284
            getter: function()
 
285
            {
 
286
                return this.get("graphic").get("width");
 
287
            }
 
288
        },
 
289
 
 
290
        /**
 
291
         * Returns the height of the parent graph
 
292
         *
 
293
         * @attribute height
 
294
         * @type Number
 
295
         */
 
296
        height: {
 
297
            readOnly: true,
 
298
 
 
299
            getter: function()
 
300
            {
 
301
                return this.get("graphic").get("height");
 
302
            }
 
303
        },
 
304
 
 
305
        /**
 
306
         * The graphic in which drawings will be rendered.
 
307
         *
 
308
         * @attribute graphic
 
309
         * @type Graphic
 
310
         */
 
311
        graphic: {
 
312
            lazyAdd: false,
 
313
 
 
314
            setter: function(val) {
 
315
                //woraround for Attribute order of operations bug
 
316
                if(!this.get("rendered")) {
 
317
                    this.set("rendered", true);
 
318
                }
 
319
                return val;
 
320
            }
 
321
        },
 
322
 
 
323
        /**
 
324
         * Reference to the `Chart` application. If no `Chart` application is present,
 
325
         * a reference to the `Graphic` instance that the series is drawn into will be returned.
 
326
         *
 
327
         * @attribute chart
 
328
         * @type ChartBase
 
329
         */
 
330
        chart: {
 
331
            getter: function()
 
332
            {
 
333
                var chart,
 
334
                    graph = this.get("graph");
 
335
                if(graph)
 
336
                {
 
337
                    chart = graph.get("chart");
 
338
                }
 
339
                return chart;
 
340
            }
 
341
        },
 
342
 
 
343
        /**
 
344
         * Reference to the `Graph` in which the series is drawn into.
 
345
         *
 
346
         * @attribute graph
 
347
         * @type Graph
 
348
         */
 
349
        graph: {},
 
350
 
 
351
        /**
 
352
         * Indicates whether the Series has been through its initial set up.
 
353
         *
 
354
         * @attribute rendered
 
355
         * @type Boolean
 
356
         */
 
357
        rendered: {
 
358
            value: false
 
359
        },
 
360
 
 
361
        /**
 
362
         * Indicates whether to show the series
 
363
         *
 
364
         * @attribute visible
 
365
         * @type Boolean
 
366
         * @default true
 
367
         */
 
368
        visible: {
 
369
            value: true
 
370
        },
 
371
 
 
372
        /**
 
373
         * Indicates whether or not markers for a series will be grouped and rendered in a single complex shape instance.
 
374
         *
 
375
         * @attribute groupMarkers
 
376
         * @type Boolean
 
377
         */
 
378
        groupMarkers: {
 
379
            getter: function()
 
380
            {
 
381
                var graph,
 
382
                    groupMarkers = this._groupMarkers;
 
383
                if(!groupMarkers) {
 
384
                    graph = this.get("graph");
 
385
                    if(graph)
 
386
                    {
 
387
                        groupMarkers = graph.get("groupMarkers");
 
388
                    }
 
389
                }
 
390
                return groupMarkers;
 
391
            },
 
392
 
 
393
            setter: function(val)
 
394
            {
 
395
                this._groupMarkers = val;
 
396
                return val;
 
397
            }
 
398
        }
 
399
    }
 
400
});
 
401
 
 
402
 
 
403
}, '3.13.0', {"requires": ["graphics", "axis-base"]});