|
|
|
@ -17,18 +17,17 @@ import * as _ from 'lodash';
|
|
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
|
|
|
|
|
|
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<HTMLDivElement>) => { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|