|
75 | 75 | # COV_EXCL_STOP |
76 | 76 |
|
77 | 77 | @eval const $(Symbol("@es")) = $(Symbol("@aes")) |
| 78 | + |
| 79 | +@testitem "Aes operations" setup=[TidierPlotsSetup] begin |
| 80 | + t = ggplot(penguins) + |
| 81 | + geom_point(aes(x = :bill_length_mm => (x -> x .+ 10), |
| 82 | + y = :bill_depth_mm => (y -> y .+ 20))) |
| 83 | + m = Makie.plot( |
| 84 | + Makie.SpecApi.GridLayout( |
| 85 | + Makie.SpecApi.Axis( |
| 86 | + plots = [ |
| 87 | + Makie.PlotSpec( |
| 88 | + :Scatter, |
| 89 | + penguins.bill_length_mm .+ 10, |
| 90 | + penguins.bill_depth_mm .+ 20) |
| 91 | + ] |
| 92 | + ) |
| 93 | + ) |
| 94 | + ) |
| 95 | + @test plot_images_equal(t, m) |
| 96 | + t = ggplot(penguins) + |
| 97 | + geom_point(aes(x = [:bill_length_mm, :bill_depth_mm] => ((x, y) ->x .+ y), y = :bill_depth_mm)) |
| 98 | + m = Makie.plot( |
| 99 | + Makie.SpecApi.GridLayout( |
| 100 | + Makie.SpecApi.Axis( |
| 101 | + plots = [ |
| 102 | + Makie.PlotSpec( |
| 103 | + :Scatter, |
| 104 | + penguins.bill_length_mm .+ penguins.bill_depth_mm, |
| 105 | + penguins.bill_depth_mm) |
| 106 | + ] |
| 107 | + ) |
| 108 | + ) |
| 109 | + ) |
| 110 | + @test plot_images_equal(t, m) |
| 111 | + t = ggplot(penguins) + |
| 112 | + geom_point(aes(x = :bill_length_mm => (x -> x .- 10), |
| 113 | + y = :bill_depth_mm => (y -> y .- 20))) |
| 114 | + m = Makie.plot( |
| 115 | + Makie.SpecApi.GridLayout( |
| 116 | + Makie.SpecApi.Axis( |
| 117 | + plots = [ |
| 118 | + Makie.PlotSpec( |
| 119 | + :Scatter, |
| 120 | + penguins.bill_length_mm .- 10, |
| 121 | + penguins.bill_depth_mm .- 20) |
| 122 | + ] |
| 123 | + ) |
| 124 | + ) |
| 125 | + ) |
| 126 | + @test plot_images_equal(t, m) |
| 127 | + t = ggplot(penguins) + |
| 128 | + geom_point(aes(x = [:bill_length_mm, :bill_depth_mm] => ((x, y) ->x .- y), y = :bill_depth_mm)) |
| 129 | + tm = ggplot(penguins) + |
| 130 | + geom_point(@aes(x = bill_length_mm - bill_depth_mm, |
| 131 | + y = bill_depth_mm)) |
| 132 | + m = Makie.plot( |
| 133 | + Makie.SpecApi.GridLayout( |
| 134 | + Makie.SpecApi.Axis( |
| 135 | + plots = [ |
| 136 | + Makie.PlotSpec( |
| 137 | + :Scatter, |
| 138 | + penguins.bill_length_mm .- penguins.bill_depth_mm, |
| 139 | + penguins.bill_depth_mm) |
| 140 | + ] |
| 141 | + ) |
| 142 | + ) |
| 143 | + ) |
| 144 | + @test plot_images_equal(t, m) |
| 145 | + @test plot_images_equal(tm, m) |
| 146 | + t = ggplot(penguins) + |
| 147 | + geom_point(aes(x = :bill_length_mm => (x -> x .* 10), |
| 148 | + y = :bill_depth_mm => (y -> y .* 20))) |
| 149 | + m = Makie.plot( |
| 150 | + Makie.SpecApi.GridLayout( |
| 151 | + Makie.SpecApi.Axis( |
| 152 | + plots = [ |
| 153 | + Makie.PlotSpec( |
| 154 | + :Scatter, |
| 155 | + penguins.bill_length_mm .* 10, |
| 156 | + penguins.bill_depth_mm .* 20) |
| 157 | + ] |
| 158 | + ) |
| 159 | + ) |
| 160 | + ) |
| 161 | + @test plot_images_equal(t, m) |
| 162 | + t = ggplot(penguins) + |
| 163 | + geom_point(aes(x = [:bill_length_mm, :bill_depth_mm] => ((x, y) ->x .* y), y = :bill_depth_mm)) |
| 164 | + m = Makie.plot( |
| 165 | + Makie.SpecApi.GridLayout( |
| 166 | + Makie.SpecApi.Axis( |
| 167 | + plots = [ |
| 168 | + Makie.PlotSpec( |
| 169 | + :Scatter, |
| 170 | + penguins.bill_length_mm .* penguins.bill_depth_mm, |
| 171 | + penguins.bill_depth_mm) |
| 172 | + ] |
| 173 | + ) |
| 174 | + ) |
| 175 | + ) |
| 176 | + @test plot_images_equal(t, m) |
| 177 | + t = ggplot(penguins) + |
| 178 | + geom_point(aes(x = :bill_length_mm => (x -> x ./ 10), |
| 179 | + y = :bill_depth_mm => (y -> y ./ 20))) |
| 180 | + m = Makie.plot( |
| 181 | + Makie.SpecApi.GridLayout( |
| 182 | + Makie.SpecApi.Axis( |
| 183 | + plots = [ |
| 184 | + Makie.PlotSpec( |
| 185 | + :Scatter, |
| 186 | + penguins.bill_length_mm ./ 10, |
| 187 | + penguins.bill_depth_mm ./ 20) |
| 188 | + ] |
| 189 | + ) |
| 190 | + ) |
| 191 | + ) |
| 192 | + @test plot_images_equal(t, m) |
| 193 | + t = ggplot(penguins) + |
| 194 | + geom_point(aes(x = [:bill_length_mm, :bill_depth_mm] => ((x, y) ->x ./ y), y = :bill_depth_mm)) |
| 195 | + m = Makie.plot( |
| 196 | + Makie.SpecApi.GridLayout( |
| 197 | + Makie.SpecApi.Axis( |
| 198 | + plots = [ |
| 199 | + Makie.PlotSpec( |
| 200 | + :Scatter, |
| 201 | + penguins.bill_length_mm ./ penguins.bill_depth_mm, |
| 202 | + penguins.bill_depth_mm) |
| 203 | + ] |
| 204 | + ) |
| 205 | + ) |
| 206 | + ) |
| 207 | + @test plot_images_equal(t, m) |
| 208 | + my_func(x) = x ./ 10 |
| 209 | + t = ggplot(penguins) + |
| 210 | + geom_point(aes(x = :bill_length_mm => my_func, y = :bill_depth_mm)) |
| 211 | + m = Makie.plot( |
| 212 | + Makie.SpecApi.GridLayout( |
| 213 | + Makie.SpecApi.Axis( |
| 214 | + plots = [ |
| 215 | + Makie.PlotSpec( |
| 216 | + :Scatter, |
| 217 | + penguins.bill_length_mm ./ 10, |
| 218 | + penguins.bill_depth_mm) |
| 219 | + ] |
| 220 | + ) |
| 221 | + ) |
| 222 | + ) |
| 223 | + @test plot_images_equal(t, m) |
| 224 | + my_func(x, y) = x ./ y |
| 225 | + t = ggplot(penguins) + |
| 226 | + geom_point(aes(x = [:bill_length_mm, :bill_depth_mm] => my_func, y= :bill_depth_mm)) |
| 227 | + m = Makie.plot( |
| 228 | + Makie.SpecApi.GridLayout( |
| 229 | + Makie.SpecApi.Axis( |
| 230 | + plots = [ |
| 231 | + Makie.PlotSpec( |
| 232 | + :Scatter, |
| 233 | + penguins.bill_length_mm ./ penguins.bill_depth_mm, |
| 234 | + penguins.bill_depth_mm) |
| 235 | + ] |
| 236 | + ) |
| 237 | + ) |
| 238 | + ) |
| 239 | + @test plot_images_equal(t, m) |
| 240 | +end |
| 241 | + |
| 242 | +@testitem "Aes specifications" setup=[TidierPlotsSetup] begin |
| 243 | + function Base.:(==)(aes1::TidierPlots.Aesthetics, aes2::TidierPlots.Aesthetics) |
| 244 | + if length(aes1.positional) != 0 || length(aes2.positional) != 0 |
| 245 | + if length(aes2.positional) != length(aes1.positional) |
| 246 | + return false |
| 247 | + end |
| 248 | + if any(aes1.positional .!= aes2.positional) |
| 249 | + return false |
| 250 | + end |
| 251 | + end |
| 252 | + |
| 253 | + if length(aes1.named) != 0 || length(aes2.named) != 0 |
| 254 | + if length(aes2.named) != length(aes1.named) |
| 255 | + return false |
| 256 | + end |
| 257 | + if length(intersect(keys(aes1.named), keys(aes2.named))) != length(aes1. named) |
| 258 | + return false |
| 259 | + end |
| 260 | + for (k, v) in aes1.named |
| 261 | + if aes2.named[k] != v |
| 262 | + return false |
| 263 | + end |
| 264 | + end |
| 265 | + end |
| 266 | + |
| 267 | + return true |
| 268 | + end |
| 269 | + |
| 270 | + @test aes(x = "x", y = "y") == @aes(x = x, y = y) |
| 271 | + @test aes(x = "x", y = "y") == @es(x = x, y = y) |
| 272 | + @test aes(x = "x", y = "y") == aes(x = :x, y = :y) |
| 273 | + @test aes("x", "y") == @aes(x, y) |
| 274 | + @test aes("x", "y") == @es(x, y) |
| 275 | + @test aes("x", "y") == aes(:x, :y) |
| 276 | + @test aes("x", y = "y") == aes(:x, y = :y) |
| 277 | + @test aes("x", y = "y") == @es(x, y = y) |
| 278 | + @test aes("x", y = "y") == @aes(x, y = y) |
| 279 | + @test_throws ErrorException @macroexpand @aes(x/10) |
| 280 | + to_cm(x) = x ./ 10 |
| 281 | + @test_throws ErrorException aes(:x => to_cm) |
| 282 | +end |
0 commit comments