1import { PanelData } from '@grafana/data'; 2import { useTheme2 } from '@grafana/ui'; 3import { STAT, TIMESERIES } from '../utils/constants'; 4 5export function useVizHeight(data: PanelData, pluginId: string, frameIndex: number) { 6 const theme = useTheme2(); 7 if (pluginId === TIMESERIES || pluginId === STAT || dataIsEmpty(data)) { 8 return 200; 9 } 10 11 const values = data.series[frameIndex].fields[0].values.length; 12 const rowHeight = theme.spacing.gridSize * 5; 13 14 /* 15 Calculate how if we can make the table smaller than 200px 16 for when we only have 1-2 values 17 The extra rowHeight is to accommodate the header. 18 */ 19 const tableHeight = values * rowHeight + rowHeight; 20 21 return tableHeight >= 200 ? 200 : tableHeight; 22} 23 24function dataIsEmpty(data: PanelData) { 25 return !data || !data.series[0] || !data.series[0].fields[0] || !data.series[0].fields[0].values; 26} 27