Esempio n. 1
0
        protected virtual Tick[] XAxisTicks(
            System.Drawing.RectangleF rectangle,
            System.Drawing.Graphics graphics,
            System.Drawing.Font font,
            Range range,
            bool isRangeNumeric,
            int xAxisScale,
            int xAxisPrecision,
            Bamboo.DataStructures.Table table)
        {
            float labelWidth = Math.Max(MeasureString(graphics, range.Min.ToString("N" + xAxisPrecision), font).Width, MeasureString(graphics, range.Max.ToString("N" + xAxisPrecision), font).Width);

            int availableSpaces = (int)Math.Floor(rectangle.Width / labelWidth);

            if (availableSpaces <= 1)
            {
                return(new Tick[0]);
            }
            else
            {
                decimal min          = Math.Floor(range.Min);
                decimal max          = Math.Ceiling(range.Max);
                decimal precision    = Power(10, xAxisPrecision);
                decimal neededSpaces = (max - min) * precision;

                decimal interval   = 1 / precision;
                int     multiplier = 2;
                while (neededSpaces > availableSpaces)
                {
                    if ((neededSpaces / multiplier) <= availableSpaces)
                    {
                        interval *= multiplier;
                        break;
                    }
                    multiplier++;
                }



                List <Tick> ticks = new List <Tick>();
                Tick        tick;
                decimal     value = min;
                while (value <= max)
                {
                    tick       = new Tick();
                    tick.Point = Coordinate(System.Convert.ToSingle(value), System.Convert.ToSingle(min), System.Convert.ToSingle(max), rectangle.Left, rectangle.Width, 0, 0, 1, rectangle.Top, rectangle.Height);
                    if (isRangeNumeric)
                    {
                        tick.Label = value.ToString("N" + xAxisPrecision);
                    }
                    else
                    {
                        tick.Label = table.Rows[(int)value][0].ToString();
                    }
                    ticks.Add(tick);
                    value += interval;
                }
                return(ticks.ToArray());
            }
        }
Esempio n. 2
0
        public OrderByIterator(Iterator iterator, List <Sort> orderBy)
        {
            this._iterator = iterator;
            this._orderBy  = orderBy;

            Bamboo.DataStructures.Table table = this._iterator.ToTable();
//TODO			table.Rows.Sort(new Bamboo.DataStructures.TupleComparer(GetOrdinals(columns)));
            this._sortedIterator = new TableIterator(table);
        }
Esempio n. 3
0
 public Bamboo.DataStructures.Table ToTable()
 {
     Bamboo.DataStructures.Table table = new Bamboo.DataStructures.Table(Columns(), new List <Bamboo.DataStructures.Tuple>());
     Bamboo.DataStructures.Tuple row;
     while ((row = Next()) != null)
     {
         table.Rows.Add(row);
     }
     return(table);
 }
Esempio n. 4
0
        public static Bamboo.DataStructures.Table Group(Bamboo.DataStructures.Table table, int[] columns)
        {
//TODO			table.Rows.Sort(new Bamboo.DataStructures.TupleComparer(GetOrdinals(columns)));

            int count         = table.Rows.Count;
            int columnsLength = columns.Length;

            object[] groupedColumns = new object[columnsLength];
            for (int k = 0; k < columnsLength; k++)
            {
                groupedColumns[k] = table.Columns[columns[k]];
            }

            List <Bamboo.DataStructures.Tuple> groupedRows = new List <Bamboo.DataStructures.Tuple>(table.Rows.Count);

            Bamboo.DataStructures.Tuple row = table.Rows[0];
            object[] groupedRow             = new object[columnsLength];
            for (int k = 0; k < columnsLength; k++)
            {
                groupedRow[k] = row[columns[k]];
            }
            groupedRows.Add(new Bamboo.DataStructures.Tuple(groupedRow));

            for (int i = 1; i < count; i++)
            {
                row = table.Rows[i];
                Bamboo.DataStructures.Tuple row2 = table.Rows[i - 1];

                bool rowEquals = true;
                for (int j = 0; j < columnsLength; j++)
                {
                    int cmp = System.Collections.Comparer.Default.Compare(row2[columns[j]], row[columns[j]]);
                    if (cmp != 0)
                    {
                        rowEquals = false;
                        break;
                    }
                }

                if (!rowEquals)
                {
                    groupedRow = new object[columnsLength];
                    for (int k = 0; k < columnsLength; k++)
                    {
                        groupedRow[k] = row[columns[k]];
                    }
                    groupedRows.Add(new Bamboo.DataStructures.Tuple(groupedRow));
                }
            }

            return(new Bamboo.DataStructures.Table(new Bamboo.DataStructures.Tuple(groupedColumns), groupedRows));
        }
Esempio n. 5
0
 public static Bamboo.DataStructures.Table Resolve(Database database, string name)
 {
     Bamboo.DataStructures.Table table = database.ReadTable(name);
     if (table == null)
     {
         Query view = database.ReadView(name);
         if (view != null)
         {
             table = Evaluate(database, view);
         }
     }
     return(table);
 }
Esempio n. 6
0
        private Bamboo.DataStructures.Table Read(Bamboo.DataStructures.Table table)
        {
            CsvParser parser = new CsvParser(new CsvTextReader(this._reader));

            while (this._reader.Peek() != -1)
            {
                Evaluate(parser.Parse());
                Bamboo.DataStructures.Tuple row = new Bamboo.DataStructures.Tuple(this._row.ToArray());
                this._row.Clear();
                if (table == null)
                {
                    table = new Bamboo.DataStructures.Table(row, new List <Bamboo.DataStructures.Tuple>());
                }
                else
                {
                    table.Rows.Add(row);
                }
            }

            return(table);
        }
Esempio n. 7
0
        public void Write(Bamboo.DataStructures.Table table)
        {
            bool first = true;

            for (int i = 0; i < table.Columns.Count; i++)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    this._writer.Write(",");
                }
                this._writer.Write(Escape(table.Columns[i]));
            }
            this._writer.Write("\r\n");
            foreach (Bamboo.DataStructures.Tuple row in table.Rows)
            {
                first = true;
                for (int i = 0; i < row.Count; i++)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        this._writer.Write(",");
                    }
                    object item = row[i];
                    if (item != null)
                    {
                        this._writer.Write(Escape(item));
                    }
                }
                this._writer.Write("\r\n");
            }
            this._writer.Flush();
        }
Esempio n. 8
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Charts.Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("ColumnGraph");



            string axisForeColor = (string)styleStack["AxisForeColor"];
            string axisLineColor = (string)styleStack["AxisLineColor"];
            string backColor     = (string)styleStack["BackColor"];

            Bamboo.Css.Font font          = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor     = (string)styleStack["ForeColor"];
            string          gridLineColor = (string)styleStack["GridLineColor"];
            int             padding       = (int)styleStack["Padding"];
            float           tickSize      = System.Convert.ToSingle(styleStack["TickSize"]);

            string[] colors = (string[])styleStack["Colors"];

            //TODO put in stylesheet
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            //TODO put in stylesheet
            System.Drawing.Font axisTickFont  = palette.Font(font.Name, font.Size * .66f);            //TODO put in stylesheet.
            System.Drawing.Font axisTitleFont = palette.Font(font.Name, font.Size, System.Drawing.FontStyle.Bold);

            System.Drawing.Brush axisForeColorBrush = palette.Brush(axisForeColor);
            System.Drawing.Pen   axisLineColorPen   = palette.Pen(axisLineColor);
            System.Drawing.Pen   backColorPen       = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush     = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush     = palette.Brush(foreColor);
            System.Drawing.Pen   gridLineColorPen   = palette.Pen(gridLineColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }

            //TODO
            // Legend
            rectangle = new System.Drawing.RectangleF(rectangle.Left, rectangle.Top, rectangle.Width - padding - padding, rectangle.Height);



            string  xAxisTitle      = table.Columns[0].ToString();
            decimal x_min           = 0;
            decimal x_max           = table.Rows.Count - 1;
            Range   xRange          = new Range(x_min, x_max);
            bool    isXRangeNumeric = true;
            int     xAxisScale      = 0;
            int     xAxisPrecision  = 0;


            string  yAxisTitle = table.Columns[1].ToString();
            decimal y0         = System.Convert.ToDecimal(table.Rows[0][1]);
            decimal y_min      = y0;
            decimal y_max      = y0;

            for (int j = 1; j < table.Rows.Count; j++)
            {
                for (int i = 1; i < table.Columns.Count; i++)
                {
                    decimal y = System.Convert.ToDecimal(table.Rows[j][i]);
                    if (y > y_max)
                    {
                        y_max = y;
                    }
                    else if (y < y_min)
                    {
                        y_min = y;
                    }
                }
            }
            y_min = Math.Min(0, y_min);
            Range yRange             = new Range(y_min, y_max);
            bool  isYRangeNumeric    = true;
            int   yAxisScale         = CalculateScale(yRange);
            int   yAxisPrecision     = Math.Max(0, 0 - yAxisScale);
            float maxYTickLabelWidth = Math.Max(
                MeasureString(graphics, y_min.ToString("N" + yAxisPrecision), axisTickFont).Width,
                MeasureString(graphics, y_max.ToString("N" + yAxisPrecision), axisTickFont).Width);



            System.Drawing.SizeF yAxisTitleSize = MeasureString(graphics, yAxisTitle, axisTitleFont);
            System.Drawing.SizeF xAxisTitleSize = MeasureString(graphics, xAxisTitle, axisTitleFont);
            float maxXTickLabelHeight           = MeasureString(graphics, "A", axisTickFont).Height;

            // Y-Axis Title
            rectangle = DrawYAxisTitle(graphics, rectangle, yAxisTitle, axisTitleFont, yAxisTitleSize, xAxisTitleSize.Height + maxXTickLabelHeight + tickSize, axisForeColorBrush);

            // X-Axis Title
            rectangle = DrawXAxisTitle(graphics, rectangle, xAxisTitle, axisTitleFont, xAxisTitleSize, yAxisTitleSize.Height + maxYTickLabelWidth + tickSize, axisForeColorBrush);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + maxYTickLabelWidth + tickSize, rectangle.Top, rectangle.Width - (maxYTickLabelWidth + tickSize), rectangle.Height - (maxXTickLabelHeight + tickSize));

            DrawYAxis(graphics, rectangle, YAxisTicks(rectangle, graphics, axisTickFont, yRange, isYRangeNumeric, yAxisScale, yAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);
            DrawXAxis(graphics, rectangle, XAxisTicks(rectangle, graphics, axisTickFont, xRange, isXRangeNumeric, xAxisScale, xAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + 1, rectangle.Top, rectangle.Width, rectangle.Height - 1);



            // Plot
            float barWidth = rectangle.Width / table.Rows.Count;
            float bottom   = (float)Math.Ceiling(rectangle.Top) + (float)Math.Ceiling(rectangle.Height);
            float x        = rectangle.Left;

            Bar[] bars = new Bar[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                Bamboo.DataStructures.Tuple row = table.Rows[i];

                System.Drawing.PointF point = Coordinate(i, System.Convert.ToSingle(xRange.Min), System.Convert.ToSingle(xRange.Max), rectangle.Left, rectangle.Width, System.Convert.ToSingle(row[1]), System.Convert.ToSingle(yRange.Min), System.Convert.ToSingle(yRange.Max), rectangle.Top, rectangle.Height);

                bars[i].X      = x;
                bars[i].Y      = (float)Math.Ceiling(point.Y);
                bars[i].Width  = barWidth;
                bars[i].Height = (float)Math.Ceiling(bottom - point.Y);
                bars[i].Brush  = palette.Brush(colors[i % colors.Length]);

                x += barWidth;                 //TODO this isn't pretty.
            }
            DrawBars(graphics, bars);



            styleStack.PopTag();
        }
Esempio n. 9
0
        protected override Tick[] XAxisTicks(System.Drawing.RectangleF rectangle, System.Drawing.Graphics graphics, System.Drawing.Font font, Range range, bool isRangeNumeric, int xAxisScale, int xAxisPrecision, Bamboo.DataStructures.Table table)
        {
            Tick[] xAxisTicks = new Tick[table.Rows.Count];
            float  barWidth   = rectangle.Width / table.Rows.Count;
            float  x          = rectangle.Left;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                Bamboo.DataStructures.Tuple row   = table.Rows[i];
                System.Drawing.PointF       point = Coordinate(i, System.Convert.ToSingle(range.Min), System.Convert.ToSingle(range.Max), rectangle.Left, rectangle.Width, 0, 0, 1, rectangle.Top, rectangle.Height);
                xAxisTicks[i].Point = new System.Drawing.PointF(x + (barWidth / 2), point.Y);
                xAxisTicks[i].Label = row[0].ToString();
                x += barWidth;                 //TODO this isn't pretty.
            }
            return(xAxisTicks);
        }
Esempio n. 10
0
 public TableIterator(Bamboo.DataStructures.Table table)         //TODO pass in a database instead of a table.
 {
     this._table = table;
     this._i     = 0;
 }
Esempio n. 11
0
 protected abstract void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table);
Esempio n. 12
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("LineGraph");



            string axisForeColor = (string)styleStack["AxisForeColor"];
            string axisLineColor = (string)styleStack["AxisLineColor"];
            string backColor     = (string)styleStack["BackColor"];

            Bamboo.Css.Font font          = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor     = (string)styleStack["ForeColor"];
            string          gridLineColor = (string)styleStack["GridLineColor"];
            float           lineWidth     = System.Convert.ToSingle(styleStack["LineWidth"]);
            int             padding       = (int)styleStack["Padding"];
            bool            showPoints    = (bool)styleStack["ShowPoints"];
            float           tickSize      = System.Convert.ToSingle(styleStack["TickSize"]);

            string[] colors = (string[])styleStack["Colors"];

            //TODO put in stylesheet
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            //TODO put in stylesheet
            System.Drawing.Font axisTickFont  = palette.Font(font.Name, font.Size * .66f);            //TODO put in stylesheet.
            System.Drawing.Font axisTitleFont = palette.Font(font.Name, font.Size, System.Drawing.FontStyle.Bold);

            System.Drawing.Brush axisForeColorBrush = palette.Brush(axisForeColor);
            System.Drawing.Pen   axisLineColorPen   = palette.Pen(axisLineColor);
            System.Drawing.Pen   backColorPen       = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush     = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush     = palette.Brush(foreColor);
            System.Drawing.Pen   gridLineColorPen   = palette.Pen(gridLineColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }

            //TODO
            // Legend
            rectangle = new System.Drawing.RectangleF(rectangle.Left, rectangle.Top, rectangle.Width - padding - padding, rectangle.Height);



            string  xAxisTitle      = table.Columns[0].ToString();
            decimal x_min           = 0;
            decimal x_max           = table.Rows.Count - 1;
            Range   xRange          = new Range(x_min, x_max);
            bool    isXRangeNumeric = IsNumeric(table.Rows[0][0]);
            int     xAxisScale      = CalculateScale(xRange);
            int     xAxisPrecision  = Math.Max(0, 0 - xAxisScale);


            string  yAxisTitle = table.Columns[1].ToString();
            decimal y0         = System.Convert.ToDecimal(table.Rows[0][1]);
            decimal y_min      = y0;
            decimal y_max      = y0;

            for (int j = 1; j < table.Rows.Count; j++)
            {
                for (int i = 1; i < table.Columns.Count; i++)
                {
                    decimal y = System.Convert.ToDecimal(table.Rows[j][i]);
                    if (y > y_max)
                    {
                        y_max = y;
                    }
                    else if (y < y_min)
                    {
                        y_min = y;
                    }
                }
            }
            Range yRange             = new Range(y_min, y_max);
            bool  isYRangeNumeric    = true;
            int   yAxisScale         = CalculateScale(yRange);
            int   yAxisPrecision     = Math.Max(0, 0 - yAxisScale);
            float maxYTickLabelWidth = Math.Max(
                MeasureString(graphics, y_min.ToString("N" + yAxisPrecision), axisTickFont).Width,
                MeasureString(graphics, y_max.ToString("N" + yAxisPrecision), axisTickFont).Width);



            System.Drawing.SizeF yAxisTitleSize = MeasureString(graphics, yAxisTitle, axisTitleFont);
            System.Drawing.SizeF xAxisTitleSize = MeasureString(graphics, xAxisTitle, axisTitleFont);
            float maxXTickLabelHeight           = MeasureString(graphics, "A", axisTickFont).Height;

            // Y-Axis Title
            rectangle = DrawYAxisTitle(graphics, rectangle, yAxisTitle, axisTitleFont, yAxisTitleSize, xAxisTitleSize.Height + maxXTickLabelHeight + tickSize, axisForeColorBrush);

            // X-Axis Title
            rectangle = DrawXAxisTitle(graphics, rectangle, xAxisTitle, axisTitleFont, xAxisTitleSize, yAxisTitleSize.Height + maxYTickLabelWidth + tickSize, axisForeColorBrush);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + maxYTickLabelWidth + tickSize, rectangle.Top, rectangle.Width - (maxYTickLabelWidth + tickSize), rectangle.Height - (maxXTickLabelHeight + tickSize));

            DrawYAxis(graphics, rectangle, YAxisTicks(rectangle, graphics, axisTickFont, yRange, isYRangeNumeric, yAxisScale, yAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);
            DrawXAxis(graphics, rectangle, XAxisTicks(rectangle, graphics, axisTickFont, xRange, isXRangeNumeric, xAxisScale, xAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + 1, rectangle.Top, rectangle.Width - 1, rectangle.Height - 1);



            // Plot
            float pointRadius = lineWidth * 2f;             //TODO put in stylesheet.

            Line[] lines = new Line[table.Columns.Count - 1];
            for (int i = 1; i < table.Columns.Count; i++)
            {
                lines[i - 1].Pen   = palette.Pen(colors[(i - 1) % colors.Length], lineWidth);
                lines[i - 1].Brush = palette.Brush(colors[(i - 1) % colors.Length]);

                lines[i - 1].Points = new Point[table.Rows.Count];
                for (int j = 0; j < table.Rows.Count; j++)
                {
                    float value = System.Convert.ToSingle(table.Rows[j][i]);
                    System.Drawing.PointF point = Coordinate(j, System.Convert.ToSingle(xRange.Min), System.Convert.ToSingle(xRange.Max), rectangle.Left, rectangle.Width, value, System.Convert.ToSingle(yRange.Min), System.Convert.ToSingle(yRange.Max), rectangle.Top, rectangle.Height);
                    lines[i - 1].Points[j].X = point.X;
                    lines[i - 1].Points[j].Y = point.Y;
                }
            }
            DrawLines(graphics, lines);
            if (showPoints)
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    System.Drawing.PointF[] points = new System.Drawing.PointF[lines[i].Points.Length - 1];
                    for (int j = 1; j < points.Length; j++)
                    {
                        points[j - 1] = new System.Drawing.PointF(lines[i].Points[j].X, lines[i].Points[j].Y);
                    }
                    DrawPoints(graphics, lines[i].Brush, points, pointRadius);
                }
            }



            styleStack.PopTag();
        }
Esempio n. 13
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("Table");



            string backColor = (string)styleStack["BackColor"];

            Bamboo.Css.Font font      = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor = (string)styleStack["ForeColor"];
            int             padding   = (int)styleStack["Padding"];

            //TODO put in stylesheet
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            System.Drawing.Pen   backColorPen   = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush = palette.Brush(foreColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }



            int width  = table.Columns.Count;
            int height = table.Rows.Count;

            List <Cell[]> cellsList = new List <Cell[]>(height + 1);

            Cell[] cells;

            styleStack.PushTag("Header");
            backColor = (string)styleStack["BackColor"];
            foreColor = (string)styleStack["ForeColor"];
            System.Drawing.ContentAlignment textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
            cells = new Cell[width];
            for (int x = 0; x < width; x++)
            {
                cells[x].HasValue        = true;
                cells[x].Type            = CellType.Header;
                cells[x].Colspan         = 1;
                cells[x].Rowspan         = 1;
                cells[x].Value           = table.Columns[x];
                cells[x].BackgroundColor = backColor;
                cells[x].ForegroundColor = foreColor;
                cells[x].TextAlign       = textAlign;
            }
            cellsList.Add(cells);
            styleStack.PopTag();


            styleStack.PushTag("Cell");
            backColor = (string)styleStack["BackColor"];
            foreColor = (string)styleStack["ForeColor"];
            textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
            for (int y = 0; y < height; y++)
            {
                Bamboo.DataStructures.Tuple row = table.Rows[y];
                cells = new Cell[width];
                for (int x = 0; x < width; x++)
                {
                    //TODO push cell.
                    cells[x].HasValue        = true;
                    cells[x].Type            = CellType.Cell;
                    cells[x].Colspan         = 1;
                    cells[x].Rowspan         = 1;
                    cells[x].Value           = row[x];
                    cells[x].BackgroundColor = backColor;
                    cells[x].ForegroundColor = foreColor;
                    cells[x].TextAlign       = textAlign;
                }
                cellsList.Add(cells);
            }
            styleStack.PopTag();


            Render(graphics, palette, styleStack, cellsList, rectangle);



            styleStack.PopTag();
        }
Esempio n. 14
0
        private void Run()
        {
            if (System.IO.Directory.Exists(this._path))
            {
                foreach (string file in System.IO.Directory.GetFiles(this._path))
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
                    if (!fileInfo.Name.EndsWith(".tmp"))
                    {
                        System.IO.Stream stream    = System.IO.File.OpenRead(file);
                        JobReader        jobReader = new JobReader(stream);
                        Job job = jobReader.Read();
                        this._jobs.Add(job.Name, job);
                        stream.Close();
                    }
                }
            }


            Bamboo.DataStructures.Table jobTimes       = this._database.ReadTable("Statibase.JobSummary");
            Dictionary <string, long>   jobTimesLookup = new Dictionary <string, long>();

            foreach (Bamboo.DataStructures.Tuple row in jobTimes.Rows)
            {
                jobTimesLookup.Add((string)row[0], (long)row[1]);
            }


            while (true)
            {
                List <Job> jobs = new List <Job>();
                lock (this._sync)
                {
                    foreach (Job job in this._jobs.Values)
                    {
                        jobs.Add(job);
                    }
                }

                System.DateTime now2 = System.DateTime.Now;
                long            now  = now2.Ticks;

                foreach (Job job in jobs)
                {
                    //TODO do this in memory.
                    long lastRun = 0;
                    if (jobTimesLookup.ContainsKey(job.Name))
                    {
                        lastRun = jobTimesLookup[job.Name];
                    }


                    switch (job.Type)
                    {
                    case JobType.Interval:
                    {
                        long next = lastRun + job.Interval.Ticks;
                        if (next < now)
                        {
                            this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                            jobTimesLookup[job.Name] = now;
                        }
                        break;
                    }

                    case JobType.Daily:
                    {
                        System.DateTime lastRunDate = new System.DateTime(lastRun);
                        if (!lastRunDate.Date.Equals(now2.Date) && job.Time.TimeOfDay < now2.TimeOfDay)
                        {
                            this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                            jobTimesLookup[job.Name] = now;
                        }
                        break;
                    }

                    case JobType.Weekly:
                    {
                        if (job.Days.Contains(GetDay(System.DateTime.Now.DayOfWeek)))
                        {
                            System.DateTime lastRunDate = new System.DateTime(lastRun);
                            if (!lastRunDate.Date.Equals(now2.Date) && job.Time.TimeOfDay < now2.TimeOfDay)
                            {
                                this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                                jobTimesLookup[job.Name] = now;
                            }
                        }
                        break;
                    }
                    }
                }

                System.Threading.Thread.Sleep(500);
            }
        }
Esempio n. 15
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("Table");



            string backColor = (string)styleStack["BackColor"];

            Bamboo.Css.Font font      = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor = (string)styleStack["ForeColor"];
            int             padding   = (int)styleStack["Padding"];

            //TODO put in stylesheet
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            System.Drawing.Pen   backColorPen   = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush = palette.Brush(foreColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }



            List <Cell[]> cellsList = new List <Cell[]>();

            Cell[] cells;
            int    x;
            int    y = 0;


            //
            // Get a table of column headers.
            //
            int[] columnHeaders = new int[this._columnColumns.Count];
            for (int i = 0; i < columnHeaders.Length; i++)
            {
                columnHeaders[i] = i;
            }
            Bamboo.DataStructures.Table columnHeadersTable = Bamboo.Sql2.Iterators.GroupByIterator.Group(table, columnHeaders);


            //
            // Calculate the width of the cell arrays (i.e., table rows).
            //
            int width = (this._columnColumns.Count == 0) ? this._rowColumns.Count + this._dataColumns.Count : this._rowColumns.Count + (columnHeadersTable.Rows.Count * this._dataColumns.Count);


            //
            // Create the column headers.
            //
            styleStack.PushTag("Header");
            backColor = (string)styleStack["BackColor"];
            foreColor = (string)styleStack["ForeColor"];
            System.Drawing.ContentAlignment textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
            for (int i = 0; i < this._columnColumns.Count; i++)
            {
                cells = new Cell[width];
                cellsList.Add(cells);
                x = this._rowColumns.Count;
                Bamboo.DataStructures.Tuple row = null;
                for (int j = 0; j < columnHeadersTable.Rows.Count; j++)
                {
                    Bamboo.DataStructures.Tuple row2 = columnHeadersTable.Rows[j];
                    if (row == null || !row.Equals(0, row2, 0, i + 1))
                    {
                        //TODO push header
//						Bamboo.Css.StyleRule styleRule = GetStyle(styleSheet, "Header", this2._columnColumns, row2, i + 1);

                        cells[x].HasValue = true;
                        cells[x].Type     = CellType.Header;
                        cells[x].Colspan  = this._dataColumns.Count;
                        cells[x].Rowspan  = 1;
                        cells[x].Value    = row2[i];
//						if (styleRule == null)
//						{
                        cells[x].BackgroundColor = backColor;
                        cells[x].ForegroundColor = foreColor;
                        cells[x].TextAlign       = textAlign;
//						}
//						else
//						{
//							cells[x].BackgroundColor = (string)styleRule["BackColor"];
//							cells[x].ForegroundColor = (string)styleRule["ForeColor"];
//							cells[x].TextAlign = (System.Drawing.ContentAlignment)styleRule["TextAlign"];
//						}
                    }
                    else
                    {
                        int k     = 1;
                        int index = x - k;
                        k++;
                        while (cells[index].Colspan == 0)
                        {
                            index = x - k;
                            k++;
                        }
                        cells[index].Colspan += this._dataColumns.Count;
                    }
                    row = row2;
                    x  += this._dataColumns.Count;
                }
                y++;
            }

            cells = new Cell[width];
            cellsList.Add(cells);
            x = this._rowColumns.Count;
            for (int i = 0; i < Math.Max(columnHeadersTable.Rows.Count, 1); i++)
            {
                for (int k = 0; k < this._dataColumns.Count; k++)
                {
//					Bamboo.Css.StyleRule styleRule = GetStyle(styleSheet, new Statibase.Tuple(new object[] { this2._dataColumns[k] }), 0, 1);

                    cells[x].HasValue = true;
                    cells[x].Type     = CellType.Header;
                    cells[x].Colspan  = 1;
                    cells[x].Rowspan  = 1;
                    cells[x].Value    = this._dataColumns[k];
//					if (styleRule == null)
//					{
                    cells[x].BackgroundColor = backColor;
                    cells[x].ForegroundColor = foreColor;
                    cells[x].TextAlign       = textAlign;
//					}
//					else
//					{
//						cells[x].BackgroundColor = (string)styleRule["BackColor"];
//						cells[x].ForegroundColor = (string)styleRule["ForeColor"];
//						cells[x].TextAlign = (System.Drawing.ContentAlignment)styleRule["TextAlign"];
//					}
                    x++;
                }
            }
            y++;
            styleStack.PopTag();



            backColor = (string)styleStack["BackColor"];

            //
            // Add the empty cell if necessary.
            //
            if (this._rowColumns.Count > 0)
            {
                cellsList[0][0].HasValue        = true;
                cellsList[0][0].Type            = CellType.Empty;
                cellsList[0][0].Colspan         = this._rowColumns.Count;
                cellsList[0][0].Rowspan         = this._columnColumns.Count + 1;
                cellsList[0][0].BackgroundColor = backColor;
            }



            //
            // Get a table of row headers.
            //
            int[] rowHeadersPlusData = new int[this._columnColumns.Count + this._rowColumns.Count + this._dataColumns.Count];
            int   ii = 0;

            for (int i = 0; i < this._rowColumns.Count; i++)
            {
                rowHeadersPlusData[ii] = this._columnColumns.Count + i;
                ii++;
            }
            for (int i = 0; i < this._columnColumns.Count; i++)
            {
                rowHeadersPlusData[ii] = i;
                ii++;
            }
            for (int i = 0; i < this._dataColumns.Count; i++)
            {
                rowHeadersPlusData[ii] = this._columnColumns.Count + this._rowColumns.Count + i;;
                ii++;
            }
            table = Bamboo.Sql2.Iterators.OrderByIterator.Sort(table, rowHeadersPlusData);


            //
            // Fill in the row headers and data.
            //
            if (this._rowColumns.Count > 0)
            {
                int[] rowHeaderIndexes = new int[this._rowColumns.Count];
                int[] yPositions       = new int[columnHeadersTable.Rows.Count + 1];

                cells = new Cell[width];
                styleStack.PushTag("Header");
                backColor = (string)styleStack["BackColor"];
                foreColor = (string)styleStack["ForeColor"];
                textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
                for (int j = 0; j < this._rowColumns.Count; j++)
                {
//					Bamboo.Css.StyleRule styleRule = GetStyle(styleSheet, table.Rows[0], this2._columnColumns.Count + j, 1);

                    cells[j].HasValue = true;
                    cells[j].Type     = CellType.Header;
                    cells[j].Colspan  = 1;
                    cells[j].Rowspan  = 1;
                    cells[j].Value    = table.Rows[0][this._columnColumns.Count + j];
//					if (styleRule == null)
//					{
                    cells[j].BackgroundColor = backColor;
                    cells[j].ForegroundColor = foreColor;
                    cells[j].TextAlign       = textAlign;
//					}
//					else
//					{
//						cells[j].BackgroundColor = (string)styleRule["BackColor"];
//						cells[j].ForegroundColor = (string)styleRule["ForeColor"];
//						cells[j].TextAlign = (System.Drawing.ContentAlignment)styleRule["TextAlign"];
//					}
                    rowHeaderIndexes[j] = cellsList.Count;
                }
                styleStack.PopTag();

                styleStack.PushTag("Cell");
                backColor = (string)styleStack["BackColor"];
                foreColor = (string)styleStack["ForeColor"];
                textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
                for (int k = this._rowColumns.Count; k < width; k++)
                {
                    cells[k].HasValue        = true;
                    cells[k].Type            = CellType.Cell;
                    cells[k].Colspan         = 1;
                    cells[k].Rowspan         = 1;
                    cells[k].BackgroundColor = backColor;
                    cells[k].ForegroundColor = foreColor;
                    cells[k].TextAlign       = textAlign;
                }
                styleStack.PopTag();

                for (int l = 0; l < yPositions.Length; l++)
                {
                    yPositions[l] = cellsList.Count;
                }
                cellsList.Add(cells);


                Bamboo.DataStructures.Tuple previousRow = null;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    Bamboo.DataStructures.Tuple row = table.Rows[i];

                    if (previousRow != null)
                    {
                        for (int j = 0; j < this._rowColumns.Count; j++)
                        {
                            //TODO use an array of values instead of fetching the last row.
                            if (!cellsList[rowHeaderIndexes[j]][j].Value.Equals(row[this._columnColumns.Count + j]))
                            {
//								Bamboo.Css.StyleRule styleRule = GetStyle(styleSheet, row, this2._columnColumns.Count + j, 1);
                                styleStack.PushTag("Header");
                                backColor = (string)styleStack["BackColor"];
                                foreColor = (string)styleStack["ForeColor"];
                                textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];

                                // The row keys have changed.  Write a new row.
                                cells = new Cell[width];

                                cells[j].HasValue = true;
                                cells[j].Type     = CellType.Header;
                                cells[j].Colspan  = 1;
                                cells[j].Rowspan  = 1;
                                cells[j].Value    = row[this._columnColumns.Count + j];
//								if (styleRule == null)
//								{
                                cells[j].BackgroundColor = backColor;
                                cells[j].ForegroundColor = foreColor;
                                cells[j].TextAlign       = textAlign;
//								}
//								else
//								{
//									cells[j].BackgroundColor = (string)styleRule["BackColor"];
//									cells[j].ForegroundColor = (string)styleRule["ForeColor"];
//									cells[j].TextAlign = (System.Drawing.ContentAlignment)styleRule["TextAlign"];
//								}
                                rowHeaderIndexes[j] = cellsList.Count;

                                for (int k = 0; k < j; k++)
                                {
                                    cellsList[rowHeaderIndexes[k]][k].Rowspan++;
                                }
                                for (int k = (j + 1); k < this._rowColumns.Count; k++)
                                {
                                    cells[k].HasValue = true;
                                    cells[k].Type     = CellType.Header;
                                    cells[k].Colspan  = 1;
                                    cells[k].Rowspan  = 1;
                                    cells[k].Value    = row[this._columnColumns.Count + k];
//									if (styleRule == null)
//									{
                                    cells[k].BackgroundColor = backColor;
                                    cells[k].ForegroundColor = foreColor;
                                    cells[k].TextAlign       = textAlign;
//									}
//									else
//									{
//										cells[k].BackgroundColor = (string)styleRule["BackColor"];
//										cells[k].ForegroundColor = (string)styleRule["ForeColor"];
//										cells[k].TextAlign = (System.Drawing.ContentAlignment)styleRule["TextAlign"];
//									}
                                    rowHeaderIndexes[k] = cellsList.Count;
                                }
                                styleStack.PopTag();

                                styleStack.PushTag("Cell");
                                backColor = (string)styleStack["BackColor"];
                                foreColor = (string)styleStack["ForeColor"];
                                textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
                                for (int k = this._rowColumns.Count; k < width; k++)
                                {
                                    cells[k].HasValue        = true;
                                    cells[k].Type            = CellType.Cell;
                                    cells[k].Colspan         = 1;
                                    cells[k].Rowspan         = 1;
                                    cells[k].BackgroundColor = backColor;
                                    cells[k].ForegroundColor = foreColor;
                                    cells[k].TextAlign       = textAlign;
                                }
                                styleStack.PopTag();

                                for (int l = 0; l < yPositions.Length; l++)
                                {
                                    yPositions[l] = cellsList.Count;
                                }
                                cellsList.Add(cells);
                                break;
                            }
                        }
                    }



                    if (columnHeadersTable.Rows.Count == 0)
                    {
                        int columnNumber = 0;
                        x = (columnNumber * this._dataColumns.Count) + this._rowColumns.Count;
                        y = yPositions[columnNumber];

                        while (y >= cellsList.Count)
                        {
                            cells = new Cell[width];

                            for (int k = 0; k < this._rowColumns.Count; k++)
                            {
                                cellsList[rowHeaderIndexes[k]][k].Rowspan++;
                            }

                            styleStack.PushTag("Cell");
                            backColor = (string)styleStack["BackColor"];
                            foreColor = (string)styleStack["ForeColor"];
                            textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
                            for (int k = this._rowColumns.Count; k < width; k++)
                            {
                                cells[k].HasValue        = true;
                                cells[k].Type            = CellType.Cell;
                                cells[k].Colspan         = 1;
                                cells[k].Rowspan         = 1;
                                cells[k].BackgroundColor = backColor;
                                cells[k].ForegroundColor = foreColor;
                                cells[k].TextAlign       = textAlign;
                            }
                            styleStack.PopTag();

                            cellsList.Add(cells);
                        }

                        for (int j = 0; j < this._dataColumns.Count; j++)
                        {
                            cellsList[y][x + j].Value = row[this._columnColumns.Count + this._rowColumns.Count + j];
                        }
                        yPositions[columnNumber]++;
                    }
                    else
                    {
                        for (int m = 0; m < columnHeadersTable.Rows.Count; m++)
                        {
                            Bamboo.DataStructures.Tuple columnRow = columnHeadersTable.Rows[m];
                            if (row.Equals(0, columnRow, 0, this._columnColumns.Count))
                            {
                                int columnNumber = m;
                                x = (columnNumber * this._dataColumns.Count) + this._rowColumns.Count;
                                y = yPositions[columnNumber];

                                while (y >= cellsList.Count)
                                {
                                    cells = new Cell[width];

                                    for (int k = 0; k < this._rowColumns.Count; k++)
                                    {
                                        cellsList[rowHeaderIndexes[k]][k].Rowspan++;
                                    }

                                    styleStack.PushTag("Cell");
                                    backColor = (string)styleStack["BackColor"];
                                    foreColor = (string)styleStack["ForeColor"];
                                    textAlign = (System.Drawing.ContentAlignment)styleStack["TextAlign"];
                                    for (int k = this._rowColumns.Count; k < width; k++)
                                    {
                                        cells[k].HasValue        = true;
                                        cells[k].Type            = CellType.Cell;
                                        cells[k].Colspan         = 1;
                                        cells[k].Rowspan         = 1;
                                        cells[k].BackgroundColor = backColor;
                                        cells[k].ForegroundColor = foreColor;
                                        cells[k].TextAlign       = textAlign;
                                    }
                                    styleStack.PopTag();

                                    cellsList.Add(cells);
                                }

                                for (int j = 0; j < this._dataColumns.Count; j++)
                                {
                                    cellsList[y][x + j].Value = row[this._columnColumns.Count + this._rowColumns.Count + j];
                                }
                                yPositions[columnNumber]++;
                                break;
                            }
                        }
                    }



                    previousRow = row;
                }
            }


            Render(graphics, palette, styleStack, cellsList, rectangle);



            styleStack.PopTag();
        }
Esempio n. 16
0
        private static Iterators.Iterator CreateIterator(Database database, SelectStatement select)
        {
            // From
            if (select.From.Count > 1)
            {
                throw new System.Exception("Multiple tables in FROM not supported.");
            }
            string tableName = TableName(select.From[0]);

            Bamboo.DataStructures.Table table    = Resolve(database, tableName);
            Iterators.Iterator          iterator = new Iterators.TableIterator(table);

            // Join
            if (select.Joins != null)
            {
                foreach (object join in select.Joins)
                {
                    if (join is InnerJoin)
                    {
                        iterator = new Iterators.InnerJoinIterator(iterator, (InnerJoin)join);
                    }
                    else if (join is LeftOuterJoin)
                    {
                        iterator = new Iterators.LeftOuterJoinIterator(iterator, (LeftOuterJoin)join);
                    }
                    else if (join is RightOuterJoin)
                    {
                        iterator = new Iterators.RightOuterJoinIterator(iterator, (RightOuterJoin)join);
                    }
                    else
                    {
                        throw new System.Exception("Invalid join: " + join.GetType().FullName);
                    }
                }
            }

            // Where
            if (select.Where != null)
            {
                iterator = new Iterators.WhereIterator(iterator, CreatePredicate(select.Where, iterator));
            }

            // Group
            if (select.GroupBy != null)
            {
                iterator = new Iterators.GroupByIterator(iterator, GetOrdinals(select.GroupBy, iterator.Columns()));
            }

            // Order
            if (select.OrderBy != null)
            {
                iterator = new Iterators.OrderByIterator(iterator, select.OrderBy);
            }

            // Select
            List <Iterators.ColumnIterator> columnIterators = new List <Iterators.ColumnIterator>();

            foreach (object column in select.Columns)
            {
                if (column is Identifier && ((Identifier)column).Value.Equals("*"))
                {
                    if (select.From.Count == 1)
                    {
                        for (int i = 0; i < table.Columns.Count; i++)
                        {
                            columnIterators.Add(new Iterators.ColumnIterator(GetOrdinal(table.Columns[i], iterator.Columns()), (string)table.Columns[i]));
                        }
                    }
                    else
                    {
                        throw new System.Exception("Multiple tables in FROM not supported.");
                    }
                }
                else
                {
                    columnIterators.Add(CreateColumnIterator(column, iterator));
                }
            }
            iterator = new Iterators.SelectIterator(iterator, columnIterators);

            return(iterator);
        }
Esempio n. 17
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("ScatterGraph");



            string axisForeColor = (string)styleStack["AxisForeColor"];
            string axisLineColor = (string)styleStack["AxisLineColor"];
            string backColor     = (string)styleStack["BackColor"];

            Bamboo.Css.Font font          = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor     = (string)styleStack["ForeColor"];
            string          gridLineColor = (string)styleStack["GridLineColor"];
            int             padding       = (int)styleStack["Padding"];
            float           pointRadius   = System.Convert.ToSingle(styleStack["PointRadius"]);
            float           tickSize      = System.Convert.ToSingle(styleStack["TickSize"]);

            string[] colors = (string[])styleStack["Colors"];

            //TODO put in stylesheet
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            //TODO put in stylesheet
            System.Drawing.Font axisTickFont  = palette.Font(font.Name, font.Size * .66f);            //TODO put in stylesheet.
            System.Drawing.Font axisTitleFont = palette.Font(font.Name, font.Size, System.Drawing.FontStyle.Bold);

            System.Drawing.Brush axisForeColorBrush = palette.Brush(axisForeColor);
            System.Drawing.Pen   axisLineColorPen   = palette.Pen(axisLineColor);
            System.Drawing.Pen   backColorPen       = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush     = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush     = palette.Brush(foreColor);
            System.Drawing.Pen   gridLineColorPen   = palette.Pen(gridLineColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }

            //TODO
            // Legend
            rectangle = new System.Drawing.RectangleF(rectangle.Left, rectangle.Top, rectangle.Width - padding - padding, rectangle.Height);



            string  xAxisTitle = table.Columns[0].ToString();
            decimal x0         = System.Convert.ToDecimal(table.Rows[0][0]);
            decimal x_min      = x0;
            decimal x_max      = x0;

            for (int i = 1; i < table.Rows.Count; i++)
            {
                decimal x = System.Convert.ToDecimal(table.Rows[i][0]);
                if (x > x_max)
                {
                    x_max = x;
                }
                else if (x < x_min)
                {
                    x_min = x;
                }
            }
            Range xRange          = new Range(x_min, x_max);
            bool  isXRangeNumeric = true;
            int   xAxisScale      = CalculateScale(xRange);
            int   xAxisPrecision  = Math.Max(0, 0 - xAxisScale);


            string  yAxisTitle = table.Columns[1].ToString();
            decimal y0         = System.Convert.ToDecimal(table.Rows[0][1]);
            decimal y_min      = y0;
            decimal y_max      = y0;

            for (int j = 1; j < table.Rows.Count; j++)
            {
                for (int i = 1; i < table.Columns.Count; i++)
                {
                    decimal y = System.Convert.ToDecimal(table.Rows[j][i]);
                    if (y > y_max)
                    {
                        y_max = y;
                    }
                    else if (y < y_min)
                    {
                        y_min = y;
                    }
                }
            }
            Range yRange             = new Range(y_min, y_max);
            bool  isYRangeNumeric    = true;
            int   yAxisScale         = CalculateScale(yRange);
            int   yAxisPrecision     = Math.Max(0, 0 - yAxisScale);
            float maxYTickLabelWidth = Math.Max(
                MeasureString(graphics, y_min.ToString("N" + yAxisPrecision), axisTickFont).Width,
                MeasureString(graphics, y_max.ToString("N" + yAxisPrecision), axisTickFont).Width);



            System.Drawing.SizeF yAxisTitleSize = MeasureString(graphics, yAxisTitle, axisTitleFont);
            System.Drawing.SizeF xAxisTitleSize = MeasureString(graphics, xAxisTitle, axisTitleFont);
            float maxXTickLabelHeight           = MeasureString(graphics, "A", axisTickFont).Height;

            // Y-Axis Title
            rectangle = DrawYAxisTitle(graphics, rectangle, yAxisTitle, axisTitleFont, yAxisTitleSize, xAxisTitleSize.Height + maxXTickLabelHeight + tickSize, axisForeColorBrush);

            // X-Axis Title
            rectangle = DrawXAxisTitle(graphics, rectangle, xAxisTitle, axisTitleFont, xAxisTitleSize, yAxisTitleSize.Height + maxYTickLabelWidth + tickSize, axisForeColorBrush);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + maxYTickLabelWidth + tickSize, rectangle.Top, rectangle.Width - (maxYTickLabelWidth + tickSize), rectangle.Height - (maxXTickLabelHeight + tickSize));

            DrawYAxis(graphics, rectangle, YAxisTicks(rectangle, graphics, axisTickFont, yRange, isYRangeNumeric, yAxisScale, yAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);
            DrawXAxis(graphics, rectangle, XAxisTicks(rectangle, graphics, axisTickFont, xRange, isXRangeNumeric, xAxisScale, xAxisPrecision, table), tickSize, axisTickFont, gridLineColorPen, axisLineColorPen, axisForeColorBrush, true);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + 1, rectangle.Top, rectangle.Width - 1, rectangle.Height - 1);



            // Plot
//			graphics.FillRectangle(B.WhiteSmoke, canvasX, canvasY - canvasHeight, canvasWidth, canvasHeight);
            System.Drawing.PointF[] points = new System.Drawing.PointF[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                Bamboo.DataStructures.Tuple row = table.Rows[i];
                points[i] = Coordinate(System.Convert.ToSingle(row[0]), System.Convert.ToSingle(xRange.Min), System.Convert.ToSingle(xRange.Max), rectangle.Left, rectangle.Width, System.Convert.ToSingle(row[1]), System.Convert.ToSingle(yRange.Min), System.Convert.ToSingle(yRange.Max), rectangle.Top, rectangle.Height);
            }
            DrawPoints(graphics, palette.Brush(colors[0]), points, pointRadius);



            styleStack.PopTag();
        }
Esempio n. 18
0
        protected override void RenderChart(System.Drawing.Graphics graphics, Palette palette, Bamboo.Css.StyleStack styleStack, System.Drawing.RectangleF rectangle, string title, Bamboo.DataStructures.Table table)
        {
            styleStack.PushTag("PieChart");



            string backColor = (string)styleStack["BackColor"];

            Bamboo.Css.Font font      = (Bamboo.Css.Font)styleStack["Font"];
            string          foreColor = (string)styleStack["ForeColor"];
            int             padding   = (int)styleStack["Padding"];

            string[] colors = (string[])styleStack["Colors"];

            //TODO put in stylesheet.
            System.Drawing.Font titleFont = palette.Font(font.Name, font.Size * 1.2f, System.Drawing.FontStyle.Bold);

            //TODO put in stylesheet.
            System.Drawing.Font labelFont = palette.Font(font.Name, font.Size, System.Drawing.FontStyle.Bold);

            System.Drawing.Pen   backColorPen   = palette.Pen(backColor);
            System.Drawing.Brush backColorBrush = palette.Brush(backColor);
            System.Drawing.Brush foreColorBrush = palette.Brush(foreColor);



            // Background
            graphics.DrawRectangle(backColorPen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
            graphics.FillRectangle(backColorBrush, rectangle);
            rectangle = new System.Drawing.RectangleF(rectangle.Left + padding, rectangle.Top + padding, rectangle.Width - padding - padding, rectangle.Height - padding - padding);

            // Title
            if (title != null)
            {
                rectangle = DrawTitle(title, titleFont, foreColorBrush, graphics, rectangle);
            }

            //TODO
            // Legend
//			rectangle = new System.Drawing.RectangleF(rectangle.Left, rectangle.Top, rectangle.Width - padding - padding, rectangle.Height);



            Slice[] slices = new Slice[table.Rows.Count];
            float   sum    = 0;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                Bamboo.DataStructures.Tuple row = table.Rows[i];

                slices[i].Label = row[0].ToString();

                float value = System.Convert.ToSingle(row[1]);
                slices[i].Value = value;

                sum += value;
            }
            sum /= 360;



            float startAngle = -90;

            for (int i = 0; i < slices.Length; i++)
            {
                slices[i].StartAngle = startAngle;

                float sweepAngle = slices[i].Value / sum;
                slices[i].SweepAngle = sweepAngle;

                double startPlusHalfSweepRadian = DegreeToRadian(startAngle + (sweepAngle / 2));
                slices[i].LabelCos = (float)Math.Cos(startPlusHalfSweepRadian);
                slices[i].LabelSin = (float)Math.Sin(startPlusHalfSweepRadian);

                System.Drawing.SizeF sizef = MeasureString(graphics, slices[i].Label, labelFont);
                slices[i].LabelWidth  = sizef.Width;
                slices[i].LabelHeight = sizef.Height;

                slices[i].Adjacent   = slices[i].LabelCos * slices[i].LabelWidth;
                slices[i].Opposite   = slices[i].LabelSin * slices[i].LabelHeight;
                slices[i].Hypotenuse = (float)Math.Sqrt((slices[i].Adjacent * slices[i].Adjacent) + (slices[i].Opposite * slices[i].Opposite));

                slices[i].Brush = palette.Brush(colors[i % colors.Length]);

                startAngle += sweepAngle;
            }



            float x_min = 0;
            float x_max = 0;
            float y_min = 0;
            float y_max = 0;

            for (int i = 0; i < slices.Length; i++)
            {
                x_min = Math.Min(x_min, slices[i].Adjacent);
                x_max = Math.Max(x_max, slices[i].Adjacent);
                y_min = Math.Min(y_min, slices[i].Opposite);
                y_max = Math.Max(y_max, slices[i].Opposite);
            }
            float x_offset = Math.Max(Math.Abs(x_min), x_max);
            float y_offset = Math.Max(Math.Abs(y_min), y_max);

            rectangle = new System.Drawing.RectangleF(rectangle.Left + x_offset, rectangle.Top + y_offset, rectangle.Width - (x_offset * 2), rectangle.Height - (y_offset * 2));



            float halfInnerWidth  = rectangle.Width / 2;
            float halfInnerHeight = rectangle.Height / 2;
            float radius          = Math.Min(halfInnerWidth, halfInnerHeight);
            float diameter        = radius + radius;
            float x = rectangle.Left + halfInnerWidth - radius;
            float y = rectangle.Top + halfInnerHeight - radius;

            if (radius > 0)
            {
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                for (int i = 0; i < slices.Length; i++)
                {
                    graphics.FillPie(slices[i].Brush, x, y, diameter, diameter, slices[i].StartAngle, slices[i].SweepAngle);

                    float radiusPlusHalfHypotenuse = radius + slices[i].Hypotenuse / 2;
                    float labelLeft = x + radius - (slices[i].LabelWidth / 2) + (slices[i].LabelCos * radiusPlusHalfHypotenuse);
                    float labelTop  = y + radius - (slices[i].LabelHeight / 2) + (slices[i].LabelSin * radiusPlusHalfHypotenuse);

                    //TODO use a style for Brush
                    DrawString(graphics, slices[i].Label, labelFont, foreColorBrush, labelLeft, labelTop);
                }
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
            }



            styleStack.PopTag();
        }
Esempio n. 19
0
 public static Bamboo.DataStructures.Table Sort(Bamboo.DataStructures.Table table, int[] columns)
 {
     return(null);
 }
Esempio n. 20
0
 public void AddTable(string name, Bamboo.DataStructures.Table table)
 {
     this._tables.Add(name, table);
 }