proteic icon indicating copy to clipboard operation
proteic copied to clipboard

Add method for datum transformation in the datasources

Open jorgeyp opened this issue 8 years ago • 1 comments

At this moment Proteic datasources only work with the following data format:

[
  { "date": "01/03", "value": 234, "key": "v1" },
  { "date": "01/03", "value": 532, "key": "v2" },
  { "date": "01/03", "value": 233, "key": "v3" },
  { "date": "02/03", "value": 243, "key": "v1" },
  { "date": "02/03", "value": 531, "key": "v2" },
  { "date": "02/03", "value": 156, "key": "v3" }
]

Having a specific data format for static data is not a big problem, since you can allways apply a transformation to your data. However, with streaming data the library should provide a method to transform the incoming data to the Proteic format. This could be solved passing a transform function to the datasource, that applies the transformation to each datum.

A typical time-series example could be the following:

Incoming data:

[
  {  "date":  "01/03",  "v1": "234", "v2": "532", "v3": "233" },
  {  "date":  "02/03",  "v1": "243", "v2": "531", "v3": "156" }
]

Chart creation applying the transformation function:

new proteic.Linechart([]).ds(ws).apply( (d) => [ 
  { date: d.date, value: d.v1, key: 'v1' },
  { date: d.date, value: d.v2, key: 'v2' },
  { date: d.date, value: d.v3, key: 'v3' }
 ] );

jorgeyp avatar Jan 19 '17 15:01 jorgeyp

The unpivot() method has already been implemented

0xNacho avatar Jun 14 '17 21:06 0xNacho