From c6a045a528663447f1f43cb9b605be5519ea7072 Mon Sep 17 00:00:00 2001 From: Gaurav Singhania Date: Fri, 17 Jul 2015 16:12:38 +0530 Subject: [PATCH] Updating label in case of split charts for rows & columns --- src/kibana/components/vislib/lib/data.js | 18 +++++- test/unit/specs/vislib/lib/data.js | 79 ++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/vislib/lib/data.js b/src/kibana/components/vislib/lib/data.js index 97264e71b43e1..24964abf126ec 100644 --- a/src/kibana/components/vislib/lib/data.js +++ b/src/kibana/components/vislib/lib/data.js @@ -43,7 +43,7 @@ define(function (require) { if (this.type === 'series') { if (getLabels(data).length === 1 && getLabels(data)[0] === '') { this.labels = [(this.get('yAxisLabel'))]; - this.data.series[0].label = this.get('yAxisLabel'); + this._updateData(); } else { this.labels = getLabels(data); } @@ -74,6 +74,22 @@ define(function (require) { } } + Data.prototype._updateData = function () { + if (this.data.rows) { + _.map(this.data.rows, this._updateDataSeriesLabel, this); + } else if (this.data.columns) { + _.map(this.data.columns, this._updateDataSeriesLabel, this); + } else { + this._updateDataSeriesLabel(this.data); + } + }; + + Data.prototype._updateDataSeriesLabel = function (eachData) { + if (eachData.series) { + eachData.series[0].label = this.get('yAxisLabel'); + } + }; + /** * Returns true for positive numbers */ diff --git a/test/unit/specs/vislib/lib/data.js b/test/unit/specs/vislib/lib/data.js index 10e4e70377035..0723632480afb 100644 --- a/test/unit/specs/vislib/lib/data.js +++ b/test/unit/specs/vislib/lib/data.js @@ -120,8 +120,87 @@ define(function (require) { var rowIn = new Data(rowsData, {}); expect(_.isObject(rowIn)).to.be(true); }); + + it('should update label in series data', function () { + var seriesDataWithoutLabelInSeries = { + 'label': '', + 'series': [ + { + 'label': '', + 'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}] + } + ], + 'yAxisLabel': 'customLabel' + }; + var modifiedData = new Data(seriesDataWithoutLabelInSeries, {}); + expect(modifiedData.data.series[0].label).to.be('customLabel'); + }); + + it('should update label in row data', function () { + var seriesDataWithoutLabelInRow = { + 'rows': [ + { + 'label': '', + 'series': [ + { + 'label': '', + 'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}] + } + ], + 'yAxisLabel': 'customLabel' + }, + { + 'label': '', + 'series': [ + { + 'label': '', + 'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}] + } + ], + 'yAxisLabel': 'customLabel' + } + ], + }; + + var modifiedData = new Data(seriesDataWithoutLabelInRow, {}); + expect(modifiedData.data.rows[0].series[0].label).to.be('customLabel'); + expect(modifiedData.data.rows[1].series[0].label).to.be('customLabel'); + }); + + it('should update label in column data', function () { + var seriesDataWithoutLabelInRow = { + 'columns': [ + { + 'label': '', + 'series': [ + { + 'label': '', + 'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}] + } + ], + 'yAxisLabel': 'customLabel' + }, + { + 'label': '', + 'series': [ + { + 'label': '', + 'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}] + } + ], + 'yAxisLabel': 'customLabel' + } + ], + 'yAxisLabel': 'customLabel' + }; + + var modifiedData = new Data(seriesDataWithoutLabelInRow, {}); + expect(modifiedData.data.columns[0].series[0].label).to.be('customLabel'); + expect(modifiedData.data.columns[1].series[0].label).to.be('customLabel'); + }); }); + describe('_removeZeroSlices', function () { var data; var pieData = {