Commit ee9abc92 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix min/max for Gauge chart - #536

parent 9ee5464e
...@@ -4174,7 +4174,8 @@ ...@@ -4174,7 +4174,8 @@
c3_chart_internal_fn.updateAngle = function (d) { c3_chart_internal_fn.updateAngle = function (d) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
found = false, index = 0; found = false, index = 0,
gMin = config.gauge_min, gMax = config.gauge_max, gTic, gValue;
$$.pie($$.filterTargetsToShow($$.data.targets)).forEach(function (t) { $$.pie($$.filterTargetsToShow($$.data.targets)).forEach(function (t) {
if (! found && t.data.id === d.data.id) { if (! found && t.data.id === d.data.id) {
found = true; found = true;
...@@ -4187,11 +4188,10 @@ ...@@ -4187,11 +4188,10 @@
d.endAngle = d.startAngle; d.endAngle = d.startAngle;
} }
if ($$.isGaugeType(d.data)) { if ($$.isGaugeType(d.data)) {
var gMin = config.gauge_min, gMax = config.gauge_max, gTic = (Math.PI) / (gMax - gMin);
gF = Math.abs(gMin) + gMax, gValue = d.value < gMin ? 0 : d.value < gMax ? d.value - gMin : (gMax - gMin);
aTic = (Math.PI) / gF; d.startAngle = -1 * (Math.PI / 2);
d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); d.endAngle = d.startAngle + gTic * gValue;
d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value));
} }
return found ? d : null; return found ? d : null;
}; };
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
</head> </head>
<body> <body>
<div id="chart"></div> <div id="chart"></div>
<div id="chart1"></div>
<div id="chart2"></div>
<div id="chart3"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
...@@ -40,6 +43,48 @@ ...@@ -40,6 +43,48 @@
} }
}); });
var chart1 = c3.generate({
bindto: '#chart1',
data: {
columns: [
['data', 75.0]
],
type: 'gauge',
},
gauge: {
min: 50,
max: 100
}
});
var chart2 = c3.generate({
bindto: '#chart2',
data: {
columns: [
['data', 0.0]
],
type: 'gauge',
},
gauge: {
min: -100,
max: 100
}
});
var chart3 = c3.generate({
bindto: '#chart3',
data: {
columns: [
['data', -75.0]
],
type: 'gauge',
},
gauge: {
min: -100,
max: -50
}
});
var cycleDemo = function () { var cycleDemo = function () {
setTimeout(function () { setTimeout(function () {
......
...@@ -26,7 +26,8 @@ c3_chart_internal_fn.updateArc = function () { ...@@ -26,7 +26,8 @@ c3_chart_internal_fn.updateArc = function () {
c3_chart_internal_fn.updateAngle = function (d) { c3_chart_internal_fn.updateAngle = function (d) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
found = false, index = 0; found = false, index = 0,
gMin = config.gauge_min, gMax = config.gauge_max, gTic, gValue;
$$.pie($$.filterTargetsToShow($$.data.targets)).forEach(function (t) { $$.pie($$.filterTargetsToShow($$.data.targets)).forEach(function (t) {
if (! found && t.data.id === d.data.id) { if (! found && t.data.id === d.data.id) {
found = true; found = true;
...@@ -39,11 +40,10 @@ c3_chart_internal_fn.updateAngle = function (d) { ...@@ -39,11 +40,10 @@ c3_chart_internal_fn.updateAngle = function (d) {
d.endAngle = d.startAngle; d.endAngle = d.startAngle;
} }
if ($$.isGaugeType(d.data)) { if ($$.isGaugeType(d.data)) {
var gMin = config.gauge_min, gMax = config.gauge_max, gTic = (Math.PI) / (gMax - gMin);
gF = Math.abs(gMin) + gMax, gValue = d.value < gMin ? 0 : d.value < gMax ? d.value - gMin : (gMax - gMin);
aTic = (Math.PI) / gF; d.startAngle = -1 * (Math.PI / 2);
d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); d.endAngle = d.startAngle + gTic * gValue;
d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value));
} }
return found ? d : null; return found ? d : null;
}; };
......
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