Browse Source

Add legend.hide option - #731

pull/742/head
Masayuki Tanaka 10 years ago
parent
commit
dbd6461239
  1. 4
      c3.js
  2. 10
      c3.min.js
  3. 45
      spec/legend-spec.js
  4. 1
      src/config.js
  5. 3
      src/core.js

4
c3.js

@ -179,6 +179,9 @@
if (config.data_hide) { if (config.data_hide) {
$$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide); $$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide);
} }
if (config.legend_hide) {
$$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide);
}
// when gauge, hide legend // TODO: fix // when gauge, hide legend // TODO: fix
if ($$.hasType('gauge')) { if ($$.hasType('gauge')) {
@ -988,6 +991,7 @@
color_threshold: {}, color_threshold: {},
// legend // legend
legend_show: true, legend_show: true,
legend_hide: false,
legend_position: 'bottom', legend_position: 'bottom',
legend_inset_anchor: 'top-left', legend_inset_anchor: 'top-left',
legend_inset_x: 10, legend_inset_x: 10,

10
c3.min.js vendored

File diff suppressed because one or more lines are too long

45
spec/legend-spec.js

@ -106,4 +106,49 @@ describe('c3 chart legend', function () {
}); });
describe('legend.hide', function () {
it('should update args', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 130, 100, 200, 100, 250, 150]
]
},
legend: {
hide: true
}
};
expect(true).toBeTruthy();
});
it('should not show legends', function () {
d3.selectAll('.c3-legend-item').each(function () {
expect(d3.select(this).style('visibility')).toBe('hidden');
});
});
it('should update args', function () {
args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 130, 100, 200, 100, 250, 150]
]
},
legend: {
hide: 'data2'
}
};
expect(true).toBeTruthy();
});
it('should not show legends', function () {
expect(d3.select('.c3-legend-item-data1').style('visibility')).toBe('visible');
expect(d3.select('.c3-legend-item-data2').style('visibility')).toBe('hidden');
});
});
}); });

1
src/config.js

@ -68,6 +68,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
color_threshold: {}, color_threshold: {},
// legend // legend
legend_show: true, legend_show: true,
legend_hide: false,
legend_position: 'bottom', legend_position: 'bottom',
legend_inset_anchor: 'top-left', legend_inset_anchor: 'top-left',
legend_inset_x: 10, legend_inset_x: 10,

3
src/core.js

@ -174,6 +174,9 @@ c3_chart_internal_fn.initWithData = function (data) {
if (config.data_hide) { if (config.data_hide) {
$$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide); $$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide);
} }
if (config.legend_hide) {
$$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide);
}
// when gauge, hide legend // TODO: fix // when gauge, hide legend // TODO: fix
if ($$.hasType('gauge')) { if ($$.hasType('gauge')) {

Loading…
Cancel
Save