Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG export: labels as text elements, not vectorized paths #73

Open
MrTomRod opened this issue Jun 5, 2024 · 2 comments
Open

SVG export: labels as text elements, not vectorized paths #73

MrTomRod opened this issue Jun 5, 2024 · 2 comments

Comments

@MrTomRod
Copy link

MrTomRod commented Jun 5, 2024

Dear @ggonnella

I would like to make your SVGs interactive in the browser. However, the SVG does not remember the names of the edges and nodes. If it's easy to achieve, could you enable me to export SVGs with <text> elements as opposed to rendered <paths>. Alternatively, it could be done using an attribute, e.g. data-contig-id="contig_1"

Example path element: <path vector-effect="none" fill-rule="nonzero" d="M3.92188,3.84375 ... L23.2969,7 L23.2969,6.5"></path> => It's impossible to know what contig this is about.

Desired output: <text fill="#000000" ...>contig_1</text> => Something like that would allow be great, now I can identify the contig via JavaScript!

Or: <path (...) data-contig-id="contig_1""></path>

I know Qt can render text as text, maybe it's really easy for you to implement this "feature".

Best, MrTomRod

PS: This is how I know Qt can render text
# pip install PyQt5
from PyQt5.QtGui import QPainter, QFont
from PyQt5.QtSvg import QSvgGenerator
from PyQt5.QtCore import QRectF, QSize
from PyQt5.QtWidgets import QApplication

# Create the application object
app = QApplication([])

# Set up the SVG generator
generator = QSvgGenerator()
generator.setFileName("output.svg")
generator.setSize(QSize(200, 200))
generator.setViewBox(QRectF(0, 0, 200, 200))
generator.setTitle("SVG Title")
generator.setDescription("Description of the SVG")

# Create a QPainter and attach it to the generator
painter = QPainter()
painter.begin(generator)

# Set the font for the painter
font = QFont("Arial", 12)
painter.setFont(font)

# Draw text
painter.drawText(QRectF(0, 0, 200, 200), "contig_1")

# Finish the painting
painter.end()

Output svg contains:

<text xmlns="http://www.w3.org/2000/svg" fill="#000000" fill-opacity="1" stroke="none" xml:space="preserve" x="0" y="11" font-family="Arial" font-size="12" font-weight="400" font-style="normal">Hello, World!</text>
@ggonnella
Copy link
Owner

ggonnella commented Jun 24, 2024 via email

@MrTomRod
Copy link
Author

MrTomRod commented Jul 9, 2024

I created an ugly patch for myself: https://github.com/MrTomRod/gfaviz/tree/text-not-path

Here's the diff.

Possible issues:

  • The text element is missing a stroke.
  • Maybe it causes issues with the rest of the library, I didn't run any tests.

I don't know C++ and don't have time to do this properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants