Export graph image when using command line
Hey,
For my master thesis project I have created a plug-in for ProM 6 that mines a log, resulting in a graph which extends an AbstractDirectedGraph, which is then visualized in ProM. The plug-in itself is working fine.
However, the idea now is that the plug-in should also be able to run through command line, which (for the mining part) it does. But, I would also like to output an image of the graph to disk (in any (common) format) when running it through the command line.
So my question is: Does anyone know if there is a way to export a graph to disk (as an image) without using the GUI of ProM?
Regards,
Michel
Best Answer
-
Hi Michel,
First of all: welcome on the ProM forum!
I know that some visualizers (for instance the PetriNet and Heuristic net) use the 'freehep' library to allow for exporting of the visualization.
This is build in the framework so the library is available on all ProM installations.
I would suggest that you investigate how you can automatically execute a conversion. I think that it should be possible.
Let us know if you got it to work. And good luck on your plugin.
Joos Buijs
Senior Data Scientist and process mining expert at APG (Dutch pension fund executor).
Previously Assistant Professor in Process Mining at Eindhoven University of Technology
Answers
-
First of all: Best wishes to everyone at this forum!
<SOLVED>
Using the freehep library works. However, I can't seem to get the graph visualized.
I use the following call to get the visualization panel:mainPanel = ProMJGraphVisualizer.instance().visualizeGraph(pluginContext, pdmmodel); //pdmmodel extends AbstractDirectedGraph<...>
After which I am able to print the main visualization panel, but not the graph itself.
So either I'm missing something or the visualizeGraph() doesn't actually visualize the graph on the panel (that it returns) and I need to do something else in order to get the graph visualized (which I can't seem to figure out)...
Edit: Seems the size of the graph was not set:
ProMJGraph graph = (ProMJGraph) mainPanel.getComponent();
graph.setSize(new Dimension(500,500)
Did the trick, together with printing this component using freehep. -
Code to output a .pdf file:
public static void visualize2(PDMModel pdmmodel) {
CLIContext context = new CLIContext();
CLIPluginContext pluginContext = new CLIPluginContext(context, "test");
ProMJGraphPanel mainPanel = ProMJGraphVisualizer.instance().visualizeGraph(pluginContext, pdmmodel); //pdmmodel extends AbstractDirectedGraph
mainPanel.setSize(new Dimension(500,500));
// Get graph
ProMJGraph graph = (ProMJGraph) mainPanel.getComponent();
graph.setSize(new Dimension(500,500));
try {
VectorGraphics g = new PDFGraphics2D(new File("output.pdf"), new Dimension(500,500));
g.setProperties(new Properties());
g.startExport();
graph.print(g);
g.endExport();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} -
Hi Michel,
Thank you for sharing the solution! This helps others who are trying to achieve the same.
Joos Buijs
Senior Data Scientist and process mining expert at APG (Dutch pension fund executor).
Previously Assistant Professor in Process Mining at Eindhoven University of Technology
Howdy, Stranger!
Categories
- 1.6K All Categories
- 45 Announcements / News
- 225 Process Mining
- 6 - BPI Challenge 2020
- 9 - BPI Challenge 2019
- 24 - BPI Challenge 2018
- 27 - BPI Challenge 2017
- 8 - BPI Challenge 2016
- 68 Research
- 1K ProM 6
- 394 - Usage
- 288 - Development
- 9 RapidProM
- 1 - Usage
- 7 - Development
- 54 ProM5
- 19 - Usage
- 187 Event Logs
- 32 - ProMimport
- 75 - XESame