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

graphviz draw tooltip with special characters #750

Closed
LaurentBergeron opened this issue Nov 24, 2022 · 5 comments · Fixed by #1203
Closed

graphviz draw tooltip with special characters #750

LaurentBergeron opened this issue Nov 24, 2022 · 5 comments · Fixed by #1203
Assignees
Labels
bug Something isn't working

Comments

@LaurentBergeron
Copy link

LaurentBergeron commented Nov 24, 2022

Information

  • rustworkx version: 0.12.1
  • Python version: 3.9.13
  • Rust version: NA
  • Operating system: Windows 10

What is the current behavior?

Adding a \n or : character to the tooltip throws this error:

Error: <stdin>: syntax error in line 4 near ']'      
Traceback (most recent call last):
  File main.py", line 6, in <module>
    graphviz_draw(
  File "venv\lib\site-packages\rustworkx\visualization\graphviz.py", line 199, in graphviz_draw
    subprocess.run(
  File "AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,  
subprocess.CalledProcessError: Command '['dot', '-T', 'svg', '-o', 'graph.svg']' returned non-zero exit status 1.

What is the expected behavior?

I would like the tooltip to support special characters such as \n and :, like label does.
In http://magjac.com/graphviz-visual-editor/, I'm allowed to do that with:

digraph {
  label="Graph Label"
  Node1 [tooltip="Node1 Tooltip\nlinebreak in tooltip: it's fine"]
}

Steps to reproduce the problem

import rustworkx as rx
from rustworkx.visualization import graphviz_draw

graphviz_draw(
    rx.generators.path_graph(2),
    filename="graph.svg",
    image_type="svg",
    node_attr_fn=lambda x: {"label": "the\nlabel", "tooltip": "the\ntooltip"},
)
@LaurentBergeron LaurentBergeron added the bug Something isn't working label Nov 24, 2022
@mtreinish
Copy link
Member

I took a quick look at this, the error is we're not wrapping tooltip in double quotes so it's getting inserted as a line break and graphviz isn't able to parse it. This is the output of calling .to_dot() in your example:

graph {
0 [label="the
label", tooltip=the
tooltip];
1 [label="the
label", tooltip=the
tooltip];
0 -- 1 ;
}

The simple fix is to update: https://github.com/Qiskit/rustworkx/blob/main/src/dot_utils.rs#L89 to be label or tooltip. But I wonder if there are more fields that take strings and need to be wrapped too?

@1ucian0
Copy link
Member

1ucian0 commented May 29, 2024

For reference, the tooltip documentation https://graphviz.org/docs/attrs/tooltip/

@anushkrishnav
Copy link
Contributor

Heyy I saw this issue at the unitaryhacks .
This seems like a straightforward fix, will start on this, kindly assign this to me, will ask for doubts if something comes up.

@mtreinish
Copy link
Member

This issue is participating on UnitaryHack 2024, between May 29 and June 12, 2024.

Because the nature of the event, there is no need to request to be assigned: just go ahead and PR your fix. The first/best PR can get the bounty (or it could be shared if they complement each other).

@anushkrishnav
Copy link
Contributor

@mtreinish Got it , thank you, the PR is open , Would love to know your thoughts on if the fix is what you are looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants