mirror of
https://github.com/grafana/grafana.git
synced 2024-12-30 10:47:30 -06:00
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
This commit is contained in:
parent
12dcba5d0b
commit
205dc0a2f6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user