示例#1
0
        private void DrawCategoryOntoVerticalAxis(Categories categories,
                                                  Graphics g,
                                                  Brush brush,
                                                  Font labelFont,
                                                  Rdl.Runtime.Context context,
                                                  bool centered,
                                                  int l, int t, int h, int offset,
                                                  int axisPos,
                                                  Pen majorGridPen, int majorTickStart, int majorTickWidth,
                                                  Pen minorGridPen, int minorTickStart, int minorTickWidth
                                                  )
        {
            //Draw the labels at this category level.
            int i = 0;

            foreach (Category cat in categories)
            {
                // Find the total members below this point.
                int membersAtThisPoint = 1;
                if (cat.Categories != null)
                {
                    membersAtThisPoint = cat.Categories.LeafCategories.Count;
                }

                int top = t + h - (int)(i * ((float)h / _totalCategories));
                if (Visible)
                {
                    int labelTop = top;
                    if (centered)
                    {
                        labelTop -= (int)(membersAtThisPoint * ((float)h / _totalCategories) / 2);
                    }
                    SizeF stringSize = g.MeasureString(cat.Value, labelFont);
                    g.DrawString(cat.Value, labelFont, brush, l + offset + _categoryLabelWidth - stringSize.Width,
                                 labelTop - (stringSize.Height / 2));
                }

                // Draw the tick mark
                if (offset == 0 && majorTickWidth > 0)
                {
                    g.DrawLine(majorGridPen,
                               new Point(l + _categoryLabelWidth + axisPos + majorTickStart, top),
                               new Point(l + _categoryLabelWidth + axisPos + majorTickStart + majorTickWidth, top));
                }
                else if (offset != 0 && minorTickWidth > 0)
                {
                    g.DrawLine(minorGridPen,
                               new Point(l + _categoryLabelWidth + axisPos + minorTickStart, top),
                               new Point(l + _categoryLabelWidth + axisPos + minorTickStart + minorTickWidth, top));
                }

                // Find the height of this group entry
                int groupEntryHeight = h;
                if (_totalCategories > 1)
                {
                    groupEntryHeight = (int)(membersAtThisPoint * h / _totalCategories);
                }

                // Recurse down to draw stuff below this group.
                if (cat.Categories != null)
                {
                    DrawCategoryOntoVerticalAxis(cat.Categories, g, brush, labelFont, context,
                                                 centered, l + 20, top - groupEntryHeight, groupEntryHeight, offset + 20,
                                                 axisPos, majorGridPen, majorTickStart, majorTickWidth,
                                                 minorGridPen, minorTickStart, minorTickWidth);
                }

                i += membersAtThisPoint;
            }
        }
示例#2
0
        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);
        }
示例#3
0
        private int DrawCategoryOntoHorizontalAxis(Categories categories,
                                                   Graphics g,
                                                   Brush brush,
                                                   Rdl.Runtime.Context context,
                                                   Axis axis,
                                                   bool centered,
                                                   int level,
                                                   int left, int top, int w,
                                                   List <int> majorMarks, List <int> minorMarks)
        {
            Font  font  = axis.Style.GetWindowsFont(context);
            float yMult = (float)g.DpiY / 72;

            // Determine if the labels need to be vertical and find the height required for the labels.
            bool vertical    = false;
            int  labelHeight = (int)(font.Height * yMult);
            int  adjustment  = (centered) ? 0 : 1;

            foreach (Category cat in categories)
            {
                SizeF size = g.MeasureString(cat.Value, font);

                // Find the total members below this point.
                int membersAtThisPoint = 1;
                if (cat.Categories != null)
                {
                    membersAtThisPoint = cat.Categories.LeafCategories.Count;
                }

                // If we exceed the available width then go to vertical labels.
                if (_totalCategories > 1 &&
                    size.Width > (w * membersAtThisPoint / (_totalCategories - adjustment)))
                {
                    vertical = true;
                    foreach (Category cat2 in categories)
                    {
                        size        = g.MeasureString(cat2.Value, font, 0, new StringFormat(StringFormatFlags.DirectionVertical));
                        labelHeight = Math.Max(labelHeight, (int)size.Height);
                    }
                    break;
                }
                labelHeight = Math.Max(labelHeight, (int)size.Height);
            }

            //Draw the labels at this category level.
            int totalHeight = labelHeight;

            foreach (Category cat in categories)
            {
                // Find the total members below this point.
                int membersAtThisPoint = 1;
                if (cat.Categories != null)
                {
                    membersAtThisPoint = cat.Categories.LeafCategories.Count;
                }

                // Find the width of this group entry
                int groupEntryWidth = w;
                if (_totalCategories > 1)
                {
                    groupEntryWidth = (int)(membersAtThisPoint * w / (_totalCategories - adjustment));
                }

                // Measure the space needed for the label
                //SizeF size = g.MeasureString(cat.Value, font, 0, (vertical) ? new StringFormat(StringFormatFlags.DirectionVertical) : StringFormat.GenericDefault);
                SizeF size = g.MeasureString(cat.Value, font, 0, StringFormat.GenericDefault);

                int center = left;
                if (centered)
                {
                    center += groupEntryWidth / 2;
                }
                if (vertical)
                {
                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(cat.Value, font.FontFamily, (int)font.Style, font.Size * yMult,
                                   new Point(center - ((int)size.Width / 2), top),
                                   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, top), System.Drawing.Drawing2D.MatrixOrder.Append);
                        path.Transform(matrix);
                    }
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.DrawPath(new Pen(brush), path);
                }
                else
                {
                    g.DrawString(cat.Value, font, brush,
                                 center - (int)size.Width / 2, top, StringFormat.GenericDefault);
                }



                // Draw this label.
                //if (vertical)
                //{
                //    g.TranslateTransform(0, size.Width);
                //    g.RotateTransform(-30);
                //}
                //g.DrawString(cat.Value, font, brush, center - size.Width / 2, top, StringFormat.GenericDefault);
                //return totalHeight;
                //g.ResetTransform();



                // Add in the tick mark position for this entry.
                if (level == 0)
                {
                    majorMarks.Add(left);
                }
                else
                {
                    minorMarks.Add(left);
                }

                // Recurse down to draw stuff below this group.
                if (cat.Categories != null)
                {
                    int h = DrawCategoryOntoHorizontalAxis(cat.Categories, g, brush, context, axis, centered,
                                                           level + 1, left, top + labelHeight, groupEntryWidth, majorMarks, minorMarks);
                    totalHeight = Math.Max(totalHeight, labelHeight + h);
                }

                // Adjust the left to one group entry over.
                left += groupEntryWidth;
            }
            return(totalHeight);
        }