diff --git a/src/ChartInternal/Axis/Axis.ts b/src/ChartInternal/Axis/Axis.ts index 061d30e0a..1936b85c6 100644 --- a/src/ChartInternal/Axis/Axis.ts +++ b/src/ChartInternal/Axis/Axis.ts @@ -735,10 +735,11 @@ class Axis { * @returns {object} Padding object values with 'left' & 'right' key * @private */ - getXAxisPadding(tickCount) { + getXAxisPadding(tickCount: number): {left: number, right: number} { const $$ = this.owner; - let {left = 0, right = 0} = $$.config.axis_x_padding; - let padding = {left, right}; + const padding = $$.config.axis_x_padding; + let {left = 0, right = 0} = isNumber(padding) ? + {left: padding, right: padding} : padding; if ($$.axis.isTimeSeries()) { const firstX = +$$.getXDomainMin($$.data.targets); @@ -752,11 +753,9 @@ class Axis { left = left / range / relativeTickWidth; right = right / range / relativeTickWidth; } - - padding = {left, right}; } - return padding; + return {left, right}; } updateLabels(withTransition) { diff --git a/test/internals/axis-spec.ts b/test/internals/axis-spec.ts index e071999c0..854259cec 100644 --- a/test/internals/axis-spec.ts +++ b/test/internals/axis-spec.ts @@ -2509,6 +2509,59 @@ describe("AXIS", function() { util.generate(option); }); + + it("set options", () => { + args = { + data: { + x: "x", + columns: [ + ["x", 1, 2, 3, 4, 5], + ["data1", 30, 200, 100, 400, 150], + ], + type: "line" + }, + axis: { + x: { + type: "category", + tick: { + rotate: 5 + }, + padding: 10 + } + } + } + }); + + it("check if axis.x.padding correctly set when is given as number value.", () => { + const {state} = chart.internal; + const padding = args.axis.x.padding; + + expect(state.axis.x.padding).to.be.deep.equal({left: padding, right: padding}); + }); + + it("set options axis.x.padding={left: 5}", () => { + args.axis.x.padding = {left: 5}; + }); + + it("check if axis.x.padding correctly set when is given as 'left' key only.", () => { + const {state} = chart.internal; + const padding = args.axis.x.padding; + + padding.right = 0; + + expect(state.axis.x.padding).to.be.deep.equal(padding); + }); + + it("set options axis.x.padding={left: 15, right: 5}", () => { + args.axis.x.padding = {left: 15, right: 5}; + }); + + it("check if axis.x.padding correctly set when is given as object type.", () => { + const {state} = chart.internal; + const padding = args.axis.x.padding; + + expect(state.axis.x.padding).to.be.deep.equal(padding); + }); }); describe("axis min/max", () => {