Skip to content

Commit

Permalink
fix(axis): Fix axis.x.height=0 to be applied
Browse files Browse the repository at this point in the history
Fix conditional to check given value is numeric

Fix #3424
  • Loading branch information
netil committed Sep 15, 2023
1 parent 20fc229 commit 0c562c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/ChartInternal/internals/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export default {
x.domain(domain || sortValue($$.getXDomain(targets), !config.axis_x_inverted));
org.xDomain = x.domain();

zoomEnabled && $$.zoom.updateScaleExtent();
// zoomEnabled && $$.zoom.updateScaleExtent();

subX.domain(x.domain());
$$.brush?.scale(subX);
Expand All @@ -333,6 +333,10 @@ export default {
org.xDomain : getBrushSelection($$).map(subX.invert);

x.domain(domainValue);
// zoomEnabled && $$.zoom.updateScaleExtent();
}

if (withUpdateOrgXDomain || withUpdateXDomain) {
zoomEnabled && $$.zoom.updateScaleExtent();
}

Expand Down
3 changes: 2 additions & 1 deletion src/ChartInternal/internals/size.axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
*/
import {isNumber} from "../../module/util";
import type {AxisType} from "../../../types/types";

export default {
Expand Down Expand Up @@ -52,7 +53,7 @@ export default {
return 8;
}

if (id === "x" && config.axis_x_height) {
if (id === "x" && isNumber(config.axis_x_height)) {
return config.axis_x_height;
}

Expand Down
35 changes: 31 additions & 4 deletions test/internals/axis-x-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("X AXIS", function() {
});
});

describe("", () => {
describe("x Axis dimension", () => {
before(() => {
args = {
data: {
Expand All @@ -243,9 +243,9 @@ describe("X AXIS", function() {
x: {
type: "category",
tick: {
rotate: 75,
multiline: false,
tooltip: true
rotate: 75,
multiline: false,
tooltip: true
},
height: 130
}
Expand All @@ -260,6 +260,33 @@ describe("X AXIS", function() {
expect(axisRect.height).to.be.below(+clipRect.attr("height"));
expect(+clipRect.attr("y") > -50).to.be.be.ok;
});

it("set options", () => {
args = {
data: {
columns: [
["pv", 90, 100, 140]
],
type: "bar"
},
legend: {
show: false
},
axis: {
x: {
height: 0
}
}
};
});

it("x axis height option should be applied", () => {
const {$: {main}, internal: {state}} = chart;

expect(
main.select(`.${$AXIS.axisX}`).node().getBoundingClientRect().y
).to.be.above(state.height);
});
});
});
});

0 comments on commit 0c562c3

Please sign in to comment.