Browse Source

Fix x padding - #457

pull/590/head
Masayuki Tanaka 10 years ago
parent
commit
979c61cbae
  1. 8
      c3.js
  2. 2
      c3.min.js
  3. 8
      src/domain.js

8
c3.js

@ -1315,13 +1315,13 @@
($$.isTimeSeries() ? this.parseDate(config.axis_x_max) : config.axis_x_max) : ($$.isTimeSeries() ? this.parseDate(config.axis_x_max) : config.axis_x_max) :
$$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); });
}; };
c3_chart_internal_fn.getXDomainPadding = function (targets) { c3_chart_internal_fn.getXDomainPadding = function (domain) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], diff = domain[1] - domain[0],
maxDataCount, padding, paddingLeft, paddingRight; maxDataCount, padding, paddingLeft, paddingRight;
if ($$.isCategorized()) { if ($$.isCategorized()) {
padding = 0; padding = 0;
} else if ($$.hasType('bar', targets)) { } else if ($$.hasType('bar')) {
maxDataCount = $$.getMaxDataCount(); maxDataCount = $$.getMaxDataCount();
padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5;
} else { } else {
@ -1341,7 +1341,7 @@
var $$ = this, var $$ = this,
xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)],
firstX = xDomain[0], lastX = xDomain[1], firstX = xDomain[0], lastX = xDomain[1],
padding = $$.getXDomainPadding(targets), padding = $$.getXDomainPadding(xDomain),
min = 0, max = 0; min = 0, max = 0;
// show center of x domain if min and max are the same // show center of x domain if min and max are the same
if ((firstX - lastX) === 0 && !$$.isCategorized()) { if ((firstX - lastX) === 0 && !$$.isCategorized()) {

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

8
src/domain.js

@ -146,13 +146,13 @@ c3_chart_internal_fn.getXDomainMax = function (targets) {
($$.isTimeSeries() ? this.parseDate(config.axis_x_max) : config.axis_x_max) : ($$.isTimeSeries() ? this.parseDate(config.axis_x_max) : config.axis_x_max) :
$$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); });
}; };
c3_chart_internal_fn.getXDomainPadding = function (targets) { c3_chart_internal_fn.getXDomainPadding = function (domain) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], diff = domain[1] - domain[0],
maxDataCount, padding, paddingLeft, paddingRight; maxDataCount, padding, paddingLeft, paddingRight;
if ($$.isCategorized()) { if ($$.isCategorized()) {
padding = 0; padding = 0;
} else if ($$.hasType('bar', targets)) { } else if ($$.hasType('bar')) {
maxDataCount = $$.getMaxDataCount(); maxDataCount = $$.getMaxDataCount();
padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5;
} else { } else {
@ -172,7 +172,7 @@ c3_chart_internal_fn.getXDomain = function (targets) {
var $$ = this, var $$ = this,
xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)],
firstX = xDomain[0], lastX = xDomain[1], firstX = xDomain[0], lastX = xDomain[1],
padding = $$.getXDomainPadding(targets), padding = $$.getXDomainPadding(xDomain),
min = 0, max = 0; min = 0, max = 0;
// show center of x domain if min and max are the same // show center of x domain if min and max are the same
if ((firstX - lastX) === 0 && !$$.isCategorized()) { if ((firstX - lastX) === 0 && !$$.isCategorized()) {

Loading…
Cancel
Save