Skip to content

Commit

Permalink
[XY] Defaults the point size to 1 and corrects the vislib migrations (#…
Browse files Browse the repository at this point in the history
…118994) (#120718)

* [XY] Changes the default point size to 1 and corrects the vislib migrations

* Fixes the unit test

* Change the migration function to default te fitting function to linear

* Update src/plugins/visualizations/server/migrations/visualization_saved_object_migrations.test.ts

Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>

* Update src/plugins/visualizations/server/migrations/visualization_saved_object_migrations.ts

Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>

* Fixes on PR review

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
  • Loading branch information
3 people authored Dec 8, 2021
1 parent c9bf625 commit 9cd3925
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('getSeriesParams', () => {
);
expect(seriesParams).toStrictEqual([
{
circlesRadius: 3,
circlesRadius: 1,
data: {
id: '1',
label: 'Total quantity',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/public/utils/get_series_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const makeSerie = (
type: ChartType.Line,
drawLinesBetweenPoints: true,
showCircles: true,
circlesRadius: 3,
circlesRadius: 1,
interpolate: InterpolationMode.Linear,
lineWidth: 2,
valueAxis: defaultValueAxis,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/public/vis_types/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const areaVisTypeDefinition = {
drawLinesBetweenPoints: true,
lineWidth: 2,
showCircles: true,
circlesRadius: 3,
circlesRadius: 1,
interpolate: InterpolationMode.Linear,
valueAxis: 'ValueAxis-1',
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/public/vis_types/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const histogramVisTypeDefinition = {
drawLinesBetweenPoints: true,
lineWidth: 2,
showCircles: true,
circlesRadius: 3,
circlesRadius: 1,
},
],
radiusRatio: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const horizontalBarVisTypeDefinition = {
drawLinesBetweenPoints: true,
lineWidth: 2,
showCircles: true,
circlesRadius: 3,
circlesRadius: 1,
},
],
addTooltip: true,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/public/vis_types/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const lineVisTypeDefinition = {
lineWidth: 2,
interpolate: InterpolationMode.Linear,
showCircles: true,
circlesRadius: 3,
circlesRadius: 1,
},
],
addTooltip: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,8 @@ describe('migration visualization', () => {
type = 'area',
categoryAxes?: object[],
valueAxes?: object[],
hasPalette = false
hasPalette = false,
hasCirclesRadius = false
) => ({
attributes: {
title: 'My Vis',
Expand All @@ -1694,6 +1695,21 @@ describe('migration visualization', () => {
labels: {},
},
],
seriesParams: [
{
show: true,
type,
mode: 'stacked',
drawLinesBetweenPoints: true,
lineWidth: 2,
showCircles: true,
interpolate: 'linear',
valueAxis: 'ValueAxis-1',
...(hasCirclesRadius && {
circlesRadius: 3,
}),
},
],
...(hasPalette && {
palette: {
type: 'palette',
Expand Down Expand Up @@ -1732,6 +1748,20 @@ describe('migration visualization', () => {
expect(palette.name).toEqual('default');
});

it("should decorate existing docs with the circlesRadius attribute if it doesn't exist", () => {
const migratedTestDoc = migrate(getTestDoc());
const [result] = JSON.parse(migratedTestDoc.attributes.visState).params.seriesParams;

expect(result.circlesRadius).toEqual(1);
});

it('should not decorate existing docs with the circlesRadius attribute if it exists', () => {
const migratedTestDoc = migrate(getTestDoc('area', undefined, undefined, true, true));
const [result] = JSON.parse(migratedTestDoc.attributes.visState).params.seriesParams;

expect(result.circlesRadius).toEqual(3);
});

describe('labels.filter', () => {
it('should keep existing categoryAxes labels.filter value', () => {
const migratedTestDoc = migrate(getTestDoc('area', [{ labels: { filter: false } }]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,20 @@ const decorateAxes = <T extends { labels: { filter?: boolean } }>(
},
}));

/**
* Defaults circlesRadius to 1 if it is not configured
*/
const addCirclesRadius = <T extends { circlesRadius: number }>(axes: T[]): T[] =>
axes.map((axis) => {
const hasCircleRadiusAttribute = Number.isFinite(axis?.circlesRadius);
return {
...axis,
...(!hasCircleRadiusAttribute && {
circlesRadius: 1,
}),
};
});

// Inlined from vis_type_xy
const CHART_TYPE_AREA = 'area';
const CHART_TYPE_LINE = 'line';
Expand Down Expand Up @@ -912,10 +926,12 @@ const migrateVislibAreaLineBarTypes: SavedObjectMigrationFn<any, any> = (doc) =>
valueAxes:
visState.params.valueAxes &&
decorateAxes(visState.params.valueAxes, isHorizontalBar),
seriesParams:
visState.params.seriesParams && addCirclesRadius(visState.params.seriesParams),
isVislibVis: true,
detailedTooltip: true,
...(isLineOrArea && {
fittingFunction: 'zero',
fittingFunction: 'linear',
}),
},
}),
Expand Down

0 comments on commit 9cd3925

Please sign in to comment.