Debian Codegraph @

dojox/charting/StoreSeries.js

raw symbols SCIP
1 define(["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
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._initialRendering = true;
48 this.fetch();
49 },
50
51 destroy: function(){
52 // summary:
53 // Clean up before GC.
54 if(this.observeHandle){
55 this.observeHandle.remove();
56 }
57 },
58
59 setSeriesObject: function(series){
60 // summary:
61 // Sets a dojox/charting/Series object we will be working with.
62 // series: dojox/charting/Series
63 // Our interface to the chart.
64 this.series = series;
65 },
66
67 // store fetch loop
68
69 fetch: function(query, options){
70 // summary:
71 // Fetches data from the store and updates a chart.
72 // query: String | Object | Function
73 // Optional update to the query to use for retrieving objects from the store.
74 // options: dojo/store/api/Store.QueryOptions
75 // Optional arguments to apply to the resultset.
76 var self = this;
77 if(this.observeHandle){
78 this.observeHandle.remove();
79 }
80 var results = this.store.query(query || this.kwArgs.query, options || this.kwArgs);
81 Deferred.when(results, function(objects){
82 self.objects = objects;
83 update();
84 });
85 if(results.observe){
86 this.observeHandle = results.observe(update, true);
87 }
88 function update(){
89 self.data = arr.map(self.objects, function(object){
90 return self.value(object, self.store);
91 });
92 self._pushDataChanges();
93 }
94 },
95
96 _pushDataChanges: function(){
97 if(this.series){
98 this.series.chart.updateSeries(this.series.name, this, this._initialRendering);
99 this._initialRendering = false;
100 this.series.chart.delayedRender();
101 }
102 }
103
104 });
105 });