Skip to content
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

add plot-inset and plot-legend-padding parameters #124

Merged
merged 5 commits into from
Oct 6, 2023

Conversation

alex-hhh
Copy link
Sponsor Collaborator

@alex-hhh alex-hhh commented Jul 4, 2023

This PR introduces two new plot parameters, plot-inset and plot-legend-padding, which control the amount of space left unused around the plot edge and plot legend. The motivation for this is using wider lines for the plot elements, these wider lines have an "end cap" which extends past the last pixel coordinate for the line, but, since the plot package attempts to maximize the plot area, it attempts to draw things like the axis ticks al the way to the edge.

Here is an example of the problem. When using very thick lines, the top and right edge of the plot appears to be cut off, and the sample lines in the legend extend over the legend border -- the effect is present for thinner lines as well, but it is less noticeable, this example uses an extremely thick line to make the issue more apparent.

(parameterize ([plot-line-width 20]
               [line-width 20])
  (plot
   (list
    (function sin -5 5 #:color 0 #:label "sin(x)")
    (function cos -5 5 #:color 1 #:label "cos(x)"))))

pr124-no-padding

The plot-inset and plot-legend-padding parameters allow the user to control the "empty" space, allowing for the line end caps to be drawn on the plot:

(parameterize ([plot-line-width 20]
               [line-width 20]
               [plot-inset 11]
               [plot-legend-padding 11])
  (plot
   (list
    (function sin -5 5 #:color 0 #:label "sin(x)")
    (function cos -5 5 #:color 1 #:label "cos(x)"))))

pr124-with-padding

NOTE: I considered updating the plot layout calculations to automatically add space for the line end caps, however this would be a backwards incompatible change, as it would change plot layouts in existing plot programs that people already have.

@alex-hhh alex-hhh marked this pull request as draft July 4, 2023 12:56
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

@alex-hhh alex-hhh marked this pull request as ready for review October 2, 2023 22:51
@racket-discourse-github-bot

This pull request has been mentioned on Racket Discourse. There might be relevant details there:

https://racket.discourse.group/t/adding-inset-and-margings-to-plots-new-feature-in-the-plot-package/2360/1

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

@alex-hhh alex-hhh merged commit 2417c22 into racket:master Oct 6, 2023
6 checks passed
@alex-hhh alex-hhh deleted the ah/inset-and-padding branch October 6, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants