public HierarchicalGraphViewModel(IProjectService projectService, IImageExportService exportService, IGraphService graphService) : base("Hierarchical Graph") { _projectService = projectService; _exportService = exportService; _graphService = graphService; _projectService.ProjectOpened += _projectService_ProjectOpened; Messenger.Default.Register<ComparisonPerformedMessage>(this, msg => { if (_projectService.AreAllVarietiesCompared) Graph = _graphService.GenerateHierarchicalGraph(_graphType, _clusteringMethod, _similarityMetric); }); Messenger.Default.Register<DomainModelChangedMessage>(this, msg => { if (msg.AffectsComparison) Graph = null; }); Messenger.Default.Register<PerformingComparisonMessage>(this, msg => Graph = null); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Graph type", new TaskAreaCommandViewModel("Dendrogram", new RelayCommand(() => GraphType = HierarchicalGraphType.Dendrogram)), new TaskAreaCommandViewModel("Tree", new RelayCommand(() => GraphType = HierarchicalGraphType.Tree)))); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Clustering method", new TaskAreaCommandViewModel("UPGMA", new RelayCommand(() => ClusteringMethod = ClusteringMethod.Upgma)), new TaskAreaCommandViewModel("Neighbor-joining", new RelayCommand(() => ClusteringMethod = ClusteringMethod.NeighborJoining)))); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Similarity metric", new TaskAreaCommandViewModel("Lexical", new RelayCommand(() => SimilarityMetric = SimilarityMetric.Lexical)), new TaskAreaCommandViewModel("Phonetic", new RelayCommand(() => SimilarityMetric = SimilarityMetric.Phonetic)))); TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks", new TaskAreaCommandViewModel("Export graph", new RelayCommand(Export, CanExport)))); _graphType = HierarchicalGraphType.Dendrogram; }
public bool ExportCurrentHierarchicalGraph(object ownerViewModel, HierarchicalGraphType type) { FileDialogResult result = _dialogService.ShowSaveFileDialog("Export Hierarchical Graph", ownerViewModel, new FileType("PNG image", ".png")); if (result.IsValid) { FrameworkElement graphLayout = null; switch (type) { case HierarchicalGraphType.Tree: graphLayout = System.Windows.Application.Current.MainWindow.FindVisualChild <HierarchicalGraphLayout>(); break; case HierarchicalGraphType.Dendrogram: graphLayout = System.Windows.Application.Current.MainWindow.FindVisualChild <DendrogramLayout>(); break; } if (graphLayout == null) { throw new InvalidOperationException(); } SaveElement(graphLayout, result.FileName, null); return(true); } return(false); }
public HierarchicalGraphViewModel(IProjectService projectService, IImageExportService exportService, IGraphService graphService) : base("Hierarchical Graph") { _projectService = projectService; _exportService = exportService; _graphService = graphService; _projectService.ProjectOpened += _projectService_ProjectOpened; Messenger.Default.Register <ComparisonPerformedMessage>(this, msg => Graph = _graphService.GenerateHierarchicalGraph(_graphType, _clusteringMethod, _similarityMetric)); Messenger.Default.Register <DomainModelChangedMessage>(this, msg => { if (msg.AffectsComparison) { Graph = null; } }); Messenger.Default.Register <PerformingComparisonMessage>(this, msg => Graph = null); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Graph type", new TaskAreaCommandViewModel("Dendrogram", new RelayCommand(() => GraphType = HierarchicalGraphType.Dendrogram)), new TaskAreaCommandViewModel("Tree", new RelayCommand(() => GraphType = HierarchicalGraphType.Tree)))); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Clustering method", new TaskAreaCommandViewModel("UPGMA", new RelayCommand(() => ClusteringMethod = ClusteringMethod.Upgma)), new TaskAreaCommandViewModel("Neighbor-joining", new RelayCommand(() => ClusteringMethod = ClusteringMethod.NeighborJoining)))); TaskAreas.Add(new TaskAreaCommandGroupViewModel("Similarity metric", new TaskAreaCommandViewModel("Lexical", new RelayCommand(() => SimilarityMetric = SimilarityMetric.Lexical)), new TaskAreaCommandViewModel("Phonetic", new RelayCommand(() => SimilarityMetric = SimilarityMetric.Phonetic)))); TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks", new TaskAreaCommandViewModel("Export this graph", new RelayCommand(Export)))); _graphType = HierarchicalGraphType.Dendrogram; }
public bool ExportHierarchicalGraph(object ownerViewModel, HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { FileDialogResult result = _dialogService.ShowSaveFileDialog("Export Hierarchical Graph", ownerViewModel, new FileType("PNG image", ".png")); if (result.IsValid) { IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> graph = _graphService.GenerateHierarchicalGraph(graphType, clusteringMethod, similarityMetric); Action <double> scaleUpdate = null; FrameworkElement graphLayout = null; switch (graphType) { case HierarchicalGraphType.Dendrogram: graphLayout = new DendrogramLayout { Graph = graph, Background = Brushes.White }; break; case HierarchicalGraphType.Tree: var hgl = new HierarchicalGraphLayout { IsAnimationEnabled = false, CreationTransition = null, DestructionTransition = null, LayoutAlgorithmType = "RadialTree", LayoutParameters = new RadialTreeLayoutParameters { BranchLengthScaling = BranchLengthScaling.MinimizeLabelOverlapMinimum }, Graph = graph, Background = Brushes.White, ScaleLabelsToZoom = 1.0 }; hgl.Resources[typeof(VertexControl)] = System.Windows.Application.Current.Resources["HierarchicalVertexControlStyle"]; hgl.Resources[typeof(EdgeControl)] = System.Windows.Application.Current.Resources["HierarchicalEdgeControlStyle"]; graphLayout = hgl; scaleUpdate = scale => hgl.ScaleLabelsToZoom = scale; break; } Debug.Assert(graphLayout != null); SaveElement(graphLayout, result.FileName, scaleUpdate); return(true); } return(false); }
public IBidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { switch (clusteringMethod) { case ClusteringMethod.Upgma: Func<Variety, Variety, double> upgmaGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var upgma = new UpgmaClusterer<Variety>(upgmaGetDistance); IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties); return BuildHierarchicalGraph(upgmaTree); case ClusteringMethod.NeighborJoining: Func<Variety, Variety, double> njGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var nj = new NeighborJoiningClusterer<Variety>(njGetDistance); IUndirectedGraph<Cluster<Variety>, ClusterEdge<Variety>> njTree = nj.GenerateClusters(_projectService.Project.Varieties); switch (graphType) { case HierarchicalGraphType.Dendrogram: IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> rootedTree = njTree.ToRootedTree(); return BuildHierarchicalGraph(rootedTree); case HierarchicalGraphType.Tree: return BuildHierarchicalGraph(njTree); } break; } return null; }
public IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { switch (clusteringMethod) { case ClusteringMethod.Upgma: Func <Variety, Variety, double> upgmaGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var upgma = new UpgmaClusterer <Variety>(upgmaGetDistance); IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties); return(BuildHierarchicalGraph(upgmaTree)); case ClusteringMethod.NeighborJoining: Func <Variety, Variety, double> njGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var nj = new NeighborJoiningClusterer <Variety>(njGetDistance); IUndirectedGraph <Cluster <Variety>, ClusterEdge <Variety> > njTree = nj.GenerateClusters(_projectService.Project.Varieties); switch (graphType) { case HierarchicalGraphType.Dendrogram: IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > rootedTree = njTree.ToRootedTree(); return(BuildHierarchicalGraph(rootedTree)); case HierarchicalGraphType.Tree: return(BuildHierarchicalGraph(njTree)); } break; } return(null); }