From 7fb7866321589e5c6e367c5ef3a65eddc3dee531 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Fri, 10 Apr 2015 17:04:38 -0400 Subject: [PATCH 01/43] troubleshooting --- .../vislib/lib/handler/types/pie.js | 2 +- .../vislib/lib/handler/types/point_series.js | 2 +- src/kibana/components/vislib/lib/legend.js | 52 ++++++++++++++++--- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/kibana/components/vislib/lib/handler/types/pie.js b/src/kibana/components/vislib/lib/handler/types/pie.js index 4bcb4a3c7d923..8406ff315adca 100644 --- a/src/kibana/components/vislib/lib/handler/types/pie.js +++ b/src/kibana/components/vislib/lib/handler/types/pie.js @@ -13,7 +13,7 @@ define(function (require) { var data = new Data(vis.data, vis._attr); return new Handler(vis, { - legend: new Legend(vis, vis.el, data.pieNames(), data.getPieColorFunc(), vis._attr), + legend: new Legend(vis, data), chartTitle: new ChartTitle(vis.el) }); }; diff --git a/src/kibana/components/vislib/lib/handler/types/point_series.js b/src/kibana/components/vislib/lib/handler/types/point_series.js index c5fa17ae6bd60..ccd97c9c30f8d 100644 --- a/src/kibana/components/vislib/lib/handler/types/point_series.js +++ b/src/kibana/components/vislib/lib/handler/types/point_series.js @@ -29,7 +29,7 @@ define(function (require) { return new Handler(vis, { data: data, - legend: new Legend(vis, vis.el, data.labels, data.color, vis._attr), + legend: new Legend(vis, data), axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')), chartTitle: new ChartTitle(vis.el), xAxis: new XAxis({ diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index c597efbcf31d8..cce500260e2ae 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -1,6 +1,7 @@ define(function (require) { - return function LegendFactory(d3) { + return function LegendFactory(d3, Private) { var _ = require('lodash'); + var Dispatch = Private(require('components/vislib/lib/dispatch')); var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); require('css!components/vislib/styles/main'); @@ -16,16 +17,20 @@ define(function (require) { * @param color {Function} Color function * @param _attr {Object|*} Reference to Vis options */ - function Legend(vis, el, labels, color, _attr) { + function Legend(vis, data) { if (!(this instanceof Legend)) { - return new Legend(vis, el, labels, color, _attr); + return new Legend(vis, data); } + var isPie = (vis._attr.type === 'pie'); + this.vis = vis; - this.el = el; - this.labels = labels; - this.color = color; - this._attr = _.defaults(_attr || {}, { + this.data = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); + this.el = vis.el; + this.events = new Dispatch(); + this.labels = isPie ? data.pieNames() : data.labels; + this.color = isPie ? data.getPieColorFunc() : data.color; + this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', 'blurredOpacity' : 0.3, 'focusOpacity' : 1, @@ -35,6 +40,37 @@ define(function (require) { }); } + Legend.prototype._transformPieData = function (arr) { + var data = []; + + + arr.forEach(function (chart) { + chart.slices.children.forEach(function (obj) { + if (obj.children) data.push(obj.children); + data.push(obj); + }); + }); + + return data; + }; + + Legend.prototype._transformSeriesData = function (arr) { + var data = []; + + arr.forEach(function (chart) { + chart.series.forEach(function (obj, i) { + var currentObj = data[i]; + if (!currentObj) data.push(obj); + + if (currentObj && currentObj.label === obj.label) { + currentObj.values = currentObj.values.concat(obj.values); + } + }); + }); + + return data; + }; + /** * Adds legend header * @@ -198,6 +234,8 @@ define(function (require) { eventEl.style('white-space', 'nowrap'); eventEl.style('word-break', 'inherit'); }); + + legendDiv.call(this.events.addClickEvent()); }; return Legend; From 68f0bba4938d672560fbb5f376775a3a73efa2cd Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 01:09:05 -0400 Subject: [PATCH 02/43] shaping up the click events for legend --- src/kibana/components/vislib/lib/dispatch.js | 18 ++--- src/kibana/components/vislib/lib/legend.js | 72 ++++++++++++++------ 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index f59694dfb8b78..3006fe1e0e91f 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -33,26 +33,27 @@ define(function (require) { */ Dispatch.prototype.eventResponse = function (d, i) { var datum = d._input || d; - var data = d3.event.target.nearestViewportElement.__data__; + var data = d3.event.target.nearestViewportElement ? + d3.event.target.nearestViewportElement.__data__ : d3.event.target.__data__; var label = d.label ? d.label : d.name; - var isSeries = !!(data.series); - var isSlices = !!(data.slices); + var isSeries = !!(data && data.series); + var isSlices = !!(data && data.slices); var series = isSeries ? data.series : undefined; var slices = isSlices ? data.slices : undefined; var handler = this.handler; - var color = handler.data.color; - var isPercentage = (handler._attr.mode === 'percentage'); + var color = handler && handler.data && handler.data.color; + var isPercentage = (handler && handler._attr.mode === 'percentage'); var eventData = { value: d.y, point: datum, datum: datum, label: label, - color: color(label), + color: color ? color(label) : undefined, pointIndex: i, series: series, slices: slices, - config: handler._attr, + config: handler && handler._attr, data: data, e: d3.event, handler: handler @@ -235,7 +236,8 @@ define(function (require) { .select('.legend-ul') .selectAll('li.color') .filter(function (d, i) { - return this.getAttribute('data-label') !== label; + var thisLabel = d.label ? d.label : d.name; + return thisLabel !== label; }) .classed('blur_shape', true); }; diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 90572cab83b7d..67f7b428ae573 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -26,7 +26,7 @@ define(function (require) { var isPie = (vis._attr.type === 'pie'); this.vis = vis; - this.data = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); + this.dataLabels = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); this.el = vis.el; this.events = new Dispatch(); this.labels = isPie ? data.pieNames() : data.labels; @@ -41,20 +41,32 @@ define(function (require) { }); } + /** + * Returns an arr of data objects that includes labels, aggConfig, and an array of data values + * for the pie chart. + */ Legend.prototype._transformPieData = function (arr) { var data = []; - + var recurse = function (obj) { + if (obj.children) { + recurse(obj.children.reverse()).forEach(function (d) { data.unshift(d); }); + } + return obj; + }; arr.forEach(function (chart) { - chart.slices.children.forEach(function (obj) { - if (obj.children) data.push(obj.children); - data.push(obj); - }); + chart.slices.children.map(recurse) + .reverse() + .forEach(function (d) { data.unshift(d); }); }); - return data; + return _.unique(data, function (d) { return d.name; }); }; + /** + * Returns an arr of data objects that includes labels, aggConfig, and an array of data values + * for the point series charts. + */ Legend.prototype._transformSeriesData = function (arr) { var data = []; @@ -63,6 +75,19 @@ define(function (require) { var currentObj = data[i]; if (!currentObj) data.push(obj); + // Copies first aggConfigResults object to data object. + if (obj.values && obj.values.length) { + + // Filter out zero injected values + var values = obj.values.filter(function (d) { + return d.aggConfigResult !== undefined; + }); + + obj.aggConfig = values[0].aggConfigResult && values[0].aggConfigResult.aggConfig ? + _.clone(values[0].aggConfigResult.aggConfig) : undefined; + } + + // Joins all values arrays that share a common label if (currentObj && currentObj.label === obj.label) { currentObj.values = currentObj.values.concat(obj.values); } @@ -104,9 +129,7 @@ define(function (require) { return el.append('ul') .attr('class', function () { - if (args._attr.isOpen) { - return 'legend-ul'; - } + if (args._attr.isOpen) { return 'legend-ul'; } return 'legend-ul hidden'; }) .selectAll('li') @@ -115,8 +138,9 @@ define(function (require) { .append('li') .attr('class', 'color') .each(self._addIdentifier) - .html(function (d) { - return '' + d; + .html(function (d, i) { + var label = d.label ? d.label : d.name; + return '' + label; }); }; @@ -141,7 +165,7 @@ define(function (require) { var self = this; var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); - var items = this.labels; + var items = this.dataLabels; this.header(legendDiv, this); this.list(legendDiv, items, this); @@ -168,21 +192,25 @@ define(function (require) { }); legendDiv.select('.legend-ul').selectAll('li') - .on('mouseover', function (label) { + .on('mouseover', function (d) { + var label = d.label ? d.label : d.name; var charts = visEl.selectAll('.chart'); + function filterLabel(d) { + var pointLabel = d.label ? d.label : d.name; + return pointLabel !== label; + } + + d3.select(this).style('cursor', 'pointer'); // Add mouse pointer + // legend legendDiv.selectAll('li') - .filter(function (d) { - return this.getAttribute('data-label') !== label; - }) + .filter(filterLabel) .classed('blur_shape', true); // all data-label attribute charts.selectAll('[data-label]') - .filter(function (d) { - return this.getAttribute('data-label') !== label; - }) + .filter(filterLabel) .classed('blur_shape', true); var eventEl = d3.select(this); @@ -210,7 +238,9 @@ define(function (require) { eventEl.style('word-break', 'inherit'); }); - legendDiv.call(this.events.addClickEvent()); + legendDiv.selectAll('li.color').each(function () { + d3.select(this).call(self.events.addClickEvent()); + }); }; return Legend; From 6a9a3364149ba6a5a3583c29cb70152995681105 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 01:19:54 -0400 Subject: [PATCH 03/43] removing labels code since its no longer needed --- src/kibana/components/vislib/lib/legend.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 67f7b428ae573..7353ea2ecd6c5 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -29,7 +29,6 @@ define(function (require) { this.dataLabels = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); this.el = vis.el; this.events = new Dispatch(); - this.labels = isPie ? data.pieNames() : data.labels; this.color = isPie ? data.getPieColorFunc() : data.color; this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', From 3e58851ad96eda15dd82c7b861944eee1ab8821e Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 09:59:49 -0400 Subject: [PATCH 04/43] fixing data-labels in the legend --- src/kibana/components/vislib/lib/legend.js | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 7353ea2ecd6c5..28b6beda4d7cf 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -48,26 +48,35 @@ define(function (require) { var data = []; var recurse = function (obj) { if (obj.children) { - recurse(obj.children.reverse()).forEach(function (d) { data.unshift(d); }); + recurse(obj.children).reverse().forEach(function (d) { data.unshift(d); }); } return obj; }; arr.forEach(function (chart) { chart.slices.children.map(recurse) - .reverse() - .forEach(function (d) { data.unshift(d); }); + .reverse().forEach(function (d) { data.unshift(d); }); }); return _.unique(data, function (d) { return d.name; }); }; + /** + * Filter out zero injected objects + */ + Legend.prototype._filterZeroInjectedValues = function (arr) { + return arr.filter(function (d) { + return d.aggConfigResult !== undefined; + }); + }; + /** * Returns an arr of data objects that includes labels, aggConfig, and an array of data values * for the point series charts. */ Legend.prototype._transformSeriesData = function (arr) { var data = []; + var self = this; arr.forEach(function (chart) { chart.series.forEach(function (obj, i) { @@ -76,11 +85,7 @@ define(function (require) { // Copies first aggConfigResults object to data object. if (obj.values && obj.values.length) { - - // Filter out zero injected values - var values = obj.values.filter(function (d) { - return d.aggConfigResult !== undefined; - }); + var values = self._filterZeroInjectedValues(obj.values); obj.aggConfig = values[0].aggConfigResult && values[0].aggConfigResult.aggConfig ? _.clone(values[0].aggConfigResult.aggConfig) : undefined; @@ -149,7 +154,8 @@ define(function (require) { * @method _addIdentifier * @param label {string} label to use */ - Legend.prototype._addIdentifier = function (label) { + Legend.prototype._addIdentifier = function (d) { + var label = d.label ? d.label : d.name; dataLabel(this, label); }; From fb0c811755e801d5716fc8c0d7aaf24644780e84 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 11:16:04 -0400 Subject: [PATCH 05/43] troubleshooting mouseover on legend for area charts --- src/kibana/components/vislib/lib/dispatch.js | 1 + src/kibana/components/vislib/lib/legend.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index 3006fe1e0e91f..84626e04477e6 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -149,6 +149,7 @@ define(function (require) { var addEvent = this.addEvent; function click(d, i) { + console.log(d); d3.event.stopPropagation(); self.dispatch.click.call(this, self.eventResponse(d, i)); } diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 28b6beda4d7cf..b60fff652da4f 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -26,8 +26,9 @@ define(function (require) { var isPie = (vis._attr.type === 'pie'); this.vis = vis; - this.dataLabels = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); + this.data = data; this.el = vis.el; + this.dataLabels = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); this.events = new Dispatch(); this.color = isPie ? data.getPieColorFunc() : data.color; this._attr = _.defaults(vis._attr || {}, { @@ -144,6 +145,7 @@ define(function (require) { .each(self._addIdentifier) .html(function (d, i) { var label = d.label ? d.label : d.name; + if (!label) { label = self.data.get('yAxisLabel'); } return '' + label; }); }; @@ -202,11 +204,13 @@ define(function (require) { var charts = visEl.selectAll('.chart'); function filterLabel(d) { - var pointLabel = d.label ? d.label : d.name; + var pointLabel = this.getAttribute('data-label'); return pointLabel !== label; } - d3.select(this).style('cursor', 'pointer'); // Add mouse pointer + if (label !== undefined && label !== '_all') { + d3.select(this).style('cursor', 'pointer'); + } // legend legendDiv.selectAll('li') @@ -243,8 +247,11 @@ define(function (require) { eventEl.style('word-break', 'inherit'); }); - legendDiv.selectAll('li.color').each(function () { - d3.select(this).call(self.events.addClickEvent()); + legendDiv.selectAll('li.color').each(function (d) { + var label = d.label ? d.label : d.name; + if (label !== undefined && label !== '_all') { + d3.select(this).call(self.events.addClickEvent()); + } }); }; From 2803c47ccbc267e1e5aefda64a82152aa86b1a9b Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 15:21:45 -0400 Subject: [PATCH 06/43] fixing broken tests --- src/kibana/components/vislib/lib/dispatch.js | 2 +- src/kibana/components/vislib/lib/legend.js | 2 +- test/unit/specs/vislib/lib/legend.js | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index 84626e04477e6..5aaecece0a0c1 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -149,7 +149,7 @@ define(function (require) { var addEvent = this.addEvent; function click(d, i) { - console.log(d); + console.log(self.eventResponse(d, i)); d3.event.stopPropagation(); self.dispatch.click.call(this, self.eventResponse(d, i)); } diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index b60fff652da4f..a905c3ab587a7 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -88,7 +88,7 @@ define(function (require) { if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); - obj.aggConfig = values[0].aggConfigResult && values[0].aggConfigResult.aggConfig ? + obj.aggConfig = values.length && values[0].aggConfigResult && values[0].aggConfigResult.aggConfig ? _.clone(values[0].aggConfigResult.aggConfig) : undefined; } diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 53763f0d71557..2d74a67fe4ab2 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -59,14 +59,17 @@ define(function (require) { it('should match the slice label', function () { var chartType = chartTypes[i]; var paths = $(vis.el).find(chartSelectors[chartType]).toArray(); - var items = vis.handler.legend.labels; + var items = vis.handler.legend.dataLabels; - items.forEach(function (label) { + items.forEach(function (d) { var path = _(paths) .map(function (path) { return path.getAttribute('data-label'); }) .filter(function (dataLabel) { + var label = d.label ? d.label : d.name; + + if (typeof label === 'number') dataLabel = +dataLabel; return dataLabel === label; }) .value(); From 745cfbc62c4fffde4eee8ff2ee17163b4b9a76f3 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 15:35:10 -0400 Subject: [PATCH 07/43] removing console.log --- src/kibana/components/vislib/lib/dispatch.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index 5aaecece0a0c1..3006fe1e0e91f 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -149,7 +149,6 @@ define(function (require) { var addEvent = this.addEvent; function click(d, i) { - console.log(self.eventResponse(d, i)); d3.event.stopPropagation(); self.dispatch.click.call(this, self.eventResponse(d, i)); } From 416cb6a89ee49dcc0337296e762629492e616660 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 16:15:49 -0400 Subject: [PATCH 08/43] adding tests for the legend class --- test/unit/specs/vislib/lib/legend.js | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 2d74a67fe4ab2..4aaf54d05f482 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -35,6 +35,7 @@ define(function (require) { type: chartTypes[i], addLegend: true }; + var Legend; var vis; beforeEach(function () { @@ -44,6 +45,7 @@ define(function (require) { beforeEach(function () { inject(function (Private) { vis = Private(require('vislib_fixtures/_vis_fixture'))(visLibParams); + Legend = Private(require('components/vislib/lib/legend')); require('css!components/vislib/styles/main'); vis.render(data); @@ -55,6 +57,90 @@ define(function (require) { vis = null; }); + describe('_transformPieData method', function () { + var pieData = { + slices: { + children: [ + { name: 'm', size: 20 }, + { + name: 'n', + size: 30, + children: [ + { name: 's', size: 10 }, + { name: 't', size: 20 }, + { name: 'u', size: 4 } + ] + }, + { name: 'b', size: 40 } + ] + } + }; + + it('should flatten the nested objects', function () { + var items = Legend.prototype._transformPieData([pieData]); + expect(items.length).to.be(6); + }); + }); + + describe('_filterZeroInjectedValues method', function () { + // Zero injected values do not contain aggConfigResults + var seriesData = [ + { aggConfigResult: {} }, + { aggConfigResult: {} }, + {} + ]; + + it('should remove zero injected values', function () { + var items = Legend.prototype._filterZeroInjectedValues(seriesData); + expect(items.length).to.be(2); + }); + }); + + describe('_transformSeriesData method', function () { + var seriesData = [ + { + series: [ + { + label: 'html', + values: [{y: 2}, {y: 3}, {y: 4}] + }, + { + label: 'css', + values: [{y: 5}, {y: 6}, {y: 7}] + }, + { + label: 'png', + values: [{y: 8}, {y: 9}, {y: 10}] + } + ] + }, + { + series: [ + { + label: 'html', + values: [{y: 2}, {y: 3}, {y: 4}] + }, + { + label: 'css', + values: [{y: 5}, {y: 6}, {y: 7}] + }, + { + label: 'png', + values: [{y: 8}, {y: 9}, {y: 10}] + } + ] + }, + ]; + + it('should combine values arrays of objects with identical labels', function () { + var items = Legend.prototype._transformSeriesData(seriesData); + expect(items.length).to.be(3); + items.forEach(function (item) { + expect(item.values.length).to.be(6); + }); + }); + }); + describe('legend item label matches vis item label', function () { it('should match the slice label', function () { var chartType = chartTypes[i]; From 765d28a5c4ca5c5024a9b651a22dbc7d4fb0704f Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 16:24:03 -0400 Subject: [PATCH 09/43] bring back aggConfigResult --- src/kibana/components/vislib/lib/legend.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index a905c3ab587a7..e1da67939ead7 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -88,8 +88,8 @@ define(function (require) { if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); - obj.aggConfig = values.length && values[0].aggConfigResult && values[0].aggConfigResult.aggConfig ? - _.clone(values[0].aggConfigResult.aggConfig) : undefined; + obj.aggConfigResult = values.length && values[0].aggConfigResult ? + _.clone(values[0].aggConfigResult) : undefined; } // Joins all values arrays that share a common label From 8e4b47c8f6506e8b12b89305f2d5c77d111a1dc6 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 21 Apr 2015 16:43:05 -0400 Subject: [PATCH 10/43] adding an onclick listener test for the first li.color in the legend list --- test/unit/specs/vislib/lib/legend.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 4aaf54d05f482..5cf4356812e27 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -188,6 +188,7 @@ define(function (require) { it('should have an onclick listener', function () { expect(!!$('.legend-toggle')[0].__onclick).to.be(true); + expect(!!$('li.color')[0].__onclick).to.be(true); }); it('should attach onmouseover listener', function () { From cd7353c8f139c5824649095cc52c0e240368fa18 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 23 Apr 2015 17:51:39 -0400 Subject: [PATCH 11/43] hooking up legend filtering --- .../components/vislib/lib/handler/handler.js | 49 +++++++++++-------- src/kibana/components/vislib/lib/legend.js | 8 ++- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/kibana/components/vislib/lib/handler/handler.js b/src/kibana/components/vislib/lib/handler/handler.js index b66ef1c70f5a7..b01706a7dfeed 100644 --- a/src/kibana/components/vislib/lib/handler/handler.js +++ b/src/kibana/components/vislib/lib/handler/handler.js @@ -4,6 +4,7 @@ define(function (require) { var errors = require('errors'); var Data = Private(require('components/vislib/lib/data')); + var Legend = Private(require('components/vislib/lib/legend')); var Layout = Private(require('components/vislib/lib/layout/layout')); /** @@ -67,6 +68,28 @@ define(function (require) { } }; + /** + * Adds event listeners + */ + Handler.prototype._addEventListeners = function (chart) { + var self = this; + var enabledEvents; + + if (chart.events.dispatch) { + enabledEvents = this.vis.eventTypes.enabled; + + // Copy dispatch.on methods to chart object + d3.rebind(chart, chart.events.dispatch, 'on'); + + // Bind events to chart(s) + if (enabledEvents.length) { + enabledEvents.forEach(function (event) { + self.enable(event, chart); + }); + } + } + }; + /** * Renders the constructors that create the visualization, * including the chart constructor @@ -83,6 +106,10 @@ define(function (require) { this._validateData(); this.renderArray.forEach(function (property) { + if (property instanceof Legend) { + self._addEventListeners(property); + } + if (typeof property.render === 'function') { property.render(); } @@ -92,28 +119,8 @@ define(function (require) { selection.selectAll('.chart') .each(function (chartData) { var chart = new self.ChartClass(self, this, chartData); - var enabledEvents; - - /* - * inside handler: if there are charts, bind events to charts - * functionality: track in array that event is enabled - * clean up event handlers every time it destroys the chart - * rebind them every time it creates the charts - */ - if (chart.events.dispatch) { - enabledEvents = self.vis.eventTypes.enabled; - - // Copy dispatch.on methods to chart object - d3.rebind(chart, chart.events.dispatch, 'on'); - - // Bind events to chart(s) - if (enabledEvents.length) { - enabledEvents.forEach(function (event) { - self.enable(event, chart); - }); - } - } + self._addEventListeners(chart); charts.push(chart); chart.render(); }); diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index e1da67939ead7..b64883a92c1d3 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -4,6 +4,7 @@ define(function (require) { var Dispatch = Private(require('components/vislib/lib/dispatch')); var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); + var AggConfigResult = require('components/vis/_agg_config_result'); require('css!components/vislib/styles/main'); @@ -87,9 +88,12 @@ define(function (require) { // Copies first aggConfigResults object to data object. if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); + var aggConfigResult = values[0].aggConfigResult; - obj.aggConfigResult = values.length && values[0].aggConfigResult ? - _.clone(values[0].aggConfigResult) : undefined; + obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, aggConfigResult.$parent, + aggConfigResult.value, aggConfigResult.key); + + obj.aggConfigResult.$parent.$parent = null; } // Joins all values arrays that share a common label From c17f132df9ef91ef0785ff7eb5a07d44963efea9 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 23 Apr 2015 23:02:05 -0400 Subject: [PATCH 12/43] troubleshooting issues with aggConfigResults --- src/kibana/components/vislib/lib/legend.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index b64883a92c1d3..389bd03403900 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -88,12 +88,10 @@ define(function (require) { // Copies first aggConfigResults object to data object. if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); - var aggConfigResult = values[0].aggConfigResult; + var aggConfigResult = values[0].aggConfigResult.$parent; - obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, aggConfigResult.$parent, + obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, null, aggConfigResult.value, aggConfigResult.key); - - obj.aggConfigResult.$parent.$parent = null; } // Joins all values arrays that share a common label From 5c11aafc534b869144abea7a1d97fa7c923a3400 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Fri, 24 Apr 2015 16:44:35 -0400 Subject: [PATCH 13/43] fixing tests and issues with clickable legend not returning the proper results --- src/kibana/components/vislib/lib/legend.js | 32 ++++++++++++---------- test/unit/specs/vislib/lib/legend.js | 3 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 389bd03403900..d5606555d1040 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -88,12 +88,14 @@ define(function (require) { // Copies first aggConfigResults object to data object. if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); - var aggConfigResult = values[0].aggConfigResult.$parent; + var aggConfigResult = values.length && values[0].aggConfigResult ? + values[0].aggConfigResult.$parent : undefined; - obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, null, - aggConfigResult.value, aggConfigResult.key); + if (aggConfigResult) { + obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, null, + aggConfigResult.value, aggConfigResult.key); + } } - // Joins all values arrays that share a common label if (currentObj && currentObj.label === obj.label) { currentObj.values = currentObj.values.concat(obj.values); @@ -207,22 +209,22 @@ define(function (require) { function filterLabel(d) { var pointLabel = this.getAttribute('data-label'); - return pointLabel !== label; + return pointLabel !== label.toString(); } - if (label !== undefined && label !== '_all') { + if (label && label !== '_all') { d3.select(this).style('cursor', 'pointer'); - } - // legend - legendDiv.selectAll('li') - .filter(filterLabel) - .classed('blur_shape', true); + // legend + legendDiv.selectAll('li') + .filter(filterLabel) + .classed('blur_shape', true); - // all data-label attribute - charts.selectAll('[data-label]') - .filter(filterLabel) - .classed('blur_shape', true); + // all data-label attribute + charts.selectAll('[data-label]') + .filter(filterLabel) + .classed('blur_shape', true); + } var eventEl = d3.select(this); eventEl.style('white-space', 'inherit'); diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 5cf4356812e27..876883fe4f715 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -155,8 +155,7 @@ define(function (require) { .filter(function (dataLabel) { var label = d.label ? d.label : d.name; - if (typeof label === 'number') dataLabel = +dataLabel; - return dataLabel === label; + return dataLabel === label.toString(); }) .value(); From 8fb8dfa18c1ba7d4803ef84cb937d747ed43003c Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 28 Apr 2015 15:42:06 -0400 Subject: [PATCH 14/43] addressing review comments --- src/kibana/components/vislib/lib/legend.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index d5606555d1040..0568202502d79 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -26,10 +26,15 @@ define(function (require) { var isPie = (vis._attr.type === 'pie'); + if (isPie) { + this.dataLabels = this._transformPieData(data.pieData()); + } else { + this.dataLabels = this._transformSeriesData(data.getVisData()); + } + this.vis = vis; this.data = data; this.el = vis.el; - this.dataLabels = isPie ? this._transformPieData(data.pieData()) : this._transformSeriesData(data.getVisData()); this.events = new Dispatch(); this.color = isPie ? data.getPieColorFunc() : data.color; this._attr = _.defaults(vis._attr || {}, { @@ -88,8 +93,11 @@ define(function (require) { // Copies first aggConfigResults object to data object. if (obj.values && obj.values.length) { var values = self._filterZeroInjectedValues(obj.values); - var aggConfigResult = values.length && values[0].aggConfigResult ? - values[0].aggConfigResult.$parent : undefined; + var aggConfigResult; + + if (values.length && values[0].aggConfigResult) { + aggConfigResult = values[0].aggConfigResult.$parent; + } if (aggConfigResult) { obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, null, From ffb35adf105a26d88ef7fc93dec007c886251700 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 30 Apr 2015 15:33:58 -0400 Subject: [PATCH 15/43] addressing review comments, added _.deepGet to dispatch for retrieving the color function --- src/kibana/components/vislib/lib/dispatch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index 3006fe1e0e91f..a82b56a1fb002 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -41,7 +41,7 @@ define(function (require) { var series = isSeries ? data.series : undefined; var slices = isSlices ? data.slices : undefined; var handler = this.handler; - var color = handler && handler.data && handler.data.color; + var color = _.deepGet(handler, 'data.color'); var isPercentage = (handler && handler._attr.mode === 'percentage'); var eventData = { From 0327be469396040523ee7e2feae0f40db6ce871f Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 5 May 2015 09:53:40 -0400 Subject: [PATCH 16/43] troubleshooting --- .../vislib/components/labels/data_array.js | 7 +--- .../components/labels/flatten_series.js | 1 - .../vislib/components/labels/labels.js | 10 ++--- .../components/labels/pie/get_pie_names.js | 23 ++++++++++ .../components/labels/pie/pie_labels.js | 26 ++++++++++++ .../labels/pie/remove_zero_slices.js | 17 ++++++++ .../components/labels/pie/return_pie_names.js | 22 ++++++++++ .../vislib/components/labels/uniq_labels.js | 1 - src/kibana/components/vislib/lib/data.js | 32 +++++++------- .../vislib/lib/handler/types/pie.js | 4 +- .../vislib/lib/handler/types/point_series.js | 2 +- src/kibana/components/vislib/lib/legend.js | 42 ++++++++++++------- 12 files changed, 137 insertions(+), 50 deletions(-) create mode 100644 src/kibana/components/vislib/components/labels/pie/get_pie_names.js create mode 100644 src/kibana/components/vislib/components/labels/pie/pie_labels.js create mode 100644 src/kibana/components/vislib/components/labels/pie/remove_zero_slices.js create mode 100644 src/kibana/components/vislib/components/labels/pie/return_pie_names.js diff --git a/src/kibana/components/vislib/components/labels/data_array.js b/src/kibana/components/vislib/components/labels/data_array.js index b5efd59fd7c47..5ef9bdcc5ef8e 100644 --- a/src/kibana/components/vislib/components/labels/data_array.js +++ b/src/kibana/components/vislib/components/labels/data_array.js @@ -1,22 +1,17 @@ define(function (require) { return function GetArrayUtilService(Private) { var _ = require('lodash'); - var flattenSeries = Private(require('components/vislib/components/labels/flatten_series')); /* * Accepts a Kibana data object and returns an array of values objects. */ - return function (obj) { if (!_.isObject(obj) || !obj.rows && !obj.columns && !obj.series) { throw new TypeError('GetArrayUtilService expects an object with a series, rows, or columns key'); } - if (!obj.series) { - return flattenSeries(obj); - } - + if (!obj.series) { return flattenSeries(obj); } return obj.series; }; }; diff --git a/src/kibana/components/vislib/components/labels/flatten_series.js b/src/kibana/components/vislib/components/labels/flatten_series.js index ce9ab413b7f55..3b77945c308d7 100644 --- a/src/kibana/components/vislib/components/labels/flatten_series.js +++ b/src/kibana/components/vislib/components/labels/flatten_series.js @@ -6,7 +6,6 @@ define(function (require) { * Accepts a Kibana data object with a rows or columns key * and returns an array of flattened series values. */ - return function (obj) { if (!_.isObject(obj) || !obj.rows && !obj.columns) { throw new TypeError('GetSeriesUtilService expects an object with either a rows or columns key'); diff --git a/src/kibana/components/vislib/components/labels/labels.js b/src/kibana/components/vislib/components/labels/labels.js index 264c82754eb4c..3e2acc99d360a 100644 --- a/src/kibana/components/vislib/components/labels/labels.js +++ b/src/kibana/components/vislib/components/labels/labels.js @@ -4,6 +4,7 @@ define(function (require) { var createArr = Private(require('components/vislib/components/labels/data_array')); var getArrOfUniqLabels = Private(require('components/vislib/components/labels/uniq_labels')); + var getPieLabels = Private(require('components/vislib/components/labels/pie/pie_labels')); /* * Accepts a Kibana data object and returns an array of unique labels (strings). @@ -12,12 +13,9 @@ define(function (require) { * * Currently, this service is only used for vertical bar charts and line charts. */ - - return function (obj) { - if (!_.isObject(obj)) { - throw new TypeError('LabelUtil expects an object'); - } - + return function (obj, chartType) { + if (!_.isObject(obj)) { throw new TypeError('LabelUtil expects an object'); } + if (chartType === 'pie') { return getPieLabels(obj); } return getArrOfUniqLabels(createArr(obj)); }; }; diff --git a/src/kibana/components/vislib/components/labels/pie/get_pie_names.js b/src/kibana/components/vislib/components/labels/pie/get_pie_names.js new file mode 100644 index 0000000000000..bbb280e3bebe8 --- /dev/null +++ b/src/kibana/components/vislib/components/labels/pie/get_pie_names.js @@ -0,0 +1,23 @@ +define(function (require) { + var _ = require('lodash'); + + return function GetPieNames(Private) { + var returnNames = Private(require('components/vislib/components/labels/pie/return_pie_names')); + + return function (data, columns) { + var slices = data.slices; + + if (slices.children) { + var namedObj = returnNames(slices.children, 0, columns); + + return _(namedObj) + .sortBy(function (obj) { + return obj.index; + }) + .pluck('key') + .unique() + .value(); + } + }; + }; +}); \ No newline at end of file diff --git a/src/kibana/components/vislib/components/labels/pie/pie_labels.js b/src/kibana/components/vislib/components/labels/pie/pie_labels.js new file mode 100644 index 0000000000000..169b0bbd4262c --- /dev/null +++ b/src/kibana/components/vislib/components/labels/pie/pie_labels.js @@ -0,0 +1,26 @@ +define(function (require) { + var _ = require('lodash'); + + return function PieLabels(Private) { + var removeZeroSlices = Private(require('components/vislib/components/labels/pie/remove_zero_slices')); + var getNames = Private(require('components/vislib/components/labels/pie/get_pie_names')); + + return function (obj) { + var data = obj.columns || obj.rows || [obj]; + var names = []; + + if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); } + + data.forEach(function (obj) { + var columns = obj.raw ? obj.raw.columns : undefined; + obj.slices = removeZeroSlices(obj.slices); + + getNames(obj, columns).forEach(function (name) { + names.push(name); + }); + }); + + return _.uniq(names); + }; + }; +}); diff --git a/src/kibana/components/vislib/components/labels/pie/remove_zero_slices.js b/src/kibana/components/vislib/components/labels/pie/remove_zero_slices.js new file mode 100644 index 0000000000000..d2be485a6b9fe --- /dev/null +++ b/src/kibana/components/vislib/components/labels/pie/remove_zero_slices.js @@ -0,0 +1,17 @@ +define(function (require) { + var _ = require('lodash'); + + return function RemoveZeroSlices() { + return function removeZeroSlices(slices) { + if (!slices.children) return slices; + + slices = _.clone(slices); + slices.children = slices.children.reduce(function (children, child) { + if (child.size !== 0) { children.push(removeZeroSlices(child)); } + return children; + }, []); + + return slices; + }; + }; +}); \ No newline at end of file diff --git a/src/kibana/components/vislib/components/labels/pie/return_pie_names.js b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js new file mode 100644 index 0000000000000..c95fb46d5bcb9 --- /dev/null +++ b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js @@ -0,0 +1,22 @@ +define(function () { + return function ReturnPieNames() { + return function returnNames(array, index, columns) { + var names = []; + + array.forEach(function (obj) { + var fieldFormatter = obj.aggConfig ? obj.aggConfig.fieldFormatter() : String; + names.push({ key: fieldFormatter(obj.name), index: index }); + + if (obj.children) { + var plusIndex = index + 1; + + returnNames(obj.children, plusIndex, columns).forEach(function (namedObj) { + names.push(namedObj); + }); + } + }); + + return names; + }; + }; +}); \ No newline at end of file diff --git a/src/kibana/components/vislib/components/labels/uniq_labels.js b/src/kibana/components/vislib/components/labels/uniq_labels.js index d0c2b160aa16f..699bbd401ad22 100644 --- a/src/kibana/components/vislib/components/labels/uniq_labels.js +++ b/src/kibana/components/vislib/components/labels/uniq_labels.js @@ -6,7 +6,6 @@ define(function (require) { * Accepts an array of data objects and a formatter function. * Returns a unique list of formatted labels (strings). */ - return function (arr) { if (!_.isArray(arr)) { throw new TypeError('UniqLabelUtil expects an array of objects'); diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index 6e8dfb7b25cec..b04e678475e6b 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -37,21 +37,8 @@ define(function (require) { this.data = data; this.type = this.getDataType(); - - this.labels; - - if (this.type === 'series') { - if (getLabels(data).length === 1 && getLabels(data)[0] === '') { - this.labels = [(this.get('yAxisLabel'))]; - } else { - this.labels = getLabels(data); - } - } else if (this.type === 'slices') { - this.labels = this.pieNames(); - } - + this.labels = this._getLabels(this.data); this.color = this.labels ? color(this.labels) : undefined; - this._normalizeOrdered(); this._attr = _.defaults(attr || {}, { @@ -73,6 +60,18 @@ define(function (require) { } } + Data.prototype._getLabels = function (data) { + if (this.type === 'series') { + if (getLabels(data).length === 1 && getLabels(data)[0] === '') { + return [(this.get('yAxisLabel'))]; + } else { + return getLabels(data); + } + } else if (this.type === 'slices') { + return this.pieNames(); + } + }; + /** * Returns true for positive numbers */ @@ -530,9 +529,8 @@ define(function (require) { * @method pieNames * @returns {Array} Array of unique names (strings) */ - Data.prototype.pieNames = function () { + Data.prototype.pieNames = function (data) { var self = this; - var data = this.getVisData(); var names = []; _.forEach(data, function (obj) { @@ -596,7 +594,7 @@ define(function (require) { * @returns {Function} Performs lookup on string and returns hex color */ Data.prototype.getPieColorFunc = function () { - return color(this.pieNames()); + return color(this.pieNames(this.getVisData())); }; /** diff --git a/src/kibana/components/vislib/lib/handler/types/pie.js b/src/kibana/components/vislib/lib/handler/types/pie.js index 8406ff315adca..c6ca26f1ffc39 100644 --- a/src/kibana/components/vislib/lib/handler/types/pie.js +++ b/src/kibana/components/vislib/lib/handler/types/pie.js @@ -10,10 +10,8 @@ define(function (require) { */ return function (vis) { - var data = new Data(vis.data, vis._attr); - return new Handler(vis, { - legend: new Legend(vis, data), + legend: new Legend(vis, vis.data), chartTitle: new ChartTitle(vis.el) }); }; diff --git a/src/kibana/components/vislib/lib/handler/types/point_series.js b/src/kibana/components/vislib/lib/handler/types/point_series.js index 8cdee54ebd554..e66730ceec6b0 100644 --- a/src/kibana/components/vislib/lib/handler/types/point_series.js +++ b/src/kibana/components/vislib/lib/handler/types/point_series.js @@ -27,7 +27,7 @@ define(function (require) { return new Handler(vis, { data: data, - legend: new Legend(vis, data), + legend: new Legend(vis, vis.data), axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')), chartTitle: new ChartTitle(vis.el), xAxis: new XAxis({ diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index c05ab46c21f14..47764e7e534df 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -5,6 +5,8 @@ define(function (require) { var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); var AggConfigResult = require('components/vis/_agg_config_result'); + var color = Private(require('components/vislib/components/color/color')); + var getLabels = Private(require('components/vislib/components/labels/labels')); require('css!components/vislib/styles/main'); @@ -24,19 +26,13 @@ define(function (require) { return new Legend(vis, data); } - var isPie = (vis._attr.type === 'pie'); - - if (isPie) { - this.dataLabels = this._transformPieData(data.pieData()); - } else { - this.dataLabels = this._transformSeriesData(data.getVisData()); - } - + this.events = new Dispatch(); this.vis = vis; - this.data = data; this.el = vis.el; - this.events = new Dispatch(); - this.color = isPie ? data.getPieColorFunc() : data.color; + this.data = this._getData(data); + this.labels = getLabels(data, vis._attr.type); + this.color = color(this.labels); + this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', 'blurredOpacity' : 0.3, @@ -47,6 +43,22 @@ define(function (require) { }); } + Legend.prototype._getLabels = function (data) { + if (data.series) { + if (data.series.length === 1 && getLabels(data)[0] === '') { + return [(this.get('yAxisLabel'))]; + } else { + return getLabels(data); + } + } else if (this.type === 'slices') { + return this.pieNames(); + } + }; + + Legend.prototype._getData = function (data) { + return data.columns || data.rows || [data.series] || [data.slices]; + }; + /** * Returns an arr of data objects that includes labels, aggConfig, and an array of data values * for the pie chart. @@ -122,7 +134,7 @@ define(function (require) { * @param args {Object|*} Legend options * @returns {*} HTML element */ - Legend.prototype.header = function (el, args) { + Legend.prototype._header = function (el, args) { return el.append('div') .attr('class', 'header') .append('div') @@ -141,7 +153,7 @@ define(function (require) { * @param args {Object|*} Legend options * @returns {D3.Selection} HTML element with list of labels attached */ - Legend.prototype.list = function (el, arrOfLabels, args) { + Legend.prototype._list = function (el, arrOfLabels, args) { var self = this; return el.append('ul') @@ -185,8 +197,8 @@ define(function (require) { var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); var items = this.dataLabels; - this.header(legendDiv, this); - this.list(legendDiv, items, this); + this._header(legendDiv, this); + this._list(legendDiv, items, this); var headerIcon = visEl.select('.legend-toggle'); From e4f7d1412a9c642550d3e97109f522a01202d58f Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 6 May 2015 09:33:19 -0400 Subject: [PATCH 17/43] troubleshooting bugs with pie in the legend --- src/kibana/components/vislib/lib/legend.js | 129 +++++++++++---------- 1 file changed, 68 insertions(+), 61 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 47764e7e534df..8641057949cec 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -30,7 +30,7 @@ define(function (require) { this.vis = vis; this.el = vis.el; this.data = this._getData(data); - this.labels = getLabels(data, vis._attr.type); + this.labels = this._getLabels(data, vis._attr.type); this.color = color(this.labels); this._attr = _.defaults(vis._attr || {}, { @@ -43,87 +43,95 @@ define(function (require) { }); } - Legend.prototype._getLabels = function (data) { - if (data.series) { - if (data.series.length === 1 && getLabels(data)[0] === '') { - return [(this.get('yAxisLabel'))]; - } else { - return getLabels(data); - } - } else if (this.type === 'slices') { - return this.pieNames(); + Legend.prototype._getLabels = function (data, type) { + if (data.series && data.series.length === 1 && getLabels(data)[0] === '') { + return [data.yAxisLabel]; } + return getLabels(data, type); }; Legend.prototype._getData = function (data) { - return data.columns || data.rows || [data.series] || [data.slices]; + return data.columns || data.rows || [data]; }; - /** - * Returns an arr of data objects that includes labels, aggConfig, and an array of data values - * for the pie chart. - */ - Legend.prototype._transformPieData = function (arr) { - var data = []; - var recurse = function (obj) { - if (obj.children) { - recurse(obj.children).reverse().forEach(function (d) { data.unshift(d); }); - } - return obj; - }; + Legend.prototype._filter = function (item) { + if (item !== undefined) return item; + }; - arr.forEach(function (chart) { - chart.slices.children.map(recurse) - .reverse().forEach(function (d) { data.unshift(d); }); - }); + Legend.prototype._reduce = function (a, b) { + return a.concat(b); + }; - return _.unique(data, function (d) { return d.name; }); + Legend.prototype._value = function (d) { + return d; }; /** * Filter out zero injected objects */ - Legend.prototype._filterZeroInjectedValues = function (arr) { - return arr.filter(function (d) { - return d.aggConfigResult !== undefined; - }); + Legend.prototype._filterZeroInjectedValues = function (d) { + return d.aggConfigResult !== undefined; }; - /** - * Returns an arr of data objects that includes labels, aggConfig, and an array of data values - * for the point series charts. - */ - Legend.prototype._transformSeriesData = function (arr) { - var data = []; + Legend.prototype._modifyPointSeriesLabels = function (data, labels) { var self = this; - arr.forEach(function (chart) { - chart.series.forEach(function (obj, i) { - var currentObj = data[i]; - if (!currentObj) data.push(obj); + return labels.map(function (label) { + var values = data.map(function (datum) { + if (datum.series) { + return datum.series.map(function (d) { + if (d.label !== label) return; + return d.values.map(self._value); + }) + .filter(self._filter) + .reduce(self._reduce); + } + }) + .reduce(self._reduce) + .filter(self._filterZeroInjectedValues); + var prevAggConfigResult; + var aggConfigResult; + + if (values.length && values[0].aggConfigResult) { + prevAggConfigResult = values[0].aggConfigResult.$parent; + aggConfigResult = new AggConfigResult(prevAggConfigResult.aggConfig, null, + prevAggConfigResult.value, prevAggConfigResult.key); + } - // Copies first aggConfigResults object to data object. - if (obj.values && obj.values.length) { - var values = self._filterZeroInjectedValues(obj.values); - var aggConfigResult; + return { + label: label, + aggConfigResult: aggConfigResult, + values: values + }; + }); + }; - if (values.length && values[0].aggConfigResult) { - aggConfigResult = values[0].aggConfigResult.$parent; - } + /** + * Returns an arr of data objects that includes labels, aggConfig, and an array of data values + * for the pie chart. + */ + Legend.prototype._modifyPieLabels = function (data) { + var labels = []; - if (aggConfigResult) { - obj.aggConfigResult = new AggConfigResult(aggConfigResult.aggConfig, null, - aggConfigResult.value, aggConfigResult.key); - } - } - // Joins all values arrays that share a common label - if (currentObj && currentObj.label === obj.label) { - currentObj.values = currentObj.values.concat(obj.values); + data.forEach(function (chart) { + chart.slices.children.map(function recurse(obj) { + if (obj.children) { + recurse(obj.children).reverse().forEach(function (d) { labels.unshift(d); }); } - }); + + return obj; + }) + .reverse() + .forEach(function (d) { labels.unshift(d); }); }); - return data; + labels.map(function (d) { d.aggConfigResult.$parent = undefined; }); + return _.unique(labels, function (d) { return d.name; }); + }; + + Legend.prototype._getDataLabels = function (data, type, labels) { + if (type === 'pie') return this._modifyPieLabels(data); + return this._modifyPointSeriesLabels(data, labels); }; /** @@ -169,7 +177,6 @@ define(function (require) { .each(self._addIdentifier) .html(function (d, i) { var label = d.label ? d.label : d.name; - if (!label) { label = self.data.get('yAxisLabel'); } return '' + label; }); }; @@ -196,7 +203,7 @@ define(function (require) { var self = this; var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); - var items = this.dataLabels; + var items = this._getDataLabels(this.data, this._attr.type, this.labels); this._header(legendDiv, this); this._list(legendDiv, items, this); From 3314dd05ab09092d33f2ffcacfde1da7cb5ad288 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 6 May 2015 16:56:58 -0400 Subject: [PATCH 18/43] fixing point series legend --- .../vislib/lib/handler/types/pie.js | 4 +- .../vislib/lib/handler/types/point_series.js | 2 +- src/kibana/components/vislib/lib/legend.js | 76 ++++++++++--------- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/kibana/components/vislib/lib/handler/types/pie.js b/src/kibana/components/vislib/lib/handler/types/pie.js index c6ca26f1ffc39..58877731d4529 100644 --- a/src/kibana/components/vislib/lib/handler/types/pie.js +++ b/src/kibana/components/vislib/lib/handler/types/pie.js @@ -10,8 +10,10 @@ define(function (require) { */ return function (vis) { + var data = new Data(vis.data, vis._attr); + return new Handler(vis, { - legend: new Legend(vis, vis.data), + legend: new Legend(vis, vis.data, data.getPieColorFunc()), chartTitle: new ChartTitle(vis.el) }); }; diff --git a/src/kibana/components/vislib/lib/handler/types/point_series.js b/src/kibana/components/vislib/lib/handler/types/point_series.js index e66730ceec6b0..ae1e7e6a5973e 100644 --- a/src/kibana/components/vislib/lib/handler/types/point_series.js +++ b/src/kibana/components/vislib/lib/handler/types/point_series.js @@ -27,7 +27,7 @@ define(function (require) { return new Handler(vis, { data: data, - legend: new Legend(vis, vis.data), + legend: new Legend(vis, vis.data, data.getColorFunc()), axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')), chartTitle: new ChartTitle(vis.el), xAxis: new XAxis({ diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 8641057949cec..a6451747305b0 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -5,7 +5,6 @@ define(function (require) { var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); var AggConfigResult = require('components/vis/_agg_config_result'); - var color = Private(require('components/vislib/components/color/color')); var getLabels = Private(require('components/vislib/components/labels/labels')); require('css!components/vislib/styles/main'); @@ -21,9 +20,9 @@ define(function (require) { * @param color {Function} Color function * @param _attr {Object|*} Reference to Vis options */ - function Legend(vis, data) { + function Legend(vis, data, color) { if (!(this instanceof Legend)) { - return new Legend(vis, data); + return new Legend(vis, data, color); } this.events = new Dispatch(); @@ -31,7 +30,7 @@ define(function (require) { this.el = vis.el; this.data = this._getData(data); this.labels = this._getLabels(data, vis._attr.type); - this.color = color(this.labels); + this.color = color; this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', @@ -70,28 +69,27 @@ define(function (require) { * Filter out zero injected objects */ Legend.prototype._filterZeroInjectedValues = function (d) { - return d.aggConfigResult !== undefined; + return (d.aggConfigResult !== undefined); }; Legend.prototype._modifyPointSeriesLabels = function (data, labels) { - var self = this; - return labels.map(function (label) { - var values = data.map(function (datum) { - if (datum.series) { - return datum.series.map(function (d) { - if (d.label !== label) return; - return d.values.map(self._value); - }) - .filter(self._filter) - .reduce(self._reduce); - } - }) - .reduce(self._reduce) - .filter(self._filterZeroInjectedValues); + var values = []; var prevAggConfigResult; var aggConfigResult; + data.forEach(function (datum) { + datum.series.forEach(function (d) { + if (d.label === label) { + d.values.forEach(function (e) { + if (e.aggConfigResult) { + values.push(e); + } + }); + } + }); + }); + if (values.length && values[0].aggConfigResult) { prevAggConfigResult = values[0].aggConfigResult.$parent; aggConfigResult = new AggConfigResult(prevAggConfigResult.aggConfig, null, @@ -110,27 +108,33 @@ define(function (require) { * Returns an arr of data objects that includes labels, aggConfig, and an array of data values * for the pie chart. */ - Legend.prototype._modifyPieLabels = function (data) { - var labels = []; - - data.forEach(function (chart) { - chart.slices.children.map(function recurse(obj) { - if (obj.children) { - recurse(obj.children).reverse().forEach(function (d) { labels.unshift(d); }); - } - - return obj; - }) - .reverse() - .forEach(function (d) { labels.unshift(d); }); - }); + Legend.prototype._modifyPieLabels = function (data, labels) { + return labels.map(function (label) { + var values = []; + var aggConfigResult; + + data.forEach(function (datum) { + datum.slices.children.forEach(function traverse(d) { + if (d.children) d.children.forEach(traverse); + if (d.name === label) values.push(d); + }); + }); - labels.map(function (d) { d.aggConfigResult.$parent = undefined; }); - return _.unique(labels, function (d) { return d.name; }); + if (values.length && values[0].aggConfigResult) { + aggConfigResult = values[0].aggConfigResult; + if (aggConfigResult.$parent) aggConfigResult.$parent = undefined; + } + + return { + label: label, + aggConfigResult: aggConfigResult, + values: values + }; + }); }; Legend.prototype._getDataLabels = function (data, type, labels) { - if (type === 'pie') return this._modifyPieLabels(data); + if (type === 'pie') return this._modifyPieLabels(data, labels); return this._modifyPointSeriesLabels(data, labels); }; From 983fbe21400cccb4d477157003b7a16135570e6d Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 6 May 2015 17:53:13 -0400 Subject: [PATCH 19/43] fixing bugs --- .../vislib/lib/handler/types/pie.js | 4 +-- .../vislib/lib/handler/types/point_series.js | 2 +- src/kibana/components/vislib/lib/legend.js | 30 ++++--------------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/kibana/components/vislib/lib/handler/types/pie.js b/src/kibana/components/vislib/lib/handler/types/pie.js index 58877731d4529..c6ca26f1ffc39 100644 --- a/src/kibana/components/vislib/lib/handler/types/pie.js +++ b/src/kibana/components/vislib/lib/handler/types/pie.js @@ -10,10 +10,8 @@ define(function (require) { */ return function (vis) { - var data = new Data(vis.data, vis._attr); - return new Handler(vis, { - legend: new Legend(vis, vis.data, data.getPieColorFunc()), + legend: new Legend(vis, vis.data), chartTitle: new ChartTitle(vis.el) }); }; diff --git a/src/kibana/components/vislib/lib/handler/types/point_series.js b/src/kibana/components/vislib/lib/handler/types/point_series.js index ae1e7e6a5973e..e66730ceec6b0 100644 --- a/src/kibana/components/vislib/lib/handler/types/point_series.js +++ b/src/kibana/components/vislib/lib/handler/types/point_series.js @@ -27,7 +27,7 @@ define(function (require) { return new Handler(vis, { data: data, - legend: new Legend(vis, vis.data, data.getColorFunc()), + legend: new Legend(vis, vis.data), axisTitle: new AxisTitle(vis.el, data.get('xAxisLabel'), data.get('yAxisLabel')), chartTitle: new ChartTitle(vis.el), xAxis: new XAxis({ diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index a6451747305b0..32ff8db3c0d09 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -6,6 +6,7 @@ define(function (require) { var dataLabel = require('components/vislib/lib/_data_label'); var AggConfigResult = require('components/vis/_agg_config_result'); var getLabels = Private(require('components/vislib/components/labels/labels')); + var color = Private(require('components/vislib/components/color/color')); require('css!components/vislib/styles/main'); @@ -20,9 +21,9 @@ define(function (require) { * @param color {Function} Color function * @param _attr {Object|*} Reference to Vis options */ - function Legend(vis, data, color) { + function Legend(vis, data) { if (!(this instanceof Legend)) { - return new Legend(vis, data, color); + return new Legend(vis, data); } this.events = new Dispatch(); @@ -30,7 +31,7 @@ define(function (require) { this.el = vis.el; this.data = this._getData(data); this.labels = this._getLabels(data, vis._attr.type); - this.color = color; + this.color = color(this.labels); this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', @@ -53,25 +54,6 @@ define(function (require) { return data.columns || data.rows || [data]; }; - Legend.prototype._filter = function (item) { - if (item !== undefined) return item; - }; - - Legend.prototype._reduce = function (a, b) { - return a.concat(b); - }; - - Legend.prototype._value = function (d) { - return d; - }; - - /** - * Filter out zero injected objects - */ - Legend.prototype._filterZeroInjectedValues = function (d) { - return (d.aggConfigResult !== undefined); - }; - Legend.prototype._modifyPointSeriesLabels = function (data, labels) { return labels.map(function (label) { var values = []; @@ -133,7 +115,7 @@ define(function (require) { }); }; - Legend.prototype._getDataLabels = function (data, type, labels) { + Legend.prototype._getDataLabels = function (data, labels, type) { if (type === 'pie') return this._modifyPieLabels(data, labels); return this._modifyPointSeriesLabels(data, labels); }; @@ -207,7 +189,7 @@ define(function (require) { var self = this; var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); - var items = this._getDataLabels(this.data, this._attr.type, this.labels); + var items = this._getDataLabels(this.data, this.labels, this._attr.type); this._header(legendDiv, this); this._list(legendDiv, items, this); From eee7ee1b6e744cb5ae0b4b22ae6bd667ad9259e5 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 7 May 2015 11:18:09 -0400 Subject: [PATCH 20/43] fixing tests --- src/kibana/components/vislib/lib/legend.js | 5 +- test/unit/specs/vislib/lib/data.js | 4 +- test/unit/specs/vislib/lib/dispatch.js | 24 +++++---- test/unit/specs/vislib/lib/legend.js | 57 ++++++++++++---------- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 32ff8db3c0d09..59ed2573ad689 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -64,14 +64,13 @@ define(function (require) { datum.series.forEach(function (d) { if (d.label === label) { d.values.forEach(function (e) { - if (e.aggConfigResult) { - values.push(e); - } + values.push(e); }); } }); }); + values = values.filter(function (d) { return d.aggConfigResult; }); // Remove zero injected values if (values.length && values[0].aggConfigResult) { prevAggConfigResult = values[0].aggConfigResult.$parent; aggConfigResult = new AggConfigResult(prevAggConfigResult.aggConfig, null, diff --git a/test/unit/specs/vislib/lib/data.js b/test/unit/specs/vislib/lib/data.js index c8d5aef8771e4..d6fb1c1388cd1 100644 --- a/test/unit/specs/vislib/lib/data.js +++ b/test/unit/specs/vislib/lib/data.js @@ -217,6 +217,7 @@ define(function (require) { }; var DataFactory; var data; + var slices; beforeEach(function () { module('DataFactory'); @@ -226,12 +227,11 @@ define(function (require) { inject(function (Private) { DataFactory = Private(require('components/vislib/lib/data')); data = new DataFactory(pieData, {}); - data._removeZeroSlices(pieData.slices); + slices = data._removeZeroSlices(pieData.slices); }); }); it('should remove zero values', function () { - var slices = data.data.slices; expect(slices.children.length).to.be(2); }); }); diff --git a/test/unit/specs/vislib/lib/dispatch.js b/test/unit/specs/vislib/lib/dispatch.js index bfa87ece5ffba..52845b4d5b0ec 100644 --- a/test/unit/specs/vislib/lib/dispatch.js +++ b/test/unit/specs/vislib/lib/dispatch.js @@ -106,21 +106,27 @@ define(function (require) { }); describe('Custom event handlers', function () { - it('should attach whatever gets passed on vis.on() to dispatch', function (done) { - var vis; - var chart; + var vis; + + beforeEach(function () { module('AreaChartFactory'); + }); + + beforeEach(function () { inject(function (Private) { vis = Private(require('vislib_fixtures/_vis_fixture'))(); - vis.on('someEvent', _.noop); + vis.on('click', _.noop); vis.render(data); + }); + }); - vis.handler.charts.forEach(function (chart) { - expect(chart.events.dispatch.someEvent).to.be.a(Function); - }); + afterEach(function () { + destroyVis(vis); + }); - destroyVis(vis); - done(); + it('should attach whatever gets passed on vis.on() to dispatch', function () { + vis.handler.charts.forEach(function (chart) { + expect(chart.events.dispatch.click).to.be.a(Function); }); }); }); diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 4cc23818e49bc..7e9620e881a3e 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -60,8 +60,9 @@ define(function (require) { vis = null; }); - describe('_transformPieData method', function () { - var pieData = { + describe('_modifyPieLabels method', function () { + var labels = ['m', 'n', 'b', 's', 't', 'u']; + var pieData = [{ slices: { children: [ { name: 'm', size: 20 }, @@ -77,29 +78,16 @@ define(function (require) { { name: 'b', size: 40 } ] } - }; + }]; it('should flatten the nested objects', function () { - var items = Legend.prototype._transformPieData([pieData]); + var items = Legend.prototype._modifyPieLabels(pieData, labels); expect(items.length).to.be(6); }); }); - describe('_filterZeroInjectedValues method', function () { - // Zero injected values do not contain aggConfigResults - var seriesData = [ - { aggConfigResult: {} }, - { aggConfigResult: {} }, - {} - ]; - - it('should remove zero injected values', function () { - var items = Legend.prototype._filterZeroInjectedValues(seriesData); - expect(items.length).to.be(2); - }); - }); - - describe('_transformSeriesData method', function () { + describe('_modifyPointSeriesLabels method', function () { + var labels = ['html', 'css', 'png']; var seriesData = [ { series: [ @@ -132,12 +120,33 @@ define(function (require) { values: [{y: 8}, {y: 9}, {y: 10}] } ] - }, + } ]; it('should combine values arrays of objects with identical labels', function () { - var items = Legend.prototype._transformSeriesData(seriesData); + seriesData.forEach(function (obj) { + obj.series.forEach(function (data) { + data.values.forEach(function (d) { + d.aggConfigResult = { + $parent: { + $parent: undefined, + aggConfig: { + schema: { + group: 'bucket' + } + }, + key: data.label, + type: 'bucket', + value: data.label + }, + }; + }); + }); + }); + + var items = Legend.prototype._modifyPointSeriesLabels(seriesData, labels); expect(items.length).to.be(3); + items.forEach(function (item) { expect(item.values.length).to.be(6); }); @@ -148,7 +157,7 @@ define(function (require) { it('should match the slice label', function () { var chartType = chartTypes[i]; var paths = $(vis.el).find(chartSelectors[chartType]).toArray(); - var items = vis.handler.legend.dataLabels; + var items = vis.handler.legend.labels; items.forEach(function (d) { var path = _(paths) @@ -156,9 +165,7 @@ define(function (require) { return path.getAttribute('data-label'); }) .filter(function (dataLabel) { - var label = d.label ? d.label : d.name; - - return dataLabel === label.toString(); + return dataLabel === d; }) .value(); From f054ca373656ed093a57a06f0235f8f0cbd0a222 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 11 May 2015 15:15:45 -0400 Subject: [PATCH 21/43] adding back clickable legend labels --- .../components/vislib/lib/handler/handler.js | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/kibana/components/vislib/lib/handler/handler.js b/src/kibana/components/vislib/lib/handler/handler.js index 1f37e1786364a..23da01fdc0833 100644 --- a/src/kibana/components/vislib/lib/handler/handler.js +++ b/src/kibana/components/vislib/lib/handler/handler.js @@ -77,28 +77,6 @@ define(function (require) { } }; - /** - * Adds event listeners - */ - Handler.prototype._addEventListeners = function (chart) { - var self = this; - var enabledEvents; - - if (chart.events.dispatch) { - enabledEvents = this.vis.eventTypes.enabled; - - // Copy dispatch.on methods to chart object - d3.rebind(chart, chart.events.dispatch, 'on'); - - // Bind events to chart(s) - if (enabledEvents.length) { - enabledEvents.forEach(function (event) { - self.enable(event, chart); - }); - } - } - }; - /** * Renders the constructors that create the visualization, * including the chart constructor @@ -116,7 +94,9 @@ define(function (require) { this._validateData(); this.renderArray.forEach(function (property) { if (property instanceof Legend) { - self._addEventListeners(property); + self.vis.activeEvents().forEach(function (event) { + self.enable(event, property); + }); } if (typeof property.render === 'function') { @@ -133,7 +113,6 @@ define(function (require) { self.enable(event, chart); }); - self._addEventListeners(chart); charts.push(chart); chart.render(); }); From deca71903e2178536e5f27277672d7d00bfeed26 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 18 May 2015 10:21:31 -0400 Subject: [PATCH 22/43] fixing bug --- src/kibana/components/vislib/lib/legend.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 59ed2573ad689..a998af33b80ce 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -30,7 +30,7 @@ define(function (require) { this.vis = vis; this.el = vis.el; this.data = this._getData(data); - this.labels = this._getLabels(data, vis._attr.type); + this.labels = this._getLabels(this.data, vis._attr.type); this.color = color(this.labels); this._attr = _.defaults(vis._attr || {}, { @@ -44,10 +44,19 @@ define(function (require) { } Legend.prototype._getLabels = function (data, type) { - if (data.series && data.series.length === 1 && getLabels(data)[0] === '') { - return [data.yAxisLabel]; - } - return getLabels(data, type); + var labelArray = []; + + data.forEach(function (d) { + if (d.series && d.series.length === 1 && getLabels(d)[0] === '') { + return labelArray.push(d.yAxisLabel); + } + + getLabels(d, type).forEach(function (label) { + return labelArray.push(label); + }); + }); + + return _.unique(labelArray); }; Legend.prototype._getData = function (data) { From ef3da967c1e4f51644826ec473affc935456f409 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 19 May 2015 13:26:14 -0400 Subject: [PATCH 23/43] resolving issue with undefined labels in legend --- src/kibana/components/vislib/lib/legend.js | 11 ++++------- test/unit/specs/vislib/lib/legend.js | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index a998af33b80ce..05bbc7108f128 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -170,8 +170,7 @@ define(function (require) { .attr('class', 'color') .each(self._addIdentifier) .html(function (d, i) { - var label = d.label ? d.label : d.name; - return '' + label; + return '' + d.label; }); }; @@ -182,11 +181,9 @@ define(function (require) { * @param label {string} label to use */ Legend.prototype._addIdentifier = function (d) { - var label = d.label ? d.label : d.name; - dataLabel(this, label); + dataLabel(this, d.label); }; - /** * Renders legend * @@ -225,7 +222,7 @@ define(function (require) { legendDiv.select('.legend-ul').selectAll('li') .on('mouseover', function (d) { - var label = d.label ? d.label : d.name; + var label = d.label; var charts = visEl.selectAll('.chart'); function filterLabel() { @@ -273,7 +270,7 @@ define(function (require) { }); legendDiv.selectAll('li.color').each(function (d) { - var label = d.label ? d.label : d.name; + var label = d.label; if (label !== undefined && label !== '_all') { d3.select(this).call(self.events.addClickEvent()); } diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 7e9620e881a3e..90ca9858fa768 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -40,16 +40,18 @@ define(function (require) { }; var Legend; var vis; + var $el; beforeEach(function () { module('LegendFactory'); }); beforeEach(function () { - inject(function (Private) { + inject(function (Private, d3) { vis = Private(require('vislib_fixtures/_vis_fixture'))(visLibParams); Legend = Private(require('components/vislib/lib/legend')); require('css!components/vislib/styles/main'); + $el = d3.select('body').append('div').attr('class', 'fake-legend'); vis.render(data); }); @@ -57,6 +59,7 @@ define(function (require) { afterEach(function () { $(vis.el).remove(); + $('.fake-legend').remove(); vis = null; }); @@ -188,6 +191,22 @@ define(function (require) { it('should contain a list of items', function () { expect($(vis.el).find('li').length).to.be.greaterThan(1); }); + it('should not return an undefined value', function () { + var emptyObject = { + label: '' + }; + var labels = [emptyObject, emptyObject, emptyObject]; + var args = { + _attr: {isOpen: true}, + color: function () { return 'blue'; } + }; + + Legend.prototype._list($el, labels, args); + + $el.selectAll('li').each(function (d) { + expect(d.label).not.to.be(undefined); + }); + }); }); describe('render method', function () { From 1bf987f151055d1388b51e5196950e28b8a8ab3c Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 19 May 2015 14:01:31 -0400 Subject: [PATCH 24/43] #3873. Fixing issue with numbers and dates not being highlighted properly in pie charts. --- .../vislib/components/labels/pie/return_pie_names.js | 3 +-- src/kibana/components/vislib/lib/dispatch.js | 3 +-- src/kibana/components/vislib/lib/legend.js | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/kibana/components/vislib/components/labels/pie/return_pie_names.js b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js index c95fb46d5bcb9..7521a76374bc8 100644 --- a/src/kibana/components/vislib/components/labels/pie/return_pie_names.js +++ b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js @@ -4,8 +4,7 @@ define(function () { var names = []; array.forEach(function (obj) { - var fieldFormatter = obj.aggConfig ? obj.aggConfig.fieldFormatter() : String; - names.push({ key: fieldFormatter(obj.name), index: index }); + names.push({ key: obj.name, index: index }); if (obj.children) { var plusIndex = index + 1; diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index c7aad3607bd0a..ae96e927a784c 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -237,8 +237,7 @@ define(function (require) { .select('.legend-ul') .selectAll('li.color') .filter(function (d, i) { - var thisLabel = d.label ? d.label : d.name; - return thisLabel !== label; + return d.label.toString() !== label; }) .classed('blur_shape', true); }; diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 05bbc7108f128..dddec24e3169e 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -170,7 +170,9 @@ define(function (require) { .attr('class', 'color') .each(self._addIdentifier) .html(function (d, i) { - return '' + d.label; + var aggConfig = d.aggConfigResult ? d.aggConfigResult.aggConfig : undefined; + var fieldFormatter = aggConfig ? aggConfig.fieldFormatter() : String; + return '' + fieldFormatter(d.label); }); }; From 960292dc74e8ba747b1a67df94f3360d8edab5fd Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 19 May 2015 14:18:46 -0400 Subject: [PATCH 25/43] fixing tests --- test/unit/specs/vislib/lib/legend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 90ca9858fa768..a5b83f3628475 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -168,7 +168,7 @@ define(function (require) { return path.getAttribute('data-label'); }) .filter(function (dataLabel) { - return dataLabel === d; + return dataLabel === d.toString(); }) .value(); From 12a21b8a0cbc22e789e21e0dc2e6098861cfe5f9 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 19 May 2015 14:57:17 -0400 Subject: [PATCH 26/43] removing reference to aggConfigResult.aggConfig.fieldFormatter() --- src/kibana/components/vislib/lib/legend.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index dddec24e3169e..242cab3be32ce 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -102,6 +102,7 @@ define(function (require) { return labels.map(function (label) { var values = []; var aggConfigResult; + var aggConfig; data.forEach(function (datum) { datum.slices.children.forEach(function traverse(d) { @@ -115,8 +116,13 @@ define(function (require) { if (aggConfigResult.$parent) aggConfigResult.$parent = undefined; } + if (values.length && values[0].aggConfig) { + aggConfig = values[0].aggConfig; + } + return { label: label, + aggConfig: aggConfig, aggConfigResult: aggConfigResult, values: values }; @@ -170,7 +176,7 @@ define(function (require) { .attr('class', 'color') .each(self._addIdentifier) .html(function (d, i) { - var aggConfig = d.aggConfigResult ? d.aggConfigResult.aggConfig : undefined; + var aggConfig = d.aggConfig ? d.aggConfig : undefined; var fieldFormatter = aggConfig ? aggConfig.fieldFormatter() : String; return '' + fieldFormatter(d.label); }); From 418c153f546d947046006cc3c5ed6980c02055d0 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 19 May 2015 16:23:22 -0400 Subject: [PATCH 27/43] making corrections based on @spalger pr comments --- .../vislib/components/labels/data_array.js | 2 +- .../components/labels/pie/get_pie_names.js | 16 +++++++--------- .../components/labels/pie/return_pie_names.js | 4 +--- src/kibana/components/vislib/lib/data.js | 10 +++------- src/kibana/components/vislib/lib/dispatch.js | 2 +- .../components/vislib/lib/handler/types/pie.js | 2 +- src/kibana/components/vislib/lib/legend.js | 10 +++++----- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/kibana/components/vislib/components/labels/data_array.js b/src/kibana/components/vislib/components/labels/data_array.js index 5ef9bdcc5ef8e..de2f41976ae3f 100644 --- a/src/kibana/components/vislib/components/labels/data_array.js +++ b/src/kibana/components/vislib/components/labels/data_array.js @@ -11,7 +11,7 @@ define(function (require) { throw new TypeError('GetArrayUtilService expects an object with a series, rows, or columns key'); } - if (!obj.series) { return flattenSeries(obj); } + if (!obj.series) return flattenSeries(obj); return obj.series; }; }; diff --git a/src/kibana/components/vislib/components/labels/pie/get_pie_names.js b/src/kibana/components/vislib/components/labels/pie/get_pie_names.js index bbb280e3bebe8..01cf2fc2f12fc 100644 --- a/src/kibana/components/vislib/components/labels/pie/get_pie_names.js +++ b/src/kibana/components/vislib/components/labels/pie/get_pie_names.js @@ -8,15 +8,13 @@ define(function (require) { var slices = data.slices; if (slices.children) { - var namedObj = returnNames(slices.children, 0, columns); - - return _(namedObj) - .sortBy(function (obj) { - return obj.index; - }) - .pluck('key') - .unique() - .value(); + return _(returnNames(slices.children, 0, columns)) + .sortBy(function (obj) { + return obj.index; + }) + .pluck('key') + .unique() + .value(); } }; }; diff --git a/src/kibana/components/vislib/components/labels/pie/return_pie_names.js b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js index 7521a76374bc8..36aa21d82f7cc 100644 --- a/src/kibana/components/vislib/components/labels/pie/return_pie_names.js +++ b/src/kibana/components/vislib/components/labels/pie/return_pie_names.js @@ -7,9 +7,7 @@ define(function () { names.push({ key: obj.name, index: index }); if (obj.children) { - var plusIndex = index + 1; - - returnNames(obj.children, plusIndex, columns).forEach(function (namedObj) { + returnNames(obj.children, (index + 1), columns).forEach(function (namedObj) { names.push(namedObj); }); } diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index b04e678475e6b..54edb2ff31cdf 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -62,14 +62,10 @@ define(function (require) { Data.prototype._getLabels = function (data) { if (this.type === 'series') { - if (getLabels(data).length === 1 && getLabels(data)[0] === '') { - return [(this.get('yAxisLabel'))]; - } else { - return getLabels(data); - } - } else if (this.type === 'slices') { - return this.pieNames(); + if (getLabels(data).length === 1 && getLabels(data)[0] === '') return [(this.get('yAxisLabel'))]; + return getLabels(data); } + return this.pieNames(); }; /** diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index ae96e927a784c..325750b332ffc 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -237,7 +237,7 @@ define(function (require) { .select('.legend-ul') .selectAll('li.color') .filter(function (d, i) { - return d.label.toString() !== label; + return String(d.label) !== label; }) .classed('blur_shape', true); }; diff --git a/src/kibana/components/vislib/lib/handler/types/pie.js b/src/kibana/components/vislib/lib/handler/types/pie.js index c6ca26f1ffc39..10293e4bdda56 100644 --- a/src/kibana/components/vislib/lib/handler/types/pie.js +++ b/src/kibana/components/vislib/lib/handler/types/pie.js @@ -11,7 +11,7 @@ define(function (require) { return function (vis) { return new Handler(vis, { - legend: new Legend(vis, vis.data), + legend: new Legend(vis), chartTitle: new ChartTitle(vis.el) }); }; diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 242cab3be32ce..e802bf48a53a5 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -21,16 +21,16 @@ define(function (require) { * @param color {Function} Color function * @param _attr {Object|*} Reference to Vis options */ - function Legend(vis, data) { + function Legend(vis) { if (!(this instanceof Legend)) { - return new Legend(vis, data); + return new Legend(vis); } this.events = new Dispatch(); this.vis = vis; this.el = vis.el; - this.data = this._getData(data); - this.labels = this._getLabels(this.data, vis._attr.type); + this.dataValues = this._getData(vis.data); + this.labels = this._getLabels(this.dataValues, vis._attr.type); this.color = color(this.labels); this._attr = _.defaults(vis._attr || {}, { @@ -202,7 +202,7 @@ define(function (require) { var self = this; var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); - var items = this._getDataLabels(this.data, this.labels, this._attr.type); + var items = this._getDataLabels(this.dataValues, this.labels, this._attr.type); this._header(legendDiv, this); this._list(legendDiv, items, this); From a5ca179afd6b1229848980ff86f2cd6e1dd8c879 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 11 Jun 2015 16:19:20 -0400 Subject: [PATCH 28/43] fixing test in data.js --- test/unit/specs/vislib/lib/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/vislib/lib/data.js b/test/unit/specs/vislib/lib/data.js index bf85158c35314..8606209fdcdc5 100644 --- a/test/unit/specs/vislib/lib/data.js +++ b/test/unit/specs/vislib/lib/data.js @@ -136,10 +136,10 @@ define(function (require) { beforeEach(function () { data = new Data(pieData, {}); - data._removeZeroSlices(pieData.slices); }); it('should remove zero values', function () { + var slices = data._removeZeroSlices(data.data.slices); expect(slices.children.length).to.be(2); }); }); From ae1612947d90cd131fd710e798ebe6ca55d01acb Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 15 Jun 2015 11:06:40 -0400 Subject: [PATCH 29/43] changes --- src/kibana/components/vislib/lib/legend.js | 133 +++++++-------------- 1 file changed, 46 insertions(+), 87 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index c5deddb339b7e..ddfd731bb66a7 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -4,7 +4,6 @@ define(function (require) { var Dispatch = Private(require('components/vislib/lib/dispatch')); var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); - var AggConfigResult = require('components/vis/_agg_config_result'); var getLabels = Private(require('components/vislib/components/labels/labels')); var color = Private(require('components/vislib/components/color/color')); @@ -26,12 +25,24 @@ define(function (require) { return new Legend(vis); } + var data = vis.data.columns || vis.data.rows || [vis.data]; + var type = vis._attr.type; + var labelValues; + + function getValues(arr) { + return arr.map() + } + this.events = new Dispatch(); this.vis = vis; this.el = vis.el; - this.dataValues = this._getData(vis.data); - this.labels = this._getLabels(this.dataValues, vis._attr.type); - this.color = color(this.labels); + this.labels = this._getLabels(data, type); + + labelValues = this.labels.map(function (obj) { + return obj.label; + }); + + this.color = color(labelValues); this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', @@ -43,95 +54,43 @@ define(function (require) { }); } - Legend.prototype._getLabels = function (data, type) { - var labelArray = []; - - data.forEach(function (d) { - if (d.series && d.series.length === 1 && getLabels(d)[0] === '') { - return labelArray.push(d.yAxisLabel); - } - - getLabels(d, type).forEach(function (label) { - return labelArray.push(label); - }); - }); - - return _.unique(labelArray); - }; - - Legend.prototype._getData = function (data) { - return data.columns || data.rows || [data]; - }; + Legend.prototype._getSeriesLabels = function (data) { + if (data && data.length === 1 && data[0].series.length === 1 && data[0].series[0].label === '') { + return data[0].yAxisLabel; + } - Legend.prototype._modifyPointSeriesLabels = function (data, labels) { - return labels.map(function (label) { - var values = []; - var prevAggConfigResult; - var aggConfigResult; - - data.forEach(function (datum) { - datum.series.forEach(function (d) { - if (d.label === label) { - d.values.forEach(function (e) { - values.push(e); - }); - } - }); + return data.map(function (chart) { + return chart.series.map(function (series) { + return series; }); - - values = values.filter(function (d) { return d.aggConfigResult; }); // Remove zero injected values - if (values.length && values[0].aggConfigResult) { - prevAggConfigResult = values[0].aggConfigResult.$parent; - aggConfigResult = new AggConfigResult(prevAggConfigResult.aggConfig, null, - prevAggConfigResult.value, prevAggConfigResult.key); - } - - return { - label: label, - aggConfigResult: aggConfigResult, - values: values - }; + }).reduce(function (a, b) { + return a.concat(b); }); }; - /** - * Returns an arr of data objects that includes labels, aggConfig, and an array of data values - * for the pie chart. - */ - Legend.prototype._modifyPieLabels = function (data, labels) { - return labels.map(function (label) { - var values = []; - var aggConfigResult; - var aggConfig; - - data.forEach(function (datum) { - datum.slices.children.forEach(function traverse(d) { - if (d.children) d.children.forEach(traverse); - if (d.name === label) values.push(d); - }); - }); - - if (values.length && values[0].aggConfigResult) { - aggConfigResult = values[0].aggConfigResult; - if (aggConfigResult.$parent) aggConfigResult.$parent = undefined; - } - - if (values.length && values[0].aggConfig) { - aggConfig = values[0].aggConfig; - } - - return { - label: label, - aggConfig: aggConfig, - aggConfigResult: aggConfigResult, - values: values - }; - }); - }; + Legend.prototype._getLabels = function (data, type) { + if (type === 'pie') { + return this._modifyPieLabels(data); + } - Legend.prototype._getDataLabels = function (data, labels, type) { - if (type === 'pie') return this._modifyPieLabels(data, labels); - return this._modifyPointSeriesLabels(data, labels); + return this._getSeriesLabels(data); + + //var labelArray = []; + // + //if (data && data.length === 1 && data[0].label === '') { + // return labelArray.push() + //} + //data.forEach(function (d) { + // if (d && d.length === 1 && getLabels(chart)[0] === '') { + // return labelArray.push(chart.yAxisLabel); + // } + // + // getLabels(chart, type).forEach(function (label) { + // return labelArray.push(label); + // }); + //}); + // + //return _.unique(labelArray); }; /** From ebaeb49124e3987c3aee313db43dd68623506413 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Mon, 15 Jun 2015 18:38:51 -0400 Subject: [PATCH 30/43] creating data label functions --- src/kibana/components/vislib/lib/legend.js | 80 ++++++++++------------ 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index ddfd731bb66a7..9bc67d03c1201 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -4,7 +4,6 @@ define(function (require) { var Dispatch = Private(require('components/vislib/lib/dispatch')); var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); - var getLabels = Private(require('components/vislib/components/labels/labels')); var color = Private(require('components/vislib/components/color/color')); require('css!components/vislib/styles/main'); @@ -27,23 +26,13 @@ define(function (require) { var data = vis.data.columns || vis.data.rows || [vis.data]; var type = vis._attr.type; - var labelValues; - - function getValues(arr) { - return arr.map() - } + var labels = this.labels = this._getLabels(data, type); + var labelsArray = labels.map(function (obj) { return obj.label; }); this.events = new Dispatch(); this.vis = vis; this.el = vis.el; - this.labels = this._getLabels(data, type); - - labelValues = this.labels.map(function (obj) { - return obj.label; - }); - - this.color = color(labelValues); - + this.color = color(labelsArray); this._attr = _.defaults(vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', 'blurredOpacity' : 0.3, @@ -54,43 +43,44 @@ define(function (require) { }); } + Legend.prototype._modifyPieLabels = function (data) { + var values = []; + + data.forEach(function (datum) { + datum.slices.children.forEach(function traverse(d) { + if (d.children) d.children.forEach(traverse); + values.push({ + label: d.name, + values: d + }); + }); + }); + + return _.uniq(values, 'label'); + }; + Legend.prototype._getSeriesLabels = function (data) { - if (data && data.length === 1 && data[0].series.length === 1 && data[0].series[0].label === '') { - return data[0].yAxisLabel; - } + var isOneSeries = data.every(function (chart) { + return chart.series.length === 1; + }); + + var values = data.map(function (chart) { + var yLabel = isOneSeries ? chart.yAxisLabel : undefined; - return data.map(function (chart) { return chart.series.map(function (series) { + if (yLabel) series.label = yLabel; return series; }); }).reduce(function (a, b) { return a.concat(b); }); + + return _.uniq(values, 'label'); }; Legend.prototype._getLabels = function (data, type) { - if (type === 'pie') { - return this._modifyPieLabels(data); - } - + if (type === 'pie') return this._modifyPieLabels(data); return this._getSeriesLabels(data); - - //var labelArray = []; - // - //if (data && data.length === 1 && data[0].label === '') { - // return labelArray.push() - //} - //data.forEach(function (d) { - // if (d && d.length === 1 && getLabels(chart)[0] === '') { - // return labelArray.push(chart.yAxisLabel); - // } - // - // getLabels(chart, type).forEach(function (label) { - // return labelArray.push(label); - // }); - //}); - // - //return _.unique(labelArray); }; /** @@ -133,15 +123,15 @@ define(function (require) { .enter() .append('li') .attr('class', 'color') - .each(function (label) { + .each(function (d) { var li = d3.select(this); - self._addIdentifier.call(this, label); + self._addIdentifier.call(this, d); li.append('i') .attr('class', 'fa fa-circle dots') - .attr('style', 'color:' + args.color(label)); + .attr('style', 'color:' + args.color(d.label)); - li.append('span').text(label); + li.append('span').text(d.label); }); }; @@ -165,7 +155,7 @@ define(function (require) { var self = this; var visEl = d3.select(this.el); var legendDiv = visEl.select('.' + this._attr.legendClass); - var items = this._getDataLabels(this.dataValues, this.labels, this._attr.type); + var items = this.labels; this._header(legendDiv, this); this._list(legendDiv, items, this); @@ -242,7 +232,7 @@ define(function (require) { legendDiv.selectAll('li.color').each(function (d) { var label = d.label; - if (label !== undefined && label !== '_all') { + if (label && label !== '_all') { d3.select(this).call(self.events.addClickEvent()); } }); From d244ddbf22b03e74c0ce4e749a33b9a3cdecf6d3 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 16 Jun 2015 10:47:05 -0400 Subject: [PATCH 31/43] changes --- src/kibana/components/vislib/lib/legend.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 9bc67d03c1201..c8c9361c88d6f 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -110,7 +110,7 @@ define(function (require) { * @param args {Object|*} Legend options * @returns {D3.Selection} HTML element with list of labels attached */ - Legend.prototype._list = function (el, arrOfLabels, args) { + Legend.prototype._list = function (el, data, args) { var self = this; return el.append('ul') @@ -119,7 +119,7 @@ define(function (require) { return 'legend-ul hidden'; }) .selectAll('li') - .data(arrOfLabels) + .data(data) .enter() .append('li') .attr('class', 'color') From b36434ea5ea9f5cb8bbc64ef66d352e70ec6dd24 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Tue, 16 Jun 2015 15:01:53 -0400 Subject: [PATCH 32/43] troubleshooting --- src/kibana/components/vislib/lib/legend.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index c8c9361c88d6f..875c5f1d53a3d 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -48,11 +48,12 @@ define(function (require) { data.forEach(function (datum) { datum.slices.children.forEach(function traverse(d) { - if (d.children) d.children.forEach(traverse); values.push({ label: d.name, values: d }); + + if (d.children) d.children.forEach(traverse); }); }); From f6954cff9f25d0698138893f8609723711f02860 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 17 Jun 2015 18:02:42 -0400 Subject: [PATCH 33/43] adding code to click handler to deal with legend values --- .../components/filter_bar/filter_bar_click_handler.js | 11 ++++++++++- src/kibana/components/vislib/lib/legend.js | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/filter_bar/filter_bar_click_handler.js b/src/kibana/components/filter_bar/filter_bar_click_handler.js index 8632b9e18bf51..45b8eb1375571 100644 --- a/src/kibana/components/filter_bar/filter_bar_click_handler.js +++ b/src/kibana/components/filter_bar/filter_bar_click_handler.js @@ -9,13 +9,22 @@ define(function (require) { // Hierarchical and tabular data set their aggConfigResult parameter // differently because of how the point is rewritten between the two. So // we need to check if the point.orig is set, if not use try the point.aggConfigResult - var aggConfigResult = event.point.orig && event.point.orig.aggConfigResult || event.point.aggConfigResult; + var aggConfigResult = event.point.orig && event.point.orig.aggConfigResult || + event.point.values && event.point.values[_.findIndex(event.point.values, 'aggConfigResult')].aggConfigResult + || event.point.aggConfigResult; var notify = new Notifier({ location: 'Filter bar' }); if (aggConfigResult) { + var isLegendLabel = !!event.point.values; var results = _.filter(aggConfigResult.getPath(), { type: 'bucket' }); + + results = isLegendLabel ? _.filter(results, function (obj) { + var formatter = obj.aggConfig.fieldFormatter(); // TODO: find out if there is always a fieldFormatter + return formatter(obj.key) === event.label; + }) : results; + var filters = _(results) .map(function (result) { try { diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 875c5f1d53a3d..0215d787bd83a 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -74,6 +74,11 @@ define(function (require) { }); }).reduce(function (a, b) { return a.concat(b); + }).filter(function (series) { + // Return only objects with an aggConfigResult + return series.values.some(function (d) { + return d.aggConfigResult; + }); }); return _.uniq(values, 'label'); From ac3243c9dce1dae6238e764939d427f5b2b81a39 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 17 Jun 2015 18:17:57 -0400 Subject: [PATCH 34/43] refactoring --- .../filter_bar/filter_bar_click_handler.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/kibana/components/filter_bar/filter_bar_click_handler.js b/src/kibana/components/filter_bar/filter_bar_click_handler.js index 45b8eb1375571..2bbe62d395bd5 100644 --- a/src/kibana/components/filter_bar/filter_bar_click_handler.js +++ b/src/kibana/components/filter_bar/filter_bar_click_handler.js @@ -10,20 +10,26 @@ define(function (require) { // differently because of how the point is rewritten between the two. So // we need to check if the point.orig is set, if not use try the point.aggConfigResult var aggConfigResult = event.point.orig && event.point.orig.aggConfigResult || - event.point.values && event.point.values[_.findIndex(event.point.values, 'aggConfigResult')].aggConfigResult - || event.point.aggConfigResult; + event.point.values && findAggConfig(event.point.values) || event.point.aggConfigResult; var notify = new Notifier({ location: 'Filter bar' }); + function findAggConfig(values) { + return values.aggConfigResult || values[_.findIndex(values, 'aggConfigResult')].aggConfigResult; + } + if (aggConfigResult) { var isLegendLabel = !!event.point.values; var results = _.filter(aggConfigResult.getPath(), { type: 'bucket' }); - results = isLegendLabel ? _.filter(results, function (obj) { - var formatter = obj.aggConfig.fieldFormatter(); // TODO: find out if there is always a fieldFormatter - return formatter(obj.key) === event.label; - }) : results; + if (isLegendLabel) { + // TODO: find out if there is always a fieldFormatter + results = _.filter(results, function (obj) { + var formatter = obj.aggConfig.fieldFormatter(); + return formatter(obj.key) === event.label; + }); + } var filters = _(results) .map(function (result) { From c19a0af3771ff7a576f016f67750f21fd97de5b9 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 18 Jun 2015 15:12:20 -0400 Subject: [PATCH 35/43] cleaning up tests, fixing issues with pie charts --- .../filter_bar/filter_bar_click_handler.js | 20 ++-- src/kibana/components/vislib/lib/data.js | 12 ++- src/kibana/components/vislib/lib/legend.js | 30 ++---- test/unit/specs/vislib/lib/legend.js | 97 +------------------ 4 files changed, 29 insertions(+), 130 deletions(-) diff --git a/src/kibana/components/filter_bar/filter_bar_click_handler.js b/src/kibana/components/filter_bar/filter_bar_click_handler.js index 2bbe62d395bd5..e36523269bc13 100644 --- a/src/kibana/components/filter_bar/filter_bar_click_handler.js +++ b/src/kibana/components/filter_bar/filter_bar_click_handler.js @@ -16,20 +16,24 @@ define(function (require) { }); function findAggConfig(values) { - return values.aggConfigResult || values[_.findIndex(values, 'aggConfigResult')].aggConfigResult; + if (_.isArray(values)) { // point series chart + var index = _.findIndex(values, 'aggConfigResult'); + return values[index].aggConfigResult; + } + return values.aggConfigResult; // pie chart + } + + function findLabel(obj) { + // TODO: find out if there is always a fieldFormatter + var formatter = obj.aggConfig.fieldFormatter(); + return formatter(obj.key) === event.label; } if (aggConfigResult) { var isLegendLabel = !!event.point.values; var results = _.filter(aggConfigResult.getPath(), { type: 'bucket' }); - if (isLegendLabel) { - // TODO: find out if there is always a fieldFormatter - results = _.filter(results, function (obj) { - var formatter = obj.aggConfig.fieldFormatter(); - return formatter(obj.key) === event.label; - }); - } + if (isLegendLabel) results = _.filter(results, findLabel); // filter results array by legend label var filters = _(results) .map(function (result) { diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index a5f472a48b670..5058ae2267127 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -463,7 +463,7 @@ define(function (require) { var self = this; _.forEach(array, function (obj) { - names.push({ key: obj.name, index: index }); + names.push({ label: obj.name, values: obj, index: index }); if (obj.children) { var plusIndex = index + 1; @@ -497,8 +497,10 @@ define(function (require) { .sortBy(function (obj) { return obj.index; }) - .pluck('key') - .unique() + //.pluck('key') + .unique(function (d) { + return d.label; + }) .value(); } }; @@ -596,7 +598,9 @@ define(function (require) { * @returns {Function} Performs lookup on string and returns hex color */ Data.prototype.getPieColorFunc = function () { - return color(this.pieNames(this.getVisData())); + return color(this.pieNames(this.getVisData()).map(function (d) { + return d.label; + })); }; /** diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 0215d787bd83a..bb2670dc37882 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -2,6 +2,7 @@ define(function (require) { return function LegendFactory(d3, Private) { var _ = require('lodash'); var Dispatch = Private(require('components/vislib/lib/dispatch')); + var Data = Private(require('components/vislib/lib/data')); var legendHeaderTemplate = _.template(require('text!components/vislib/partials/legend_header.html')); var dataLabel = require('components/vislib/lib/_data_label'); var color = Private(require('components/vislib/components/color/color')); @@ -43,21 +44,8 @@ define(function (require) { }); } - Legend.prototype._modifyPieLabels = function (data) { - var values = []; - - data.forEach(function (datum) { - datum.slices.children.forEach(function traverse(d) { - values.push({ - label: d.name, - values: d - }); - - if (d.children) d.children.forEach(traverse); - }); - }); - - return _.uniq(values, 'label'); + Legend.prototype._getPieLabels = function (data) { + return Data.prototype.pieNames(data); }; Legend.prototype._getSeriesLabels = function (data) { @@ -72,20 +60,16 @@ define(function (require) { if (yLabel) series.label = yLabel; return series; }); - }).reduce(function (a, b) { + }) + .reduce(function (a, b) { return a.concat(b); - }).filter(function (series) { - // Return only objects with an aggConfigResult - return series.values.some(function (d) { - return d.aggConfigResult; - }); }); return _.uniq(values, 'label'); }; Legend.prototype._getLabels = function (data, type) { - if (type === 'pie') return this._modifyPieLabels(data); + if (type === 'pie') return this._getPieLabels(data); return this._getSeriesLabels(data); }; @@ -238,7 +222,7 @@ define(function (require) { legendDiv.selectAll('li.color').each(function (d) { var label = d.label; - if (label && label !== '_all') { + if (label !== undefined && label !== '_all') { d3.select(this).call(self.events.addClickEvent()); } }); diff --git a/test/unit/specs/vislib/lib/legend.js b/test/unit/specs/vislib/lib/legend.js index 7e1bc21b6ca66..f21bb7f56aee5 100644 --- a/test/unit/specs/vislib/lib/legend.js +++ b/test/unit/specs/vislib/lib/legend.js @@ -63,108 +63,15 @@ define(function (require) { vis = null; }); - describe('_modifyPieLabels method', function () { - var labels = ['m', 'n', 'b', 's', 't', 'u']; - var pieData = [{ - slices: { - children: [ - { name: 'm', size: 20 }, - { - name: 'n', - size: 30, - children: [ - { name: 's', size: 10 }, - { name: 't', size: 20 }, - { name: 'u', size: 4 } - ] - }, - { name: 'b', size: 40 } - ] - } - }]; - - it('should flatten the nested objects', function () { - var items = Legend.prototype._modifyPieLabels(pieData, labels); - expect(items.length).to.be(6); - }); - }); - - describe('_modifyPointSeriesLabels method', function () { - var labels = ['html', 'css', 'png']; - var seriesData = [ - { - series: [ - { - label: 'html', - values: [{y: 2}, {y: 3}, {y: 4}] - }, - { - label: 'css', - values: [{y: 5}, {y: 6}, {y: 7}] - }, - { - label: 'png', - values: [{y: 8}, {y: 9}, {y: 10}] - } - ] - }, - { - series: [ - { - label: 'html', - values: [{y: 2}, {y: 3}, {y: 4}] - }, - { - label: 'css', - values: [{y: 5}, {y: 6}, {y: 7}] - }, - { - label: 'png', - values: [{y: 8}, {y: 9}, {y: 10}] - } - ] - } - ]; - - it('should combine values arrays of objects with identical labels', function () { - seriesData.forEach(function (obj) { - obj.series.forEach(function (data) { - data.values.forEach(function (d) { - d.aggConfigResult = { - $parent: { - $parent: undefined, - aggConfig: { - schema: { - group: 'bucket' - } - }, - key: data.label, - type: 'bucket', - value: data.label - }, - }; - }); - }); - }); - - var items = Legend.prototype._modifyPointSeriesLabels(seriesData, labels); - expect(items.length).to.be(3); - - items.forEach(function (item) { - expect(item.values.length).to.be(6); - }); - }); - }); - describe('legend item label matches vis item label', function () { it('should match the slice label', function () { var chartType = chartTypes[i]; var paths = $(vis.el).find(chartSelectors[chartType]).toArray(); var items = vis.handler.legend.labels; - items.forEach(function (label) { + items.forEach(function (d) { var path = _.find(paths, function (path) { - return path.getAttribute('data-label') === String(label); + return path.getAttribute('data-label') === String(d.label); }); expect(path).to.be.ok(); From 4c8548e849441797948034c72130144a9434bf93 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 18 Jun 2015 15:17:08 -0400 Subject: [PATCH 36/43] correcting _.uniq function --- src/kibana/components/vislib/lib/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index 5058ae2267127..a6bf3e9224189 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -546,7 +546,7 @@ define(function (require) { }); }); - return _.uniq(names); + return _.uniq(names, 'label'); }; /** From 5495c7fcc30b11f962ec8a317f0ed4b68c2535dc Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 18 Jun 2015 15:29:59 -0400 Subject: [PATCH 37/43] removing commented code --- src/kibana/components/vislib/lib/data.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index a6bf3e9224189..e9b178dadc145 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -497,7 +497,6 @@ define(function (require) { .sortBy(function (obj) { return obj.index; }) - //.pluck('key') .unique(function (d) { return d.label; }) From 17a6ae524cfb1777a0d7c5b427ad92beec4d3ec2 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 25 Jun 2015 07:27:33 -0400 Subject: [PATCH 38/43] refactoring --- src/kibana/components/vislib/lib/dispatch.js | 2 +- src/kibana/components/vislib/lib/legend.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/kibana/components/vislib/lib/dispatch.js b/src/kibana/components/vislib/lib/dispatch.js index 40906fa804fa7..3977d8499a795 100644 --- a/src/kibana/components/vislib/lib/dispatch.js +++ b/src/kibana/components/vislib/lib/dispatch.js @@ -43,7 +43,7 @@ define(function (require) { var series = isSeries ? data.series : undefined; var slices = isSlices ? data.slices : undefined; var handler = this.handler; - var color = _.deepGet(handler, 'data.color'); + var color = _.get(handler, 'data.color'); var isPercentage = (handler && handler._attr.mode === 'percentage'); var eventData = { diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index bb2670dc37882..412605e27d705 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -15,10 +15,6 @@ define(function (require) { * @class Legend * @constructor * @param vis {Object} Reference to Vis Constructor - * @param el {HTMLElement} Reference to DOM element - * @param labels {Array} Array of chart labels - * @param color {Function} Color function - * @param _attr {Object|*} Reference to Vis options */ function Legend(vis) { if (!(this instanceof Legend)) { @@ -34,7 +30,7 @@ define(function (require) { this.vis = vis; this.el = vis.el; this.color = color(labelsArray); - this._attr = _.defaults(vis._attr || {}, { + this._attr = _.defaults({}, vis._attr || {}, { 'legendClass' : 'legend-col-wrapper', 'blurredOpacity' : 0.3, 'focusOpacity' : 1, From ad2d228bbcaf98842ae4613cde0679676212aafd Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 9 Jul 2015 16:04:30 -0400 Subject: [PATCH 39/43] refactoring based on review comments --- .../filter_bar/filter_bar_click_handler.js | 17 ++++++++++++----- src/kibana/components/vislib/lib/data.js | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/kibana/components/filter_bar/filter_bar_click_handler.js b/src/kibana/components/filter_bar/filter_bar_click_handler.js index e53a2d94d50e8..ca0af22b268bd 100644 --- a/src/kibana/components/filter_bar/filter_bar_click_handler.js +++ b/src/kibana/components/filter_bar/filter_bar_click_handler.js @@ -6,14 +6,21 @@ define(function (require) { return function (Notifier) { return function ($state) { return function (event) { - // Hierarchical and tabular data set their aggConfigResult parameter - // differently because of how the point is rewritten between the two. So - // we need to check if the point.orig is set, if not use try the point.aggConfigResult - var aggConfigResult = event.point.orig && event.point.orig.aggConfigResult || - event.point.values && findAggConfig(event.point.values) || event.point.aggConfigResult; var notify = new Notifier({ location: 'Filter bar' }); + var aggConfigResult; + + // Hierarchical and tabular data set their aggConfigResult parameter + // differently because of how the point is rewritten between the two. So + // we need to check if the point.orig is set, if not use try the point.aggConfigResult + if (event.point.orig) { + aggConfigResult = event.point.orig.aggConfigResult; + } else if (event.point.values) { + aggConfigResult = findAggConfig(event.point.values); + } else { + aggConfigResult = event.point.aggConfigResult; + } function findAggConfig(values) { if (_.isArray(values)) { // point series chart diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index ed38f9b85d49b..ceaf62d136bc9 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -62,7 +62,8 @@ define(function (require) { Data.prototype._getLabels = function (data) { if (this.type === 'series') { - if (getLabels(data).length === 1 && getLabels(data)[0] === '') return [(this.get('yAxisLabel'))]; + var noLabel = getLabels(data).length === 1 && getLabels(data)[0] === ''; + if (noLabel) return [(this.get('yAxisLabel'))]; return getLabels(data); } return this.pieNames(); From 1060a4144bb0842cd7a13c46f001eb1a9386c877 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 15 Jul 2015 16:21:05 -0400 Subject: [PATCH 40/43] refactoring according to @jbudz 's comments. --- .../components/vislib/components/labels/pie/pie_labels.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kibana/components/vislib/components/labels/pie/pie_labels.js b/src/kibana/components/vislib/components/labels/pie/pie_labels.js index 169b0bbd4262c..9f75f623bd76b 100644 --- a/src/kibana/components/vislib/components/labels/pie/pie_labels.js +++ b/src/kibana/components/vislib/components/labels/pie/pie_labels.js @@ -6,11 +6,11 @@ define(function (require) { var getNames = Private(require('components/vislib/components/labels/pie/get_pie_names')); return function (obj) { + if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); } + var data = obj.columns || obj.rows || [obj]; var names = []; - if (!_.isObject(obj)) { throw new TypeError('PieLabel expects an object'); } - data.forEach(function (obj) { var columns = obj.raw ? obj.raw.columns : undefined; obj.slices = removeZeroSlices(obj.slices); From 153a60ae50759d7d3abf1b0b1fe94ec58b09cb29 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Wed, 15 Jul 2015 16:41:52 -0400 Subject: [PATCH 41/43] fixing bug with clicking on a legend that is not associated with any values --- src/kibana/components/vislib/lib/legend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 412605e27d705..ea40440acb271 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -59,7 +59,7 @@ define(function (require) { }) .reduce(function (a, b) { return a.concat(b); - }); + }, []); return _.uniq(values, 'label'); }; From c243f8d410699e2de89ee0f6daa277b2ce9c97b6 Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 16 Jul 2015 10:53:12 -0400 Subject: [PATCH 42/43] removing pointer from legend when value === Count --- src/kibana/components/vislib/lib/legend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index ea40440acb271..26f2403438eff 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -177,7 +177,7 @@ define(function (require) { return pointLabel !== label.toString(); } - if (label && label !== '_all') { + if (label && label !== '_all' && label !== 'Count') { d3.select(this).style('cursor', 'pointer'); } From 7dbba6b6260930f7c0b7db263b6e74ac59ff430e Mon Sep 17 00:00:00 2001 From: Shelby Sturgis Date: Thu, 16 Jul 2015 10:54:30 -0400 Subject: [PATCH 43/43] reverting previous change --- src/kibana/components/vislib/lib/legend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/legend.js b/src/kibana/components/vislib/lib/legend.js index 26f2403438eff..ea40440acb271 100644 --- a/src/kibana/components/vislib/lib/legend.js +++ b/src/kibana/components/vislib/lib/legend.js @@ -177,7 +177,7 @@ define(function (require) { return pointLabel !== label.toString(); } - if (label && label !== '_all' && label !== 'Count') { + if (label && label !== '_all') { d3.select(this).style('cursor', 'pointer'); }