Skip to content

Commit

Permalink
adding error message for no results when vislib gets a data object wi…
Browse files Browse the repository at this point in the history
…th no data
  • Loading branch information
stormpython committed Dec 13, 2014
1 parent c5f15f1 commit 566e60d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/kibana/components/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,12 @@ define(function (require) {
};
inherits(errors.NotEnoughData, KbnError);

errors.NoResults = function NoResults() {
KbnError.call(this,
'No results found',
errors.NoResults);
};
inherits(errors.NoResults, KbnError);

return errors;
});
6 changes: 4 additions & 2 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ define(function (require) {
}

this.color = this.labels ? color(this.labels) : undefined;

this._normalizeOrdered();

this._attr = _.defaults(attr || {}, {
Expand All @@ -67,6 +67,8 @@ define(function (require) {
type = 'series';
} else if (obj.slices) {
type = 'slices';
} else if (obj.geoJSON) {
type = 'goeJSON';
}
});

Expand Down Expand Up @@ -459,7 +461,7 @@ define(function (require) {
* series.rows is an array of arrays
* each row is an array of values
* last value in row array is bucket count
*
*
* @method mapDataExtents
* @param series {Array} Array of data objects
* @returns {Array} min and max values
Expand Down
25 changes: 22 additions & 3 deletions src/kibana/components/vislib/lib/handler/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define(function (require) {
return function HandlerBaseClass(d3, Private) {
var _ = require('lodash');
var errors = require('errors');

var Data = Private(require('components/vislib/lib/data'));
var Layout = Private(require('components/vislib/lib/layout/layout'));
Expand All @@ -20,6 +21,7 @@ define(function (require) {
}

this.data = opts.data || new Data(vis.data, vis._attr);

this.vis = vis;
this.el = vis.el;
this.ChartClass = vis.ChartClass;
Expand Down Expand Up @@ -49,6 +51,14 @@ define(function (require) {
], Boolean);
}

Handler.prototype._validateData = function () {
var dataType = this.data.type;

if (!dataType) {
throw new errors.NoResults();
}
};

/**
* Renders the constructors that create the visualization,
* including the chart constructor
Expand All @@ -60,6 +70,7 @@ define(function (require) {
var self = this;
var charts = this.charts = [];

this._validateData();
this.renderArray.forEach(function (property) {
if (typeof property.render === 'function') {
property.render();
Expand Down Expand Up @@ -153,13 +164,21 @@ define(function (require) {
Handler.prototype.error = function (message) {
this.removeAll(this.el);

return d3.select(this.el)
var div = d3.select(this.el)
.append('div')
// class name needs `chart` in it for the polling checkSize function
// to continuously call render on resize
.attr('class', 'visualize-error chart error')
.append('h4')
.attr('class', 'visualize-error chart error');

if (message === 'No results found') {
div.append('h2')
.html('<i class="fa fa-meh-o"></i>');
}

div.append('h4')
.text(message);

return div;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/vislib/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ define(function (require) {
// Because we have to wait for the DOM element to initialize, we do not
// want to throw an error when the DOM `el` is zero
if (error instanceof errors.ContainerTooSmall ||
error instanceof errors.NotEnoughData) {
error instanceof errors.NotEnoughData ||
error instanceof errors.NoResults) {
this.handler.error(error.message);
} else {
throw error;
Expand Down

0 comments on commit 566e60d

Please sign in to comment.