From be3086e31dd624b3374acc578fa104113421c1d2 Mon Sep 17 00:00:00 2001 From: Germain Bergeron Date: Thu, 15 Oct 2015 09:41:41 -0400 Subject: [PATCH] Created updateCulling function in Axis Fixes #1430 --- src/axis.js | 20 ++++++++++++++++++++ src/core.js | 20 ++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/axis.js b/src/axis.js index ee83bb3..d78f0df 100644 --- a/src/axis.js +++ b/src/axis.js @@ -320,6 +320,26 @@ Axis.prototype.updateLabels = function updateLabels(withTransition) { .attr("dy", this.dyForY2AxisLabel.bind(this)) .text(this.textForY2AxisLabel.bind(this)); }; +Axis.prototype.updateCulling = function updateCulling(tickValues) { + var $$ = this.owner, config = $$.config; + if (config.axis_x_tick_culling && tickValues) { + var intervalForCulling, i; + for (i = 1; i < tickValues.length; i++) { + if (tickValues.length / i < config.axis_x_tick_culling_max) { + intervalForCulling = i; + break; + } + } + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { + var index = tickValues.indexOf(e); + if (index >= 0) { + d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); + } + }); + } else { + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); + } +}; Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) { var p = typeof padding === 'number' ? padding : padding[key]; if (!isValue(p)) { diff --git a/src/core.js b/src/core.js index 60ee0c5..c628f47 100644 --- a/src/core.js +++ b/src/core.js @@ -466,7 +466,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis; var waitForDraw, flow; - var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling, xDomainForZoom; + var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, xDomainForZoom; var xv = $$.xv.bind($$), cx, cy; options = options || {}; @@ -534,24 +534,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { // Update axis label $$.axis.updateLabels(withTransition); - // show/hide if manual culling needed if ((withUpdateXDomain || withUpdateXAxis) && targetsToShow.length) { - if (config.axis_x_tick_culling && tickValues) { - for (i = 1; i < tickValues.length; i++) { - if (tickValues.length / i < config.axis_x_tick_culling_max) { - intervalForCulling = i; - break; - } - } - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { - var index = tickValues.indexOf(e); - if (index >= 0) { - d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); - } - }); - } else { - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); - } + $$.axis.updateCulling(tickValues); } // setup drawer - MEMO: these must be called after axis updated