Commit bc815a87 authored by Evgeny's avatar Evgeny

Move exploded pie implementation

parent 328f718a
...@@ -11,8 +11,10 @@ c3_chart_internal_fn.initPie = function () { ...@@ -11,8 +11,10 @@ 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,
w = config.gauge_width || config.donut_width; w = config.gauge_width || config.donut_width;
$$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2;
$$.radius = $$.radiusExpanded * 0.95; $$.radius = $$.radiusExpanded * 0.95;
$$.radius -= config.explodeRadius;
$$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6;
$$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0; $$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0;
}; };
...@@ -260,47 +262,8 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf ...@@ -260,47 +262,8 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
this._current = d; this._current = d;
}); });
mainArc mainArc
.attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) .attr("transform", withTransform ? "scale(0)" : $$.wrapExplode())
.style("opacity", function (d) { return d === this._current ? 0 : 1; }) .style("opacity", function (d) { return d === this._current ? 0 : 1; })
.on('mouseover', config.interaction_enabled ? function (d) {
var updated, arcData;
if ($$.transiting) { // skip while transiting
return;
}
updated = $$.updateAngle(d);
arcData = $$.convertToArcData(updated);
// transitions
$$.expandArc(updated.data.id);
$$.api.focus(updated.data.id);
$$.toggleFocusLegend(updated.data.id, true);
$$.config.data_onmouseover(arcData, this);
} : null)
.on('mousemove', config.interaction_enabled ? function (d) {
var updated = $$.updateAngle(d),
arcData = $$.convertToArcData(updated),
selectedData = [arcData];
$$.showTooltip(selectedData, this);
} : null)
.on('mouseout', config.interaction_enabled ? function (d) {
var updated, arcData;
if ($$.transiting) { // skip while transiting
return;
}
updated = $$.updateAngle(d);
arcData = $$.convertToArcData(updated);
// transitions
$$.unexpandArc(updated.data.id);
$$.api.revert();
$$.revertLegend();
$$.hideTooltip();
$$.config.data_onmouseout(arcData, this);
} : null)
.on('click', config.interaction_enabled ? function (d, i) {
var updated = $$.updateAngle(d),
arcData = $$.convertToArcData(updated);
if ($$.toggleShape) { $$.toggleShape(this, arcData, i); }
$$.config.data_onclick.call($$.api, arcData, this);
} : null)
.each(function () { $$.transiting = true; }) .each(function () { $$.transiting = true; })
.transition().duration(duration) .transition().duration(duration)
.attrTween("d", function (d) { .attrTween("d", function (d) {
...@@ -308,12 +271,6 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf ...@@ -308,12 +271,6 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
if (! updated) { if (! updated) {
return function () { return "M 0 0"; }; return function () { return "M 0 0"; };
} }
// if (this._current === d) {
// this._current = {
// startAngle: Math.PI*2,
// endAngle: Math.PI*2,
// };
// }
if (isNaN(this._current.endAngle)) { if (isNaN(this._current.endAngle)) {
this._current.endAngle = this._current.startAngle; this._current.endAngle = this._current.startAngle;
} }
...@@ -325,7 +282,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf ...@@ -325,7 +282,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
return $$.getArc(interpolated, true); return $$.getArc(interpolated, true);
}; };
}) })
.attr("transform", withTransform ? "scale(1)" : "") .attr("transform", withTransform ? "scale(1)" : $$.wrapExplode())
.style("fill", function (d) { .style("fill", function (d) {
return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id);
}) // Where gauge reading color would receive customization. }) // Where gauge reading color would receive customization.
...@@ -347,29 +304,63 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf ...@@ -347,29 +304,63 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
main.select('.' + CLASS.chartArcsTitle) main.select('.' + CLASS.chartArcsTitle)
.style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0); .style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0);
if ($$.hasType('gauge')) { if($$.config.hasSubs || $$.config.isSub){
$$.arcs.select('.' + CLASS.chartArcsBackground) $$.buffer.onlastfinish("draw-lines", function(){
.attr("d", function () { $$.ed3Internal.redrawLinesOnBoth();
var d = { $$.ed3Internal.redrawLinesOnBoth();
data: [{value: config.gauge_max}], });
startAngle: -1 * (Math.PI / 2),
endAngle: Math.PI / 2
};
return $$.getArc(d, true, true);
});
$$.arcs.select('.' + CLASS.chartArcsGaugeUnit)
.attr("dy", ".75em")
.text(config.gauge_label_show ? config.gauge_units : '');
$$.arcs.select('.' + CLASS.chartArcsGaugeMin)
.attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px")
.attr("dy", "1.2em")
.text(config.gauge_label_show ? config.gauge_min : '');
$$.arcs.select('.' + CLASS.chartArcsGaugeMax)
.attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px")
.attr("dy", "1.2em")
.text(config.gauge_label_show ? config.gauge_max : '');
} }
}; };
c3_chart_internal_fn.getAngle = function(d){
var $$ = this;
$$.config.newd = d;
};
c3_chart_internal_fn.wrapExplode = function(){
var $$ = this;
explode.offset = $$.config.explodeRadius;
explode.updateAngle = $$.updateAngle.bind($$);
explode.turn = $$.api.turn.bind($$.api);
explode.config = $$.config;
explode.getAngle = $$.getAngle.bind($$);
return explode;
};
function explode(d, index) {
d = explode.updateAngle(d);
if(isNull(d)){
return "";
}
var offset = explode.offset;
var angle = (d.startAngle + d.endAngle) / 2;
var xOff = Math.sin(angle) * offset;
var yOff = -Math.cos(angle) * offset;
if(index === 0 && explode.config.hasSubs){
if(!explode.config.turned){
explode.getAngle(d);
var turnAngle = ((d.startAngle - d.endAngle) / 2 % (2 * Math.PI)) + toRadians(90);
explode.turn({
radians: turnAngle
});
explode.config.turned = true;
}
}
if(!offset){
return "translate(0, 0)";
}
return 'translate(' + xOff + ',' + yOff +')';
}
c3_chart_internal_fn.initGauge = function () { c3_chart_internal_fn.initGauge = function () {
var arcs = this.arcs; var arcs = this.arcs;
if (this.hasType('gauge')) { if (this.hasType('gauge')) {
......
...@@ -162,6 +162,7 @@ c3_chart_internal_fn.getDefaultConfig = function () { ...@@ -162,6 +162,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
pie_label_format: undefined, pie_label_format: undefined,
pie_label_threshold: 0.05, pie_label_threshold: 0.05,
pie_expand: true, pie_expand: true,
explodeRadius: 0,
// gauge // gauge
gauge_label_show: true, gauge_label_show: true,
gauge_label_format: undefined, gauge_label_format: undefined,
......
...@@ -10,6 +10,9 @@ var isValue = c3_chart_internal_fn.isValue = function (v) { ...@@ -10,6 +10,9 @@ var isValue = c3_chart_internal_fn.isValue = function (v) {
isUndefined = c3_chart_internal_fn.isUndefined = function (v) { isUndefined = c3_chart_internal_fn.isUndefined = function (v) {
return typeof v === 'undefined'; return typeof v === 'undefined';
}, },
isNull = c3_chart_internal_fn.isNull = function(v){
return v === null;
},
isDefined = c3_chart_internal_fn.isDefined = function (v) { isDefined = c3_chart_internal_fn.isDefined = function (v) {
return typeof v !== 'undefined'; return typeof v !== 'undefined';
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment