A system is built to complete some simple or complex product logic through configuration. After the system is put into use, product personnel have configured many products on it, the product process is stored in an XML file. I suddenly had an idea a few days ago. I planned to display the process in graphs. So I opened Google and went online to find the Java drawing tool, I didn't see any useful free libraries, and I thought it was too troublesome to crack them. I accidentally found graphviz. After preliminary use, I found that this tool was really powerful. In addition to the inability to use Java for direct operations, it is very simple to draw various flowcharts and network diagrams, and the drawing effect is also very good.
Graphviz home page in http://www.graphviz.org/, he is a graph drawing tool developed by at&t labs-Research and he can easily be used to draw a structured graph network that supports output in multiple formats, the quality and speed of generating images are both good.
Graphviz itself is an open-source product. You can download it here and use graphviz's demo interface to run smoothly on both Windows and Linux.
After graphviz is installed, the default graphviz command is automatically added to the command walk. It is very easy to use. We need to write a dot file in the following format:
/* The format of the comment */
/* Digraph indicates a directed graph */
Digraph G {
"A"-> "B"
}
After saving the preceding content as test. Dot, test.png will be generated in the current directory through "dot test. Dot-tpng-O result.png" on the command line, which is very convenient.
For details about the dot format, refer to the PDF document of the system. I can provide a complicated example and a solution to Chinese in windows.
Digraph G {
Graph [
Ratio = "Auto"
Label = "Hello, my tests"
Labelloc = T
Fontname = "simyou. TTF"
];
Node [
Shape = "box ",
Style = "dotted ",
Fontname = "simyou. TTF ",
Fontsize = "10"
];
Edge [fontname = "simyou. TTF"];
"James"
[
Peripheries = 2,
Style = filled,
Label = "Zhang San, Citizen"
Color = "# eecc80"
];
"Li Si "[
Style = filled,
Label = "farmer Li Si"
Color = "# eecc80"
];
"Wang Wu "[
Style = filled,
Label = "farmer Wang Wu"
Color = "# eecc80"
];
"Zhang San"-> "Li Si" [label = "relative"];
"Zhang San"-> "Wang Wu" [label = "friend"];
"Li Si"-> "Wang Wu" [label = "don't know"];
}
In Windows, save the file in UTF-8 format and set fontname = "simyou. TTF "(you can also set it through the command line parameter-e-n-g fontname =" XX "). The image generated in my Simplified Chinese WindowsXP can display Chinese normally.
Use Java to call the graphviz method. The Code is as follows:
Remember that after the dot script is generated using freemarker, it must be locally saved as UTF-8 and processed using DOT. It is not feasible to directly pass the string through the pipeline. I tried multiple encodings and all failed. In addition, simyou. TTF is the name of the font file. You can find their list under your windows \ fonts \ directory.