Merge pull request #4353 from stormpython/fix/empty_field

Fix/empty field
This commit is contained in:
Joe Fleming 2015-07-24 14:33:23 -07:00
commit a3656e0ff9
6 changed files with 62 additions and 10 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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();
}
}
]
})

View file

@ -81,6 +81,7 @@ define(function (require) {
return yScale(d.y0 + d.y);
})
.defined(function (d) { return !_.isNull(d.y); })
.interpolate(interpolate);
// Data layers
@ -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);
});
});

View file

@ -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
@ -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) {

View file

@ -355,7 +355,7 @@ define(function (require) {
-112.06054687499999
]
}
},
}
}, {
title: 'Top 5 _type: nginx',
label: 'Top 5 _type: nginx',
@ -371,7 +371,7 @@ define(function (require) {
-112.06054687499999
]
}
},
}
}]
};
@ -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);
});
});
});
});