Commit ffa68f6f by Dominik Prokop Committed by GitHub

GraphNG: Disable Plot logging by default (#30390)

* Disable Plot loggging by default

* Fix
parent ffd39933
...@@ -25,6 +25,7 @@ export const UPlotChart: React.FC<PlotProps> = (props) => { ...@@ -25,6 +25,7 @@ export const UPlotChart: React.FC<PlotProps> = (props) => {
props.timeZone, props.timeZone,
props.config props.config
); );
const getPlotInstance = useCallback(() => { const getPlotInstance = useCallback(() => {
return plotInstance.current; return plotInstance.current;
}, []); }, []);
......
...@@ -2,13 +2,14 @@ import throttle from 'lodash/throttle'; ...@@ -2,13 +2,14 @@ import throttle from 'lodash/throttle';
import { Options } from 'uplot'; import { Options } from 'uplot';
import { PlotPlugin, PlotProps } from './types'; import { PlotPlugin, PlotProps } from './types';
const LOGGING_ENABLED = false;
const ALLOWED_FORMAT_STRINGS_REGEX = /\b(YYYY|YY|MMMM|MMM|MM|M|DD|D|WWWW|WWW|HH|H|h|AA|aa|a|mm|m|ss|s|fff)\b/g; const ALLOWED_FORMAT_STRINGS_REGEX = /\b(YYYY|YY|MMMM|MMM|MM|M|DD|D|WWWW|WWW|HH|H|h|AA|aa|a|mm|m|ss|s|fff)\b/g;
export const timeFormatToTemplate = (f: string) => { export function timeFormatToTemplate(f: string) {
return f.replace(ALLOWED_FORMAT_STRINGS_REGEX, (match) => `{${match}}`); return f.replace(ALLOWED_FORMAT_STRINGS_REGEX, (match) => `{${match}}`);
}; }
export const buildPlotConfig = (props: PlotProps, plugins: Record<string, PlotPlugin>): Options => { export function buildPlotConfig(props: PlotProps, plugins: Record<string, PlotPlugin>): Options {
return { return {
width: props.width, width: props.width,
height: props.height, height: props.height,
...@@ -27,10 +28,10 @@ export const buildPlotConfig = (props: PlotProps, plugins: Record<string, PlotPl ...@@ -27,10 +28,10 @@ export const buildPlotConfig = (props: PlotProps, plugins: Record<string, PlotPl
hooks: p[1].hooks, hooks: p[1].hooks,
})), })),
hooks: {}, hooks: {},
} as any; } as Options;
}; }
export const isPlottingTime = (config: Options) => { export function isPlottingTime(config: Options) {
let isTimeSeries = false; let isTimeSeries = false;
if (!config.scales) { if (!config.scales) {
...@@ -46,17 +47,17 @@ export const isPlottingTime = (config: Options) => { ...@@ -46,17 +47,17 @@ export const isPlottingTime = (config: Options) => {
} }
return isTimeSeries; return isTimeSeries;
}; }
// Dev helpers // Dev helpers
export const throttledLog = throttle((...t: any[]) => { export const throttledLog = throttle((...t: any[]) => {
console.log(...t); console.log(...t);
}, 500); }, 500);
export const pluginLog = (id: string, throttle = false, ...t: any[]) => { export function pluginLog(id: string, throttle = false, ...t: any[]) {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production' || !LOGGING_ENABLED) {
return; return;
} }
const fn = throttle ? throttledLog : console.log; const fn = throttle ? throttledLog : console.log;
fn(`[Plugin: ${id}]: `, ...t); fn(`[Plugin: ${id}]: `, ...t);
}; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment