...
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
Consider a query of min, max and average comments length per day which we want to visualize as a plot in Jira. For this to work without data transformation all three data series would be placed in one dimension (called like commentLenght) and additional dimmension for distinguish between them (see Multiple series / charts composition ).
But with data transformation we could have a query which calculates different data series in different columns and then transform this data to a format know by the SmartQL plot library . For this need we want to create a new view with following steps:
...
Go to Smart QL → New query and place following query
Code Block language sql 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)
Save a query as EXAMPLE_VIEW
Now you will have an example view as shown below:
...
Lets create new plot.
...
Add new gadget to the dashboard. Choose Smart QL Advanced Gadget. Select newly created EXAMPLE_VIEW as a data feed.
In configuration place following JSON snippet.
Code Block language json { "type": "line", "x": "X", "y": "Y", "color":"C", "plugins": [ { "name": "tooltip" }, { "name": "legend" }, { "name": "export-to" } ] }
In data transformation place following javascript lambda transformation.
Code Block language js 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.
...
For this particular query you want be able to render three different data series without data transformation, but only of them:
...