import { Options } from '../models/options'; import { Series } from '../models/series'; import { PanelOptions } from '../types'; import { DataProcessor } from '../grafana/data_processor'; import { ChartwerkGaugePod } from '@chartwerk/gauge-pod'; import { PanelProps } from '@grafana/data'; import { PanelData, TimeRange } from '@grafana/data'; import React, { useRef } from 'react'; import { css } from 'emotion'; import * as _ from 'lodash'; interface Props extends PanelProps {} export function Panel({ options, data, width, height, timeZone, timeRange, onChangeTimeRange }: Props) { console.log('options', options); const grafanaSeriesList = getGrafanaSeriesList(data, timeRange); const series = new Series(grafanaSeriesList, options.gauge.value).getChartwerkSeries(); console.log('series', series); 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(() => { // TODO: switch / case pod type const pod = new ChartwerkGaugePod( (chartContainer as any).current, series, chartwerkOptions ); pod.render(); }); return (
); } function getGrafanaSeriesList(grafanaData: PanelData, timeRange: TimeRange): any[] { const processor = new DataProcessor({}); return processor.getSeriesList({ dataList: grafanaData.series, range: timeRange, }); }