diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index bf5c66dbd4f..7edaf0a0540 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -32,6 +32,7 @@ export class DashboardGrid extends PureComponent { private panelMap: { [id: string]: PanelModel } = {}; private eventSubs = new Subscription(); private windowHeight = 1200; + private windowWidth = 1920; private gridWidth = 0; constructor(props: Props) { @@ -152,6 +153,7 @@ export class DashboardGrid extends PureComponent { // We assume here that if width change height might have changed as well if (this.gridWidth !== gridWidth) { this.windowHeight = window.innerHeight ?? 1000; + this.windowWidth = window.innerWidth; this.gridWidth = gridWidth; } @@ -170,6 +172,7 @@ export class DashboardGrid extends PureComponent { gridPos={panel.gridPos} gridWidth={gridWidth} windowHeight={this.windowHeight} + windowWidth={this.windowWidth} isViewing={panel.isViewing} > {(width: number, height: number) => { @@ -259,6 +262,7 @@ interface GrafanaGridItemProps extends Record { gridPos?: GridPos; isViewing: string; windowHeight: number; + windowWidth: number; children: any; } @@ -270,15 +274,15 @@ const GrafanaGridItem = React.forwardRef(( let width = 100; let height = 100; - const { gridWidth, gridPos, isViewing, windowHeight, ...divProps } = props; + const { gridWidth, gridPos, isViewing, windowHeight, windowWidth, ...divProps } = props; const style: CSSProperties = props.style ?? {}; if (isViewing) { - width = props.gridWidth!; + width = gridWidth!; height = windowHeight * 0.85; style.height = height; style.width = '100%'; - } else if (props.gridWidth! < theme.breakpoints.values.md) { + } else if (windowWidth < theme.breakpoints.values.md) { width = props.gridWidth!; height = props.gridPos!.h * (GRID_CELL_HEIGHT + GRID_CELL_VMARGIN) - GRID_CELL_VMARGIN; style.height = height;