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 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 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); }
private void _projectService_ProjectOpened(object sender, EventArgs e) { Graph = _projectService.AreAllVarietiesCompared ? _graphService.GenerateHierarchicalGraph(_graphType, _clusteringMethod, _similarityMetric) : null; }