public virtual Point Transform(double x, double y, Axis yAxis) { Debug.Assert(yAxis != null); if (IsPolar) { double r = (x - Offset) * Scale; double th = yAxis != null ? (y - yAxis.Offset) * yAxis.Scale : double.NaN; return(new Point(MidPoint.X + r * Math.Cos(th), MidPoint.Y + r * Math.Sin(th))); } if (yAxis == null) { return(new Point()); } return(new Point(TransformX(x), yAxis != null ? yAxis.TransformX(y) : double.NaN)); }
private void RenderVerticalAxis(Axis axis, Axis perpendicularAxis) { double x = Plot.Bounds.Left; switch (axis.Position) { case AxisPosition.Left: x = Plot.Bounds.Left; break; case AxisPosition.Right: x = Plot.Bounds.Right; break; } if (axis.PositionAtZeroCrossing) { x = perpendicularAxis.TransformX(0); } double x0, x1; if (axis.ShowMinorTicks) { GetHorizontalTickPositions(axis, axis.TickStyle, axis.MinorTickSize, out x0, out x1); foreach (double yValue in minorTickValues) { if (yValue < axis.ActualMinimum || yValue > axis.ActualMaximum) { continue; } if (majorTickValues.Contains(yValue)) { continue; } double y = axis.TransformX(yValue); if (minorPen != null) { RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, minorPen); } RenderLine(x + x0, y, x + x1, y, minorTickPen); } } GetHorizontalTickPositions(axis, axis.TickStyle, axis.MajorTickSize, out x0, out x1); double maxw = 0; bool isleft = axis.Position == AxisPosition.Left; foreach (double yValue in majorTickValues) { if (yValue < axis.ActualMinimum || yValue > axis.ActualMaximum) { continue; } double y = axis.TransformX(yValue); if (majorPen != null) { RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, majorPen); } RenderLine(x + x0, y, x + x1, y, majorTickPen); if (yValue == 0 && axis.PositionAtZeroCrossing) { continue; } var pt = new ScreenPoint(isleft ? x + x1 - TICK_DIST : x + x1 + TICK_DIST, y); string text = axis.FormatValue(yValue); double w = rc.MeasureText(text, axis.FontFamily, axis.FontSize, axis.FontWeight).Height; rc.DrawText(pt, text, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, axis.Angle, isleft ? HorizontalTextAlign.Right : HorizontalTextAlign.Left, VerticalTextAlign.Middle); maxw = Math.Max(maxw, w); } if (axis.PositionAtZeroCrossing) { double y = axis.TransformX(0); RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, zeroPen); } if (axis.ExtraGridlines != null) { foreach (double y in axis.ExtraGridlines) { if (!IsWithin(y, axis.ActualMinimum, axis.ActualMaximum)) { continue; } double sy = axis.TransformX(y); RenderLine(Plot.Bounds.Left, sy, Plot.Bounds.Right, sy, extraPen); } } RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, majorPen); double ymid = axis.TransformX((axis.ActualMinimum + axis.ActualMaximum) / 2); HorizontalTextAlign halign = HorizontalTextAlign.Center; VerticalTextAlign valign = VerticalTextAlign.Top; if (axis.PositionAtZeroCrossing) { ymid = perpendicularAxis.TransformX(perpendicularAxis.ActualMaximum); // valign = axis.IsReversed ? VerticalTextAlign.Top : VerticalTextAlign.Bottom; } if (isleft) { x = AXIS_LEGEND_DIST; } else { x = rc.Width - AXIS_LEGEND_DIST; valign = VerticalTextAlign.Bottom; } rc.DrawText(new ScreenPoint(x, ymid), axis.Title, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, -90, halign, valign); }
private void RenderHorizontalAxis(Axis axis, Axis perpendicularAxis) { double y = Plot.Bounds.Bottom; switch (axis.Position) { case AxisPosition.Top: y = Plot.Bounds.Top; break; case AxisPosition.Bottom: y = Plot.Bounds.Bottom; break; } if (axis.PositionAtZeroCrossing) { y = perpendicularAxis.TransformX(0); } double y0, y1; if (axis.ShowMinorTicks) { GetVerticalTickPositions(axis, axis.TickStyle, axis.MinorTickSize, out y0, out y1); foreach (double xValue in minorTickValues) { if (xValue < axis.ActualMinimum || xValue > axis.ActualMaximum) { continue; } if (majorTickValues.Contains(xValue)) { continue; } double x = axis.TransformX(xValue); if (minorPen != null) { RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, minorPen); } RenderLine(x, y + y0, x, y + y1, minorTickPen); } } GetVerticalTickPositions(axis, axis.TickStyle, axis.MajorTickSize, out y0, out y1); double maxh = 0; bool istop = axis.Position == AxisPosition.Top; foreach (double xValue in majorTickValues) { if (xValue < axis.ActualMinimum || xValue > axis.ActualMaximum) { continue; } double x = axis.TransformX(xValue); if (majorPen != null) { RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, majorPen); } RenderLine(x, y + y0, x, y + y1, majorTickPen); if (xValue == 0 && axis.PositionAtZeroCrossing) { continue; } var pt = new ScreenPoint(x, istop ? y + y1 - TICK_DIST : y + y1 + TICK_DIST); string text = axis.FormatValue(xValue); double h = rc.MeasureText(text, axis.FontFamily, axis.FontSize, axis.FontWeight).Height; rc.DrawText(pt, text, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, axis.Angle, HorizontalTextAlign.Center, istop ? VerticalTextAlign.Bottom : VerticalTextAlign.Top); maxh = Math.Max(maxh, h); } if (axis.PositionAtZeroCrossing) { double x = axis.TransformX(0); RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, zeroPen); } if (axis.ExtraGridlines != null) { foreach (double x in axis.ExtraGridlines) { if (!IsWithin(x, axis.ActualMinimum, axis.ActualMaximum)) { continue; } double sx = axis.TransformX(x); RenderLine(sx, Plot.Bounds.Top, sx, Plot.Bounds.Bottom, extraPen); } } // The horizontal axis line RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, majorPen); // The horizontal axis legend (centered horizontally) double legendX = axis.TransformX((axis.ActualMinimum + axis.ActualMaximum) / 2); HorizontalTextAlign halign = HorizontalTextAlign.Center; VerticalTextAlign valign = VerticalTextAlign.Bottom; if (axis.PositionAtZeroCrossing) { legendX = perpendicularAxis.TransformX(perpendicularAxis.ActualMaximum); } double legendY = rc.Height - AXIS_LEGEND_DIST; if (istop) { legendY = AXIS_LEGEND_DIST; valign = VerticalTextAlign.Top; } rc.DrawText(new ScreenPoint(legendX, legendY), axis.Title, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, 0, halign, valign); }
private void RenderVerticalAxis(Axis axis, Axis perpendicularAxis) { double x = Plot.Bounds.Left; switch (axis.Position) { case AxisPosition.Left: x = Plot.Bounds.Left; break; case AxisPosition.Right: x = Plot.Bounds.Right; break; } if (axis.PositionAtZeroCrossing) x = perpendicularAxis.TransformX(0); double x0, x1; if (axis.ShowMinorTicks) { GetHorizontalTickPositions(axis, axis.TickStyle, axis.MinorTickSize, out x0, out x1); foreach (double yValue in minorTickValues) { if (yValue < axis.ActualMinimum || yValue > axis.ActualMaximum) { continue; } if (majorTickValues.Contains(yValue)) { continue; } double y = axis.TransformX(yValue); if (minorPen != null) { RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, minorPen); } RenderLine(x + x0, y, x + x1, y, minorTickPen); } } GetHorizontalTickPositions(axis, axis.TickStyle, axis.MajorTickSize, out x0, out x1); double maxw = 0; bool isleft = axis.Position == AxisPosition.Left; foreach (double yValue in majorTickValues) { if (yValue < axis.ActualMinimum || yValue > axis.ActualMaximum) continue; double y = axis.TransformX(yValue); if (majorPen != null) { RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, majorPen); } RenderLine(x + x0, y, x + x1, y, majorTickPen); if (yValue == 0 && axis.PositionAtZeroCrossing) continue; var pt = new ScreenPoint(isleft ? x + x1 - TICK_DIST : x + x1 + TICK_DIST, y); string text = axis.FormatValue(yValue); double w = rc.MeasureText(text, axis.FontFamily, axis.FontSize, axis.FontWeight).Height; rc.DrawText(pt, text, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, axis.Angle, isleft ? HorizontalTextAlign.Right : HorizontalTextAlign.Left, VerticalTextAlign.Middle); maxw = Math.Max(maxw, w); } if (axis.PositionAtZeroCrossing) { double y = axis.TransformX(0); RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, zeroPen); } if (axis.ExtraGridlines != null) foreach (double y in axis.ExtraGridlines) { if (!IsWithin(y, axis.ActualMinimum, axis.ActualMaximum)) continue; double sy = axis.TransformX(y); RenderLine(Plot.Bounds.Left, sy, Plot.Bounds.Right, sy, extraPen); } RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, majorPen); double ymid = axis.TransformX((axis.ActualMinimum + axis.ActualMaximum)/2); HorizontalTextAlign halign = HorizontalTextAlign.Center; VerticalTextAlign valign = VerticalTextAlign.Top; if (axis.PositionAtZeroCrossing) { ymid = perpendicularAxis.TransformX(perpendicularAxis.ActualMaximum); // valign = axis.IsReversed ? VerticalTextAlign.Top : VerticalTextAlign.Bottom; } if (isleft) { x = AXIS_LEGEND_DIST; } else { x = rc.Width - AXIS_LEGEND_DIST; valign = VerticalTextAlign.Bottom; } rc.DrawText(new ScreenPoint(x, ymid), axis.Title, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, -90, halign, valign); }
private void RenderHorizontalAxis(Axis axis, Axis perpendicularAxis) { double y = Plot.Bounds.Bottom; switch (axis.Position) { case AxisPosition.Top: y = Plot.Bounds.Top; break; case AxisPosition.Bottom: y = Plot.Bounds.Bottom; break; } if (axis.PositionAtZeroCrossing) { y = perpendicularAxis.TransformX(0); } double y0, y1; if (axis.ShowMinorTicks) { GetVerticalTickPositions(axis, axis.TickStyle, axis.MinorTickSize, out y0, out y1); foreach (double xValue in minorTickValues) { if (xValue < axis.ActualMinimum || xValue > axis.ActualMaximum) { continue; } if (majorTickValues.Contains(xValue)) { continue; } double x = axis.TransformX(xValue); if (minorPen != null) { RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, minorPen); } RenderLine(x, y + y0, x, y + y1, minorTickPen); } } GetVerticalTickPositions(axis, axis.TickStyle, axis.MajorTickSize, out y0, out y1); double maxh = 0; bool istop = axis.Position == AxisPosition.Top; foreach (double xValue in majorTickValues) { if (xValue < axis.ActualMinimum || xValue > axis.ActualMaximum) { continue; } double x = axis.TransformX(xValue); if (majorPen != null) { RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, majorPen); } RenderLine(x, y + y0, x, y + y1, majorTickPen); if (xValue == 0 && axis.PositionAtZeroCrossing) continue; var pt = new ScreenPoint(x, istop ? y + y1 - TICK_DIST : y + y1 + TICK_DIST); string text = axis.FormatValue(xValue); double h = rc.MeasureText(text, axis.FontFamily, axis.FontSize, axis.FontWeight).Height; rc.DrawText(pt, text, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, axis.Angle, HorizontalTextAlign.Center, istop ? VerticalTextAlign.Bottom : VerticalTextAlign.Top); maxh = Math.Max(maxh, h); } if (axis.PositionAtZeroCrossing) { double x = axis.TransformX(0); RenderLine(x, Plot.Bounds.Top, x, Plot.Bounds.Bottom, zeroPen); } if (axis.ExtraGridlines != null) { foreach (double x in axis.ExtraGridlines) { if (!IsWithin(x, axis.ActualMinimum, axis.ActualMaximum)) continue; double sx = axis.TransformX(x); RenderLine(sx, Plot.Bounds.Top, sx, Plot.Bounds.Bottom, extraPen); } } // The horizontal axis line RenderLine(Plot.Bounds.Left, y, Plot.Bounds.Right, y, majorPen); // The horizontal axis legend (centered horizontally) double legendX = axis.TransformX((axis.ActualMinimum + axis.ActualMaximum)/2); HorizontalTextAlign halign = HorizontalTextAlign.Center; VerticalTextAlign valign = VerticalTextAlign.Bottom; if (axis.PositionAtZeroCrossing) { legendX = perpendicularAxis.TransformX(perpendicularAxis.ActualMaximum); } double legendY = rc.Height - AXIS_LEGEND_DIST; if (istop) { legendY = AXIS_LEGEND_DIST; valign = VerticalTextAlign.Top; } rc.DrawText(new ScreenPoint(legendX, legendY), axis.Title, Plot.TextColor, axis.FontFamily, axis.FontSize, axis.FontWeight, 0, halign, valign); }
public virtual Point Transform(double x, double y, Axis yAxis) { Debug.Assert(yAxis != null); if (IsPolar) { double r = (x - Offset) * Scale; double th = yAxis != null ? (y - yAxis.Offset) * yAxis.Scale : double.NaN; return new Point(MidPoint.X + r * Math.Cos(th), MidPoint.Y + r * Math.Sin(th)); } if (yAxis == null) return new Point(); return new Point(TransformX(x), yAxis != null ? yAxis.TransformX(y) : double.NaN); }