Drawing with graphviz 2

Source: Internet
Author: User
Although graphviz is powerful, there are two shortcomings.
    1. Poor Support for Chinese characters. UTF-8 can also be used for processing in windows. It is very troublesome in Linux, and I cannot solve it multiple times.
    2. It is because graphviz and Java cannot interact. in Java, I can only call graphviz by creating a new process. It is completely blackbox and cannot be controlled. It cannot ensure that the image is correctly drawn.
After several attempts, I found several solutions

1. I found that graphviz has another inconspicuous sub-project grappa, which is completely written in Java. According to its document, it is a simplified version of graphviz (it is troublesome to download grappa. It seems that the webpage of the other party has an error and the direct connection cannot be downloaded. I can only get it on maillist,Source codeIf you want to use graphviz, you can send it to me by email.) download back and use it. It is disappointing at first. The original simplified version does not have graphviz's most valuable Automatic Layout function. all the directly generated images are stacked together and completely unavailable. When I was about to give up, I found that grappa was classified in the view category of graphviz and suddenly opened up. I returned and went back to the query, graphviz supports multiple outputs, including outputs. dot files, SVG files, etc. these files are all text and well processed. I tried to generate dot files and SVG files through graphviz. It was very fast and there was no problem with Chinese characters, after processing, the dot file is much larger than the original dot file. Check the following and find that all nodes and images are automatically laid out. The dot file contains coordinates. processing with grappa is successful. draw a graph smoothly in Java (the efficiency is much slower than graphviz). In this way, the first method is to generate a dot through graphviz and then display it through grappa. it can be displayed in the applet. Grappa supports very old java1.1, which seems to be usable in IE.

2. graphviz can generate an SVG file !, This is much easier to do. Grappa is not required. Using the Jakarta's batik package, I smoothly converted SVG to JPG images through servlet, if any problem occurs, see jdk1.5 font setting in Linux ). it should be noted that graphviz does not perform special processing on Chinese characters. In the final generated XML, it will write encoding = "UTF-8 ", but the actual encoding is your system's default encoding (I use GBK), so you need to manually adjust the encoding. if you are abnormal. you can use batik to read SVG and output it as SVG. The final SVG compatibility is very good. It can be directly displayed in IE through the SVG plug-in of adobe.

PS. When graphivz is used, graphiviz does not automatically wrap long rows. If there are long rows, You need to manually wrap them, such as writingProgramChange 12345678 to 123 \ n456 \ n78. The final effect is line feed.CodeThis is what we do.

Private   Static String filter (string raw) {
String [] lines = Raw. Trim (). Split ( " \ N " );
If (Lines. Length >   0 ) {
Stringbuffer newline =   New Stringbuffer ();
For ( Int I =   0 ; I < Lines. length; I ++ ) {
String line = Lines [I];
Newline. append (nearline (line ));
If (I ! = Lines. Length -   1 )
Newline. append ( " \ N " );
}
Return Newline. tostring ();
}   Else   {
ReturnUsing line (raw );
}
}
Private   Static String inline line (string line) {
If (Line. Length () >   10 ) {
Char [] Chars = Line. tochararray ();
Stringbuffer sb =   New Stringbuffer ();
For ( Int I =   0 ; I < Chars. length; I ++ ) {
Char Achar = Chars [I];
If (I ! =   0   && I %   12   =   0 )
SB. append ( " \ N " );
SB. append (Achar );

}
Return SB. tostring ();
}   Else   {
ReturnLine;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.