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

Error on unknown plot attributes #2966

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e034db2
error on unknown plot attributes
jkrumbiegel May 19, 2023
8a28123
add `label`
jkrumbiegel May 19, 2023
3f6e4fa
delete `xmin` and `xmax` in hvlines
jkrumbiegel May 19, 2023
dc26934
disallow figure explicitly to fix tests
jkrumbiegel May 19, 2023
74f6332
add `fxaa`
jkrumbiegel May 19, 2023
04073e2
add lowclip, highclip, nan_color to Text defaults
jkrumbiegel May 19, 2023
f0a3dd2
delete more unused attributes from contour
jkrumbiegel May 19, 2023
b5631da
pop `transformation` from attributes
jkrumbiegel May 19, 2023
94f7044
rotation -> rotations
jkrumbiegel May 19, 2023
61107b6
add `rasterize`
jkrumbiegel May 19, 2023
badd777
remove old `alpha` keyword
jkrumbiegel May 19, 2023
0da784e
add model to allowlist
jkrumbiegel May 19, 2023
67f0503
add direction and remove non barplot attrs for hist
jkrumbiegel May 19, 2023
2ad1835
add default title xlabel ylabel to raincloud
jkrumbiegel May 19, 2023
87ff15c
add `enable_depth` to `volume`
jkrumbiegel May 19, 2023
16af75e
remove incorrect huge plot using nonexistent `dist_between_categories`
jkrumbiegel May 19, 2023
7626e59
add `absorption` to `volume`
jkrumbiegel May 19, 2023
de46dd4
add barplot keys to hist
jkrumbiegel May 19, 2023
c62bd9d
fix waterfall color and bar attrs
jkrumbiegel May 19, 2023
78583a5
fix hvspan keys
jkrumbiegel May 19, 2023
e023aac
add `matcap` to `Mesh`
jkrumbiegel May 19, 2023
59680f4
correct arg order in ablines theme
jkrumbiegel May 19, 2023
7de4d4b
correct `StepHist` attrs
jkrumbiegel May 19, 2023
79bff1a
`ScatterLines` `space`
jkrumbiegel May 19, 2023
f87e68e
Merge branch 'master' into jk/error-on-unknown-attributes
SimonDanisch Jul 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion MakieCore/src/basic_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ Available algorithms are:
space = :data,
diffuse=0.4,
specular=0.2,
shininess=32.0f0
shininess=32.0f0,
enable_depth=true,
absorption=1.0,
)
end

Expand Down Expand Up @@ -542,6 +544,9 @@ Plots one or multiple texts passed via the `text` keyword.
color = theme(scene, :textcolor),
colormap = theme(scene, :colormap),
colorrange = automatic,
lowclip = automatic,
highclip = automatic,
nan_color = :transparent,
font = theme(scene, :font),
fonts = theme(scene, :fonts),
strokecolor = (:black, 0.0),
Expand Down
2 changes: 1 addition & 1 deletion ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ end

@reference_test "Arrows on hemisphere" begin
s = Sphere(Point3f(0), 0.9f0)
fig, ax, meshplot = mesh(s, transparency=true, alpha=0.05)
fig, ax, meshplot = mesh(s)
pos = decompose(Point3f, s)
dirs = decompose_normals(s)
arrows!(ax, pos, dirs, arrowcolor=:red, arrowsize=0.1, linecolor=:red)
Expand Down
2 changes: 1 addition & 1 deletion ReferenceTests/src/tests/examples3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
rot = qrotation(Vec3f(1, 0, 0), 0.5pi) * qrotation(Vec3f(0, 1, 0), 0.7pi)
meshscatter(
1:3, 1:3, fill(0, 3, 3),
marker=catmesh, color=img, markersize=1, rotation=rot,
marker=catmesh, color=img, markersize=1, rotations=rot,
axis=(type=LScene, show_axis=false)
)
end
Expand Down
65 changes: 0 additions & 65 deletions docs/examples/plotting_functions/rainclouds.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,68 +135,3 @@ rainclouds(category_labels, data_array;
color = colors[indexin(category_labels, unique(category_labels))])
```
\end{examplefigure}

4 of these, between 3 distributions
Left and Right example
With and Without Box Plot

\begin{examplefigure}{}
```julia
fig = Figure(resolution = (800*2, 600*5))
colors = [Makie.wong_colors(); Makie.wong_colors()]

category_labels, data_array = mockup_categories_and_data_array(3)
rainclouds!(Axis(fig[1, 1]), category_labels, data_array;
title = "Left Side, with Box Plot",
side = :left,
plot_boxplots = true,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[2, 1]), category_labels, data_array;
title = "Left Side, without Box Plot",
side = :left,
plot_boxplots = false,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[1, 2]), category_labels, data_array;
title = "Right Side, with Box Plot",
side = :right,
plot_boxplots = true,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[2, 2]), category_labels, data_array;
title = "Right Side, without Box Plot",
side = :right,
plot_boxplots = false,
color = colors[indexin(category_labels, unique(category_labels))])

# Plots wiht more categories
# dist_between_categories (0.6, 1.0)
# with and without clouds

category_labels, data_array = mockup_categories_and_data_array(12)
rainclouds!(Axis(fig[3, 1:2]), category_labels, data_array;
title = "More categories. Default spacing.",
plot_boxplots = true,
dist_between_categories = 1.0,
color = colors[indexin(category_labels, unique(category_labels))])

rainclouds!(Axis(fig[4, 1:2]), category_labels, data_array;
title = "More categories. Adjust space. (smaller cloud widths and smaller category distances)",
plot_boxplots = true,
cloud_width = 0.3,
dist_between_categories = 0.5,
color = colors[indexin(category_labels, unique(category_labels))])


rainclouds!(Axis(fig[5, 1:2]), category_labels, data_array;
title = "More categories. Adjust space. No clouds.",
plot_boxplots = true,
clouds = nothing,
dist_between_categories = 0.5,
color = colors[indexin(category_labels, unique(category_labels))])

supertitle = Label(fig[0, :], "Cloud Plot Testing (Scatter, Violin, Boxplot)", fontsize=30)
fig
```
\end{examplefigure}
3 changes: 3 additions & 0 deletions src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
pop!(attr, :labelsize)
pop!(attr, :labelcolor)
pop!(attr, :labelformatter)
pop!(attr, :linestyle)
pop!(attr, :linewidth)
pop!(attr, :alpha)
volume!(plot, attr, x, y, z, volume)
end

Expand Down
2 changes: 1 addition & 1 deletion src/basic_recipes/hvlines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Makie.plot!(p::Union{HLines, VLines})
notify(p[1])

line_attributes = copy(p.attributes)
delete!.(line_attributes, (:ymin, :ymax, :yautolimits))
delete!.(line_attributes, (:xmin, :xmax, :ymin, :ymax, :yautolimits))
linesegments!(p, line_attributes, points)
p
end
3 changes: 3 additions & 0 deletions src/basic_recipes/raincloud.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ paired with the scatter plot so the default is to not show them)

color = theme(scene, :patchcolor),
cycle = [:color => :patchcolor],
title = "",
xlabel = "",
ylabel = "",
)
end

Expand Down
2 changes: 2 additions & 0 deletions src/figureplotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ end
function plot(P::PlotFunc, gp::GridPosition, args...; axis = NamedTuple(), kwargs...)

_validate_nt_like_keyword(axis, "axis")
_disallow_keyword(:figure, kwargs)

f = get_top_parent(gp)

Expand Down Expand Up @@ -121,6 +122,7 @@ end
function plot(P::PlotFunc, gsp::GridSubposition, args...; axis = NamedTuple(), kwargs...)

_validate_nt_like_keyword(axis, "axis")
_disallow_keyword(:figure, kwargs)

layout = GridLayoutBase.get_layout_at!(gsp.parent, createmissing = true)
c = contents(gsp, exact = true)
Expand Down
7 changes: 5 additions & 2 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ function (PlotType::Type{<: AbstractPlot{Typ}})(scene::SceneLike, attributes::At
# PlotType

FinalType = Combined{Typ, ArgTyp}

trans = pop!(attributes, :transformation, automatic)

plot_attributes = merged_get!(
()-> default_theme(scene, FinalType),
plotsym(FinalType), scene, attributes
plotsym(FinalType), scene, attributes;
allowlist = Set([:text, :xautolimits, :yautolimits, :zautolimits, :interpolate_in_fragment_shader, :label, :fxaa, :rasterize, :model])
Copy link
Member

Choose a reason for hiding this comment

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

inspectable, material, texture, transformation, are also things which should be added, plus all the GLMakie lighting stuff (specular, diffuse, etc)

It would also be nice to have a signature which does not perform this check, for easy programmatic passing of attributes inherited from the parent plot!

Copy link
Member Author

Choose a reason for hiding this comment

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

transformation is already removed elsewhere prior to this check

Wouldn't it be better to group all backend related keywords under one umbrella rather than just letting them potentially collide with the rest?

I think I would like it better if an RPRMakie plot had meshscatter(data; RPRMakie = (; material = ...)

Copy link
Member Author

Choose a reason for hiding this comment

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

same for GLMakie

Copy link
Member Author

Choose a reason for hiding this comment

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

and rasterize in CairoMakie

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want both name checking and the ability to add arbitrary attributes to a plot we need to separate them somehow. I was thinking we could have one whitelisted attribute Dict of core attributes, which may become fields of specific plot object (struct Scatter ... end etc) if we want that, and one Dict with everything else.

Having RPRMakie = (; ...) etc is similar to that I guess. Though I would say attributes that influence other objects (inspectable, label, ...) and overwrites (model, view, ...) should also move out of the directly defined attributes. I guess the latter could also be part of the backend groups. The former is kind of the "random stuff that you want to attach to a plot" group, which I think is useful to have in a dynamic way.

Copy link
Member Author

@jkrumbiegel jkrumbiegel May 19, 2023

Choose a reason for hiding this comment

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

random stuff that you want to attach to a plot

You could still do that by doing plotobject.attributes[:something] = xyz no? For me it's currently most important to make our user interface more robust against user error

Copy link
Member Author

Choose a reason for hiding this comment

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

we could also add a misc allowed key or something which should only ever be set to an Attributes instance with further keys. Then we could disallow such a key for any other recipe so we know it will never conflict, and people can use it to carry arbitrary stuff forward. I want to avoid a situation where people make recipes and we break them by introducing some new add-on keyword arg.

)

# Transformation is a field of the plot type, but can be given as an attribute
trans = get(plot_attributes, :transformation, automatic)
transval = to_value(trans)
transformation = if transval === automatic
Transformation(scene)
Expand Down
8 changes: 7 additions & 1 deletion src/stats/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ $(ATTRIBUTES)
label_offset = 5,
label_font = theme(scene, :font),
label_size = 20,
label_formatter = bar_label_formatter
label_formatter = bar_label_formatter,
direction = :x,
)
end

Expand Down Expand Up @@ -180,6 +181,11 @@ function Makie.plot!(plot::Hist)
x === :values ? :y : x
end
# plot the values, not the observables, to be in control of updating

for key in [:bins, :normalization, :over_background_color, :over_bar_color, :scale_to, :weights]
jkrumbiegel marked this conversation as resolved.
Show resolved Hide resolved
delete!(plot.attributes, key)
end

bp = barplot!(plot, points[]; width = widths[], gap = 0, plot.attributes..., fillto=plot.fillto, offset=plot.offset, bar_labels=bar_labels, color=color)

# update the barplot points without triggering, then trigger with `width`
Expand Down
23 changes: 22 additions & 1 deletion src/utilities/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,34 @@ function merged_get!(defaults::Function, key, scene, input::Vector{Any})
return merged_get!(defaults, key, scene, Attributes(input))
end

function merged_get!(defaults::Function, key, scene::SceneLike, input::Attributes)
function merged_get!(defaults::Function, key, scene::SceneLike, input::Attributes; allowlist::Set{Symbol} = Set{Symbol}())
d = defaults()
if haskey(theme(scene), key)
# we need to merge theme(scene) with the defaults, because it might be an incomplete theme
# TODO have a mark that says "theme uncomplete" and only then get the defaults
d = merge!(to_value(theme(scene, key)), d)
end
sd = setdiff(
keys(input),
keys(d),
allowlist
)
sd = setdiff(sd, )
if !isempty(sd)
error("""
Found attributes not in the defaults for $(key) or the general allowlist:

$(join(sort(collect(sd)), ", ", " and "))

The default attributes for this call were:

$(isempty(keys(d)) ? "No entries available." : join(sort(collect(keys(d))), ", ", " and "))

The additional allowlist for this call was:

$(isempty(allowlist) ? "No entries available." : join(sort(collect(allowlist)), ", ", " and "))
""")
end
return merge!(input, d)
end

Expand Down