Commit 205dc0a2 by Torkel Ödegaard Committed by GitHub

Graph: Make axes unit option work even when field option unit is set (#31205)

* Graph: Make axes unit option work even when field option unit is set

* Updated tests
parent 12dcba5d
......@@ -51,7 +51,13 @@ export class AxesEditorCtrl {
setUnitFormat(axis: { format: any }) {
return (unit: string) => {
axis.format = unit;
this.panelCtrl.render();
// if already set via field config we need to update that as well
if (this.panel.fieldConfig.defaults.unit) {
this.panel.fieldConfig.defaults.unit = unit;
this.panelCtrl.refresh();
} else {
this.panelCtrl.render();
}
};
}
......
......@@ -156,6 +156,7 @@ export class GraphCtrl extends MetricsPanelCtrl {
this.useDataFrames = true;
this.processor = new DataProcessor(this.panel);
this.contextMenuCtrl = new GraphContextMenuCtrl($scope);
this.annotationsPromise = Promise.resolve({ annotations: [] });
this.events.on(PanelEvents.render, this.onRender.bind(this));
this.events.on(PanelEvents.dataFramesReceived, this.onDataFramesReceived.bind(this));
......@@ -163,7 +164,11 @@ export class GraphCtrl extends MetricsPanelCtrl {
this.events.on(PanelEvents.editModeInitialized, this.onInitEditMode.bind(this));
this.events.on(PanelEvents.initPanelActions, this.onInitPanelActions.bind(this));
this.annotationsPromise = Promise.resolve({ annotations: [] });
// set axes format from field config
const fieldConfigUnit = this.panel.fieldConfig.defaults.unit;
if (fieldConfigUnit) {
this.panel.yaxes[0].format = fieldConfigUnit;
}
}
onInitEditMode() {
......
......@@ -78,6 +78,9 @@ describe('grafanaGraph', () => {
tooltip: {
shared: true,
},
fieldConfig: {
defaults: {},
},
},
renderingCompleted: jest.fn(),
hiddenSeries: {},
......
......@@ -30,6 +30,9 @@ describe('GraphCtrl', () => {
gridPos: {
w: 100,
},
fieldConfig: {
defaults: {},
},
};
const ctx = {} as any;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment