Axis Labels Filter - better geometry assessment (#16130)

Fixes #13590

Scales in line/area/bar charts are often of type 'rangeBands', that
applies padding on the sides and leaves space for the bands.

During axis label filtering, this padding was not taken in
consideration.
This commit is contained in:
daniele-pini 2018-05-24 13:00:54 +02:00 committed by Tim Roes
parent e662b48d4a
commit 294bc30a43

View file

@ -77,12 +77,17 @@ export function VislibAxisLabelsProvider() {
return function (selection) {
if (!config.get('labels.filter')) return;
const el = $(config.get('rootEl')).find(config.get('elSelector'));
const maxSize = config.isHorizontal() ? el.width() : el.height();
const scaleRange = self.axisScale.scale.range();
const scaleWidth = scaleRange[scaleRange.length - 1] - scaleRange[0];
const scaleStartPad = .5 * (maxSize - scaleWidth);
selection.selectAll('.tick text')
.text(function (d) {
const par = d3.select(this.parentNode).node();
const el = $(config.get('rootEl')).find(config.get('elSelector'));
const maxSize = config.isHorizontal() ? el.width() : el.height();
const myPos = config.isHorizontal() ? self.axisScale.scale(d) : maxSize - self.axisScale.scale(d);
const myPos = scaleStartPad + (config.isHorizontal() ? self.axisScale.scale(d) : maxSize - self.axisScale.scale(d));
const mySize = (config.isHorizontal() ? par.getBBox().width : par.getBBox().height) * padding;
const halfSize = mySize / 2;