private static string CreateHtmlJSONDataContentForClass(CSClass csClass) { List <CSClass> associations = csClass.GetAssociationsInList(CSClassController.GetAllCSClasses()); associations.Add(csClass); string htmlContent = "<script>\n" + "var tempdata = {\n" + "\"nodes\": [\n"; // Generate JSON data for each associated class of the csClass for (int i = 0; i < associations.Count; i++) { htmlContent += "{ \"id\": \"" + associations[i].Name + "\", \"group\": 1 }"; if (i == associations.Count - 1) { htmlContent += "\n"; } else { htmlContent += ",\n"; } } htmlContent += "],\n" + "\"links\": [\n"; // Generate JSON data for each association in each association of the csClass for (int i = 0; i < associations.Count; i++) { List <CSClass> innerAssociations = associations[i].GetAssociationsInList(associations); for (int j = 0; j < innerAssociations.Count; j++) { if (associations[i].GetAssociationsInList(associations).Count > 0) { htmlContent += "{\"source\": \"" + associations[i].Name + "\", \"target\": \"" + associations[j].Name + "\"}"; if (i == associations.Count - 1 && j == associations.Count) { htmlContent += "\n"; } else { htmlContent += ",\n"; } } } } htmlContent += "]\n" + "};\n" + "</script>"; return(htmlContent); }
private void ScatterPlot_ChartOnDataClick(object sender, ChartPoint p) { // Get the position of the item in the list, // since the scatter plot is populated in the same order as the list that it is based on. CSClass _CSClass = CSClassController.GetCSClassByIndex(p.Key); Window window = new Window { Title = _CSClass.Name, Content = new CSClassView(_CSClass) }; window.ShowDialog(); }
// Set the display properties of the class. public void SetProperties(CSClass _CSClass) { List <CSClass> associations = _CSClass.GetAssociationsInList(CSClassController.GetAllCSClasses()); TextBoxName.Text = _CSClass.Name; TextBoxLOC.Text = "LOC: " + _CSClass.CountLOC(); TextBoxAssociations.Text = "Associations: " + associations.Count; foreach (CSClass csClass in associations) { ListBoxItem lbi = new ListBoxItem { Content = csClass.Name }; lbi.Selected += AssociationListBoxItem_Click; AssociationsList.Items.Add(lbi); } }
//============================================================ // BACKEND //============================================================ private void ScatterPlot_PlotData() { CSClasses.Clear(); foreach (CSClass _CSClass in CSClassController.GetAllCSClasses()) { _CSClass.GetAssociationsInList(CSClassController.GetAllCSClasses()); _CSClass.CountLOC(); CSClasses.Add(_CSClass); } // Create a mapper so LiveCharts know how to plot our CSClass class var _CSClassVm = Mappers.Xy <CSClass>() .X(value => value.NumLOC) .Y(value => value.NumAssociations); // Save the mapper globally Charting.For <CSClass>(_CSClassVm); DataContext = this; }
// Link to new class window if an association is clicked. private void AssociationListBoxItem_Click(object sender, RoutedEventArgs e) { ListBoxItem lbi = e.Source as ListBoxItem; CSClass _CSClass = null; if (lbi != null) { _CSClass = CSClassController.GetCSClassByName(lbi.Content.ToString()); Window window = new Window { Title = _CSClass.Name, Content = new CSClassView(_CSClass) }; window.ShowDialog(); } else { Debug.WriteLine("Error getting clicked class."); } }
private void RowChart_PlotData(bool toggled) { ChartValues <int> Values = new ChartValues <int>(); SortedList = new List <CSClass>(); // Clear previous names so the old names dont remain and display the new values. Names.Clear(); // Clear axis values to remove old values. Histogram1.AxisX.Clear(); Axis axis = new Axis { Title = toggled ? "Associations" : "LOC" }; Histogram1.AxisX.Add(axis); // Get the correct sorted list from the controller. int numClasses = 25; SortedList = toggled ? CSClassController.GetTopCSClassesByAssociations(numClasses) : CSClassController.GetTopCSClassesByLOC(numClasses); Values.AddRange(toggled ? CSClassController.GetTopAssociations(numClasses) : CSClassController.GetTopLOC(numClasses)); Names.AddRange(toggled ? CSClassController.GetTopCSClassNamesByAssociations(numClasses) : CSClassController.GetTopCSClassNamesByLOC(numClasses)); if (RowSeries != null) { SeriesCollection.Remove(RowSeries); } RowSeries = new RowSeries { Title = toggled ? "Associations" : "LOC", Fill = (SolidColorBrush) new BrushConverter().ConvertFromString("#6df4e9"), Values = Values }; SeriesCollection.Add(RowSeries); Formatter = value => value.ToString("N"); DataContext = this; }
private void BTNLoadProject_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select Project Directory"; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CSClassController.GetCSFilesInDirectory(fbd.SelectedPath); RowChart_PlotData(false); ToggledAssociationsLOC = true; ScatterPlot_PlotData(); // If current view is Force Directed Graph, refresh the graph to show the loaded project. if (webBrowser.Visibility == Visibility.Visible) { BTNAssociations_Click(this, null); } } BTNScatterPlot.IsEnabled = true; BTNRowChart.IsEnabled = true; BTNForceDirectedGraph.IsEnabled = true; }