angular - 我可以将角度组件附加到 SVG
问题描述
我正在尝试使用 d3 和 svg 创建网络拓扑图。在封面下看起来像这样:
我想要做的是当用户点击一个节点时,我添加一个我想注入我的 Angular 组件的矩形。
const popRect = me.svg.select('.agent-popover');
popRect
.append('svg:rect')
.attr('x', d.x)
.attr('y', d.y)
.attr('width', 200)
.attr('height', 200);
popRect
.append('agent-popover');
这可能吗?要附加在开发工具 DOM 中的节目,但未显示在屏幕上。
更新:
通过使用 ViewContainerRef 并像这样设置我的组件,然后更改 foreignObject 的坐标以将其放置在需要的位置,我能够使其工作:
<svg:g [zoomableOf]="network" class="zoom-container" >
<svg:g class="links" ></svg:g>
<svg:g class="nodes"></svg:g>
<svg:g class="securities"></svg:g>
<svg:g class="agent-popover">
<svg:foreignObject x="100" y="100" height="200" width="200">
<ng-template #dynamic></ng-template>
</svg:foreignObject>
</svg:g>
</svg:g>
现在,我需要弄清楚当我关闭它时如何删除/隐藏它。
解决方案
推荐阅读
- excel - 我可以在 Excel 中没有 VBA 的情况下循环每个单元格吗?
- mysql - 无法从 SQL Server 迁移助手连接到 MySQL 服务器
- r - vcdExtra::datasets 不适用于某些包
- python - NumPy 一般布尔索引混淆
- java - 关于类中的类的 OOP 相关问题
- django-celery - 澄清需要 django celery、celery 和 djangoceleryemail 兼容版本来处理异步任务
- javascript - 如何编写一个“for 循环”,其中一个 php 值设置一个 html 元素值?
- javascript - 除非我使用 setTimeout,否则不透明度动画不起作用
- css - 我有一个 3x3 网格。如何根据使用 flexbox 的最长宽度使我的元素适合我的第一列?
- arduino - 如何通过 Arduino 将 16 位整数写入 SRAM?