Esempio n. 1
0
        public void MultiBarSeriesAddValues_WrongNumber()
        {
            // user asks for 3 bars per category
            var series = new MultiBarSeries(3, 7, 1);

            var ex = Assert.Throws <ArgumentException>(() => series.AddBars("Cars", '#', 1));

            Assert.Equal("Number of values must match the number of bars per category (Parameter 'values')", ex.Message);
        }
Esempio n. 2
0
        private void MultiBarGraph()
        {
            graphView.Reset();

            about.Text = "Housing Expenditures by income thirds 1996-2003";

            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;

            var series = new MultiBarSeries(3, 1, 0.25f, new [] { magenta, cyan, red });

            var stiple = Application.Driver.Stipple;

            series.AddBars("'96", stiple, 5900, 9000, 14000);
            series.AddBars("'97", stiple, 6100, 9200, 14800);
            series.AddBars("'98", stiple, 6000, 9300, 14600);
            series.AddBars("'99", stiple, 6100, 9400, 14950);
            series.AddBars("'00", stiple, 6200, 9500, 15200);
            series.AddBars("'01", stiple, 6250, 9900, 16000);
            series.AddBars("'02", stiple, 6600, 11000, 16700);
            series.AddBars("'03", stiple, 7000, 12000, 17000);

            graphView.CellSize = new PointF(0.25f, 1000);
            graphView.Series.Add(series);
            graphView.SetNeedsDisplay();

            graphView.MarginLeft   = 3;
            graphView.MarginBottom = 1;

            graphView.AxisY.LabelGetter = (v) => '$' + (v.Value / 1000f).ToString("N0") + 'k';

            // Do not show x axis labels (bars draw their own labels)
            graphView.AxisX.Increment       = 0;
            graphView.AxisX.ShowLabelsEvery = 0;
            graphView.AxisX.Minimum         = 0;


            graphView.AxisY.Minimum = 0;

            var legend = new LegendAnnotation(new Rect(graphView.Bounds.Width - 20, 0, 20, 5));

            legend.AddEntry(new GraphCellToRender(stiple, series.SubSeries.ElementAt(0).OverrideBarColor), "Lower Third");
            legend.AddEntry(new GraphCellToRender(stiple, series.SubSeries.ElementAt(1).OverrideBarColor), "Middle Third");
            legend.AddEntry(new GraphCellToRender(stiple, series.SubSeries.ElementAt(2).OverrideBarColor), "Upper Third");
            graphView.Annotations.Add(legend);
        }
Esempio n. 3
0
        private void SetupMultiBarSeries(DataTable dt, string countColumnName, int boundsWidth, int boundsHeight)
        {
            int numberOfBars = dt.Columns.Count - 1;
            var colors       = GetColors(numberOfBars).ToArray();
            var mediumStiple = '\u2592';

            graphView.GraphColor = Driver.MakeAttribute(Color.White, Color.Black);

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

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                legend.AddEntry(new GraphCellToRender(mediumStiple, colors[i - 1]), dt.Columns[i].ColumnName);
            }

            // Configure multi bar series
            var barSeries = new MultiBarSeries(numberOfBars, numberOfBars + 1, 1, colors);

            float min = 0;
            float max = 1;

            foreach (DataRow dr in dt.Rows)
            {
                var label = dr[0].ToString();

                if (string.IsNullOrWhiteSpace(label))
                {
                    label = "<Null>";
                }
                var vals = dr.ItemArray.Skip(1)
                           .Select(v => v == DBNull.Value ? 0 : (float)Convert.ToDouble(v)).ToArray();

                barSeries.AddBars(label, mediumStiple, vals);

                foreach (var val in vals)
                {
                    min = Math.Min(min, val);
                    max = Math.Max(max, val);
                }
            }

            // Configure Axis, Margins etc

            // make sure whole graph fits on axis
            float yIncrement = (max - min) / (boundsHeight - 2 /*MarginBottom*/);

            // 1 bar per row of console
            graphView.CellSize = new PointF(1, yIncrement);

            graphView.Series.Add(barSeries);
            graphView.MarginBottom = 2;
            graphView.MarginLeft   = (uint)(Math.Max(FormatValue(max, min, max).Length, FormatValue(min, min, max).Length)) + 1;

            // work out how to space x axis without scrolling
            graphView.AxisY.Increment       = yIncrement * 5;
            graphView.AxisY.ShowLabelsEvery = 1;
            graphView.AxisY.LabelGetter     = (v) => FormatValue(v.Value, min, max);
            graphView.AxisY.Text            = countColumnName;

            graphView.AxisX.Increment       = numberOfBars + 1;
            graphView.AxisX.ShowLabelsEvery = 1;
            graphView.AxisX.Increment       = 0;
            graphView.AxisX.Text            = dt.Columns[0].ColumnName;
        }
Esempio n. 4
0
        public void TestRendering_MultibarSeries()
        {
            GraphViewTests.InitFakeDriver();

            var gv = new GraphView();

            gv.ColorScheme = new ColorScheme();

            // y axis goes from 0.1 to 1 across 10 console rows
            // x axis goes from 0 to 20 across 20 console columns
            gv.Bounds       = new Rect(0, 0, 20, 10);
            gv.CellSize     = new PointF(1f, 0.1f);
            gv.MarginBottom = 1;
            gv.MarginLeft   = 1;

            var multibarSeries = new MultiBarSeries(2, 4, 1);

            //nudge them left to avoid float rounding errors at the boundaries of cells
            foreach (var sub in multibarSeries.SubSeries)
            {
                sub.Offset -= 0.001f;
            }

            gv.Series.Add(multibarSeries);

            FakeHAxis fakeXAxis;

            // don't show axis labels that means any labels
            // that appaer are explicitly from the bars
            gv.AxisX = fakeXAxis = new FakeHAxis()
            {
                Increment = 0
            };
            gv.AxisY = new FakeVAxis()
            {
                Increment = 0
            };

            gv.Redraw(gv.Bounds);

            // Since bar series has no bars yet no labels should be displayed
            Assert.Empty(fakeXAxis.LabelPoints);

            multibarSeries.AddBars("hey", 'M', 0.5001f, 0.5001f);
            fakeXAxis.LabelPoints.Clear();
            gv.Redraw(gv.Bounds);

            Assert.Equal(4, fakeXAxis.LabelPoints.Single());

            multibarSeries.AddBars("there", 'M', 0.24999f, 0.74999f);
            multibarSeries.AddBars("bob", 'M', 1, 2);
            fakeXAxis.LabelPoints.Clear();
            gv.Redraw(gv.Bounds);

            Assert.Equal(3, fakeXAxis.LabelPoints.Count);
            Assert.Equal(4, fakeXAxis.LabelPoints[0]);
            Assert.Equal(8, fakeXAxis.LabelPoints[1]);
            Assert.Equal(12, fakeXAxis.LabelPoints [2]);

            string looksLike =
                @" 
 │          MM
 │       M  MM
 │       M  MM
 │  MM   M  MM
 │  MM   M  MM
 │  MM   M  MM
 │  MM  MM  MM
 │  MM  MM  MM
 ┼──┬M──┬M──┬M──────
   heytherebob  ";

            GraphViewTests.AssertDriverContentsAre(looksLike);
        }