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/features/alerting/unified/hooks/useVizHeight.ts

27 lines
877 B

import { PanelData } from '@grafana/data';
import { useTheme2 } from '@grafana/ui';
import { STAT, TIMESERIES } from '../utils/constants';
export function useVizHeight(data: PanelData, pluginId: string, frameIndex: number) {
const theme = useTheme2();
if (pluginId === TIMESERIES || pluginId === STAT || dataIsEmpty(data)) {
return 200;
}
const values = data.series[frameIndex].fields[0].values.length;
const rowHeight = theme.spacing.gridSize * 5;
/*
Calculate how if we can make the table smaller than 200px
for when we only have 1-2 values
The extra rowHeight is to accommodate the header.
*/
const tableHeight = values * rowHeight + rowHeight;
return tableHeight >= 200 ? 200 : tableHeight;
}
function dataIsEmpty(data: PanelData) {
return !data || !data.series[0] || !data.series[0].fields[0] || !data.series[0].fields[0].values;
}