-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
match visualization type to first series type when available (#119377)
- Loading branch information
1 parent
13e0310
commit 57134d4
Showing
10 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/plugins/vis_types/xy/public/vis_types/get_vis_type_from_params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { VisParams } from 'src/plugins/visualizations/common'; | ||
import { getVisTypeFromParams } from './get_vis_type_from_params'; | ||
|
||
describe('extracting visualization type from vis params', () => { | ||
[ | ||
{ | ||
message: 'return undefined when no params', | ||
params: undefined, | ||
expectedType: undefined, | ||
}, | ||
{ | ||
message: 'extract a line type', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'line', | ||
}, | ||
], | ||
} as VisParams, | ||
expectedType: 'line', | ||
}, | ||
{ | ||
message: 'extract an area type', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'area', | ||
}, | ||
], | ||
} as VisParams, | ||
expectedType: 'area', | ||
}, | ||
{ | ||
message: 'extract a histogram type when axes not defined', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'histogram', | ||
}, | ||
], | ||
} as VisParams, | ||
expectedType: 'histogram', | ||
}, | ||
{ | ||
message: 'extract a histogram type when first axis on bottom', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'histogram', | ||
}, | ||
], | ||
categoryAxes: [{ position: 'bottom' }], | ||
} as VisParams, | ||
expectedType: 'histogram', | ||
}, | ||
{ | ||
message: 'extract a histogram type when first axis on top', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'histogram', | ||
}, | ||
], | ||
categoryAxes: [{ position: 'top' }], | ||
} as VisParams, | ||
expectedType: 'histogram', | ||
}, | ||
{ | ||
message: 'extract a horizontal_bar type when first axis to left', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'histogram', | ||
}, | ||
], | ||
categoryAxes: [{ position: 'left' }], | ||
} as VisParams, | ||
expectedType: 'horizontal_bar', | ||
}, | ||
{ | ||
message: 'extract a horizontal_bar type when first axis to right', | ||
params: { | ||
seriesParams: [ | ||
{ | ||
type: 'histogram', | ||
}, | ||
], | ||
categoryAxes: [{ position: 'right' }], | ||
} as VisParams, | ||
expectedType: 'horizontal_bar', | ||
}, | ||
].forEach(({ message, params, expectedType }) => | ||
it(message, () => { | ||
expect(getVisTypeFromParams(params)).toBe(expectedType); | ||
}) | ||
); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/plugins/vis_types/xy/public/vis_types/get_vis_type_from_params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { VisParams } from 'src/plugins/visualizations/common'; | ||
|
||
export const getVisTypeFromParams = (params?: VisParams) => { | ||
let type = params?.seriesParams?.[0]?.type; | ||
if (type === 'histogram' && ['left', 'right'].includes(params?.categoryAxes?.[0]?.position)) { | ||
type = 'horizontal_bar'; | ||
} | ||
return type; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters