diff --git a/packages/grafana-ui/src/components/BarChart/BarChart.tsx b/packages/grafana-ui/src/components/BarChart/BarChart.tsx index 38baeb67cd5..15e820be7f4 100644 --- a/packages/grafana-ui/src/components/BarChart/BarChart.tsx +++ b/packages/grafana-ui/src/components/BarChart/BarChart.tsx @@ -105,6 +105,8 @@ class UnthemedBarChart extends React.Component { config={config} onSeriesColorChange={onSeriesColorChange} onLegendClick={onLegendClick} + maxHeight="35%" + maxWidth="60%" {...legend} /> ); diff --git a/packages/grafana-ui/src/components/GraphNG/GraphNG.tsx b/packages/grafana-ui/src/components/GraphNG/GraphNG.tsx index e07776bd473..b5a1485e278 100755 --- a/packages/grafana-ui/src/components/GraphNG/GraphNG.tsx +++ b/packages/grafana-ui/src/components/GraphNG/GraphNG.tsx @@ -165,6 +165,8 @@ class UnthemedGraphNG extends React.Component { config={config} onSeriesColorChange={onSeriesColorChange} onLegendClick={onLegendClick} + maxHeight="35%" + maxWidth="60%" {...legend} /> ); diff --git a/packages/grafana-ui/src/components/VizLayout/VizLayout.tsx b/packages/grafana-ui/src/components/VizLayout/VizLayout.tsx index 1503b8c39ac..966bfcb2293 100644 --- a/packages/grafana-ui/src/components/VizLayout/VizLayout.tsx +++ b/packages/grafana-ui/src/components/VizLayout/VizLayout.tsx @@ -94,9 +94,9 @@ interface VizSize { */ export interface VizLayoutLegendProps { placement: LegendPlacement; + children: React.ReactNode; maxHeight?: string; maxWidth?: string; - children: React.ReactNode; } /** diff --git a/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx b/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx index f9beaf2aacc..a460246e081 100644 --- a/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx +++ b/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx @@ -3,14 +3,14 @@ import { DataFrame, DisplayValue, fieldReducers, reduceField } from '@grafana/da import { UPlotConfigBuilder } from './config/UPlotConfigBuilder'; import { VizLegendItem, VizLegendOptions } from '../VizLegend/types'; import { AxisPlacement } from './config'; -import { VizLayout } from '../VizLayout/VizLayout'; +import { VizLayout, VizLayoutLegendProps } from '../VizLayout/VizLayout'; import { mapMouseEventToMode } from '../GraphNG/utils'; import { VizLegend } from '../VizLegend/VizLegend'; import { GraphNGLegendEvent } from '..'; const defaultFormatter = (v: any) => (v == null ? '-' : v.toFixed(1)); -interface PlotLegendProps extends VizLegendOptions { +interface PlotLegendProps extends VizLegendOptions, Omit { data: DataFrame[]; config: UPlotConfigBuilder; onSeriesColorChange?: (label: string, color: string) => void; @@ -22,7 +22,10 @@ export const PlotLegend: React.FC = ({ config, onSeriesColorChange, onLegendClick, - ...legend + placement, + calcs, + displayMode, + ...vizLayoutLegendProps }) => { const onLegendLabelClick = useCallback( (legend: VizLegendItem, event: React.MouseEvent) => { @@ -60,17 +63,17 @@ export const PlotLegend: React.FC = ({ label: seriesConfig.fieldName, yAxis: axisPlacement === AxisPlacement.Left ? 1 : 2, getDisplayValues: () => { - if (!legend.calcs?.length) { + if (!calcs?.length) { return []; } const fmt = field.display ?? defaultFormatter; const fieldCalcs = reduceField({ field, - reducers: legend.calcs, + reducers: calcs, }); - return legend.calcs.map((reducer) => { + return calcs.map((reducer) => { return { ...fmt(fieldCalcs[reducer]), title: fieldReducers.get(reducer).name, @@ -82,12 +85,12 @@ export const PlotLegend: React.FC = ({ .filter((i) => i !== undefined) as VizLegendItem[]; return ( - +