css - 如何为svg着色:标记线的颜色
问题描述
我有以下用于生成箭头线的 ng 模板:
<ng-template #linkTemplate let-link>
<svg:g class="edge">
<svg:marker id="arrow" viewBox="0 -5 10 10" refX="8" refY="0" markerWidth="4" markerHeight="4"
orient="auto">
<svg:path d="M0,-5L10,0L0,5" class="arrow-head" />
</svg:marker>
<svg:path class="line" [attr.stroke]="link.color" stroke-width="2" marker-end="url(#arrow)">
</svg:path>
</svg:g>
</ng-template>
如何将箭头着色为 link.color 变量中指定的颜色?
解决方案
诀窍是为箭头定义两个模板并相应地从行路径引用。
<ng-template #linkTemplate let-link>
<svg:g class="edge">
<svg:marker id="arrow" viewBox="0 -5 10 10" refX="8" refY="0" markerWidth="4" markerHeight="4" orient="auto">
<svg:path d="M0,-5L10,0L0,5" class="arrow-head" />
</svg:marker>
<svg:marker id="arrow-sel" viewBox="0 -5 10 10" refX="8" refY="0" markerWidth="4" markerHeight="4" orient="auto">
<svg:path d="M0,-5L10,0L0,5" class="arrow-head-sel" />
</svg:marker>
<svg:path class="line" [attr.stroke]="link.color" stroke-width="2" [attr.marker-end]="link.color === undefined ? 'url(#arrow)' : 'url(#arrow-sel)'">
</svg:path>
</svg:g>
</ng-template>
推荐阅读
- r - 为什么一段独立工作的代码不能在 R 中并行工作?
- c++ - C ++中for循环中的不同条件
- mysql - 如何使用节点js在mysql不同列中插入json数组对象
- flutter - 制作完整文件时如何合并颤振文件
- android - kotlin 中的 recycler 不能为空
- c# - C# 自定义异常不可调用或类型无效
- css - 将 UIFont 转换为 css 字体样式字符串
- azure - 主机路径不允许作为卷源,您需要引用“卷”部分中定义的 Azure 文件共享
- python - 下划线的使用:q.choice_set.all()
- firebase - 如何递归删除firestore中的集合?