mirror of https://github.com/grafana/grafana.git
Add option for aligning series names to the right
This commit is contained in:
parent
f01b1131e7
commit
68685f4224
|
|
@ -16,6 +16,7 @@ export interface TimelineProps extends Omit<GraphNGProps, 'prepConfig' | 'propsT
|
||||||
rowHeight?: number;
|
rowHeight?: number;
|
||||||
showValue: VisibilityMode;
|
showValue: VisibilityMode;
|
||||||
alignValue?: TimelineValueAlignment;
|
alignValue?: TimelineValueAlignment;
|
||||||
|
seriesNameAlignment?: 'left' | 'right';
|
||||||
colWidth?: number;
|
colWidth?: number;
|
||||||
legendItems?: VizLegendItem[];
|
legendItems?: VizLegendItem[];
|
||||||
tooltip?: VizTooltipOptions;
|
tooltip?: VizTooltipOptions;
|
||||||
|
|
@ -23,7 +24,16 @@ export interface TimelineProps extends Omit<GraphNGProps, 'prepConfig' | 'propsT
|
||||||
paginationRev?: string;
|
paginationRev?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const propsToDiff = ['rowHeight', 'colWidth', 'showValue', 'mergeValues', 'alignValue', 'tooltip', 'paginationRev'];
|
const propsToDiff = [
|
||||||
|
'rowHeight',
|
||||||
|
'colWidth',
|
||||||
|
'showValue',
|
||||||
|
'mergeValues',
|
||||||
|
'alignValue',
|
||||||
|
'seriesNameAlignment',
|
||||||
|
'tooltip',
|
||||||
|
'paginationRev',
|
||||||
|
];
|
||||||
|
|
||||||
export class TimelineChart extends Component<TimelineProps> {
|
export class TimelineChart extends Component<TimelineProps> {
|
||||||
getValueColor = (frameIdx: number, fieldIdx: number, value: unknown) => {
|
getValueColor = (frameIdx: number, fieldIdx: number, value: unknown) => {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ interface UPlotConfigOptions {
|
||||||
colWidth?: number;
|
colWidth?: number;
|
||||||
showValue: VisibilityMode;
|
showValue: VisibilityMode;
|
||||||
alignValue?: TimelineValueAlignment;
|
alignValue?: TimelineValueAlignment;
|
||||||
|
seriesNameAlignment?: 'left' | 'right';
|
||||||
mergeValues?: boolean;
|
mergeValues?: boolean;
|
||||||
getValueColor: (frameIdx: number, fieldIdx: number, value: unknown) => string;
|
getValueColor: (frameIdx: number, fieldIdx: number, value: unknown) => string;
|
||||||
hoverMulti: boolean;
|
hoverMulti: boolean;
|
||||||
|
|
@ -90,6 +91,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
||||||
colWidth,
|
colWidth,
|
||||||
showValue,
|
showValue,
|
||||||
alignValue,
|
alignValue,
|
||||||
|
seriesNameAlignment,
|
||||||
mergeValues,
|
mergeValues,
|
||||||
getValueColor,
|
getValueColor,
|
||||||
hoverMulti,
|
hoverMulti,
|
||||||
|
|
@ -181,11 +183,12 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
||||||
const yCustomConfig = frame.fields[1].config.custom;
|
const yCustomConfig = frame.fields[1].config.custom;
|
||||||
const yAxisWidth = yCustomConfig.axisWidth;
|
const yAxisWidth = yCustomConfig.axisWidth;
|
||||||
const yAxisHidden = yCustomConfig.axisPlacement === AxisPlacement.Hidden;
|
const yAxisHidden = yCustomConfig.axisPlacement === AxisPlacement.Hidden;
|
||||||
|
const yAxisPlacement = seriesNameAlignment === 'right' ? AxisPlacement.Right : AxisPlacement.Left;
|
||||||
|
|
||||||
builder.addAxis({
|
builder.addAxis({
|
||||||
scaleKey: FIXED_UNIT, // y
|
scaleKey: FIXED_UNIT, // y
|
||||||
isTime: false,
|
isTime: false,
|
||||||
placement: AxisPlacement.Left,
|
placement: yAxisPlacement,
|
||||||
splits: coreConfig.ySplits,
|
splits: coreConfig.ySplits,
|
||||||
values: yAxisHidden ? (u, splits) => splits.map((v) => null) : coreConfig.yValues,
|
values: yAxisHidden ? (u, splits) => splits.map((v) => null) : coreConfig.yValues,
|
||||||
grid: { show: false },
|
grid: { show: false },
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,18 @@ export const plugin = new PanelPlugin<Options, FieldConfig>(StateTimelinePanel)
|
||||||
},
|
},
|
||||||
defaultValue: defaultOptions.alignValue,
|
defaultValue: defaultOptions.alignValue,
|
||||||
})
|
})
|
||||||
|
.addRadio({
|
||||||
|
path: 'seriesNameAlignment',
|
||||||
|
name: t('state-timeline.name-align-series-names', 'Align series names'),
|
||||||
|
category,
|
||||||
|
settings: {
|
||||||
|
options: [
|
||||||
|
{ value: 'left', label: t('state-timeline.align-series-names-options.label-left', 'Left') },
|
||||||
|
{ value: 'right', label: t('state-timeline.align-series-names-options.label-right', 'Right') },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
defaultValue: 'left',
|
||||||
|
})
|
||||||
.addSliderInput({
|
.addSliderInput({
|
||||||
path: 'rowHeight',
|
path: 'rowHeight',
|
||||||
name: t('state-timeline.name-row-height', 'Row height'),
|
name: t('state-timeline.name-row-height', 'Row height'),
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ composableKinds: PanelCfg: {
|
||||||
mergeValues?: bool | *true
|
mergeValues?: bool | *true
|
||||||
//Controls value alignment on the timelines
|
//Controls value alignment on the timelines
|
||||||
alignValue?: ui.TimelineValueAlignment & (*"left" | _)
|
alignValue?: ui.TimelineValueAlignment & (*"left" | _)
|
||||||
|
//Controls series name alignment on the y-axis
|
||||||
|
seriesNameAlignment?: ("left" | "right") & (*"left" | _)
|
||||||
//Enables pagination when > 0
|
//Enables pagination when > 0
|
||||||
perPage?: number & >=1 | *20
|
perPage?: number & >=1 | *20
|
||||||
} @cuetsy(kind="interface")
|
} @cuetsy(kind="interface")
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ export interface Options extends ui.OptionsWithLegend, ui.OptionsWithTooltip, ui
|
||||||
* Controls the row height
|
* Controls the row height
|
||||||
*/
|
*/
|
||||||
rowHeight: number;
|
rowHeight: number;
|
||||||
|
/**
|
||||||
|
* Controls series name alignment on the y-axis
|
||||||
|
*/
|
||||||
|
seriesNameAlignment?: 'left' | 'right';
|
||||||
/**
|
/**
|
||||||
* Show timeline values on chart
|
* Show timeline values on chart
|
||||||
*/
|
*/
|
||||||
|
|
@ -38,6 +42,7 @@ export const defaultOptions: Partial<Options> = {
|
||||||
mergeValues: true,
|
mergeValues: true,
|
||||||
perPage: 20,
|
perPage: 20,
|
||||||
rowHeight: 0.9,
|
rowHeight: 0.9,
|
||||||
|
seriesNameAlignment: 'left',
|
||||||
showValue: ui.VisibilityMode.Auto,
|
showValue: ui.VisibilityMode.Auto,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue