Coder Social home page Coder Social logo

graphviz-java's Introduction

graphviz-java Build Status

Use graphviz with pure java.

Uses this javascript version of graphviz created using Emscripten.

The javascript code is executed either with J2V8 or, as a fallback with Java 8's Nashorn engine.

Usage

The basic usage is as follows:

import static guru.nidi.graphviz.model.Factory.*;

Graph g = graph("example").directed().node(node("a").link(node("b")));
Graphviz.fromGraph(g).renderToFile(new File("example.png"));

Complex example

Node
    init = node("init"),
    execute = node("execute"),
    compare = node("compare").attr(Shape.RECTANGLE, Style.FILLED, Color.hsv(.7, .3, 1.0)),
    mkString = node("mkString").attr(Label.of("make a\nstring")),
    printf = node("printf");

Graph g = graph("example2").directed().node(
    node("main").attr(Shape.RECTANGLE).link(
        to(node("parse").link(execute)).attr("weight", 8),
        to(init).attr(Style.DOTTED),
        node("cleanup"),
        to(printf).attr(Style.BOLD, Label.of("100 times"), Color.RED)),
    execute.link(
        graph().node(mkString, printf),
        to(compare).attr(Color.RED)),
    init.link(mkString));

Graphviz.fromGraph(g).renderToFile(new File("example/ex2.png"));

Example with records

    Node
        node0 = node("node0").attr(Records.of(rec("f0", ""), rec("f1", ""), rec("f2", ""), rec("f3", ""), rec("f4", ""))),
        node1 = node("node1").attr(Records.of(turn(rec("n4"), rec("v", "719"), rec("")))),
        node2 = node("node2").attr(Records.of(turn(rec("a1"), rec("805"), rec("p","")))),
        node3 = node("node3").attr(Records.of(turn(rec("i9"), rec("718"), rec("")))),
        node4 = node("node4").attr(Records.of(turn(rec("e5"), rec("989"), rec("p","")))),
        node5 = node("node5").attr(Records.of(turn(rec("t2"), rec("v", "959"), rec("")))),
        node6 = node("node6").attr(Records.of(turn(rec("o1"), rec("794"), rec("")))),
        node7 = node("node7").attr(Records.of(turn(rec("s7"), rec("659"), rec(""))));
    Graph g = graph("example3").directed()
        .general().attr(RankDir.LEFT_TO_RIGHT)
        .node(
            node0.link(
                between(loc("f0"), node1.loc("v", SOUTH)),
                between(loc("f1"), node2.loc(WEST)),
                between(loc("f2"), node3.loc(WEST)),
                between(loc("f3"), node4.loc(WEST)),
                between(loc("f4"), node5.loc("v", NORTH))),
            node2.link(between(loc("p"), node6.loc(NORTH_WEST))),
            node4.link(between(loc("p"), node7.loc(SOUTH_WEST))));
    Graphviz.fromGraph(g).renderToFile(new File("example/ex3.png"));

graphviz-java's People

Contributors

nidi3 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.