public void CreateSeriesSet(CSVObject csvObject) { csvList.Add (csvObject); if (csvList.Count == 1) { return; } //csvObject = SubtractCSVs (csvList [0], csvObject); Dictionary<string, int> diffList = csvObject.AverageDifferenceCSVs (csvList [0]); string label = seriesSets.Count == 0 ? "Initial" : seriesSets.Count.ToString (); SeriesSet seriesSet = new SeriesSet (label, new DynamicRect (0, 0, 0, barWidth)); int seriesScore = 1; foreach (KeyValuePair<string, List<string>> entry in csvObject.csvList) { string name = entry.Key; // Designate color for Series (only used if no convergeManager) if (!colorList.ContainsKey (name)) { if (convergeManager == null) { colorList [name] = new Color ( Random.Range (0.4f, 0.7f), Random.Range (0.4f, 0.7f), Random.Range (0.4f, 0.7f)); } else { colorList [name] = convergeManager.seriesColors [name]; } } // Convert values from String to Float. -1 to represent empty. //List<string> strValues = entry.Value; //List<float> values = new List<float> (); //for (int i = 0; i < strValues.Count; i++) { // float value = (strValues [i] == "" ? -1f : float.Parse (strValues [i])); // values.Add (value); //} int score = diffList [name]; seriesScore += score; // Create a Series to store series BarSeries series = new BarSeries ( name, score, //values, new DynamicRect (0, 0, 0, seriesSet.rect.height), colorList [name]); seriesSet.Add (series); } //sort seriesList in seriesSet seriesSet.Sort (convergeManager.seriesLabels); seriesSets.Add (seriesSet); // Adjust Max Y-Range //UpdateRange (); yRange = Mathf.Max (yRange, seriesScore); // Adjust init slider val; exclude initial (default) bar maxSliderValue = Mathf.Max (0, seriesSets.Count - perPage); sliderValue = maxSliderValue; }
private void DrawSeriesSet(SeriesSet seriesSet, int index = 0) { float xPos; xPos = hStart.x + interBarWidth/2 + (index * (barWidth + interBarWidth)); seriesSet.rect.x = xPos; seriesSet.rect.y = hStart.y - 1; GUI.color = (seriesSet.label == selected) ? Color.gray : Color.white; // Rotate -90 degrees to allow Rect to expand upwards by adjusting the width Matrix4x4 matrix = GUI.matrix; Vector2 origin = new Vector2 (seriesSet.rect.x, seriesSet.rect.y); GUIUtility.RotateAroundPivot (-90, origin); // Draw Series Set GUI.BeginGroup (seriesSet.rect.GetRect ()); float yNext = 0; foreach (BarSeries series in seriesSet.seriesList) { float barHeight = ((float) series.score / (float) yRange) * yAxisLength; //prev series.GetSum() // Draw horizontally, then rotate vertically DynamicRect barRect = series.GetRect (); barRect.x = yNext; barRect.width = barHeight; // Next stacking position yNext += barHeight - 1f; Functions.DrawBackground (barRect.GetRect (), barTexture, series.color); } GUI.EndGroup (); // Restore Rotation GUI.matrix = matrix; // Expand "Animation" if (Mathf.Abs (seriesSet.rect.width - yAxisLength) > 0.1f) { seriesSet.rect.width = Mathf.Lerp (0, yAxisLength, seriesSet.rect.deltaTime += Time.deltaTime * 0.4f); } else { // Create labels GUIStyle style = new GUIStyle (GUI.skin.label); style.richText = true; style.alignment = TextAnchor.LowerCenter; foreach (BarSeries series in seriesSet.seriesList) { DynamicRect barRect = series.GetRect (); string text = series.score.ToString (); //GetSum ().ToString ("F2"); // GUI.Label(new Rect(seriesSet.rect.x - 65, yAxisLength - barRect.x - barRect.width / 2 - 9, 200, 60), text, style); } } { GUIStyle style = new GUIStyle (GUI.skin.label); style.richText = true; style.alignment = TextAnchor.UpperCenter; string xLabel = seriesSet.label; GUI.Label (new Rect (seriesSet.rect.x + (seriesSet.rect.height - 200) / 2, seriesSet.rect.y + 10, 200, 60), xLabel, style); } }
public void CreateSeriesSet(CSVObject csvObject) { csvList.Add(csvObject); if (csvList.Count == 1) { return; } //csvObject = SubtractCSVs (csvList [0], csvObject); Dictionary <string, int> diffList = csvObject.AverageDifferenceCSVs(csvList [0]); string label = seriesSets.Count == 0 ? "Initial" : seriesSets.Count.ToString(); SeriesSet seriesSet = new SeriesSet(label, new DynamicRect(0, 0, 0, barWidth)); int seriesScore = 1; foreach (KeyValuePair <string, List <string> > entry in csvObject.csvList) { string name = entry.Key; // Designate color for Series (only used if no convergeManager) if (!colorList.ContainsKey(name)) { if (convergeManager == null) { colorList [name] = new Color( Random.Range(0.4f, 0.7f), Random.Range(0.4f, 0.7f), Random.Range(0.4f, 0.7f)); } else { colorList [name] = convergeManager.seriesColors [name]; } } // Convert values from String to Float. -1 to represent empty. //List<string> strValues = entry.Value; //List<float> values = new List<float> (); //for (int i = 0; i < strValues.Count; i++) { // float value = (strValues [i] == "" ? -1f : float.Parse (strValues [i])); // values.Add (value); //} int score = diffList [name]; seriesScore += score; // Create a Series to store series BarSeries series = new BarSeries( name, score, //values, new DynamicRect(0, 0, 0, seriesSet.rect.height), colorList [name]); seriesSet.Add(series); } //sort seriesList in seriesSet seriesSet.Sort(convergeManager.seriesLabels); seriesSets.Add(seriesSet); // Adjust Max Y-Range //UpdateRange (); yRange = Mathf.Max(yRange, seriesScore); // Adjust init slider val; exclude initial (default) bar maxSliderValue = Mathf.Max(0, seriesSets.Count - perPage); sliderValue = maxSliderValue; }
public void SetSeriesSetActive(int index, bool active) { SeriesSet seriesSet = seriesSets [index]; seriesSet.SetActive(active); }
private void DrawSeriesSet(SeriesSet seriesSet, int index = 0) { float xPos; xPos = hStart.x + interBarWidth / 2 + (index * (barWidth + interBarWidth)); seriesSet.rect.x = xPos; seriesSet.rect.y = hStart.y - 1; GUI.color = (seriesSet.label == selected) ? Color.gray : Color.white; // Rotate -90 degrees to allow Rect to expand upwards by adjusting the width Matrix4x4 matrix = GUI.matrix; Vector2 origin = new Vector2(seriesSet.rect.x, seriesSet.rect.y); GUIUtility.RotateAroundPivot(-90, origin); // Draw Series Set GUI.BeginGroup(seriesSet.rect.GetRect()); float yNext = 0; foreach (BarSeries series in seriesSet.seriesList) { float barHeight = ((float)series.score / (float)yRange) * yAxisLength; //prev series.GetSum() // Draw horizontally, then rotate vertically DynamicRect barRect = series.GetRect(); barRect.x = yNext; barRect.width = barHeight; // Next stacking position yNext += barHeight - 1f; Functions.DrawBackground(barRect.GetRect(), barTexture, series.color); } GUI.EndGroup(); // Restore Rotation GUI.matrix = matrix; // Expand "Animation" if (Mathf.Abs(seriesSet.rect.width - yAxisLength) > 0.1f) { seriesSet.rect.width = Mathf.Lerp(0, yAxisLength, seriesSet.rect.deltaTime += Time.deltaTime * 0.4f); } else { // Create labels GUIStyle style = new GUIStyle(GUI.skin.label); style.richText = true; style.alignment = TextAnchor.LowerCenter; foreach (BarSeries series in seriesSet.seriesList) { DynamicRect barRect = series.GetRect(); string text = series.score.ToString(); //GetSum ().ToString ("F2"); // GUI.Label(new Rect(seriesSet.rect.x - 65, yAxisLength - barRect.x - barRect.width / 2 - 9, 200, 60), text, style); } } { GUIStyle style = new GUIStyle(GUI.skin.label); style.richText = true; style.alignment = TextAnchor.UpperCenter; string xLabel = seriesSet.label; GUI.Label(new Rect(seriesSet.rect.x + (seriesSet.rect.height - 200) / 2, seriesSet.rect.y + 10, 200, 60), xLabel, style); } }
private void DrawGrid(Rect rect) { Color color = Color.white; GUI.BeginGroup(rect, GUI.skin.box); GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = Color.white; style.richText = true; // X-Axis Drawing.DrawLine(hStart, hEnd, color, thickness, false); // X-Axis Markers for (int i = 0; i < xNumMarkers; i++) { float xPos = hStart.x + xUnitLength * (i + 1), yPos = hStart.y - 5; // Unit Line // Drawing.DrawLine(new Vector2(xPos, yPos), new Vector2(xPos, yPos + 10), color, thickness, false); // Unit Label style.alignment = TextAnchor.UpperCenter; if (i < xAxisLabels.Count) { // GUI.Label(new Rect(xPos - 42, yPos + 10, 80, 70), xAxisLabels[xMin + i], style); } } // X-Axis Label style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(hStart.x + (xAxisLength - 80) / 2, hStart.y + 35, 80, 30), "<color=yellow>" + xTitle + "</color>", style); // Y-Axis Drawing.DrawLine(vStart, vEnd, color, thickness, false); // Y-Axis Markers for (int i = 0; i <= yNumMarkers; i++) { float xPos = vStart.x - 5, yPos = vStart.y - yUnitLength * i; // Unit Line Drawing.DrawLine(new Vector2(xPos, yPos), new Vector2(xPos + 10, yPos), color, thickness, false); // Unit Label style.alignment = TextAnchor.UpperRight; GUI.Label(new Rect(xPos - 85, yPos - 11, 80, 30), (i * yRange / 5).ToString(), style); } // Y-Axis Label style.alignment = TextAnchor.UpperCenter; Matrix4x4 matrix = GUI.matrix; GUIUtility.RotateAroundPivot(-90, new Vector2(hStart.x - 35, (rect.height) / 2)); GUI.Label(new Rect(hStart.x - 100, (rect.height - 60) / 2, 200, 30), "<color=orange>" + yTitle + "</color>", style ); GUI.matrix = matrix; // Draw Series Sets // for (int i = 0; i < Mathf.Min(seriesSets.Count, 3); i++) { // SeriesSet seriesSet = seriesSets[sliderValue + i]; // DrawSeriesSet(seriesSet, i); // } if (seriesSets.Count > 0) { //draw default vs target SeriesSet seriesSet = seriesSets [0]; DrawSeriesSet(seriesSet, 0); Vector2 v1 = new Vector2( seriesSet.rect.x + barWidth + (interBarWidth / 2), seriesSet.rect.y ); Vector2 v2 = new Vector2( v1.x, seriesSet.rect.y - yAxisLength ); //separate default from player attempts with a line Drawing.DrawLine(v1, v2, color, thickness, false); //draw attempts vs target for (int series = 1; series < Mathf.Min(perPage, seriesSets.Count); series++) { seriesSet = seriesSets [sliderValue + series]; DrawSeriesSet(seriesSet, series); } } GUI.EndGroup(); }