Browse Source

Fix legend when revert called - #790

pull/807/head
Masayuki Tanaka 10 years ago
parent
commit
cd316b3b60
  1. 2
      c3.js
  2. 2
      c3.min.js
  3. 62
      spec/api.focus-spec.js
  4. 2
      src/api.focus.js

2
c3.js

@ -5690,7 +5690,9 @@
if ($$.hasArcType()) { if ($$.hasArcType()) {
$$.unexpandArc(targetIds); $$.unexpandArc(targetIds);
} }
if ($$.config.legend_show) {
$$.showLegend(targetIds); $$.showLegend(targetIds);
}
$$.focusedTargetIds = []; $$.focusedTargetIds = [];
$$.defocusedTargetIds = []; $$.defocusedTargetIds = [];

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

62
spec/api.focus-spec.js

@ -368,4 +368,66 @@ describe('c3 api load', function () {
}); });
describe('when legend.show = false', function () {
it('should update args to hide legend', function () {
args.legend = {
show: false
};
expect(true).toBeTruthy();
});
it('should focus all targets without showing legend', function (done) {
var main = chart.internal.main,
legend = chart.internal.legend;
chart.focus();
setTimeout(function () {
var targets = main.select('.c3-chart-line.c3-target'),
legendItems = legend.select('.c3-legend-item');
targets.each(function () {
var line = d3.select(this);
expect(line.classed('c3-focused')).toBeTruthy();
});
expect(legendItems.size()).toBeCloseTo(0);
done();
}, 500);
});
it('should defocus all targets without showing legend', function (done) {
var main = chart.internal.main,
legend = chart.internal.legend;
chart.defocus();
setTimeout(function () {
var targets = main.select('.c3-chart-line.c3-target'),
legendItems = legend.select('.c3-legend-item');
targets.each(function () {
var line = d3.select(this);
expect(line.classed('c3-defocused')).toBeTruthy();
});
expect(legendItems.size()).toBeCloseTo(0);
done();
}, 500);
});
it('should revert all targets after focus', function (done) {
var main = chart.internal.main,
legend = chart.internal.legend;
chart.focus();
setTimeout(function () {
chart.revert();
setTimeout(function () {
var targets = main.select('.c3-chart-line.c3-target'),
legendItems = legend.select('.c3-legend-item');
targets.each(function () {
var line = d3.select(this);
expect(line.classed('c3-focused')).toBeFalsy();
});
expect(legendItems.size()).toBeCloseTo(0);
done();
}, 500);
}, 500);
});
});
}); });

2
src/api.focus.js

@ -47,7 +47,9 @@ c3_chart_fn.revert = function (targetIds) {
if ($$.hasArcType()) { if ($$.hasArcType()) {
$$.unexpandArc(targetIds); $$.unexpandArc(targetIds);
} }
if ($$.config.legend_show) {
$$.showLegend(targetIds); $$.showLegend(targetIds);
}
$$.focusedTargetIds = []; $$.focusedTargetIds = [];
$$.defocusedTargetIds = []; $$.defocusedTargetIds = [];

Loading…
Cancel
Save