private void button2_Click(object sender, EventArgs e) { //upload button if (!(textBox1.Text.Equals(""))) { //for (int i = 0; i < textData.getTotalPeople(); i++) graph.RemoveNode(graph.FindNode(textData.getPerson(i))); //g.Clear(); textData = new TextHandler(); prevAccount = ""; prevExplore = ""; comboBox1.Items.Clear(); comboBox2.Items.Clear(); textData.Load(textBox1.Text); graph = new Microsoft.Msagl.Drawing.Graph("graph"); g = new GraphKita(textData); for (int i = 0; i < textData.getTotalConnection(); i++) { g.NewEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]); var edge = graph.AddEdge(textData.getFriendConnection(i)[0], textData.getFriendConnection(i)[1]); edge.Attr.ArrowheadAtSource = Microsoft.Msagl.Drawing.ArrowStyle.None; edge.Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; } for (int i = 0; i < textData.getTotalPeople(); i++) { comboBox1.Items.Add(textData.getPerson(i)); comboBox2.Items.Add(textData.getPerson(i)); } if ((textData.getTotalPeople() == 1)) { comboBox1.SelectedItem = (textData.getPerson(0)); comboBox2.SelectedItem = (textData.getPerson(0)); button3.Enabled = true; } else if ((textData.getTotalPeople() > 1)) { comboBox1.SelectedItem = (textData.getPerson(0)); comboBox2.SelectedItem = (textData.getPerson(1)); comboBox1.Items.Remove(comboBox2.SelectedItem.ToString()); comboBox2.Items.Remove(comboBox1.SelectedItem.ToString()); comboBox1.Enabled = true; comboBox2.Enabled = true; button3.Enabled = true; } printGraph(); instantSearch(); } else { Console.WriteLine("Path file tidak valid"); } }
private List <List <string> > pointingTo; //list of list of string, yang tiap index nya adalah node-node yg ditunjuk oleh node bersangkutan //Misal //nodes = ["A","B"] //pointingTo = [ ["A"], ["B"], ["C"] ] //Berarti, node A menunjuk ke node B dan C, dst //Maaf kalau keliru istilah. idgaf about istilah public GraphKita(TextHandler handler) { //ctor with size nodes = new List <string>(); pointingTo = new List <List <string> >(); totalnode = handler.getTotalPeople(); for (int i = 0; i < handler.getTotalPeople(); i++) { pointingTo.Add(new List <string>()); pointingTo[i].Add(handler.getPerson(i)); nodes.Add(handler.getPerson(i)); //Console.WriteLine(pointingTo[i][0]); } //Console.WriteLine(pointingTo.Count); }
private void instantSearch() { //no button, just instant search if (!(comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)) { for (int i = 0; i < textData.getTotalPeople(); i++) { graph.FindNode(textData.getPerson(i)).Attr.FillColor = Microsoft.Msagl.Drawing.Color.White; graph.FindNode(textData.getPerson(i)).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Octagon; } List <string> test = g.SearchPath(comboBox1.SelectedItem.ToString(), comboBox2.SelectedItem.ToString(), method); textBox2.Text = "Nama akun: " + comboBox1.SelectedItem.ToString() + " dan " + comboBox2.SelectedItem.ToString() + "\r\n"; if (test[test.Count - 1] != "") { if (test.Count == 1) { textBox2.Text += ("1st - degree connection\r\n"); } else if (test.Count == 2) { textBox2.Text += ("2nd - degree connection\r\n"); } else if (test.Count == 3) { textBox2.Text += ("3rd - degree connection\r\n"); } else { textBox2.Text += (test.Count + "th - degree connection\r\n"); } for (int i = 0; i < test.Count; i++) { graph.FindNode(test[i]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; if (i == 0) { graph.FindNode(test[i]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue; } textBox2.Text += (test[i]); if (i != test.Count - 1) { textBox2.Text += (" → "); } } graph.FindNode(test[0]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; graph.FindNode(test[test.Count - 1]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; } else { textBox2.Text += ("tidak ada relasi pada kedua akun\r\n"); graph.FindNode(test[0]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightBlue; graph.FindNode(test[test.Count - 2]).Attr.FillColor = Microsoft.Msagl.Drawing.Color.Red; graph.FindNode(test[0]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; graph.FindNode(test[test.Count - 2]).Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; } printGraph(); } }