From b4fa746599ed2c1da7c08af1aa459e822b5c1de0 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 9 May 2013 13:27:55 +0900 Subject: [PATCH] Fix focus animation --- c3.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/c3.js b/c3.js index a2bf79e..f3cf377 100644 --- a/c3.js +++ b/c3.js @@ -367,6 +367,13 @@ function maxDataCount () { return d3.max(c3.data.targets, function(t){ return t.values.length; }); } + function hasTarget (id) { + var ids = c3.data.targets.map(function(d){ return d.id; }); + for (var i = 0; i < ids.length; i++) { + if (ids[i] === id) return true; + } + return false; + } function isLineType (id) { return !(id in __data_types) || __data_types[id] === 'line'; } @@ -875,7 +882,6 @@ // rect for mouseover var w = ((width*getXDomainRatio())/(maxDataCount()-1)); - console.log(w); main.selectAll('rect.event-rect') .attr("width", w) .attr("x", function(d) { return x(d.x) - (w/2); }); @@ -1121,6 +1127,7 @@ c3.focus = function (target) { d3.selectAll(getTargetSelector(target)) + .filter(function(d){ return hasTarget(d.id); }) .classed('focused', true) .transition().duration(100) .style('opacity', 1); @@ -1128,6 +1135,7 @@ c3.defocus = function (target) { d3.selectAll(getTargetSelector(target)) + .filter(function(d){ return hasTarget(d.id); }) .classed('focused', false) .transition().duration(100) .style('opacity', 0.3) @@ -1135,6 +1143,7 @@ c3.revert = function (target) { d3.selectAll(getTargetSelector(target)) + .filter(function(d){ return hasTarget(d.id); }) .classed('focused', false) .transition().duration(100) .style('opacity', 1); @@ -1202,7 +1211,7 @@ main.select('.y.axis').transition().call(yAxis); } - update(true); + if (c3.data.targets.length > 0) update(true); }; c3.selected = function (target) {