Skip to content

Commit

Permalink
Closes #445. Legend is now displayed when there are multiple charts w…
Browse files Browse the repository at this point in the history
…ith different labels
  • Loading branch information
stormpython committed Oct 2, 2014
1 parent e17a04c commit 6d50b8c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ define(function (require) {
return [this.data];
};

// Function to determine whether to display the legend or not
// Displays legend when more than one series of data present
Data.prototype.isLegendShown = function () {
var isLegend = false;
Data.prototype.getVisData = function () {
var visData;

if (this.data.rows) {
Expand All @@ -52,10 +49,30 @@ define(function (require) {
visData = [this.data];
}

return visData;
};

// Function to determine whether to display the legend or not
// Displays legend when more than one series of data present
Data.prototype.isLegendShown = function () {
var isLegend = false;
var visData = this.getVisData();
var sameSeriesLabel = true;
var seriesLabel;

_.forEach(visData, function countSeriesLength(obj) {
var dataLength = obj.series ? obj.series.length : obj.slices.children.length;
var label = dataLength === 1 && obj.series ? obj.series[0].label : undefined;

if (!seriesLabel) {
seriesLabel = label;
}

if (seriesLabel !== label) {
sameSeriesLabel = false;
}

if (dataLength > 1) {
if (dataLength > 1 || !sameSeriesLabel) {
isLegend = true;
}
});
Expand Down

0 comments on commit 6d50b8c

Please sign in to comment.