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

Size revamp 2: Guide.sizekey #1379

Merged
merged 2 commits into from
Jan 18, 2020
Merged

Conversation

Mattriks
Copy link
Member

@Mattriks Mattriks commented Jan 5, 2020

  • I've updated the documentation to reflect these changes
  • I've added an entry to NEWS.md
  • I've added and/or updated the unit tests
  • I've run the regression tests
  • I've built the docs and confirmed these changes don't cause new errors

This PR

This PR makes changes to the layout of shapekey and sizekey, via render_discrete_key. This doesn't affect colorkey, which currently uses render_discrete_color_key. render_discrete_color_key contains bugs (#859), that become worse with larger swatch sizes. The long-term plan is that all discrete aesthetics (including color) will use render_discrete_key.

Examples

labels = rand(randstring.(fill(8, 5)), 100) 
datas, aes = Gadfly.Data(size=labels), Gadfly.Aesthetics()
sc1 = Scale.size_discrete2(n->range(4pt, 8pt, length=n))
Scale.apply_scale(sc1, [aes], datas)
 gsk = Guide.sizekey(title="Size key")
theme = Theme(key_swatch_shape=Shape.hexagon, key_label_font_size=10pt, 
    discrete_highlight_color=identity, alphas=[0.1], key_max_columns=5)
ctxs =  Guide.render(gsk, theme, aes)[1].ctxs
vstack(hstack(ctxs[1:2]...), ctxs[5]) 

sizekey

Example from gallery/guides.md (in this PR):

plot(Titanic, Scale.x_log10,  Scale.y_log10,
    x=:Freq, y=:prcnt, color=:Age, shape=:Sex,  size=:Class,
    Scale.size_discrete2(sizemap), Guide.sizekey(title="Passenger\n Class"),
    Guide.colorkey(pos=[0.1, -0.3h]), Guide.shapekey(pos=[0.5, -0.31h]),
    Guide.ylabel("% of Passenger Class"),
 Theme(discrete_highlight_color=identity, alphas=[0.1], key_swatch_color="grey",
    key_swatch_shape=Shape.circle, point_size=3pt) )

Titanic

@codecov-io
Copy link

codecov-io commented Jan 5, 2020

Codecov Report

Merging #1379 into master will decrease coverage by 0.25%.
The diff coverage is 77.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1379      +/-   ##
==========================================
- Coverage   90.57%   90.31%   -0.26%     
==========================================
  Files          39       39              
  Lines        3988     4028      +40     
==========================================
+ Hits         3612     3638      +26     
- Misses        376      390      +14
Impacted Files Coverage Δ
src/theme.jl 69.49% <ø> (ø) ⬆️
src/Gadfly.jl 78.14% <100%> (ø) ⬆️
src/guide/keys.jl 85.34% <76.78%> (-9.4%) ⬇️
src/scale/scales.jl 88.88% <0%> (-3.71%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf50828...749c3e2. Read the comment docs.

@Mattriks
Copy link
Member Author

Mattriks commented Jan 6, 2020

To do:

  • change the key swatch stroke width (to theme.highlight_width)
  • Theme(key_swatch_size= ) to override point_size
  • Update discrete scale table in the Tutorial

@Mattriks
Copy link
Member Author

Mattriks commented Jan 7, 2020

I completed my To do list, and updated the figures in my OP. I also refactored some unit tests so that the key item order is always consistent (which makes it easier to regression test the keys). In the regression testing, small changes occur in any test with a shapekey (8 in total). The small changes occur because of the updated layout, and because the key swatch size (for render_discrete_key) now defaults to the default point_size.

I would also like to suggest raising the default point_size from 0.95mm to 3pt (~1mm), you can see 3pt swatch size in the Titanic example above (compare the color and shape keys inside the plot).

Copy link
Member

@bjarthur bjarthur left a comment

Choose a reason for hiding this comment

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

looks great! thanks for all your work on keys recently. looking forward to the third installment. in addition to the two comments in the code, it'd be nice if you could give the second commit a more informative message.

docs/src/gallery/guides.md Show resolved Hide resolved
src/guide/keys.jl Show resolved Hide resolved
@Mattriks
Copy link
Member Author

The only q remaining for me in this PR is: can the default point size be changed from 0.95mm to 3pt (~1mm).? The reason is that with this PR the key swatch size defaults to Theme(point_size), and 3pt is closer to the current key swatch size (0.95mm is slightly smaller than the current key swatch size).

error("$(theme.guide_title_position) is not a valid guide title position")
end

title_padding = 1.5mm
Copy link
Member

Choose a reason for hiding this comment

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

the only difference i can see between render_key_title and render_key_title2 is the use of 4mm in the former here. to eliminate such code duplication, would it be possible to pass in title_padding as an argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer to keep the two functions separate for the moment, as I'm working towards separating the keys for discrete and continuous aesthetics. After I complete that I'm happy to tidy up whatever's remaining.

@Mattriks
Copy link
Member Author

Please answer my question above about the default point size.

@bjarthur bjarthur merged commit fb97e75 into GiovineItalia:master Jan 18, 2020
@bjarthur bjarthur mentioned this pull request Jan 18, 2020
@Mattriks Mattriks mentioned this pull request Jan 19, 2020
5 tasks
@Mattriks Mattriks mentioned this pull request Jan 5, 2022
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.

3 participants