Skip to content

Commit

Permalink
Fix grid filtering to add and remove - #720
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki0812 committed Nov 16, 2014
1 parent 3dad31a commit 12cb277
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3507,7 +3507,7 @@
return params ? function (line) {
var found = false;
[].concat(params).forEach(function (param) {
if ((('value' in param && line.value === params.value) || ('class' in param && line['class'] === params['class']))) {
if ((('value' in param && line.value === param.value) || ('class' in param && line['class'] === param['class']))) {
found = true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion c3.min.js

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions spec/api.grid-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var describe = window.describe,
expect = window.expect,
it = window.it,
beforeEach = window.beforeEach;

describe('c3 api grid', function () {
'use strict';

var chart, d3;

var args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250]
]
}
};

beforeEach(function (done) {
chart = window.initChart(chart, args, done);
d3 = chart.internal.d3;
});

describe('ygrid.add and ygrid.remove', function () {

it('should update y grids', function (done) {
var main = chart.internal.main,
expectedGrids = [
{
value: 100,
text: 'Pressure Low'
},
{
value: 200,
text: 'Pressure High'
}
],
grids;

// Call ygrids.add
chart.ygrids.add(expectedGrids);
setTimeout(function () {
grids = main.selectAll('.c3-ygrid-line');
expect(grids.size()).toBe(expectedGrids.length);
grids.each(function (d, i) {
var y = +d3.select(this).select('line').attr('y1'),
text = d3.select(this).select('text').text(),
expectedY = Math.round(chart.internal.y(expectedGrids[i].value)),
expectedText = expectedGrids[i].text;
expect(y).toBe(expectedY);
expect(text).toBe(expectedText);
});

// Call ygrids.remove
chart.ygrids.remove(expectedGrids);
setTimeout(function () {
grids = main.selectAll('.c3-ygrid-line');
expect(grids.size()).toBe(0);
}, 500);

}, 500);


setTimeout(function () {
done();
}, 1200);
});

});

});
2 changes: 1 addition & 1 deletion src/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ c3_chart_internal_fn.getGridFilterToRemove = function (params) {
return params ? function (line) {
var found = false;
[].concat(params).forEach(function (param) {
if ((('value' in param && line.value === params.value) || ('class' in param && line['class'] === params['class']))) {
if ((('value' in param && line.value === param.value) || ('class' in param && line['class'] === param['class']))) {
found = true;
}
});
Expand Down

0 comments on commit 12cb277

Please sign in to comment.