Ejemplo n.º 1
0
        /// <summary>
        /// Creates the type graph.
        /// </summary>
        /// <returns>The graph view model.</returns>
        public AGraphViewModel CreateTypeGraph()
        {
            GraphViewModel lGraph = new GraphViewModel();
            NodeViewModel  lNode0 = new TypeNodeViewModel(typeof(SampleClass));

            lGraph.AddNode(lNode0);

            NodeViewModel lNode1 = new TypeNodeViewModel(typeof(SampleClass1VeryTooMuchLong));

            lGraph.AddNode(lNode1);

            NodeViewModel lNode2 = new NodeViewModel();

            lNode2.DisplayString = "Empty node";
            lGraph.AddNode(lNode2);

            int i = 0;

            foreach (NodeViewModel lNode in lGraph.Nodes)
            {
                lNode.X = 300 * i;
                lNode.Y = 100 * i;
                i++;
            }

            ConnectionViewModel lConnectionViewModel = new ConnectionViewModel();

            lConnectionViewModel.Output = lGraph.Nodes.ElementAt(0).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Output);
            lConnectionViewModel.Input  = lGraph.Nodes.ElementAt(1).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Input);
            lGraph.AddConnection(lConnectionViewModel);

            return(lGraph);
        }
Ejemplo n.º 2
0
 private static void DeSelectAllNodes(GraphViewModel graphViewModel)
 {
     foreach (var node in graphViewModel.Nodes)
     {
         node.DeSelect();
     }
 }
Ejemplo n.º 3
0
        public bool TryLoadFromClipboard(GraphViewModel item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var text = Clipboard.GetText().Trim();

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            var csv    = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            var points = CsvConverter.ToPointList(csv);

            if (points.Count == 0)
            {
                return(false);
            }

            item.Points.Clear();

            foreach (var point in points)
            {
                item.Points.Add(point);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void PrintGraph()
        {
            Encoders.AddEncoder <JpegEncoder>();
            Encoders.AddEncoder <PngEncoder>();

            GraphViewModel graphVM = ViewModelLocator.GraphDataStatic;

            ExtendedImage extendedImage = graphVM.GraphToImage();

            Grid          printGrid          = new Grid();
            RowDefinition printRowDefinition = new RowDefinition();

            printGrid.RowDefinitions.Add(printRowDefinition);

            Image image = new Image()
            {
                Source = extendedImage.ToBitmap()
            };

            printGrid.Children.Add(image);

            PrintDocument printDocument = new PrintDocument();

            printDocument.PrintPage += (s, args) =>
            {
                args.PageVisual   = printGrid;
                args.HasMorePages = false;
            };
            printDocument.Print("SnagL Graph");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retrieves the graph and converts it into displayable data type.
        /// </summary>
        /// <returns>Graph view model.</returns>
        public async Task <GraphViewModel> GetGraphDataForDisplaying()
        {
            IEnumerable <SubTreeEntity> wholeTree = await this.nodeRepository.GetWholeTree();

            GraphViewModel viewModel = new GraphViewModel();

            if (wholeTree != null && wholeTree.Any())
            {
                viewModel.Nodes = wholeTree
                                  .Select(wte => new NodeViewModel
                {
                    Id    = wte.Root.Id,
                    Label = wte.Root.Label,
                    Type  = "Connected"
                });

                List <EdgeViewModel> listOfEdges = new List <EdgeViewModel>();
                wholeTree.ToList().ForEach(st =>
                {
                    foreach (var child in st.Children)
                    {
                        listOfEdges.Add(new EdgeViewModel {
                            Source = st.Root.Id, Target = child.Id, Label = "Connected1"
                        });
                    }
                });

                viewModel.Edges = listOfEdges;
            }

            return(viewModel);
        }
Ejemplo n.º 6
0
        public void TestMixedGraphViewModel()
        {
            var graphViewModel = new GraphViewModel()
            {
                Begin   = new DateTime(2019, 01, 01, 12, 0, 0, DateTimeKind.Utc),
                Spacing = TimeSpan.FromMinutes(1),
                Name    = "test",
                Format  = "#.00 Unit",
                Points  = new dynamic[] { 1, 2, 5d, 4f, "23" }
            };

            Assert.Equal(new DateTime(2019, 01, 01, 12, 0, 0, DateTimeKind.Utc), graphViewModel.Begin);
            Assert.Equal(TimeSpan.FromMinutes(1), graphViewModel.Spacing);
            Assert.Equal("test", graphViewModel.Name);
            Assert.Equal("#.00 Unit", graphViewModel.Format);
            Assert.Equal(new dynamic[] { 1, 2, 5d, 4f, "23" }, graphViewModel.Points);

            Assert.Equal(1546344000000, graphViewModel.BeginUnixTimestamp);
            Assert.Equal(60000, graphViewModel.SpacingMillis);

            Assert.Equal(new dynamic[] {
                new dynamic[] { 1, 1546344000000 },
                new dynamic[] { 2, 1546344060000 },
                new dynamic[] { 5d, 1546344120000 },
                new dynamic[] { 4f, 1546344180000 },
                new dynamic[] { "23", 1546344240000 }
            }, graphViewModel.TimestampedPoints());
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public sealed override async Task <bool> Initialize()
        {
            sourceResolver = ServiceProvider.Get <IScriptSourceCodeResolver>();
            if (sourceResolver.LatestCompilation == null)
            {
                // Wait for initial compilation to be done before continuing initialization
                var          compilationReady  = new TaskCompletionSource <bool>();
                EventHandler compilationChange = (sender, args) => compilationReady.TrySetResult(true);

                sourceResolver.LatestCompilationChanged += compilationChange;
                await compilationReady.Task;
                sourceResolver.LatestCompilationChanged -= compilationChange;
            }

            properties = GraphViewModel.Create(ServiceProvider, new[] { new SinglePropertyProvider(propertiesNode.Target) });

            // Since Roslyn compilation is ready, regenerate slots
            await RegenerateSlots();

            // Regenerate slot on next compilations
            sourceResolver.LatestCompilationChanged += CompilationUpdated;

            // Listen to changes
            Session.AssetPropertiesChanged += Session_AssetPropertiesChanged;

            // Select first function
            SelectedMethod = Methods.FirstOrDefault();

            // Trigger initial compilation
            TriggerBackgroundCompilation().Forget();

            return(true);
        }
Ejemplo n.º 8
0
        public static GraphViewModel Get(Graph value)
        {
            var gvm = new GraphViewModel();

            if (value.East != null)
            {
                gvm.East = Get(value.East);
            }

            if (value.West != null)
            {
                gvm.West = Get(value.West);
            }

            if (value.North != null)
            {
                gvm.North = Get(value.North);
            }

            if (value.South != null)
            {
                gvm.South = Get(value.South);
            }

            return(gvm);
        }
Ejemplo n.º 9
0
 public Graph()
 {
     InitializeComponent();
     plotInfo       = new GraphViewModel();
     BindingContext = plotInfo;
     MakePlot();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Delegate called when the "Add" button is clicked.
        /// </summary>
        /// <param name="pSender">The button sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnAddButtonClicked(object pSender, RoutedEventArgs pEventArgs)
        {
            GraphViewModel lRootViewModel = this.GraphView.DataContext as GraphViewModel;
            NodeViewModel  lNode1         = new TypeNodeViewModel(typeof(SampleClass1VeryTooMuchLong));

            lRootViewModel.AddNode(lNode1);
        }
Ejemplo n.º 11
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            myViewModel = BindingContext as GraphViewModel;
            if (myViewModel != null)
            {
                var startDate = DateTime.Now.AddDays(-10);
                var endDate   = DateTime.Now;

                var minValue = DateTimeAxis.ToDouble(startDate);
                var maxValue = DateTimeAxis.ToDouble(endDate);

                myViewModel.PlotModel = new PlotModel
                {
                    Title = "Line"
                };
                CreatePlot();
                myViewModel.PlotModel.Axes.Add(new DateTimeAxis {
                    Position = AxisPosition.Bottom, Minimum = minValue, Maximum = maxValue, StringFormat = "M/d"
                });

                //myViewModel.OnAppearing();
            }
        }
        public ActionResult NewGraph(string graphType, string label, double[] dataPoint)
        {
            var model = new GraphViewModel(graphType);

            fillModelData(model, label);
            return(PartialView("EditorTemplates/GraphViewModel", model));
        }
        public async Task <IEnumerable <TransactionView> > Tables(GraphViewModel formModel)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");

            string date1 = formModel.Date1.ToShortDateString();
            string date2 = formModel.Date2.ToShortDateString();

            HttpResponseMessage response;

            if (formModel.CustomerID == 0)
            {
                response = await WebApi.InitializeClient().GetAsync($"api/transactions/intable?date1={date1}&date2={date2}");
            }
            else
            {
                int id = formModel.CustomerID;
                response = await WebApi.InitializeClient().GetAsync($"api/transactions/intablewithid?id={id}&date1={date1}&date2={date2}");
            }

            if (!response.IsSuccessStatusCode)
            {
                return(new List <TransactionView>());
            }

            //gets the results of the transdatecount objs as JsonString
            var result = response.Content.ReadAsStringAsync().Result;

            //converts it to objects again
            var transactions = JsonConvert.DeserializeObject <List <TransactionView> >(result);

            return(transactions);
        }
Ejemplo n.º 14
0
        public async Task <IEnumerable <TransDateCount> > BarGraph(GraphViewModel formModel)
        {
            string date1 = formModel.Date1.ToString("dd-MM-yyyy hh:mm:ss");
            string date2 = formModel.Date2.ToString("dd-MM-yyyy hh:mm:ss");

            HttpResponseMessage response;

            if (formModel.CustomerID == 0)
            {
                response = await WebApi.InitializeClient().GetAsync($"api/transactions/inbar?date1={date1}&date2={date2}");
            }
            else
            {
                int id = formModel.CustomerID;
                response = await WebApi.InitializeClient().GetAsync($"api/transactions/inbarwithid?id={id}&date1={date1}&date2={date2}");
            }

            if (!response.IsSuccessStatusCode)
            {
                return(new List <TransDateCount>());
            }

            //gets the results of the transdatecount objs as JsonString
            var result = response.Content.ReadAsStringAsync().Result;

            //converts it to objects again
            var transPDay = JsonConvert.DeserializeObject <List <TransDateCount> >(result);

            foreach (TransDateCount trans in transPDay)
            {
                trans.Date = DateTime.Parse(trans.Date.ToString("dd/MM/yy"));
            }

            return(transPDay);
        }
Ejemplo n.º 15
0
        public bool HasChanged(GraphViewModel graph)
        {
            if (graph == null)
            {
                throw new ArgumentException(nameof(graph));
            }

            if (!_savedStates.TryGetValue(graph.Id, out var savedState))
            {
                throw new NotSupportedException();
            }

            if (savedState.Name != graph.Name ||
                savedState.Points.Length != graph.Points.Count)
            {
                return(true);
            }

            var pointCount = graph.Points.Count;

            for (var i = 0; i < pointCount; i++)
            {
                var point1 = savedState.Points[i];
                var point2 = graph.Points[i];

                if (point1.X != point2.X || point1.Y != point2.Y)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 16
0
        public void TestGenericGraphViewModel()
        {
            var span       = new TimeSeriesSpan(new DateTime(2019, 01, 01, 12, 0, 0, DateTimeKind.Utc), TimeSeriesSpan.Spacing.Spacing1Min, 5);
            var timeseries = new TimeSeries <int>(span);

            timeseries[2] = 23;
            timeseries[4] = 42;

            var graphViewModel = new GraphViewModel <int>(timeseries, "test", "#.00 Unit");

            Assert.Equal(new DateTime(2019, 01, 01, 12, 2, 0, DateTimeKind.Utc), graphViewModel.Begin);
            Assert.Equal(TimeSpan.FromMinutes(1), graphViewModel.Spacing);
            Assert.Equal("test", graphViewModel.Name);
            Assert.Equal("#.00 Unit", graphViewModel.Format);
            Assert.Equal(new dynamic?[] { 23, null, 42 }, graphViewModel.Points);

            Assert.Equal(1546344120000, graphViewModel.BeginUnixTimestamp);
            Assert.Equal(60000, graphViewModel.SpacingMillis);

            Assert.Equal(new dynamic[] {
                new dynamic?[] { 23, 1546344120000 },
                new dynamic?[] { null, 1546344180000 },
                new dynamic?[] { 42, 1546344240000 }
            }, graphViewModel.TimestampedPoints());
        }
Ejemplo n.º 17
0
        public ActionResult FindRoles(GraphViewModel graphViewModel)
        {
            try
            {
                if (graphViewModel.Graph.Edges.Count != 0 && graphViewModel.Graph.GraphSet.Count == 0)
                {
                    foreach (Edge <UserDto> edge in graphViewModel.Graph.Edges)
                    {
                        graphViewModel.Graph.CreateGraphSet(edge);
                    }
                }

                FetchItemServiceResponse <Graph <UserDto> > response = _graphService.DetectRolesInGraph(graphViewModel.Graph);

                if (response.Succeeded)
                {
                    graphViewModel.Graph = response.Item;
                    FetchItemServiceResponse <SSRMRolesDto> ssrmRolesCounts = _graphService.FetchSSRMRolesCounts(graphViewModel.Graph);
                    graphViewModel.SsrmRolesDto = ssrmRolesCounts.Item;

                    List <NodeDto> nodes = graphViewModel.Graph.Nodes.Select(x => new NodeDto()
                    {
                        id    = x.Id,
                        label = x.NodeElement.Name,
                        group = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).group),
                        title = $"Node degree: {x.Degree}",
                        size  = GetNodeSizeBasedOnRole(x),
                        shape = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).shape)
                    }).ToList();
                    List <EdgeDto> edges = graphViewModel.Graph.Edges.Select(x => new EdgeDto()
                    {
                        from = x.Node1.Id, to = x.Node2.Id
                    }).ToList();

                    if (nodes.FirstOrDefault(x => x.id == graphViewModel.SelectedEgoId) != null)
                    {
                        nodes.First(x => x.id == graphViewModel.SelectedEgoId).size = 25;
                    }

                    foreach (Node <UserDto> node in graphViewModel.Graph.Nodes.Where(x => x.Role != 0))
                    {
                        nodes.First(x => x.id == node.Id).shape = GetNodeShapeBasedOnRole(node);
                    }
                    graphViewModel.Graph.SetCommunityNodes();
                    GraphDto graphDto = new GraphDto
                    {
                        nodes = nodes,
                        edges = edges
                    };
                    graphViewModel.RolesDetected = true;
                    graphViewModel.GraphDto      = graphDto;
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }
            return(View("GraphView_partial", graphViewModel));
        }
        public async Task <IActionResult> GetByBirthDate(DateTime birthDate)
        {
            var results = await _graphPersonService.GetPersonGraphByBirthDateAsync(birthDate);

            var model = new GraphViewModel(results);

            return(Ok(model));
        }
        public async Task <IActionResult> GetByBirthYear(int year)
        {
            var results = await _graphPersonService.GetPersonGraphByBirthYearAsync(year);

            var model = new GraphViewModel(results);

            return(Ok(model));
        }
        public async Task <IActionResult> GetFilmography(string name)
        {
            var results = await _graphPersonService.GetPersonGraphByNameAsync(name);

            var model = new GraphViewModel(results);

            return(Ok(model));
        }
Ejemplo n.º 21
0
 public GraphView(GraphViewModel graphViewModel)
 {
     InitializeComponent();
     ShowCloseButton = false;
     AutoHide        = false;
     GraphViewModel  = graphViewModel;
     DataContext     = GraphViewModel;
 }
Ejemplo n.º 22
0
        public void TestMainViewModel()
        {
            GraphViewModel gvm = new GraphViewModel();

            gvm.YearsModel = new YearsModel();
            gvm.YearsModel.SelectedYear = 2003;
            Assert.IsTrue(gvm.YearsModel.SelectedYear == 2003);
        }
Ejemplo n.º 23
0
        public ActionResult FindCommunities(GraphViewModel graphViewModel)
        {
            try
            {
                if (graphViewModel.Graph.Edges.Count != 0)
                {
                    foreach (Edge <UserDto> edge in graphViewModel.Graph.Edges)
                    {
                        graphViewModel.Graph.CreateGraphSet(edge);
                    }
                }

                if (graphViewModel.Graph.Communities.Count > 0)
                {
                    graphViewModel.Graph.Communities = new HashSet <Community <UserDto> >();
                }

                Dictionary <int, int>         partition   = LouvainCommunity.BestPartition(graphViewModel.Graph);
                Dictionary <int, List <int> > communities = new Dictionary <int, List <int> >();
                foreach (KeyValuePair <int, int> kvp in partition)
                {
                    List <int> nodeset;
                    if (!communities.TryGetValue(kvp.Value, out nodeset))
                    {
                        nodeset = communities[kvp.Value] = new List <int>();
                    }
                    nodeset.Add(kvp.Key);
                }
                graphViewModel.Graph.SetCommunities(communities);

                graphViewModel.Graph.SetDegrees();
                List <NodeDto> nodes = graphViewModel.Graph.Nodes.Select(x => new NodeDto()
                {
                    id    = x.Id,
                    label = x.NodeElement.Name,
                    group = x.CommunityId,
                    title = $"Node degree: {x.Degree}",
                    size  = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).size)
                }).ToList();
                List <EdgeDto> edges = graphViewModel.Graph.Edges.Select(x => new EdgeDto()
                {
                    from = x.Node1.Id, to = x.Node2.Id
                }).ToList();

                GraphDto graphDto = new GraphDto
                {
                    nodes = nodes,
                    edges = edges
                };

                graphViewModel.GraphDto = graphDto;
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }
            return(View("GraphView_partial", graphViewModel));
        }
        public ActionResult WidgetContentTwo()
        {
            System.Threading.Thread.Sleep(1000); // Fake waiting time to show javascript spinner
            var model = new GraphViewModel(GraphViewModel.PIE);

            model.SingleSeries.Add("pencils", 37.5);
            model.SingleSeries.Add("pens", 62.5);
            return(PartialView("EditorTemplates/GraphViewModel", model));
        }
        public async Task <IActionResult> GetDegreesOfSeparation(string from, string to)
        {
            var results =
                await _graphPersonService.GetDegreesOfSeparationGraph(new Person { Name = from }, new Person { Name = to });

            var model = new GraphViewModel(results);

            return(Ok(model));
        }
Ejemplo n.º 26
0
        public void ThenTheScopeOfTheGraphIs(string scope)
        {
            Enum.TryParse(scope, true, out GraphViewScope expected)
            .Should().BeTrue();
            scenarioContext.WaitForSilentPulse();
            GraphViewModel viewModel = scenarioContext.Get <GraphViewModel>(StringConstants.GraphViewModelCreated);

            viewModel.Scope.Should().Be(expected);
        }
Ejemplo n.º 27
0
 public AssetNodeViewModel(GraphViewModel ownerViewModel, NodeViewModel parent, string baseName, Type nodeType, List <INodePresenter> nodePresenters)
     : base(ownerViewModel, parent, baseName, nodeType, nodePresenters)
 {
     foreach (var nodePresenter in NodePresenters)
     {
         nodePresenter.OverrideChanging += OverrideChanging;
         nodePresenter.OverrideChanged  += OverrideChanged;
     }
 }
        public void WhenISwitchTheGraphViewScopeTo(string newScope)
        {
            Enum.TryParse(newScope, true, out GraphViewScope scope)
            .Should().BeTrue();
            scenarioContext.WaitForSilentPulse();
            GraphViewModel viewModel = scenarioContext.Get <GraphViewModel>(StringConstants.GraphViewModelCreated);

            viewModel.Scope = scope;
        }
Ejemplo n.º 29
0
        public Graphs()
        {
            InitializeComponent();

            DataContextChanged += (s, e) =>
            {
                VM = DataContext as GraphViewModel;
            };
        }
Ejemplo n.º 30
0
        public GraphWindow()
        {
            InitializeComponent();
            GraphView   = new GraphViewModel();
            DataContext = GraphView;

            ShowWindowCommand = new Command(ShowWindow);

            this.Closing += GraphWindow_Closing;
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Provides a deterministic way to create the ViewModelPropertyName property
 /// </summary>
 public static void CreateGraphData()
 {
     if (graphData == null)
         {
             graphData = new GraphViewModel();
         }
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Provides a deterministic way to delete the ViewModelPropertyName property
 /// </summary>
 public static void ClearGraphData()
 {
     graphData.Cleanup();
         graphData = null;
 }