Allow custom colors on arcs

This commit is contained in:
ines 2018-03-09 13:37:05 +01:00
parent 8e822b50fc
commit 4387ce1e20
2 changed files with 6 additions and 5 deletions

View File

@ -67,7 +67,8 @@ class DependencyRenderer(object):
words = [self.render_word(w['text'], w['tag'], i)
for i, w in enumerate(words)]
arcs = [self.render_arrow(a['label'], a['start'],
a['end'], a['dir'], i)
a['end'], a['dir'], i,
a.get('color', 'currentColor'))
for i, a in enumerate(arcs)]
content = ''.join(words) + ''.join(arcs)
return TPL_DEP_SVG.format(id=self.id, width=self.width,
@ -86,7 +87,7 @@ class DependencyRenderer(object):
x = self.offset_x+i*self.distance
return TPL_DEP_WORDS.format(text=text, tag=tag, x=x, y=y)
def render_arrow(self, label, start, end, direction, i):
def render_arrow(self, label, start, end, direction, i, color='currentColor'):
"""Render indivicual arrow.
label (unicode): Dependency label.

View File

@ -20,11 +20,11 @@ TPL_DEP_WORDS = """
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-arc" id="arrow-{id}-{i}" stroke-width="{stroke}px" d="{arc}" fill="none" stroke="{color}"/>
<text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">
<textPath xlink:href="#arrow-{id}-{i}" class="displacy-label" startOffset="50%" fill="currentColor" text-anchor="middle">{label}</textPath>
<textPath xlink:href="#arrow-{id}-{i}" class="displacy-label" startOffset="50%" fill="{color}" text-anchor="middle">{label}</textPath>
</text>
<path class="displacy-arrowhead" d="{head}" fill="currentColor"/>
<path class="displacy-arrowhead" d="{head}" fill="{color}"/>
</g>
"""