Esempio n. 1
0
        private void DrawSeries(Series series)
        {
            if (Mathf.Abs (series.width - graphRect.width) > 0.1f) {
            series.width = Mathf.Lerp (0, graphRect.width, series.deltaTime += Time.deltaTime * 0.5f);
            }

            GUI.BeginGroup (series.GetRect ());
            List<float> values = series.values;
            //Color color = (series.label == convergeManager.selected) ? Color.white : convergeManager.seriesColors [series.label];
            Color color = convergeManager.seriesColors [series.label];
            float thickness = (series.label == convergeManager.selected) ? thicknessLineSelected : thicknessLine;  //jtc - new

            { // Draw First Point
            string text = ("<color=#" + convergeManager.seriesColorsHex [series.label] + ">" + series.label + "</color>" + '\n' + values [xMin].ToString ("F2"));
            //DrawMarker(series.label, new Rect(hStart.x + xUnitLength - 7, hStart.y - (values[xMin] / yRange * yAxisLength) - 7, 14, 14), color, text);
            }

            for (int i = 1; i < Mathf.Min(series.values.Count, xNumMarkers); i++) {
            // Previous Point
            float xPos = hStart.x + xUnitLength * i;
            float yPos = hStart.y - (values [xMin + i - 1] / yRange * yAxisLength);
            // Current Point
            float xPosNext = hStart.x + xUnitLength * (i + 1);
            float yPosNext = hStart.y - (values [xMin + i] / yRange * yAxisLength);
            // Connect the Points by Drawing Line
            Drawing.DrawLine (new Vector2 (xPos, yPos), new Vector2 (xPosNext, yPosNext), color, thickness, true);
            // Draw End Point
            string text = ("<color=#" + convergeManager.seriesColorsHex [series.label] + ">" + series.label + "</color>" + '\n' + values [xMin + i].ToString ("F2"));
            //DrawMarker(series.label, new Rect(xPosNext - 7, yPosNext - 7, 14, 14), color, text);
            }
            GUI.EndGroup ();
        }
Esempio n. 2
0
        public void UpdateData()
        {
            // Update X-Axis Labels
            //List<string> labels = GameState.csvList.xLabels;
            if (labels == null) {
            Debug.LogError ("Invalid data submitted to GraphUnit::UpdateDate()");
            return;
            }
            for (int i = 0; i < labels.Count; i++) {
            int month = int.Parse (labels [i]);
            string name = DateTimeFormatInfo.CurrentInfo.GetMonthName ((month - 1) % 12 + 1).Substring (0, 3);

            if (xAxisLabels.Count != labels.Count) {
                xAxisLabels.Add (name + ((month - 1) % 12 == 0 ? "\n'0" + (month / 12 + 1) : ""));
            } else if (xAxisLabels [i] != name) {
                xAxisLabels [i] = name;
            }
            }

            // Update Values
            float yMaxValue = 1;

            //CSVObject csv = GameState.csvList;
            foreach (KeyValuePair<string, List<string>> entry in csv.csvList) {
            string name = entry.Key;
            List<string> values = entry.Value;

            if (name == ".xLabels") {
                continue;
            }

            if (!seriesList.ContainsKey (name)) {
                Rect seriesRect = new Rect (0, 0, 0, graphRect.height);
                //moved color setting to ConvergeManager.SetColors();
                //Color color = new Color (Random.Range (0.2f, 1.0f), Random.Range (0.2f, 1.0f), Random.Range (0.2f, 1.0f));

                seriesList [name] = new Series (name, seriesRect, Color.white);  //not using this color var
                if (!isFirstGraph) {
                    convergeManager.seriesLabels.Add (name);
                    //convergeManager.seriesColors [name] = color;
                    //convergeManager.seriesColorsHex [name] = Functions.ColorToHex(color);

                    if (convergeManager.lastSeriesToDraw == null) {
                        convergeManager.lastSeriesToDraw = name;
                    }
                }
            }

            List<float> temp = seriesList [name].values;
            for (int i = 0; i < values.Count - 1; i++) { // Exclude Last Point
                float value = (values [i] == "" ? -1f : float.Parse (values [i]));

                if (temp.Count != values.Count) {
                    temp.Add (value);
                } else if (!Mathf.Approximately (temp [i], value)) {
                    temp [i] = value;
                }

                yMaxValue = Mathf.Max (value, yMaxValue);
            }
            }

            if (!isFirstGraph) {
            convergeManager.SortLabelsAndNodes ();
            convergeManager.SetColors ();
            }

            int roundTo = int.Parse ("5".PadRight (((int)yMaxValue).ToString ().Length - 1, '0'));
            yRangeActual = Mathf.CeilToInt (yMaxValue / roundTo) * roundTo;
            yRange = yRangeActual;
        }