From 566e60dc7d29e493485ac9c43772fd1360bc213e Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Sat, 13 Dec 2014 01:33:12 +0100 Subject: [PATCH] adding error message for no results when vislib gets a data object with no data --- src/kibana/components/errors.js | 7 ++++++ src/kibana/components/vislib/lib/data.js | 6 +++-- .../components/vislib/lib/handler/handler.js | 25 ++++++++++++++++--- src/kibana/components/vislib/vis.js | 3 ++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/kibana/components/errors.js b/src/kibana/components/errors.js index 877b30efc8137..06aaf2bd70d6a 100644 --- a/src/kibana/components/errors.js +++ b/src/kibana/components/errors.js @@ -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; }); diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index 25aa81d4322ce..b39c3411c0e75 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -45,7 +45,7 @@ define(function (require) { } this.color = this.labels ? color(this.labels) : undefined; - + this._normalizeOrdered(); this._attr = _.defaults(attr || {}, { @@ -67,6 +67,8 @@ define(function (require) { type = 'series'; } else if (obj.slices) { type = 'slices'; + } else if (obj.geoJSON) { + type = 'goeJSON'; } }); @@ -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 diff --git a/src/kibana/components/vislib/lib/handler/handler.js b/src/kibana/components/vislib/lib/handler/handler.js index 8e7a94545308d..6c9c7233495a8 100644 --- a/src/kibana/components/vislib/lib/handler/handler.js +++ b/src/kibana/components/vislib/lib/handler/handler.js @@ -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')); @@ -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; @@ -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 @@ -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(); @@ -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(''); + } + + div.append('h4') .text(message); + + return div; }; /** diff --git a/src/kibana/components/vislib/vis.js b/src/kibana/components/vislib/vis.js index 902583f1d56dc..b187132e8fdff 100644 --- a/src/kibana/components/vislib/vis.js +++ b/src/kibana/components/vislib/vis.js @@ -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;