Optimized graph drawing for the web - java

Having seen some suggestions for graphs, I wonder what's the optimum for my problem.
I want to render a directed graph to a servlet/picture that is displayed in the browser. There should be some kind of optimization of position. No dependency to Swing would be preferred. Algorithms are not important, since the structure of the graph is determined by business logic. It would be desired to be able add labels to edges as well.
it would be optimal if i can serve this as png/svg.
Which library/service would you recommend?
clarifications:
1) The question is all about Graphs - like Directed Acyclic Graph - NOT - Charts.
2) flot, Google Charts - cannot plot graphs, only charts, or have i missed something?
3) no i do not need interactivity
4) graphviz would be nice, but the grappa java library is quite outdated and is built upon swing/awt. while it may be theoretically possible to render swing to images, it would not be my favorite way to to so in a server-app.
5) it would be fine to use an online service where the images are not hosted locally.
edit: added links to Wikipedia to clarify graph/chart term

Take a look at graphviz

yFiles might be useful for this.

How about the dot component of Graphviz? It produces graphs (not charts), outputs to PNG and SVG, and supports labeling edges. You can shell out to dot to generate the image you need, and return an img tag that references that. Alternatively, you can return an img tag that references a URL that will generate the requisite graph (or retrieve a cached copy). Here's the dot info:
http://www.graphviz.org/pdf/dotguide.pdf
You might also take a look at WebDot, which is apparently designed for this purpose:
http://www.graphviz.org/webdot/

As well as waiting weeks to hear about the Magic Framework that's going to solve all your problems in one line of code, there is also the other option of just Writing Some Code yourself to do exactly what you want... (I'm not saying it's 10 minutes' work, but it's probably one or two days, and you posted your question over two weeks ago...)
Have you had a look, for example, at the Wikipedia entry on Force-based algorithms-- it has pseudocode and a few links that might be helpful.
I'm assuming it is the layout algorithm that's the issue, and not the matter of creating a BufferedImage, drawing to its graphics context, PNG-encoding it and sending it down the socket. You really don't need a framework for that bit, I don't think.

Try aiSee. It is used by all kinds of web-based applications for data mining, static program analysis, matrix visualization, network analysis, and whatnot. It is also used by some MediaWikis as their graph-layout backend.
They have a huge database of sample graphs over at aiSee.com. Check it out. It supports edge labels, export to mapped SVG and HTML, and is not dependent on Swing.

We create mxGraph for such requirements. We did actually release it in 2006, but took a while to notice this question...

For serverside, try JUNG, you can run it against Batik and produce beautiful SVG or PNG files. JUNG has a nice design and very powerful layout algorithms...
Also, since you mention that "it would be fine to use an online service", graphviz provide a service called webdot to render graphs.
There are others along this line as well... e.g. http://graph.gafol.net/ (seems to be down)
Client side:
Try http://arborjs.org/ for a minimal(ish) library it is dedicated to layout, use this is you like to prefer your own rendering routines (div, canvas, svg, paper.js, processing... etc).
I also like http://sigmajs.org/ for a more complete approach, build in touch support, plugins, file formats, etc.

Interestingly, the Eclipse project has an SWT/JFace component/framework capable of displaying and generating (import/export) Graphviz's 'DOT' format, in pure Java:
ZEST (home page & download links)
See http://wiki.eclipse.org/Graphviz_DOT_as_a_DSL_for_Zest for usage examples.
Although ZEST is touted as an Eclipse plugin, it does seem that the DOT-manipulation API's can be used standalone and external to an Eclipse installation.
Cheers
Rich

You may try sigma.js: http://sigmajs.org/
It is a lightweight, open source library in Javascript to display large graphs on the Web.

JPGD is a Graphviz parser in Java. It's a little abandoned, but the code is nice and clear, and if you find bugs I'm sure the author would accept contributed fixes.
Although advertised as a parser, it is also a generator. You can build Graphs as collections of Node and Edge objects, then get .dot using Graph.toString(). Getting this as a graphic would be a simple shell out to the Graphviz dot executable.
Alternatively, dot is very easy to generate yourself. In the simplest case, it's just a matter of writing a potted header
digraph myGraph {
... followed by one edge definition per edge
node1 -> node2 ;
... followed by a closing brace
}

so i took alook at all the given answers and links, it looks like Prefuse/Flare will by the optimal choice.
they have very appealing visialisations, plus they have built in support for graphs.

Maybe check out Google Charts?

You can use SVG in combination with Batik. I have used this several times for displaying graphics. Batik with Java 1.5 is very fast. With this solution you can program your graph in Java with no dependency on Swing. You can add labels where you want, host it as a Servlet and display it as png or svg.
You can create the graphs in SVG (this is an XML document).
You use Batik to transform the SVG-document to a PNG/JPG image.
You can use a Servlet to stream this image back to the browser.
In java you build an SVG(=XML) document. Samples for SVG graphs can be found here:
Directed graph and here: Simple directed graph

See this question, especially Stephan's answer about prefuse. I read that you do not need interactivity, but prefuse still may be useful.

I can whole-heartedly recommend flot - excellent!
See examples here.

JFreeChart might be the way you want to go, but you make a distinction between Charts and Graphs. Maybe you can explain what you mean by that. I've usually used these terms synonymously. :)
JFreeChart has good scatter, bar and line graphs as well as fun ones like Pie and Dial so maybe it will work for you.

Related

How do you load a tmx/xml file in javafx?

What is the most efficient way to add a tile map in a JavaFX program?
The program that I use for creating tile maps is called "Tiled", and the saved files are in .tmx format.
Now, the question is, how do I import that exactly in my 2d game? I haven't been able to find helpful information on the net.
Code examples are greatly appreciated.
Thanks
Use the Eppleton JavaFX TileEngine (unfortunately this link is now dead: similar content is still hosted on javageeks: Beware link comes with annoying add popup).
Update: Unfortunately the eppleton blog entry previously linked, which contained detailed information on creating a tile engine using JavaFX, no longer exists.
I have no idea how to import the file, still.
You will not find at present some library somebody has created and packaged as a binary jar you can just add to your class path to get a generic tile reader for JavaFX.
Loading a TileMap is a complex task. The Eppleton link I provided provides detailed information on how to implement that task as well as source code snippets. The Eppleton information is the best available on TileMaps in JavaFX. By using the Eppleton engine you can reduce the effort involved to load a TileMap to:
TileMap map = TileMapReader.readMapFromFile(fileURL);
There is a github repository for the Eppleton game engine. I tried it and most of the code is there but some of the dependencies for the project did not resolve for me so I was unable to build it. You can contact the author for assistance in resolving dependencies or you can fork the engine and patch it to allow it to work for you. The approach the engine seems to take is to use an abstraction for canvas so that the engine can render into different canvas types (JavaFX canvas being one of these). But I couldn't find the code for the abstraction layer.
The core code for the time map reader is in the de.eppleton.fx2d.tileengine package. You can fork the code and study it to understand how in detail how the tile map reader works and how you might adapt it for your game.

Weka visualize data

I have a question related to Weka. I have data and I want to visualize them. I use k-means for clustering. I found the option to visualize the data, but I would like something more than that. When you visualize the clusters if you right click on them, then a window appears. In that window there is some information, but I would like to see i.e the data that this point came from. Is there any way through Weka or i should write Java?
I have tried it but with no luck.
If I do not have matlab or R in my machine to plot data, I use GNUPlot ( http://www.gnuplot.info/ ) to plot data from command line and files.
you can use ELKI or Processing Tool as an API in your Java program and can visualize your result. However, the visualization may not be interactive in ELKI but you can certainly extend the interactive property using customized methods while plugging the Processing Tool in your java code.
You may need to write some code on your own but you may not need to start from scratch. You could use Weka's own code (it is open source) to develop a visualization plugin that satisfies your needs. Check the Wiki for more information and examples: https://weka.wikispaces.com/Explorer+visualization+plugins

Templated correspondence generation using Java

I am looking for a way to create pixel perfect, paginated, styled correspondence in a Java web application.
The requirements for this functionality are
- Ability to define outer/ master template with header/ footer/ logo etc...
- Ability to define inner content template where specific variables/ fields can be substituted with instance values at run time - e.g. employeeName. employeeAddress. The content template would be defined online using rich text editor or something similar
- Supports tables/ list
I believe iText does most/ if not all. Other options that I have considered is BIRT. Are there other/ better choices for this purpose?
Thanks
I have done something like with iText, although our case did not use an online text editor (we had a small number of templates and they were defined as part of the development cycle)
[Note: We did this under an older version of iText when it was still LGPL rather than Affero GPL]
The results were excellent, but in order to get it pixel-perfect we had to do a lot of work ourselves. We did manual layout and pagination - including manual text wrapping, etc. The layout tools that iText provides looked good, but they didn't give us the pixel-perfect control that we needed for the use case we had.
Have a look at iReport.

How to modify an OpenOffice.org Draw diagram in Java?

I have an OpenOffice.org Draw diagram, which shows individual modules of my software.
I also have a file with information about problems in those modules (each module can be in one of 3 states: OK, ERROR, UNKNOWN).
I want to
a) color the figures in the diagram according to the information from the file (problematic modules - red, OK modules - green and all others - gray) and
b) export the diagram to an image file.
The original diagram is created manually (so that it is laid out nicely).
Question: How can I do this, preferably in Java?
Thanks in advance
Dmitri
OpenOffice has an official API. You should check if it can do what you need.
If not, a reasonable way to progress would be to export to SVG, and then use a SVG library to manipulate the SVG XML as needed.
#TRA has a good point. On the other hand, if you're feeling brave..
Open Office files are Zipped XML. Use a ZipInputStream to get access to the entries, then any of the plethora of J2SE based XML handling APIs (Sax, DOM etc.) to parse the XML.

How do I use Blender models in Java?

Just a general question really?
Let's say I am making a game and have made a character model in Blender. How would I use this model in Java?
Would I import it somehow?
Thanks.
Generally when making models in blender you export the model in a format which allows you to later import it in the game engine of your choice, which format you use differ in requirements.
The export-import cycle is often referred to as the "Asset Pipeline", and you generally want to keep it as simple and automated as possible since it is something you or your artists will perform on a regular basis.
So if we look at a few specific graphics engines and platforms;
OGRE3D (or Ogre4J) supports it's own plain-text format (.scene, .mesh.xml, .material.xml) in order to load scenes, models and materials. It also has support for armature animations among other things, there is also some support for loading .blend-files directly. See their documentation for blender.
JmonkeyEngine has support for loading both OGRE3D .scene's and .blend's directly. It also has it's own binary j3o format which these can be converted into when you want to package the game. For specific examples, see their tutorials.
There are multiple formats you can take into consideration when deciding how you want to use your model. When it is imported however, the game engine of choice represents it in an internal structure which usually allows you to be decoupled from the exact format of choice.
Picking which to use is and should not be written in stone since requirements might change and if done properly it should not have a considerable effect on the project. This is also something you should take into consideration if you are writing your own engine.
There are input/output scripts available for Blender that will help you.
Blend2Java, for example, is a set of Python scripts for use with Blender that will export to Java XML, which can be decoded with the standard java.beans.XMLDecoder class.
There's a good overview of how to do this at http://blend2java.sourceforge.net/blend2java-howto.html
Here's a better idea: Use an existing Java 3D library (dzzd I highly recommend) and load in your model using the library's built in functions. Then, instead of just working with the data, you can actually display it. From Blender, it's a simple matter of exporting as 3DS.
Yet another solution: Java .Blend provides you with a type-safe Java API to all data in a Blender file. It supports even creating new Blender files from within Java ;)

Categories