-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes problem with one chart plotted for multiple y axis when migrati…
…ng from an old SO (#112972) * Fixes problem with one chart plotted for multiple y axis when migrationg from an old SO * Add unit tests * Address PR comments Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
7c27822
commit fa59b52
Showing
10 changed files
with
177 additions
and
60 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
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
64 changes: 64 additions & 0 deletions
64
src/plugins/vis_types/xy/public/utils/get_series_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,64 @@ | ||
/* | ||
* 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 type { AggConfigs } from '../../../../data/public'; | ||
import type { SeriesParam } from '../types'; | ||
import { getSeriesParams } from './get_series_params'; | ||
import { sampleAreaVis } from '../sample_vis.test.mocks'; | ||
|
||
describe('getSeriesParams', () => { | ||
it('returns correct params', () => { | ||
const seriesParams = getSeriesParams( | ||
sampleAreaVis.data.aggs as unknown as AggConfigs, | ||
sampleAreaVis.params.seriesParams as unknown as SeriesParam[], | ||
'metric', | ||
'ValueAxis-1' | ||
); | ||
expect(seriesParams).toStrictEqual([ | ||
{ | ||
circlesRadius: 5, | ||
data: { | ||
id: '1', | ||
label: 'Total quantity', | ||
}, | ||
drawLinesBetweenPoints: true, | ||
interpolate: 'linear', | ||
mode: 'stacked', | ||
show: 'true', | ||
showCircles: true, | ||
type: 'area', | ||
valueAxis: 'ValueAxis-1', | ||
}, | ||
]); | ||
}); | ||
|
||
it('returns default params if no params provided', () => { | ||
const seriesParams = getSeriesParams( | ||
sampleAreaVis.data.aggs as unknown as AggConfigs, | ||
[], | ||
'metric', | ||
'ValueAxis-1' | ||
); | ||
expect(seriesParams).toStrictEqual([ | ||
{ | ||
circlesRadius: 3, | ||
data: { | ||
id: '1', | ||
label: 'Total quantity', | ||
}, | ||
drawLinesBetweenPoints: true, | ||
interpolate: 'linear', | ||
lineWidth: 2, | ||
mode: 'normal', | ||
show: true, | ||
showCircles: true, | ||
type: 'line', | ||
valueAxis: 'ValueAxis-1', | ||
}, | ||
]); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/plugins/vis_types/xy/public/utils/get_series_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,63 @@ | ||
/* | ||
* 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 { ValueAxis, SeriesParam, ChartMode, InterpolationMode } from '../types'; | ||
import { ChartType } from '../../common'; | ||
import type { AggConfigs } from '../../../../data/public'; | ||
|
||
const makeSerie = ( | ||
id: string, | ||
label: string, | ||
defaultValueAxis: ValueAxis['id'], | ||
lastSerie?: SeriesParam | ||
): SeriesParam => { | ||
const data = { id, label }; | ||
const defaultSerie = { | ||
show: true, | ||
mode: ChartMode.Normal, | ||
type: ChartType.Line, | ||
drawLinesBetweenPoints: true, | ||
showCircles: true, | ||
circlesRadius: 3, | ||
interpolate: InterpolationMode.Linear, | ||
lineWidth: 2, | ||
valueAxis: defaultValueAxis, | ||
}; | ||
return { ...defaultSerie, ...lastSerie, data }; | ||
}; | ||
export const getSeriesParams = ( | ||
aggs: AggConfigs | undefined, | ||
seriesParams: SeriesParam[], | ||
schemaName: string, | ||
firstValueAxesId: string | ||
) => { | ||
const metrics = aggs?.bySchemaName(schemaName); | ||
|
||
return metrics?.map((agg) => { | ||
const params = seriesParams.find((param) => param.data.id === agg.id); | ||
const label = agg.makeLabel(); | ||
|
||
// update labels for existing params or create new one | ||
if (params) { | ||
return { | ||
...params, | ||
data: { | ||
...params.data, | ||
label, | ||
}, | ||
}; | ||
} else { | ||
const series = makeSerie( | ||
agg.id, | ||
label, | ||
firstValueAxesId, | ||
seriesParams[seriesParams.length - 1] | ||
); | ||
return series; | ||
} | ||
}); | ||
}; |
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