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

Added text node. #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Added text node. #37

wants to merge 2 commits into from

Conversation

asteppke
Copy link

In the first commit the flip transformation of the y-axis is exchanged by a sign change of all given y coordinates. This allows upright text.

Then we can add a basic text node relatively straightforward. Of course I am looking forward for any feedback!

@asteppke asteppke mentioned this pull request Jan 14, 2022
@@ -249,8 +249,7 @@ def render(self):
svg_header = render_tag(**attrs)+ "\n"
svg_footer = "</svg>\n"

# flip the y axis so that y grows upwards
node = Group(self.nodes) | Scale(sx=1, sy=-1)
node = Group(self.nodes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think replacing y to -y wherever it is used for avoiding this transformation is a good idea. Right now we don't maintain the exact attributes used to create a shape, but we would like to do that at some point.

I think it would better to apply scale(y=-1) to text shape to compesate for this.

>>> t = text("Hello!", center=Point(x=100, y=100), alignment_baseline="middle", text_anchor="middle")
>>> show(t)
"""
def __init__(self, content, anchor=Point(0, 0), **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is inconsitent with other shapes. We typically use x and y attributes to specify position instead of a Point.

For example: circle(x=100, y=100)

I think it would be better to use it as text("Hello", x=100, y=100)

show(t)

"""
return Text(content, anchor=Point(x=x, y=-y), **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see that you've retained the interface of using x and y here.

@@ -116,7 +116,7 @@ For example, draw 10 circles:

```
c = circle(x=-100, y=0, r=50)
shape = c | Repeat(10, Translate(x=10, y=0)
shape = c | repeat(10, translate(x=10, y=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related to adding text node. Could you please remove this change from this PR?

@anandology
Copy link
Contributor

Thanks @asteppke for the PR. I've added some comments. Please review.

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.

2 participants