mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Fixes under public/app/plugins * Fixes under public/app/plugins/datasource * Fixes under public/app/features * Fixes under public/app/features * Fixes under public/app/features * Fixes under public/app/components * Fix PanelNotSupported test * Fix one more warning * Fix warning in usePanelSave * Fix traceview empty response * Azure monitor fixes * More fixes * Fix tests for azure monitor * Fixes after merging master * Add comment for disabled rules * Fixes after merging master * Fixes after merging master * Adress review comments * Fix azure tests * Address review feedbacks
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { CSSProperties } from 'react';
|
|
import { set as lodashSet, omit } from 'lodash';
|
|
import { FieldConfigSource, PanelPlugin } from '@grafana/data';
|
|
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,
|
|
};
|
|
}
|
|
|
|
export function supportsDataQuery(plugin: PanelPlugin | undefined | null): boolean {
|
|
return plugin?.meta.skipDataQuery === false;
|
|
}
|
|
|
|
export const updateDefaultFieldConfigValue = (
|
|
config: FieldConfigSource,
|
|
name: string,
|
|
value: any,
|
|
isCustom?: boolean
|
|
) => {
|
|
let defaults = { ...config.defaults };
|
|
const remove = value === undefined || value === null || '';
|
|
|
|
if (isCustom) {
|
|
if (defaults.custom) {
|
|
if (remove) {
|
|
defaults.custom = omit(defaults.custom, name);
|
|
} else {
|
|
defaults.custom = lodashSet({ ...defaults.custom }, name, value);
|
|
}
|
|
} else if (!remove) {
|
|
defaults.custom = lodashSet({ ...defaults.custom }, name, value);
|
|
}
|
|
} else if (remove) {
|
|
defaults = omit(defaults, name);
|
|
} else {
|
|
defaults = lodashSet({ ...defaults }, name, value);
|
|
}
|
|
|
|
return {
|
|
...config,
|
|
defaults,
|
|
};
|
|
};
|