The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/packages/grafana-ui/src/options/builder/axis.tsx

162 lines
3.8 KiB

import React from 'react';
import {
FieldConfigEditorBuilder,
FieldOverrideEditorProps,
FieldType,
identityOverrideProcessor,
SelectableValue,
} from '@grafana/data';
import { graphFieldOptions, Select, HorizontalGroup, RadioButtonGroup } from '../../index';
import { AxisConfig, AxisPlacement, ScaleDistribution, ScaleDistributionConfig } from '@grafana/schema';
/**
* @alpha
*/
export function addAxisConfig(
builder: FieldConfigEditorBuilder<AxisConfig>,
defaultConfig: AxisConfig,
hideScale?: boolean
) {
const category = ['Axis'];
builder
.addRadio({
path: 'axisPlacement',
name: 'Placement',
category,
defaultValue: graphFieldOptions.axisPlacement[0].value,
settings: {
options: graphFieldOptions.axisPlacement,
},
})
.addTextInput({
path: 'axisLabel',
name: 'Label',
category,
defaultValue: '',
settings: {
placeholder: 'Optional text',
},
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
// no matter what the field type is
shouldApply: () => true,
})
.addNumberInput({
path: 'axisWidth',
name: 'Width',
category,
settings: {
placeholder: 'Auto',
},
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
})
.addNumberInput({
path: 'axisSoftMin',
name: 'Soft min',
defaultValue: defaultConfig.axisSoftMin,
category,
settings: {
placeholder: 'See: Standard options > Min',
},
})
.addNumberInput({
path: 'axisSoftMax',
name: 'Soft max',
defaultValue: defaultConfig.axisSoftMax,
category,
settings: {
placeholder: 'See: Standard options > Max',
},
})
.addRadio({
path: 'axisGridShow',
name: 'Show grid lines',
category,
defaultValue: undefined,
settings: {
options: [
{ value: undefined, label: 'Auto' },
{ value: true, label: 'On' },
{ value: false, label: 'Off' },
],
},
});
if (!hideScale) {
builder.addCustomEditor<void, ScaleDistributionConfig>({
id: 'scaleDistribution',
path: 'scaleDistribution',
name: 'Scale',
category,
editor: ScaleDistributionEditor,
override: ScaleDistributionEditor,
defaultValue: { type: ScaleDistribution.Linear },
shouldApply: (f) => f.type === FieldType.number,
process: identityOverrideProcessor,
});
}
}
const DISTRIBUTION_OPTIONS: Array<SelectableValue<ScaleDistribution>> = [
{
label: 'Linear',
value: ScaleDistribution.Linear,
},
{
label: 'Logarithmic',
value: ScaleDistribution.Log,
},
];
const LOG_DISTRIBUTION_OPTIONS: Array<SelectableValue<number>> = [
{
label: '2',
value: 2,
},
{
label: '10',
value: 10,
},
];
/**
* @alpha
*/
const ScaleDistributionEditor: React.FC<FieldOverrideEditorProps<ScaleDistributionConfig, any>> = ({
value,
onChange,
}) => {
return (
<HorizontalGroup>
<RadioButtonGroup
value={value.type || ScaleDistribution.Linear}
options={DISTRIBUTION_OPTIONS}
onChange={(v) => {
console.log(v, value);
onChange({
...value,
type: v!,
log: v === ScaleDistribution.Linear ? undefined : 2,
});
}}
/>
{value.type === ScaleDistribution.Log && (
<Select
Select: Make portalling the menu opt-in, but opt-in *everywhere* (#37501) * Select: Don't portal by default * Select: Portal all the Selects * Fix indendentation in this comment * Select: Remove @example docs until formatting is correct * Docs: Add some documentation for the Select changes * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update packages/grafana-ui/src/components/Select/types.ts Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/prepareTimeSeries/PrepareTimeSeriesEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Docs: Variants instead of varients * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
4 years ago
menuShouldPortal
allowCustomValue={false}
autoFocus
options={LOG_DISTRIBUTION_OPTIONS}
value={value.log || 2}
prefix={'base'}
width={12}
onChange={(v) => {
onChange({
...value,
log: v.value!,
});
}}
/>
)}
</HorizontalGroup>
);
};