mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
28 lines
877 B
TypeScript
28 lines
877 B
TypeScript
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;
|
|
}
|