Parts of the angular code that are specific
|SVG File|
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="950" height="450" viewBox="0 0 1280.000000 1119.000000"
preserveAspectRatio="xMidYMid meet">
<circle r="50px" cx="650" cy="968" fill="red" stroke="black" visibility="visible"/>
<rect x="650.117" y="968.413" width="1000" height="800" fill="green" visibility="visible"/>
</svg>
|HTML File|
<object #svgmyimage>
</object>
|Type Script File|
@ViewChild('svgmyimage') imageSvg?:ElementRef;
ngOnInit() {
this.reset();
this.httpClient
.get(`assets/svgimages/image1.svg`, { responseType: 'text' })
.subscribe((value: string) => {
this.svgStr = value;
// console.log(this.svgStr);
this.drawImage();
});
}
drawImage() {
if (this.imageSvg && this.svgStr) {
this.imageSvg.nativeElement.innerHTML = this.svgStr;
if(this.imageSvg.nativeElement.children[0])
{
this.imageSvg.nativeElement.children[0]setAttribute('visibility', 'visible');
this.imageSvg.nativeElement.children[1]setAttribute('fill', 'yellow');
}
}
}
It is possible to access and modify attributes in order to incorporate an Angular Material Tooltip. The tooltip property can be utilized within the HTML file itself, with the requirement that the entire SVG code is contained within the HTML rather than being referenced as an external file. Assistance is needed on how to achieve this.
As
this.imageSvg.nativeElement.children[0]setAttribute('matTooltip', 'information');
does not make sense since Tooltip is not a property of the SVG. Therefore, the query remains on how to add a tooltip specifically to the circle element in the externally linked SVG file from the Typescript file. The objective is to implement a tooltip solely for the circle in the SVG!