Browse Source

Fix padding for y/y2 axis label

pull/763/merge
Masayuki Tanaka 10 years ago
parent
commit
d826f88dc5
  1. 24
      c3.js
  2. 10
      c3.min.js
  3. 6
      src/axis.js
  4. 4
      src/clip.js
  5. 8
      src/size.js

24
c3.js

@ -113,8 +113,8 @@
$$.defocusedTargetIds = []; $$.defocusedTargetIds = [];
$$.xOrient = config.axis_rotated ? "left" : "bottom"; $$.xOrient = config.axis_rotated ? "left" : "bottom";
$$.yOrient = config.axis_rotated ? "bottom" : "left"; $$.yOrient = config.axis_rotated ? (config.axis_y_inner ? "top" : "bottom") : (config.axis_y_inner ? "right" : "left");
$$.y2Orient = config.axis_rotated ? "top" : "right"; $$.y2Orient = config.axis_rotated ? (config.axis_y_inner ? "bottom" : "top") : (config.axis_y_inner ? "left" : "right");
$$.subXOrient = config.axis_rotated ? "left" : "bottom"; $$.subXOrient = config.axis_rotated ? "left" : "bottom";
$$.isLegendRight = config.legend_position === 'right'; $$.isLegendRight = config.legend_position === 'right';
@ -1029,6 +1029,7 @@
axis_y_max: undefined, axis_y_max: undefined,
axis_y_min: undefined, axis_y_min: undefined,
axis_y_center: undefined, axis_y_center: undefined,
axis_y_inner: undefined,
axis_y_label: {}, axis_y_label: {},
axis_y_tick_format: undefined, axis_y_tick_format: undefined,
axis_y_tick_outer: true, axis_y_tick_outer: true,
@ -1042,6 +1043,7 @@
axis_y2_max: undefined, axis_y2_max: undefined,
axis_y2_min: undefined, axis_y2_min: undefined,
axis_y2_center: undefined, axis_y2_center: undefined,
axis_y2_inner: undefined,
axis_y2_label: {}, axis_y2_label: {},
axis_y2_tick_format: undefined, axis_y2_tick_format: undefined,
axis_y2_tick_outer: true, axis_y2_tick_outer: true,
@ -2501,8 +2503,10 @@
return config.padding_left; return config.padding_left;
} else if (config.axis_rotated) { } else if (config.axis_rotated) {
return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40); return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
} else if (!config.axis_y_show || config.axis_y_inner) { // && !config.axis_rotated
return $$.getYAxisLabelPosition().isOuter ? 30 : 1;
} else { } else {
return !config.axis_y_show ? 1 : ceil10($$.getAxisWidthByAxisId('y', withoutRecompute)); return ceil10($$.getAxisWidthByAxisId('y', withoutRecompute));
} }
}; };
c3_chart_internal_fn.getCurrentPaddingRight = function () { c3_chart_internal_fn.getCurrentPaddingRight = function () {
@ -2512,8 +2516,10 @@
return config.padding_right + 1; // 1 is needed not to hide tick line return config.padding_right + 1; // 1 is needed not to hide tick line
} else if (config.axis_rotated) { } else if (config.axis_rotated) {
return defaultPadding + legendWidthOnRight; return defaultPadding + legendWidthOnRight;
} else if (!config.axis_y2_show || config.axis_y2_inner) { // && !config.axis_rotated
return defaultPadding + legendWidthOnRight + ($$.getY2AxisLabelPosition().isOuter ? 20 : 0);
} else { } else {
return (!config.axis_y2_show ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; return ceil10($$.getAxisWidthByAxisId('y2')) + legendWidthOnRight;
} }
}; };
@ -3983,7 +3989,7 @@
$$.axes.y = main.append("g") $$.axes.y = main.append("g")
.attr("class", CLASS.axis + ' ' + CLASS.axisY) .attr("class", CLASS.axis + ' ' + CLASS.axisY)
.attr("clip-path", $$.clipPathForYAxis) .attr("clip-path", config.axis_y_inner ? "" : $$.clipPathForYAxis)
.attr("transform", $$.getTranslate('y')) .attr("transform", $$.getTranslate('y'))
.style("visibility", config.axis_y_show ? 'visible' : 'hidden'); .style("visibility", config.axis_y_show ? 'visible' : 'hidden');
$$.axes.y.append("text") $$.axes.y.append("text")
@ -4194,7 +4200,7 @@
if ($$.config.axis_rotated) { if ($$.config.axis_rotated) {
return position.isInner ? "-0.5em" : "3em"; return position.isInner ? "-0.5em" : "3em";
} else { } else {
return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); return position.isInner ? "1.2em" : -10 - ($$.config.axis_y_inner ? 0 : ($$.getMaxTickWidth('y') + 10));
} }
}; };
c3_chart_internal_fn.dyForY2AxisLabel = function () { c3_chart_internal_fn.dyForY2AxisLabel = function () {
@ -4203,7 +4209,7 @@
if ($$.config.axis_rotated) { if ($$.config.axis_rotated) {
return position.isInner ? "1.2em" : "-2.2em"; return position.isInner ? "1.2em" : "-2.2em";
} else { } else {
return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); return position.isInner ? "-0.5em" : 15 + ($$.config.axis_y2_inner ? 0 : (this.getMaxTickWidth('y2') + 15));
} }
}; };
c3_chart_internal_fn.textAnchorForXAxisLabel = function () { c3_chart_internal_fn.textAnchorForXAxisLabel = function () {
@ -4367,7 +4373,7 @@
}; };
c3_chart_internal_fn.getYAxisClipX = function () { c3_chart_internal_fn.getYAxisClipX = function () {
var $$ = this; var $$ = this;
return $$.getAxisClipX($$.config.axis_rotated); return $$.config.axis_y_inner ? -1 : $$.getAxisClipX($$.config.axis_rotated);
}; };
c3_chart_internal_fn.getYAxisClipY = function () { c3_chart_internal_fn.getYAxisClipY = function () {
var $$ = this; var $$ = this;
@ -4393,7 +4399,7 @@
}; };
c3_chart_internal_fn.getYAxisClipWidth = function () { c3_chart_internal_fn.getYAxisClipWidth = function () {
var $$ = this; var $$ = this;
return $$.getAxisClipWidth($$.config.axis_rotated); return $$.getAxisClipWidth($$.config.axis_rotated) + ($$.config.axis_y_inner ? 20 : 0);
}; };
c3_chart_internal_fn.getYAxisClipHeight = function () { c3_chart_internal_fn.getYAxisClipHeight = function () {
var $$ = this; var $$ = this;

10
c3.min.js vendored

File diff suppressed because one or more lines are too long

6
src/axis.js

@ -12,7 +12,7 @@ c3_chart_internal_fn.initAxis = function () {
$$.axes.y = main.append("g") $$.axes.y = main.append("g")
.attr("class", CLASS.axis + ' ' + CLASS.axisY) .attr("class", CLASS.axis + ' ' + CLASS.axisY)
.attr("clip-path", $$.clipPathForYAxis) .attr("clip-path", config.axis_y_inner ? "" : $$.clipPathForYAxis)
.attr("transform", $$.getTranslate('y')) .attr("transform", $$.getTranslate('y'))
.style("visibility", config.axis_y_show ? 'visible' : 'hidden'); .style("visibility", config.axis_y_show ? 'visible' : 'hidden');
$$.axes.y.append("text") $$.axes.y.append("text")
@ -223,7 +223,7 @@ c3_chart_internal_fn.dyForYAxisLabel = function () {
if ($$.config.axis_rotated) { if ($$.config.axis_rotated) {
return position.isInner ? "-0.5em" : "3em"; return position.isInner ? "-0.5em" : "3em";
} else { } else {
return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); return position.isInner ? "1.2em" : -10 - ($$.config.axis_y_inner ? 0 : ($$.getMaxTickWidth('y') + 10));
} }
}; };
c3_chart_internal_fn.dyForY2AxisLabel = function () { c3_chart_internal_fn.dyForY2AxisLabel = function () {
@ -232,7 +232,7 @@ c3_chart_internal_fn.dyForY2AxisLabel = function () {
if ($$.config.axis_rotated) { if ($$.config.axis_rotated) {
return position.isInner ? "1.2em" : "-2.2em"; return position.isInner ? "1.2em" : "-2.2em";
} else { } else {
return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); return position.isInner ? "-0.5em" : 15 + ($$.config.axis_y2_inner ? 0 : (this.getMaxTickWidth('y2') + 15));
} }
}; };
c3_chart_internal_fn.textAnchorForXAxisLabel = function () { c3_chart_internal_fn.textAnchorForXAxisLabel = function () {

4
src/clip.js

@ -23,7 +23,7 @@ c3_chart_internal_fn.getXAxisClipY = function () {
}; };
c3_chart_internal_fn.getYAxisClipX = function () { c3_chart_internal_fn.getYAxisClipX = function () {
var $$ = this; var $$ = this;
return $$.getAxisClipX($$.config.axis_rotated); return $$.config.axis_y_inner ? -1 : $$.getAxisClipX($$.config.axis_rotated);
}; };
c3_chart_internal_fn.getYAxisClipY = function () { c3_chart_internal_fn.getYAxisClipY = function () {
var $$ = this; var $$ = this;
@ -49,7 +49,7 @@ c3_chart_internal_fn.getXAxisClipHeight = function () {
}; };
c3_chart_internal_fn.getYAxisClipWidth = function () { c3_chart_internal_fn.getYAxisClipWidth = function () {
var $$ = this; var $$ = this;
return $$.getAxisClipWidth($$.config.axis_rotated); return $$.getAxisClipWidth($$.config.axis_rotated) + ($$.config.axis_y_inner ? 20 : 0);
}; };
c3_chart_internal_fn.getYAxisClipHeight = function () { c3_chart_internal_fn.getYAxisClipHeight = function () {
var $$ = this; var $$ = this;

8
src/size.js

@ -21,8 +21,10 @@ c3_chart_internal_fn.getCurrentPaddingLeft = function (withoutRecompute) {
return config.padding_left; return config.padding_left;
} else if (config.axis_rotated) { } else if (config.axis_rotated) {
return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40); return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
} else if (!config.axis_y_show || config.axis_y_inner) { // && !config.axis_rotated
return $$.getYAxisLabelPosition().isOuter ? 30 : 1;
} else { } else {
return !config.axis_y_show || config.axis_y_inner ? 1 : ceil10($$.getAxisWidthByAxisId('y', withoutRecompute)); return ceil10($$.getAxisWidthByAxisId('y', withoutRecompute));
} }
}; };
c3_chart_internal_fn.getCurrentPaddingRight = function () { c3_chart_internal_fn.getCurrentPaddingRight = function () {
@ -32,8 +34,10 @@ c3_chart_internal_fn.getCurrentPaddingRight = function () {
return config.padding_right + 1; // 1 is needed not to hide tick line return config.padding_right + 1; // 1 is needed not to hide tick line
} else if (config.axis_rotated) { } else if (config.axis_rotated) {
return defaultPadding + legendWidthOnRight; return defaultPadding + legendWidthOnRight;
} else if (!config.axis_y2_show || config.axis_y2_inner) { // && !config.axis_rotated
return defaultPadding + legendWidthOnRight + ($$.getY2AxisLabelPosition().isOuter ? 20 : 0);
} else { } else {
return (!config.axis_y2_show || config.axis_y2_inner ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; return ceil10($$.getAxisWidthByAxisId('y2')) + legendWidthOnRight;
} }
}; };

Loading…
Cancel
Save