Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Data transformation is available only for advanced chart gadget.

Using data transformation

In data transformation you write custom javascript function (or lambda). This functions accepts only one parameter which is an array of rows. Each row has properties with names corresponding to a selected data columns names.

Code Block
// example of a function
function addAdditionalDimension(data) {
  return data.map(row => {...row, newDimension: row.columnA + row.columnB})
}
Code Block
// example of a lambda
data => data.map(row => {...row, newDimension: row.columnA + row.columnB})
Code Block
// another example of injecting additional row
function addMissingRow(data) {
  const missingRow = {...};
  data.push(missingRow);
  return data;
}

Example usage of data transformation

...

  1. Go to Smart QL → New query and place following query

    Code Block
    languagesql
    SELECT 
    	floor(created to day) creationday, 
    	max(CHAR_LENGTH(body)) maxcommentlength, 
    	avg(CHAR_LENGTH(body)) avgcommentlength, 
    	min(CHAR_LENGTH(body)) mincommentlength 
    FROM 
    	CORE.comments 
    GROUP BY 
    	floor(created to day)
  2. Save a query as EXAMPLE_VIEW

Now you will have an example view as shown below:

...

Lets create new plot.

...

  1. Add new gadget to the dashbpard. Choose Smart QL Advanced Gadget. Select newly created EXAMPLE_VIEW as a data feed.

  2. In configuration place following JSON snippet.

    Code Block
    languagejson
    {
      "type": "line",
      "x": "X",
      "y": "Y",
      "color":"C",
      "plugins": [
        {
          "name": "tooltip"
        },
        {
          "name": "legend"
        },
        {
          "name": "export-to"
        }
      ]
    }
  3. In data transformation place following javascript lambda transformation.

    Code Block
    languagejs
    data => data.reduce((acc, curr)=>[
      ...acc,
      {X: curr.creationday, Y: curr.maxcommentlength, C: 'max'},
      {X: curr.creationday, Y: curr.mincommentlength, C: 'min'},
      {X: curr.creationday, Y: curr.avgcommentlength, C: 'avg'}
    	], [])

Now you will see following plot consisting of 3 data series.

...