package nl.tudelft.ti2306.blockchain;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import nl.tudelft.ti2306.blockchain.datastructure.PeerGraph;

public class PeerGraphToViz implements Runnable {

    private PeerGraph graph;
    private String output;

    public PeerGraphToViz(PeerGraph graph, String output) {
        this.graph = graph;
        this.output = output;
    }

    @Override
    public void run() {
        try (PrintWriter out = new PrintWriter(new File(output))) {
            out.println("graph peergraph {");
            out.println("ratio=expand;");
            out.println("node[width=.40,height=.40, label=\"\"]");
            out.println("edge[arrowsize=\"0.3\"]");
            for (int i = 0; i < graph.getNodes().size(); i++) {
                out.println(i + " [label=" + i + " style=filled fillcolor=red]");
                for (int j = 0; j < graph.getEdges(i).size(); j++) {
                    int k = graph.getEdges(i).get(j);
                    if (i > k) continue;
                    out.println(i + "--" + k + " [color=black]");
                }
            }
            out.println("}");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}

@@ -788,24 +788,91 @@
 e(); i++) %7B%0A
+                double hue = i / (double) graph.getNodes().size();%0A
             
@@ -937,11 +937,31 @@
 lor=
-red
+%5C%22%22 + hue + %22 1.0 1.0%5C%22
 %5D%22);

Add colors to peer graph