From 9339ef653bbb8a560316107cff0a0d6e11ff8382 Mon Sep 17 00:00:00 2001 From: vargburz Date: Wed, 18 May 2022 14:39:31 +0300 Subject: [PATCH] remove defaults --- src/components/Panel.tsx | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx index 16a7b32..5de391e 100644 --- a/src/components/Panel.tsx +++ b/src/components/Panel.tsx @@ -17,18 +17,17 @@ import * as _ from 'lodash'; interface Props extends PanelProps {} export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) { - const panelOptions = fillGrafanaOptionsWithDefaults(options); - console.log('panelOptions', panelOptions); + console.log('panelOptions', options); const grafanaSeriesList = getGrafanaSeriesList(data, timeRange); - const series = new Series(grafanaSeriesList, panelOptions.gauge.value).getChartwerkSeries(); + const series = new Series(grafanaSeriesList, options.gauge.value).getChartwerkSeries(); console.log('series', series); - const chartwerkOptions = new Options(grafanaSeriesList, panelOptions).getChartwerkOptions(); + const chartwerkOptions = new Options(grafanaSeriesList, options).getChartwerkOptions(); let chartContainer = useRef(null); // we request animation frame here because we need an existing DOM-element at the moment we render the pod window.requestAnimationFrame(() => { let pod; - switch (panelOptions.visualizationType) { + switch (options.visualizationType) { case Pod.GAUGE: pod = new ChartwerkGaugePod((chartContainer as any).current, series, chartwerkOptions); break; @@ -36,18 +35,18 @@ export function Panel({ options, data, width, height, timeZone, timeRange, onCha pod = new ChartwerkBarPod((chartContainer as any).current, series, chartwerkOptions); break; default: - throw new Error(`Unknown visualization type: ${panelOptions.visualizationType}`); + throw new Error(`Unknown visualization type: ${options.visualizationType}`); } pod.render(); }); - const isLinkActive = !_.isEmpty(panelOptions.gauge.link); + const isLinkActive = !_.isEmpty(options.gauge.link); const chartClickHandler = (event: React.MouseEvent) => { event.preventDefault(); if (!isLinkActive) { return; } - window.open(panelOptions.gauge.link, '_self'); + window.open(options.gauge.link, '_self'); }; return ( @@ -70,22 +69,3 @@ function getGrafanaSeriesList(grafanaData: PanelData, timeRange: TimeRange): any range: timeRange, }); } - -function fillGrafanaOptionsWithDefaults(options: PanelOptions): PanelOptions { - const defaults = { - gauge: { - min: { useMetric: false }, - max: { useMetric: false }, - value: { useMetric: false }, - valueSize: 20, - reversed: false, - thresholds: { - arcBackground: 'gray', - defaultColor: 'green', - thresholds: [], - }, - icons: [], - }, - }; - return _.defaultsDeep(options, defaults); -}