示例#1
0
 /// <summary>
 /// Sets the properties of the graph such as how many axis labels
 /// get shown and which color the line has
 /// </summary>
 /// <param name="graphWidget">The corresponding GraphWidget which holds the data such as the color</param>
 private void SetGraphProperties(GraphWidget graphWidget)
 {
     SetColor(graphWidget.name, graphWidget.color);
     SetNumLabelsShownX(graphWidget.numXLabels);
     SetNumLabelsShownY(graphWidget.numYLabels);
     titleText.text = graphWidget.name;
 }
示例#2
0
        /// <summary>
        /// Inserts a new datapoint and sets the properties of the graph
        /// </summary>
        /// <param name="widget">The corresponding GraphWidget which holds the data</param>
        public void UpdateView(Widget widget)
        {
            GraphWidget graphWidget = (GraphWidget)widget;

            SetGraphProperties(graphWidget);
            if (graphWidget.datapoints.Count > 0)
            {
                GraphWidget.Datapoint dp = graphWidget.datapoints[graphWidget.datapoints.Count - 1];
                graph.DataSource.AddPointToCategoryRealtime(graphWidget.name, dp.time, dp.data);
            }
        }
示例#3
0
        /// <summary>
        /// Create a new widget object from a given context.
        /// </summary>
        /// <param name="widgetContext">Context of new widget to create</param>
        /// <param name="existingWidgets">List of already existing widgets, to check for duplicate ids</param>
        /// <returns></returns>
        public Widget CreateWidgetFromContext(RosJsonMessage widgetContext, List <Widget> existingWidgets)
        {
            if (IsWidgetIdUnique(widgetContext, existingWidgets) == false)
            {
                Debug.LogWarning("duplicate ID: " + widgetContext.id + " in widget templates");
                return(null);
            }

            GameObject widgetGameObject = new GameObject();

            widgetGameObject.name = widgetContext.title;
            widgetGameObject.transform.SetParent(widgetParentGameObject.transform, false);

            switch (widgetContext.type)
            {
            case "Graph":
                GraphWidget graphWidget = widgetGameObject.AddComponent <GraphWidget>();
                graphWidget.Init(widgetContext, graphDesignPrefab);
                return(graphWidget);

            case "Toastr":
                ToastrWidget toastrWidget = widgetGameObject.AddComponent <ToastrWidget>();
                toastrWidget.Init(widgetContext, toastrDesignPrefab);
                return(toastrWidget);

            case "Icon":
                IconWidget iconWidget = widgetGameObject.AddComponent <IconWidget>();
                Dictionary <string, Texture2D> iconsForThisWidget = FindIconsWithName(widgetContext.icons);
                iconWidget.Init(widgetContext, iconDesignPrefab, iconsForThisWidget);
                return(iconWidget);

            case "Text":
                TextWidget textWidget = widgetGameObject.AddComponent <TextWidget>();
                textWidget.Init(widgetContext, textDesignPrefab);
                return(textWidget);

            default:
                Debug.LogWarning("Type not defined: " + widgetContext.type);
                Destroy(widgetGameObject);
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Creates a new graph object and initialises it with the properties given in its json file
        /// </summary>
        /// <param name="widget">The corresponding GraphWidget which holds the data</param>
        public override void Init(Widget widget)
        {
            gameObject.AddComponent <CurvedUI.CurvedUIVertexEffect>();
            GraphWidget graphWidget = (GraphWidget)widget;

            SetChildWidget(graphWidget.childWidget);

            GameObject graphObject = Instantiate(Factory.Instance.graphDesignPrefab);

            graphObject.transform.SetParent(transform);
            graphObject.transform.localScale    = Vector3.one * 0.7f;
            graphObject.transform.localPosition = Vector3.down * 45;

            InitGraphObject(graphWidget);
            SetGraphProperties(graphWidget);
            foreach (GraphWidget.Datapoint data in graphWidget.datapoints)
            {
                graph.DataSource.AddPointToCategoryRealtime(graphWidget.name, data.time,
                                                            data.data);
            }

            Init(widget.relativeChildPosition, widget.GetContext().unfoldChildDwellTimer, widget.GetContext().onActivate, widget.GetContext().onClose, widget.GetContext().xPositionOffset, widget.GetContext().yPositionOffset, widget.GetContext().scale);
        }
示例#5
0
        /// <summary>
        /// Sets properties of the newly created graph object and
        /// gets references to important scripts of the new object
        /// </summary>
        /// <param name="graphWidget">The corresponding GraphWidget which holds the data</param>
        private void InitGraphObject(GraphWidget graphWidget)
        {
            graph = GetComponentInChildren <GraphChart>();
            if (graph == null)
            {
                // the ChartGraph info is obtained via the inspector
                Debug.LogWarning("No GraphChart found! Place this script into a graph chart!");
                return;
            }

            lineMaterial = new Material(Shader.Find("Chart/Canvas/Solid"));
            graph.DataSource.AddCategory(graphWidget.name, lineMaterial, 20, new MaterialTiling(false, 20), null, true, null, 20);

            graph.AutoScrollHorizontally             = true;
            graph.DataSource.AutomaticHorizontalView = graphWidget.showCompleteHistory;
            if (verticalAxis == null)
            {
                verticalAxis          = graph.GetComponent <VerticalAxis>();
                horizontalAxis        = graph.GetComponent <HorizontalAxis>();
                horizontalAxis.Format = AxisFormat.Time;
            }
            // has to be changed if the graph gets other TextMeshProUGUI scripts
            titleText = GetComponentInChildren <TextMeshProUGUI>();
        }