Пример #1
0
    private void Awake()
    {
        instance          = this;
        graphContainer    = transform.Find("graphContainer").GetComponent <RectTransform>();
        labelTemplateX    = graphContainer.Find("labelTemplateX").GetComponent <RectTransform>();
        lableTemplateY    = graphContainer.Find("labelTemplateY").GetComponent <RectTransform>();
        dashTemplateX     = graphContainer.Find("dashTemplateX").GetComponent <RectTransform>();
        dashTemplateY     = graphContainer.Find("dashTemplateY").GetComponent <RectTransform>();
        tooltipGameObject = graphContainer.Find("ToolTip").gameObject;

        gameObjectList        = new List <GameObject>();
        yLabelList            = new List <RectTransform>();
        graphVisualObjectList = new List <IGraphVisualObject>();

        //List<int> valueList = new List<int>() { 5, 98, 56, 45, 30, 22, 17, 15, 13, 17, 25, 37, 40, 36, 33,60,54,22,67,98,34,25,2,7,87 };

        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dot, Color.green, Color.white);
        IGraphVisual barGraphVisual  = new BarChartVisual(graphContainer, Color.green, 0.8f);

        transform.Find("barGraphButton").GetComponent <Button>().onClick.AddListener(() => SetGraphVisual(barGraphVisual));
        transform.Find("LineGraphButton").GetComponent <Button>().onClick.AddListener(() => SetGraphVisual(lineGraphVisual));
        transform.Find("increaseVisibleButton").GetComponent <Button>().onClick.AddListener(() => IncreaseGraphVisual());
        transform.Find("decreaseVisibleButton").GetComponent <Button>().onClick.AddListener(() => DecreaseGraphVisual());
        transform.Find("DollarYlabelButton").GetComponent <Button>().onClick.AddListener(() => SetGetAxisLabelY((float _f) => "$" + Mathf.RoundToInt(_f)));
        transform.Find("EuroYlabelButton").GetComponent <Button>().onClick.AddListener(() => SetGetAxisLabelY((float _f) => "€" + Mathf.RoundToInt(_f / 1.18f)));

        HideToolTip();
        //ShowGraph(valueList, barGraphVisual, -1, (int _i) => "Day" + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f));
    }
Пример #2
0
    IEnumerator ChangeData()
    {
        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, new Color32(85, 165, 255, 255), new Color32(85, 165, 255, 100));
        IGraphVisual barChartVisual  = new BarChartVisual(graphContainer, new Color32(85, 165, 255, 255), .8f);

        WWWForm form = new WWWForm();

        string starttime = startRange.text;
        string endtime   = endRange.text;

        form.AddField("starttime", starttime);
        form.AddField("endtime", endtime);

        WWW getNewTimes = new WWW("http://localhost:81/percentsdata/getNewTimes.php", form);

        yield return(getNewTimes);

        string[]   newtimes = getNewTimes.text.Split(';');
        List <int> newList  = new List <int>();

        int numrows = int.Parse(newtimes[0]);

        bool skipFirst = false;

        foreach (string str in newtimes)
        {
            if (skipFirst)
            {
                int mins = (Int32.Parse(str)) / 60 / 60;
                newList.Add(mins);
            }
            skipFirst = true;
        }

        WWW getNewTags = new WWW("http://localhost:81/percentsdata/getNewTags.php", form);

        yield return(getNewTags);

        //string tagsDataString = tagsData.text;
        string[] nameArray = getNewTags.text.Split(';');
        int      num       = Int32.Parse(nameArray[0]);

        string[] names = new string[num];
        Array.Copy(nameArray, 1, names, 0, num);

        HideSearchPanel();
        ShowGraph(newList, barChartVisual, -1, (int _i) => names[(_i)], (float _f) => Mathf.RoundToInt(_f) + " hrs");

        //Debug.Log("text!!" + starttime);
        string DisplayInfo = starttime + " to " + endtime;

        UpdateDisplayPanel(DisplayInfo);
    }
    private void Start()
    {
        // Set Up graphVisual objects to use by Show Graph Method.
        IGraphVisual lineChartVisual = new LineGraphVisual(graphContainer, graphDotSprite, Color.white);

        lineGraphVisual = lineChartVisual;

        IGraphVisual barChartVisual = new BarChartVisual(graphContainer, colourOfBars);

        barGraphVisual = barChartVisual;

        graphGameObjectList = new List <GameObject>();
    }
Пример #4
0
    public void SetGraphVisual(string graphVisual)
    {
        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dot, Color.green, Color.white);
        IGraphVisual barGraphVisual  = new BarChartVisual(graphContainer, Color.green, 0.8f);

        if (graphVisual == "barGraphVisual")
        {
            ShowGraph(this.valueList, barGraphVisual, this.maxVisibleValueAmount, this.getAxisLabelX, this.getAxisLabelY);
        }
        else
        {
            ShowGraph(this.valueList, lineGraphVisual, this.maxVisibleValueAmount, this.getAxisLabelX, this.getAxisLabelY);
        }
    }
Пример #5
0
    private void ProcessJson(string json)
    {
        List <int> valueList = new List <int>();
        ListItem   items     = JsonUtility.FromJson <ListItem>(json);

        Debug.Log(items.Values.Length);
        for (int i = 0; i < items.Values.Length; i++)
        {
            Debug.Log("***" + items.Values[i].Day + "****" + items.Values[i].value);
            valueList.Add(items.Values[i].value);
        }
        IGraphVisual barGraphVisual = new BarChartVisual(graphContainer, Color.green, 0.8f);

        ShowGraph(valueList, barGraphVisual, -1, (int _i) => "Day" + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f));
    }
Пример #6
0
    private void HandleReferences(out IGraphVisual lineGraphVisual, out IGraphVisual barChartVisual)
    {
        statisticsManager = GameObject.FindObjectOfType <StatisticsManager> ();
        // Grab base objects references
        graphContainer    = transform.Find("graphContainer").GetComponent <RectTransform> ();
        labelTemplateX    = graphContainer.Find("labelTemplateX").GetComponent <RectTransform> ();
        labelTemplateY    = graphContainer.Find("labelTemplateY").GetComponent <RectTransform> ();
        dashContainer     = graphContainer.Find("dashContainer").GetComponent <RectTransform> ();
        dashTemplateX     = dashContainer.Find("dashTemplateX").GetComponent <RectTransform> ();
        dashTemplateY     = dashContainer.Find("dashTemplateY").GetComponent <RectTransform> ();
        tooltipGameObject = graphContainer.Find("tooltip").gameObject;

        startYScaleAtZero     = true;
        gameObjectList        = new List <GameObject> ();
        yLabelList            = new List <RectTransform> ();
        graphVisualObjectList = new List <IGraphVisualObject> ();

        lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, Color.green, new Color(1, 1, 1, .5f));
        barChartVisual  = new BarChartVisual(graphContainer, Color.white, .8f);
    }
Пример #7
0
    private void PlotAreaData()
    {
        plot1.Clear();
        List <string> areaNames = new List <string>()
        {
            "Africa", "Africa", "Asia", "Asia", "Europe", "Europe", "\nNorth\n America", "\nNorth\n America", "\nSouth\n America", "\nSouth\n America"
        };
        // temporary
        List <Area> areas = World.instance.areas;

        List <int> data = new List <int>();

        foreach (Area a in areas)
        {
            Debug.Log(a.cured);
            data.Add(a.dead);
            data.Add(a.cured);
        }

        BarChartVisual barVisual = new BarChartVisual(containers[0], Color.white, 0.9f, Color.black);

        plot1.ShowPlot(data, barVisual, -1, containers[0], 0, 0,
                       (int i) => areaNames[i].ToString(), (float f) => Mathf.RoundToInt(f).ToString());
    }
Пример #8
0
    private void Awake()
    {
        instace           = this;
        graphContainer    = transform.Find("graphContainer").GetComponent <RectTransform>();
        labelTemplateX    = graphContainer.Find("xAxis").GetComponent <RectTransform>();
        labelTemplateY    = graphContainer.Find("yAxis").GetComponent <RectTransform>();
        dashTemplateX     = graphContainer.Find("xDash").GetComponent <RectTransform>();
        dashTemplateY     = graphContainer.Find("yDash").GetComponent <RectTransform>();
        tooltipGameObject = graphContainer.Find("tooltip").gameObject;

        gameObjectList        = new List <GameObject>();
        graphVisualObjectlist = new List <IGraphVisualObject>();


        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, Color.white, new Color(1, 1, 1, .5f));
        IGraphVisual barChartVisual  = new BarChartVisual(graphContainer, Color.white, .8f);

        transform.Find("barChartBtn").GetComponent <Button_UI>().ClickFunc  = () => { SetGraphVisual(barChartVisual); };
        transform.Find("lineGraphBtn").GetComponent <Button_UI>().ClickFunc = () => { SetGraphVisual(lineGraphVisual); };


        // Level Selection process determined by the Scene indexer
        switch (SceneManager.GetActiveScene().buildIndex)
        {
        case (2): valueList = new List <int>()
        {
                3, 4, 6, 9, 8
        };                     break;                                                                  // 22 houses

        case (3): valueList = new List <int>()
        {
                10
        };                            break;                                                           // 10

        case (4): valueList = new List <int>()
        {
                1, 2, 2, 3, 2, 1, 1
        };         break;                                                                      // 12 houses

        case (5): valueList = new List <int>()
        {
                2, 2, 2, 3, 4, 3, 4, 2, 2
        };     break;                                                                          // 22 houses

        case (6): valueList = new List <int>()
        {
                5, 5
        };           break;

        case (7): valueList = new List <int>()
        {
                5, 5
        };           break;

        case (8): valueList = new List <int>()
        {
                5, 5
        };           break;

        case (9): valueList = new List <int>()
        {
                5, 5
        };           break;
        //  case(5): valueList = new List<int>() {  22,23,22,21,24,27,31,29,31,34,34,34,30,34,33,32,31,30,32 };
        //  case(6): valueList = new List<int>() {  22,23,22,21,24,27,31,29,31,30,29,31,30,32,35,34,33,32,33,32,31,28,26,24 };

        default: valueList = new List <int>()
        {
                0
        }; break;
        }
        transmitter_valueList = valueList;                      // transmits the values on the graph


        ShowGraph(valueList, barChartVisual, -1, (int _i) => "" + (_i), (float _f) => Mathf.RoundToInt(_f) + "  ");
    }
Пример #9
0
    private void Awake()
    {
        instance          = this;
        statisticsManager = GameObject.FindObjectOfType <StatisticsManager> ();
        // Grab base objects references
        graphContainer    = transform.Find("graphContainer").GetComponent <RectTransform> ();
        labelTemplateX    = graphContainer.Find("labelTemplateX").GetComponent <RectTransform> ();
        labelTemplateY    = graphContainer.Find("labelTemplateY").GetComponent <RectTransform> ();
        dashContainer     = graphContainer.Find("dashContainer").GetComponent <RectTransform> ();
        dashTemplateX     = dashContainer.Find("dashTemplateX").GetComponent <RectTransform> ();
        dashTemplateY     = dashContainer.Find("dashTemplateY").GetComponent <RectTransform> ();
        tooltipGameObject = graphContainer.Find("tooltip").gameObject;

        startYScaleAtZero     = true;
        gameObjectList        = new List <GameObject> ();
        yLabelList            = new List <RectTransform> ();
        graphVisualObjectList = new List <IGraphVisualObject> ();

        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, Color.green, new Color(1, 1, 1, .5f));
        IGraphVisual barChartVisual  = new BarChartVisual(graphContainer, Color.white, .8f);

        // Set up buttons
        transform.Find("barChartBtn").GetComponent <Button_UI> ().ClickFunc = () =>
        {
            SetGraphVisual(barChartVisual);
        };
        transform.Find("lineGraphBtn").GetComponent <Button_UI> ().ClickFunc = () =>
        {
            SetGraphVisual(lineGraphVisual);
        };

        transform.Find("decreaseVisibleAmountBtn").GetComponent <Button_UI> ().ClickFunc = () =>
        {
            DecreaseVisibleAmount();
        };
        transform.Find("increaseVisibleAmountBtn").GetComponent <Button_UI> ().ClickFunc = () =>
        {
            IncreaseVisibleAmount();
        };

        HideTooltip();

        // Set up base values
        //List<int> valueList = new List<int> () { 5, 98, 56, 45, 30, 22, 17, 15, 13, 17, 25, 37, 40, 36, 33 };

        // List<int> valueList = statisticsManager.numberOfChickens;
        // ShowGraph (valueList, barChartVisual, -1, (int _i) => "" + (_i + 1), (float _f) => "Chickens " + Mathf.RoundToInt (_f));

        /*
         * // Automatically modify graph values and visual
         * bool useBarChart = true;
         * FunctionPeriodic.Create(() => {
         *  for (int i = 0; i < valueList.Count; i++) {
         *      valueList[i] = Mathf.RoundToInt(valueList[i] * UnityEngine.Random.Range(0.8f, 1.2f));
         *      if (valueList[i] < 0) valueList[i] = 0;
         *  }
         *  if (useBarChart) {
         *      ShowGraph(valueList, barChartVisual, -1, (int _i) => "Day " + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f));
         *  } else {
         *      ShowGraph(valueList, lineGraphVisual, -1, (int _i) => "Day " + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f));
         *  }
         *  useBarChart = !useBarChart;
         * }, .5f);
         * //*/

        // int index = 0;
        // FunctionPeriodic.Create (() =>
        // {
        //     index = (index + 1) % valueList.Count;
        // }, .1f);
        // FunctionPeriodic.Create (() =>
        // {
        //     //int index = UnityEngine.Random.Range(0, valueList.Count);
        //     UpdateValue (index, valueList[index] + UnityEngine.Random.Range (1, 3));
        // }, .02f);
    }
Пример #10
0
    IEnumerator Start()
    {
        instance          = this;
        graphContainer    = transform.Find("graphContainer").GetComponent <RectTransform>();
        labelTemplateX    = graphContainer.Find("labelTemplateX").GetComponent <RectTransform>();
        labelTemplateY    = graphContainer.Find("labelTemplateY").GetComponent <RectTransform>();
        dashTemplateX     = graphContainer.Find("dashTemplateX").GetComponent <RectTransform>();
        dashTemplateY     = graphContainer.Find("dashTemplateY").GetComponent <RectTransform>();
        tooltipGameObject = graphContainer.Find("tooltip").gameObject;

        startYScaleAtZero     = true;
        gameObjectList        = new List <GameObject>();
        yLabelList            = new List <RectTransform>();
        graphVisualObjectList = new List <IGraphVisualObject>();

        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, new Color32(85, 165, 255, 255), new Color32(85, 165, 255, 100));
        IGraphVisual barChartVisual  = new BarChartVisual(graphContainer, new Color32(85, 165, 255, 255), .8f);

        //buttons to change graph interface
        transform.Find("barChartBtn").GetComponent <Button_UI>().ClickFunc = () =>
        {
            SetGraphVisual(barChartVisual);
        };
        transform.Find("lineGraphBtn").GetComponent <Button_UI>().ClickFunc = () =>
        {
            SetGraphVisual(lineGraphVisual);
        };
        transform.Find("decreaseVisibleAmountBtn").GetComponent <Button_UI>().ClickFunc = () => {
            DecreaseVisibleAmount();
        };
        transform.Find("increaseVisibleAmountBtn").GetComponent <Button_UI>().ClickFunc = () => {
            IncreaseVisibleAmount();
        };


        //values to be used in the graph
        List <int> valueList = new List <int>()
        {
        };
        WWW tagsTime = new WWW("http://localhost:81/percentsdata/showTotalTime.php");

        yield return(tagsTime);

        string[] timeArray = tagsTime.text.Split(';');

        int numrows = int.Parse(timeArray[0]);

        bool skipFirst = false;

        foreach (string str in timeArray)
        {
            if (skipFirst)
            {
                int mins = (Int32.Parse(str)) / 60 / 60;
                valueList.Add(mins);
            }
            skipFirst = true;
        }

        WWW tagsName = new WWW("http://localhost:81/percentsdata/ShowTags.php");

        yield return(tagsName);

        //string tagsDataString = tagsData.text;
        string[] nameArray = tagsName.text.Split(';');
        int      num       = Int32.Parse(nameArray[0]);

        string[] names = new string[num];
        Array.Copy(nameArray, 1, names, 0, num);

        //to be performed on startup
        ShowGraph(valueList, barChartVisual, -1, (int _i) => names[(_i)], (float _f) => Mathf.RoundToInt(_f) + " hrs");
    }
Пример #11
0
    IEnumerator NewDateData()
    {
        IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, new Color32(85, 165, 255, 255), new Color32(85, 165, 255, 100));
        IGraphVisual barChartVisual  = new BarChartVisual(graphContainer, new Color32(85, 165, 255, 255), .8f);

        WWWForm form = new WWWForm();

        string newDate = date.text;

        string NewYearTimes  = "http://localhost:81/percentsdata/NewYearTimes.php";
        string NewMonthTimes = "http://localhost:81/percentsdata/NewMonthTimes.php";
        string NewDayTimes   = "http://localhost:81/percentsdata/NewDayTimes.php";

        string NewYearTags  = "http://localhost:81/percentsdata/NewYearTags.php";
        string NewMonthTags = "http://localhost:81/percentsdata/NewMonthTags.php";
        string NewDayTags   = "http://localhost:81/percentsdata/NewDayTags.php";

        string toUseTime = "";
        string toUseTag  = "";

        if (newDate.Length == 4)
        {
            toUseTime = NewYearTimes;
            toUseTag  = NewYearTags;
        }
        else if (newDate.Length == 7)
        {
            toUseTime = NewMonthTimes;
            toUseTag  = NewMonthTags;
        }
        else
        {
            toUseTime = NewDayTimes;
            toUseTag  = NewDayTags;
        }

        form.AddField("date", newDate);
        WWW getNewTimes = new WWW(toUseTime, form);

        yield return(getNewTimes);


        string[]   newtimes = getNewTimes.text.Split(';');
        List <int> newList  = new List <int>();

        int numrows = int.Parse(newtimes[0]);

        bool skipFirst = false;

        foreach (string str in newtimes)
        {
            if (skipFirst)
            {
                int mins = (Int32.Parse(str)) / 60 / 60;
                newList.Add(mins);
            }
            skipFirst = true;
        }


        WWW getNewTags = new WWW(toUseTag, form);

        yield return(getNewTags);

        string[] nameArray = getNewTags.text.Split(';');
        int      num       = Int32.Parse(nameArray[0]);

        string[] names = new string[num];
        Array.Copy(nameArray, 1, names, 0, num);

        HideSearchPanel();
        ShowGraph(newList, barChartVisual, -1, (int _i) => names[(_i)], (float _f) => Mathf.RoundToInt(_f) + " hrs");
        UpdateDisplayPanel(date.text);
    }
Пример #12
0
    private void ShowGraph(List <ScoreItem> valueList, int maxVisibleValueAmount = -1)
    {
        this.valueList = valueList;
        IGraphVisual graphVisual = new BarChartVisual(graphContainer, Color.white, .8f);

        getAxisLabelY = (float _f) => "" + (_f / 100);

        if (maxVisibleValueAmount <= 0)
        {
            // Show all if no amount specified
            maxVisibleValueAmount = valueList.Count;
        }
        if (maxVisibleValueAmount > valueList.Count)
        {
            // Validate the amount to show the maximum
            maxVisibleValueAmount = valueList.Count;
        }

        this.maxVisibleValueAmount = maxVisibleValueAmount;

        // Clean up previous graph
        foreach (GameObject gameObject in gameObjectList)
        {
            Destroy(gameObject);
        }
        gameObjectList.Clear();
        yLabelList.Clear();

        foreach (IGraphVisualObject graphVisualObject in graphVisualObjectList)
        {
            graphVisualObject.CleanUp();
        }
        graphVisualObjectList.Clear();

        graphVisual.CleanUp();

        // Grab the width and height from the container
        float graphWidth  = graphContainer.sizeDelta.x;
        float graphHeight = graphContainer.sizeDelta.y;

        float yMinimum, yMaximum;

        CalculateYScale(out yMinimum, out yMaximum);

        // Set the distance between each point on the graph
        xSize = graphWidth / (maxVisibleValueAmount + 1);

        // Cycle through all visible data points
        int xIndex = 0;

        for (int i = 0; i < valueList.Count; i++)
        {
            float xPosition = xSize + xIndex * xSize;
            float yPosition = ((valueList[i].Score - yMinimum) / (yMaximum - yMinimum)) * graphHeight;

            // Add data point visual
            string             tooltipText       = getAxisLabelY(valueList[i].Score);
            IGraphVisualObject graphVisualObject = graphVisual.CreateGraphVisualObject(new Vector2(xPosition, yPosition), xSize, tooltipText);
            graphVisualObjectList.Add(graphVisualObject);

            // Duplicate the x label template
            RectTransform labelX = Instantiate(labelTemplateX);
            labelX.SetParent(graphContainer, false);
            labelX.gameObject.SetActive(true);
            labelX.anchoredPosition           = new Vector2(xPosition - 40, -7f);
            labelX.GetComponent <Text>().text = valueList[i].Name;
            gameObjectList.Add(labelX.gameObject);

            xIndex++;
        }

        // Set up separators on the y axis
        int separatorCount = 10;

        for (int i = 0; i <= separatorCount; i++)
        {
            // Duplicate the label template
            RectTransform labelY = Instantiate(labelTemplateY);
            labelY.SetParent(graphContainer, false);
            labelY.gameObject.SetActive(true);
            float normalizedValue = i * 1f / separatorCount;
            labelY.anchoredPosition           = new Vector2(-7f, normalizedValue * graphHeight);
            labelY.GetComponent <Text>().text = getAxisLabelY(yMinimum + (normalizedValue * (yMaximum - yMinimum)));
            yLabelList.Add(labelY);
            gameObjectList.Add(labelY.gameObject);
        }
    }