// Copyright 2010 by Mary McGlohon
// Carnegie Mellon University
// mmcgloho@cs.cmu.edu


import java.util.ArrayList;

public class CascadeViz {


    // Get the graphviz string for a single cascade, which will be used
    // for greater purpose.
    // cascadeName will be for the box and mylabel will be the label for it.
    public static String graphVizString(Cascade c,
                                 String cascadeName,
                                 String mylabel) {
        ArrayList<CascadeNode> nodes = c.getNodes();
	String mystring = "";
	mystring = mystring + "subgraph cluster_" + cascadeName + "{\n";
	// set up the nodes
        
	for (int i = 0; i < nodes.size(); ++i) {
	    CascadeNode cn = nodes.get(i);
            if (c.useAuthors()) {
                String colorstring = getColor(cn.author);
                mystring = mystring + cascadeName + cn.id +
                    " [label = \"" + cn.id + "\""+
                    ",color=" + colorstring + ",style=filled];\n";
            }
            else {
                mystring = mystring + cascadeName + cn.id +
                    " [label = \"" + cn.id + "\"];\n";
            }
	}
	// set up the edges
	for (int i = 0; i < nodes.size(); i++) {
	    CascadeNode cn = nodes.get(i);
	    if (!cn.isOrphan()) {
		for (int p = 0; p < cn.parents.size(); p++) {
		    long parentid = cn.parents.get(p).id;
		    mystring = mystring + cascadeName + parentid +"->" +
			cascadeName + cn.id+" ;\n";
		}
	    }
	}
	mystring = mystring + "label = \""+ mylabel + "\";\n";
	mystring = mystring + "}\n";
	return mystring;
    }
    

    // used for authored cascades
    static String getColor(int author) {
        String colorstring = "white";
        switch(author) {
        case 1:
            colorstring= "blue"; break;
        case 2:
            colorstring = "green"; break;
        case 3:
            colorstring = "red"; break;
        case 4:
            colorstring = "yellow"; break;
        case 5:
            colorstring = "aquamarine"; break;
        case 6:
            colorstring = "antiquewhite"; break;
        case 7:
            colorstring = "aliceblue"; break;
        case 8:
            colorstring = "azure"; break;
        case 9:
            colorstring = "darkgreen"; break;
        case 10:
            colorstring = "cadetblue"; break;
        default:
            colorstring= "white"; break;
        }
        return colorstring;
    }


}