/// <summary>
        /// Draws the legend.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo  cri = (ChartRendererInfo)_rendererParms.RendererInfo;
            LegendRendererInfo lri = cri.legendRendererInfo;

            if (lri == null)
            {
                return;
            }

            XGraphics          gfx   = _rendererParms.Graphics;
            RendererParameters parms = new RendererParameters();

            parms.Graphics = gfx;

            LegendEntryRenderer ler = new LegendEntryRenderer(parms);

            bool verticalLegend = (lri._legend._docking == DockingType.Left || lri._legend._docking == DockingType.Right);
            int  paddingFactor  = 1;

            if (lri.BorderPen != null)
            {
                paddingFactor = 2;
            }
            XRect legendRect = lri.Rect;

            legendRect.X += LegendRenderer.LeftPadding * paddingFactor;
            legendRect.Y += LegendRenderer.TopPadding * paddingFactor;
            foreach (LegendEntryRendererInfo leri in cri.legendRendererInfo.Entries)
            {
                XRect entryRect = legendRect;
                entryRect.Width  = leri.Width;
                entryRect.Height = leri.Height;

                leri.Rect          = entryRect;
                parms.RendererInfo = leri;
                ler.Draw();

                if (verticalLegend)
                {
                    legendRect.Y += entryRect.Height + LegendRenderer.EntrySpacing;
                }
                else
                {
                    legendRect.X += entryRect.Width + LegendRenderer.EntrySpacing;
                }
            }

            // Draw border around legend
            if (lri.BorderPen != null)
            {
                XRect borderRect = lri.Rect;
                borderRect.X      += LegendRenderer.LeftPadding;
                borderRect.Y      += LegendRenderer.TopPadding;
                borderRect.Width  -= LegendRenderer.LeftPadding + LegendRenderer.RightPadding;
                borderRect.Height -= LegendRenderer.TopPadding + LegendRenderer.BottomPadding;
                gfx.DrawRectangle(lri.BorderPen, borderRect);
            }
        }
        /// <summary>
        /// Initializes the legend's renderer info. Each data point will be represented through
        /// a legend entry renderer info.
        /// </summary>
        internal override RendererInfo Init()
        {
            LegendRendererInfo lri = null;
            ChartRendererInfo  cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            if (cri.chart.legend != null)
            {
                lri        = new LegendRendererInfo();
                lri.legend = cri.chart.legend;

                lri.Font      = Converter.ToXFont(lri.legend.font, cri.DefaultFont);
                lri.FontColor = new XSolidBrush(XColors.Black);

                if (lri.legend.lineFormat != null)
                {
                    lri.BorderPen = Converter.ToXPen(lri.legend.lineFormat, XColors.Black, DefaultLineWidth, XDashStyle.Solid);
                }

                XSeries xseries = null;
                if (cri.chart.xValues != null)
                {
                    xseries = cri.chart.xValues[0];
                }

                int index = 0;
                SeriesRendererInfo sri = cri.seriesRendererInfos[0];
                lri.Entries = new LegendEntryRendererInfo[sri.pointRendererInfos.Length];
                foreach (PointRendererInfo pri in sri.pointRendererInfos)
                {
                    LegendEntryRendererInfo leri = new LegendEntryRendererInfo();
                    leri.seriesRendererInfo = sri;
                    leri.legendRendererInfo = lri;
                    leri.EntryText          = string.Empty;
                    if (xseries != null)
                    {
                        if (xseries.Count > index)
                        {
                            leri.EntryText = xseries[index].Value;
                        }
                    }
                    else
                    {
                        leri.EntryText = (index + 1).ToString(); // create default/dummy entry
                    }
                    leri.MarkerPen   = pri.LineFormat;
                    leri.MarkerBrush = pri.FillFormat;

                    lri.Entries[index++] = leri;
                }
            }
            return(lri);
        }
        /// <summary>
        /// Initializes the legend's renderer info. Each data series will be represented through
        /// a legend entry renderer info.
        /// </summary>
        internal override RendererInfo Init()
        {
            LegendRendererInfo lri = null;
            ChartRendererInfo  cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            if (cri._chart._legend != null)
            {
                lri         = new LegendRendererInfo();
                lri._legend = cri._chart._legend;

                lri.Font      = Converter.ToXFont(lri._legend._font, cri.DefaultFont);
                lri.FontColor = new XSolidBrush(XColors.Black);

                if (lri._legend._lineFormat != null)
                {
                    lri.BorderPen = Converter.ToXPen(lri._legend._lineFormat, XColors.Black, DefaultLineWidth, XDashStyle.Solid);
                }

                lri.Entries = new LegendEntryRendererInfo[cri.seriesRendererInfos.Length];
                int index = 0;
                foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
                {
                    LegendEntryRendererInfo leri = new LegendEntryRendererInfo();
                    leri._seriesRendererInfo = sri;
                    leri._legendRendererInfo = lri;
                    leri.EntryText           = sri._series.Name;
                    if (sri._markerRendererInfo != null)
                    {
                        leri.MarkerSize.Width = leri.MarkerSize.Height = sri._markerRendererInfo.MarkerSize.Point;
                        leri.MarkerPen        = new XPen(sri._markerRendererInfo.MarkerForegroundColor);
                        leri.MarkerBrush      = new XSolidBrush(sri._markerRendererInfo.MarkerBackgroundColor);
                    }
                    else
                    {
                        leri.MarkerPen   = sri.LineFormat;
                        leri.MarkerBrush = sri.FillFormat;
                    }

                    if (cri._chart._type == ChartType.ColumnStacked2D)
                    {
                        // Stacked columns are in reverse order.
                        lri.Entries[cri.seriesRendererInfos.Length - index++ - 1] = leri;
                    }
                    else
                    {
                        lri.Entries[index++] = leri;
                    }
                }
            }
            return(lri);
        }
    /// <summary>
    /// Initializes the legend's renderer info. Each data series will be represented through
    /// a legend entry renderer info.
    /// </summary>
    internal override RendererInfo Init()
    {
      LegendRendererInfo lri = null;
      ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
      if (cri.chart.legend != null)
      {
        lri = new LegendRendererInfo();
        lri.legend = cri.chart.legend;

        lri.Font = Converter.ToXFont(lri.legend.font, cri.DefaultFont);
        lri.FontColor = new XSolidBrush(XColors.Black);

        if (lri.legend.lineFormat != null)
          lri.BorderPen = Converter.ToXPen(lri.legend.lineFormat, XColors.Black, DefaultLineWidth, XDashStyle.Solid);

        lri.Entries = new LegendEntryRendererInfo[cri.seriesRendererInfos.Length];
        int index = 0;
        foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
        {
          LegendEntryRendererInfo leri = new LegendEntryRendererInfo();
          leri.seriesRendererInfo = sri;
          leri.legendRendererInfo = lri;
          leri.EntryText = sri.series.name;
          if (sri.markerRendererInfo != null)
          {
            leri.MarkerSize.Width = leri.MarkerSize.Height = sri.markerRendererInfo.MarkerSize.Point;
            leri.MarkerPen = new XPen(sri.markerRendererInfo.MarkerForegroundColor);
            leri.MarkerBrush = new XSolidBrush(sri.markerRendererInfo.MarkerBackgroundColor);
          }
          else
          {
            leri.MarkerPen = sri.LineFormat;
            leri.MarkerBrush = sri.FillFormat;
          }

          if (cri.chart.type == ChartType.ColumnStacked2D)
            // stacked columns are revers ordered
            lri.Entries[cri.seriesRendererInfos.Length - index++ - 1] = leri;
          else
            lri.Entries[index++] = leri;
        }
      }
      return lri;
    }
Example #5
0
        /// <summary>
        /// Initializes the legend's renderer info. Each data point will be represented through
        /// a legend entry renderer info.
        /// </summary>
        internal override RendererInfo Init()
        {
            LegendRendererInfo lri = null;
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;
            if (cri._chart._legend != null)
            {
                lri = new LegendRendererInfo();
                lri._legend = cri._chart._legend;

                lri.Font = Converter.ToXFont(lri._legend._font, cri.DefaultFont);
                lri.FontColor = new XSolidBrush(XColors.Black);

                if (lri._legend._lineFormat != null)
                    lri.BorderPen = Converter.ToXPen(lri._legend._lineFormat, XColors.Black, DefaultLineWidth, XDashStyle.Solid);

                XSeries xseries = null;
                if (cri._chart._xValues != null)
                    xseries = cri._chart._xValues[0];

                int index = 0;
                SeriesRendererInfo sri = cri.seriesRendererInfos[0];
                lri.Entries = new LegendEntryRendererInfo[sri._pointRendererInfos.Length];
                foreach (PointRendererInfo pri in sri._pointRendererInfos)
                {
                    LegendEntryRendererInfo leri = new LegendEntryRendererInfo();
                    leri._seriesRendererInfo = sri;
                    leri._legendRendererInfo = lri;
                    leri.EntryText = string.Empty;
                    if (xseries != null)
                    {
                        if (xseries.Count > index)
                            leri.EntryText = xseries[index]._value;
                    }
                    else
                        leri.EntryText = (index + 1).ToString(); // create default/dummy entry
                    leri.MarkerPen = pri.LineFormat;
                    leri.MarkerBrush = pri.FillFormat;

                    lri.Entries[index++] = leri;
                }
            }
            return lri;
        }
        /// <summary>
        /// Layouts and calculates the space used by the legend.
        /// </summary>
        internal override void Format()
        {
            ChartRendererInfo  cri = (ChartRendererInfo)_rendererParms.RendererInfo;
            LegendRendererInfo lri = cri.legendRendererInfo;

            if (lri == null)
            {
                return;
            }

            RendererParameters parms = new RendererParameters();

            parms.Graphics = _rendererParms.Graphics;

            bool  verticalLegend    = (lri._legend._docking == DockingType.Left || lri._legend._docking == DockingType.Right);
            XSize maxMarkerArea     = new XSize();
            LegendEntryRenderer ler = new LegendEntryRenderer(parms);

            foreach (LegendEntryRendererInfo leri in lri.Entries)
            {
                parms.RendererInfo = leri;
                ler.Format();

                maxMarkerArea.Width  = Math.Max(leri.MarkerArea.Width, maxMarkerArea.Width);
                maxMarkerArea.Height = Math.Max(leri.MarkerArea.Height, maxMarkerArea.Height);

                if (verticalLegend)
                {
                    lri.Width   = Math.Max(lri.Width, leri.Width);
                    lri.Height += leri.Height;
                }
                else
                {
                    lri.Width += leri.Width;
                    lri.Height = Math.Max(lri.Height, leri.Height);
                }
            }

            // Add padding to left, right, top and bottom
            int paddingFactor = 1;

            if (lri.BorderPen != null)
            {
                paddingFactor = 2;
            }
            lri.Width  += (LegendRenderer.LeftPadding + LegendRenderer.RightPadding) * paddingFactor;
            lri.Height += (LegendRenderer.TopPadding + LegendRenderer.BottomPadding) * paddingFactor;
            if (verticalLegend)
            {
                lri.Height += LegendRenderer.EntrySpacing * (lri.Entries.Length - 1);
            }
            else
            {
                lri.Width += LegendRenderer.EntrySpacing * (lri.Entries.Length - 1);
            }

            foreach (LegendEntryRendererInfo leri in lri.Entries)
            {
                leri.MarkerArea = maxMarkerArea;
            }
        }