grafana/public/app/features/dashboard/components/PanelEditor/utils.ts
Torkel Ödegaard fee18f143e
NewPanelEditor: Introduce redux state and reducer (#22070)
* New panel editor redux

* minor change

* Updated

* progress

* updated

* Fixed panel data mutable issue

* more actions

* Discard works

* Updated

* Updated
2020-02-11 14:57:16 +01:00

27 lines
878 B
TypeScript

import { CSSProperties } from 'react';
import { PanelModel } from '../../state/PanelModel';
import { DisplayMode } from './types';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
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,
};
}