~ubuntu-branches/ubuntu/quantal/maas/quantal-proposed

« back to all changes in this revision

Viewing changes to src/maasserver/static/js/nodes_chart.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
var module = Y.namespace('maas.nodes_chart');
14
14
 
15
 
var NodesChartWidget = function() {
 
15
var NodesChartWidget;
 
16
 
 
17
NodesChartWidget = function() {
16
18
    NodesChartWidget.superclass.constructor.apply(this, arguments);
17
19
};
18
20
 
19
21
NodesChartWidget.NAME = 'nodes-chart-widget';
20
22
 
21
 
 
22
 
NodesChartWidget._outer_paths;
23
 
NodesChartWidget._offline_circle;
24
 
NodesChartWidget._added_circle;
25
 
 
26
23
var TRANSITION_TIME = 1000,
27
24
    TRANSITION_EASING = 'easeInOut',
28
25
    OUTER_COLOURS = ['#19b6ee', '#38b44a', '#0d80aa'],
34
31
 
35
32
NodesChartWidget.ATTRS = {
36
33
   /**
37
 
    * The node id to display the chart.
 
34
    * The node or node id to display the chart.
38
35
    *
39
36
    * @attribute node_id
40
 
    * @type string
 
37
    * @type Node or string
41
38
    */
42
39
    node_id: {
43
40
        value: ''
184
181
                }
185
182
            ];
186
183
 
187
 
        var outer_total = 0;
188
 
        for (var n in outer_nodes) {
189
 
            outer_total += outer_nodes[n].nodes;
190
 
        }
 
184
        var outer_total = Y.Array.reduce(
 
185
            outer_nodes, 0, function(total, node) {
 
186
                return total + node.nodes; });
191
187
        var inner_total = offline_nodes + added_nodes;
192
188
        var total_nodes = outer_total + inner_total;
193
189
        if (outer_total > 0) {
197
193
                this._outer_paths = [];
198
194
            }
199
195
            var segment_start = 0;
200
 
            for(var i in outer_nodes) {
201
 
                var segment_size = 360 / outer_total * outer_nodes[i].nodes;
 
196
            Y.Array.each(outer_nodes, function(outer_node, i) {
 
197
                var segment_size = 360 / outer_total * outer_node.nodes;
202
198
                var segment = [
203
199
                    this._center().x,
204
200
                    this._center().y,
209
205
                    var slice = r.path();
210
206
                    slice.attr({
211
207
                        segment: segment,
212
 
                        fill: outer_nodes[i].colour,
 
208
                        fill: outer_node.colour,
213
209
                        stroke: STROKE_COLOUR,
214
210
                        'stroke-width': STROKE_WIDTH
215
211
                        });
222
218
                            widget.fire(out);
223
219
                        },
224
220
                        null,
225
 
                        outer_nodes[i].events.over,
226
 
                        outer_nodes[i].events.out,
227
 
                        outer_nodes[i].name,
 
221
                        outer_node.events.over,
 
222
                        outer_node.events.out,
 
223
                        outer_node.name,
228
224
                        this
229
225
                        );
230
226
                    this._outer_paths.push(slice);
235
231
                        TRANSITION_TIME,
236
232
                        TRANSITION_EASING
237
233
                        );
238
 
                    this._outer_paths[i].angle = segment_start - segment_size / 2;
 
234
                    this._outer_paths[i].angle =
 
235
                        segment_start - segment_size / 2;
239
236
                }
240
237
                segment_start += segment_size;
241
 
            }
 
238
            }, this);
242
239
        }
243
240
 
244
241
        var offline_circle_width = 0;
271
268
        }
272
269
 
273
270
        var added_circle_width = 0;
274
 
        if (total_nodes == 0) {
 
271
        if (total_nodes === 0) {
275
272
            added_circle_width = this._radius() - STROKE_WIDTH * 2;
276
273
        }
277
274
        else if (added_nodes > 0) {
295
292
                this);
296
293
        }
297
294
        else {
298
 
            if (added_nodes != total_nodes || total_nodes == 0) {
 
295
            if (added_nodes !== total_nodes || total_nodes === 0) {
299
296
                this._added_circle.toFront();
300
297
                this._added_circle.animate(
301
298
                    {r: added_circle_width},
307
304
    },
308
305
 
309
306
    initializer: function(cfg) {
310
 
        canvas_size = this.get('width') + STROKE_WIDTH * 2;
 
307
        var canvas_size = this.get('width') + STROKE_WIDTH * 2;
311
308
        r = Raphael(this.get('node_id'), canvas_size, canvas_size);
312
309
        r.customAttributes.segment = function (x, y, r, a1, a2) {
313
310
            var flag = (a2 - a1) > 180;
314
 
            if (a1 == 0 && a2 == 360) {
315
 
                /* If the arc is a full circle we need to set the end point to less
316
 
                   than 360 degrees otherwise the start and end points are
317
 
                   calculated as the same location. */
 
311
            if (a1 === 0 && a2 === 360) {
 
312
                /* If the arc is a full circle we need to set the end
 
313
                   point to less than 360 degrees otherwise the start
 
314
                   and end points are calculated as the same
 
315
                   location. */
318
316
                a2 = 359.99;
319
317
            }
320
318
            a1 = (a1 % 360) * Math.PI / 180;
347
345
 
348
346
module.NodesChartWidget = NodesChartWidget;
349
347
 
350
 
}, '0.1', {'requires': ['event-custom', 'widget']}
 
348
}, '0.1', {'requires': ['array-extras', 'event-custom', 'widget']}
351
349
);