Browse Source

Accept alt click on legend to show only one data - #550

pull/590/head
Masayuki Tanaka 10 years ago
parent
commit
6a4d0179d1
  1. 23
      c3.js
  2. 4
      c3.min.js
  3. 11
      src/legend.js

23
c3.js

@ -3662,7 +3662,16 @@
.style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; })
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('click', function (id) { .on('click', function (id) {
config.legend_item_onclick ? config.legend_item_onclick.call($$, id) : $$.api.toggle(id); if (config.legend_item_onclick) {
config.legend_item_onclick.call($$, id);
} else {
if ($$.d3.event.altKey) {
$$.api.hide();
$$.api.show(id);
} else {
$$.api.toggle(id);
}
}
}) })
.on('mouseover', function (id) { .on('mouseover', function (id) {
$$.d3.select(this).classed(CLASS.legendItemFocused, true); $$.d3.select(this).classed(CLASS.legendItemFocused, true);
@ -5353,8 +5362,8 @@
c3_chart_fn.focus = function (targetIds) { c3_chart_fn.focus = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds).filter($$.isTargetToShow, $$); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds)), candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))),
this.revert(); this.revert();
this.defocus(); this.defocus();
@ -5373,8 +5382,8 @@
c3_chart_fn.defocus = function (targetIds) { c3_chart_fn.defocus = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds).filter($$.isTargetToShow, $$); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds)), candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))),
this.revert(); this.revert();
candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true); candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true);
@ -5392,8 +5401,8 @@
c3_chart_fn.revert = function (targetIds) { c3_chart_fn.revert = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds).filter($$.isTargetToShow, $$); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds)); candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$)));
candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false); candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false);
if ($$.hasArcType()) { if ($$.hasArcType()) {

4
c3.min.js vendored

File diff suppressed because one or more lines are too long

11
src/legend.js

@ -199,7 +199,16 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
.style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; })
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('click', function (id) { .on('click', function (id) {
config.legend_item_onclick ? config.legend_item_onclick.call($$, id) : $$.api.toggle(id); if (config.legend_item_onclick) {
config.legend_item_onclick.call($$, id);
} else {
if ($$.d3.event.altKey) {
$$.api.hide();
$$.api.show(id);
} else {
$$.api.toggle(id);
}
}
}) })
.on('mouseover', function (id) { .on('mouseover', function (id) {
$$.d3.select(this).classed(CLASS.legendItemFocused, true); $$.d3.select(this).classed(CLASS.legendItemFocused, true);

Loading…
Cancel
Save