コード例 #1
0
ファイル: GraphViewTests.cs プロジェクト: hong1990/gui.cs
        public void PathAnnotation_Diamond()
        {
            var gv = GraphViewTests.GetGraph();

            var path = new PathAnnotation();

            path.Points.Add(new PointF(1, 2));
            path.Points.Add(new PointF(3, 3));
            path.Points.Add(new PointF(6, 2));
            path.Points.Add(new PointF(3, 1));

            // list the starting point again to close the shape
            path.Points.Add(new PointF(1, 2));

            gv.Annotations.Add(path);
            gv.Redraw(gv.Bounds);

            var expected =
                @"
 │  ..
 ┤..  ..
 ┤ ...
0┼┬┬┬┬┬┬┬┬
 0    5";

            GraphViewTests.AssertDriverContentsAre(expected);
        }
コード例 #2
0
ファイル: GraphViewTests.cs プロジェクト: hong1990/gui.cs
        public void PathAnnotation_Box()
        {
            var gv = GraphViewTests.GetGraph();

            var path = new PathAnnotation();

            path.Points.Add(new PointF(1, 1));
            path.Points.Add(new PointF(1, 3));
            path.Points.Add(new PointF(6, 3));
            path.Points.Add(new PointF(6, 1));

            // list the starting point again so that it draws a complete square
            // (otherwise it will miss out the last line along the bottom)
            path.Points.Add(new PointF(1, 1));

            gv.Annotations.Add(path);
            gv.Redraw(gv.Bounds);

            var expected =
                @"
 │......
 ┤.    .
 ┤......
0┼┬┬┬┬┬┬┬┬
 0    5";

            GraphViewTests.AssertDriverContentsAre(expected);
        }
コード例 #3
0
        public void PathAnnotation_Diamond()
        {
            var gv = GraphViewTests.GetGraph();

            var path = new PathAnnotation();

            path.Points.Add(new PointF(1, 2));
            path.Points.Add(new PointF(3, 3));
            path.Points.Add(new PointF(6, 2));
            path.Points.Add(new PointF(3, 1));

            // list the starting point again to close the shape
            path.Points.Add(new PointF(1, 2));

            gv.Annotations.Add(path);
            gv.Redraw(gv.Bounds);

            var expected =
                @"
 │  ..
 ┤..  ..
 ┤ ...
0┼┬┬┬┬┬┬┬┬
 0    5";

            GraphViewTests.AssertDriverContentsAre(expected, output);


            // Shutdown must be called to safely clean up Application if Init has been called
            Application.Shutdown();
        }
コード例 #4
0
        public void PathAnnotation_Box()
        {
            var gv = GraphViewTests.GetGraph();

            var path = new PathAnnotation();

            path.Points.Add(new PointF(1, 1));
            path.Points.Add(new PointF(1, 3));
            path.Points.Add(new PointF(6, 3));
            path.Points.Add(new PointF(6, 1));

            // list the starting point again so that it draws a complete square
            // (otherwise it will miss out the last line along the bottom)
            path.Points.Add(new PointF(1, 1));

            gv.Annotations.Add(path);
            gv.Redraw(gv.Bounds);

            var expected =
                @"
 │......
 ┤.    .
 ┤......
0┼┬┬┬┬┬┬┬┬
 0    5";

            GraphViewTests.AssertDriverContentsAre(expected, output);


            // Shutdown must be called to safely clean up Application if Init has been called
            Application.Shutdown();
        }
コード例 #5
0
        private void SetupLineGraph(DataTable dt, AggregateContinuousDateAxis axis, string countColumnName, int boundsWidth, int boundsHeight)
        {
            graphView.AxisY.Text = countColumnName;
            graphView.GraphColor = Driver.MakeAttribute(Color.White, Color.Black);

            var xIncrement = 1f / (boundsWidth / (float)dt.Rows.Count);

            graphView.MarginBottom          = 2;
            graphView.AxisX.Increment       = xIncrement * 10;
            graphView.AxisX.ShowLabelsEvery = 1;
            graphView.AxisX.Text            = axis.AxisIncrement.ToString();
            graphView.AxisX.LabelGetter     = (v) =>
            {
                var x = (int)v.Value;
                return(x < 0 || x >= dt.Rows.Count ? "" : dt.Rows[x][0].ToString());
            };

            float minY = 0;
            float maxY = 1;

            var colors = GetColors(dt.Columns.Count - 1);

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                var series = new PathAnnotation()
                {
                    LineColor = colors[i - 1], BeforeSeries = true
                };
                int row = 0;

                foreach (DataRow dr in dt.Rows)
                {
                    // Treat nulls as 0
                    var yVal = dr[i] == DBNull.Value ? 0 : (float)Convert.ToDouble(dr[i]);

                    minY = Math.Min(minY, yVal);
                    maxY = Math.Max(maxY, yVal);

                    series.Points.Add(new PointF(row++, yVal));
                }

                graphView.Annotations.Add(series);
            }

            var yIncrement = 1 / ((boundsHeight - graphView.MarginBottom) / (maxY - minY));

            graphView.CellSize = new PointF(xIncrement, yIncrement);

            graphView.AxisY.LabelGetter = (v) => FormatValue(v.Value, minY, maxY);
            graphView.MarginLeft        = (uint)(Math.Max(FormatValue(maxY, minY, maxY).Length, FormatValue(minY, minY, maxY).Length)) + 1;

            var legend = GetLegend(dt, boundsWidth, boundsHeight);

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                legend.AddEntry(new GraphCellToRender('.', colors[i - 1]), dt.Columns[i].ColumnName);
            }
        }
コード例 #6
0
        private void SetupSineWave()
        {
            graphView.Reset();

            about.Text = "This graph shows a sine wave";

            var points = new ScatterSeries();
            var line   = new PathAnnotation();

            // Draw line first so it does not draw over top of points or axis labels
            line.BeforeSeries = true;

            // Generate line graph with 2,000 points
            for (float x = -500; x < 500; x += 0.5f)
            {
                points.Points.Add(new PointF(x, (float)Math.Sin(x)));
                line.Points.Add(new PointF(x, (float)Math.Sin(x)));
            }

            graphView.Series.Add(points);
            graphView.Annotations.Add(line);

            // How much graph space each cell of the console depicts
            graphView.CellSize = new PointF(0.1f, 0.1f);

            // leave space for axis labels
            graphView.MarginBottom = 2;
            graphView.MarginLeft   = 3;

            // One axis tick/label per
            graphView.AxisX.Increment       = 0.5f;
            graphView.AxisX.ShowLabelsEvery = 2;
            graphView.AxisX.Text            = "X →";
            graphView.AxisX.LabelGetter     = (v) => v.Value.ToString("N2");

            graphView.AxisY.Increment       = 0.2f;
            graphView.AxisY.ShowLabelsEvery = 2;
            graphView.AxisY.Text            = "↑Y";
            graphView.AxisY.LabelGetter     = (v) => v.Value.ToString("N2");

            graphView.ScrollOffset = new PointF(-2.5f, -1);

            graphView.SetNeedsDisplay();
        }
コード例 #7
0
        private void SetupLineGraph()
        {
            graphView.Reset();

            about.Text = "This graph shows random points";

            var black   = Application.Driver.MakeAttribute(graphView.ColorScheme.Normal.Foreground, Color.Black);
            var cyan    = Application.Driver.MakeAttribute(Color.BrightCyan, Color.Black);
            var magenta = Application.Driver.MakeAttribute(Color.BrightMagenta, Color.Black);
            var red     = Application.Driver.MakeAttribute(Color.BrightRed, Color.Black);

            graphView.GraphColor = black;

            List <PointF> randomPoints = new List <PointF> ();

            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                randomPoints.Add(new PointF(r.Next(100), r.Next(100)));
            }

            var points = new ScatterSeries()
            {
                Points = randomPoints
            };

            var line = new PathAnnotation()
            {
                LineColor    = cyan,
                Points       = randomPoints.OrderBy(p => p.X).ToList(),
                BeforeSeries = true,
            };

            graphView.Series.Add(points);
            graphView.Annotations.Add(line);


            randomPoints = new List <PointF> ();

            for (int i = 0; i < 10; i++)
            {
                randomPoints.Add(new PointF(r.Next(100), r.Next(100)));
            }


            var points2 = new ScatterSeries()
            {
                Points = randomPoints,
                Fill   = new GraphCellToRender('x', red)
            };

            var line2 = new PathAnnotation()
            {
                LineColor    = magenta,
                Points       = randomPoints.OrderBy(p => p.X).ToList(),
                BeforeSeries = true,
            };

            graphView.Series.Add(points2);
            graphView.Annotations.Add(line2);

            // How much graph space each cell of the console depicts
            graphView.CellSize = new PointF(2, 5);

            // leave space for axis labels
            graphView.MarginBottom = 2;
            graphView.MarginLeft   = 3;

            // One axis tick/label per
            graphView.AxisX.Increment       = 20;
            graphView.AxisX.ShowLabelsEvery = 1;
            graphView.AxisX.Text            = "X →";

            graphView.AxisY.Increment       = 20;
            graphView.AxisY.ShowLabelsEvery = 1;
            graphView.AxisY.Text            = "↑Y";

            var max = line.Points.Union(line2.Points).OrderByDescending(p => p.Y).First();

            graphView.Annotations.Add(new TextAnnotation()
            {
                Text = "(Max)", GraphPosition = new PointF(max.X + (2 * graphView.CellSize.X), max.Y)
            });

            graphView.SetNeedsDisplay();
        }