dojox/charting/DataSeries.js

  • Provides:

    • dojox.charting.DataSeries
  • Requires:

    • dojox.lang.functional in common
  • dojox.charting.DataSeries

    • type
      Function
    • parameters:
      • store: (typeof Object)
        A dojo.data store object.
      • kwArgs: (typeof Object)
        A store-specific keyword parameters used for fetching items.
        See dojo.data.api.Read.fetch().
      • value: (typeof Function|Object|String|Null)
        Function, which takes a store, and an object handle, and
        produces an output possibly inspecting the store's item. Or
        a dictionary object, which tells what names to extract from
        an object and how to map them to an output. Or a string, which
        is a numeric field name to use for plotting. If undefined, null
        or empty string (the default), "value" field is extracted.
    • source: [view]
        this.store = store;
        this.kwArgs = kwArgs;


        if(value){
         if(dojo.isFunction(value)){
          this.value = value;
         }else if(dojo.isObject(value)){
          this.value = dojo.hitch(this, "_dictValue",
           dojox.lang.functional.keys(value), value);
         }else{
          this.value = dojo.hitch(this, "_fieldValue", value);
         }
        }else{
         this.value = dojo.hitch(this, "_defaultValue");
        }


        this.data = [];


        this._events = [];


        if(this.store.getFeatures()["dojo.data.api.Notification"]){
         this._events.push(
          dojo.connect(this.store, "onNew", this, "_onStoreNew"),
          dojo.connect(this.store, "onDelete", this, "_onStoreDelete"),
          dojo.connect(this.store, "onSet", this, "_onStoreSet")
         );
        }


        this.fetch();
    • summary
      Series adapter for dojo.data stores.
  • dojox.charting.DataSeries.destroy

    • type
      Function
    • source: [view]
        dojo.forEach(this._events, dojo.disconnect);
    • summary
      Clean up before GC.
  • dojox.charting.DataSeries.setSeriesObject

    • type
      Function
    • parameters:
      • series: (typeof dojox.charting.Series)
        Our interface to the chart.
    • source: [view]
        this.series = series;
    • summary
      Sets a dojox.charting.Series object we will be working with.
  • dojox.charting.DataSeries._dictValue

    • type
      Function
    • parameters:
      • keys: (typeof )
      • dict: (typeof )
      • store: (typeof )
      • item: (typeof )
    • source: [view]
        var o = {};
        dojo.forEach(keys, function(key){
         o[key] = store.getValue(item, dict[key]);
        });
        return o;
    • summary
  • dojox.charting.DataSeries._fieldValue

    • type
      Function
    • parameters:
      • field: (typeof )
      • store: (typeof )
      • item: (typeof )
    • source: [view]
        return store.getValue(item, field);
    • summary
  • dojox.charting.DataSeries._defaultValue

    • type
      Function
    • parameters:
      • store: (typeof )
      • item: (typeof )
    • source: [view]
        return store.getValue(item, "value");
    • summary
  • dojox.charting.DataSeries.fetch

    • type
      Function
    • source: [view]
        if(!this._inFlight){
         this._inFlight = true;
         var kwArgs = dojo.delegate(this.kwArgs);
         kwArgs.onComplete = dojo.hitch(this, "_onFetchComplete");
         kwArgs.onError = dojo.hitch(this, "onFetchError");
         this.store.fetch(kwArgs);
        }
    • summary
      Fetches data from the store and updates a chart.
  • dojox.charting.DataSeries._onFetchComplete

    • type
      Function
    • parameters:
      • items: (typeof )
      • request: (typeof )
    • source: [view]
        this.items = items;
        this._buildItemMap();
        this.data = dojo.map(this.items, function(item){
         return this.value(this.store, item);
        }, this);
        this._pushDataChanges();
        this._inFlight = false;
    • summary
  • dojox.charting.DataSeries.onFetchError

    • type
      Function
    • parameters:
      • errorData: (typeof )
      • request: (typeof )
    • source: [view]
        this._inFlight = false;
    • summary
      As stub to process fetch errors. Provide so user can attach to
      it with dojo.connect(). See dojo.data.api.Read fetch() for
      details: onError property.
  • dojox.charting.DataSeries._buildItemMap

    • type
      Function
    • source: [view]
        if(this.store.getFeatures()["dojo.data.api.Identity"]){
         var itemMap = {};
         dojo.forEach(this.items, function(item, index){
          itemMap[this.store.getIdentity(item)] = index;
         }, this);
         this.itemMap = itemMap;
        }
    • summary
  • dojox.charting.DataSeries._pushDataChanges

    • type
      Function
    • source: [view]
        if(this.series){
         this.series.chart.updateSeries(this.series.name, this);
         this.series.chart.delayedRender();
        }
    • summary
  • dojox.charting.DataSeries._onStoreNew

    • type
      Function
    • source: [view]
      dojo.provide("dojox.charting.DataSeries");


      dojo.require("dojox.lang.functional");


      dojo.declare("dojox.charting.DataSeries", null, {
       constructor: function(store, kwArgs, value){
        // summary:
        //  Series adapter for dojo.data stores.
        // store: Object:
        //  A dojo.data store object.
        // kwArgs: Object:
        //  A store-specific keyword parameters used for fetching items.
        //  See dojo.data.api.Read.fetch().
        // value: Function|Object|String|Null:
        //  Function, which takes a store, and an object handle, and
        //  produces an output possibly inspecting the store's item. Or
        //  a dictionary object, which tells what names to extract from
        //  an object and how to map them to an output. Or a string, which
        //  is a numeric field name to use for plotting. If undefined, null
        //  or empty string (the default), "value" field is extracted.
        this.store = store;
        this.kwArgs = kwArgs;


        if(value){
         if(dojo.isFunction(value)){
          this.value = value;
         }else if(dojo.isObject(value)){
          this.value = dojo.hitch(this, "_dictValue",
           dojox.lang.functional.keys(value), value);
         }else{
          this.value = dojo.hitch(this, "_fieldValue", value);
         }
        }else{
         this.value = dojo.hitch(this, "_defaultValue");
        }


        this.data = [];


        this._events = [];


        if(this.store.getFeatures()["dojo.data.api.Notification"]){
         this._events.push(
          dojo.connect(this.store, "onNew", this, "_onStoreNew"),
          dojo.connect(this.store, "onDelete", this, "_onStoreDelete"),
          dojo.connect(this.store, "onSet", this, "_onStoreSet")
         );
        }


        this.fetch();
       },


       destroy: function(){
        // summary:
        //  Clean up before GC.
        dojo.forEach(this._events, dojo.disconnect);
       },


       setSeriesObject: function(series){
        // summary:
        //  Sets a dojox.charting.Series object we will be working with.
        // series: dojox.charting.Series:
        //  Our interface to the chart.
        this.series = series;
       },


       // value transformers


       _dictValue: function(keys, dict, store, item){
        var o = {};
        dojo.forEach(keys, function(key){
         o[key] = store.getValue(item, dict[key]);
        });
        return o;
       },


       _fieldValue: function(field, store, item){
        return store.getValue(item, field);
       },


       _defaultValue: function(store, item){
        return store.getValue(item, "value");
       },


       // store fetch loop


       fetch: function(){
        // summary:
        //  Fetches data from the store and updates a chart.
        if(!this._inFlight){
         this._inFlight = true;
         var kwArgs = dojo.delegate(this.kwArgs);
         kwArgs.onComplete = dojo.hitch(this, "_onFetchComplete");
         kwArgs.onError = dojo.hitch(this, "onFetchError");
         this.store.fetch(kwArgs);
        }
       },


       _onFetchComplete: function(items, request){
        this.items = items;
        this._buildItemMap();
        this.data = dojo.map(this.items, function(item){
         return this.value(this.store, item);
        }, this);
        this._pushDataChanges();
        this._inFlight = false;
       },


       onFetchError: function(errorData, request){
        // summary:
        //  As stub to process fetch errors. Provide so user can attach to
        //  it with dojo.connect(). See dojo.data.api.Read fetch() for
        //  details: onError property.
        this._inFlight = false;
       },


       _buildItemMap: function(){
        if(this.store.getFeatures()["dojo.data.api.Identity"]){
         var itemMap = {};
         dojo.forEach(this.items, function(item, index){
          itemMap[this.store.getIdentity(item)] = index;
         }, this);
         this.itemMap = itemMap;
        }
       },


       _pushDataChanges: function(){
        if(this.series){
         this.series.chart.updateSeries(this.series.name, this);
         this.series.chart.delayedRender();
        }
       },


       // store notification handlers


       _onStoreNew: function(){
        // the only thing we can do is to re-fetch items
        this.fetch();
    • summary
  • dojox.charting.DataSeries._onStoreDelete

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
      dojo.provide("dojox.charting.DataSeries");


      dojo.require("dojox.lang.functional");


      dojo.declare("dojox.charting.DataSeries", null, {
       constructor: function(store, kwArgs, value){
        // summary:
        //  Series adapter for dojo.data stores.
        // store: Object:
        //  A dojo.data store object.
        // kwArgs: Object:
        //  A store-specific keyword parameters used for fetching items.
        //  See dojo.data.api.Read.fetch().
        // value: Function|Object|String|Null:
        //  Function, which takes a store, and an object handle, and
        //  produces an output possibly inspecting the store's item. Or
        //  a dictionary object, which tells what names to extract from
        //  an object and how to map them to an output. Or a string, which
        //  is a numeric field name to use for plotting. If undefined, null
        //  or empty string (the default), "value" field is extracted.
        this.store = store;
        this.kwArgs = kwArgs;


        if(value){
         if(dojo.isFunction(value)){
          this.value = value;
         }else if(dojo.isObject(value)){
          this.value = dojo.hitch(this, "_dictValue",
           dojox.lang.functional.keys(value), value);
         }else{
          this.value = dojo.hitch(this, "_fieldValue", value);
         }
        }else{
         this.value = dojo.hitch(this, "_defaultValue");
        }


        this.data = [];


        this._events = [];


        if(this.store.getFeatures()["dojo.data.api.Notification"]){
         this._events.push(
          dojo.connect(this.store, "onNew", this, "_onStoreNew"),
          dojo.connect(this.store, "onDelete", this, "_onStoreDelete"),
          dojo.connect(this.store, "onSet", this, "_onStoreSet")
         );
        }


        this.fetch();
       },


       destroy: function(){
        // summary:
        //  Clean up before GC.
        dojo.forEach(this._events, dojo.disconnect);
       },


       setSeriesObject: function(series){
        // summary:
        //  Sets a dojox.charting.Series object we will be working with.
        // series: dojox.charting.Series:
        //  Our interface to the chart.
        this.series = series;
       },


       // value transformers


       _dictValue: function(keys, dict, store, item){
        var o = {};
        dojo.forEach(keys, function(key){
         o[key] = store.getValue(item, dict[key]);
        });
        return o;
       },


       _fieldValue: function(field, store, item){
        return store.getValue(item, field);
       },


       _defaultValue: function(store, item){
        return store.getValue(item, "value");
       },


       // store fetch loop


       fetch: function(){
        // summary:
        //  Fetches data from the store and updates a chart.
        if(!this._inFlight){
         this._inFlight = true;
         var kwArgs = dojo.delegate(this.kwArgs);
         kwArgs.onComplete = dojo.hitch(this, "_onFetchComplete");
         kwArgs.onError = dojo.hitch(this, "onFetchError");
         this.store.fetch(kwArgs);
        }
       },


       _onFetchComplete: function(items, request){
        this.items = items;
        this._buildItemMap();
        this.data = dojo.map(this.items, function(item){
         return this.value(this.store, item);
        }, this);
        this._pushDataChanges();
        this._inFlight = false;
       },


       onFetchError: function(errorData, request){
        // summary:
        //  As stub to process fetch errors. Provide so user can attach to
        //  it with dojo.connect(). See dojo.data.api.Read fetch() for
        //  details: onError property.
        this._inFlight = false;
       },


       _buildItemMap: function(){
        if(this.store.getFeatures()["dojo.data.api.Identity"]){
         var itemMap = {};
         dojo.forEach(this.items, function(item, index){
          itemMap[this.store.getIdentity(item)] = index;
         }, this);
         this.itemMap = itemMap;
        }
       },


       _pushDataChanges: function(){
        if(this.series){
         this.series.chart.updateSeries(this.series.name, this);
         this.series.chart.delayedRender();
        }
       },


       // store notification handlers


       _onStoreNew: function(){
        // the only thing we can do is to re-fetch items
        this.fetch();
       },


       _onStoreDelete: function(item){
        // we cannot do anything with deleted item, the only way is to compare
        // items for equality
        if(this.items){
         var flag = dojo.some(this.items, function(it, index){
          if(it === item){
           this.items.splice(index, 1);
           this._buildItemMap();
           this.data.splice(index, 1);
           return true;
          }
          return false;
         }, this);
         if(flag){
          this._pushDataChanges();
         }
        }
    • summary
  • dojox.charting.DataSeries._onStoreSet

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        if(this.itemMap){
         // we can use our handy item map, if the store supports Identity
         var id = this.store.getIdentity(item), index = this.itemMap[id];
         if(typeof index == "number"){
          this.data[index] = this.value(this.store, this.items[index]);
          this._pushDataChanges();
         }
        }else{
         // otherwise we have to rely on item's equality
         if(this.items){
          var flag = dojo.some(this.items, function(it, index){
           if(it === item){
            this.data[index] = this.value(this.store, it);
            return true;
           }
           return false;
          }, this);
          if(flag){
           this._pushDataChanges();
          }
         }
        }
    • summary
  • dojox.charting.DataSeries.series

    • summary
  • dojox.charting.DataSeries.setSeriesObject.series

    • type
      dojox.charting.Series
    • summary
      Our interface to the chart.
  • dojox.charting.DataSeries._inFlight

    • summary
  • dojox.charting.DataSeries.items

    • summary
  • dojox.charting.DataSeries.data

    • summary
  • dojox.charting.DataSeries.itemMap

    • summary
  • dojox.charting.DataSeries.store

    • type
      Object
    • summary
      A dojo.data store object.
  • dojox.charting.DataSeries.kwArgs

    • type
      Object
    • summary
      A store-specific keyword parameters used for fetching items.
      See dojo.data.api.Read.fetch().
  • dojox.charting.DataSeries.value

    • type
      Function|Object|String|Null
    • summary
      Function, which takes a store, and an object handle, and
      produces an output possibly inspecting the store's item. Or
      a dictionary object, which tells what names to extract from
      an object and how to map them to an output. Or a string, which
      is a numeric field name to use for plotting. If undefined, null
      or empty string (the default), "value" field is extracted.
  • dojox.charting.DataSeries._events

    • summary
  • dojox.charting

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary