Skip to content

Commit

Permalink
Fix tests for interval issue in vislib
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaDerevyankina committed Jan 16, 2021
1 parent b6ab151 commit ef45b63
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/plugins/vis_type_vislib/public/vislib/lib/axis/axis_scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import d3 from 'd3';
import _ from 'lodash';
import { range, isNumber, reduce, times } from 'lodash';
import moment from 'moment';

import { InvalidLogScaleValues } from '../../errors';
Expand Down Expand Up @@ -56,7 +56,8 @@ export class AxisScale {
getOrdinalDomain(values = []) {
if (this.ordered?.interval !== undefined) {
const [min, max] = this.getDomainExtent(values);
return _.range(min, max + this.ordered.interval, this.ordered.interval);
const valuesInterval = Math.ceil((max - min) / values.length);
return range(min, max + valuesInterval, valuesInterval);
}

return values;
Expand All @@ -82,7 +83,7 @@ export class AxisScale {

return d3[extent](
opts.reduce(function (opts, v) {
if (!_.isNumber(v)) v = +v;
if (!isNumber(v)) v = +v;
if (!isNaN(v)) opts.push(v);
return opts;
}, [])
Expand Down Expand Up @@ -110,7 +111,7 @@ export class AxisScale {
const y = moment(x);
const method = n > 0 ? 'add' : 'subtract';

_.times(Math.abs(n), function () {
times(Math.abs(n), function () {
y[method](interval);
});

Expand All @@ -120,7 +121,7 @@ export class AxisScale {
getAllPoints() {
const config = this.axisConfig;
const data = this.visConfig.data.chartData();
const chartPoints = _.reduce(
const chartPoints = reduce(
data,
(chartPoints, chart, chartIndex) => {
const points = chart.series.reduce((points, seri, seriIndex) => {
Expand Down Expand Up @@ -274,6 +275,6 @@ export class AxisScale {
}

validateScale(scale) {
if (!scale || _.isNaN(scale)) throw new Error('scale is ' + scale);
if (!scale || Number.isNaN(scale)) throw new Error('scale is ' + scale);
}
}

0 comments on commit ef45b63

Please sign in to comment.