mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeSeries: Separate field unit config for axis ticks and other display means when stacking by percent (#43713)
This commit is contained in:
parent
737bc35219
commit
4b814dbcea
@ -11,6 +11,7 @@ import {
|
|||||||
getFieldColorModeForField,
|
getFieldColorModeForField,
|
||||||
getFieldSeriesColor,
|
getFieldSeriesColor,
|
||||||
getFieldDisplayName,
|
getFieldDisplayName,
|
||||||
|
getDisplayProcessor,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
|
||||||
import { UPlotConfigBuilder, UPlotConfigPrepFn } from '../uPlot/config/UPlotConfigBuilder';
|
import { UPlotConfigBuilder, UPlotConfigPrepFn } from '../uPlot/config/UPlotConfigBuilder';
|
||||||
@ -23,6 +24,7 @@ import {
|
|||||||
ScaleDirection,
|
ScaleDirection,
|
||||||
ScaleOrientation,
|
ScaleOrientation,
|
||||||
VizLegendOptions,
|
VizLegendOptions,
|
||||||
|
StackingMode,
|
||||||
} from '@grafana/schema';
|
} from '@grafana/schema';
|
||||||
import { collectStackingGroups, orderIdsByCalcs, preparePlotData } from '../uPlot/utils';
|
import { collectStackingGroups, orderIdsByCalcs, preparePlotData } from '../uPlot/utils';
|
||||||
import uPlot from 'uplot';
|
import uPlot from 'uplot';
|
||||||
@ -135,8 +137,19 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ sync: DashboardCursor
|
|||||||
// TODO: skip this for fields with custom renderers?
|
// TODO: skip this for fields with custom renderers?
|
||||||
field.state!.seriesIndex = seriesIndex++;
|
field.state!.seriesIndex = seriesIndex++;
|
||||||
|
|
||||||
const fmt = field.display ?? defaultFormatter;
|
let fmt = field.display ?? defaultFormatter;
|
||||||
|
if (field.config.custom?.stacking?.mode === StackingMode.Percent) {
|
||||||
|
fmt = getDisplayProcessor({
|
||||||
|
field: {
|
||||||
|
...field,
|
||||||
|
config: {
|
||||||
|
...field.config,
|
||||||
|
unit: 'percentunit',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
theme,
|
||||||
|
});
|
||||||
|
}
|
||||||
const scaleKey = buildScaleKey(config);
|
const scaleKey = buildScaleKey(config);
|
||||||
const colorMode = getFieldColorModeForField(field);
|
const colorMode = getFieldColorModeForField(field);
|
||||||
const scaleColor = getFieldSeriesColor(field, theme);
|
const scaleColor = getFieldSeriesColor(field, theme);
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
isBooleanUnit,
|
isBooleanUnit,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { GraphFieldConfig, LineInterpolation, StackingMode } from '@grafana/schema';
|
import { GraphFieldConfig, LineInterpolation } from '@grafana/schema';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns null if there are no graphable fields
|
* Returns null if there are no graphable fields
|
||||||
@ -47,11 +47,6 @@ export function prepareGraphableFields(series: DataFrame[], theme: GrafanaTheme2
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (copy.config.custom?.stacking?.mode === StackingMode.Percent) {
|
|
||||||
copy.config.unit = 'percentunit';
|
|
||||||
copy.display = getDisplayProcessor({ field: copy, theme });
|
|
||||||
}
|
|
||||||
|
|
||||||
fields.push(copy);
|
fields.push(copy);
|
||||||
break; // ok
|
break; // ok
|
||||||
case FieldType.boolean:
|
case FieldType.boolean:
|
||||||
|
Loading…
Reference in New Issue
Block a user