Browse Source

visibleTargetCount for cleaner arc calculation

pull/1355/head
Gökhan Özen 9 years ago
parent
commit
5689dee384
  1. 7
      src/arc.js
  2. 1
      src/core.js
  3. 2
      src/data.js

7
src/arc.js

@ -10,9 +10,8 @@ c3_chart_internal_fn.initPie = function () {
c3_chart_internal_fn.updateRadius = function () { c3_chart_internal_fn.updateRadius = function () {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
visibleTargetCount = $$.data.targets.length - $$.hiddenTargetIds.length,
w = config.gauge_width || config.donut_width, 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); $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2 * ($$.hasType('gauge') ? 0.85 : 1);
$$.radius = $$.radiusExpanded * 0.95; $$.radius = $$.radiusExpanded * 0.95;
$$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6;
@ -56,7 +55,7 @@ c3_chart_internal_fn.updateAngle = function (d) {
c3_chart_internal_fn.getSvgArc = function () { c3_chart_internal_fn.getSvgArc = function () {
var $$ = this, hasGaugeType = $$.hasType('gauge'), var $$ = this, hasGaugeType = $$.hasType('gauge'),
singleArcWidth = $$.gaugeArcWidth / ($$.data.targets.length - $$.hiddenTargetIds.length), // TODO auslagern singleArcWidth = $$.gaugeArcWidth / $$.visibleTargetCount,
arc = $$.d3.svg.arc().outerRadius(function(d) { arc = $$.d3.svg.arc().outerRadius(function(d) {
return hasGaugeType ? $$.radius - singleArcWidth * d.index : $$.radius; return hasGaugeType ? $$.radius - singleArcWidth * d.index : $$.radius;
}).innerRadius(function(d) { }).innerRadius(function(d) {
@ -76,7 +75,7 @@ c3_chart_internal_fn.getSvgArc = function () {
c3_chart_internal_fn.getSvgArcExpanded = function (rate) { c3_chart_internal_fn.getSvgArcExpanded = function (rate) {
rate = rate || 1; rate = rate || 1;
var $$ = this, hasGaugeType = $$.hasType('gauge'), 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), expandWidth = Math.min($$.radiusExpanded * rate - $$.radius, singleArcWidth * 0.8 - (1 - rate) * 100),
arc = $$.d3.svg.arc().outerRadius(function(d){ arc = $$.d3.svg.arc().outerRadius(function(d){
return hasGaugeType ? $$.radius - singleArcWidth * d.index + expandWidth : $$.radiusExpanded * rate; return hasGaugeType ? $$.radius - singleArcWidth * d.index + expandWidth : $$.radiusExpanded * rate;

1
src/core.js

@ -135,6 +135,7 @@ c3_chart_internal_fn.initParams = function () {
["%Y/%-m/%-d", function () { return true; }] ["%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 = []; $$.hiddenTargetIds = [];
$$.hiddenLegendIds = []; $$.hiddenLegendIds = [];
$$.focusedTargetIds = []; $$.focusedTargetIds = [];

2
src/data.js

@ -176,9 +176,11 @@ c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) {
}; };
c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) {
this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds);
this.visibleTargetCount -= targetIds.length;
}; };
c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) {
this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; });
this.visibleTargetCount += targetIds.length;
}; };
c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) {
this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds);

Loading…
Cancel
Save