Example #1
0
        /// <summary>
        /// Render axis information view.
        /// </summary>
        /// <param name="dc">Platform no-associated drawing context instance.</param>
        protected override void OnPaint(DrawingContext dc)
        {
            base.OnPaint(dc);

            var ai = AxisInfo;

            if (ai == null)
            {
                return;
            }

            var g = dc.Graphics;

            var ds         = Chart.DataSource;
            var clientRect = ClientBounds;

            RGFloat fontHeight = (RGFloat)(this.FontSize * PlatformUtility.GetDPI() / 72.0) + 4;

            double rowValue = ai.Minimum;

            if (Orientation == AxisOrientation.Vertical)
            {
                RGFloat stepY    = (clientRect.Height - fontHeight) / ai.Levels;
                var     textRect = new Rectangle(0, clientRect.Bottom - fontHeight, clientRect.Width, fontHeight);

                for (int level = 0; level <= ai.Levels; level++)
                {
                    g.DrawText(Math.Round(rowValue, Math.Abs(ai.Scaler)).ToString(), FontName, FontSize, ForeColor, textRect, ReoGridHorAlign.Right, ReoGridVerAlign.Middle);

                    textRect.Y -= stepY;
                    rowValue   += Math.Round(ai.LargeStride, Math.Abs(ai.Scaler));
                }
            }
            else if (Orientation == AxisOrientation.Horizontal)
            {
                var maxWidth = Math.Max(
                    PlatformUtility.MeasureText(dc,
                                                Math.Round(ai.Minimum, Math.Abs(ai.Scaler)).ToString(),
                                                FontName, FontSize, Drawing.Text.FontStyles.Regular
                                                ).Width,
                    PlatformUtility.MeasureText(dc,
                                                Math.Round(ai.Maximum, Math.Abs(ai.Scaler)).ToString(),
                                                FontName, FontSize, Drawing.Text.FontStyles.Regular
                                                ).Width);

                int showTitleStride = Math.Max((int)Math.Ceiling(ai.Levels * maxWidth / clientRect.Width), 1);

                RGFloat columnWidth = clientRect.Width / ai.Levels * showTitleStride;
                var     textRect    = new Rectangle(clientRect.Left - (columnWidth / 2), clientRect.Top, columnWidth, clientRect.Height);

                for (int level = 0; level <= ai.Levels; level += showTitleStride)
                {
                    g.DrawText(Math.Round(rowValue, Math.Abs(ai.Scaler)).ToString(), FontName, FontSize, ForeColor, textRect, ReoGridHorAlign.Center, ReoGridVerAlign.Top);

                    textRect.X += columnWidth;
                    rowValue   += Math.Round(ai.LargeStride, Math.Abs(ai.Scaler)) * showTitleStride;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Render axis information view.
        /// </summary>
        /// <param name="dc">Platform no-associated drawing context instance.</param>
        protected override void OnPaint(DrawingContext dc)
        {
            base.OnPaint(dc);

            if (this.Chart == null)
            {
                return;
            }

            var ai = this.AxisType == AxisTypes.Primary ?
                     this.Chart.PrimaryAxisInfo : this.Chart.SecondaryAxisInfo;

            if (ai == null)
            {
                return;
            }

            var g = dc.Graphics;

            var ds         = this.Chart.DataSource;
            var clientRect = this.ClientBounds;

            RGFloat fontHeight = (RGFloat)(this.FontSize * PlatformUtility.GetDPI() / 72.0) + 4;

            double rowValue = ai.Minimum;

            if (orientation == AxisOrientation.Vertical)
            {
                RGFloat stepY    = (clientRect.Height - fontHeight) / ai.Levels;
                var     textRect = new Rectangle(0, clientRect.Bottom - fontHeight, clientRect.Width, fontHeight);

                for (int level = 0; level <= ai.Levels; level++)
                {
                    g.DrawText(Math.Round(rowValue, Math.Abs(ai.Scaler)).ToString(), this.FontName, this.FontSize, this.ForeColor, textRect, ReoGridHorAlign.Right, ReoGridVerAlign.Middle);

                    textRect.Y -= stepY;
                    rowValue   += Math.Round(ai.LargeStride, Math.Abs(ai.Scaler));
                }
            }
            else if (orientation == AxisOrientation.Horizontal)
            {
                RGFloat columnWidth = clientRect.Width / ai.Levels;
                var     textRect    = new Rectangle(clientRect.Left - (columnWidth / 2), clientRect.Top, columnWidth, clientRect.Height);

                for (int level = 0; level <= ai.Levels; level++)
                {
                    g.DrawText(Math.Round(rowValue, Math.Abs(ai.Scaler)).ToString(), this.FontName, this.FontSize, this.ForeColor, textRect, ReoGridHorAlign.Center, ReoGridVerAlign.Top);

                    textRect.X += columnWidth;
                    rowValue   += Math.Round(ai.LargeStride, Math.Abs(ai.Scaler));
                }
            }
        }