Skip to content

Commit

Permalink
update for julia 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Apr 12, 2017
1 parent 5a129fb commit 994ffa1
Show file tree
Hide file tree
Showing 31 changed files with 181 additions and 179 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
julia 0.5
Colors 0.3.4
Compat 0.8.5
Compose 0.4.4
Compose 0.5
Contour 0.1.1
DataFrames 0.4.2
DataStructures
Expand Down
63 changes: 33 additions & 30 deletions src/Gadfly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function __init__()
end


typealias ColorOrNothing @compat(Union{Colorant, (@compat Void)})
const ColorOrNothing = @compat(Union{Colorant, (@compat Void)})

element_aesthetics(::Any) = []
input_aesthetics(::Any) = []
Expand All @@ -55,12 +55,12 @@ default_statistic(::Any) = Stat.identity()
element_coordinate_type(::Any) = Coord.cartesian


abstract Element
abstract ScaleElement <: Element
abstract CoordinateElement <: Element
abstract GeometryElement <: Element
abstract GuideElement <: Element
abstract StatisticElement <: Element
@compat abstract type Element end
@compat abstract type ScaleElement <: Element end
@compat abstract type CoordinateElement <: Element end
@compat abstract type GeometryElement <: Element end
@compat abstract type GuideElement <: Element end
@compat abstract type StatisticElement <: Element end


include("misc.jl")
Expand All @@ -77,7 +77,7 @@ include("theme.jl")

# The layer and plot functions can also take functions that are evaluated with
# no arguments and are expected to produce an element.
typealias ElementOrFunction{T <: Element} @compat(Union{Element, Base.Callable, Theme})
@compat const ElementOrFunction{T <: Element} = @compat(Union{Element, Base.Callable, Theme})

const gadflyjs = joinpath(dirname(Base.source_path()), "gadfly.js")

Expand Down Expand Up @@ -184,7 +184,7 @@ end


function add_plot_element!(lyrs::Vector{Layer}, arg::GeometryElement)
if ! is(lyrs[end].geom, Geom.nil())
if lyrs[end].geom !== Geom.nil()
push!(lyrs, copy(lyrs[end]))
end
lyrs[end].geom = arg
Expand Down Expand Up @@ -313,7 +313,7 @@ end
# because a call to layer() expands to a vector of layers (one for each Geom
# supplied), we need to allow Vector{Layer} to count as an Element for the
# purposes of plot().
typealias ElementOrFunctionOrLayers @compat(Union{ElementOrFunction, Vector{Layer}})
const ElementOrFunctionOrLayers = @compat(Union{ElementOrFunction, Vector{Layer}})


"""
Expand Down Expand Up @@ -452,7 +452,7 @@ function render_prepare(plot::Plot)

# Process layers, filling inheriting mappings or data from the Plot where
# they are missing.
datas = Array(Data, length(plot.layers))
datas = Array{Data}(length(plot.layers))
for (i, layer) in enumerate(plot.layers)
if layer.data_source === nothing && isempty(layer.mapping)
layer.data_source = plot.data_source
Expand Down Expand Up @@ -507,7 +507,7 @@ function render_prepare(plot::Plot)
end

# Add default statistics for geometries.
layer_stats = Array(Vector{StatisticElement}, length(plot.layers))
layer_stats = Array{Vector{StatisticElement}}(length(plot.layers))
for (i, layer) in enumerate(plot.layers)
layer_stats[i] = isempty(layer.statistics) ?
[default_statistic(layer.geom)] : layer.statistics
Expand Down Expand Up @@ -783,8 +783,8 @@ function render_prepare(plot::Plot)
end

# build arrays of scaled aesthetics for layers within subplots
layer_subplot_aess = Array(Vector{Aesthetics}, length(plot.layers))
layer_subplot_datas = Array(Vector{Data}, length(plot.layers))
layer_subplot_aess = Array{Vector{Aesthetics}}(length(plot.layers))
layer_subplot_datas = Array{Vector{Data}}(length(plot.layers))
j = 1
for (i, layer) in enumerate(plot.layers)
layer_subplot_aess[i] = Aesthetics[]
Expand Down Expand Up @@ -1046,7 +1046,6 @@ function default_mime()
end
end

import Base.Multimedia: @try_display, xdisplayable
import Base.REPL: REPLDisplay

"""
Expand All @@ -1057,22 +1056,26 @@ Render `p` to a multimedia display, typically an internet browser.
This function is handy when rendering by `plot` has been suppressed
with either trailing semi-colon or by calling it within a function.
"""
function display(p::Union{Plot,Compose.Context})
displays = Base.Multimedia.displays
for i = length(displays):-1:1
m = default_mime()
if xdisplayable(displays[i], m, p)
@try_display return display(displays[i], m, p)
end

if xdisplayable(displays[i], p)
@try_display return display(displays[i], p)
end
function display(d::REPLDisplay, p::Union{Plot,Compose.Context})
if mimewritable("text/html", p)
display(d,"text/html", p)
return
elseif mimewritable("image/png", p)
display(d,"image/png", p)
return
elseif mimewritable("application/pdf", p)
display(d,"application/pdf", p)
return
elseif mimewritable("image/svg+xml", p)
display(d,"image/svg+xml", p)
return
elseif mimewritable("application/postscript", p)
display(d,"application/postscript", p)
return
end
invoke(display, Tuple{Any}, p)
throw(MethodError)
end


function open_file(filename)
if is_apple()
run(`open $(filename)`)
Expand Down Expand Up @@ -1112,7 +1115,7 @@ function display(d::REPLDisplay, ::MIME"text/html", p::Union{Plot,Compose.Contex
plot_output = IOBuffer()
draw(SVGJS(plot_output, Compose.default_graphic_width,
Compose.default_graphic_height, false), p)
plotsvg = takebuf_string(plot_output)
plotsvg = String(take!(plot_output))

write(output,
"""
Expand Down Expand Up @@ -1262,7 +1265,7 @@ end

# Determine whether the input is categorical or numerical

typealias CategoricalType @compat(Union{AbstractString, Bool, Symbol})
const CategoricalType = @compat(Union{AbstractString, Bool, Symbol})


function classify_data{N, T <: CategoricalType}(data::AbstractArray{T, N})
Expand Down
24 changes: 12 additions & 12 deletions src/aesthetics.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


typealias NumericalOrCategoricalAesthetic
const NumericalOrCategoricalAesthetic =
@compat(Union{(@compat Void), Vector, DataArray, PooledDataArray})

typealias CategoricalAesthetic
const CategoricalAesthetic =
@compat(Union{(@compat Void), PooledDataArray})

typealias NumericalAesthetic
const NumericalAesthetic =
@compat(Union{(@compat Void), Matrix, Vector, DataArray})


Expand Down Expand Up @@ -135,7 +135,7 @@ end
function defined_aesthetics(aes::Aesthetics)
vars = Set{Symbol}()
for name in fieldnames(Aesthetics)
if !is(getfield(aes, name), nothing)
if getfield(aes, name) !== nothing
push!(vars, name)
end
end
Expand Down Expand Up @@ -177,7 +177,7 @@ end


function assert_aesthetics_equal_length(who::AbstractString, aes::Aesthetics, vars::Symbol...)
defined_vars = filter(var -> !(getfield(aes, var) === nothing), vars)
defined_vars = Compat.Iterators.filter(var -> !(getfield(aes, var) === nothing), vars)

if !isempty(defined_vars)
n = length(getfield(aes, first(defined_vars)))
Expand Down Expand Up @@ -309,7 +309,7 @@ function cat_aes_var!{T, U}(a::AbstractArray{T}, b::AbstractArray{U})
if isa(a, DataArray) || isa(b, DataArray)
ab = DataArray(V, length(a) + length(b))
else
ab = Array(V, length(a) + length(b))
ab = Array{V}(length(a) + length(b))
end
i = 1
for x in a
Expand Down Expand Up @@ -370,13 +370,13 @@ function by_xy_group{T <: @compat(Union{Data, Aesthetics})}(aes::T, xgroup, ygro
xrefs = xgroup === nothing ? [1] : xgroup
yrefs = ygroup === nothing ? [1] : ygroup

aes_grid = Array(T, n, m)
staging = Array(AbstractArray, n, m)
aes_grid = Array{T}(n, m)
staging = Array{AbstractArray}(n, m)
for i in 1:n, j in 1:m
aes_grid[i, j] = T()
end

if is(xgroup, nothing) && is(ygroup, nothing)
if xgroup === nothing && ygroup === nothing
return aes_grid
end

Expand All @@ -401,16 +401,16 @@ function by_xy_group{T <: @compat(Union{Data, Aesthetics})}(aes::T, xgroup, ygro

vals = getfield(aes, var)
if typeof(vals) <: AbstractArray
if !is(xgroup, nothing) && length(vals) != length(xgroup) ||
!is(ygroup, nothing) && length(vals) != length(ygroup)
if xgroup !== nothing && length(vals) !== length(xgroup) ||
ygroup !== nothing && length(vals) !== length(ygroup)
error("Aesthetic $(var) must be the same length as xgroup or ygroup")
end

for i in 1:n, j in 1:m
staging[i, j] = similar(vals, 0)
end

for (i, j, v) in zip(Iterators.cycle(yrefs), Iterators.cycle(xrefs), vals)
for (i, j, v) in zip(Compat.Iterators.cycle(yrefs), Compat.Iterators.cycle(xrefs), vals)
push!(staging[i, j], v)
end

Expand Down
1 change: 0 additions & 1 deletion src/coord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using Compat
using Compose
using DataArrays
import Gadfly.Maybe
import Iterators: cycle

export cartesian

Expand Down
8 changes: 4 additions & 4 deletions src/format.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function formatter{T<:Date}(ds::AbstractArray{T}; fmt=nothing)
function format(d)
buf = IOBuffer()
print(buf, year(d))
takebuf_string(buf)
String(take!(buf))
end
elseif day_all_1
# label months and years
Expand All @@ -219,7 +219,7 @@ function formatter{T<:Date}(ds::AbstractArray{T}; fmt=nothing)
else
print(buf, month_abbrevs[month(d)])
end
takebuf_string(buf)
String(take!(buf))
end
else
function format(d)
Expand All @@ -231,7 +231,7 @@ function formatter{T<:Date}(ds::AbstractArray{T}; fmt=nothing)
else
print(buf, day(d))
end
takebuf_string(buf)
String(take!(buf))
end
end
end
Expand All @@ -242,7 +242,7 @@ function formatter(xs::AbstractArray; fmt=nothing)
function format(x)
buf = IOBuffer()
print(buf, x)
takebuf_string(buf)
String(take!(buf))
end

format
Expand Down
12 changes: 6 additions & 6 deletions src/geom/bar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function render_colorless_bar(geom::BarGeometry,
context(),
rectangle([min(xz, x) for x in aes.x],
[ymin*cy + theme.bar_spacing/2 for ymin in aes.ymin],
abs(aes.x),
abs.(aes.x),
[(ymax - ymin)*cy - theme.bar_spacing
for (ymin, ymax) in zip(aes.ymin, aes.ymax)], geom.tag),
svgclass("geometry"))
Expand All @@ -83,7 +83,7 @@ function render_colorless_bar(geom::BarGeometry,
[min(yz, y) for y in aes.y],
[(xmax - xmin)*cx - theme.bar_spacing
for (xmin, xmax) in zip(aes.xmin, aes.xmax)],
abs(aes.y), geom.tag),
abs.(aes.y), geom.tag),
svgclass("geometry"))
end

Expand Down Expand Up @@ -198,7 +198,7 @@ function render_colorful_dodged_bar(geom::BarGeometry,
dodge_pos_dict[aes.ymin[i]] = aes.ymin[i]*cy
end

dodge_pos = Array(Measure, length(idxs))
dodge_pos = Array{Measure}(length(idxs))
for (i, j) in enumerate(idxs)
dodge_pos[i] = dodge_pos_dict[aes.ymin[j]] + theme.bar_spacing/2
dodge_pos_dict[aes.ymin[j]] += dodge_height[aes.ymin[j]]
Expand All @@ -213,7 +213,7 @@ function render_colorful_dodged_bar(geom::BarGeometry,
rectangle(
[min(xz, x) for x in aes_x],
dodge_pos,
abs(aes_x),
abs.(aes_x),
[((aes.ymax[i] - aes.ymin[i])*cy - theme.bar_spacing) / dodge_count[aes.ymin[i]]
for i in idxs], geom.tag))
elseif orientation == :vertical
Expand All @@ -230,7 +230,7 @@ function render_colorful_dodged_bar(geom::BarGeometry,
dodge_pos_dict[aes.xmin[i]] = aes.xmin[i]*cx
end

dodge_pos = Array(Measure, length(idxs))
dodge_pos = Array{Measure}(length(idxs))
for (i, j) in enumerate(idxs)
dodge_pos[i] = dodge_pos_dict[aes.xmin[j]] + theme.bar_spacing/2
dodge_pos_dict[aes.xmin[j]] += dodge_width[aes.xmin[j]]
Expand All @@ -247,7 +247,7 @@ function render_colorful_dodged_bar(geom::BarGeometry,
[min(yz, y) for y in aes_y],
[((aes.xmax[i] - aes.xmin[i])*cx - theme.bar_spacing) / dodge_count[aes.xmin[i]]
for i in idxs],
abs(aes_y), geom.tag))
abs.(aes_y), geom.tag))
else
error("Orientation must be :horizontal or :vertical")
end
Expand Down
8 changes: 4 additions & 4 deletions src/geom/beeswarm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function render(geom::BeeswarmGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthet
end

point_dist = (2*theme.default_point_size + geom.padding).value
offsets = Array(Length{:mm}, length(val))
positions = Array(Compose.Measure, length(val))
offsets = Array{Length{:mm}}(length(val))
positions = Array{Compose.Measure}(length(val))

n = length(val)
overlaps = Array(Bool, n)
absvals = Array(Float64, n)
overlaps = Array{Bool}(n)
absvals = Array{Float64}(n)
for (i, v) in enumerate(val)
absvals[i] = Compose.resolve_position(
draw_context.box,
Expand Down
4 changes: 2 additions & 2 deletions src/geom/label.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function deferred_label_context(geom::LabelGeometry,
# This should maybe go in theme? Or should we be using Aesthetics.size?
padding = 2mm

point_positions = Array(AbsoluteVec2, 0)
point_positions = Array{AbsoluteVec2}(0)
for (x, y) in zip(aes.x, aes.y)
x = Compose.resolve_position(parent_box, units, parent_transform, Compose.x_measure(x))
y = Compose.resolve_position(parent_box, units, parent_transform, Compose.y_measure(y))
Expand Down Expand Up @@ -102,7 +102,7 @@ function deferred_label_context(geom::LabelGeometry,
# Checking for label overlaps is O(n^2). To mitigate these costs, we build a
# sparse overlap matrix. This also costs O(n^2), but we only have to do it
# once, rather than every iteration of annealing.
possible_overlaps = [Array(Int, 0) for _ in 1:length(positions)]
possible_overlaps = [Array{Int}(0) for _ in 1:length(positions)]

# TODO: this whole thing would be much more effecient if we forbid from
# the start labels that overlap points. We should be able to precompute
Expand Down
2 changes: 1 addition & 1 deletion src/geom/line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function render(geom::LineGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics)
sort!(points, by=first)
end

ctx = compose!(ctx, Compose.line(points,geom.tag),
ctx = compose!(ctx, Compose.line([points],geom.tag),
stroke(aes.color[1]),
strokedash(line_style),
svgclass("geometry"))
Expand Down
8 changes: 4 additions & 4 deletions src/geom/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function render(geom::PointGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics

ctx = context()
if aes.shape != nothing
xs = Array(eltype(aes_x), 0)
ys = Array(eltype(aes_y), 0)
cs = Array(eltype(aes.color), 0)
size = Array(eltype(aes.size), 0)
xs = Array{eltype(aes_x)}(0)
ys = Array{eltype(aes_y)}(0)
cs = Array{eltype(aes.color)}(0)
size = Array{eltype(aes.size)}(0)
shape_max = maximum(aes.shape)
if shape_max > length(theme.shapes)
error("Too many values for the shape aesthetic. Define more shapes in Theme.shapes")
Expand Down
Loading

0 comments on commit 994ffa1

Please sign in to comment.