Skip to content

Commit

Permalink
Updating label in case of split charts for rows & columns
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravsinghania committed Jul 17, 2015
1 parent 4782bd6 commit c6a045a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/kibana/components/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
*/
Expand Down
79 changes: 79 additions & 0 deletions test/unit/specs/vislib/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit c6a045a

Please sign in to comment.