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

Fix label and bar point overlapping on the edge of pane (T856746) #11955

Merged
merged 1 commit into from
Feb 11, 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
77 changes: 31 additions & 46 deletions js/viz/series/points/bar_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ const LEFT = 'left';
const TOP = 'top';
const BOTTOM = 'bottom';

function getLabelOrientation(point) {
const initialValue = point.initialValue;
const invert = point._getValTranslator().getBusinessRange().invert;
const isDiscreteValue = point.series.valueAxisType === 'discrete';
const isFullStacked = point.series.isFullStackedSeries();
const notAxisInverted = (!isDiscreteValue && ((initialValue >= 0 && !invert) ||
(initialValue < 0 && invert))) ||
(isDiscreteValue && !invert) ||
(isFullStacked);
return notAxisInverted ? TOP : BOTTOM;
}
module.exports = _extend({}, symbolPoint, {

correctCoordinates(correctOptions) {
Expand All @@ -33,37 +44,36 @@ module.exports = _extend({}, symbolPoint, {
}
},

_getGraphicBBox: function() {
return {
_getGraphicBBox: function(location) {
const bBox = {
x: this.x,
y: this.y,
width: this.width,
height: this.height
};
if(location) {
const isTop = location === 'top';
if(!this._options.rotated) {
bBox.y = isTop ? bBox.y : bBox.y + bBox.height;
bBox.height = 0;
} else {
bBox.x = isTop ? bBox.x + bBox.width : bBox.x;
bBox.width = 0;
}
}

return bBox;
},

_getLabelConnector: function(location) {
return this._getGraphicBBox(location);
},

_getLabelPosition: function() {
const that = this;
let position;
const initialValue = that.initialValue;
const invert = that._getValTranslator().getBusinessRange().invert;
const isDiscreteValue = that.series.valueAxisType === 'discrete';
const isFullStacked = that.series.isFullStackedSeries();
const notAxisInverted = (!isDiscreteValue && ((initialValue >= 0 && !invert) ||
(initialValue < 0 && invert))) ||
(isDiscreteValue && !invert) ||
(isFullStacked);

if(!that._options.rotated) {
position = notAxisInverted ? TOP : BOTTOM;
} else {
position = notAxisInverted ? RIGHT : LEFT;
let position = getLabelOrientation(this);
if(this._options.rotated) {
position = position === TOP ? RIGHT : LEFT;
}

return position;
},

Expand All @@ -85,15 +95,9 @@ module.exports = _extend({}, symbolPoint, {
return coords;
},

_checkLabelPosition: function(label, coord) {
const that = this;
const visibleArea = that._getVisibleArea();

if(that._isPointInVisibleArea(visibleArea, that._getGraphicBBox())) {
return that._moveLabelOnCanvas(coord, visibleArea, label.getBoundingRect());
}

return coord;
_drawLabel: function() {
this._label.pointPosition = this._label.getLayoutOptions().position !== 'inside' && getLabelOrientation(this);
symbolPoint._drawLabel.call(this);
},

hideInsideLabel: function(label, coord) {
Expand All @@ -113,25 +117,6 @@ module.exports = _extend({}, symbolPoint, {
return false;
},

_moveLabelOnCanvas: function(coord, visibleArea, labelBBox) {
let x = coord.x;
let y = coord.y;
if(visibleArea.minX > x) {
x = visibleArea.minX;
}
if(visibleArea.maxX < (x + labelBBox.width)) {
x = visibleArea.maxX - labelBBox.width;
}
if(visibleArea.minY > y) {
y = visibleArea.minY;
}
if(visibleArea.maxY < (y + labelBBox.height)) {
y = visibleArea.maxY - labelBBox.height;
}

return { x: x, y: y };
},

_showForZeroValues: function() {
return this._options.label.showForZeroValues || this.initialValue;
},
Expand Down
17 changes: 15 additions & 2 deletions js/viz/series/points/candlestick_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,33 @@ module.exports = _extend({}, barPoint, {
};
},

_getGraphicBBox: function() {
_getGraphicBBox: function(location) {
const that = this;
const rotated = that._options.rotated;
const x = that.x;
const width = that.width;
const lowY = that.lowY;
const highY = that.highY;

return {
const bBox = {
x: !rotated ? x - _round(width / 2) : lowY,
y: !rotated ? highY : x - _round(width / 2),
width: !rotated ? width : highY - lowY,
height: !rotated ? lowY - highY : width
};

if(location) {
const isTop = location === 'top';
if(!this._options.rotated) {
bBox.y = isTop ? bBox.y : bBox.y + bBox.height;
bBox.height = 0;
} else {
bBox.x = isTop ? bBox.x + bBox.width : bBox.x;
bBox.width = 0;
}
}

return bBox;
},

getTooltipParams: function(location) {
Expand Down
21 changes: 19 additions & 2 deletions js/viz/series/points/polar_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ exports.polarSymbolPoint = _extend({}, symbolPoint, {

_getLabelCoords: piePoint._getLabelCoords,

_moveLabelOnCanvas: barPoint._moveLabelOnCanvas,
_moveLabelOnCanvas: function(coord, visibleArea, labelBBox) {
let x = coord.x;
let y = coord.y;
if(visibleArea.minX > x) {
x = visibleArea.minX;
}
if(visibleArea.maxX < (x + labelBBox.width)) {
x = visibleArea.maxX - labelBBox.width;
}
if(visibleArea.minY > y) {
y = visibleArea.minY;
}
if(visibleArea.maxY < (y + labelBBox.height)) {
y = visibleArea.maxY - labelBBox.height;
}

return { x: x, y: y };
},

_getLabelPosition: function() {
return 'outside';
Expand Down Expand Up @@ -135,7 +152,7 @@ exports.polarBarPoint = _extend({}, barPoint, {

_getErrorBarSettings: exports.polarSymbolPoint._getErrorBarSettings,

_moveLabelOnCanvas: barPoint._moveLabelOnCanvas,
_moveLabelOnCanvas: exports.polarSymbolPoint._moveLabelOnCanvas,

_getLabelCoords: piePoint._getLabelCoords,

Expand Down
15 changes: 0 additions & 15 deletions js/viz/series/points/range_bar_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ module.exports = _extend({}, barPoint, {

_getLabelCoords: rangeSymbolPointMethods._getLabelCoords,

_getGraphicBBox: function(location) {
const isTop = location === 'top';
const bBox = barPoint._getGraphicBBox.call(this);

if(!this._options.rotated) {
bBox.y = isTop ? bBox.y : bBox.y + bBox.height;
bBox.height = 0;
} else {
bBox.x = isTop ? bBox.x + bBox.width : bBox.x;
bBox.width = 0;
}

return bBox;
},

getLabel: rangeSymbolPointMethods.getLabel,

getLabels: rangeSymbolPointMethods.getLabels,
Expand Down
3 changes: 2 additions & 1 deletion js/viz/series/points/symbol_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ module.exports = {
const visibleArea = that._getVisibleArea();
const labelBBox = label.getBoundingRect();
const graphicBBox = that._getGraphicBBox(label.pointPosition);
const fullGraphicBBox = that._getGraphicBBox();
const offset = LABEL_OFFSET;

if(that._isPointInVisibleArea(visibleArea, graphicBBox)) {
if(that._isPointInVisibleArea(visibleArea, fullGraphicBBox)) {
if(!that._options.rotated) {
if(visibleArea.minX > coord.x) {
coord.x = visibleArea.minX;
Expand Down
Loading