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(); }
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(); }
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(); }
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(); }
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(); }
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(); }