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 9, 2017
1 parent 5a129fb commit 53c7380
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 124 deletions.
61 changes: 32 additions & 29 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 @@ -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/svg+xml", p)
display(d,"image/svg+xml", p)
return
elseif mimewritable("image/png", p)
display(d,"image/png", p)
return
elseif mimewritable("application/postscript", p)
display(d,"application/postscript", p)
return
elseif mimewritable("application/pdf", p)
display(d,"application/pdf", 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
18 changes: 9 additions & 9 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,8 +370,8 @@ 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
Expand Down Expand Up @@ -410,7 +410,7 @@ function by_xy_group{T <: @compat(Union{Data, Aesthetics})}(aes::T, xgroup, ygro
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
2 changes: 1 addition & 1 deletion src/coord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Compat
using Compose
using DataArrays
import Gadfly.Maybe
import Iterators: cycle
import Compat.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
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
2 changes: 1 addition & 1 deletion src/geom/segment.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

abstract SegmentGeometry <: Gadfly.GeometryElement
@compat abstract type SegmentGeometry <: Gadfly.GeometryElement end

# Geometry for vectors/arrows/segments
immutable SegmentGeom <: SegmentGeometry
Expand Down
2 changes: 1 addition & 1 deletion src/geom/subplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Subplot geometries


abstract SubplotGeometry <: Gadfly.GeometryElement
@compat abstract type SubplotGeometry <: Gadfly.GeometryElement end


# Adding elements to subplots in a generic way.
Expand Down
4 changes: 2 additions & 2 deletions src/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Gadfly: render, layers, element_aesthetics, inherit, escape_id,
default_statistic, default_scales, element_coordinate_type,
ScaleElement, svg_color_class_from_label, isconcrete,
concretize
import Iterators
import Iterators: cycle, product, distinct, takestrict, chain, repeated
import Iterators: chain, distinct, takestrict
import Compat.Iterators: cycle, product, repeated

const empty_tag = Symbol("")

Expand Down
10 changes: 5 additions & 5 deletions src/guide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Gadfly: render, escape_id, default_statistic, jsdata, jsplotdata,


# Where the guide should be placed in relation to the plot.
abstract GuidePosition
@compat abstract type GuidePosition end
immutable TopGuidePosition <: GuidePosition end
immutable RightGuidePosition <: GuidePosition end
immutable BottomGuidePosition <: GuidePosition end
Expand Down Expand Up @@ -208,15 +208,15 @@ function render_discrete_color_key{C<:Color}(colors::Vector{C},

# return a context with a lyout of numcols columns
function make_layout(numcols)
colrows = Array(Int, numcols)
colrows = Array{Int}(numcols)
m = n
for i in 1:numcols
colrows[i] = min(m, ceil(Integer, (n / numcols)))
m -= colrows[i]
end

xpad = 1mm
colwidths = Array(Measure, numcols)
colwidths = Array{Measure}(numcols)
m = 0
for (i, nrows) in enumerate(colrows)
if m == n
Expand Down Expand Up @@ -406,13 +406,13 @@ function render(guide::ColorKey, theme::Gadfly.Theme,
end

used_colors = Set{Color}()
colors = Array(Color, 0) # to preserve ordering
colors = Array{Color}(0) # to preserve ordering
labels = OrderedDict{Color, Set{AbstractString}}()

continuous_guide = false
guide_title = guide.title

if guide_title === nothing && !is(aes.color_key_title, nothing)
if guide_title === nothing && aes.color_key_title !== nothing
guide_title = aes.color_key_title
end

Expand Down
6 changes: 3 additions & 3 deletions src/mapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn})
end
end

push!(V, eltyp == Vector ? Array(eltyp, vm) : DataArray(eltyp, vm))
push!(V, eltyp == Vector ? Array{eltyp}(vm) : DataArray(eltyp, vm))
name = gensym()
push!(vnames, name)
colmap[colgroup] = j
Expand All @@ -159,7 +159,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn})
end

# Indicator columns for each colgroup
indicators = Array(Symbol, (vm, length(colgroups)))
indicators = Array{Symbol}((vm, length(colgroups)))

colidxs = [isnull(colgroup.columns) ? collect(allcolumns) : get(colgroup.columns)
for colgroup in colgroups]
Expand Down Expand Up @@ -219,7 +219,7 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn})
V = similar(U, (vm, vn))

# Indicator columns for each colgroup
indicators = Array(Int, (vm, length(colgroups)))
indicators = Array{Int}((vm, length(colgroups)))

colidxs = [isnull(colgroup.columns) ? collect(allcolumns) : get(colgroup.columns)
for colgroup in colgroups]
Expand Down
8 changes: 4 additions & 4 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function concretize(xss::AbstractVector...)
@label next_j1
end

yss = Array(AbstractVector, length(xss))
yss = Array{AbstractVector}(length(xss))
for (i, xs) in enumerate(xss)
yss[i] = Array(eltype(xs), count)
yss[i] = Array{eltype(xs)}(count)
end

k = 1
Expand Down Expand Up @@ -271,7 +271,7 @@ function inherit!{T}(a::T, b::T)
end


isnothing(u) = is(u, nothing)
isnothing(u) = u === nothing
issomething(u) = !isnothing(u)

negate(f) = x -> !f(x)
Expand Down Expand Up @@ -334,7 +334,7 @@ function evalfunc(f::Function, a, b, n)
@assert n > 1

step = (b - a) / (n - 1)
xs = Array(typeof(a + step), n)
xs = Array{typeof(a + step)}(n)
for i in 1:n
xs[i] = a + (i-1) * step
end
Expand Down
Loading

0 comments on commit 53c7380

Please sign in to comment.