mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 10:00:17 -04:00
* 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
41 lines
1.1 KiB
JavaScript
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
|
|
}
|
|
}
|
|
};
|
|
}
|