svgling icon indicating copy to clipboard operation
svgling copied to clipboard

"box_constituent" Option

Open LLLena2021 opened this issue 1 year ago • 2 comments

I am trying to set a frame for one of the elements of my sentence tree, and I'm using the ".box_constituent()" option for that.

Here is my code: out = svgling.draw_tree(t5, font_size = 20, distance_to_daughter=2.5) out.set_leaf_style(font_size = 28, text_color = 'navy') out.set_node_style((0, 0, 0), font_size = 28, text_color = 'red') out.box_constituent((1, 3, 0)) out.set_node_style((1, 3, 0), font_size = 28, text_color = 'red') out.set_edge_style((1,4,1,1,0), svgling.core.TriangleEdge()) out.movement_arrow((0, 0, 0), (1, 3, 0), stroke_width=1.8, stroke="purple") out

I want both "he" to be red and "boxed".

Here is my outcome so far: image

One more question: Can a "strike_through" option be used for a text? In my case, grammar conventions prescribe the initial place for the first "he". In the real text, it is in the middle of a sentence. I have used the ".movement_arrow()" option to visualize the movement. And it works perfectly, as you can see. However, the ".box_constituent()" does not seem to work... Moreover, the initial "he" needs to be stricken through. Could you help, please?

LLLena2021 avatar Dec 07 '24 02:12 LLLena2021

Thanks for the questions!

For technical reasons, box_constituent needs to be called last after any style changes to nodes in the constituent, otherwise they get overwritten. It looks like this isn't documented so I'll make a note to add something to the manual about this.

For strikethrough, the current way to do that is via css text decorations, specifically adding text-decoration: line-through; to the css font style. I will mention I noticed some weirdness on how Jupyter (on firefox at least) was rendering line-through text, and it looked best when viewed as a standalone image, which is what the screenshot below is taken from. (The height of the linethrough when viewed in a Jupyter cell was weirdly low, and the thickness was wrong. I'm guessing this may be a browser bug. Also, I had to play with the thickness a bit to match the font size at all, this isn't automatic apparently, or the auto thing wasn't working right.)

Anyways, here's a modified snippet of your code with the resulting screenshot (I only reconstructed the most relevant parts of t5):

t5 = ("S", ("NP", ("PRON", "he")), ("VP", ("PP", "..."), ("PRON", "whom"), (svgling.core.subscript_node("V","AUX"), "should"), ("PRON", "he"), ("VP", "...")))
out = svgling.draw_tree(t5, font_size = 20, distance_to_daughter=2.5)
out.set_leaf_style(font_size = 28, text_color = 'navy')
strikethrough = svgling.core.SERIF + " text-decoration: line-through; text-decoration-thickness: 2px;"
out.set_node_style((0, 0, 0), font_size = 28, text_color = 'red', font_style=strikethrough)
out.set_node_style((1, 3, 0), font_size = 28, text_color = 'red')
out.box_constituent((1, 3, 0))
# out.set_edge_style((1,4,1,1,0), svgling.core.TriangleEdge())
out.movement_arrow((0, 0, 0), (1, 3, 0), stroke_width=1.8, stroke="purple")
out
Screenshot 2024-12-08 at 1 00 55 PM

rawlins avatar Dec 08 '24 18:12 rawlins

O!!! Thank you so much! Looks gorgeous! Just what the doctor ordered! Yes, it might be a good idea to document these findings. Perhaps, somebody else needs to use them, as well.

Thank you so much once again!

LLLena2021 avatar Dec 08 '24 18:12 LLLena2021