Skip to content

Commit 3b5d11a

Browse files
[7.9] Fix float percentiles line chart (#71902) (#72394)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 2a1ce2b commit 3b5d11a

File tree

6 files changed

+1586
-312
lines changed

6 files changed

+1586
-312
lines changed

src/plugins/vis_type_vislib/public/vislib/lib/types/point_series.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ import _ from 'lodash';
2121
import { i18n } from '@kbn/i18n';
2222

2323
function getSeriId(seri) {
24-
return seri.id && seri.id.indexOf('.') !== -1 ? seri.id.split('.')[0] : seri.id;
24+
if (!seri.id) {
25+
return;
26+
}
27+
// Ideally the format should be either ID or "ID.SERIES"
28+
// but for some values the SERIES components gets a bit more complex
29+
30+
// Float values are serialized as strings tuples (i.e. ['99.1']) rather than regular numbers (99.1)
31+
// so the complete ids are in the format ID.['SERIES']: hence the specific brackets handler
32+
const bracketsMarker = seri.id.indexOf('[');
33+
if (bracketsMarker > -1) {
34+
return seri.id.substring(0, bracketsMarker);
35+
}
36+
// Here's the dot check is enough
37+
if (seri.id.indexOf('.') > -1) {
38+
return seri.id.split('.')[0];
39+
}
40+
return seri.id;
2541
}
2642

2743
const createSeriesFromParams = (cfg, seri) => {

src/plugins/vis_type_vislib/public/vislib/lib/types/point_series.test.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import stackedSeries from '../../../fixtures/mock_data/date_histogram/_stacked_s
2020
import { vislibPointSeriesTypes } from './point_series';
2121
import percentileTestdata from './testdata_linechart_percentile.json';
2222
import percentileTestdataResult from './testdata_linechart_percentile_result.json';
23+
import percentileTestdataFloatValue from './testdata_linechart_percentile_float_value.json';
24+
import percentileTestdataFloatValueResult from './testdata_linechart_percentile_float_value_result.json';
2325

2426
const maxBucketData = {
2527
get: (prop) => {
@@ -215,18 +217,26 @@ describe('Point Series Config Type Class Test Suite', function () {
215217
});
216218

217219
describe('line chart', function () {
218-
beforeEach(function () {
220+
function prepareData({ cfg, data }) {
219221
const percentileDataObj = {
220222
get: (prop) => {
221223
return maxBucketData[prop] || maxBucketData.data[prop] || null;
222224
},
223225
getLabels: () => [],
224-
data: percentileTestdata.data,
226+
data: data,
225227
};
226-
parsedConfig = vislibPointSeriesTypes.line(percentileTestdata.cfg, percentileDataObj);
227-
});
228+
const parsedConfig = vislibPointSeriesTypes.line(cfg, percentileDataObj);
229+
return parsedConfig;
230+
}
231+
228232
it('should render a percentile line chart', function () {
229-
expect(JSON.stringify(parsedConfig)).toEqual(JSON.stringify(percentileTestdataResult));
233+
const parsedConfig = prepareData(percentileTestdata);
234+
expect(parsedConfig).toMatchObject(percentileTestdataResult);
235+
});
236+
237+
it('should render a percentile line chart when value is float', function () {
238+
const parsedConfig = prepareData(percentileTestdataFloatValue);
239+
expect(parsedConfig).toMatchObject(percentileTestdataFloatValueResult);
230240
});
231241
});
232242
});

0 commit comments

Comments
 (0)