From 5689dee384e02faf35f5de085a404d0970fdb9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20=C3=96zen?= Date: Thu, 27 Aug 2015 10:24:18 +0200 Subject: [PATCH] visibleTargetCount for cleaner arc calculation --- src/arc.js | 7 +++---- src/core.js | 1 + src/data.js | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/arc.js b/src/arc.js index 16ca75d..7fe5390 100644 --- a/src/arc.js +++ b/src/arc.js @@ -10,9 +10,8 @@ c3_chart_internal_fn.initPie = function () { c3_chart_internal_fn.updateRadius = function () { var $$ = this, config = $$.config, - visibleTargetCount = $$.data.targets.length - $$.hiddenTargetIds.length, w = config.gauge_width || config.donut_width, - gaugeArcWidth = visibleTargetCount * 5; // 5 = minimal arc width of one arc in multi arc gauge; TODO in config + gaugeArcWidth = $$.visibleTargetCount * 5; // 5 = minimal arc width of one arc in multi arc gauge; TODO in config $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2 * ($$.hasType('gauge') ? 0.85 : 1); $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; @@ -56,7 +55,7 @@ c3_chart_internal_fn.updateAngle = function (d) { c3_chart_internal_fn.getSvgArc = function () { var $$ = this, hasGaugeType = $$.hasType('gauge'), - singleArcWidth = $$.gaugeArcWidth / ($$.data.targets.length - $$.hiddenTargetIds.length), // TODO auslagern + singleArcWidth = $$.gaugeArcWidth / $$.visibleTargetCount, arc = $$.d3.svg.arc().outerRadius(function(d) { return hasGaugeType ? $$.radius - singleArcWidth * d.index : $$.radius; }).innerRadius(function(d) { @@ -76,7 +75,7 @@ c3_chart_internal_fn.getSvgArc = function () { c3_chart_internal_fn.getSvgArcExpanded = function (rate) { rate = rate || 1; var $$ = this, hasGaugeType = $$.hasType('gauge'), - singleArcWidth = $$.gaugeArcWidth / ($$.data.targets.length - $$.hiddenTargetIds.length), // TODO auslagern + singleArcWidth = $$.gaugeArcWidth / $$.visibleTargetCount, expandWidth = Math.min($$.radiusExpanded * rate - $$.radius, singleArcWidth * 0.8 - (1 - rate) * 100), arc = $$.d3.svg.arc().outerRadius(function(d){ return hasGaugeType ? $$.radius - singleArcWidth * d.index + expandWidth : $$.radiusExpanded * rate; diff --git a/src/core.js b/src/core.js index 3da0bda..1a362cc 100644 --- a/src/core.js +++ b/src/core.js @@ -135,6 +135,7 @@ c3_chart_internal_fn.initParams = function () { ["%Y/%-m/%-d", function () { return true; }] ]); + $$.visibleTargetCount = config.data_hide === true ? 0 : (config.data_columns ? (config.data_columns.length - (config.data_hide ? config.data_hide.length : 0)) : 0); $$.hiddenTargetIds = []; $$.hiddenLegendIds = []; $$.focusedTargetIds = []; diff --git a/src/data.js b/src/data.js index 531ab69..02e2586 100644 --- a/src/data.js +++ b/src/data.js @@ -176,9 +176,11 @@ c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { }; c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); + this.visibleTargetCount -= targetIds.length; }; c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + this.visibleTargetCount += targetIds.length; }; c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds);