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

dxChart: Fix unnecessary margin if the axis has a title and labels are positioned inside the chart (T891064) #13117

Merged
merged 1 commit into from
May 20, 2020
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
6 changes: 4 additions & 2 deletions js/viz/axes/base_axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ Axis.prototype = {

_adjustLabels: function(offset) {
const that = this;
const options = that.getOptions();
const positionsAreConsistent = options.position === options.label.position;
const maxSize = that._majorTicks.reduce(function(size, tick) {
if(!tick.label) return size;
const bBox = tick.labelRotationAngle ? vizUtils.rotateBBox(tick.labelBBox, [tick.labelCoords.x, tick.labelCoords.y], -tick.labelRotationAngle) : tick.labelBBox;
Expand All @@ -606,11 +608,11 @@ Axis.prototype = {
offset: _max(size.offset || 0, tick.labelOffset || 0)
};
}, {});
const additionalOffset = that._isHorizontal ? maxSize.height : maxSize.width;
const additionalOffset = positionsAreConsistent ? (that._isHorizontal ? maxSize.height : maxSize.width) : 0;

that._adjustLabelsCoord(offset, maxSize.width);

return offset + additionalOffset + (additionalOffset && that._options.label.indentFromAxis) + maxSize.offset;
return offset + additionalOffset + (additionalOffset && that._options.label.indentFromAxis) + (positionsAreConsistent ? maxSize.offset : 0);
},

_getLabelAdjustedCoord: function(tick, offset, maxWidth) {
Expand Down
34 changes: 34 additions & 0 deletions testing/tests/DevExpress.viz.core/axisDrawing.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5304,6 +5304,40 @@ QUnit.test('Vertical right. alignment = right', function(assert) {
assert.equal(renderer.text.getCall(0).returnValue.attr.getCall(0).args[0].align, 'right');
});

QUnit.test('Axis has a title and labels are positioned inside the chart (T891064)', function(assert) {
// arrange
this.createAxis();
this.updateOptions({
isHorizontal: true,
position: 'top',
width: 2,
label: {
visible: true,
position: 'inside'
},
title: {
margin: 5,
text: 'Title text',
font: {
color: '#123456',
weight: 200,
size: 10,
family: 'Tahoma'
}
}
});

this.axis._adjustTitle = sinon.spy();

this.renderer.bBoxTemplate = { x: 1, y: 2, width: 12, height: 6 };
this.generatedTicks = [1, 2, 3];

// act
this.axis.draw(this.canvas);

assert.equal(this.axis._adjustTitle.getCall(0).args[0], 0, 'Positive sharp direction');
});

QUnit.module('XY linear axis. Draw. Date marker', environment);

QUnit.test('Full markers', function(assert) {
Expand Down