Skip to content

Commit

Permalink
Merge pull request elastic#4353 from stormpython/fix/empty_field
Browse files Browse the repository at this point in the history
Fix/empty field
  • Loading branch information
w33ble committed Jul 24, 2015
2 parents e11faa5 + 8041769 commit a3656e0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/kibana/components/agg_response/point_series/_get_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ define(function (require) {
yScale: yScale
};

if (point.y === 'NaN' || point.y == null) {
// filter out NaN from stats and null
if (point.y === 'NaN') {
// filter out NaN from stats
// from metrics that are not based at zero
return;
}
Expand Down
16 changes: 16 additions & 0 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ define(function (require) {
return _.get(source, thing, def);
};

/**
* Returns true if null values are present
* @returns {*}
*/
Data.prototype.hasNullValues = function () {
var chartData = this.chartData();

return chartData.some(function (chart) {
return chart.series.some(function (obj) {
return obj.values.some(function (d) {
return d.y === null;
});
});
});
};

/**
* Return an array of all value objects
* Pluck the data.series array from each data object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ define(function (require) {
var hasNeg = data.getYMin(data._getY) < 0;
return (hasPos && hasNeg);
}
},
{
type: 'warning',
msg: 'Parts of or the entire area chart might not be displayed due to null ' +
'values in the data. A line chart is recommended when displaying data ' +
'with null values.',
test: function (vis, data) {
return data.hasNullValues();
}
}
]
})
Expand Down
9 changes: 5 additions & 4 deletions src/kibana/components/vislib/visualizations/area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define(function (require) {

return yScale(d.y0 + d.y);
})
.defined(function (d) { return !_.isNull(d.y); })
.interpolate(interpolate);

// Data layers
Expand Down Expand Up @@ -161,12 +162,12 @@ define(function (require) {
.append('g')
.attr('class', 'points area');

// append the bars
// append the circles
circles = layer
.selectAll('rect')
.selectAll('circles')
.data(function appendData(data) {
return data.filter(function isNotZero(d) {
return d.y !== 0;
return data.filter(function isZeroOrNull(d) {
return d.y !== 0 && !_.isNull(d.y);
});
});

Expand Down
7 changes: 5 additions & 2 deletions src/kibana/components/vislib/visualizations/line_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ define(function (require) {

var circles = layer
.selectAll('circle')
.data(function appendData(d) {
return d;
.data(function appendData(data) {
return data.filter(function (d) {
return !_.isNull(d.y);
});
});

circles
Expand Down Expand Up @@ -190,6 +192,7 @@ define(function (require) {
var ordered = this.handler.data.get('ordered');
var interpolate = (this._attr.smoothLines) ? 'cardinal' : this._attr.interpolate;
var line = d3.svg.line()
.defined(function (d) { return !_.isNull(d.y); })
.interpolate(interpolate)
.x(function x(d) {
if (ordered && ordered.date) {
Expand Down
27 changes: 25 additions & 2 deletions test/unit/specs/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ define(function (require) {
-112.06054687499999
]
}
},
}
}, {
title: 'Top 5 _type: nginx',
label: 'Top 5 _type: nginx',
Expand All @@ -371,7 +371,7 @@ define(function (require) {
-112.06054687499999
]
}
},
}
}]
};

Expand All @@ -394,5 +394,28 @@ define(function (require) {
});
});
});

describe('null value check', function () {
it('should return false', function () {
var data = new Data(rowsData, {});
expect(data.hasNullValues()).to.be(false);
});

it('should return true', function () {
var nullRowData = { rows: rowsData.rows.slice(0) };
nullRowData.rows.push({
'label': 'e',
'series': [
{
'label': '200',
'values': [{x: 0, y: 1}, {x: 1, y: null}, {x: 2, y: 3}]
}
]
});

var data = new Data(nullRowData, {});
expect(data.hasNullValues()).to.be(true);
});
});
});
});

0 comments on commit a3656e0

Please sign in to comment.