Skip to content

Commit de1a1a1

Browse files
authored
handle any number of positional arguments (#21)
1 parent 15072ce commit de1a1a1

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,5 @@ fig = lplot(Scatter, cs_df, :xxx, :yyy; color = :s_c, marker = :g_m, markersize
5656

5757
* combine different plots (e.g. `visual(Scatter) + linear`)
5858
* use other inputs than tables (the "slicing context")
59-
* handle plot types where the number of positional arguments is not 2 (e.g. `Band`)
6059

6160
Open an issue if you find more.

src/compose.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function tplot(P, df, x_var, y_var; attr_var_pairs...)
1+
function tplot(P, df, args...; attr_var_pairs...)
22
fig = Figure()
33

44
# 1. Grouping
@@ -20,7 +20,7 @@ function tplot(P, df, x_var, y_var; attr_var_pairs...)
2020
# 2a. Plot
2121

2222
# 2b. Layout
23-
grouped_plot_layout(P, fig, df, x_var, y_var, layout_vars, group_dict, style_dict, kws, group_pairs, style_pairs)
23+
grouped_plot_layout(P, fig, df, args, layout_vars, group_dict, style_dict, kws, group_pairs, style_pairs)
2424

2525
# 3. Legend
2626
leg, cb = nothing, nothing

src/layout.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function grouped_plot_layout(P, fig, df, x_var, y_var, layout_vars, group_dict, style_dict, kws, groups, styles)
1+
function grouped_plot_layout(P, fig, df, args, layout_vars, group_dict, style_dict, kws, groups, styles)
22
linkxaxes = true
33
linkyaxes = true
44
linkzcolor = true
@@ -50,7 +50,7 @@ function grouped_plot_layout(P, fig, df, x_var, y_var, layout_vars, group_dict,
5050
end
5151

5252
# Do the plot
53-
plt = grouped_plot(P, axs[i, j], groupdf, group_dict, x_var, y_var, kws, groups, styles)
53+
plt = grouped_plot(P, axs[i, j], groupdf, group_dict, args, kws, groups, styles)
5454

5555
let
5656
padding = (3f0, 3f0, 3f0, 3f0)
@@ -72,8 +72,8 @@ function grouped_plot_layout(P, fig, df, x_var, y_var, layout_vars, group_dict,
7272
end
7373

7474
# spanned labels
75-
span_label(:x, var_lab(x_var), axs, fig[1,1])
76-
span_label(:y, var_lab(y_var), axs, fig[1,1])
75+
span_label(:x, var_lab(args[1]), axs, fig[1,1])
76+
span_label(:y, var_lab(args[2]), axs, fig[1,1])
7777

7878
# Link axes
7979
linkyaxes && linkyaxes!(axs...)

src/plot.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
struct Incremental end
22
struct AllAtOnce end
33

4+
mode(::Type) = Incremental()
45
mode(::Type{Scatter}) = AllAtOnce()
56
mode(::Type{BarPlot}) = AllAtOnce()
6-
mode(::Type{Lines}) = Incremental()
77

88
grouped_plot(P, args...; kwargs...) = _grouped_plot(mode(P), P, args...; kwargs...)
99

10-
function _grouped_plot(::AllAtOnce, P, ax, df, group_dict, x_var, y_var, kws, group_pairs, style_pairs)
11-
x = get(df, x_var)
12-
y = get(df, y_var)
10+
function _grouped_plot(::AllAtOnce, P, ax, df, group_dict, args, kws, group_pairs, style_pairs)
11+
xyz = [get(df, arg) for arg in args]
1312

1413
pairs = lookup_symbols(df, group_pairs, style_pairs, group_dict)
1514

16-
plt = plot!(P, ax, x, y; kws..., pairs...)
15+
plt = plot!(P, ax, xyz...; kws..., pairs...)
1716

18-
categorical_ticks!(ax, x, y)
17+
categorical_ticks!(ax, xyz[1], xyz[2])
1918

2019
(; plt)
2120
end
2221

23-
function _grouped_plot(::Incremental, P, ax, gdf, group_dict, x_var, y_var, kws, group_pairs, style_pairs)
22+
function _grouped_plot(::Incremental, P, ax, gdf, group_dict, args, kws, group_pairs, style_pairs)
23+
2424

2525
if length(group_pairs) > 0
2626
grp = Symbol[Symbol(p[2]) for p in pairs(group_pairs)]
@@ -33,14 +33,13 @@ function _grouped_plot(::Incremental, P, ax, gdf, group_dict, x_var, y_var, kws,
3333
end
3434

3535
out = combine(groupby(gdf, grp)) do df
36-
x = get(df, x_var)
37-
y = get(df, y_var)
36+
xyz = [get(df, arg) for arg in args]
3837

3938
pairs = lookup_symbols(df, group_pairs, style_pairs, group_dict)
4039

41-
plt = plot!(P, ax, x, y; kws..., pairs...)
40+
plt = plot!(P, ax, xyz...; kws..., pairs...)
4241

43-
categorical_ticks!(ax, x, y)
42+
categorical_ticks!(ax, xyz[1], xyz[2])
4443

4544
(; plt)
4645
end

0 commit comments

Comments
 (0)