Set XAxis ordered.interval differently for date and numeric values in histogram (#38824) (#40638)

* Add test for numeric interval values
This commit is contained in:
Marco Vettorello 2019-07-10 09:21:13 +02:00 committed by GitHub
parent 5dd01dbe99
commit 8b59958a30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -106,8 +106,9 @@ describe('initXAxis', function () {
});
});
it('reads the interval param from the x agg', function () {
it('reads the date interval param from the x agg', function () {
chart.aspects.x[0].params.interval = 'P1D';
chart.aspects.x[0].params.date = true;
initXAxis(chart, table);
expect(chart)
.to.have.property('xAxisLabel', 'label')
@ -117,4 +118,15 @@ describe('initXAxis', function () {
expect(moment.isDuration(chart.ordered.interval)).to.be(true);
expect(chart.ordered.interval.toISOString()).to.eql('P1D');
});
it('reads the numeric interval param from the x agg', function () {
chart.aspects.x[0].params.interval = 0.5;
initXAxis(chart, table);
expect(chart)
.to.have.property('xAxisLabel', 'label')
.and.have.property('xAxisFormat', chart.aspects.x[0].format)
.and.have.property('ordered');
expect(chart.ordered.interval).to.eql(0.5);
});
});

View file

@ -28,9 +28,10 @@ export function initXAxis(chart, table) {
: uniq(table.rows.map(r => r[accessor]));
chart.xAxisFormat = format;
chart.xAxisLabel = title;
if (params.interval) {
chart.ordered = {
interval: moment.duration(params.interval),
interval: params.date ? moment.duration(params.interval) : params.interval,
};
}
}