Files
redash/client/app/visualizations/funnel/Renderer/prepareData.js
Arik Fraimovich 56d3be2248 Prettier all the Javascript code & GitHub Action (#4433)
* Prettier all the JS files

* Add GitHub Action to autoformat code pushed to master

* Fix eslint violation due to formatting.

* Remove GitHub actions for styling

* Add restyled.io config
2019-12-11 17:05:38 +02:00

29 lines
811 B
JavaScript

import { map, maxBy, sortBy } from "lodash";
export default function prepareData(rows, options) {
if (rows.length === 0 || !options.stepCol.colName || !options.valueCol.colName) {
return [];
}
rows = [...rows];
if (options.sortKeyCol.colName) {
rows = sortBy(rows, options.sortKeyCol.colName);
}
if (options.sortKeyCol.reverse) {
rows = rows.reverse();
}
const data = map(rows, row => ({
step: row[options.stepCol.colName],
value: parseFloat(row[options.valueCol.colName]) || 0.0,
}));
const maxVal = maxBy(data, d => d.value).value;
data.forEach((d, i) => {
d.pctMax = (d.value / maxVal) * 100.0;
d.pctPrevious = i === 0 || d.value === data[i - 1].value ? 100.0 : (d.value / data[i - 1].value) * 100.0;
});
return data.slice(0, options.itemsLimit);
}