mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
e612d7a2f9
* Move data links suggestions to grafana-data
* Data links - field config and overrides
* Lint
* Fix test
* Add variable suggestions to field override context
* Revert "Move data links suggestions to grafana-data"
This reverts commit 5d8d01a65e
.
* Move FieldConfigEditor to core
27 lines
878 B
TypeScript
27 lines
878 B
TypeScript
import { CSSProperties } from 'react';
|
|
import { PanelModel } from '../../state/PanelModel';
|
|
import { GRID_CELL_VMARGIN, GRID_COLUMN_COUNT, GRID_CELL_HEIGHT } from 'app/core/constants';
|
|
import { DisplayMode } from './types';
|
|
|
|
export function calculatePanelSize(mode: DisplayMode, width: number, height: number, panel: PanelModel): CSSProperties {
|
|
if (mode === DisplayMode.Fill) {
|
|
return { width, height };
|
|
}
|
|
const colWidth = (window.innerWidth - GRID_CELL_VMARGIN * 4) / GRID_COLUMN_COUNT;
|
|
const pWidth = colWidth * panel.gridPos.w;
|
|
const pHeight = GRID_CELL_HEIGHT * panel.gridPos.h;
|
|
const scale = Math.min(width / pWidth, height / pHeight);
|
|
|
|
if (mode === DisplayMode.Exact && pWidth <= width && pHeight <= height) {
|
|
return {
|
|
width: pWidth,
|
|
height: pHeight,
|
|
};
|
|
}
|
|
|
|
return {
|
|
width: pWidth * scale,
|
|
height: pHeight * scale,
|
|
};
|
|
}
|