The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/panel/xychart/XYChartPanel.old

71 lines
2.1 KiB

import React, { useMemo } from 'react';
import { LegendDisplayMode, UPlotChart, useTheme2, VizLayout, VizLegend, VizLegendItem } from '@grafana/ui';
import { PanelProps } from '@grafana/data';
import { XYChartOptions } from './models.gen';
import { prepData, prepScatter } from './scatter';
interface XYChartPanelProps extends PanelProps<XYChartOptions> {}
export const XYChartPanel = ({
data,
width,
height,
options,
fieldConfig,
timeRange,
//onFieldConfigChange,
}: XYChartPanelProps) => {
const theme = useTheme2();
const info = useMemo(() => {
console.log('prepScatter!');
return prepScatter(options, data, theme, () => {});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data.structureRev, options]);
// preps data in various shapes...aligned, stacked, merged, interpolated, etc..
const scatterData = useMemo(() => {
console.log('prepData!');
return prepData(info, data.series);
}, [info, data.series]);
const legend = useMemo(() => {
const items: VizLegendItem[] = [];
for (const s of info.series) {
const frame = s.frame(data.series);
if (frame) {
for (const item of s.legend(frame)) {
items.push(item);
}
}
}
return (
<VizLayout.Legend placement="bottom">
<VizLegend placement="bottom" items={items} displayMode={LegendDisplayMode.List} />
</VizLayout.Legend>
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [info]);
if (info.error) {
return (
<div className="panel-empty">
<p>{info.error}</p>
</div>
);
}
return (
<VizLayout width={width} height={height} legend={legend}>
{(vizWidth: number, vizHeight: number) => (
// <pre style={{ width: vizWidth, height: vizHeight, border: '1px solid green', margin: '0px' }}>
// {JSON.stringify(scatterData, null, 2)}
// </pre>
<UPlotChart config={info.builder!} data={scatterData} width={vizWidth} height={vizHeight} timeRange={timeRange}>
{/*children ? children(config, alignedFrame) : null*/}
</UPlotChart>
)}
</VizLayout>
);
};