Skip to content

Commit

Permalink
fix(Axis): Fix tick text position
Browse files Browse the repository at this point in the history
It was caused by getting tick's position earlier than it was set

Fix #672
Close #678
  • Loading branch information
netil committed Nov 29, 2018
1 parent 94d592f commit 0ca6b18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 13 additions & 2 deletions spec/internals/axis-spec.js
Expand Up @@ -536,11 +536,22 @@ describe("AXIS", function() {
const ticks = chart.internal.main.select(`.${CLASS.axisX}`).selectAll("g.tick");

ticks.each(function(d, i) {
const tspans = d3.select(this).selectAll("tspan");
const texts = d3.select(this).selectAll("text");
const tspans = texts.selectAll("tspan");

const expectedX = "-9";
const expectedDy = "3";
const expectedY = "36";

texts.each(function() {
const text = d3.select(this);

expect(text.attr("x")).to.be.equal(expectedX);
expect(text.attr("y")).to.be.equal(expectedY);
});

if (i > 0) { // i === 0 should be checked in next test
const expectedDy = "3";

expect(tspans.size()).to.be.equal(1);

tspans.each(function() {
Expand Down
10 changes: 5 additions & 5 deletions src/axis/AxisRenderer.js
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017 NAVER Corp.
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
* @ignore
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ export default class AxisRenderer {
tickEnter.select("line").attr(`${axisPx}2`, innerTickSize * sign);
tickEnter.select("text").attr(`${axisPx}`, tickLength * sign);

ctx.tickLineTextUpdate(lineUpdate, textUpdate, scale1);
ctx.setTickLineTextPosition(lineUpdate, textUpdate, scale1);

// Append <title> for tooltip display
params.tickTitle && textUpdate.append && textUpdate.append("title")
Expand Down Expand Up @@ -249,16 +249,16 @@ export default class AxisRenderer {
}

/**
* Update tick's line & text
* Set tick's line & text position
* @param lineUpdate
* @param textUpdate
* @param scale
* @private
*/
tickLineTextUpdate(lineUpdate, textUpdate, scale) {
setTickLineTextPosition(lineUpdate, textUpdate, scale) {
const tickPos = this.getTickXY(scale);
const {innerTickSize, orient, tickLength, tickOffset} = this.config;
const rotate = this.params.tickTextRotate;
const tickPos = this.getTickXY(scale);

const textAnchorForText = r => (!r ? "middle" : (r > 0 ? "start" : "end"));
const textTransform = r => (r ? `rotate(${r})` : null);
Expand Down
5 changes: 5 additions & 0 deletions src/axis/AxisRendererHelper.js
@@ -1,3 +1,8 @@
/**
* Copyright (c) 2017 ~ present NAVER Corp.
* billboard.js project is licensed under the MIT license
* @ignore
*/
import {scaleLinear as d3ScaleLinear} from "d3-scale";
import {isDefined, isNumber, isString} from "../internals/util";

Expand Down

0 comments on commit 0ca6b18

Please sign in to comment.