guru.nidi.graphviz.attribute.Color Java Examples

The following examples show how to use guru.nidi.graphviz.attribute.Color. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 6 votes vote down vote up
@Test
void ex4b() throws IOException {
    final Graph g = CreationContext.use(ctx -> {
        ctx
                .graphAttrs().add(Color.YELLOWGREEN.background())
                .nodeAttrs().add(Color.LIGHTBLUE3.fill(), Style.FILLED, Color.VIOLET.font())
                .linkAttrs().add(Style.DOTTED);
        final Node
                struct1 = node("struct1").with(Records.mOf(rec("f0", "left"), rec("f1", "mid dle"), rec("f2", "right"))),
                struct2 = node("struct2").with(Records.mOf(rec("f0", "one"), rec("f1", "two"))),
                struct3 = node("struct3").with(Records.mOf(
                        rec("hello\nworld"),
                        turn(rec("b"),
                                turn(rec("c"), rec("here", "d"), rec("e")),
                                rec("f")),
                        rec("g"), rec("h")));
        return graph("ex4b").directed().with(
                struct1.link(
                        between(port("f1"), struct2.port("f0")),
                        between(port("f2"), struct3.port("here"))));
    });
    Graphviz.fromGraph(g).render(PNG).toFile(new File("target/ex4b.png"));
}
 
Example #2
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 6 votes vote down vote up
@Test
void ex7() throws IOException {
    final Graph g = graph("ex7").directed()
            .with(
                    graph().cluster()
                            .nodeAttr().with(Style.FILLED, Color.WHITE)
                            .graphAttr().with(Style.FILLED, Color.LIGHTGREY, Label.of("process #1"))
                            .with(node("a0").link(node("a1").link(node("a2").link(node("a3"))))),
                    graph("x").cluster()
                            .nodeAttr().with(Style.FILLED)
                            .graphAttr().with(Color.BLUE, Label.of("process #2"))
                            .with(node("b0").link(node("b1").link(node("b2").link(node("b3"))))),
                    node("start").with(Shape.M_DIAMOND).link("a0", "b0"),
                    node("a1").link("b3"),
                    node("b2").link("a3"),
                    node("a3").link("a0"),
                    node("a3").link("end"),
                    node("b3").link("end"),
                    node("end").with(Shape.M_SQUARE)
            );
    Graphviz.fromGraph(g).render(PNG).toFile(new File("target/ex7"));
}
 
Example #3
Source File: PlanImpl.java    From jesterj with Apache License 2.0 6 votes vote down vote up
private void linkUp(Map<String, Node> nodes, List<String> knownSteps, StepImpl step) {
  LinkedHashMap<String, Step> nextSteps = step.getNextSteps();
  Node node = nodes.computeIfAbsent(step.getName(), Factory::node);
  if (step instanceof Scanner) {
    node= node.with(Color.BLUE,Style.lineWidth(3));
    nodes.replace(step.getName(), node);
  }
  knownSteps.add(step.getName());
  if (nextSteps.size() == 0) {
    return;
  }
  for (Step subsequentStep : nextSteps.values()) {
    if (!knownSteps.contains(subsequentStep.getName())) {
      // new node, need to recurse
      linkUp(nodes, knownSteps, (StepImpl) subsequentStep);  // yuck but I don't really want to expose next steps in interface either
    }
    Node nextNode = nodes.get(subsequentStep.getName());
    node = node.link(nextNode);
    // link returns an immutable copy of the node we just created, so we need
    // to throw out the original and keep the copy
    nodes.put(step.getName(), node);
  }
}
 
Example #4
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void ex1b() throws IOException {
    final Node
            printf = node("printf"),
            make_string = node("make_string");
    final Graph g = graph().graphAttr().with("dpi", 300).directed().with(
            node("main").with(Color.rgb("ffcc00"), Style.FILLED).link(
                    node("parse").link(node("execute")
                            .link(make_string, printf, node("compare"))),
                    node("init").link(make_string),
                    node("cleanup"),
                    printf));
    Graphviz.fromGraph(g).render(PNG).toFile(new File("target/ex1b.png"));
}
 
Example #5
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void ex3() throws IOException {
    final Node
            a = node("a").with(Shape.polygon(5).rotation(20), attr("peripheries", 3), Color.LIGHTBLUE, Style.FILLED),
            c = node("c").with(Shape.polygon(4).skew(.4), Label.html("hello world")),
            d = node("d").with(Shape.INV_TRIANGLE),
            e = node("e").with(Shape.polygon(4).distortion(.7));
    final Graph g = graph("ex3").directed().with(
            a.link(node("b").link(c, d)),
            e);
    Graphviz.fromGraph(g).render(PNG).toFile(new File("target/ex3.png"));
}
 
Example #6
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void ex8() throws IOException {
    final Node split = node("split types"),
            redString = node("reduce 'string' line"),
            redNum = node("reduce 'numbers' line"),
            succString = node("doOnSuccess print1"),
            succNum = node("doOnSuccess print2"),
            end = node("");
    final Attributes<ForAll> attr = attrs(Color.rgb("bbbbbb"), Color.rgb("bbbbbb").font(), Font.name("Arial"));
    final Graph g = graph("ex8").directed()
            .graphAttr().with(Color.rgb("444444").background())
            .nodeAttr().with(Style.FILLED.and(Style.ROUNDED), attr, Color.BLACK.font(), Color.rgb("bbbbbb").fill(), Shape.RECTANGLE)
            .linkAttr().with(Color.rgb("888888"), Style.lineWidth(2))
            .with(
                    node("input").link(split.link(redString, redNum)),
                    graph().cluster()
                            .graphAttr().with(attr, Label.of("stringPrint"))
                            .with(redString.link(succString)),
                    graph("x").cluster()
                            .graphAttr().with(attr, Label.of("numberPrint"))
                            .with(redNum.link(succNum)),
                    succString.link(end),
                    succNum.link(end)
            );
    final Graphviz viz = Graphviz.fromGraph(g).width(320);
    viz.rasterize(SALAMANDER).toFile(new File("target/ex8s.png"));
    viz.rasterize(BATIK).toFile(new File("target/ex8b.png"));
    viz.render(SVG).toFile(new File("target/ex8.svg"));
}
 
Example #7
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void ex11() throws IOException {
    Graphviz.fromGraph(mutGraph("example11").setDirected(true).use((g, ctx) -> {
        nodeAttrs().add(Color.RED);
        linkAttrs().add(Arrow.DIAMOND);
        graphAttrs().add(Label.of("Ex6"));
        mutNode("a").addLink("b");
        mutGraph("sub").setCluster(true).use((g2, ctx2) -> {
            mutNode("sa").addLink("sb");
        }).addLink(mutNode("a"));
    })).render(Format.PNG).toFile(new File("target/ex11"));
}
 
Example #8
Source File: ContextTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void overwriteNode() {
    final MutableGraph g = CreationContext.use(ctx -> {
        ctx.nodeAttrs().add(Color.RED);
        return mutGraph().add(
                node("a").with(Color.BLUE),
                node("b"));
    });
    assertEquals(mutGraph().add(
            node("a").with(Color.BLUE),
            node("b").with(Color.RED)),
            g);
}
 
Example #9
Source File: ContextTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void overwriteLink() {
    final MutableGraph g = CreationContext.use(ctx -> {
        ctx.linkAttrs().add(Color.RED);
        return mutGraph().add(
                node("a").link(to(node("b")).with(Color.BLUE)),
                node("b").link(node("c")));
    });
    assertEquals(mutGraph().add(
            node("a").link(to(node("b")).with(Color.BLUE)),
            node("b").link(to(node("c")).with(Color.RED))),
            g);
}
 
Example #10
Source File: ContextTest.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Test
void overwriteGraph() {
    final List<MutableGraph> gs = CreationContext.use(ctx -> {
        ctx.graphAttrs().add(Color.RED);
        return asList(
                mutGraph().graphAttrs().add(Color.BLUE),
                mutGraph());
    });
    assertEquals(asList(
            mutGraph().graphAttrs().add(Color.BLUE),
            mutGraph().graphAttrs().add(Color.RED)),
            gs);
}
 
Example #11
Source File: ExampleTest.java    From graphviz-java with Apache License 2.0 4 votes vote down vote up
@Test
void ex2() throws IOException {
    final Node
            init = node("init"),
            execute = node("execute"),
            compare = node("compare").with(Shape.RECTANGLE, Style.FILLED, Color.hsv(.7, .3, 1.0)),
            make_string = node("make_string").with(Label.of("make a\nstring")),
            printf = node("printf");
    final Graph g = graph("ex2").directed()
            .graphAttr().with(Color.rgb("222222").background())
            .nodeAttr().with(Font.config("Arial", 15), Color.rgb("bbbbbb").fill(), Style.FILLED)
            .with(
                    node("main").with(Shape.RECTANGLE).link(
                            to(node("parse").link(execute)).with(LinkAttr.weight(8)),
                            to(init).with(Style.DOTTED),
                            node("cleanup"),
                            to(printf).with(Style.BOLD, Label.of("100 times"), Color.RED)),
                    execute.link(graph().with(make_string, printf), to(compare).with(Color.RED)),
                    init.link(make_string));
    final Graphviz graphviz = Graphviz.fromGraph(g);
    graphviz.render(PNG).toFile(new File("target/ex2.png"));
    graphviz.render(PNG).withGraphics(gr -> {
        gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }).toFile(new File("target/ex2-anti-all-on.png"));
    graphviz.render(PNG).withGraphics(gr -> {
        gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }).toFile(new File("target/ex2-anti-off.png"));
    graphviz.render(PNG).withGraphics(gr -> {
        gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }).toFile(new File("target/ex2-anti-gasp.png"));
    graphviz.render(PNG).withGraphics(gr -> {
        gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }).toFile(new File("target/ex2-anti-on.png"));
    graphviz.engine(Engine.CIRCO).render(PNG).toFile(new File("target/ex2-ci.png"));
    graphviz.engine(Engine.NEATO).render(PNG).toFile(new File("target/ex2-ne.png"));
    graphviz.engine(Engine.OSAGE).render(PNG).toFile(new File("target/ex2-os.png"));
    graphviz.engine(Engine.TWOPI).render(PNG).toFile(new File("target/ex2-tp.png"));
    graphviz.engine(Engine.FDP).render(PNG).toFile(new File("target/ex2-fdp.png"));
    graphviz.render(SVG).toFile(new File("target/ex2.svg"));
    graphviz.render(JSON).toFile(new File("target/ex2.json"));
    graphviz.render(JSON0).toFile(new File("target/ex2.json0"));
    graphviz.render(PS).toFile(new File("target/ex2.ps"));
    graphviz.render(PS2).toFile(new File("target/ex2.ps2"));
    graphviz.render(PLAIN).toFile(new File("target/ex2.plain"));
    graphviz.render(PLAIN_EXT).toFile(new File("target/ex2.plain-ext"));
}