Skip to content

Commit

Permalink
Axis Labels Filter - better geometry assessment (#16130)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daniele-pini authored and timroes committed May 24, 2018
1 parent e662b48 commit 294bc30
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ui/public/vislib/lib/axis/axis_labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 294bc30

Please sign in to comment.