Skip to content

Conversation

@eaton-lab
Copy link
Contributor

I was having problems with text being cut-off on the right side because the Marker extents layout.right attribute did not appear to take into account the -toyplot-anchor-shift value. This was a problem for Toytree because I would routinely plot text with style {'text-anchor': 'start', '-toyplot-anchor-shift': '20px'}.

This problem is also apparent in the example for -toyplot-anchor-shift from the Toyplot documentation:

canvas = toyplot.Canvas(width=500, height=300)
axes = canvas.cartesian(show=False, ymin=-2.5, ymax=1.5)
axes.vlines(0, color="lightgray")
axes.text(0, 1, "Shifted +0px", style={"-toyplot-anchor-shift":"0", "text-anchor":"start", "font-size":"24px"})
axes.scatterplot(0, 1, color="black", size=3)
m0 = axes.text(0, 0, "Shifted +20px", style={"-toyplot-anchor-shift":"20px", "text-anchor":"start", "font-size":"24px"})
axes.scatterplot(0, 0, color="black", size=3)
m1 = axes.text(0, -1, "Shifted +40px", style={"-toyplot-anchor-shift":"40px", "text-anchor":"start", "font-size":"24px"})
axes.scatterplot(0, -1, color="black", size=3);
axes.text(0, -2, "Shifted -20px", style={"-toyplot-anchor-shift":"-20px", "text-anchor":"start", "font-size":"24px"})
axes.scatterplot(0, -2, color="black", size=3);

The marker extents do not take into account the anchor shift. You can see the right value is unchanged for m0 and m1:

>>> m0.extents('x')[1], m1.extents('x')[1]
((array([ 0.]), array([ 147.432]), array([-14.4]), array([ 14.4])),
 (array([ 0.]), array([ 147.432]), array([-14.4]), array([ 14.4])))

After making the edit that is in the pull request the extents seem to appropriately valued:

>>> m0.extents('x')[1], m1.extents('x')[1]
((array([ 0.]), array([ 167.432]), array([-14.4]), array([ 14.4])),
 (array([ 0.]), array([ 187.432]), array([-14.4]), array([ 14.4])))

@coveralls
Copy link

coveralls commented Sep 7, 2017

Coverage Status

Coverage remained the same at 93.787% when pulling 2a40499 on eaton-lab:local into e6fe2a7 on sandialabs:master.

@tshead2
Copy link
Member

tshead2 commented Sep 8, 2017

Boy do I hate text layout at this point. I'll merge this as soon as I have a chance to think through any other ramifications.

Cheers,
Tim

@tshead2 tshead2 closed this in 5f0271f Sep 8, 2017
@tshead2
Copy link
Member

tshead2 commented Sep 8, 2017

OK, I made a slightly different change, so that line.left and line.right are both set properly. Let me know if it solves the underlying problems in Toytree.

Cheers,
Tim

@tshead2
Copy link
Member

tshead2 commented Sep 8, 2017

You may also be interested in https://github.com/sandialabs/toyplot/blob/master/sandbox/text-layout-shift.ipynb for some examples of troubleshooting tools for text layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants