diff --git a/src/guide.jl b/src/guide.jl index 5e13b7c4c..9ab06f29a 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -206,7 +206,7 @@ function render_discrete_color_key(colors::Vector{C}, colrows = Array{Int}(undef, numcols) m = n for i in 1:numcols - colrows[i] = min(m, ceil(Integer, (n / numcols))) + colrows[i] = ceil(Int, m/(1+numcols-i)) m -= colrows[i] end diff --git a/src/guide/keys.jl b/src/guide/keys.jl index ac3943033..90c85c57e 100644 --- a/src/guide/keys.jl +++ b/src/guide/keys.jl @@ -91,7 +91,7 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w colrows = Array{Int}(undef, numcols) m = n for i in 1:numcols - colrows[i] = min(m, ceil(Integer, (n / numcols))) + colrows[i] = ceil(Int, m/(1+numcols-i)) m -= colrows[i] end diff --git a/test/testscripts/key_columns.jl b/test/testscripts/key_columns.jl new file mode 100644 index 000000000..5ceaf85c3 --- /dev/null +++ b/test/testscripts/key_columns.jl @@ -0,0 +1,15 @@ + +using Gadfly + +set_default_plot_size(14cm, 8cm) + +# Issue #1344 + +datas = Gadfly.Data(color= ["D", "A", "C", "D", "A", "C", "D", "D", "A", "B"], + shape=["E", "F", "F", "E", "G", "E", "E", "G", "H"]) +scales = [Scale.color_discrete(levels=["A","B","C","D"]), Scale.shape_discrete(levels=["E","F","G","H"]) ] +aes = Scale.apply_scales(scales, datas) +theme1 = Theme(key_max_columns=4) +guides = [render(g, theme1, aes[1])[1].ctxs for g in (Guide.colorkey(), Guide.shapekey())] + +gridstack([guides[i][j] for i in 1:2, j in 1:4])