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

WIP: Polar coordinates #799

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 25 additions & 9 deletions src/Gadfly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ input_aesthetics(::Any) = []
output_aesthetics(::Any) = []
default_scales(::Any) = []
default_statistic(::Any) = Stat.identity()
element_coordinate_type(::Any) = Coord.cartesian
element_coordinate_type(::Any, ::Any) = Coord.cartesian


abstract Element
Expand Down Expand Up @@ -417,8 +417,10 @@ function render_prepare(plot::Plot)

# Figure out the coordinates
coord = plot.coord
coord_type = typeof(plot.coord)
for layer in plot.layers
coord_type = element_coordinate_type(layer.geom)
mapped_aesthetics = Set(keys(layer.mapping))
coord_type = element_coordinate_type(layer.geom, mapped_aesthetics)
if coord === nothing
coord = coord_type()
elseif typeof(coord) != coord_type
Expand Down Expand Up @@ -593,12 +595,24 @@ function render_prepare(plot::Plot)
push!(guides, Guide.zoomslider())
end

if !in(Guide.XTicks, explicit_guide_types)
push!(guides, Guide.xticks())
end
if isa(coord, Coord.cartesian)
if !in(Guide.XTicks, explicit_guide_types)
push!(guides, Guide.xticks())
end

if !in(Guide.YTicks, explicit_guide_types)
push!(guides, Guide.yticks())
end

if !in(Guide.YTicks, explicit_guide_types)
push!(guides, Guide.yticks())
elseif isa(coord, Coord.polar)

if !in(Guide.RhoTicks, explicit_guide_types)
push!(guides, Guide.rhoticks())
end

if !in(Guide.PhiTicks, explicit_guide_types)
push!(guides, Guide.phiticks())
end
end
end

Expand Down Expand Up @@ -781,7 +795,7 @@ function render_prepared(plot::Plot,
for layer in plot.layers]

compose!(plot_context,
[compose(context(order=layer.order), render(layer.geom, theme, aes,
[compose(context(order=layer.order), render(layer.geom, theme, aes, coord,
subplot_aes, subplot_data,
scales))
for (layer, aes, subplot_aes, subplot_data, theme) in zip(plot.layers, layer_aess,
Expand All @@ -792,7 +806,7 @@ function render_prepared(plot::Plot,
# V. Guides
guide_contexts = Any[]
for guide in guides
guide_context = render(guide, plot.theme, plot_aes, dynamic)
guide_context = render(guide, plot.theme, plot_aes, coord, dynamic)
if guide_context != nothing
append!(guide_contexts, guide_context)
end
Expand Down Expand Up @@ -1024,6 +1038,8 @@ const default_aes_scales = @compat Dict{Symbol, Dict}(
:lower_fence => Scale.y_continuous(),
:upper_hinge => Scale.y_continuous(),
:lower_hinge => Scale.y_continuous(),
:rho => Scale.rho_continuous(),
:phi => Scale.phi_continuous(),
:xgroup => Scale.xgroup(),
:ygroup => Scale.ygroup(),
:color => Scale.color_continuous(),
Expand Down
35 changes: 28 additions & 7 deletions src/aesthetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ typealias NumericalAesthetic
x, @compat(Union{NumericalOrCategoricalAesthetic, Distribution})
y, @compat(Union{NumericalOrCategoricalAesthetic, Distribution})
z, @compat(Union{(@compat Void), Function, Matrix})
rho, NumericalAesthetic
phi, NumericalAesthetic
size, Maybe(Vector{Measure})
shape, CategoricalAesthetic
color, Maybe(@compat(Union{AbstractVector{RGBA{Float32}},
Expand Down Expand Up @@ -50,8 +52,12 @@ typealias NumericalAesthetic
# guides
xtick, NumericalAesthetic
ytick, NumericalAesthetic
rhotick, NumericalAesthetic
phitick, NumericalAesthetic
xgrid, NumericalAesthetic
ygrid, NumericalAesthetic
rhogrid, NumericalAesthetic
phigrid, NumericalAesthetic
color_key_colors, Maybe(Associative)
color_key_title, Maybe(AbstractString)
color_key_continuous, Maybe(Bool)
Expand All @@ -61,25 +67,37 @@ typealias NumericalAesthetic
# mark some ticks as initially invisible
xtickvisible, Maybe(Vector{Bool})
ytickvisible, Maybe(Vector{Bool})
rhotickvisible, Maybe(Vector{Bool})
phitickvisible, Maybe(Vector{Bool})

# scale at which ticks should become visible
xtickscale, Maybe(Vector{Float64})
ytickscale, Maybe(Vector{Float64})
rhotickscale, Maybe(Vector{Float64})
phitickscale, Maybe(Vector{Float64})

# plot viewport extents
xviewmin, Any
xviewmax, Any
yviewmin, Any
yviewmax, Any
rhoviewmin, Any
rhoviewmax, Any
phiviewmin, Any
phiviewmax, Any

# labeling functions
x_label, Function, showoff
y_label, Function, showoff
xtick_label, Function, showoff
ytick_label, Function, showoff
color_label, Function, showoff
xgroup_label, Function, showoff
ygroup_label, Function, showoff
x_label, Function, showoff
y_label, Function, showoff
rho_label, Function, showoff
phi_label, Function, showoff
xtick_label, Function, showoff
ytick_label, Function, showoff
rhotick_label, Function, showoff
phitick_label, Function, showoff
color_label, Function, showoff
xgroup_label, Function, showoff
ygroup_label, Function, showoff

# pseudo-aesthetics
pad_categorical_x, Nullable{Bool}, Nullable{Bool}()
Expand All @@ -103,6 +121,9 @@ end
# Alternate aesthetic names
const aesthetic_aliases =
@compat Dict{Symbol, Symbol}(:colour => :color,
:r => :rho,
:ρ => :rho,
:ϕ => :phi,
:x_min => :xmin,
:x_max => :xmax,
:y_min => :ymin,
Expand Down