Пример #1
0
        private void AddGraph(RemoteGraph remoteGraph)
        {
            var hasDuplicate = (_graphManager.GetGraph(remoteGraph.id) != null);

            if (!hasDuplicate)
            {
                GraphMetaData graph;

                if (remoteGraph.isNewlyCreated)
                {
                    graph = _graphManager.SpawnGraph(remoteGraph.id);
                }
                else
                {
                    graph = _graphManager.CreateGraph(remoteGraph.id);
                }

                UpdateGraph(graph, remoteGraph);
                graph.Layout.Init(_surface.PixelToUnityCoord(remoteGraph.pos), -0.5f, 0.5f);
            }
            else
            {
                Debug.LogWarning("Graph " + remoteGraph.id + " already exists!");
            }
        }
Пример #2
0
        private void UpdateGraph(GraphMetaData g, RemoteGraph remoteGraph)
        {
            g.Graph.IsColored  = remoteGraph.isColored;
            g.Graph.IsSelected = remoteGraph.isSelected;
            g.Graph.IsFlipped  = remoteGraph.isFlipped;
            g.Graph.IsPickedUp = remoteGraph.isPickedUp;
            g.Graph.SortAxis   = remoteGraph.sortAxis;

            if (remoteGraph.sortIncline)
            {
                GraphMetaData prevGraph = null;

                foreach (var graph in _graphManager.GetAllGraphs())
                {
                    if (graph.Layout.Position < g.Layout.Position)
                    {
                        if (prevGraph == null || prevGraph.Layout.Position < graph.Layout.Position)
                        {
                            prevGraph = graph;
                        }
                    }
                }

                if (prevGraph)
                {
                    g.Graph.SortInclineHack(prevGraph.Graph.DimY, false);
                    g.Graph.SortIncline = true;
                }
            }
            else if (remoteGraph.sortInclineNextHack)
            {
                GraphMetaData nextGraph = null;

                foreach (var graph in _graphManager.GetAllGraphs())
                {
                    if (graph.Layout.Position > g.Layout.Position)
                    {
                        if (nextGraph == null || nextGraph.Layout.Position > graph.Layout.Position)
                        {
                            nextGraph = graph;
                        }
                    }
                }

                if (nextGraph)
                {
                    g.Graph.SortInclineHack(nextGraph.Graph.DimY, true);
                    g.Graph.SortIncline = true;
                }
            }
            else
            {
                g.Graph.SortIncline = false;
            }

            if (g.Graph.IsNewlyCreated && !remoteGraph.isNewlyCreated)
            {
                _graphManager.RegisterGraph(g);
            }

            g.Graph.IsNewlyCreated = remoteGraph.isNewlyCreated;

            var color        = new Color();
            var colorSuccess = ColorUtility.TryParseHtmlString(remoteGraph.color, out color);

            if (colorSuccess)
            {
                g.Graph.Color = color;
            }
            else
            {
                Debug.LogWarning("Could not parse color " + remoteGraph.color);
            }

            if (String.IsNullOrEmpty(remoteGraph.dimX))
            {
                g.Graph.DimX = null;
            }
            else if (g.Graph.DimX == null || g.Graph.DimX.Name != remoteGraph.dimX)
            {
                _dataProvider.LoadDataAsync(remoteGraph.dimX, (dim) =>
                {
                    g.Graph.DimX = dim;
                });
            }

            if (String.IsNullOrEmpty(remoteGraph.dimY))
            {
                g.Graph.DimY = null;
            }
            else if (g.Graph.DimY == null || g.Graph.DimY.Name != remoteGraph.dimY)
            {
                _dataProvider.LoadDataAsync(remoteGraph.dimY, (dim) =>
                {
                    g.Graph.DimY = dim;
                });
            }

            g.Layout.Position = _surface.PixelToUnityCoord(remoteGraph.pos);
            g.Layout.Width    = _surface.PixelToUnityCoord(remoteGraph.width);
        }