From 0db8afa8612d9a67772d3a29f0b2cb7d73b26dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 21 Jul 2018 18:33:48 +1000 Subject: [PATCH 01/16] Initial --- src/geom/hvband.jl | 76 ++++++++++++++++++++++++++++++++++++++ src/geometry.jl | 1 + test/testscripts/hvband.jl | 10 +++++ 3 files changed, 87 insertions(+) create mode 100644 src/geom/hvband.jl create mode 100644 test/testscripts/hvband.jl diff --git a/src/geom/hvband.jl b/src/geom/hvband.jl new file mode 100644 index 000000000..92733d874 --- /dev/null +++ b/src/geom/hvband.jl @@ -0,0 +1,76 @@ +using Compose: x_measure, y_measure + +struct HBandGeometry <: Gadfly.GeometryElement + color::Union{Vector, Color, (Void)} + tag::Symbol + + HBandGeometry(color, tag) = new(color === nothing ? nothing : Gadfly.parse_colorant(color), tag) +end + +HBandGeometry(; color = nothing, tag = empty_tag) = HBandGeometry(color, tag) + +const hband = HBandGeometry + +element_aesthetics(::HBandGeometry) = [:ymin, :ymax] + +# Generate a form for the hband geometry +function render(geom::HBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) + + Gadfly.assert_aesthetics_defined("Geom.hband", aes, :ymin, :ymax) + Gadfly.assert_aesthetics_equal_length("Geom.hband", aes, :ymin, :ymax) + + color = geom.color === nothing ? theme.default_color : geom.color + + x0 = fill(0w, length(aes.ymin)) + x1 = fill(1w, length(aes.ymin)) + + ywidths = [(y1 - y0) * cy - theme.bar_spacing + for (y0, y1) in zip(aes.ymin, aes.ymax)] + + root = compose(context(), svgclass("geometry")) + + compose!(root, (context(), + rectangle(x0, aes.ymin, x1, ywidths, geom.tag), + fill(color), + stroke(nothing))) + + return root +end + + +struct VBandGeometry <: Gadfly.GeometryElement + color::Union{Vector, Color, (Void)} + tag::Symbol + + VBandGeometry(color, tag) = new(color === nothing ? nothing : Gadfly.parse_colorant(color), tag) +end + +VBandGeometry(; color = nothing, tag = empty_tag) = VBandGeometry(color, tag) + +const vband = VBandGeometry + +element_aesthetics(::VBandGeometry) = [:xmin, :xmax] + +# Generate a form for the vband geometry +function render(geom::VBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) + + Gadfly.assert_aesthetics_defined("Geom.vband", aes, :xmin, :xmax) + Gadfly.assert_aesthetics_equal_length("Geom.vband", aes, :xmin, :xmax) + + color = geom.color === nothing ? theme.default_color : geom.color + + y0 = fill(0h, length(aes.xmin)) + y1 = fill(1h, length(aes.xmin)) + + xwidths = [(x1 - x0) * cx - theme.bar_spacing + for (x0, x1) in zip(aes.xmin, aes.xmax)] + + root = compose(context(), svgclass("geometry")) + + compose!(root, (context(), + rectangle(aes.xmin, y0, xwidths, y1, geom.tag), + fill(color), + stroke(nothing))) + + return root +end diff --git a/src/geometry.jl b/src/geometry.jl index a814e6c23..6d9d8c71d 100644 --- a/src/geometry.jl +++ b/src/geometry.jl @@ -56,6 +56,7 @@ include("geom/boxplot.jl") include("geom/errorbar.jl") include("geom/hexbin.jl") include("geom/hvabline.jl") +include("geom/hvband.jl") include("geom/label.jl") include("geom/line.jl") include("geom/point.jl") diff --git a/test/testscripts/hvband.jl b/test/testscripts/hvband.jl new file mode 100644 index 000000000..988e721a5 --- /dev/null +++ b/test/testscripts/hvband.jl @@ -0,0 +1,10 @@ +using Gadfly + +set_default_plot_size(6inch, 3inch) + +layer_data = layer(x=collect(1:10), y=collect(1:10), Geom.point) + +plot_hvbands = hstack( + # plot(layer_data, layer(xintercept=[4], Geom.vline)), + plot(layer_data, layer(xmin=[2], xmax=[4], Geom.vband(color="green")), layer(xmin=[6], xmax=[6.5], Geom.vband)), + plot(layer_data, layer(ymin=[2,6], ymax=[4,6.5], Geom.hband(color="red")))) From c71f54e1b1195fb932d186d523695c064fb287bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 12:51:32 +1000 Subject: [PATCH 02/16] Initial gallery example --- docs/src/gallery/geometries.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/src/gallery/geometries.md b/docs/src/gallery/geometries.md index 98295d8c4..103e67a6e 100644 --- a/docs/src/gallery/geometries.md +++ b/docs/src/gallery/geometries.md @@ -171,6 +171,17 @@ pb = plot(x=s.*(x.^2), y=x, color=string.(s), hstack(pa, pb) ``` +## [`Geom.hband`](@ref), [`Geom.vband`](@ref) + +```@example +using Gadfly, RDatasets +set_default_plot_size(21cm, 8cm) +p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband(color="green"))) +p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(ymin=[2.5, 3.5], ymax=[3.0, 4.0], Geom.hband(color="red"))) +hstack(p1,p2) +``` ## [`Geom.hexbin`](@ref) From 9696c0d9cb53b1d4174b1a5e1be86afcb0d8366a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 13:13:00 +1000 Subject: [PATCH 03/16] Initial docstrings for hband and vband --- src/geom/hvband.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/geom/hvband.jl b/src/geom/hvband.jl index 92733d874..b3f8838f1 100644 --- a/src/geom/hvband.jl +++ b/src/geom/hvband.jl @@ -9,6 +9,15 @@ end HBandGeometry(; color = nothing, tag = empty_tag) = HBandGeometry(color, tag) +""" + Geom.hband[(; color=nothing)] + +Draw horizontal bands across the plot canvas with a vertical span specified by `ymin` and `ymax` aesthetics. + +# Optional Aesthetics +- `color`: + Default is `Theme.default_color`. +""" const hband = HBandGeometry element_aesthetics(::HBandGeometry) = [:ymin, :ymax] @@ -47,6 +56,15 @@ end VBandGeometry(; color = nothing, tag = empty_tag) = VBandGeometry(color, tag) +""" + Geom.vband[(; color=nothing)] + +Draw vertical bands across the plot canvas with a horizontal span specified by `xmin` and `xmax` aesthetics. + +# Optional Aesthetics +- `color`: + Default is `Theme.default_color`. +""" const vband = VBandGeometry element_aesthetics(::VBandGeometry) = [:xmin, :xmax] From 86d116fa970d39ae4a30c8facb710b898de8c232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 12:52:00 +1000 Subject: [PATCH 04/16] Match hvband testscript with gallery example --- test/testscripts/hvband.jl | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/testscripts/hvband.jl b/test/testscripts/hvband.jl index 988e721a5..0d9813a28 100644 --- a/test/testscripts/hvband.jl +++ b/test/testscripts/hvband.jl @@ -1,10 +1,7 @@ -using Gadfly - -set_default_plot_size(6inch, 3inch) - -layer_data = layer(x=collect(1:10), y=collect(1:10), Geom.point) - -plot_hvbands = hstack( - # plot(layer_data, layer(xintercept=[4], Geom.vline)), - plot(layer_data, layer(xmin=[2], xmax=[4], Geom.vband(color="green")), layer(xmin=[6], xmax=[6.5], Geom.vband)), - plot(layer_data, layer(ymin=[2,6], ymax=[4,6.5], Geom.hband(color="red")))) +using Gadfly, RDatasets +set_default_plot_size(21cm, 8cm) +p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband(color="green"))) +p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(ymin=[2.5, 3.6], ymax=[3.0, 4.0], Geom.hband(color="red"))) +hstack(p1,p2) From 8a151b5e5da71857922d85dc2b039300560134d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Tue, 31 Jul 2018 18:17:37 +1000 Subject: [PATCH 05/16] Tidy hvband render functions --- src/geom/hvband.jl | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/geom/hvband.jl b/src/geom/hvband.jl index b3f8838f1..484076f03 100644 --- a/src/geom/hvband.jl +++ b/src/geom/hvband.jl @@ -30,20 +30,21 @@ function render(geom::HBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics color = geom.color === nothing ? theme.default_color : geom.color - x0 = fill(0w, length(aes.ymin)) - x1 = fill(1w, length(aes.ymin)) + n = max(length(aes.xmin)) #Note: already passed check for equal lengths. - ywidths = [(y1 - y0) * cy - theme.bar_spacing - for (y0, y1) in zip(aes.ymin, aes.ymax)] + x0 = fill(0w, n) + x1 = fill(1w, n) - root = compose(context(), svgclass("geometry")) + ywidths = [(y1 - y0) * cy + for (y0, y1) in zip(aes.ymin, aes.ymax)] - compose!(root, (context(), + return compose!( + context(), rectangle(x0, aes.ymin, x1, ywidths, geom.tag), fill(color), - stroke(nothing))) - - return root + stroke(nothing), + svgclass("geometry"), + svgattribute("shape-rendering", "crispEdges")) end @@ -77,18 +78,19 @@ function render(geom::VBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics color = geom.color === nothing ? theme.default_color : geom.color - y0 = fill(0h, length(aes.xmin)) - y1 = fill(1h, length(aes.xmin)) + n = max(length(aes.xmin)) #Note: already passed check for equal lengths. - xwidths = [(x1 - x0) * cx - theme.bar_spacing - for (x0, x1) in zip(aes.xmin, aes.xmax)] + y0 = fill(0h, n) + y1 = fill(1h, n) - root = compose(context(), svgclass("geometry")) + xwidths = [(x1 - x0) * cx + for (x0, x1) in zip(aes.xmin, aes.xmax)] - compose!(root, (context(), + return compose!( + context(), rectangle(aes.xmin, y0, xwidths, y1, geom.tag), fill(color), - stroke(nothing))) - - return root + stroke(nothing), + svgclass("geometry"), + svgattribute("shape-rendering", "crispEdges")) end From 675a586e4aa6298a091ccb7402ee9801a3be0a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 13:19:43 +1000 Subject: [PATCH 06/16] Generic BandGeometry with orientation --- src/geom/hvband.jl | 99 ++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/src/geom/hvband.jl b/src/geom/hvband.jl index 484076f03..7a3dd5186 100644 --- a/src/geom/hvband.jl +++ b/src/geom/hvband.jl @@ -1,13 +1,15 @@ using Compose: x_measure, y_measure -struct HBandGeometry <: Gadfly.GeometryElement +# Band geometry summarizes data as vertical or horizontal bands. +struct BandGeometry <: Gadfly.GeometryElement + orientation::Symbol color::Union{Vector, Color, (Void)} tag::Symbol - - HBandGeometry(color, tag) = new(color === nothing ? nothing : Gadfly.parse_colorant(color), tag) + BandGeometry(orientation, color, tag) = new(orientation, color === nothing ? nothing : Gadfly.parse_colorant(color), tag) end -HBandGeometry(; color = nothing, tag = empty_tag) = HBandGeometry(color, tag) + +HBandGeometry(; color = nothing, tag = empty_tag) = BandGeometry(:horizontal, color, tag) """ Geom.hband[(; color=nothing)] @@ -20,42 +22,8 @@ Draw horizontal bands across the plot canvas with a vertical span specified by ` """ const hband = HBandGeometry -element_aesthetics(::HBandGeometry) = [:ymin, :ymax] - -# Generate a form for the hband geometry -function render(geom::HBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - - Gadfly.assert_aesthetics_defined("Geom.hband", aes, :ymin, :ymax) - Gadfly.assert_aesthetics_equal_length("Geom.hband", aes, :ymin, :ymax) - - color = geom.color === nothing ? theme.default_color : geom.color - - n = max(length(aes.xmin)) #Note: already passed check for equal lengths. - - x0 = fill(0w, n) - x1 = fill(1w, n) - ywidths = [(y1 - y0) * cy - for (y0, y1) in zip(aes.ymin, aes.ymax)] - - return compose!( - context(), - rectangle(x0, aes.ymin, x1, ywidths, geom.tag), - fill(color), - stroke(nothing), - svgclass("geometry"), - svgattribute("shape-rendering", "crispEdges")) -end - - -struct VBandGeometry <: Gadfly.GeometryElement - color::Union{Vector, Color, (Void)} - tag::Symbol - - VBandGeometry(color, tag) = new(color === nothing ? nothing : Gadfly.parse_colorant(color), tag) -end - -VBandGeometry(; color = nothing, tag = empty_tag) = VBandGeometry(color, tag) +VBandGeometry(; color = nothing, tag = empty_tag) = BandGeometry(:vertical, color, tag) """ Geom.vband[(; color=nothing)] @@ -68,29 +36,58 @@ Draw vertical bands across the plot canvas with a horizontal span specified by ` """ const vband = VBandGeometry -element_aesthetics(::VBandGeometry) = [:xmin, :xmax] -# Generate a form for the vband geometry -function render(geom::VBandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) +element_aesthetics(geom::BandGeometry) = geom.orientation == :vertical ? + [:xmin, :xmax, :color] : [:ymin, :ymax, :color] - Gadfly.assert_aesthetics_defined("Geom.vband", aes, :xmin, :xmax) - Gadfly.assert_aesthetics_equal_length("Geom.vband", aes, :xmin, :xmax) + +# Generate a form for the bad geometry +# +# Args: +# geom: band geometry. +# theme: the plot's theme. +# aes: aesthetics. +# +# Returns: +# A compose Form. +# +function render(geom::BandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - color = geom.color === nothing ? theme.default_color : geom.color + if geom.orientation == :horizontal + Gadfly.assert_aesthetics_defined("BandGeometry", aes, :ymin, :ymax) + Gadfly.assert_aesthetics_equal_length("BandGeometry", aes, :ymin, :ymax) - n = max(length(aes.xmin)) #Note: already passed check for equal lengths. + n = max(length(aes.ymin)) #Note: already passed check for equal lengths. - y0 = fill(0h, n) - y1 = fill(1h, n) + aes.xmin = fill(0w, n) + xwidths = fill(1w, n) - xwidths = [(x1 - x0) * cx - for (x0, x1) in zip(aes.xmin, aes.xmax)] + ywidths = [(y1 - y0) * cy + for (y0, y1) in zip(aes.ymin, aes.ymax)] + + elseif geom.orientation == :vertical + Gadfly.assert_aesthetics_defined("BandGeometry", aes, :xmin, :xmax) + Gadfly.assert_aesthetics_equal_length("BandGeometry", aes, :xmin, :xmax) + + n = max(length(aes.xmin)) #Note: already passed check for equal lengths. + + aes.ymin = fill(0h, n) + ywidths = fill(1h, n) + + xwidths = [(x1 - x0) * cx + for (x0, x1) in zip(aes.xmin, aes.xmax)] + else + error("Orientation must be :horizontal or :vertical") + end + + color = geom.color === nothing ? theme.default_color : geom.color return compose!( context(), - rectangle(aes.xmin, y0, xwidths, y1, geom.tag), + rectangle(aes.xmin, aes.ymin, xwidths, ywidths, geom.tag), fill(color), stroke(nothing), svgclass("geometry"), svgattribute("shape-rendering", "crispEdges")) + end From a2648b12b531c8d215c389e30e291668af05c974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 14:28:39 +1000 Subject: [PATCH 07/16] Develop RectangularGeometry --- src/geom/rect.jl | 110 ++++++++++++++++++++++++++++++++++++ src/geom/rectbin.jl | 16 +++--- src/geometry.jl | 1 + test/testscripts/rect.jl | 6 ++ test/testscripts/rectbin.jl | 2 - 5 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 src/geom/rect.jl create mode 100644 test/testscripts/rect.jl diff --git a/src/geom/rect.jl b/src/geom/rect.jl new file mode 100644 index 000000000..f80de7e5c --- /dev/null +++ b/src/geom/rect.jl @@ -0,0 +1,110 @@ +using Compose: x_measure, y_measure + +struct RectangularGeometry <: Gadfly.GeometryElement + default_statistic::Gadfly.StatisticElement + tag::Symbol +end + +function RectangularGeometry( + default_statistic::Gadfly.StatisticElement=Gadfly.Stat.identity(); + tag=empty_tag) + RectangularGeometry(default_statistic, tag) +end + +""" + Geom.rect + +Draw colored rectangles with the corners specified by the +`xmin`, `xmax`, `ymin` and `ymax` aesthetics. Optionally +specify their `color`. +""" +const rect = RectangularGeometry + +default_statistic(geom::RectangularGeometry) = geom.default_statistic + +element_aesthetics(::RectangularGeometry) = + [:xmin, :xmax, :ymin, :ymax, :color] + +# Render rectangle geometry. +# +# Args: +# geom: rect geometry +# theme: the plot's theme +# aes: some aesthetics +# +# Returns +# A compose form. +# +function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) + + default_aes = Gadfly.Aesthetics() + default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color]) + aes = inherit(aes, default_aes) + + Gadfly.assert_aesthetics_defined("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax) + Gadfly.assert_aesthetics_equal_length("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax) + + nx = length(aes.xmin) + ny = length(aes.ymin) + n = nx + + xmin = aes.xmin + xwidths = [(x1 - x0)*cx + for (x0, x1) in zip(aes.xmin, aes.xmax)] + + ymin = aes.ymin + ywidths = [(y1 - y0)*cy + for (y0, y1) in zip(aes.ymin, aes.ymax)] + + if length(aes.color) == n + cs = aes.color + else + cs = Array{RGBA{Float32}}(n) + for i in 1:n + cs[i] = aes.color[((i - 1) % length(aes.color)) + 1] + end + end + + allvisible = true + for c in cs + if c == nothing + allvisible = false + break + end + end + + if !allvisible + visibility = cs .!= nothing + cs = cs[visibility] + xmin = xmin[visibility] + xmax = xmax[visibility] + ymin = ymin[visibility] + ymax = ymax[visibility] + end + + return compose!( + context(), + rectangle(xmin, ymin, xwidths, ywidths, geom.tag), + fill(cs), + stroke(nothing), + svgclass("geometry"), + svgattribute("shape-rendering", "crispEdges")) + + # TODO: determine performance hit of using polygons. + # polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + # for i in 1:n + # x0 = x_measure(aes.xmin[i]) + # x1 = x_measure(aes.xmax[i]) + # y0 = y_measure(aes.ymin[i]) + # y1 = y_measure(aes.ymax[i]) + # polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)] + # end + # + # return compose!( + # context(), + # Compose.polygon(polys), + # fill(color), + # stroke(nothing), + # svgclass("geometry"), + # svgattribute("shape-rendering", "crispEdges")) +end diff --git a/src/geom/rectbin.jl b/src/geom/rectbin.jl index 94869a5f7..2b8a5f5d1 100644 --- a/src/geom/rectbin.jl +++ b/src/geom/rectbin.jl @@ -18,14 +18,14 @@ specify their `color`. """ const rectbin = RectangularBinGeometry -""" - Geom.rect - -Draw colored rectangles with the corners specified by the -`xmin`, `xmax`, `ymin` and `ymax` aesthetics. Optionally -specify their `color`. -""" -rect() = RectangularBinGeometry(Gadfly.Stat.Identity()) +# """ +# Geom.rect +# +# Draw colored rectangles with the corners specified by the +# `xmin`, `xmax`, `ymin` and `ymax` aesthetics. Optionally +# specify their `color`. +# """ +# rect() = RectangularBinGeometry(Gadfly.Stat.Identity()) """ Geom.histogram2d[(; xbincount=nothing, xminbincount=3, xmaxbincount=150, diff --git a/src/geometry.jl b/src/geometry.jl index 6d9d8c71d..fe15dff37 100644 --- a/src/geometry.jl +++ b/src/geometry.jl @@ -60,6 +60,7 @@ include("geom/hvband.jl") include("geom/label.jl") include("geom/line.jl") include("geom/point.jl") +include("geom/rect.jl") include("geom/rectbin.jl") include("geom/subplot.jl") include("geom/ribbon.jl") diff --git a/test/testscripts/rect.jl b/test/testscripts/rect.jl new file mode 100644 index 000000000..0efff4949 --- /dev/null +++ b/test/testscripts/rect.jl @@ -0,0 +1,6 @@ +using DataFrames, Gadfly + +set_default_plot_size(6inch, 3inch) + +D = DataFrame(x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5]) +pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect) diff --git a/test/testscripts/rectbin.jl b/test/testscripts/rectbin.jl index 2bce23b2c..a39c3d49b 100644 --- a/test/testscripts/rectbin.jl +++ b/test/testscripts/rectbin.jl @@ -7,5 +7,3 @@ set_default_plot_size(6inch, 3inch) D = DataFrame(x=[0.5,1], y=[0.5,1], x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5]) pa = plot(D, x=:x, y=:y, Geom.rectbin) -pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect) -hstack(pa,pb) From e418e4e97d26f519ddbf7fdd0f18459a51aa2f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 18:11:18 +1000 Subject: [PATCH 08/16] Add BandStatistic --- src/statistics.jl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/statistics.jl b/src/statistics.jl index 2be810105..637ec8e8a 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -2037,4 +2037,49 @@ function Gadfly.Stat.apply_statistic(stat::EllipseStatistic, aes.y = ellipse_y end + +struct BandStatistic <: Gadfly.StatisticElement + orientation::Symbol # :horizontal or :vertical like BarStatistic or HairStatistic +end + +function BandStatistic(;orientation=:vertical) + return BandStatistic(orientation) +end + +input_aesthetics(stat::BandStatistic) = [:xmin, :xmax, :ymin, :ymax] +output_aesthetics(stat::BandStatistic) = [:xmin, :xmax, :ymin, :ymax] +default_scales(stat::BandStatistic) = [Scale.x_continuous(), Scale.y_continuous()] + +""" + Stat.band[(; orientation=:vertical)] + +Transform points in $(aes2str(input_aesthetics(band()))) into rectangles in +$(aes2str(output_aesthetics(band()))). Used by [`Geom.band`](@ref Gadfly.Geom.band). +""" +const band = BandStatistic + +function apply_statistic(stat::BandStatistic, + scales::Dict{Symbol, Gadfly.ScaleElement}, + coord::Gadfly.CoordinateElement, + aes::Gadfly.Aesthetics) + + if stat.orientation == :horizontal + + n = max(length(aes.ymin)) #Note: already passed check for equal lengths. + + aes.xmin = fill(0w, n) + aes.xmax = fill(1w, n) + + elseif stat.orientation == :vertical + + n = max(length(aes.xmin)) #Note: already passed check for equal lengths. + + aes.ymin = fill(0h, n) + aes.ymax = fill(1h, n) + + else + error("Orientation must be :horizontal or :vertical") + end +end + end # module Stat From 7eb4f9fa9cefcbb361eb23f73bb57d877a068681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 18:12:38 +1000 Subject: [PATCH 09/16] Allow types of Measure to pass through --- src/coord.jl | 5 +++-- src/statistics.jl | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coord.jl b/src/coord.jl index 834cb7e18..c60602f01 100644 --- a/src/coord.jl +++ b/src/coord.jl @@ -4,6 +4,7 @@ using Gadfly using Compat using Compose using DataArrays +using Measures import Gadfly.Maybe export cartesian @@ -158,7 +159,7 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, for var in coord.xvars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + (vals === nothing || eltype(vals) <: Measure) && continue if !isa(vals, AbstractArray) vals = [vals] @@ -174,7 +175,7 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, for var in coord.yvars for aes in aess vals = getfield(aes, var) - vals === nothing && continue + (vals === nothing || eltype(vals) <: Measure) && continue # Outliers is an odd aesthetic that needs special treatment. if var == :outliers diff --git a/src/statistics.jl b/src/statistics.jl index 637ec8e8a..952f33fa0 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -13,6 +13,7 @@ using Hexagons using Loess using CoupledFields # It is registered in METADATA.jl using IndirectArrays +using Measures import Gadfly: Scale, Coord, input_aesthetics, output_aesthetics, default_scales, isconcrete, setfield!, discretize_make_ia, aes2str @@ -795,7 +796,7 @@ function apply_statistic(stat::TickStatistic, for var in in_vars categorical && !in(var,[:x,:y]) && continue vals = getfield(aes, var) - if vals != nothing && eltype(vals) != Function + if vals != nothing && eltype(vals) != Function && !(eltype(vals) <: Measure) if minval == nothing minval = first(vals) end From 26a0c4032df57f639ac9576c080121e75fc9d8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 18:14:19 +1000 Subject: [PATCH 10/16] Refactor hvband to use statisitics --- src/geom/hvband.jl | 89 +++++++--------------------------------------- 1 file changed, 12 insertions(+), 77 deletions(-) diff --git a/src/geom/hvband.jl b/src/geom/hvband.jl index 7a3dd5186..8f8286c0c 100644 --- a/src/geom/hvband.jl +++ b/src/geom/hvband.jl @@ -1,93 +1,28 @@ -using Compose: x_measure, y_measure +""" + Geom.band[(; orientation=:vertical)] -# Band geometry summarizes data as vertical or horizontal bands. -struct BandGeometry <: Gadfly.GeometryElement - orientation::Symbol - color::Union{Vector, Color, (Void)} - tag::Symbol - BandGeometry(orientation, color, tag) = new(orientation, color === nothing ? nothing : Gadfly.parse_colorant(color), tag) -end +Draw bands across the plot canvas with a horizontal span specifed by `xmin` and `xmax` if `orientation` is `:vertical`, or a vertical span specified by `ymin` and `ymax` if the `orientation` is `:horizontal`. +This geometry is equivalent to [`Geom.rect`](@ref) with [`Stat.band`](@ref). +""" +band(;orientation=:vertical) = RectangularGeometry(Stat.band(orientation)) -HBandGeometry(; color = nothing, tag = empty_tag) = BandGeometry(:horizontal, color, tag) """ - Geom.hband[(; color=nothing)] + Geom.hband[()] Draw horizontal bands across the plot canvas with a vertical span specified by `ymin` and `ymax` aesthetics. -# Optional Aesthetics -- `color`: - Default is `Theme.default_color`. +This geometry is equivalent to [`Geom.band`](@ref) with `orientation` set to `:vertical`. """ -const hband = HBandGeometry - +hband() = band(orientation=:horizontal) -VBandGeometry(; color = nothing, tag = empty_tag) = BandGeometry(:vertical, color, tag) """ - Geom.vband[(; color=nothing)] + Geom.vband[()] Draw vertical bands across the plot canvas with a horizontal span specified by `xmin` and `xmax` aesthetics. -# Optional Aesthetics -- `color`: - Default is `Theme.default_color`. +This geometry is equivalent to [`Geom.band`](@ref). """ -const vband = VBandGeometry - - -element_aesthetics(geom::BandGeometry) = geom.orientation == :vertical ? - [:xmin, :xmax, :color] : [:ymin, :ymax, :color] - - -# Generate a form for the bad geometry -# -# Args: -# geom: band geometry. -# theme: the plot's theme. -# aes: aesthetics. -# -# Returns: -# A compose Form. -# -function render(geom::BandGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - - if geom.orientation == :horizontal - Gadfly.assert_aesthetics_defined("BandGeometry", aes, :ymin, :ymax) - Gadfly.assert_aesthetics_equal_length("BandGeometry", aes, :ymin, :ymax) - - n = max(length(aes.ymin)) #Note: already passed check for equal lengths. - - aes.xmin = fill(0w, n) - xwidths = fill(1w, n) - - ywidths = [(y1 - y0) * cy - for (y0, y1) in zip(aes.ymin, aes.ymax)] - - elseif geom.orientation == :vertical - Gadfly.assert_aesthetics_defined("BandGeometry", aes, :xmin, :xmax) - Gadfly.assert_aesthetics_equal_length("BandGeometry", aes, :xmin, :xmax) - - n = max(length(aes.xmin)) #Note: already passed check for equal lengths. - - aes.ymin = fill(0h, n) - ywidths = fill(1h, n) - - xwidths = [(x1 - x0) * cx - for (x0, x1) in zip(aes.xmin, aes.xmax)] - else - error("Orientation must be :horizontal or :vertical") - end - - color = geom.color === nothing ? theme.default_color : geom.color - - return compose!( - context(), - rectangle(aes.xmin, aes.ymin, xwidths, ywidths, geom.tag), - fill(color), - stroke(nothing), - svgclass("geometry"), - svgattribute("shape-rendering", "crispEdges")) - -end +const vband = band From a6fbcaf8c2dafee1bb510d766bc713e5820da14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 1 Aug 2018 20:04:39 +1000 Subject: [PATCH 11/16] Update gallery and test plots Derived from the suggestions and examples of @Mattriks . --- docs/src/gallery/geometries.md | 48 +++++++++++++++++++++++----------- test/testscripts/hvband.jl | 22 +++++++++++++--- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/docs/src/gallery/geometries.md b/docs/src/gallery/geometries.md index 103e67a6e..57961d36f 100644 --- a/docs/src/gallery/geometries.md +++ b/docs/src/gallery/geometries.md @@ -11,6 +11,35 @@ plot(dataset("ggplot2", "mpg"), Guide.annotation(compose(context(), text(6,4, "y=x", hleft, vtop), fill("red")))) ``` +## [`Geom.band`](@ref), [`Geom.hband`](@ref), [`Geom.vband`](@ref) + + +```@example +using Colors, Gadfly, RDatasets + +Dp = dataset("ggplot2","presidential")[3:end,:] +De = dataset("ggplot2","economics") +De[:Unemploy] /= 10^3 + +plot(De, x=:Date, y=:Unemploy, Geom.line, + layer(Dp, xmin=:Start, xmax=:End, Geom.vband, color=:Party), + Scale.color_discrete_manual("deepskyblue", "lightcoral"), + Coord.cartesian(xmin=Date("1965-01-01"), ymax=12), + Guide.xlabel("Time"), Guide.ylabel("Unemployment (x10³)"), Guide.colorkey(title=""), + Theme(default_color="black", key_position=:top)) +``` + +```@example +using Gadfly, RDatasets + +p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband, Theme(default_color="green"))); + +p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, + layer(ymin=[2.5, 3.6], ymax=[3.0, 4.0], Geom.hband, Theme(default_color="red"))); + +hstack(p1, p2) +``` ## [`Geom.bar`](@ref) @@ -102,7 +131,7 @@ using Gadfly, RDatasets, Distributions set_default_plot_size(14cm, 8cm) dist = MixtureModel(Normal, [(0.5, 0.2), (1, 0.1)]) xs = rand(dist, 10^5) -plot(layer(x=xs, Geom.density, Theme(default_color="orange")), +plot(layer(x=xs, Geom.density, Theme(default_color="orange")), layer(x=xs, Geom.density(bandwidth=0.0003), Theme(default_color="green")), layer(x=xs, Geom.density(bandwidth=0.25), Theme(default_color="purple")), Guide.manual_color_key("bandwidth", ["auto", "bw=0.0003", "bw=0.25"], @@ -171,17 +200,6 @@ pb = plot(x=s.*(x.^2), y=x, color=string.(s), hstack(pa, pb) ``` -## [`Geom.hband`](@ref), [`Geom.vband`](@ref) - -```@example -using Gadfly, RDatasets -set_default_plot_size(21cm, 8cm) -p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, - layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband(color="green"))) -p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, - layer(ymin=[2.5, 3.5], ymax=[3.0, 4.0], Geom.hband(color="red"))) -hstack(p1,p2) -``` ## [`Geom.hexbin`](@ref) @@ -475,8 +493,8 @@ using Gadfly, RDatasets set_default_plot_size(21cm, 8cm) coord = Coord.cartesian(xmin=-2, xmax=2, ymin=-2, ymax=2) -p1 = plot(coord, z=(x,y)->x*exp(-(x^2+y^2)), - xmin=[-2], xmax=[2], ymin=[-2], ymax=[2], +p1 = plot(coord, z=(x,y)->x*exp(-(x^2+y^2)), + xmin=[-2], xmax=[2], ymin=[-2], ymax=[2], # or: x=-2:0.25:2.0, y=-2:0.25:2.0, Geom.vectorfield(scale=0.4, samples=17), Geom.contour(levels=6), Scale.x_continuous(minvalue=-2.0, maxvalue=2.0), @@ -484,7 +502,7 @@ p1 = plot(coord, z=(x,y)->x*exp(-(x^2+y^2)), Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(title="z")) volcano = Matrix{Float64}(dataset("datasets", "volcano")) -volc = volcano[1:4:end, 1:4:end] +volc = volcano[1:4:end, 1:4:end] coord = Coord.cartesian(xmin=1, xmax=22, ymin=1, ymax=16) p2 = plot(coord, z=volc, x=1.0:22, y=1.0:16, Geom.vectorfield(scale=0.05), Geom.contour(levels=7), diff --git a/test/testscripts/hvband.jl b/test/testscripts/hvband.jl index 0d9813a28..96d073f8d 100644 --- a/test/testscripts/hvband.jl +++ b/test/testscripts/hvband.jl @@ -1,7 +1,21 @@ -using Gadfly, RDatasets +using Colors, Gadfly, RDatasets set_default_plot_size(21cm, 8cm) + +Dp = dataset("ggplot2","presidential")[3:end,:] +De = dataset("ggplot2","economics") +De[:Unemploy] /= 10^3 + +p0 = plot(De, x=:Date, y=:Unemploy, Geom.line, + layer(Dp, xmin=:Start, xmax=:End, Geom.vband, color=:Party), + Scale.color_discrete_manual("deepskyblue", "lightcoral"), + Coord.cartesian(xmin=Date("1965-01-01"), ymax=12), + Guide.xlabel("Time"), Guide.ylabel("Unemployment (x10³)"), Guide.colorkey(title=""), + Theme(default_color="black", key_position=:top)); + p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, - layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband(color="green"))) + layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband, Theme(default_color="green"))); + p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, - layer(ymin=[2.5, 3.6], ymax=[3.0, 4.0], Geom.hband(color="red"))) -hstack(p1,p2) + layer(ymin=[2.5, 3.6], ymax=[3.0, 4.0], Geom.hband, Theme(default_color="red"))); + +hstack(p0, p1, p2) From 3d6f4453e75c469aeec261cdaf6bf3e87a256fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Fri, 26 Oct 2018 16:43:42 +0200 Subject: [PATCH 12/16] Simplify test case --- test/testscripts/hvband.jl | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/test/testscripts/hvband.jl b/test/testscripts/hvband.jl index 96d073f8d..3fc5dc396 100644 --- a/test/testscripts/hvband.jl +++ b/test/testscripts/hvband.jl @@ -1,21 +1,10 @@ -using Colors, Gadfly, RDatasets +using Gadfly set_default_plot_size(21cm, 8cm) -Dp = dataset("ggplot2","presidential")[3:end,:] -De = dataset("ggplot2","economics") -De[:Unemploy] /= 10^3 - -p0 = plot(De, x=:Date, y=:Unemploy, Geom.line, - layer(Dp, xmin=:Start, xmax=:End, Geom.vband, color=:Party), - Scale.color_discrete_manual("deepskyblue", "lightcoral"), - Coord.cartesian(xmin=Date("1965-01-01"), ymax=12), - Guide.xlabel("Time"), Guide.ylabel("Unemployment (x10³)"), Guide.colorkey(title=""), - Theme(default_color="black", key_position=:top)); - -p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, +p1 = plot(x=collect(1:9), y=collect(1:9), Geom.point, layer(xmin=[5.0, 7.0], xmax=[6.5, 8.0] , Geom.vband, Theme(default_color="green"))); -p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth", Geom.point, +p2 = plot(x=collect(1:9), y=collect(1:9), Geom.point, layer(ymin=[2.5, 3.6], ymax=[3.0, 4.0], Geom.hband, Theme(default_color="red"))); -hstack(p0, p1, p2) +hstack(p1, p2) From b1fadc0191b31dcf065f44de657410a62068af05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Fri, 26 Oct 2018 16:52:04 +0200 Subject: [PATCH 13/16] Correct visibility logic --- src/geom/rect.jl | 59 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/geom/rect.jl b/src/geom/rect.jl index f80de7e5c..e32206beb 100644 --- a/src/geom/rect.jl +++ b/src/geom/rect.jl @@ -44,22 +44,17 @@ function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aest Gadfly.assert_aesthetics_defined("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax) Gadfly.assert_aesthetics_equal_length("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax) - nx = length(aes.xmin) - ny = length(aes.ymin) - n = nx - xmin = aes.xmin - xwidths = [(x1 - x0)*cx - for (x0, x1) in zip(aes.xmin, aes.xmax)] - + xmax = aes.xmax ymin = aes.ymin - ywidths = [(y1 - y0)*cy - for (y0, y1) in zip(aes.ymin, aes.ymax)] + ymax = aes.ymax + + n = length(xmin) if length(aes.color) == n cs = aes.color else - cs = Array{RGBA{Float32}}(n) + cs = Vector{RGBA{Float32}}(undef, n) for i in 1:n cs[i] = aes.color[((i - 1) % length(aes.color)) + 1] end @@ -82,29 +77,35 @@ function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aest ymax = ymax[visibility] end - return compose!( - context(), - rectangle(xmin, ymin, xwidths, ywidths, geom.tag), - fill(cs), - stroke(nothing), - svgclass("geometry"), - svgattribute("shape-rendering", "crispEdges")) - - # TODO: determine performance hit of using polygons. - # polys = Vector{Vector{Tuple{Measure, Measure}}}(n) - # for i in 1:n - # x0 = x_measure(aes.xmin[i]) - # x1 = x_measure(aes.xmax[i]) - # y0 = y_measure(aes.ymin[i]) - # y1 = y_measure(aes.ymax[i]) - # polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)] - # end + # xwidths = [(x1 - x0)*cx + # for (x0, x1) in zip(xmin, xmax)] + # + # ywidths = [(y1 - y0)*cy + # for (y0, y1) in zip(ymin, ymax)] # # return compose!( # context(), - # Compose.polygon(polys), - # fill(color), + # rectangle(xmin, ymin, xwidths, ywidths, geom.tag), + # fill(cs), # stroke(nothing), # svgclass("geometry"), # svgattribute("shape-rendering", "crispEdges")) + + # TODO: determine performance hit of using polygons. + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, length(xmin)) + for i in 1:length(xmin) + x0 = x_measure(xmin[i]) + x1 = x_measure(xmax[i]) + y0 = y_measure(ymin[i]) + y1 = y_measure(ymax[i]) + polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)] + end + + return compose!( + context(), + Compose.polygon(polys), + fill(cs), + stroke(nothing), + svgclass("geometry"), + svgattribute("shape-rendering", "crispEdges")) end From 10a4030a9f7333ab5037b593054825e2f2a7fc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Fri, 26 Oct 2018 16:53:37 +0200 Subject: [PATCH 14/16] Tweak doc string --- src/statistics.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/statistics.jl b/src/statistics.jl index 934a73867..13a5dc8fe 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -760,7 +760,7 @@ data with `coverage_weight`; and of having a nice numbering with granularity_weight=1/4, simplicity_weight=1/6, coverage_weight=1/3, - niceness_weight=1/4) = + niceness_weight=1/4) = TickStatistic("x", granularity_weight, simplicity_weight, coverage_weight, niceness_weight, ticks) @@ -1643,7 +1643,7 @@ function apply_statistic(stat::ViolinStatistic, uxflag && (grouped_y = Dict(x=>aes.y[aes.x.==x] for x in ux)) - grouped_color = (colorflag ? Dict(x=>first(aes.color[aes.x.==x]) for x in ux) : + grouped_color = (colorflag ? Dict(x=>first(aes.color[aes.x.==x]) for x in ux) : uxflag && Dict(x=>nothing for x in ux) ) aes.x = Array{Float64}(undef, 0) @@ -2042,7 +2042,7 @@ default_scales(stat::BandStatistic) = [Scale.x_continuous(), Scale.y_continuous( """ Stat.band[(; orientation=:vertical)] -Transform points in $(aes2str(input_aesthetics(band()))) into rectangles in +Transform intercepts in $(aes2str(input_aesthetics(band()))) into rectangles in $(aes2str(output_aesthetics(band()))). Used by [`Geom.band`](@ref Gadfly.Geom.band). """ const band = BandStatistic From 78170c1be4b823fd2952704dc23b5c5883c3164e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Fri, 26 Oct 2018 16:53:58 +0200 Subject: [PATCH 15/16] Possible render cascade --- src/geom/rectbin.jl | 50 +++------------------------------------------ 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/src/geom/rectbin.jl b/src/geom/rectbin.jl index cad8b631e..32b7e0279 100644 --- a/src/geom/rectbin.jl +++ b/src/geom/rectbin.jl @@ -64,56 +64,12 @@ element_aesthetics(::RectangularBinGeometry) = # function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - default_aes = Gadfly.Aesthetics() - default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color]) - aes = inherit(aes, default_aes) - Gadfly.assert_aesthetics_defined("RectangularBinGeometry", aes, :xmin, :xmax, :ymin, :ymax) Gadfly.assert_aesthetics_equal_length("RectangularBinGeometry", aes, :xmin, :xmax, :ymin, :ymax) - nx = length(aes.xmin) - ny = length(aes.ymin) - n = nx - - xmin = aes.xmin - xwidths = [(x1 - x0)*cx - theme.bar_spacing - for (x0, x1) in zip(aes.xmin, aes.xmax)] - - ymin = aes.ymin - ywidths = [(y1 - y0)*cy - theme.bar_spacing - for (y0, y1) in zip(aes.ymin, aes.ymax)] - - if length(aes.color) == n - cs = aes.color - else - cs = Array{RGBA{Float32}}(undef, n) - for i in 1:n - cs[i] = aes.color[((i - 1) % length(aes.color)) + 1] - end - end - - allvisible = true - for c in cs - if c == nothing - allvisible = false - break - end - end + aes.xmax = x_measure(aes.xmax) .- theme.bar_spacing - if !allvisible - visibility = cs .!= nothing - cs = cs[visibility] - xmin = xmin[visibility] - xmax = xmax[visibility] - ymin = ymin[visibility] - ymax = ymax[visibility] - end + aes.ymax = y_measure(aes.ymax) .- theme.bar_spacing - return compose!( - context(), - rectangle(xmin, ymin, xwidths, ywidths, geom.tag), - fill(cs), - stroke(nothing), - svgclass("geometry"), - svgattribute("shape-rendering", "crispEdges")) + return render(RectangularGeometry(geom.default_statistic, geom.tag), theme, aes) end From cb9e44da1b35a7b44e6d75b9c6467079d4188cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Fri, 26 Oct 2018 19:22:24 +0200 Subject: [PATCH 16/16] News --- NEWS.md | 79 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/NEWS.md b/NEWS.md index bdb9021d8..2573e44a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,61 +2,66 @@ This is a log of major changes in Gadfly between releases. It is not exhaustive. Each release typically has a number of minor bug fixes beyond what is listed here. +# Version 1.1.0 + * Add `Geom.vband` and `Geom.hband`. + * Add RectangularGeometry. + * RectangularBinGeometry now uses RectangularGeometry for rendering. + # Version 0.9.0 - * conditionally depend on DataFrames (#1204) - * `Geom.abline`: add support for nonlinear `Scale` transformations (#1201) - * drop support for Julia 0.6 (#1189) + * conditionally depend on DataFrames. (#1204) + * `Geom.abline`: add support for nonlinear `Scale` transformations. (#1201) + * drop support for Julia 0.6. (#1189) # Version 0.8.0 - * Add `linestyle` aesthetic (#1181) - * Add `Guide.shapekey` (#1156) - * `Geom.contour`: add support for `DataFrame` (#1150) + * Add `linestyle` aesthetic. (#1181) + * Add `Guide.shapekey`. (#1156) + * `Geom.contour`: add support for `DataFrame`. (#1150) # Version 0.7.0 - * Support DataFrames.jl v0.11+ (#1090, #1129, #1131) - * Change `Theme(grid_strokedash=)` to `Theme(grid_line_style=)` and include in docs (#1106) - * Add `Geom.ellipse` (#1103) - * Improved SVG interactivity (#1037) + * Support DataFrames.jl v0.11+. (#1090, #1129, #1131) + * Change `Theme(grid_strokedash=)` to `Theme(grid_line_style=)` and include in docs. (#1106) + * Add `Geom.ellipse`. (#1103) + * Improved SVG interactivity. (#1037) # Version 0.6.5 - * ColorKeys inside plot panel (#1087) - * Add `Geom.hair` (#1076) - * Shape module (#1050) - * Boxplot improvements + * ColorKeys inside plot panel. (#1087) + * Add `Geom.hair`. (#1076) + * Shape module. (#1050) + * Boxplot improvements. # Version 0.6.4 - * Regression testing tools (#1020) - + * Regression testing tools. (#1020) + # Version 0.6.3 - * Wide format data (#1013) + * Wide format data. (#1013) # Version 0.6.2 - * Add `Geom.rect` (#993) - * Add `Geom.vectorfield` (#992) - * Unified size, color, shape aesthetics for Geom.point (#991) - * {h,v}line point shapes + * Add `Geom.rect`. (#993) + * Add `Geom.vectorfield`. (#992) + * Unified size, color, shape aesthetics for Geom.point. (#991) + * {h,v}line point shapes. # Version 0.6.1 - * Add `Stat.smooth` (#983) + * Add `Stat.smooth`. (#983) # Version 0.6.0 - * Dramatically speed up precompilation by removing old, duplicate code (#958) - * Add `Geom.abline` (#957) - * Add `Geom.density2d` (#959) - * Drop support for Julia 0.4 (#954) + * Dramatically speed up precompilation by removing old, duplicate code. (#958) + * Add `Geom.abline`. (#957) + * Add `Geom.density2d`. (#959) + * Drop support for Julia 0.4. (#954) # Version 0.5.3 - * Support for size aesthetic for `Geom.point` (#952, @tlnagy & @Mattriks) - * Various doc improvements (#923, #933, #943) - * Improved Juno support (#920, @MikeInnes) + * Support for size aesthetic for `Geom.point`. (#952, @tlnagy & @Mattriks) + * Various doc improvements. (#923, #933, #943) + * Improved Juno support. (#920, @MikeInnes) # Version 0.4.1 @@ -74,13 +79,13 @@ Each release typically has a number of minor bug fixes beyond what is listed her * Switch from the Color package to the new Colors package. - * Add `Geom.beeswarm` + * Add `Geom.beeswarm`. # Version 0.3.13 * Add a `push!` function allowing plots to be built incrementally. - * Add `Stat.x_jitter` and `Stat.y_jitter` + * Add `Stat.x_jitter` and `Stat.y_jitter`. * Fix a missing key with `colorkey_swatch_shape=:circle`. @@ -90,7 +95,7 @@ Each release typically has a number of minor bug fixes beyond what is listed her # Version 0.3.12 - * Add `Geom.polygon` + * Add `Geom.polygon`. * Add `Geom.violin`. @@ -121,18 +126,18 @@ Each release typically has a number of minor bug fixes beyond what is listed her # Version 0.3.10 - * Support for [Patchwork.jl](https://github.com/shashi/Patchwork.jl) + * Support for [Patchwork.jl](https://github.com/shashi/Patchwork.jl). * Several fixes for plotting dates. # Version 0.3.9 - * Transition from DateTime.jl to Dates.jl (or Base.Dates in Julia 0.4) + * Transition from DateTime.jl to Dates.jl (or Base.Dates in Julia 0.4). - * Several fixes for `Stat.contour` + * Several fixes for `Stat.contour`. * Split the interface for pretty printing scales into a separate package: - [Showoff.jl](https://github.com/dcjones/Showoff.jl) + [Showoff.jl](https://github.com/dcjones/Showoff.jl). # Version 0.3.8 @@ -220,5 +225,3 @@ Each release typically has a number of minor bug fixes beyond what is listed her keys are wrapped automatically. * Default Theme changes. - -