Browse Source

issue 1662 (#1663)

Fixes issue #1662.
pull/1947/merge
Robert Elliott 8 years ago committed by Ændrew Rininsland
parent
commit
9a43cda97d
  1. 1
      .gitignore
  2. 59
      spec/data-spec.js
  3. 14
      src/data.js

1
.gitignore vendored

@ -6,6 +6,7 @@ d3.min.js
components components
build build
.sass-cache .sass-cache
.idea/
# coverage report # coverage report
/coverage /coverage

59
spec/data-spec.js

@ -186,6 +186,65 @@ describe('c3 chart data', function () {
}); });
}); });
describe('addHiddenTargetIds if not already hidden', function () {
it('should update args', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 150, 120, 110, 140, 115, 125]
]
}
};
expect(true).toBeTruthy();
});
it('length of hiddenTargetIds should not change if same key added twice', function () {
chart.internal.addHiddenTargetIds('data1');
expect(chart.internal.hiddenTargetIds.length).toBe(1);
chart.internal.addHiddenTargetIds('data1');
expect(chart.internal.hiddenTargetIds.length).toBe(1);
chart.hide('data1');
expect(chart.internal.hiddenTargetIds.length).toBe(1);
chart.internal.addHiddenTargetIds('data2');
expect(chart.internal.hiddenTargetIds.length).toBe(2);
chart.show();
chart.hide(['data1', 'data2']);
expect(chart.internal.hiddenTargetIds.length).toBe(2);
chart.show();
chart.hide();
expect(chart.internal.hiddenTargetIds.length).toBe(2);
});
});
describe('addHiddenLegendIds if not already hidden', function () {
it('should update args', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 150, 120, 110, 140, 115, 125]
]
}
};
expect(true).toBeTruthy();
});
it('length of hiddenLegendIds should not change if same key added twice', function () {
chart.internal.addHiddenLegendIds('data1');
expect(chart.internal.hiddenLegendIds.length).toBe(1);
chart.internal.addHiddenLegendIds('data1');
expect(chart.internal.hiddenLegendIds.length).toBe(1);
chart.hide('data1', {withLegend: true});
expect(chart.internal.hiddenLegendIds.length).toBe(1);
chart.hide('data2', {withLegend: true});
expect(chart.internal.hiddenLegendIds.length).toBe(2);
chart.show(['data1', 'data2'], {withLegend: true});
chart.hide(['data1', 'data2'], {withLegend: true});
expect(chart.internal.hiddenLegendIds.length).toBe(2);
});
});
describe('data.xs', function () { describe('data.xs', function () {
beforeAll(function () { beforeAll(function () {

14
src/data.js

@ -179,13 +179,23 @@ c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) {
return xs.sort(function (a, b) { return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; }); return xs.sort(function (a, b) { return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; });
}; };
c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) {
this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); targetIds = (targetIds instanceof Array) ? targetIds : new Array(targetIds);
for (var i = 0; i < targetIds.length; i++) {
if (this.hiddenTargetIds.indexOf(targetIds[i]) < 0) {
this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds[i]);
}
}
}; };
c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) {
this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
}; };
c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) {
this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); targetIds = (targetIds instanceof Array) ? targetIds : new Array(targetIds);
for (var i = 0; i < targetIds.length; i++) {
if (this.hiddenLegendIds.indexOf(targetIds[i]) < 0) {
this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds[i]);
}
}
}; };
c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) { c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) {
this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; });

Loading…
Cancel
Save