mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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 }) {
|
setUnitFormat(axis: { format: any }) {
|
||||||
return (unit: string) => {
|
return (unit: string) => {
|
||||||
axis.format = unit;
|
axis.format = unit;
|
||||||
|
// 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();
|
this.panelCtrl.render();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +156,7 @@ export class GraphCtrl extends MetricsPanelCtrl {
|
|||||||
this.useDataFrames = true;
|
this.useDataFrames = true;
|
||||||
this.processor = new DataProcessor(this.panel);
|
this.processor = new DataProcessor(this.panel);
|
||||||
this.contextMenuCtrl = new GraphContextMenuCtrl($scope);
|
this.contextMenuCtrl = new GraphContextMenuCtrl($scope);
|
||||||
|
this.annotationsPromise = Promise.resolve({ annotations: [] });
|
||||||
|
|
||||||
this.events.on(PanelEvents.render, this.onRender.bind(this));
|
this.events.on(PanelEvents.render, this.onRender.bind(this));
|
||||||
this.events.on(PanelEvents.dataFramesReceived, this.onDataFramesReceived.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.editModeInitialized, this.onInitEditMode.bind(this));
|
||||||
this.events.on(PanelEvents.initPanelActions, this.onInitPanelActions.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() {
|
onInitEditMode() {
|
||||||
|
@ -78,6 +78,9 @@ describe('grafanaGraph', () => {
|
|||||||
tooltip: {
|
tooltip: {
|
||||||
shared: true,
|
shared: true,
|
||||||
},
|
},
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
renderingCompleted: jest.fn(),
|
renderingCompleted: jest.fn(),
|
||||||
hiddenSeries: {},
|
hiddenSeries: {},
|
||||||
|
@ -30,6 +30,9 @@ describe('GraphCtrl', () => {
|
|||||||
gridPos: {
|
gridPos: {
|
||||||
w: 100,
|
w: 100,
|
||||||
},
|
},
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = {} as any;
|
const ctx = {} as any;
|
||||||
|
Loading…
Reference in New Issue
Block a user