Browse Source

Add config for non zerobased bar charts

pull/333/head
Melzar 11 years ago
parent
commit
5290f1f235
  1. 11
      c3.js

11
c3.js

@ -248,7 +248,8 @@
// bar // bar
var __bar_width = getConfig(['bar', 'width']), var __bar_width = getConfig(['bar', 'width']),
__bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6); __bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6),
__bar_zerobased = getConfig(['bar', 'zerobased'], true);
// pie // pie
var __pie_label_show = getConfig(['pie', 'label', 'show'], true), var __pie_label_show = getConfig(['pie', 'label', 'show'], true),
@ -1235,7 +1236,7 @@
isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
// Bar/Area chart should be 0-based if all positive|negative // Bar/Area chart should be 0-based if all positive|negative
if (hasBarType(yTargets) || hasAreaType(yTargets)) { if ((hasBarType(yTargets) && isBarZerobased()) || hasAreaType(yTargets)) {
if (isAllPositive) { yDomainMin = 0; } if (isAllPositive) { yDomainMin = 0; }
if (isAllNegative) { yDomainMax = 0; } if (isAllNegative) { yDomainMax = 0; }
} }
@ -1269,7 +1270,7 @@
padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength); padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength);
} }
// Bar/Area chart should be 0-based if all positive|negative // Bar/Area chart should be 0-based if all positive|negative
if (hasBarType(yTargets) || hasAreaType(yTargets)) { if ((hasBarType(yTargets) && isBarZerobased()) || hasAreaType(yTargets)) {
if (isAllPositive) { padding_bottom = yDomainMin; } if (isAllPositive) { padding_bottom = yDomainMin; }
if (isAllNegative) { padding_top = -yDomainMax; } if (isAllNegative) { padding_top = -yDomainMax; }
} }
@ -2201,6 +2202,10 @@
var id = (typeof d === 'string') ? d : d.id; var id = (typeof d === 'string') ? d : d.id;
return __data_types[id] === 'bar'; return __data_types[id] === 'bar';
} }
function isBarZerobased()
{
return __bar_zerobased;
}
function isScatterType(d) { function isScatterType(d) {
var id = (typeof d === 'string') ? d : d.id; var id = (typeof d === 'string') ? d : d.id;
return __data_types[id] === 'scatter'; return __data_types[id] === 'scatter';

Loading…
Cancel
Save