mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
TimeSeries: Migration from old graph legend values (#34997)
* fix(timeseries): filter enabled graph legend values when migrating * test(timeseries): update snapshots * test(timeseries): add additional tests for legend
This commit is contained in:
parent
a9f652ab7a
commit
cb3c317e81
@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Graph Migrations legend 1`] = `
|
||||
exports[`Graph Migrations legend with multiple values 1`] = `
|
||||
Object {
|
||||
"fieldConfig": Object {
|
||||
"defaults": Object {
|
||||
@ -39,8 +39,6 @@ Object {
|
||||
"calcs": Array [
|
||||
"mean",
|
||||
"lastNotNull",
|
||||
"max",
|
||||
"min",
|
||||
"sum",
|
||||
],
|
||||
"displayMode": "table",
|
||||
@ -53,6 +51,56 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Graph Migrations legend with single value 1`] = `
|
||||
Object {
|
||||
"fieldConfig": Object {
|
||||
"defaults": Object {
|
||||
"custom": Object {
|
||||
"drawStyle": "points",
|
||||
"spanNulls": false,
|
||||
},
|
||||
},
|
||||
"overrides": Array [],
|
||||
},
|
||||
"options": Object {
|
||||
"legend": Object {
|
||||
"calcs": Array [
|
||||
"sum",
|
||||
],
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
},
|
||||
"tooltip": Object {
|
||||
"mode": "single",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Graph Migrations legend without values 1`] = `
|
||||
Object {
|
||||
"fieldConfig": Object {
|
||||
"defaults": Object {
|
||||
"custom": Object {
|
||||
"drawStyle": "points",
|
||||
"spanNulls": false,
|
||||
},
|
||||
},
|
||||
"overrides": Array [],
|
||||
},
|
||||
"options": Object {
|
||||
"legend": Object {
|
||||
"calcs": Array [],
|
||||
"displayMode": "list",
|
||||
"placement": "bottom",
|
||||
},
|
||||
"tooltip": Object {
|
||||
"mode": "single",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Graph Migrations simple bars 1`] = `
|
||||
Object {
|
||||
"fieldConfig": Object {
|
||||
@ -152,8 +200,6 @@ Object {
|
||||
"calcs": Array [
|
||||
"mean",
|
||||
"lastNotNull",
|
||||
"max",
|
||||
"min",
|
||||
"sum",
|
||||
],
|
||||
"displayMode": "table",
|
||||
@ -209,8 +255,6 @@ Object {
|
||||
"calcs": Array [
|
||||
"mean",
|
||||
"lastNotNull",
|
||||
"max",
|
||||
"min",
|
||||
"sum",
|
||||
],
|
||||
"displayMode": "table",
|
||||
|
@ -40,13 +40,51 @@ describe('Graph Migrations', () => {
|
||||
expect(panel).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('legend', () => {
|
||||
const old: any = {
|
||||
angular: legend,
|
||||
};
|
||||
const panel = {} as PanelModel;
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old);
|
||||
expect(panel).toMatchSnapshot();
|
||||
describe('legend', () => {
|
||||
test('without values', () => {
|
||||
const old: any = {
|
||||
angular: {
|
||||
legend: {
|
||||
show: true,
|
||||
values: false,
|
||||
min: false,
|
||||
max: false,
|
||||
current: false,
|
||||
total: false,
|
||||
avg: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const panel = {} as PanelModel;
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old);
|
||||
expect(panel).toMatchSnapshot();
|
||||
});
|
||||
test('with single value', () => {
|
||||
const old: any = {
|
||||
angular: {
|
||||
legend: {
|
||||
show: true,
|
||||
values: true,
|
||||
min: false,
|
||||
max: false,
|
||||
current: false,
|
||||
total: true,
|
||||
avg: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const panel = {} as PanelModel;
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old);
|
||||
expect(panel).toMatchSnapshot();
|
||||
});
|
||||
test('with multiple values', () => {
|
||||
const old: any = {
|
||||
angular: legend,
|
||||
};
|
||||
const panel = {} as PanelModel;
|
||||
panel.options = graphPanelChangedHandler(panel, 'graph', old);
|
||||
expect(panel).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('stacking', () => {
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
TooltipDisplayMode,
|
||||
} from '@grafana/ui';
|
||||
import { TimeSeriesOptions } from './types';
|
||||
import { omitBy, isNil, isNumber, isString } from 'lodash';
|
||||
import { omitBy, pickBy, isNil, isNumber, isString } from 'lodash';
|
||||
import { defaultGraphConfig } from './config';
|
||||
|
||||
/**
|
||||
@ -314,7 +314,8 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
|
||||
}
|
||||
|
||||
if (angular.legend.values) {
|
||||
options.legend.calcs = getReducersFromLegend(angular.legend);
|
||||
const enabledLegendValues = pickBy(angular.legend);
|
||||
options.legend.calcs = getReducersFromLegend(enabledLegendValues);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user