// Use this for initialization void Start() { //Scale the graph graph.transform.localScale *= scale / 10.0f; // Set pointlist to results of function Reader with argument inputfile pointList = CSVReader.Read(directory, inputfile); //If the user wants the data flipped, here is where it is done if (flipData) { pointList = TransposeData.TransposeList(pointList); } // Declare list of strings, fill with keys (column names) columnList = new List <string>(pointList[1].Keys); //Create a graph legend and color the points if know categories if (knownCategories) { ColorGraph.createColor(pointList, categoryColumn); colorMap = ColorGraph.getColorMap(); } //Plot according to input data given if (coorData) { //Coordinate data does not have PCA run on it. //Converting the file into an appropriate format for plotting is enough double[][] pointCoor = convertTo2D(pointList); plot(pointCoor); } else { //Calculate PCA and project data onto three most significant components before plotting double[][] transformedPoints = calcPCAProject(); plot(transformedPoints); } createLegend(); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graph graph = new Graph(); //graph.addVertex("S"); //graph.addVertex("P"); //graph.addVertex("G"); //graph.addVertex("U"); //graph.addVertex("L"); //graph.addVertex("C"); //graph.addEdge("C", "L"); //graph.addEdge("C", "S"); //graph.addEdge("L", "C"); //graph.addEdge("L", "U"); //graph.addEdge("L", "P"); //graph.addEdge("S", "U"); //graph.addEdge("S", "C"); //graph.addEdge("S", "P"); //graph.addEdge("S", "G"); //graph.addEdge("U", "S"); //graph.addEdge("U", "L"); //graph.addEdge("U", "G"); //graph.addEdge("P", "S"); //graph.addEdge("P", "L"); //graph.addEdge("P", "G"); //graph.addEdge("G", "P"); //graph.addEdge("G", "S"); //graph.addEdge("G", "U"); //color.color(); //Graph graph = new Graph(); //ColorGraph color = new ColorGraph(graph); string[] student1 = { "maths", "english", "biology", "chemistry" }; string[] student2 = { "maths", "english", "compsci", "geography" }; string[] student3 = { "biology", "psychology", "geography", "spanish" }; string[] student4 = { "biology", "compsci", "history", "french" }; string[] student5 = { "english", "psychology", "compsci", "history" }; string[] student6 = { "psychology", "chemistry", "compsci", "french" }; string[] student7 = { "psychology", "geography", "history", "spanish" }; graph.addVertex("maths"); graph.addVertex("english"); graph.addVertex("biology"); graph.addVertex("chemistry"); graph.addVertex("compsci"); graph.addVertex("geography"); graph.addVertex("history"); graph.addVertex("french"); graph.addVertex("spanish"); graph.addVertex("psychology"); graph.addEdge(student1); graph.addEdge(student2); graph.addEdge(student3); graph.addEdge(student4); graph.addEdge(student5); graph.addEdge(student6); graph.addEdge(student7); ColorGraph color = new ColorGraph(graph); color.color(); // int totalcolors = color.ChromaticNumber; int n = graph.Nodes.Count; int width = n * 50; int height = n * 60; int xcentre = (width) / 2; int ycentre = (height) / 2; int radius = (int)(Math.Min(height, width) * 0.4); Graphics graphic = this.CreateGraphics(); Font font = new Font(Font, FontStyle.Bold); Brush[] colorss = { Brushes.Red, Brushes.Blue, Brushes.Yellow, Brushes.Green, Brushes.HotPink, Brushes.Brown }; for (int i = 0; i < n; i++) { float x1point = (float)(xcentre + 20 + radius * Math.Cos(i * 2 * Math.PI / n)); float y1point = (float)(xcentre + 20 - radius * Math.Sin(i * 2 * Math.PI / n)); for (int j = i + 1; j < n; j++) { float x2point = (float)(xcentre + 20 + radius * Math.Cos(j * 2 * Math.PI / n)); float y2point = (float)(xcentre + 20 - radius * Math.Sin(j * 2 * Math.PI / n)); if (graph.isAdjacent(graph.Nodes[i], graph.Nodes[j])) { graphic.DrawLine(Pens.Black, x1point, y1point, x2point, y2point); } } } for (int i = 0; i < n; i++) { int colornumber = graph.Nodes[i].Color; //Color color = Color.FromArgb(colornumber*10); float x1point = (float)(xcentre + radius * Math.Cos(i * 2 * Math.PI / n)) - 40; float y1point = (float)(xcentre - radius * Math.Sin(i * 2 * Math.PI / n)); graphic.FillEllipse(colorss[colornumber - 1], (float)(xcentre + radius * Math.Cos(i * 2 * Math.PI / n)), (float)(xcentre - radius * Math.Sin(i * 2 * Math.PI / n)), 30, 30); graphic.DrawString(graph.Nodes[i].Name, font, Brushes.Black, x1point, y1point - 10); } }