762
Views
2
Comments
[SVG JS] Adding text inside polygon
Question
svg-js
Mobile icon
Forge asset by Frederico Sousa

Hello all,

is it possible for adding text inside the polygon?

UserImage.jpg
Daniel Resende

Hi,


By default you shouldn't add text to the polygon you should have a text or textPath or a Path (should not be your first try) to add text to your SVG.

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/polygon


you should go at the end with something like this.

<svg xmlns="https://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 64 64">
  <polygon fill="#F3BC23" stroke="#F3BC23" stroke-width="1" points="30,4,4,60,60,60"/>
  <text x="32" y="50" text-anchor="middle" fill="white" font-size="30">X</text>
</svg>


I check this component and right now its not possible to add text Elements(via webblock). Maybe you should contribute and make that improvement or go to other component. 


Good Luck!



2021-03-24 17-29-38
Frederico Sousa
Champion

I'm sorry I had a very busy day.


If you check the svg.js API you can see that it allows you to draw text by using one of these methods  (Link) 

It's a matter of doing those methods. I'll try to include this asap but you can also do it and then I can add you to the component team.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.