Browse Source

Fix bar.zerobased and add sample

pull/340/head
Masayuki Tanaka 11 years ago
parent
commit
056c402db3
  1. 9
      c3.js
  2. 6
      c3.min.js
  3. 6
      htdocs/index.html
  4. 9
      htdocs/samples/chart_bar.html

9
c3.js

@ -1259,6 +1259,7 @@
domainLength, padding, padding_top, padding_bottom,
center = axisId === 'y2' ? __axis_y2_center : __axis_y_center,
yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative,
isZeroBased = (hasBarType(yTargets) && __bar_zerobased) || hasAreaType(yTargets),
showHorizontalDataLabel = hasDataLabel() && __axis_rotated,
showVerticalDataLabel = hasDataLabel() && !__axis_rotated;
if (yTargets.length === 0) { // use current domain if target of axisId is none
@ -1271,7 +1272,7 @@
isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
// Bar/Area chart should be 0-based if all positive|negative
if ((hasBarType(yTargets) && isBarZerobased()) || hasAreaType(yTargets)) {
if (isZeroBased) {
if (isAllPositive) { yDomainMin = 0; }
if (isAllNegative) { yDomainMax = 0; }
}
@ -1305,7 +1306,7 @@
padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength);
}
// Bar/Area chart should be 0-based if all positive|negative
if ((hasBarType(yTargets) && isBarZerobased()) || hasAreaType(yTargets)) {
if (isZeroBased) {
if (isAllPositive) { padding_bottom = yDomainMin; }
if (isAllNegative) { padding_top = -yDomainMax; }
}
@ -2237,10 +2238,6 @@
var id = (typeof d === 'string') ? d : d.id;
return __data_types[id] === 'bar';
}
function isBarZerobased()
{
return __bar_zerobased;
}
function isScatterType(d) {
var id = (typeof d === 'string') ? d : d.id;
return __data_types[id] === 'scatter';

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

6
htdocs/index.html

@ -313,6 +313,12 @@
Change radius of data point
</a>
</div>
<div class="col-md-4">
<h3>Bar</h3>
<a href="./samples/bar_zerobased.html">
Disable zero-based y domain
</a>
</div>
</div>
</div>
</div>

9
htdocs/samples/chart_bar.html

@ -11,8 +11,10 @@
var chart = c3.generate({
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 130, 100, 140, 200, 150, 50]
['data1', 1030, 1200, 1100, 1400, 1150, 1250],
['data2', 2130, 2100, 2140, 2200, 2150, 1850]
// ['data1', 30, 200, 100, 400, 150, 250],
// ['data2', 130, 100, 140, 200, 150, 50]
],
type: 'bar',
onclick: function (d, element) { console.log("onclick", d, element); },
@ -27,7 +29,8 @@
bar: {
width: {
ratio: 0.3
}
},
zerobased: false
}
});
</script>

Loading…
Cancel
Save