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::parse_string and unicode lables #115

Open
vizvamitra opened this issue Dec 23, 2015 · 13 comments · May be fixed by #151
Open

GraphViz::parse_string and unicode lables #115

vizvamitra opened this issue Dec 23, 2015 · 13 comments · May be fixed by #151

Comments

@vizvamitra
Copy link

I've found some strange behavior:

dot_str = "digraph G {\nHello [label = \"안녕하세요\"];\nWorld [label = \"Мир\"];\n  Hello -> World;\n}\n"

GraphViz.parse_string(dot_str).output(none: String)
# => "digraph G {\nHello [label = \"\\xEC\\x95\\x88\\xEB\\x85\\x95\\xED\\x95\\x98\\xEC\\x84\\xB8\\xEC\\x9A\\x94\"];\nWorld [label = \"\\xD0\\x9C\\xD0\\xB8\\xD1\\x80\"];\n  Hello -> World;\n}\n""

GraphViz.parse_string(dot_str).output(png: 'test.png') # =>

test

(ruby 2.0.0p353, ruby-graphviz 1.2.2, graphviz 2.36.0)

@froderik
Copy link

Same issue here but with swedish characters. Any progress? As far as I can tell GraphViz supports unicode so I guess it is called in the wrong way somehow.

@vizvamitra
Copy link
Author

@froderik I ended up writing my own simple implementation of a tool that converts directed graph to dot string and feeding this string directly to dot command.

@froderik
Copy link

aah - thanks for posting! We have a dot file already that is generated from another source so maybe we should try to just pass it directly to dot instead of using graphviz. What do you think?

@vizvamitra
Copy link
Author

@froderik it does work with russian so I think it'll do so with swedish too =)

system('dot /path/to/dot/file.dot -Tsvg -o /path/to/output/file.svg')

But you will probably need to handle all posible errors from dot command (I believe in this gem they handle errors here with just raising "Error from #{cmd}:\n#{errors}")

Also Ruby-Graphviz gem is quite heavy and I guess it'll be beter not to use it if your use cases are as simple as just format simple graph to dot or convert dot to image

@froderik
Copy link

great! will try it right away!

@froderik
Copy link

@vizvamitra - works like a charm - thanks for the help!

@abruzzi
Copy link

abruzzi commented Oct 26, 2016

Any update about this?

I got a similar issue with Chinese character in the label of nodes.

script as the following

require "graphviz"

g = GraphViz::new( "G" )
g.add_nodes "chinese", label: '你好'
g.output( :dot => "x.dot" )

would generate dot as this:

digraph G {
    graph [bb="0,0,115.69,36"];
    node [label="\N"];
    chinese  [height=0.5,
        label="\u4F60\u597D",
        pos="57.845,18",
        width=1.6068];
}

and will generate graph contains node with label as u4F60u597D, any solutions or walk around please ?

@atitan
Copy link

atitan commented Apr 15, 2017

It's platform-related issue.
to_gv uses 'string'.to_s.inspect.gsub( "\\\\", "\\" ) to escape string, and inspect behaves differently on Windows.

c:\script>ruby test.rb
"\u4F60\u597D"
[user@i2 ~]$ ruby test.rb
"你好"

reference: http://stackoverflow.com/questions/34454084/ruby-sometimes-prints-unicode-escaped-chars-instead-of-the-chars-themselves-why

@ghost
Copy link

ghost commented Aug 20, 2017

The problem is in lib/graphviz/utils.rb:46
function output_and_errors_from_command: Open3 works in binmode, that force
Encoding:ASCII-8BIT

@davidmoshal
Copy link

this worked for me: < for the less than sign.

@vanboom
Copy link

vanboom commented Aug 6, 2021

This issue is still present in 2021 when labels have UTF-8 character codes, in our case French names with é character.

@vanboom
Copy link

vanboom commented Aug 6, 2021

The problem is in lib/graphviz/utils.rb:46
function output_and_errors_from_command: Open3 works in binmode, that force
Encoding:ASCII-8BIT

When producing a SVG using -Tsvg, binode should be false. Working on a PR with hopes to finally resolve this. Is this gem actively maintained?

vanboom pushed a commit to vanboom/Ruby-Graphviz that referenced this issue Aug 6, 2021
…ould be false when the command produces text
@vanboom vanboom linked a pull request Aug 6, 2021 that will close this issue
@vanboom
Copy link

vanboom commented Aug 6, 2021

PR submitted - not sure if anyone is listening though.

To contributors: Thank you for your consideration on my PR and for supporting this great gem.

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

Successfully merging a pull request may close this issue.

6 participants