Commit dd83fa72 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Add dount chart - #10

parent 95b9b7c4
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
/*-- Set Chart Params --*/ /*-- Set Chart Params --*/
var margin, margin2, margin3, width, width2, height, height2, height3, currentWidth, currentHeight; var margin, margin2, margin3, width, width2, height, height2, height3, currentWidth, currentHeight;
var radius, radiusExpanded, svgArc, svgArcExpanded, svgArcExpandedSub, pie; var radius, radiusExpanded, innerRadius, svgArc, svgArcExpanded, svgArcExpandedSub, pie;
var xMin, xMax, yMin, yMax, subXMin, subXMax, subYMin, subYMax; var xMin, xMax, yMin, yMax, subXMin, subXMax, subYMin, subYMax;
var x, y, y2, subX, subY, subY2, xAxis, yAxis, yAxis2, subXAxis; var x, y, y2, subX, subY, subY2, xAxis, yAxis, yAxis2, subXAxis;
...@@ -238,6 +238,7 @@ ...@@ -238,6 +238,7 @@
radiusExpanded = height / 2; radiusExpanded = height / 2;
radius = radiusExpanded * 0.95; radius = radiusExpanded * 0.95;
innerRadius = hasDountType(c3.data.targets) ? radius * 0.6 : 0;
} }
function getCurrentWidth() { function getCurrentWidth() {
return __size_width === null ? getParentWidth() : __size_width; return __size_width === null ? getParentWidth() : __size_width;
...@@ -408,7 +409,7 @@ ...@@ -408,7 +409,7 @@
} }
function getSvgArc() { function getSvgArc() {
var arc = d3.svg.arc().outerRadius(radius).innerRadius(0), var arc = d3.svg.arc().outerRadius(radius).innerRadius(innerRadius),
newArc = function (d, withoutUpdate) { newArc = function (d, withoutUpdate) {
var updated; var updated;
if (withoutUpdate) { return arc(d); } // for interpolate if (withoutUpdate) { return arc(d); } // for interpolate
...@@ -420,7 +421,7 @@ ...@@ -420,7 +421,7 @@
return newArc; return newArc;
} }
function getSvgArcExpanded(rate) { function getSvgArcExpanded(rate) {
var arc = d3.svg.arc().outerRadius(radiusExpanded * (rate ? rate : 1)).innerRadius(0); var arc = d3.svg.arc().outerRadius(radiusExpanded * (rate ? rate : 1)).innerRadius(innerRadius);
return function (d) { return function (d) {
var updated = updateAngle(d); var updated = updateAngle(d);
return updated ? arc(updated) : "M 0 0"; return updated ? arc(updated) : "M 0 0";
...@@ -709,6 +710,11 @@ ...@@ -709,6 +710,11 @@
}); });
}); });
// set target types
if (__data_type) {
setTargetType(getTargetIds(targets).filter(function (id) { return ! (id in __data_types); }), __data_type);
}
// cache as original id keyed // cache as original id keyed
targets.forEach(function (d) { targets.forEach(function (d) {
addCache(d.id_org, d); addCache(d.id_org, d);
...@@ -1035,9 +1041,15 @@ ...@@ -1035,9 +1041,15 @@
function hasScatterType(targets) { function hasScatterType(targets) {
return hasType(targets, 'scatter'); return hasType(targets, 'scatter');
} }
function hasArcType(targets) { function hasPieType(targets) {
return hasType(targets, 'pie'); return hasType(targets, 'pie');
} }
function hasDountType(targets) {
return hasType(targets, 'dount');
}
function hasArcType(targets) {
return hasPieType(targets) || hasDountType(targets);
}
function isLineType(d) { function isLineType(d) {
var id = (typeof d === 'string') ? d : d.id; var id = (typeof d === 'string') ? d : d.id;
return !(id in __data_types) || __data_types[id] === 'line' || __data_types[id] === 'spline' || __data_types[id] === 'area' || __data_types[id] === 'area-spline'; return !(id in __data_types) || __data_types[id] === 'line' || __data_types[id] === 'spline' || __data_types[id] === 'area' || __data_types[id] === 'area-spline';
...@@ -1056,7 +1068,7 @@ ...@@ -1056,7 +1068,7 @@
} }
function isArcType(d) { function isArcType(d) {
var id = (typeof d === 'string') ? d : d.id; var id = (typeof d === 'string') ? d : d.id;
return __data_types[id] === 'pie'; return __data_types[id] === 'pie' || __data_types[id] === 'dount';
} }
/* not used /* not used
function lineData(d) { function lineData(d) {
...@@ -1920,7 +1932,7 @@ ...@@ -1920,7 +1932,7 @@
var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1, maxDataCountTarget; var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1, maxDataCountTarget;
var rectX, rectW; var rectX, rectW;
var withY, withSubchart, withTransition, withUpdateXDomain, withUpdateOrgXDomain; var withY, withSubchart, withTransition, withUpdateXDomain, withUpdateOrgXDomain;
var isPieChart; var hideAxis = hasArcType(c3.data.targets);
var duration; var duration;
options = isDefined(options) ? options : {}; options = isDefined(options) ? options : {};
...@@ -1929,7 +1941,6 @@ ...@@ -1929,7 +1941,6 @@
withTransition = isDefined(options.withTransition) ? options.withTransition : true; withTransition = isDefined(options.withTransition) ? options.withTransition : true;
withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : false; withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : false;
withUpdateOrgXDomain = isDefined(options.withUpdateOrgXDomain) ? options.withUpdateOrgXDomain : false; withUpdateOrgXDomain = isDefined(options.withUpdateOrgXDomain) ? options.withUpdateOrgXDomain : false;
isPieChart = hasArcType(c3.data.targets);
duration = withTransition ? 250 : 0; duration = withTransition ? 250 : 0;
...@@ -1950,9 +1961,9 @@ ...@@ -1950,9 +1961,9 @@
y2.domain(getYDomain('y2')); y2.domain(getYDomain('y2'));
// axis // axis
main.select(".x.axis").transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : xAxis).style("opacity", isPieChart ? 0 : 1); main.select(".x.axis").transition().duration(__axis_rotated ? duration : 0).call(__axis_rotated ? yAxis : xAxis).style("opacity", hideAxis ? 0 : 1);
main.select(".y.axis").transition().duration(__axis_rotated ? 0 : duration).call(__axis_rotated ? xAxis : yAxis).style("opacity", isPieChart ? 0 : 1); main.select(".y.axis").transition().duration(__axis_rotated ? 0 : duration).call(__axis_rotated ? xAxis : yAxis).style("opacity", hideAxis ? 0 : 1);
main.select(".y2.axis").transition().call(yAxis2).style("opacity", isPieChart ? 0 : 1); main.select(".y2.axis").transition().call(yAxis2).style("opacity", hideAxis ? 0 : 1);
// Update label position // Update label position
main.select(".x.axis .-axis-x-label").attr("x", width); main.select(".x.axis .-axis-x-label").attr("x", width);
...@@ -2314,11 +2325,6 @@ ...@@ -2314,11 +2325,6 @@
/*-- Main --*/ /*-- Main --*/
// Set data type if data.type is specified
if (__data_type) {
setTargetType(getTargetIds(targets).filter(function (id) { return ! (id in __data_types); }), __data_type);
}
//-- Bar --// //-- Bar --//
mainBarUpdate = main.select('.chart-bars') mainBarUpdate = main.select('.chart-bars')
.selectAll('.chart-bar') .selectAll('.chart-bar')
......
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