Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions spacy/displacy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,17 @@ def render_arrow(
y_curve = -self.distance
arrowhead = self.get_arrowhead(direction, x_start, y, x_end)
arc = self.get_arc(x_start, y, y_curve, x_end)
label_side = "right" if self.direction == "rtl" else "left"
label_arc = arc
if self.direction == "rtl":
label_arc = self.get_arc(x_end, y, y_curve, x_start)
return TPL_DEP_ARCS.format(
id=self.id,
i=i,
stroke=self.arrow_stroke,
head=arrowhead,
label=label,
label_side=label_side,
arc=arc,
label_arc=label_arc,
)

def get_arc(self, x_start: int, y: int, y_curve: int, x_end: int) -> str:
Expand Down
3 changes: 2 additions & 1 deletion spacy/displacy/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
TPL_DEP_ARCS = """
<g class="displacy-arrow">
<path class="displacy-arc" id="arrow-{id}-{i}" stroke-width="{stroke}px" d="{arc}" fill="none" stroke="currentColor"/>
<path class="displacy-label-arc" id="label-{id}-{i}" d="{label_arc}" fill="none" stroke="none"/>
<text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">
<textPath xlink:href="#arrow-{id}-{i}" class="displacy-label" startOffset="50%" side="{label_side}" fill="currentColor" text-anchor="middle">{label}</textPath>
<textPath xlink:href="#label-{id}-{i}" class="displacy-label" startOffset="50%" fill="currentColor" text-anchor="middle">{label}</textPath>
</text>
<path class="displacy-arrowhead" d="{head}" fill="currentColor"/>
</g>
Expand Down
3 changes: 3 additions & 0 deletions spacy/tests/test_displacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ def test_displacy_rtl():
assert "direction: rtl" in html
assert 'direction="rtl"' in html
assert f'lang="{nlp.lang}"' in html
assert 'class="displacy-label-arc"' in html
assert 'xlink:href="#label-' in html
assert " side=" not in html
html = displacy.render(doc, page=True, style="ent")
assert "direction: rtl" in html
assert f'lang="{nlp.lang}"' in html
Expand Down