/// <summary> /// Renders the minor items. /// </summary> /// <param name="axis">The axis.</param> /// <param name="axisPosition">The axis position.</param> protected virtual void RenderMinorItems(AxisBase axis, double axisPosition) { var eps = axis.ActualMinorStep * 1e-3; var actualMinimum = axis.ActualMinimum; var actualMaximum = axis.ActualMaximum; var plotAreaLeft = Editor.CurveArea.Left; var plotAreaRight = Editor.CurveArea.Right; var plotAreaTop = Editor.CurveArea.Top; var plotAreaBottom = Editor.CurveArea.Bottom; var isHorizontal = axis.IsHorizontal(); double a0; double a1; var minorSegments = new List <Point>(); var minorTickSegments = new List <Point>(); GetTickPositions(axis, axis.TickStyle, axis.MinorTickSize, axis.Position, out a0, out a1); foreach (var value in MinorTickValues) { if (value < actualMinimum - eps || value > actualMaximum + eps) { continue; } if (MajorTickValues.Contains(value)) { continue; } var transformedValue = axis.Transform(value); if (isHorizontal) { SnapTo(plotAreaLeft, ref transformedValue); SnapTo(plotAreaRight, ref transformedValue); } else { SnapTo(plotAreaTop, ref transformedValue); SnapTo(plotAreaBottom, ref transformedValue); } // Draw the minor grid line if (isHorizontal) { minorSegments.Add(new Point(transformedValue, plotAreaTop)); minorSegments.Add(new Point(transformedValue, plotAreaBottom)); } else { minorSegments.Add(new Point(plotAreaLeft, transformedValue)); minorSegments.Add(new Point(plotAreaRight, transformedValue)); } // Draw the minor tick if (axis.TickStyle != TickStyle.None && axis.MinorTickSize > 0) { if (isHorizontal) { minorTickSegments.Add(new Point(transformedValue, axisPosition + a0)); minorTickSegments.Add(new Point(transformedValue, axisPosition + a1)); } else { minorTickSegments.Add(new Point(axisPosition + a0, transformedValue)); minorTickSegments.Add(new Point(axisPosition + a1, transformedValue)); } } } // Draw all the line segments DrawingContext.DrawLineSegments(minorSegments, MinorColor); DrawingContext.DrawLineSegments(minorTickSegments, MinorTickColor); }
public override void Render(Axis axis) { base.Render(axis); var perpendicularAxis = Plot.DefaultXAxis; bool isHorizontal = true; // Axis position (x or y screen coordinate) double apos = 0; switch (axis.Position) { case AxisPosition.Left: apos = Plot.PlotArea.Left; isHorizontal = false; break; case AxisPosition.Right: apos = Plot.PlotArea.Right; isHorizontal = false; break; case AxisPosition.Top: apos = Plot.PlotArea.Top; perpendicularAxis = Plot.DefaultYAxis; break; case AxisPosition.Bottom: apos = Plot.PlotArea.Bottom; perpendicularAxis = Plot.DefaultYAxis; break; } if (axis.PositionAtZeroCrossing) { apos = perpendicularAxis.Transform(0); } double a0, a1; if (axis.ShowMinorTicks) { GetTickPositions(axis, axis.TickStyle, axis.MinorTickSize, axis.Position, out a0, out a1); foreach (double value in MinorTickValues) { if (value < axis.ActualMinimum || value > axis.ActualMaximum) { continue; } if (MajorTickValues.Contains(value)) { continue; } double transformedValue = axis.Transform(value); if (MinorPen != null) { if (isHorizontal) { rc.DrawLine(transformedValue, Plot.PlotArea.Top, transformedValue, Plot.PlotArea.Bottom, MinorPen); } else { rc.DrawLine(Plot.PlotArea.Left, transformedValue, Plot.PlotArea.Right, transformedValue, MinorPen); } } if (isHorizontal) { rc.DrawLine(transformedValue, apos + a0, transformedValue, apos + a1, MinorTickPen); } else { rc.DrawLine(apos + a0, transformedValue, apos + a1, transformedValue, MinorTickPen); } } } GetTickPositions(axis, axis.TickStyle, axis.MajorTickSize, axis.Position, out a0, out a1); double maxWidth = 0; double maxHeight = 0; foreach (double value in MajorTickValues) { if (value < axis.ActualMinimum || value > axis.ActualMaximum) { continue; } double transformedValue = axis.Transform(value); if (MajorPen != null) { if (isHorizontal) { rc.DrawLine(transformedValue, Plot.PlotArea.Top, transformedValue, Plot.PlotArea.Bottom, MajorPen); } else { rc.DrawLine(Plot.PlotArea.Left, transformedValue, Plot.PlotArea.Right, transformedValue, MajorPen); } } if (isHorizontal) { rc.DrawLine(transformedValue, apos + a0, transformedValue, apos + a1, MajorTickPen); } else { rc.DrawLine(apos + a0, transformedValue, apos + a1, transformedValue, MajorTickPen); } if (value == 0 && axis.PositionAtZeroCrossing) { continue; } var pt = new ScreenPoint(); var ha = HorizontalTextAlign.Right; var va = VerticalTextAlign.Middle; switch (axis.Position) { case AxisPosition.Left: pt = new ScreenPoint(apos + a1 - TICK_DIST, transformedValue); GetRotatedAlignments(axis.Angle, HorizontalTextAlign.Right, VerticalTextAlign.Middle, out ha, out va); break; case AxisPosition.Right: pt = new ScreenPoint(apos + a1 + TICK_DIST, transformedValue); GetRotatedAlignments(axis.Angle, HorizontalTextAlign.Left, VerticalTextAlign.Middle, out ha, out va); break; case AxisPosition.Top: pt = new ScreenPoint(transformedValue, apos + a1 - TICK_DIST); GetRotatedAlignments(axis.Angle, HorizontalTextAlign.Center, VerticalTextAlign.Bottom, out ha, out va); break; case AxisPosition.Bottom: pt = new ScreenPoint(transformedValue, apos + a1 + TICK_DIST); GetRotatedAlignments(axis.Angle, HorizontalTextAlign.Center, VerticalTextAlign.Top, out ha, out va); break; } string text = axis.FormatValue(value); var size = rc.DrawMathText(pt, text, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, axis.Angle, ha, va); maxWidth = Math.Max(maxWidth, size.Width); maxHeight = Math.Max(maxHeight, size.Height); } if (axis.PositionAtZeroCrossing) { double t0 = axis.Transform(0); if (isHorizontal) { rc.DrawLine(t0, Plot.PlotArea.Top, t0, Plot.PlotArea.Bottom, ZeroPen); } else { rc.DrawLine(Plot.PlotArea.Left, t0, Plot.PlotArea.Right, t0, ZeroPen); } } if (axis.ExtraGridlines != null) { foreach (double value in axis.ExtraGridlines) { if (!IsWithin(value, axis.ActualMinimum, axis.ActualMaximum)) { continue; } double transformedValue = axis.Transform(value); if (isHorizontal) { rc.DrawLine(transformedValue, Plot.PlotArea.Top, transformedValue, Plot.PlotArea.Bottom, ExtraPen); } else { rc.DrawLine(Plot.PlotArea.Left, transformedValue, Plot.PlotArea.Right, transformedValue, ExtraPen); } } } if (isHorizontal) { rc.DrawLine(Plot.PlotArea.Left, apos, Plot.PlotArea.Right, apos, MajorPen); } else { rc.DrawLine(apos, Plot.PlotArea.Top, apos, Plot.PlotArea.Bottom, MajorPen); } if (!String.IsNullOrWhiteSpace(axis.Title)) { // Axis legend double ymid = axis.Transform((axis.ActualMinimum + axis.ActualMaximum) / 2); double angle = -90; var lpt = new ScreenPoint(); var halign = HorizontalTextAlign.Center; var valign = VerticalTextAlign.Top; if (axis.PositionAtZeroCrossing) { ymid = perpendicularAxis.Transform(perpendicularAxis.ActualMaximum); // valign = axis.IsReversed ? VerticalTextAlign.Top : VerticalTextAlign.Bottom; } switch (axis.Position) { case AxisPosition.Left: lpt = new ScreenPoint(AXIS_LEGEND_DIST, ymid); break; case AxisPosition.Right: lpt = new ScreenPoint(rc.Width - AXIS_LEGEND_DIST, ymid); valign = VerticalTextAlign.Bottom; break; case AxisPosition.Top: lpt = new ScreenPoint(ymid, AXIS_LEGEND_DIST); halign = HorizontalTextAlign.Center; valign = VerticalTextAlign.Top; angle = 0; break; case AxisPosition.Bottom: lpt = new ScreenPoint(ymid, rc.Height - AXIS_LEGEND_DIST); halign = HorizontalTextAlign.Center; valign = VerticalTextAlign.Bottom; angle = 0; break; } rc.DrawText(lpt, axis.Title, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, angle, halign, valign); } }