Opened 8 years ago

Closed 4 years ago

#13807 closed enhancement (patchwelcome)

Implementing "value" feature from dojox.charting.DataSeries in dojox.charting.DataChart

Reported by: Jose Moreira Owned by: Eugene Lazutkin
Priority: low Milestone: 1.13
Component: Charting Version: 1.7.0b1
Keywords: Cc:
Blocked By: Blocking:

Description

According to my current understanding of Dojo 1.6.1 code (and also a read of 1.7.0b5), dojox.charting.DataChart? has a "fieldName" constructor argument, which is used to extract the series value (or values if the property value is a array) from a datastore item, for example:

http://bugs.dojotoolkit.org/browser/dojo/dojox/trunk/charting/DataChart.js#L371

var field = this.getProperty(m, this.fieldName);
this.seriesData[nm].push(field);

Given a dataset in which the developer only wants some specific properties of an item plotted from a flat format, for example only 'cpu',

'rsize', 'vsize' and 'vprvt' from :

{
  "identifier": "pid",
  "idAttribute": "pid",
  "label": "cmd",
  "labelAttribute": "cmd",
  "items": [
    {"pid": 1639, "cmd": "kernel_task"  , "cpu": 10.3   , "rsize": 659000000  , "vsize": 18000    , "vprvt": 81000    },
    {"pid": 1572, "cmd": "iTerm"        , "cpu": 10.0   , "rsize": 139400000  , "vsize": 9000     , "vprvt": 52000    },
    {"pid": 1524, "cmd": "top"          , "cpu": 7.7    , "rsize": 350000000  , "vsize": 46000    , "vprvt": 17000    },
    {"pid": 1470, "cmd": "launchd"      , "cpu": 15.4   , "rsize": 186800000  , "vsize": 50000    , "vprvt": 57000    },
    {"pid": 1823, "cmd": "Colloquy"     , "cpu": 5.2    , "rsize": 116000000  , "vsize": 6873000  , "vprvt": 226000   },
    {"pid": 1442, "cmd": "WindowServer" , "cpu": 4.5    , "rsize": 157000000  , "vsize": 2525000  , "vprvt": 328000   },
    {"pid": 1340, "cmd": "iTunes"       , "cpu": 3.8    , "rsize": 700000000  , "vsize": 3293000  , "vprvt": 81000    },
    {"pid": 1556, "cmd": "backupd"      , "cpu": 3.4    , "rsize": 150000000  , "vsize": 2555000  , "vprvt": 57000    },
    {"pid": 1363, "cmd": "Finder"       , "cpu": 2.7    , "rsize": 600000000  , "vsize": 2667000  , "vprvt": 81000    },
    {"pid": 1329, "cmd": "mdworker"     , "cpu": 2.3    , "rsize": 100000000  , "vsize": 2416000  , "vprvt": 36000    }
   ]
}

it's currently not possible to only plot a subset of the properties using dojox.charting.DataChart? directly or pre-processing the data (as far as i know).

A possible solution could be to mimic dojox.charting.DataSeries?, in which it's "value" property:

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.

can be passed a function which receives the datastore item and returns a transformation, for example as described in the Dojo docs:

function trans1(store, item){
  // let's create our object
  var o = {
    x: store.getValue(item, "order"),
    y: store.getValue(item, "value"),
    tooltip: store.getValue(item, "title"),
    color: store.getValue(item, "urgency") ? "red" : "green"
  };
  // we can massage the object, if we want, and return it
  return o;
}

In this particular case, an implementation could be:

function trans_subset(store, item){
  // let's create our object
  var o = {
    "cpu": store.getValue(item, "cpu"),
    "rsize": store.getValue(item, "rsize"),
    "vsize": store.getValue(item, "vsize"),
    "vprvt": store.getValue(item, "vprvt"),
  };
  // we can massage the object, if we want, and return it
  return o;
}

Although it it more complex that for example allowing "fieldName" to be an array of property names (that could be another possible solution), this solution would also allow the developer to transform the property values, as also intented on the dojox.charting.DataSeries? "value", for example:

/**
  * function that normalizes Kb/Mb/Gb bytes to bytes
  */
function normalizeToBytes(/*String*/ value)  {
    //TODO do me
}

function trans_subset(store, item){
  var o = {
    "cpu": store.getValue(item, "cpu"),
    "rsize": normalizeToBytes(store.getValue(item, "rsize")),
    "vsize": normalizeToBytes(store.getValue(item, "vsize")),
    "vprvt": normalizeToBytes(store.getValue(item, "vprvt")),
  };
  return o;
}

Change History (1)

comment:1 Changed 4 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: newclosed

Given that no one has shown interest in creating a patch in the past 4+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.