Пример #1
0
 public void SetSeriesFormat(int seriesIndex, SeriesFormatParams format)
 {
     if (seriesIndex >= 0 && seriesIndex < this.SeriesList.Count)
     {
         this.SeriesList[seriesIndex].Format = format;
     }
 }
Пример #2
0
 public void SetSeriesColor(int seriesIndex, Color color)
 {
     if (seriesIndex >= 0 && seriesIndex < this.SeriesList.Count)
     {
         SeriesFormatParams format = this.SeriesList[seriesIndex].Format;
         format.PrimaryColor = color;
         this.SeriesList[seriesIndex].Format = format;
     }
 }
Пример #3
0
 public void SetSeriesStyle(int seriesIndex, GraphStyle style)
 {
     if (seriesIndex >= 0 && seriesIndex < this.SeriesList.Count)
     {
         SeriesFormatParams format = this.SeriesList[seriesIndex].Format;
         format.Style = style;
         this.SeriesList[seriesIndex].Format = format;
     }
 }
Пример #4
0
 public void SetSeriesName(int seriesIndex, string name)
 {
     if (seriesIndex >= 0 && seriesIndex < this.SeriesList.Count)
     {
         SeriesFormatParams format = this.SeriesList[seriesIndex].Format;
         format.Name = name;
         this.SeriesList[seriesIndex].Format = format;
     }
 }
Пример #5
0
        private void RenderSeries(Series series, SeriesFormatParams format, int maxSamples, int pixelsPerDataPoint, Vector2 xPointPixelRange, Vector2 yRange)
        {
            int count = series.Data.Count;

            if (count == 0)
            {
                return;
            }

            int drawSamples = Mathf.Min(maxSamples, count);

            int baseScreenX = (int)this.GraphRect.xMax - drawSamples * pixelsPerDataPoint;

            float z = this.Z;

            switch (format.Style)
            {
            case GraphStyle.Line: {
                GL.Begin(GL.LINES);
                GL.Color(format.PrimaryColor);

                int startIndex = Mathf.Max(1, count - maxSamples);

                Vector3 prevPoint = new Vector3(baseScreenX, this.GraphRect.yMin + this.GraphRect.height * Mathf.InverseLerp(yRange[0], yRange[1], series.Data[startIndex - 1].y), z);

                for (int i = startIndex; i < count; ++i)
                {
                    Vector3 point = new Vector3(prevPoint.x + pixelsPerDataPoint,
                                                this.GraphRect.yMin + this.GraphRect.height * Mathf.InverseLerp(yRange[0], yRange[1], series.Data[i].y), z);
                    GL.Vertex(prevPoint);
                    GL.Vertex(point);
                    prevPoint = point;
                }

                GL.End();
            }
            break;

            case GraphStyle.Bar: {
                GL.Begin(GL.QUADS);
                GL.Color(format.PrimaryColor);

                float y0 = this.GraphRect.yMin + this.GraphRect.height * Mathf.InverseLerp(yRange[0], yRange[1], 0f);

                int startIndex = Mathf.Max(0, count - maxSamples);
                for (int i = startIndex, drawSample = 0; i < count; ++i, ++drawSample)
                {
                    Vector3 p0 = new Vector3(baseScreenX + drawSample * pixelsPerDataPoint + xPointPixelRange[0],
                                             this.GraphRect.yMin + this.GraphRect.height * Mathf.InverseLerp(yRange[0], yRange[1], series.Data[i].y), z);

                    Vector3 p1 = new Vector3(p0.x + xPointPixelRange[1] - xPointPixelRange[0], y0, z);

                    GL.Vertex(p0);
                    GL.Vertex3(p0.x, p1.y, z);
                    GL.Vertex(p1);
                    GL.Vertex3(p1.x, p0.y, z);
                }

                GL.End();
            }
            break;
            }
        }
Пример #6
0
        protected void Render()
        {
            // figure out size/scale for all series

            int pixelsPerDataPoint = Mathf.FloorToInt(this.GraphRect.width / this.MaxSamples);

            int barSeriesCount    = this.BarSeriesCount;
            int minimumPixelWidth = 6 * (barSeriesCount + 1);

            pixelsPerDataPoint = Mathf.Max(pixelsPerDataPoint, minimumPixelWidth);

            int maxSamples = Mathf.FloorToInt(this.GraphRect.width / pixelsPerDataPoint);

            Vector2 yRange = CalcYRange(maxSamples);

            if (yRange[0] > 0f)
            {
                yRange[0] = 0f;
            }
            else if (yRange[1] < 0f)
            {
                yRange[1] = 0f;
            }

            Graph.LineMaterial.SetPass(0);

            GL.PushMatrix();

            GL.LoadPixelMatrix();

            float z = this.Z;

            float y = Mathf.Lerp(this.GraphRect.yMin, this.GraphRect.yMax, Mathf.InverseLerp(yRange[0], yRange[1], 0f));

            RenderAxis(this.Format.XAxis, new Vector3(this.GraphRect.xMin, y, z), new Vector3(this.GraphRect.xMax, y, z));

            RenderAxis(this.Format.YAxis, new Vector3(this.GraphRect.xMin, this.GraphRect.yMin, z), new Vector3(this.GraphRect.xMin, this.GraphRect.yMax, z));

            int     barSeriesIndex   = -1;
            float   pixelsPerBar     = pixelsPerDataPoint / (barSeriesCount + 1);
            Vector2 xPointPixelRange = new Vector2(0f, pixelsPerDataPoint);

            for (int i = 0; i < this.SeriesList.Count; ++i)
            {
                Series             series = this.SeriesList[i];
                SeriesFormatParams format = this.SeriesList[i].Format;

                if (format.Style == GraphStyle.Bar)
                {
                    barSeriesIndex++;
                    xPointPixelRange = new Vector2(barSeriesIndex + 0.5f, barSeriesIndex + 1.5f) * pixelsPerBar;
                }
                else
                {
                    xPointPixelRange = new Vector2(0f, pixelsPerDataPoint);
                }

                RenderSeries(series, format, maxSamples, pixelsPerDataPoint, xPointPixelRange, yRange);
            }

            GL.PopMatrix();
        }