【发布时间】:2021-12-26 13:56:08
【问题描述】:
在我的 Angular 应用程序中,我已经完成了以下工作。
但是,圆圈不会在 svg 上绘制。
我做错了什么,圆圈没有显示?
svg: any;
margin = 50;
width = 350 - (this.margin * 2);
height = 300 - (this.margin * 2);
ngOnInit(): void {
this.createSvg();
this.createCircle();
}
createSvg(): void {
this.svg = d3
.select("figure#zoom-pan")
.append("svg")
.attr("width", "100%")
.attr("height", "100%")
.append("g")
.attr("transform", "translate(" + this.margin + "," + this.margin + ")");
}
createCircle(): void {
this.svg
.append("circle")
.attr("cx", document.body.clientWidth / 2)
.attr("cy", document.body.clientHeight / 2)
.attr("r", 50)
.style("fill", "#B8DEE6")
}
ngAfterViewInit() {
let svg = d3
.select("svg")
.call(d3.zoom().on("zoom", (event) => {
svg.attr("transform", event.transform);
}))
.append("g");
}
我的html 模板和css 代码非常简单:
<h3 class="center">Zoom Pan</h3>
<figure id="zoom-pan" class="center"></figure>
<ng-content></ng-content>
.center {
display: flex;
justify-content: center;
}
figure#zoom-pan {
margin: 0;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
我只得到“缩放平移”和一个空白区域......我错过了什么?
【问题讨论】:
标签: javascript angular typescript d3.js