Skip to content

Allow controlling line ending caps for plots (#6) #123

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

Merged
merged 2 commits into from
Jul 4, 2023

Conversation

alex-hhh
Copy link
Collaborator

New plot-cap and plot-line-cap control the line endings for lines in the plot. Previously all line endings were 'round:

6-round

Now they can be chosen by the user (one for the plot decorations, such as axes and ticks, another for the lines on the plot):

#lang racket
(require plot)
(plot-width 800)
(plot-height 600)

(parameterize
    ([plot-line-width 15]
     [line-width 15]
     [plot-pen-color-map 'set1]
     [plot-line-cap 'projecting]
     [line-cap 'butt])
  (plot
   (list
    (function sin -5 5 #:color 0 #:label "sin(x)")
    (function cos -5 5 #:color 1 #:label "cos(x)"))))

6

alex-hhh added 2 commits June 24, 2023 06:58
... they control the line endings for plotted elements (`line-cap`) and the
plot decorations, such as axis ticks (`plot-line-cap`).

Previously all line endings were round, creating a "crayon" style effect,
visible for lines whose width is greater than 1.

Also fixed a bug with `hrule`, `vrule` renderers, which attempted to use
`'butt` style: since pens were cached, if `vrule` created a pen, all
subsequent uses of that pen (same color and width) would use `'butt` line
endings, OTOH, if `vrule` reused a pen, because a pen if the same color and
width was previously used, the `vrule` line ending would be `'round`
@alex-hhh
Copy link
Collaborator Author

This also fixes a small bug with vrule and hrule renderers, which attempted to override the line endins for their lines to 'butt insead of 'round: since plot pens are kept in a hash table, which is not indexed by line cap, if a pen with the same width and color was created before a vrule renderer, the vrule would have round endings, if vrule created the pen, other renderers which used the same width and color would have 'butt line endings. This is now fixed and vrule/hrule renderers use the value of line-cap

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 2 files in this pull request and found no issues.

@alex-hhh alex-hhh linked an issue Jul 4, 2023 that may be closed by this pull request
@alex-hhh
Copy link
Collaborator Author

alex-hhh commented Jul 4, 2023

A noticeable effect when using very thick lines is that the line edges are clipped for both the plot area and the legend. This is visible in both screenshots above. However, this is a different problem not linked to these changes and a fix for that will be done as a separate PR.

@alex-hhh alex-hhh merged commit b0da526 into racket:master Jul 4, 2023
@alex-hhh alex-hhh deleted the ah/pr6 branch July 4, 2023 13:19
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.

Square pen cap for decorations
1 participant