Commit 979c61cb authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix x padding - #457

parent 932b7fba
...@@ -1315,13 +1315,13 @@ ...@@ -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 @@ ...@@ -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()) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -146,13 +146,13 @@ c3_chart_internal_fn.getXDomainMax = function (targets) { ...@@ -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) { ...@@ -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()) {
......
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