Repository navigation
Add AxisArea, AxisLineArea and AxisTitleArea property in Axis class (… #1966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 9 commits
1959a5f
77d5352
53b2ef2
a7a5db8
284c795
e8e3df6
ac877c1
aa9a369
c3eb7e3
ce40c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,13 +51,18 @@ public override void Render(Axis axis, int pass) | |
|
|
||
| var axisLength = Math.Abs(scaledEndAngle - scaledStartAngle); | ||
| var eps = axis.MinorStep * 1e-3; | ||
|
|
||
| ScreenPoint? innerTangentPoint = null; | ||
| double maxTextLength = double.MinValue; | ||
|
|
||
| if (this.MinorPen != null) | ||
| { | ||
| var tickCount = Math.Abs((int)(axisLength / axis.ActualMinorStep)); | ||
| var screenPoints = this.MinorTickValues | ||
| .Take(tickCount + 1) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| innerTangentPoint = screenPoints.FirstOrDefault(); | ||
| foreach (var screenPoint in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, screenPoint.x, screenPoint.y, this.MinorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -77,6 +82,8 @@ public override void Render(Axis axis, int pass) | |
| .Take(majorTickCount) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| if (innerTangentPoint == null && screenPoints.Count() > 0) | ||
| innerTangentPoint = screenPoints.FirstOrDefault(); | ||
| foreach (var point in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, point.x, point.y, this.MajorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -112,9 +119,26 @@ public override void Render(Axis axis, int pass) | |
| ha = HorizontalAlignment.Right; | ||
| } | ||
|
|
||
| maxTextLength = Math.Max(maxTextLength, this.RenderContext.MeasureText(text).Width); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be |
||
|
|
||
| this.RenderContext.DrawMathText( | ||
| pt, text, axis.ActualTextColor, axis.ActualFont, axis.ActualFontSize, axis.ActualFontWeight, angle, ha, va); | ||
| } | ||
|
|
||
| if (innerTangentPoint != null) | ||
| { | ||
| double r1 = magnitudeAxis.MidPoint.DistanceTo(innerTangentPoint.Value); | ||
| double r2 = r1 + maxTextLength + axis.AxisTickToLabelDistance; | ||
| if (r2 < 5) | ||
| r2 = r1 + 5; | ||
| axis.AxisLineArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| axis.AxisArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| } | ||
| else | ||
| { | ||
| axis.AxisLineArea = new EmptyShape(); | ||
| axis.AxisArea = new EmptyShape(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,6 +274,40 @@ protected virtual void RenderAxisTitle(Axis axis, double titlePosition) | |
|
|
||
| var lpt = this.GetAxisTitlePositionAndAlignment(axis, titlePosition, ref angle, ref halign, ref valign); | ||
|
|
||
| var titleSize = this.RenderContext.MeasureText(axis.ActualTitle, axis.ActualTitleFont, axis.TitleFontSize, axis.TitleFontWeight); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be |
||
|
|
||
| ScreenPoint areaBottomLeft = new ScreenPoint(0, 0); | ||
| ScreenPoint areaTopRight = new ScreenPoint(0, 0); | ||
|
|
||
| switch (axis.Position) | ||
| { | ||
| case AxisPosition.Left: | ||
| areaTopRight = new ScreenPoint(lpt.X, lpt.Y + titleSize.Width * 0.5); | ||
| areaBottomLeft = new ScreenPoint(lpt.X + titleSize.Height, lpt.Y - titleSize.Width * 0.5); | ||
| break; | ||
| case AxisPosition.Right: | ||
| areaTopRight = new ScreenPoint(lpt.X - titleSize.Height, lpt.Y + titleSize.Width * 0.5); | ||
| areaBottomLeft = new ScreenPoint(lpt.X, lpt.Y - titleSize.Width * 0.5); | ||
| break; | ||
| case AxisPosition.Top: | ||
| areaTopRight = new ScreenPoint(lpt.X - titleSize.Width * 0.5, lpt.Y + titleSize.Height); | ||
| areaBottomLeft = new ScreenPoint(lpt.X + titleSize.Width * 0.5, lpt.Y); | ||
| break; | ||
| case AxisPosition.Bottom: | ||
| areaTopRight = new ScreenPoint(lpt.x - titleSize.Width * 0.5, lpt.Y); | ||
| areaBottomLeft = new ScreenPoint(lpt.X + titleSize.Width * 0.5, lpt.Y - titleSize.Height); | ||
| break; | ||
|
|
||
| } | ||
| // TODO: ensure min area of 5px x X to capture clicks, o this above acc. to axis position | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this TODO get resolved?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VisualMelon I added two examples based on @Jonarw's code above and added the AxisArea to be set for the MagnitudeAxisRenderer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks indeed! Shall try to take a proper look myself later today. |
||
| //if (Math.Abs(this.pt2.X - this.pt3.X) < 5) | ||
| // this.pt3.X = this.pt2.X + 5; | ||
|
|
||
| axis.TitleArea = new OxyRect(areaBottomLeft, areaTopRight); | ||
|
|
||
| if (axis.AxisLineArea is OxyRect axisLineArea) | ||
| axis.AxisArea = axisLineArea.Union(new OxyRect(areaBottomLeft, areaTopRight)); | ||
|
|
||
| this.RenderContext.DrawMathText( | ||
| lpt, | ||
| axis.ActualTitle, | ||
|
|
@@ -296,6 +330,9 @@ protected virtual void RenderAxisTitle(Axis axis, double titlePosition) | |
| /// <param name="drawAxisLine">Draw the axis line if set to <c>true</c>.</param> | ||
| protected virtual void RenderMajorItems(Axis axis, double axisPosition, double titlePosition, bool drawAxisLine) | ||
| { | ||
| ScreenPoint pt0; | ||
| ScreenPoint pt1; | ||
|
Comment on lines
+344
to
+345
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move these guys to just above their usage |
||
|
|
||
| double eps = axis.ActualMinorStep * 1e-3; | ||
|
|
||
| double clipMinimum = axis.ClipMinimum; | ||
|
|
@@ -378,6 +415,10 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| } | ||
| } | ||
|
|
||
| // Label max width | ||
| double labelEndPosition = double.MinValue; | ||
| if (axis.Position == AxisPosition.Left || axis.Position == AxisPosition.Top) labelEndPosition = double.MaxValue; | ||
|
|
||
| // Render the axis labels (numbers or category names) | ||
| foreach (double value in this.MajorLabelValues) | ||
| { | ||
|
|
@@ -403,6 +444,9 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| SnapTo(plotAreaBottom, ref transformedValue); | ||
| } | ||
|
|
||
| string text = axis.FormatValue(value); | ||
| var labelSize = this.RenderContext.MeasureText(text, axis.ActualFont, axis.ActualFontSize, axis.ActualFontWeight); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the overload that takes an angle and passing it |
||
|
|
||
| var pt = new ScreenPoint(); | ||
| var ha = HorizontalAlignment.Right; | ||
| var va = VerticalAlignment.Middle; | ||
|
|
@@ -412,25 +456,40 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| pt = new ScreenPoint(axisPosition + a1 - axis.AxisTickToLabelDistance, transformedValue); | ||
| this.GetRotatedAlignments(axis.Angle, -90, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.x - labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.x - labelSize.Height); | ||
| break; | ||
| case AxisPosition.Right: | ||
| pt = new ScreenPoint(axisPosition + a1 + axis.AxisTickToLabelDistance, transformedValue); | ||
| this.GetRotatedAlignments(axis.Angle, 90, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.x + labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.x + labelSize.Height); | ||
| break; | ||
|
|
||
| case AxisPosition.Top: | ||
| pt = new ScreenPoint(transformedValue, axisPosition + a1 - axis.AxisTickToLabelDistance); | ||
| this.GetRotatedAlignments(axis.Angle, 0, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.y - labelSize.Height); | ||
| else | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.y - labelSize.Width); | ||
| break; | ||
| case AxisPosition.Bottom: | ||
| pt = new ScreenPoint(transformedValue, axisPosition + a1 + axis.AxisTickToLabelDistance); | ||
| this.GetRotatedAlignments(axis.Angle, -180, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.y + labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.y + labelSize.Height); | ||
| break; | ||
| } | ||
|
|
||
| string text = axis.FormatValue(value); | ||
| this.RenderContext.DrawMathText( | ||
| pt, | ||
| text, | ||
|
|
@@ -471,6 +530,21 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| this.RenderContext.DrawLineSegments(extraSegments, this.ExtraPen, axis.EdgeRenderingMode.GetActual(EdgeRenderingMode.PreferSharpness)); | ||
| } | ||
|
|
||
| // Capture the points for the axis area | ||
| if (isHorizontal) | ||
| { | ||
| pt0 = new ScreenPoint(axis.Transform(clipMinimum), axisPosition); | ||
| pt1 = new ScreenPoint(axis.Transform(clipMaximum), labelEndPosition); | ||
| } | ||
| else | ||
| { | ||
| pt0 = new ScreenPoint(axisPosition, axis.Transform(clipMinimum)); | ||
| pt1 = new ScreenPoint(labelEndPosition, axis.Transform(clipMaximum)); | ||
| } | ||
|
|
||
| axis.AxisLineArea = new OxyRect(pt0, pt1); | ||
| axis.AxisArea = new OxyRect(pt0, pt1); | ||
|
|
||
| if (drawAxisLine) | ||
| { | ||
| // Draw the axis line (across the tick marks) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace OxyPlot | ||
| { | ||
| /// <summary> | ||
| /// Describes an empty shape | ||
| /// </summary> | ||
| public struct EmptyShape : IOxyRegion | ||
| { | ||
| /// <inheritdoc/> | ||
| public bool Contains(double x, double y) { return false; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
|
|
||
| namespace OxyPlot | ||
| { | ||
| /// <summary> | ||
| /// Describes the Interface for a shape. | ||
| /// </summary> | ||
| public interface IOxyRegion | ||
| { | ||
| /// <summary> | ||
| /// Determines whether the specified point is inside the shape. | ||
| /// </summary> | ||
| /// <param name="x">The x coordinate.</param> | ||
| /// <param name="y">The y coordinate.</param> | ||
| /// <returns><c>true</c> if the shape contains the specified point; otherwise, <c>false</c>.</returns> | ||
| bool Contains(double x, double y); | ||
|
|
||
|
VisualMelon marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.