public override void Draw(RuntimeGizmoDrawer drawer) { var facingPosition = getFacingPosition(); var labeledPosition = getLabeledPosition(); // Instead of "drawing", we're going to update the data for the Label, // which handles its own drawing. label.gameObject.transform.position = labeledPosition; label.gameObject.transform.rotation = Utils.FaceTargetWithoutTwist( labeledPosition, facingPosition, flip180: true); label.textStyle.Overlay(Style.Color(this.color)); label.text = this.text; }
public void DrawAtTop(Graphics g, Rdl.Runtime.Context context, ref int l, ref int t, ref int w, ref int h) { string title = Caption(context); if (title != null && title != string.Empty) { Font titleFont = Style.GetWindowsFont(context); SizeF stringSize = g.MeasureString(title, titleFont); int xPos = 0; if (Position == Title.PositionEnum.Center) { xPos = (w / 2) - ((int)stringSize.Width / 2); } if (Position == Title.PositionEnum.Far) { xPos = w - (int)stringSize.Width; } g.DrawString(title, titleFont, new SolidBrush(Style.W32Color(Style.Color(context))), l + xPos, t); t += (int)stringSize.Height; h -= (int)stringSize.Height; } }
public void DrawAtLeft(Graphics g, Rdl.Runtime.Context context, ref int l, ref int t, ref int w, ref int h) { string title = Caption(context); if (title != null && title != string.Empty) { Font titleFont = Style.GetWindowsFont(context); SizeF stringSize = g.MeasureString(title, titleFont, 0, new StringFormat(StringFormatFlags.DirectionVertical)); int yPos = 0; if (Position == Title.PositionEnum.Center) { yPos = (h / 2) - ((int)stringSize.Height / 2); } if (Position == Title.PositionEnum.Far) { yPos = h - (int)stringSize.Height; } g.DrawString(title, titleFont, new SolidBrush(Style.W32Color(Style.Color(context))), l, t + yPos, new StringFormat(StringFormatFlags.DirectionVertical)); l += (int)stringSize.Width; w -= (int)stringSize.Width; } }
internal void DrawVertical(Chart chart, Rdl.Runtime.Context context, Graphics g, ref int l, int t, ref int w, int h) { int majorIntervals = (int)((_maxValue - _minValue) / _majorIntervalValue); int minorIntervals = (int)((_maxValue - _minValue) / _minorIntervalValue); // Find the tick mark and axis position for the axis. int majorTickStart, majorTickWidth, minorTickStart, minorTickWidth, axisPos, axisWidth; AdjustAxisPosition(GetAxisThickness(context), out majorTickStart, out majorTickWidth, out minorTickStart, out minorTickWidth, out axisPos, out axisWidth); // If we are showing the grid lines then adjust the tick width to include the whole chart area. if (MajorGridLines.ShowGridLines) { majorTickWidth = w - _labelWidth - axisPos - majorTickStart; } if (MinorGridLines.ShowGridLines) { minorTickWidth = w - _labelWidth - axisPos - minorTickStart; } // Draw the axis line Color color = Style.W32Color(Style.Color(context)); Brush brush = new SolidBrush(color); Pen majorGridPen = new Pen(brush, 1); if (MajorGridLines != null) { majorGridPen = new Pen(new SolidBrush(Style.W32Color(MajorGridLines.Style.Color(context))), (int)MajorGridLines.Style.BorderWidth.Left(context).points); } Pen minorGridPen = new Pen(brush, 1); if (MinorGridLines != null) { minorGridPen = new Pen(new SolidBrush(Style.W32Color(MinorGridLines.Style.Color(context))), (int)MinorGridLines.Style.BorderWidth.Left(context).points); } g.DrawLine(new Pen(brush, GetAxisThickness(context)), new Point(l + _labelWidth + axisPos + (GetAxisThickness(context) >> 1), t), new Point(l + _labelWidth + axisPos + (GetAxisThickness(context) >> 1), t + h)); Font labelFont = chart.ValueAxis.Style.GetWindowsFont(context); float majorEntryHeight = (float)h / majorIntervals; float minorEntryHeight = (float)h / minorIntervals; for (int i = 0; i <= majorIntervals; i++) { int top = t + h - (int)(i * majorEntryHeight); if (Visible) { // Determine the amount of space required for the axis labels. SizeF stringSize; // Draw the axis labels. decimal dValue = _minValue + (i * _majorIntervalValue); stringSize = g.MeasureString(dValue.ToString().ToString(), labelFont); g.DrawString(dValue.ToString(), labelFont, new SolidBrush(color), l + _labelWidth - (int)stringSize.Width - 1, top - ((int)stringSize.Height / 2)); } if (i > 0) { // Draw the major tick marks if (majorTickWidth > 0) { g.DrawLine(majorGridPen, new Point(l + _labelWidth + axisPos + majorTickStart, top), new Point(l + _labelWidth + axisPos + majorTickStart + majorTickWidth, top)); } // Draw the minor tick marks if (minorTickWidth > 0) { for (int j = 1; j < minorIntervals / majorIntervals; j++) { g.DrawLine(minorGridPen, new Point(l + _labelWidth + axisPos + minorTickStart, top - (int)(j * minorEntryHeight)), new Point(l + _labelWidth + axisPos + minorTickStart + majorTickWidth, top - (int)(j * minorEntryHeight))); } } } } l += _labelWidth + axisWidth; w -= _labelWidth + axisWidth; }
internal void DrawHorizontal(Chart chart, Rdl.Runtime.Context context, Graphics g, bool centered, int l, int t, int w, ref int h) { int majorIntervals = (int)((_maxValue - _minValue) / _majorIntervalValue); int minorIntervals = (int)((_maxValue - _minValue) / _minorIntervalValue); // Find the tick mark and axis position for the axis. int majorTickStart, majorTickHeight, minorTickStart, minorTickHeight, axisPos, axisWidth; AdjustAxisPosition(GetAxisThickness(context), out majorTickStart, out majorTickHeight, out minorTickStart, out minorTickHeight, out axisPos, out axisWidth); Color color = Style.W32Color(Style.Color(context)); Brush brush = new SolidBrush(color); Pen majorGridPen = new Pen(brush, 1); if (MajorGridLines != null) { majorGridPen = new Pen(new SolidBrush(Style.W32Color(MajorGridLines.Style.Color(context))), (int)MajorGridLines.Style.BorderWidth.Left(context).points); } Pen minorGridPen = new Pen(brush, 1); if (MinorGridLines != null) { minorGridPen = new Pen(new SolidBrush(Style.W32Color(MinorGridLines.Style.Color(context))), (int)MinorGridLines.Style.BorderWidth.Left(context).points); } Font font = Style.GetWindowsFont(context); bool vertical = false; float yMult = (float)g.DpiY / 72; int labelHeight = 0; float majorEntryWidth = (float)w / majorIntervals; float minorEntryWidth = (float)w / minorIntervals; // Determine how much vertical space is required for the axis labels. if (Visible) { // Determine if the labels need to be vertical and find the height required for the labels. labelHeight = (int)(font.Height * yMult); // Determine the amount of space required for the axis labels. GetValueLableWidth(context, g, majorIntervals); if (_labelWidth > (int)majorEntryWidth) { labelHeight = _labelWidth; vertical = true; } } // If we are showing the grid lines then adjust the tick width to include the whole chart area. if (MajorGridLines.ShowGridLines) { majorTickHeight = h - labelHeight - axisPos - majorTickStart; } if (MinorGridLines.ShowGridLines) { minorTickHeight = h - labelHeight - axisPos - minorTickStart; } // Fill in the background of the plot area. g.FillRectangle(new SolidBrush(Style.W32Color(chart.PlotAreaStyle.BackgroundColor(context))), l, t, w, h - (labelHeight + axisWidth)); // Draw the axis line g.DrawLine(new Pen(new SolidBrush(color), GetAxisThickness(context)), new Point(l, t + h - labelHeight - axisPos - (GetAxisThickness(context) >> 1)), new Point(l + w, t + h - labelHeight - axisPos - (GetAxisThickness(context) >> 1))); // Loop through the major interval values int left = l; for (int i = 0; i <= majorIntervals; i++) { left = l + (int)(i * majorEntryWidth); if (Visible) { decimal dValue = _minValue + (i * _majorIntervalValue); int center = left; if (centered) { center += (int)(majorEntryWidth / 2); } SizeF size = g.MeasureString(dValue.ToString(), font); if (vertical) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(dValue.ToString(), font.FontFamily, (int)font.Style, font.Size * yMult, new Point(center - ((int)size.Width / 2), t + h - labelHeight), StringFormat.GenericDefault); if (vertical) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0 - (size.Width / 2), 0); matrix.RotateAt(-30, new PointF(center, t + h - labelHeight), System.Drawing.Drawing2D.MatrixOrder.Append); path.Transform(matrix); } g.DrawPath(new Pen(brush), path); } else { g.DrawString(dValue.ToString(), font, brush, center - (int)size.Width / 2, t + h - labelHeight, StringFormat.GenericDefault); } } if (i > 0) { // Draw the major tick mark if (majorTickHeight > 0) { g.DrawLine(majorGridPen, new Point(left, t + h - labelHeight - (axisWidth >> 1) - majorTickStart), new Point(left, t + h - labelHeight - (axisWidth >> 1) - majorTickStart - majorTickHeight)); } // Draw the minor tick marks if (minorTickHeight > 0) { for (int j = 1; j < minorIntervals / majorIntervals; j++) { g.DrawLine(minorGridPen, new Point(left + (int)(j * minorEntryWidth), t + h - labelHeight - (axisWidth >> 1) + minorTickStart), new Point(left + (int)(j * minorEntryWidth), t + h - labelHeight - (axisWidth >> 1) + minorTickStart - minorTickHeight)); } } } } h -= labelHeight + ((axisWidth + GetAxisThickness(context)) >> 1); }
private void DrawLegend(Rdl.Runtime.Context context, System.Drawing.Graphics g, Bitmap bm, ref int l, ref int t, ref int w, ref int h, bool includeGroups, decimal xMult, decimal yMult) { if (_legend == null) { return; } if (!_legend.Visible) { return; } // The legend is only required if there is a series. if (_seriesGrouping == null) { return; } // Build the color values to use for each group int index = 0; foreach (Series ser in _leafSeriesList) { if (!_seriesColors.ContainsKey(ser.CombinedValue)) { _seriesColors.Add(ser.CombinedValue, Rdl.Engine.Chart.Palette.GetColor(_palette, index)); index++; } } // Get the font to use to draw the text. System.Drawing.Font font = _legend.Style.GetWindowsFont(context); // Measure the space required for the text. int height = 0; int width = 0; int lineHeight = 0; foreach (string s in _seriesColors.Keys) { SizeF size = g.MeasureString(s, font); lineHeight = (int)size.Height + 1; height += lineHeight; width = Math.Max(width, (int)size.Width + 1); } // Add some room for the color boxes and space between columns. width += lineHeight * 2; int columns = 1; int top = t, left = l; if (_legend.Position == Legend.PositionEnum.LeftBottom || _legend.Position == Legend.PositionEnum.LeftCenter || _legend.Position == Legend.PositionEnum.LeftTop || _legend.Position == Legend.PositionEnum.RightTop || _legend.Position == Legend.PositionEnum.RightCenter || _legend.Position == Legend.PositionEnum.RightBottom) { // If the legend is going on the left or right of the chart then don't use more than // 1/3 of the available area for the legend. width = Math.Min(width, w / 3); w -= width + _legendPadding; height = Math.Min(height, h - (_legendPadding << 1)); if (_legend.Position == Legend.PositionEnum.LeftBottom || _legend.Position == Legend.PositionEnum.LeftCenter || _legend.Position == Legend.PositionEnum.LeftTop) { l += width + _legendPadding; } else { left = w + _legendPadding; } if (_legend.Position == Legend.PositionEnum.LeftBottom || _legend.Position == Legend.PositionEnum.RightBottom) { top = t + h - height; } if (_legend.Position == Legend.PositionEnum.LeftCenter || _legend.Position == Legend.PositionEnum.RightCenter) { top = t + (h / 2) - (height / 2); } } else { columns = (int)(w / width); height = lineHeight * (int)Math.Ceiling((double)_seriesColors.Count / columns); // If the legend is going above or below the chart then don't use more than // %60 the available space. height = Math.Min(height, (int)((h - _legendPadding - _legendPadding) * .6)); h -= height + _legendPadding + _legendPadding; if (_legend.Position == Legend.PositionEnum.TopCenter || _legend.Position == Legend.PositionEnum.TopLeft || _legend.Position == Legend.PositionEnum.TopRight) { top = t + _legendPadding; t += height + _legendPadding + _legendPadding; } else { top = t + h + _legendPadding; } if (_legend.Position == Legend.PositionEnum.BottomRight || _legend.Position == Legend.PositionEnum.TopRight) { left = l + w - (width * columns); } if (_legend.Position == Legend.PositionEnum.BottomCenter || _legend.Position == Legend.PositionEnum.TopCenter) { left = l + (w / 2) - ((width * columns) / 2); } } if (lineHeight * _seriesColors.Count > height) { lineHeight = height / _seriesColors.Count; } if (_legend.Style.BorderWidth != null) { Rdl.Render.Drawing.DrawBorder(g, new System.Drawing.Rectangle(left, top, (width * columns), height), new Rdl.Render.BorderWidth(_legend.Style.BorderWidth, context), new Rdl.Render.BorderStyle(_legend.Style.BorderStyle, context), new Rdl.Render.BorderColor(_legend.Style.BorderColor, context), xMult, yMult); } // Draw the text onto the chart legend area. System.Drawing.Brush brush = new SolidBrush(Style.W32Color(Style.Color(context))); float x, y; x = left; y = top; int c = 1; foreach (string s in _seriesColors.Keys) { if (y + lineHeight <= top + height) { // Draw the collored box g.FillRectangle(new SolidBrush(_seriesColors[s]), new RectangleF(x, y + (lineHeight / 10), (lineHeight * .8f), (lineHeight * .8f))); g.DrawString(s, font, brush, new RectangleF(x + lineHeight, y, width, height - (y - top)), new StringFormat(StringFormatFlags.NoWrap)); if (c == columns) { c = 1; y += lineHeight; x = left; } else { x += width; c++; } } } }
public System.Drawing.Image RenderChart(Rdl.Runtime.Context context, int width, int height, decimal xMult, decimal yMult) { if (width <= 0 || height <= 0) { return(null); } Bitmap bm = new Bitmap(width, height); Graphics g = Graphics.FromImage(bm); g.PageUnit = GraphicsUnit.Pixel; int t = 0; int l = 0; int w = width; int h = height; if (context.Rows.Count == 0) { g.FillRectangle(new SolidBrush(Style.W32Color(Style.BackgroundColor(context))), new System.Drawing.Rectangle(0, 0, w, h)); g.DrawString("No Data", Style.GetWindowsFont(context), new SolidBrush(Style.W32Color(Style.Color(context))), new Point(0, 0)); return(bm); } System.Drawing.Rectangle clipRect = new System.Drawing.Rectangle(l, t, w, h); if (Style.BackgroundColor(context) != null) { g.FillRectangle(new SolidBrush(Style.W32Color(Style.BackgroundColor(context))), clipRect); } if (Style.BorderWidth != null) { Rdl.Render.Drawing.DrawBorder(g, new System.Drawing.Rectangle(l, t, w, h), new Rdl.Render.BorderWidth(Style.BorderWidth, context), new Rdl.Render.BorderStyle(Style.BorderStyle, context), new Rdl.Render.BorderColor(Style.BorderColor, context), xMult, yMult); } if (Style != null) { l += (int)(Style.PaddingLeft(context).points *xMult); t += (int)(Style.PaddingTop(context).points *yMult); w -= (int)((Style.PaddingLeft(context).points + Style.PaddingRight(context).points) * xMult); h -= (int)((Style.PaddingTop(context).points + Style.PaddingBottom(context).points) * yMult); } // Draw in the title. if (_title != null) { _title.DrawAtTop(g, context, ref l, ref t, ref w, ref h); } // Get the categories. if (_categoryGrouping != null) { _categories = _categoryGrouping.GetCategories(context, null); _leafCategories = _categories.LeafCategories; } // Get the series if (_seriesGrouping != null) { _seriesList = _seriesGrouping.GetSeriesList(context, null); _leafSeriesList = _seriesList.LeafSeriesList; } // Draw in the Legend DrawLegend(context, g, bm, ref l, ref t, ref w, ref h, (_type == TypeEnum.Pie), xMult, yMult); // Draw the chart. switch (_type) { case TypeEnum.Area: break; case TypeEnum.Bar: Type.Bar barChart = new Type.Bar(this, context, g, l, t, w, h); break; case TypeEnum.Bubble: break; case TypeEnum.Column: Type.Column columnChart = new Type.Column(this, context, g, l, t, w, h); break; case TypeEnum.Doughnut: break; case TypeEnum.Line: Type.Line lineChart = new Type.Line(this, context, g, l, t, w, h); break; case TypeEnum.Pie: break; case TypeEnum.Scatter: break; case TypeEnum.Stock: break; } return(bm); }
internal void DrawVertical(Chart chart, Rdl.Runtime.Context context, Graphics g, bool centered, ref int l, int t, ref int w, int h) { if (chart.LeafCategories != null) { _totalCategories = chart.LeafCategories.Count; } // Find the tick mark sizes and axis position for the axis. int majorTickStart, majorTickWidth, minorTickStart, minorTickWidth, axisPos, axisWidth; AdjustAxisPosition(GetAxisThickness(context), out majorTickStart, out majorTickWidth, out minorTickStart, out minorTickWidth, out axisPos, out axisWidth); // If we are showing the grid lines then adjust the tick width to include the whole chart area. if (MajorGridLines.ShowGridLines) { majorTickWidth = w - _categoryLabelWidth - axisPos - majorTickStart; } if (MinorGridLines.ShowGridLines) { minorTickWidth = w - _categoryLabelWidth - axisPos - minorTickStart; } // Draw the axis line Color color = Style.W32Color(chart.ValueAxis.Style.Color(context)); g.DrawLine(new Pen(new SolidBrush(color), GetAxisThickness(context)), new Point(l + _categoryLabelWidth + axisPos, t), new Point(l + _categoryLabelWidth + axisPos, t + h)); Font labelFont = Style.GetWindowsFont(context); Brush brush = new SolidBrush(Style.W32Color(Style.Color(context))); Pen majorGridPen = new Pen(color, 1); if (chart.CategoryAxis.MajorGridLines != null) { majorGridPen = new Pen(Style.W32Color(MajorGridLines.Style.Color(context)), (int)MajorGridLines.Style.BorderWidth.Top(context).points); } Pen minorGridPen = new Pen(color, 1); if (chart.CategoryAxis.MinorGridLines != null) { minorGridPen = new Pen(Style.W32Color(MinorGridLines.Style.Color(context)), (int)MinorGridLines.Style.BorderWidth.Top(context).points); } if (Scalar) { if (chart.CategoryGrouping == null || chart.CategoryGrouping.NextGrouping != null) { throw new Exception("There must be exactly one grouping on a scalar axis."); } // Find the min and max values from the data. decimal min = 0; decimal max = 0; foreach (Category cat in chart.Categories) { min = Math.Min(min, decimal.Parse(cat.Value)); max = Math.Max(max, decimal.Parse(cat.Value)); } // Adjust the min and max values and find int intervals. SetMinMaxValues(context, min, max); int majorIntervals = (int)((_maxValue - _minValue) / _majorIntervalValue); int minorIntervals = (int)((_maxValue - _minValue) / _minorIntervalValue); float majorIntervalSize = (float)h / majorIntervals; float minorIntervalSize = (float)h / minorIntervals; int i = 0; for (decimal dValue = min; dValue <= max; dValue += _majorIntervalValue) { // Draw the labels. if (Visible) { SizeF stringSize = g.MeasureString(dValue.ToString(), labelFont); g.DrawString(dValue.ToString(), labelFont, brush, l + _categoryLabelWidth - stringSize.Width, t + h - (int)(i * majorIntervalSize) - (stringSize.Height / 2)); } // Draw the major tick mark if (majorTickWidth > 0) { g.DrawLine(majorGridPen, new Point(l + _categoryLabelWidth + axisPos + majorTickStart, t + h - (int)(i * majorIntervalSize)), new Point(l + _categoryLabelWidth + axisPos + majorTickStart + majorTickWidth, t + h - (int)(i * majorIntervalSize))); } // Draw the minor tick marks if (majorTickWidth > 0) { for (int j = 1; j < minorIntervals / majorIntervals; j++) { g.DrawLine(minorGridPen, new Point(l + _categoryLabelWidth + axisPos + minorTickStart, t + h - (int)(i * majorIntervalSize) - (int)(j * minorIntervalSize)), new Point(l + _categoryLabelWidth + axisPos + minorTickStart + minorTickWidth, t + h - (int)(i * majorIntervalSize) - (int)(j * minorIntervalSize))); } } i++; } } else if (chart.Categories != null && chart.Categories.Count > 0) { DrawCategoryOntoVerticalAxis(chart.Categories, g, brush, labelFont, context, centered, l, t, h, 0, axisPos, majorGridPen, majorTickStart, majorTickWidth, minorGridPen, minorTickStart, minorTickWidth); } l += _categoryLabelWidth + axisWidth; w -= _categoryLabelWidth + axisWidth; }