source: Dev/branches/rest-dojo-ui/client/dojox/charting/StoreSeries.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.6 KB
Line 
1define(["dojo/_base/array", "dojo/_base/declare", "dojo/_base/Deferred"],
2  function(arr, declare, Deferred){
3       
4        return declare("dojox.charting.StoreSeries", null, {
5                constructor: function(store, kwArgs, value){
6                        //      summary:
7                        //              Series adapter for dojo object stores (dojo.store).
8                        //      store: Object:
9                        //              A dojo object store.
10                        //      kwArgs: Object:
11                        //              A store-specific keyword parameters used for querying objects.
12                        //              See dojo.store docs
13                        //      value: Function|Object|String|Null:
14                        //              Function, which takes an object handle, and
15                        //              produces an output possibly inspecting the store's item. Or
16                        //              a dictionary object, which tells what names to extract from
17                        //              an object and how to map them to an output. Or a string, which
18                        //              is a numeric field name to use for plotting. If undefined, null
19                        //              or empty string (the default), "value" field is extracted.
20                        this.store = store;
21                        this.kwArgs = kwArgs;
22       
23                        if(value){
24                                if(typeof value == "function"){
25                                        this.value = value;
26                                }else if(typeof value == "object"){
27                                        this.value = function(object){
28                                                var o = {};
29                                                for(var key in value){
30                                                        o[key] = object[value[key]];
31                                                }
32                                                return o;
33                                        };
34                                }else{
35                                        this.value = function(object){
36                                                return object[value];
37                                        };
38                                }
39                        }else{
40                                this.value = function(object){
41                                        return object.value;
42                                };
43                        }
44       
45                        this.data = [];
46       
47                        this.fetch();
48                },
49       
50                destroy: function(){
51                        //      summary:
52                        //              Clean up before GC.
53                        if(this.observeHandle){
54                                this.observeHandle.dismiss();
55                        }
56                },
57       
58                setSeriesObject: function(series){
59                        //      summary:
60                        //              Sets a dojox.charting.Series object we will be working with.
61                        //      series: dojox.charting.Series:
62                        //              Our interface to the chart.
63                        this.series = series;
64                },
65       
66                // store fetch loop
67       
68                fetch: function(){
69                        //      summary:
70                        //              Fetches data from the store and updates a chart.
71                        var objects = this.objects = [];
72                        var self = this;
73                        if(this.observeHandle){
74                                this.observeHandle.dismiss();
75                        }
76                        var results = this.store.query(this.kwArgs.query, this.kwArgs);
77                        Deferred.when(results, function(objects){
78                                self.objects = objects;
79                                update();
80                        });
81                        if(results.observe){
82                                this.observeHandle = results.observe(update, true);
83                        }
84                        function update(){
85                                self.data = arr.map(self.objects, function(object){
86                                        return self.value(object, self.store);
87                                });
88                                self._pushDataChanges();
89                        }
90                },
91       
92                _pushDataChanges: function(){
93                        if(this.series){
94                                this.series.chart.updateSeries(this.series.name, this);
95                                this.series.chart.delayedRender();
96                        }
97                }
98       
99        });
100});
Note: See TracBrowser for help on using the repository browser.