Graph: support setting field units (#26529)

This commit is contained in:
Ryan McKinley 2020-07-23 11:00:19 -07:00 committed by GitHub
parent 43ef052d57
commit ad5f1c953b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -13,7 +13,10 @@
<div ng-if="yaxis.show"> <div ng-if="yaxis.show">
<div class="gf-form gf-form--grow"> <div class="gf-form gf-form--grow">
<label class="gf-form-label width-6">Unit</label> <label class="gf-form-label width-6">
Unit
<info-popover mode="right-normal">The default unit used when not defined by the datasource or in the Fields or Overrides configuration.</info-popover>
</label>
<unit-picker onChange="ctrl.setUnitFormat(yaxis)" value="yaxis.format" class="flex-grow-1" /> <unit-picker onChange="ctrl.setUnitFormat(yaxis)" value="yaxis.format" class="flex-grow-1" />
</div> </div>
</div> </div>

View File

@ -305,6 +305,7 @@ export class GraphCtrl extends MetricsPanelCtrl {
for (const series of this.seriesList) { for (const series of this.seriesList) {
series.applySeriesOverrides(this.panel.seriesOverrides); series.applySeriesOverrides(this.panel.seriesOverrides);
// Always use the configured field unit
if (series.unit) { if (series.unit) {
this.panel.yaxes[series.yaxis - 1].format = series.unit; this.panel.yaxes[series.yaxis - 1].format = series.unit;
} }
@ -378,6 +379,7 @@ export const plugin = new PanelPlugin<GraphPanelOptions, GraphFieldConfig>(null)
.useFieldConfig({ .useFieldConfig({
standardOptions: [ standardOptions: [
FieldConfigProperty.DisplayName, FieldConfigProperty.DisplayName,
FieldConfigProperty.Unit,
FieldConfigProperty.Links, // previously saved as dataLinks on options FieldConfigProperty.Links, // previously saved as dataLinks on options
], ],
}) })