diff --git a/c3.js b/c3.js index f5c2943..4bcc679 100644 --- a/c3.js +++ b/c3.js @@ -17,6 +17,9 @@ chartArc: 'c3-chart-arc', chartArcs: 'c3-chart-arcs', chartArcsTitle: 'c3-chart-arcs-title', + gaugeArc: 'c3-gauge-arc', + gaugeArcs: 'c3-gauge-arcs', + gaugeArcsTitle: 'c3-gauge-arcs-title', selectedCircle: 'c3-selected-circle', selectedCircles: 'c3-selected-circles', eventRect: 'c3-event-rect', @@ -227,6 +230,14 @@ __pie_onmouseover = getConfig(['pie', 'onmouseover'], function () {}), __pie_onmouseout = getConfig(['pie', 'onmouseout'], function () {}); + // gauge + var __gauge_label_show = getConfig(['gauge', 'label', 'show'], true), + __gauge_label_format = getConfig(['gauge', 'label', 'format']), + __gauge_onclick = getConfig(['gauge', 'onclick'], function () {}), + __gauge_onmouseover = getConfig(['gauge', 'onmouseover'], function () {}), + __gauge_onmouseout = getConfig(['gauge', 'onmouseout'], function () {}), + __gauge_style = getConfig(['gauge', 'style']); + // donut var __donut_label_show = getConfig(['donut', 'label', 'show'], true), __donut_label_format = getConfig(['donut', 'label', 'format']), @@ -415,7 +426,7 @@ function updateRadius() { radiusExpanded = height / 2; radius = radiusExpanded * 0.95; - innerRadius = hasDonutType(c3.data.targets) ? radius * 0.6 : 0; + innerRadius = hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? radius * 0.6 : 0; } function getSvgLeft() { var leftAxisClass = __axis_rotated ? CLASS.axisX : CLASS.axisY, @@ -983,6 +994,11 @@ return; } }); + if (isNaN(d.endAngle)) d.endAngle = d.startAngle; + if (__gauge_style === 'arc') { + d.startAngle = (-1*(Math.PI/2))+d.startAngle; + d.endAngle = d.endAngle/4; + } console.log(d); return found ? d : null; } @@ -1972,11 +1988,14 @@ function hasPieType(targets) { return hasType(targets, 'pie'); } + function hasGaugeType(targets) { + return hasType(targets, 'gauge'); + } function hasDonutType(targets) { return hasType(targets, 'donut'); } function hasArcType(targets) { - return hasPieType(targets) || hasDonutType(targets); + return hasPieType(targets) || hasDonutType(targets) || hasGaugeType(targets); } function isLineType(d) { var id = (typeof d === 'string') ? d : d.id; @@ -2006,12 +2025,16 @@ var id = (typeof d === 'string') ? d : d.id; return __data_types[id] === 'pie'; } + function isGaugeType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'gauge'; + } function isDonutType(d) { var id = (typeof d === 'string') ? d : d.id; return __data_types[id] === 'donut'; } function isArcType(d) { - return isPieType(d) || isDonutType(d); + return isPieType(d) || isDonutType(d) || isGaugeType(d); } /* not used function lineData(d) { @@ -3414,7 +3437,7 @@ .text(textForArcLabel) .style("opacity", function (d) { return isTargetToShow(d.data.id) && isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS.chartArcsTitle) - .style("opacity", hasDonutType(c3.data.targets) ? 1 : 0); + .style("opacity", hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? 1 : 0); // subchart if (__subchart_show) {