Example #1
0
            // Instantiate Chart Holder
            public GameObject InstantiateInteractiveChartHolder(Transform parent, String name, List <int> markerPointIndices, List <Color> markerPointColors)
            {
                ChartObjectFactory      chartFactory         = FindObjectOfType <ChartObjectFactory>();
                GameObject              chart                = chartFactory.InstantiateChartHolder(parent, name);
                MarkerInteractableChart interactiveComponent = chart.AddComponent <MarkerInteractableChart>();

                interactiveComponent.MarkerIndexList = markerPointIndices;
                interactiveComponent.MarkerColorList = markerPointColors;
                return(chart);
            }
Example #2
0
    // Use this for initialization
    void Start()
    {
        // Define x and y test data
        int   numOfSamples = 50;
        float spacing      = 0.5f;

        xData   = new float[numOfSamples];
        sinData = new float[numOfSamples];
        cosData = new float[numOfSamples];
        for (int i = 0; i < numOfSamples; ++i)
        {
            float x = i * spacing;
            xData[i]   = x;
            sinData[i] = Mathf.Sin(x);
            cosData[i] = Mathf.Cos(x);
        }

        // Chart factory
        ChartObjectFactory chartHolderFactory = FindObjectOfType <ChartObjectFactory>();

        // Instantiate chart game object
        chart = chartHolderFactory.InstantiateChartHolder(this.gameObject.transform, "ChartHolder");

        // Add Interactable component to the chart
        MarkerInteractableChart interactableComponent = chart.AddComponent <MarkerInteractableChart>();

        interactableComponent.MarkerIndexList.Add(0);         // marker at position X: 0
        interactableComponent.MarkerColorList.Add(Color.red); // marker color: red

        UpdateChartDisplay();

        // Configure slider
        slider          = GameObject.FindObjectOfType <Slider>();
        slider.minValue = 0;
        slider.maxValue = numOfSamples - 1;
        slider.value    = 0;
        slider.onValueChanged.AddListener(sliderChangedAction);
    }
Example #3
0
            public void UpdateChart()
            {
                // Destroy chart line container
                DestroyImmediate(this.gameObject.transform.Find("Lines").gameObject);

                // Create new chart line container
                GameObject lineContainer = new GameObject("Lines");

                lineContainer.transform.parent = this.gameObject.transform;

                // Get text game object containing tick text meshes
                Transform textGroup = this.gameObject.transform.Find("Layout").Find("Text");

                // Set default chart bounds on tick text meshes
                textGroup.Find("XFirstValue").GetComponent <TextMesh>().text = "";
                textGroup.Find("XLastValue").GetComponent <TextMesh>().text  = "";
                textGroup.Find("YFirstValue").GetComponent <TextMesh>().text = "";
                textGroup.Find("YLastValue").GetComponent <TextMesh>().text  = "";

                // Set default chart units
                textGroup.Find("XUnit").GetComponent <TextMesh>().text = "";
                textGroup.Find("YUnit").GetComponent <TextMesh>().text = "";

                if (X.Length == 0 || YSet.Count == 0)
                {
                    return;
                }

                // Get minimum and maximum values in x array
                float minX = X.Min();
                float maxX = X.Max();

                // Define chart bounds in x axis
                float[] xBounds = new float[] { minX, maxX };

                // Get minimum and maximum values in y set
                float minY = YSet.Select(p => p.Min()).Min();
                float maxY = YSet.Select(p => p.Max()).Max();

                // Define chart bounds in y axis
                float[] yBounds = new float[] {
                    minY - Mathf.Abs(minY * 0.1f), // min minus 10%
                    maxY + Mathf.Abs(maxY * 0.1f)
                };                                 // max plus 10%

                // Create chart lines
                ChartObjectFactory factory = FindObjectOfType <ChartObjectFactory>();

                foreach (float[] Y in YSet)
                {
                    // Instantiate chart line from prefab
                    ChartLine line = factory.InstantiateChartLine(
                        this.gameObject.transform.Find("Lines"), "Line").GetComponent <ChartLine>();
                    // Set x and y points
                    line.X = X;
                    line.Y = Y;
                    // Set chart bounds
                    line.XBounds = xBounds;
                    line.YBounds = yBounds;
                    // Generate line
                    line.UpdateLine();
                }

                // Set chart bounds on tick text meshes
                textGroup.Find("XFirstValue").GetComponent <TextMesh>().text = xBounds[0].ToString("0.0#");
                textGroup.Find("XLastValue").GetComponent <TextMesh>().text  = xBounds[1].ToString("0.0#");
                textGroup.Find("YFirstValue").GetComponent <TextMesh>().text = yBounds[0].ToString("0.0#");
                textGroup.Find("YLastValue").GetComponent <TextMesh>().text  = yBounds[1].ToString("0.0#");

                // Set chart units
                textGroup.Find("XUnit").GetComponent <TextMesh>().text = Unit[0];
                textGroup.Find("YUnit").GetComponent <TextMesh>().text = Unit[1];

                // Update interaction component
                if (this.gameObject.GetComponent <InteractableChartBase>())
                {
                    this.gameObject.GetComponent <InteractableChartBase>().UpdateInteraction();
                }
            }