/// <summary> /// Calculates the space used for the axis title. /// </summary> internal override void Format() { XGraphics gfx = this.rendererParms.Graphics; AxisTitleRendererInfo atri = ((AxisRendererInfo)this.rendererParms.RendererInfo).axisTitleRendererInfo; if (atri.AxisTitleText != "") { XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); if (atri.AxisTitleOrientation != 0) { XPoint[] points = new XPoint[2]; points[0].X = 0; points[0].Y = 0; points[1].X = size.Width; points[1].Y = size.Height; XMatrix matrix = new XMatrix(); //XMatrix.Identity; matrix.RotatePrepend(-atri.AxisTitleOrientation); matrix.TransformPoints(points); size.Width = Math.Abs(points[1].X - points[0].X); size.Height = Math.Abs(points[1].Y - points[0].Y); } atri.X = 0; atri.Y = 0; atri.Height = size.Height; atri.Width = size.Width; } }
/// <summary> /// Initializes the axis title of the rendererInfo. All missing font attributes will be taken /// from the specified defaultFont. /// </summary> protected void InitAxisTitle(AxisRendererInfo rendererInfo, XFont defaultFont) { if (rendererInfo.axis.title != null) { AxisTitleRendererInfo atri = new AxisTitleRendererInfo(); rendererInfo.axisTitleRendererInfo = atri; atri.axisTitle = rendererInfo.axis.title; atri.AxisTitleText = rendererInfo.axis.title.caption; atri.AxisTitleAlignment = rendererInfo.axis.title.alignment; atri.AxisTitleVerticalAlignment = rendererInfo.axis.title.verticalAlignment; atri.AxisTitleFont = Converter.ToXFont(rendererInfo.axis.title.font, defaultFont); XColor fontColor = XColors.Black; if (rendererInfo.axis.title.font != null && !rendererInfo.axis.title.font.color.IsEmpty) { fontColor = rendererInfo.axis.title.font.color; } atri.AxisTitleBrush = new XSolidBrush(fontColor); atri.AxisTitleOrientation = rendererInfo.axis.title.orientation; } }
/// <summary> /// Calculates the space used for the X axis. /// </summary> internal override void Format() { AxisRendererInfo xari = ((ChartRendererInfo)this.rendererParms.RendererInfo).xAxisRendererInfo; if (xari.axis != null) { AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; // Calculate space used for axis title. XSize titleSize = new XSize(0, 0); if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { titleSize = this.rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); atri.AxisTitleSize = titleSize; } // Calculate space used for tick labels. XSize size = new XSize(0, 0); if (xari.XValues.Count > 0) { XSeries xs = xari.XValues[0]; foreach (XValue xv in xs) { if (xv != null) { string tickLabel = xv.Value; XSize valueSize = this.rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont); size.Height = Math.Max(valueSize.Height, size.Height); size.Width += valueSize.Width; } } } // Remember space for later drawing. xari.TickLabelsHeight = size.Height; xari.Height = titleSize.Height + size.Height + xari.MajorTickMarkWidth; xari.Width = Math.Max(titleSize.Width, size.Width); } }
/// <summary> /// Draws the axis title. /// </summary> internal override void Draw() { AxisRendererInfo ari = (AxisRendererInfo)this.rendererParms.RendererInfo; AxisTitleRendererInfo atri = ari.axisTitleRendererInfo; if (atri.AxisTitleText != "") { XGraphics gfx = this.rendererParms.Graphics; if (atri.AxisTitleOrientation != 0) { XRect layout = atri.Rect; layout.X = -(layout.Width / 2); layout.Y = -(layout.Height / 2); double x = 0; switch (atri.AxisTitleAlignment) { case HorizontalAlignment.Center: x = atri.X + atri.Width / 2; break; case HorizontalAlignment.Right: x = atri.X + atri.Width - layout.Width / 2; break; case HorizontalAlignment.Left: default: x = atri.X; break; } double y = 0; switch (atri.AxisTitleVerticalAlignment) { case VerticalAlignment.Center: y = atri.Y + atri.Height / 2; break; case VerticalAlignment.Bottom: y = atri.Y + atri.Height - layout.Height / 2; break; case VerticalAlignment.Top: default: y = atri.Y; break; } XStringFormat xsf = new XStringFormat(); xsf.Alignment = XStringAlignment.Center; xsf.LineAlignment = XLineAlignment.Center; XGraphicsState state = gfx.Save(); gfx.TranslateTransform(x, y); gfx.RotateTransform(-atri.AxisTitleOrientation); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, layout, xsf); gfx.Restore(state); } else { XStringFormat format = new XStringFormat(); switch (atri.AxisTitleAlignment) { case HorizontalAlignment.Center: format.Alignment = XStringAlignment.Center; break; case HorizontalAlignment.Right: format.Alignment = XStringAlignment.Far; break; case HorizontalAlignment.Left: default: format.Alignment = XStringAlignment.Near; break; } switch (atri.AxisTitleVerticalAlignment) { case VerticalAlignment.Center: format.LineAlignment = XLineAlignment.Center; break; case VerticalAlignment.Bottom: format.LineAlignment = XLineAlignment.Far; break; case VerticalAlignment.Top: default: format.LineAlignment = XLineAlignment.Near; break; } gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, atri.Rect, format); } } }
/// <summary> /// Draws the horizontal X axis. /// </summary> internal override void Draw() { XGraphics gfx = this.rendererParms.Graphics; ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo; AxisRendererInfo xari = cri.xAxisRendererInfo; double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double xMinorTick = xari.MinorTick; double xMaxExtension = xari.MajorTick; // Draw tick labels. Each tick label will be aligned centered. int countTickLabels = (int)xMax; double tickLabelStep = xari.Height / countTickLabels; XPoint startPos = new XPoint(xari.X + xari.Width - xari.MajorTickMarkWidth, xari.Y + tickLabelStep / 2); foreach (XSeries xs in xari.XValues) { for (int idx = countTickLabels - 1; idx >= 0; --idx) { XValue xv = xs[idx]; string tickLabel = xv.Value; XSize size = gfx.MeasureString(tickLabel, xari.TickLabelsFont); gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width, startPos.Y + size.Height / 2); startPos.Y += tickLabelStep; } } // Draw axis. // First draw tick marks, second draw axis. double majorTickMarkStart = 0, majorTickMarkEnd = 0, minorTickMarkStart = 0, minorTickMarkEnd = 0; GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd); LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat); XPoint[] points = new XPoint[2]; // Minor ticks. if (xari.MinorTickMark != TickMarkType.None) { int countMinorTickMarks = (int)(xMax / xMinorTick); double minorTickMarkStep = xari.Height / countMinorTickMarks; startPos.Y = xari.Y; for (int x = 0; x <= countMinorTickMarks; x++) { points[0].X = minorTickMarkStart; points[0].Y = startPos.Y + minorTickMarkStep * x; points[1].X = minorTickMarkEnd; points[1].Y = points[0].Y; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Major ticks. if (xari.MajorTickMark != TickMarkType.None) { int countMajorTickMarks = (int)(xMax / xMajorTick); double majorTickMarkStep = xari.Height / countMajorTickMarks; startPos.Y = xari.Y; for (int x = 0; x <= countMajorTickMarks; x++) { points[0].X = majorTickMarkStart; points[0].Y = startPos.Y + majorTickMarkStep * x; points[1].X = majorTickMarkEnd; points[1].Y = points[0].Y; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Axis. if (xari.LineFormat != null) { points[0].X = xari.X + xari.Width; points[0].Y = xari.Y; points[1].X = xari.X + xari.Width; points[1].Y = xari.Y + xari.Height; if (xari.MajorTickMark != TickMarkType.None) { points[0].Y -= xari.LineFormat.Width / 2; points[1].Y += xari.LineFormat.Width / 2; } lineFormatRenderer.DrawLine(points[0], points[1]); } // Draw axis title. AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { XRect rect = new XRect(xari.X, xari.Y + xari.Height / 2, atri.AxisTitleSize.Width, 0); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect); } }
/// <summary> /// Calculates the space used for the X axis. /// </summary> internal override void Format() { AxisRendererInfo xari = ((ChartRendererInfo)this.rendererParms.RendererInfo).xAxisRendererInfo; if (xari.axis != null) { AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; // Calculate space used for axis title. XSize titleSize = new XSize(0, 0); if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { titleSize = this.rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); atri.AxisTitleSize = titleSize; } Chart chart = (Chart)this.rendererParms.DrawingItem; XSize size = new XSize(0, 0); bool isxy = false; Series s = chart.seriesCollection[0]; if (s != null && s.Elements.getPointX(0) != null) { isxy = true; // width of all ticklabels double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double lineHeight = Double.MinValue; XSize labelSize = new XSize(0, 0); XGraphics gfx = this.rendererParms.Graphics; for (double x = xMin; x <= xMax; x += xMajorTick) { string str = x.ToString(xari.TickLabelsFormat); labelSize = gfx.MeasureString(str, xari.TickLabelsFont); size.Width += labelSize.Width; size.Height = Math.Max(size.Height, labelSize.Height); lineHeight = Math.Max(lineHeight, labelSize.Height); } // add space for tickmarks size.Width += xari.MajorTickMarkWidth * 1.5; } if (!isxy) { // Calculate space used for tick labels. if (xari.XValues.Count > 0) { XSeries xs = xari.XValues[0]; foreach (XValue xv in xs) { if (xv != null) { string tickLabel = xv.Value; XSize valueSize = this.rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont); size.Height = Math.Max(valueSize.Height, size.Height); size.Width += valueSize.Width; } } } // Remember space for later drawing. xari.TickLabelsHeight = size.Height; xari.Height = titleSize.Height + size.Height + xari.MajorTickMarkWidth; xari.Width = Math.Max(titleSize.Width, size.Width); } } }
/// <summary> /// Draws the horizontal X axis. /// </summary> internal override void Draw() { XGraphics gfx = this.rendererParms.Graphics; ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo; AxisRendererInfo xari = cri.xAxisRendererInfo; LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat); double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double xMinorTick = xari.MinorTick; double xMaxExtension = xari.MajorTick; bool isxy = false; double majorTickMarkStart = 0, majorTickMarkEnd = 0, minorTickMarkStart = 0, minorTickMarkEnd = 0; GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd); XPoint[] points = new XPoint[2]; Chart chart = (Chart)this.rendererParms.DrawingItem; Series s = chart.seriesCollection[0]; double tickLabelStep = xari.Width; int countTickLabels = (int)xMax; // for non-xy if (countTickLabels != 0) { tickLabelStep = xari.Width / countTickLabels; } XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + xari.TickLabelsHeight); if (s != null && s.Elements.getPointX(0) != null) { isxy = true; countTickLabels = (int)((xMax - xMin) / xMajorTick) + 1; if (countTickLabels != 0) { tickLabelStep = xari.Width / countTickLabels; } startPos = new XPoint(0, xari.Y + xari.TickLabelsHeight); XMatrix matrix = new XMatrix(); //XMatrix.Identity; //matrix.TranslatePrepend(xari.X, xari.InnerRect.Y ); //-xari.InnerRect.X, xMax); matrix.Scale(xari.InnerRect.Width / (xMax - xMin), 1, XMatrixOrder.Append); //matrix.ScalePrepend( 1, 1); // mirror Vertical matrix.Translate(xari.InnerRect.X, xari.InnerRect.Y, XMatrixOrder.Append); if (xari.MajorTickMark != TickMarkType.None) { startPos.Y += xari.MajorTickMarkWidth; } //matrix.OffsetX = startPos.X; // Draw axis. // First draw tick marks, second draw axis. LineFormatRenderer minorTickMarkLineFormat = new LineFormatRenderer(gfx, xari.MinorTickMarkLineFormat); LineFormatRenderer majorTickMarkLineFormat = new LineFormatRenderer(gfx, xari.MajorTickMarkLineFormat); // Draw minor tick marks. if (xari.MinorTickMark != TickMarkType.None) { for (double x = xMin + xMinorTick; x < xMax; x += xMinorTick) { points[0].X = x; points[0].Y = minorTickMarkStart; points[1].X = x; points[1].Y = minorTickMarkEnd; matrix.TransformPoints(points); minorTickMarkLineFormat.DrawLine(points[0], points[1]); } } double lineSpace = xari.TickLabelsFont.GetHeight(); int cellSpace = xari.TickLabelsFont.FontFamily.GetLineSpacing(xari.TickLabelsFont.Style); double xHeight = xari.TickLabelsFont.Metrics.XHeight; XSize labelSize = new XSize(0, 0); labelSize.Height = lineSpace * xHeight / cellSpace; for (int i = 0; i < countTickLabels; ++i) { double x = xMin + xMajorTick * i; string str = x.ToString(xari.TickLabelsFormat); labelSize = gfx.MeasureString(str, xari.TickLabelsFont); // Draw major tick marks. if (xari.MajorTickMark != TickMarkType.None) { labelSize.Width += xari.MajorTickMarkWidth * 1.5; points[0].X = x; points[0].Y = 0; // majorTickMarkStart; points[1].X = x; points[1].Y = 0; // majorTickMarkEnd; matrix.TransformPoints(points); points[1].Y += xari.MajorTickMarkWidth; majorTickMarkLineFormat.DrawLine(points[0], points[1]); } else { labelSize.Height += SpaceBetweenLabelAndTickmark; } // Draw label text. XPoint[] layoutText = new XPoint[1]; layoutText[0].X = x; layoutText[0].Y = 0; matrix.TransformPoints(layoutText); layoutText[0].Y += labelSize.Height; layoutText[0].X -= labelSize.Width / 2; // Center text horizontally gfx.DrawString(str, xari.TickLabelsFont, xari.TickLabelsBrush, layoutText[0]); } } if (!isxy) { // Draw tick labels. Each tick label will be aligned centered. //XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + /*xari.TickLabelsHeight +*/ xari.MajorTickMarkWidth); if (xari.MajorTickMark != TickMarkType.None) { startPos.Y += xari.MajorTickMarkWidth; } foreach (XSeries xs in xari.XValues) { for (int idx = 0; idx < countTickLabels && idx < xs.Count; ++idx) { XValue xv = xs[idx]; if (xv != null) { string tickLabel = xv.Value; XSize size = gfx.MeasureString(tickLabel, xari.TickLabelsFont); gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width / 2, startPos.Y); } startPos.X += tickLabelStep; } } // Minor ticks. if (xari.MinorTickMark != TickMarkType.None) { int countMinorTickMarks = (int)(xMax / xMinorTick); double minorTickMarkStep = xari.Width / countMinorTickMarks; startPos.X = xari.X; for (int x = 0; x <= countMinorTickMarks; x++) { points[0].X = startPos.X + minorTickMarkStep * x; points[0].Y = minorTickMarkStart; points[1].X = points[0].X; points[1].Y = minorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Major ticks. if (xari.MajorTickMark != TickMarkType.None) { int countMajorTickMarks = (int)(xMax / xMajorTick); double majorTickMarkStep = xari.Width; if (countMajorTickMarks != 0) { majorTickMarkStep = xari.Width / countMajorTickMarks; } startPos.X = xari.X; for (int x = 0; x <= countMajorTickMarks; x++) { points[0].X = startPos.X + majorTickMarkStep * x; points[0].Y = majorTickMarkStart; points[1].X = points[0].X; points[1].Y = majorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } } // Axis. if (xari.LineFormat != null) { points[0].X = xari.X; points[0].Y = xari.Y; points[1].X = xari.X + xari.Width; points[1].Y = xari.Y; if (xari.MajorTickMark != TickMarkType.None) { points[0].X -= xari.LineFormat.Width / 2; points[1].X += xari.LineFormat.Width / 2; } lineFormatRenderer.DrawLine(points[0], points[1]); } // Draw axis title. AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); XRect rect = new XRect(xari.Rect.Right / 2 - atri.AxisTitleSize.Width / 2, xari.Rect.Bottom + size.Height * 2, atri.AxisTitleSize.Width, 0); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect); } }
/// <summary> /// Draws the horizontal X axis. /// </summary> internal override void Draw() { XGraphics gfx = this.rendererParms.Graphics; ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo; AxisRendererInfo xari = cri.xAxisRendererInfo; double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double xMinorTick = xari.MinorTick; double xMaxExtension = xari.MajorTick; // Draw tick labels. Each tick label will be aligned centered. int countTickLabels = (int)xMax; double tickLabelStep = xari.Width; if (countTickLabels != 0) { tickLabelStep = xari.Width / countTickLabels; } //XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + /*xari.TickLabelsHeight +*/ xari.MajorTickMarkWidth); XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + xari.TickLabelsHeight); if (xari.MajorTickMark != TickMarkType.None) { startPos.Y += xari.MajorTickMarkWidth; } foreach (XSeries xs in xari.XValues) { for (int idx = 0; idx < countTickLabels && idx < xs.Count; ++idx) { XValue xv = xs[idx]; if (xv != null) { string tickLabel = xv.Value; XSize size = gfx.MeasureString(tickLabel, xari.TickLabelsFont); XGraphicsState state = null; int margin = 0; if (xs.TextRotation != default) { state = gfx.Save(); margin = 20; gfx.RotateAtTransform(xs.TextRotation, new XPoint(startPos.X - size.Width / 2, startPos.Y + margin)); } gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width / 2, startPos.Y + margin); if (xs.TextRotation != default && state != null) { gfx.Restore(state); } } startPos.X += tickLabelStep; } } // Draw axis. // First draw tick marks, second draw axis. double majorTickMarkStart = 0, majorTickMarkEnd = 0, minorTickMarkStart = 0, minorTickMarkEnd = 0; GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd); LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat); XPoint[] points = new XPoint[2]; // Minor ticks. if (xari.MinorTickMark != TickMarkType.None) { int countMinorTickMarks = (int)(xMax / xMinorTick); double minorTickMarkStep = xari.Width / countMinorTickMarks; startPos.X = xari.X; for (int x = 0; x <= countMinorTickMarks; x++) { points[0].X = startPos.X + minorTickMarkStep * x; points[0].Y = minorTickMarkStart; points[1].X = points[0].X; points[1].Y = minorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Major ticks. if (xari.MajorTickMark != TickMarkType.None) { int countMajorTickMarks = (int)(xMax / xMajorTick); double majorTickMarkStep = xari.Width; if (countMajorTickMarks != 0) { majorTickMarkStep = xari.Width / countMajorTickMarks; } startPos.X = xari.X; for (int x = 0; x <= countMajorTickMarks; x++) { points[0].X = startPos.X + majorTickMarkStep * x; points[0].Y = majorTickMarkStart; points[1].X = points[0].X; points[1].Y = majorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Axis. if (xari.LineFormat != null) { points[0].X = xari.X; points[0].Y = xari.Y; points[1].X = xari.X + xari.Width; points[1].Y = xari.Y; if (xari.MajorTickMark != TickMarkType.None) { points[0].X -= xari.LineFormat.Width / 2; points[1].X += xari.LineFormat.Width / 2; } lineFormatRenderer.DrawLine(points[0], points[1]); } // Draw axis title. AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { XRect rect = new XRect(xari.Rect.Right / 2 - atri.AxisTitleSize.Width / 2, xari.Rect.Bottom, atri.AxisTitleSize.Width, 0); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect); } }