Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add axis.x.inner #2299

Merged
merged 2 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 23 additions & 39 deletions c3.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};











var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};











var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
Expand All @@ -132,16 +112,6 @@ var inherits = function (subClass, superClass) {
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};











var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
Expand Down Expand Up @@ -481,9 +451,21 @@ c3_axis_internal_fn.generateAxis = function () {
{
// TODO: rotated tick text
tickTransform = internal.axisX;
lineUpdate.attr("x2", 0).attr("y2", -internal.innerTickSize);
textUpdate.attr("x", 0).attr("y", -internal.tickLength).style("text-anchor", "middle");
tspanUpdate.attr('x', 0).attr("dy", "0em");
lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", function (d, i) {
return -1 * internal.lineY2(d, i);
});
textUpdate.attr("x", 0).attr("y", function (d, i) {
return -1 * internal.textY(d, i) - (params.isCategory ? 2 : internal.tickLength - 2);
}).attr("transform", function (d, i) {
return internal.textTransform(d, i);
}).style("text-anchor", function (d, i) {
return internal.textTextAnchor(d, i);
});
tspanUpdate.attr('x', 0).attr("dy", function (d, i) {
return internal.tspanDy(d, i);
}).attr('dx', function (d, i) {
return internal.tspanDx(d, i);
});
pathUpdate.attr("d", "M" + internal.range[0] + "," + -internal.outerTickSize + "V0H" + internal.range[1] + "V" + -internal.outerTickSize);
break;
}
Expand All @@ -501,8 +483,8 @@ c3_axis_internal_fn.generateAxis = function () {
case "right":
{
tickTransform = internal.axisY;
lineUpdate.attr("x2", internal.innerTickSize).attr("y2", 0);
textUpdate.attr("x", internal.tickLength).attr("y", 0).style("text-anchor", "start");
lineUpdate.attr("x2", internal.innerTickSize).attr("y1", tickY).attr("y2", tickY);
textUpdate.attr("x", internal.tickLength).attr("y", internal.tickOffset).style("text-anchor", "start");
tspanUpdate.attr('x', internal.tickLength).attr("dy", function (d, i) {
return internal.tspanDy(d, i);
});
Expand Down Expand Up @@ -625,7 +607,7 @@ c3_axis_fn.init = function init() {
var $$ = this.owner,
config = $$.config,
main = $$.main;
$$.axes.x = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisX).attr("clip-path", $$.clipPathForXAxis).attr("transform", $$.getTranslate('x')).style("visibility", config.axis_x_show ? 'visible' : 'hidden');
$$.axes.x = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisX).attr("clip-path", config.axis_x_inner ? "" : $$.clipPathForXAxis).attr("transform", $$.getTranslate('x')).style("visibility", config.axis_x_show ? 'visible' : 'hidden');
$$.axes.x.append("text").attr("class", CLASS.axisXLabel).attr("transform", config.axis_rotated ? "rotate(-90)" : "").style("text-anchor", this.textAnchorForXAxisLabel.bind(this));
$$.axes.y = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisY).attr("clip-path", config.axis_y_inner ? "" : $$.clipPathForYAxis).attr("transform", $$.getTranslate('y')).style("visibility", config.axis_y_show ? 'visible' : 'hidden');
$$.axes.y.append("text").attr("class", CLASS.axisYLabel).attr("transform", config.axis_rotated ? "" : "rotate(-90)").style("text-anchor", this.textAnchorForYAxisLabel.bind(this));
Expand Down Expand Up @@ -844,7 +826,7 @@ c3_axis_fn.dyForXAxisLabel = function dyForXAxisLabel() {
config = $$.config,
position = this.getXAxisLabelPosition();
if (config.axis_rotated) {
return position.isInner ? "1.2em" : -25 - this.getMaxTickWidth('x');
return position.isInner ? "1.2em" : -25 - ($$.config.axis_x_inner ? 0 : this.getMaxTickWidth('x'));
} else {
return position.isInner ? "-0.5em" : config.axis_x_height ? config.axis_x_height - 10 : "3em";
}
Expand Down Expand Up @@ -1122,7 +1104,7 @@ c3_chart_internal_fn.initParams = function () {
$$.focusedTargetIds = [];
$$.defocusedTargetIds = [];

$$.xOrient = config.axis_rotated ? "left" : "bottom";
$$.xOrient = config.axis_rotated ? config.axis_x_inner ? "right" : "left" : config.axis_x_inner ? "top" : "bottom";
$$.yOrient = config.axis_rotated ? config.axis_y_inner ? "top" : "bottom" : config.axis_y_inner ? "right" : "left";
$$.y2Orient = config.axis_rotated ? config.axis_y2_inner ? "bottom" : "top" : config.axis_y2_inner ? "left" : "right";
$$.subXOrient = config.axis_rotated ? "left" : "bottom";
Expand Down Expand Up @@ -2162,6 +2144,7 @@ if (!Function.prototype.bind) {
// changes which were implemented in Firefox 43 and Chrome 46.

(function () {

if (!("SVGPathSeg" in window)) {
// Spec: http://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGPathSeg
window.SVGPathSeg = function (type, typeAsLetter, owningPathSegList) {
Expand Down Expand Up @@ -5202,6 +5185,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_x_height: undefined,
axis_x_extent: undefined,
axis_x_label: {},
axis_x_inner: undefined,
axis_y_show: true,
axis_y_type: undefined,
axis_y_max: undefined,
Expand Down Expand Up @@ -8498,7 +8482,7 @@ c3_chart_internal_fn.getCurrentPaddingLeft = function (withoutRecompute) {
if (isValue(config.padding_left)) {
return config.padding_left;
} else if (config.axis_rotated) {
return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
return !config.axis_x_show || config.axis_x_inner ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
} else if (!config.axis_y_show || config.axis_y_inner) {
// && !config.axis_rotated
return $$.axis.getYAxisLabelPosition().isOuter ? 30 : 1;
Expand Down
2 changes: 1 addition & 1 deletion c3.min.js

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,16 @@ c3_axis_internal_fn.generateAxis = function () {
{
// TODO: rotated tick text
tickTransform = internal.axisX;
lineUpdate.attr("x2", 0)
.attr("y2", -internal.innerTickSize);
lineUpdate.attr("x1", tickX)
.attr("x2", tickX)
.attr("y2", function (d, i) { return -1 * internal.lineY2(d, i); });
textUpdate.attr("x", 0)
.attr("y", -internal.tickLength)
.style("text-anchor", "middle");
.attr("y", function (d, i) { return -1 * internal.textY(d, i) - (params.isCategory ? 2 : (internal.tickLength - 2)); })
.attr("transform", function (d, i) { return internal.textTransform(d, i); })
.style("text-anchor", function (d, i) { return internal.textTextAnchor(d, i); });
tspanUpdate.attr('x', 0)
.attr("dy", "0em");
.attr("dy", function (d, i) { return internal.tspanDy(d, i); })
.attr('dx', function (d, i) { return internal.tspanDx(d, i); });
pathUpdate.attr("d", "M" + internal.range[0] + "," + -internal.outerTickSize + "V0H" + internal.range[1] + "V" + -internal.outerTickSize);
break;
}
Expand All @@ -283,9 +286,10 @@ c3_axis_internal_fn.generateAxis = function () {
{
tickTransform = internal.axisY;
lineUpdate.attr("x2", internal.innerTickSize)
.attr("y2", 0);
.attr("y1", tickY)
.attr("y2", tickY);
textUpdate.attr("x", internal.tickLength)
.attr("y", 0)
.attr("y", internal.tickOffset)
.style("text-anchor", "start");
tspanUpdate.attr('x', internal.tickLength)
.attr("dy", function (d, i) { return internal.tspanDy(d, i); });
Expand Down Expand Up @@ -385,7 +389,7 @@ c3_axis_fn.init = function init() {
var $$ = this.owner, config = $$.config, main = $$.main;
$$.axes.x = main.append("g")
.attr("class", CLASS.axis + ' ' + CLASS.axisX)
.attr("clip-path", $$.clipPathForXAxis)
.attr("clip-path", config.axis_x_inner ? "" : $$.clipPathForXAxis)
.attr("transform", $$.getTranslate('x'))
.style("visibility", config.axis_x_show ? 'visible' : 'hidden');
$$.axes.x.append("text")
Expand Down Expand Up @@ -606,7 +610,7 @@ c3_axis_fn.dyForXAxisLabel = function dyForXAxisLabel() {
var $$ = this.owner, config = $$.config,
position = this.getXAxisLabelPosition();
if (config.axis_rotated) {
return position.isInner ? "1.2em" : -25 - this.getMaxTickWidth('x');
return position.isInner ? "1.2em" : -25 - ($$.config.axis_x_inner ? 0 : this.getMaxTickWidth('x'));
} else {
return position.isInner ? "-0.5em" : config.axis_x_height ? config.axis_x_height - 10 : "3em";
}
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_x_height: undefined,
axis_x_extent: undefined,
axis_x_label: {},
axis_x_inner: undefined,
axis_y_show: true,
axis_y_type: undefined,
axis_y_max: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ c3_chart_internal_fn.initParams = function () {
$$.focusedTargetIds = [];
$$.defocusedTargetIds = [];

$$.xOrient = config.axis_rotated ? "left" : "bottom";
$$.xOrient = config.axis_rotated ? (config.axis_x_inner ? "right" : "left") : (config.axis_x_inner ? "top" : "bottom");
$$.yOrient = config.axis_rotated ? (config.axis_y_inner ? "top" : "bottom") : (config.axis_y_inner ? "right" : "left");
$$.y2Orient = config.axis_rotated ? (config.axis_y2_inner ? "bottom" : "top") : (config.axis_y2_inner ? "left" : "right");
$$.subXOrient = config.axis_rotated ? "left" : "bottom";
Expand Down
2 changes: 1 addition & 1 deletion src/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ c3_chart_internal_fn.getCurrentPaddingLeft = function (withoutRecompute) {
if (isValue(config.padding_left)) {
return config.padding_left;
} else if (config.axis_rotated) {
return !config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
return (!config.axis_x_show || config.axis_x_inner) ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x', withoutRecompute)), 40);
} else if (!config.axis_y_show || config.axis_y_inner) { // && !config.axis_rotated
return $$.axis.getYAxisLabelPosition().isOuter ? 30 : 1;
} else {
Expand Down