[v8.5.x] TimeSeries: Add an option to set legend width (#50549)
* TimeSeries: Add an option to set legend width (#49126)
* Add an option to set legend width
* Add width to the cue file
* Use legendStyle
Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
(cherry picked from commit a6693ba62f)
* Add missing migration
Co-authored-by: Ivan Babrou <github@ivan.computer>
This commit is contained in:
co-authored by
Ivan Babrou
parent
e9ec97b34c
commit
c114e3ff5c
@@ -272,6 +272,7 @@ export interface VizLegendOptions {
|
||||
placement: LegendPlacement;
|
||||
sortBy?: string;
|
||||
sortDesc?: boolean;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export enum BarGaugeDisplayMode {
|
||||
|
||||
@@ -11,5 +11,6 @@ VizLegendOptions: {
|
||||
isVisible?: bool
|
||||
sortBy?: string
|
||||
sortDesc?: bool
|
||||
width?: number
|
||||
calcs: [...string]
|
||||
} @cuetsy(kind="interface")
|
||||
|
||||
@@ -68,6 +68,11 @@ export const VizLayout: VizLayoutComponentType = ({ width, height, legend, child
|
||||
if (legendMeasure) {
|
||||
size = { width: width - legendMeasure.width, height };
|
||||
}
|
||||
|
||||
if (legend.props.width) {
|
||||
legendStyle.width = legend.props.width;
|
||||
size = { width: width - legend.props.width, height };
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -115,6 +120,7 @@ export interface VizLayoutLegendProps {
|
||||
children: React.ReactNode;
|
||||
maxHeight?: string;
|
||||
maxWidth?: string;
|
||||
width?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,15 @@ export function addLegendOptions<T extends OptionsWithLegend>(
|
||||
],
|
||||
},
|
||||
showIf: (c) => c.legend.displayMode !== LegendDisplayMode.Hidden,
|
||||
})
|
||||
.addNumberInput({
|
||||
path: 'legend.width',
|
||||
name: 'Width',
|
||||
category: ['Legend'],
|
||||
settings: {
|
||||
placeholder: 'Auto',
|
||||
},
|
||||
showIf: (c) => c.legend.displayMode !== LegendDisplayMode.Hidden && c.legend.placement === 'right',
|
||||
});
|
||||
|
||||
if (includeLegendCalcs) {
|
||||
|
||||
@@ -125,6 +125,23 @@ describe('Graph Migrations', () => {
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
|
||||
expect(panel).toMatchSnapshot();
|
||||
});
|
||||
test('with sideWidth', () => {
|
||||
const old: any = {
|
||||
angular: {
|
||||
legend: {
|
||||
alignAsTable: true,
|
||||
rightSide: true,
|
||||
show: true,
|
||||
sideWidth: 200,
|
||||
total: true,
|
||||
values: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
const panel = {} as PanelModel;
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
|
||||
expect(panel.options.legend.width).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stacking', () => {
|
||||
|
||||
@@ -345,6 +345,10 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
|
||||
const enabledLegendValues = pickBy(angular.legend);
|
||||
options.legend.calcs = getReducersFromLegend(enabledLegendValues);
|
||||
}
|
||||
|
||||
if (angular.legend.sideWidth) {
|
||||
options.legend.width = angular.legend.sideWidth;
|
||||
}
|
||||
}
|
||||
|
||||
const tooltipConfig = angular.tooltip;
|
||||
|
||||
Reference in New Issue
Block a user