Files
redash/client/app/visualizations/chart/plotly/customChartUtils.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

41 lines
1.1 KiB
JavaScript

import { each } from "lodash";
import { normalizeValue } from "./utils";
export function prepareCustomChartData(series) {
const x = [];
const ys = {};
each(series, ({ name, data }) => {
ys[name] = [];
each(data, point => {
x.push(normalizeValue(point.x));
ys[name].push(normalizeValue(point.y));
});
});
return { x, ys };
}
export function createCustomChartRenderer(code, logErrorsToConsole = false) {
// Create a function from custom code; catch syntax errors
let render = () => {};
try {
render = new Function("x, ys, element, Plotly", code); // eslint-disable-line no-new-func
} catch (err) {
if (logErrorsToConsole) {
console.log(`Error while executing custom graph: ${err}`); // eslint-disable-line no-console
}
}
// Return function that will invoke custom code; catch runtime errors
return (x, ys, element, Plotly) => {
try {
render(x, ys, element, Plotly);
} catch (err) {
if (logErrorsToConsole) {
console.log(`Error while executing custom graph: ${err}`); // eslint-disable-line no-console
}
}
};
}