BarChart: show x tick picker (#43510)

This commit is contained in:
Ryan McKinley
2022-01-10 15:12:33 -08:00
committed by GitHub
parent 5e7804f466
commit 6b70e1af76
3 changed files with 72 additions and 15 deletions

View File

@ -0,0 +1,62 @@
import React from 'react';
import { SelectableValue, StandardEditorProps } from '@grafana/data';
import { Checkbox, HorizontalGroup, RadioButtonGroup, Tooltip } from '@grafana/ui';
const GAPS_OPTIONS: Array<SelectableValue<number>> = [
{
label: 'None',
value: 0,
description: 'Show all tick marks',
},
{
label: 'Small',
value: 100,
description: 'Require 100px spacing',
},
{
label: 'Medium',
value: 200,
description: 'Require 200px spacing',
},
{
label: 'Large',
value: 300,
description: 'Require 300px spacing',
},
];
export const TickSpacingEditor: React.FC<StandardEditorProps<number, any>> = (props) => {
let value = props.value ?? 0;
const isRTL = value < 0;
if (isRTL) {
value *= -1;
}
let gap = GAPS_OPTIONS[0];
for (const v of GAPS_OPTIONS) {
gap = v;
if (value <= gap.value!) {
break;
}
}
const onSpacingChange = (val: number) => {
props.onChange(val * (isRTL ? -1 : 1));
};
const onRTLChange = () => {
props.onChange(props.value * -1);
};
return (
<HorizontalGroup>
<RadioButtonGroup value={gap.value} options={GAPS_OPTIONS} onChange={onSpacingChange} />
{value !== 0 && (
<Tooltip content="Require space from the right side" placement="top">
<div>
<Checkbox value={isRTL} onChange={onRTLChange} label="RTL" />
</div>
</Tooltip>
)}
</HorizontalGroup>
);
};

View File

@ -28,7 +28,7 @@ export const defaultPanelOptions: Partial<PanelOptions> = {
stacking: StackingMode.None, stacking: StackingMode.None,
orientation: VizOrientation.Auto, orientation: VizOrientation.Auto,
xTickLabelRotation: 0, xTickLabelRotation: 0,
xTickLabelMaxLength: 0, xTickLabelSpacing: 0,
showValue: VisibilityMode.Auto, showValue: VisibilityMode.Auto,
groupWidth: 0.7, groupWidth: 0.7,
barWidth: 0.97, barWidth: 0.97,

View File

@ -14,6 +14,7 @@ import { BarChartFieldConfig, PanelOptions, defaultBarChartFieldConfig, defaultP
import { BarChartSuggestionsSupplier } from './suggestions'; import { BarChartSuggestionsSupplier } from './suggestions';
import { prepareBarChartDisplayValues } from './utils'; import { prepareBarChartDisplayValues } from './utils';
import { config } from '@grafana/runtime'; import { config } from '@grafana/runtime';
import { TickSpacingEditor } from './TickSpacingEditor';
export const plugin = new PanelPlugin<PanelOptions, BarChartFieldConfig>(BarChartPanel) export const plugin = new PanelPlugin<PanelOptions, BarChartFieldConfig>(BarChartPanel)
.useFieldConfig({ .useFieldConfig({
@ -113,23 +114,17 @@ export const plugin = new PanelPlugin<PanelOptions, BarChartFieldConfig>(BarChar
name: 'Bar label max length', name: 'Bar label max length',
description: 'Bar labels will be truncated to the length provided', description: 'Bar labels will be truncated to the length provided',
settings: { settings: {
placeholder: 'Auto', placeholder: 'None',
min: 0, min: 0,
}, },
}) })
// .addSliderInput({ .addCustomEditor({
// path: 'xTickLabelSpacing', id: 'xTickLabelSpacing',
// name: 'Bar label minimum spacing', path: 'xTickLabelSpacing',
// description: 'Bar labels will be skipped to maintain this distance', name: 'Bar labels minimum spacing',
// defaultValue: 0, defaultValue: defaultPanelOptions.xTickLabelSpacing,
// settings: { editor: TickSpacingEditor,
// min: -300, })
// max: 300,
// step: 10,
// marks: { '-300': 'Backward', 0: 'None', 300: 'Forward' },
// included: false,
// },
// })
.addRadio({ .addRadio({
path: 'showValue', path: 'showValue',
name: 'Show values', name: 'Show values',