diff --git a/REQUIRE b/REQUIRE index 8097e3482..1cd55a52c 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,5 @@ julia 0.7 +CategoricalArrays # might be able to remove Colors 0.3.4 Compat 0.18.0 Compose 0.5.2 @@ -13,6 +14,7 @@ IterTools JSON KernelDensity Loess +Measures Showoff 0.0.3 StatsBase Juno diff --git a/src/Gadfly.jl b/src/Gadfly.jl index eac16e868..8ea28addd 100755 --- a/src/Gadfly.jl +++ b/src/Gadfly.jl @@ -9,10 +9,12 @@ using JSON using Showoff using IndirectArrays using CategoricalArrays +using Printf +using Base64 import IterTools import IterTools: distinct, drop, chain -import Compose: draw, hstack, vstack, gridstack, isinstalled, parse_colorant +import Compose: draw, hstack, vstack, gridstack, parse_colorant import Base: +, -, /, *, copy, push!, start, next, done, show, getindex, cat, show, isfinite, display @@ -378,7 +380,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}(undef, length(plot.layers)) for (i, layer) in enumerate(plot.layers) if layer.data_source === nothing && isempty(layer.mapping) layer.data_source = plot.data_source @@ -434,7 +436,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}}(undef, length(plot.layers)) for (i, layer) in enumerate(plot.layers) layer_stats[i] = isempty(layer.statistics) ? ( isa(layer.geom, Geom.SubplotGeometry) ? default_statistic(layer.geom) : [default_statistic(layer.geom)] ) : layer.statistics @@ -550,7 +552,7 @@ function render_prepare(plot::Plot) (haskey(plot.mapping, var) || haskey(scales, var)) && continue t = :categorical - for data in chain(datas, subplot_datas) + for data in Iterators.flatten((datas, subplot_datas)) val = getfield(data, var) if val != nothing && val != :categorical t = classify_data(val) @@ -711,8 +713,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}}(undef, length(plot.layers)) + layer_subplot_datas = Array{Vector{Data}}(undef, length(plot.layers)) j = 1 for (i, layer) in enumerate(plot.layers) layer_subplot_aess[i] = Aesthetics[] @@ -988,7 +990,7 @@ function default_mime() end end -import Base.REPL: REPLDisplay +import REPL: REPLDisplay """ display(p::Plot) @@ -998,19 +1000,19 @@ 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(d::REPLDisplay, p::Union{Plot,Compose.Context}) - if mimewritable("text/html", p) + if showable("text/html", p) display(d,"text/html", p) return - elseif mimewritable("image/png", p) + elseif showable("image/png", p) display(d,"image/png", p) return - elseif mimewritable("application/pdf", p) + elseif showable("application/pdf", p) display(d,"application/pdf", p) return - elseif mimewritable("image/svg+xml", p) + elseif showable("image/svg+xml", p) display(d,"image/svg+xml", p) return - elseif mimewritable("application/postscript", p) + elseif showable("application/postscript", p) display(d,"application/postscript", p) return end diff --git a/src/aesthetics.jl b/src/aesthetics.jl index cb0281683..4086dbc37 100755 --- a/src/aesthetics.jl +++ b/src/aesthetics.jl @@ -11,14 +11,14 @@ const NumericalAesthetic = @varset Aesthetics begin x, Union{NumericalOrCategoricalAesthetic, Distribution} y, Union{NumericalOrCategoricalAesthetic, Distribution} - z, Union{(Void), Function, NumericalAesthetic} + z, Union{Nothing, Function, NumericalAesthetic} xend, NumericalAesthetic yend, NumericalAesthetic - size, Union{CategoricalAesthetic,Vector,Void} - shape, Union{CategoricalAesthetic,Vector,Void} - color, Union{CategoricalAesthetic,Vector,Void} - linestyle, Union{CategoricalAesthetic,Vector,Void} + size, Union{CategoricalAesthetic,Vector,Nothing} + shape, Union{CategoricalAesthetic,Vector,Nothing} + color, Union{CategoricalAesthetic,Vector,Nothing} + linestyle, Union{CategoricalAesthetic,Vector,Nothing} label, CategoricalAesthetic group, CategoricalAesthetic @@ -56,7 +56,7 @@ const NumericalAesthetic = ytick, NumericalAesthetic xgrid, NumericalAesthetic ygrid, NumericalAesthetic - color_key_colors, Maybe(Associative) + color_key_colors, Maybe(AbstractDict) color_key_title, Maybe(AbstractString) color_key_continuous, Maybe(Bool) color_function, Maybe(Function) @@ -88,8 +88,8 @@ const NumericalAesthetic = shape_label, Function, showoff # pseudo-aesthetics - pad_categorical_x, Nullable{Bool}, Nullable{Bool}() - pad_categorical_y, Nullable{Bool}, Nullable{Bool}() + pad_categorical_x, Union{Missing,Bool}, missing + pad_categorical_y, Union{Missing,Bool}, missing end @@ -273,9 +273,9 @@ cat_aes_var!(a, b) = a function cat_aes_var!(a::AbstractArray{T}, b::AbstractArray{U}) where {T, U} V = promote_type(T, U) if isa(a, Array{Union{Missing,T}}) || isa(b, Array{Union{Missing,U}}) - ab = Array{Union{Missing,V}}(length(a) + length(b)) + ab = Array{Union{Missing,V}}(undef, length(a) + length(b)) else - ab = Array{V}(length(a) + length(b)) + ab = Array{V}(undef, length(a) + length(b)) end i = 1 for x in a @@ -320,8 +320,8 @@ function by_xy_group(aes::T, xgroup, ygroup, 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}(undef, n, m) + staging = Array{AbstractArray}(undef, n, m) for i in 1:n, j in 1:m aes_grid[i, j] = T() end @@ -370,7 +370,7 @@ function by_xy_group(aes::T, xgroup, ygroup, if !applicable(convert, typeof(vals), staging[i, j]) T2 = eltype(vals) if T2 <: Color T2 = Color end - da = Array{Union{Missing,T2}}(length(staging[i, j])) + da = Array{Union{Missing,T2}}(undef, length(staging[i, j])) copy!(da, staging[i, j]) setfield!(aes_grid[i, j], var, da) else @@ -404,7 +404,7 @@ function inherit!(a::Aesthetics, b::Aesthetics; bval = getfield(b, field) if field in clobber_set setfield!(a, field, bval) - elseif aval === nothing || aval === string || aval == showoff + elseif aval === missing || aval === nothing || aval === string || aval == showoff setfield!(a, field, bval) elseif field == :xviewmin || field == :yviewmin bval != nothing && (aval == nothing || aval > bval) && setfield!(a, field, bval) diff --git a/src/bincount.jl b/src/bincount.jl index 75e7bd43b..f13d90349 100644 --- a/src/bincount.jl +++ b/src/bincount.jl @@ -69,7 +69,7 @@ end # numbins: number of bins # function bin!(bincounts::Vector, xs, x_min, binwidth, numbins) - bincounts[1:numbins] = 0 + bincounts[1:numbins] .= 0 for x in xs if !isconcrete(x) continue diff --git a/src/coord.jl b/src/coord.jl index 23cb90c3f..5358591a1 100644 --- a/src/coord.jl +++ b/src/coord.jl @@ -132,21 +132,21 @@ end # function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, scales::Dict{Symbol, Gadfly.ScaleElement}) - pad_categorical_x = Nullable{Bool}() - pad_categorical_y = Nullable{Bool}() + pad_categorical_x = missing + pad_categorical_y = missing for aes in aess - if !isnull(aes.pad_categorical_x) - if isnull(pad_categorical_x) + if aes.pad_categorical_x !== missing + if pad_categorical_x === missing pad_categorical_x = aes.pad_categorical_x else - pad_categorical_x = Nullable(get(pad_categorical_x) || get(aes.pad_categorical_x)) + pad_categorical_x = pad_categorical_x || aes.pad_categorical_x end end - if !isnull(aes.pad_categorical_y) - if isnull(pad_categorical_y) + if aes.pad_categorical_y !== missing + if pad_categorical_y === missing pad_categorical_y = aes.pad_categorical_y else - pad_categorical_y = Nullable(get(pad_categorical_y) || get(aes.pad_categorical_y)) + pad_categorical_y = pad_categorical_y || aes.pad_categorical_y end end end @@ -237,12 +237,12 @@ function apply_coordinate(coord::Cartesian, aess::Vector{Gadfly.Aesthetics}, xpadding = Scale.iscategorical(scales, :x) ? 0mm : 2mm ypadding = Scale.iscategorical(scales, :y) ? 0mm : 2mm - if Scale.iscategorical(scales, :x) && (isnull(pad_categorical_x) || get(pad_categorical_x)) + if Scale.iscategorical(scales, :x) && (pad_categorical_x===missing || pad_categorical_x) xmin -= 0.5 xmax += 0.5 end - if Scale.iscategorical(scales, :y) && (isnull(pad_categorical_y) || get(pad_categorical_y)) + if Scale.iscategorical(scales, :y) && (pad_categorical_y===missing || pad_categorical_y) ymin -= 0.5 ymax += 0.5 end diff --git a/src/geom/bar.jl b/src/geom/bar.jl index 3a7b5efc6..ad9d5e3fc 100644 --- a/src/geom/bar.jl +++ b/src/geom/bar.jl @@ -190,7 +190,7 @@ function render_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}(undef, 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]] @@ -220,7 +220,7 @@ function render_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}(undef, 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]] diff --git a/src/geom/beeswarm.jl b/src/geom/beeswarm.jl index f74066db4..797c3beb0 100644 --- a/src/geom/beeswarm.jl +++ b/src/geom/beeswarm.jl @@ -51,12 +51,12 @@ function render(geom::BeeswarmGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthet point_dist = (2*theme.point_size + geom.padding).value point_dist += eps(point_dist) - offsets = Array{Length{:mm}}(length(val)) - positions = Array{Compose.Measure}(length(val)) + offsets = Array{Length{:mm}}(undef, length(val)) + positions = Array{Compose.Measure}(undef, length(val)) n = length(val) - overlaps = Array{Bool}(n) - absvals = Array{Float64}(n) + overlaps = Array{Bool}(undef, n) + absvals = Array{Float64}(undef, n) for (i, v) in enumerate(val) absvals[i] = Compose.resolve_position( draw_context.box, diff --git a/src/geom/line.jl b/src/geom/line.jl index 63845b997..a0b435c45 100644 --- a/src/geom/line.jl +++ b/src/geom/line.jl @@ -142,9 +142,9 @@ function Gadfly.Geom.render(geom::LineGeometry, theme::Gadfly.Theme, aes::Gadfly ug = unique(groups) n = length(ug) - lines = Vector{Vector{Tuple{XT,YT}}}(n) - line_colors = Vector{CT}(n) - line_styles = Vector{LST}(n) + lines = Vector{Vector{Tuple{XT,YT}}}(undef, n) + line_colors = Vector{CT}(undef, n) + line_styles = Vector{LST}(undef, n) linestyle_palette_length = length(theme.line_style) for (k,g) in enumerate(ug) i = groups.==[g] diff --git a/src/geom/polygon.jl b/src/geom/polygon.jl index 47aaac300..a2c223ed4 100644 --- a/src/geom/polygon.jl +++ b/src/geom/polygon.jl @@ -46,7 +46,7 @@ function polygon_points(xs, ys, preserve_order) return T[(x, y) for (x, y) in zip(xs, ys)] else centroid_x, centroid_y = mean(xs), mean(ys) - θ = atan(xs - centroid_x, ys - centroid_y) + θ = atan.(xs - centroid_x, ys - centroid_y) perm = sortperm(θ) return T[(x, y) for (x, y) in zip(xs[perm], ys[perm])] end diff --git a/src/geom/rectbin.jl b/src/geom/rectbin.jl index 94869a5f7..9b64363ff 100644 --- a/src/geom/rectbin.jl +++ b/src/geom/rectbin.jl @@ -86,7 +86,7 @@ function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.A if length(aes.color) == n cs = aes.color else - cs = Array{RGBA{Float32}}(n) + cs = Array{RGBA{Float32}}(undef, n) for i in 1:n cs[i] = aes.color[((i - 1) % length(aes.color)) + 1] end diff --git a/src/geom/subplot.jl b/src/geom/subplot.jl index c73b9dab3..e21f87dc2 100644 --- a/src/geom/subplot.jl +++ b/src/geom/subplot.jl @@ -159,12 +159,12 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, end end - layer_aes_grid = Array{Matrix{Gadfly.Aesthetics}}(length(geom.layers)) + layer_aes_grid = Array{Matrix{Gadfly.Aesthetics}}(undef, length(geom.layers)) for (i, (layer, aes)) in enumerate(zip(geom.layers, subplot_layer_aess)) layer_aes_grid[i] = Gadfly.by_xy_group(aes, aes.xgroup, aes.ygroup, m, n) end - layer_data_grid = Array{Matrix{Gadfly.Data}}(length(geom.layers)) + layer_data_grid = Array{Matrix{Gadfly.Data}}(undef, length(geom.layers)) for (i, (layer, data, aes)) in enumerate(zip(geom.layers, subplot_layer_datas, subplot_layer_aess)) layer_data_grid[i] = Gadfly.by_xy_group(data, aes.xgroup, aes.ygroup, m, n) @@ -224,7 +224,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, Gadfly.inherit!(col_aes, geom_aes) Stat.apply_statistic(Stat.xticks(), scales, coord, col_aes) - aes_grid[:, j] = col_aes + aes_grid[:, j] .= col_aes end end @@ -349,7 +349,7 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme, # copy over the correct units, since we are reparenting the children for u in 1:size(subtbl, 1), v in 1:size(subtbl, 2) for child in subtbl[u, v] - if isnull(child.units) + if child.units===nothing child.units = subtbl.units end end diff --git a/src/guide.jl b/src/guide.jl index 77eb5938b..731b0a3c8 100644 --- a/src/guide.jl +++ b/src/guide.jl @@ -204,7 +204,7 @@ function render_discrete_color_key(colors::Vector{C}, # return a context with a lyout of numcols columns function make_layout(numcols) - colrows = Array{Int}(numcols) + colrows = Array{Int}(undef, numcols) m = n for i in 1:numcols colrows[i] = min(m, ceil(Integer, (n / numcols))) @@ -212,7 +212,7 @@ function render_discrete_color_key(colors::Vector{C}, end xpad = 1mm - colwidths = Array{Measure}(numcols) + colwidths = Array{Measure}(undef, numcols) m = 0 for (i, nrows) in enumerate(colrows) if m == n @@ -1164,8 +1164,8 @@ function layout_guides(plot_context::Context, aspect_ratio = nothing if isa(coord, Gadfly.Coord.cartesian) if coord.fixed - aspect_ratio = isnull(plot_context.units) ? 1.0 : - abs(get(plot_context.units).width / get(plot_context.units).height) + aspect_ratio = plot_context.units===nothing ? 1.0 : + abs(plot_context.units.width / plot_context.units.height) elseif coord.aspect_ratio != nothing aspect_ratio = coord.aspect_ratio end @@ -1176,8 +1176,8 @@ function layout_guides(plot_context::Context, i = 1 for (ctxs, order) in guides[top_guide_position] for ctx in ctxs - if isnull(ctx.units) && !isnull(plot_units) - ctx.units = UnitBox(get(plot_units), toppad=0mm, bottompad=0mm) + if ctx.units===nothing && plot_units!==nothing + ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1187,8 +1187,8 @@ function layout_guides(plot_context::Context, i += 1 for (ctxs, order) in guides[bottom_guide_position] for ctx in ctxs - if isnull(ctx.units) && !isnull(plot_units) - ctx.units = UnitBox(get(plot_units), toppad=0mm, bottompad=0mm) + if ctx.units===nothing && plot_units!==nothing + ctx.units = UnitBox(plot_units, toppad=0mm, bottompad=0mm) end end @@ -1199,8 +1199,8 @@ function layout_guides(plot_context::Context, j = 1 for (ctxs, order) in guides[left_guide_position] for ctx in ctxs - if isnull(ctx.units) && !isnull(plot_units) - ctx.units = UnitBox(get(plot_units), leftpad=0mm, rightpad=0mm) + if ctx.units===nothing && plot_units!==nothing + ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end @@ -1210,8 +1210,8 @@ function layout_guides(plot_context::Context, j += 1 for (ctxs, order) in guides[right_guide_position] for ctx in ctxs - if isnull(ctx.units) && !isnull(plot_units) - ctx.units = UnitBox(get(plot_units), leftpad=0mm, rightpad=0mm) + if ctx.units===nothing && plot_units!==nothing + ctx.units = UnitBox(plot_units, leftpad=0mm, rightpad=0mm) end end diff --git a/src/guide/keys.jl b/src/guide/keys.jl index 988050b0c..de1216994 100644 --- a/src/guide/keys.jl +++ b/src/guide/keys.jl @@ -30,7 +30,7 @@ function Guide.render(guide::Guide.ShapeKey, theme::Gadfly.Theme, aes::Gadfly.Ae gpos = guide.pos (theme.key_position == :inside) && (gpos == Float64[]) && (gpos = [0.7w, 0.25h]) - # Aesthetics for keys: shape_key_title, shape_label (Function), shape_key_shapes (Associative) + # Aesthetics for keys: shape_key_title, shape_label (Function), shape_key_shapes (AbstractDict) nshapes = length(unique(aes.shape)) guide_title = (guide.title!="Shape" || aes.shape_key_title==nothing) ? guide.title : aes.shape_key_title shape_key_labels = !(guide.labels==[""]) ? guide.labels : aes.shape_label(1:nshapes) @@ -88,7 +88,7 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w # return a context with a lyout of numcols columns function make_layout(numcols) - colrows = Array{Int}(numcols) + colrows = Array{Int}(undef, numcols) m = n for i in 1:numcols colrows[i] = min(m, ceil(Integer, (n / numcols))) @@ -96,7 +96,7 @@ function render_discrete_key(labels::Vector{String}, title_ctx::Context, title_w end xpad = 1mm - colwidths = Array{Measure}(numcols) + colwidths = Array{Measure}(undef, numcols) m = 0 for (i, nrows) in enumerate(colrows) if m == n diff --git a/src/mapping.jl b/src/mapping.jl index df105c5b1..c0aa21906 100644 --- a/src/mapping.jl +++ b/src/mapping.jl @@ -2,35 +2,34 @@ module Col using Compat using DataFrames -import IterTools import Base: == struct GroupedColumn - columns::Nullable{Vector} + columns::Union{Nothing,Vector} end Base.hash(colgroup::GroupedColumn, h::UInt64) = hash(colgroup.columns, h) function ==(a::GroupedColumn, b::GroupedColumn) - return (isnull(a.columns) && isnull(b.columns)) || - (!isnull(a.columns) && !isnull(b.columns) && get(a.columns) == get(b.columns)) + return (a.columns===nothing && b.columns===nothing) || + (a.columns!==nothing && b.columns!==nothing && a.columns == b.columns) end Base.show(io::IO, gc::GroupedColumn) = print(io, "Column") -index() = GroupedColumn(Nullable{Vector}()) +index() = GroupedColumn(nothing) -index(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumn(Nullable(collect(T, xs))) +index(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumn(collect(Union{Nothing,T}, xs)) struct GroupedColumnValue - columns::Nullable{Vector} + columns::Union{Nothing,Vector} end Base.show(io::IO, gc::GroupedColumnValue) = print(io, "Column Value") -value() = GroupedColumnValue(Nullable{Vector}()) +value() = GroupedColumnValue(nothing) -value(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumnValue(Nullable(collect(T, xs))) +value(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumnValue(collect(Union{Nothing,T}, xs)) end # module Col @@ -41,12 +40,12 @@ using Compat # represent a row index correspondig to a set of columns struct GroupedColumnRowIndex - columns::Nullable{Vector} + columns::Union{Nothing,Vector} end -index() = GroupedColumnRowIndex(Nullable{Vector}()) +index() = GroupedColumnRowIndex(nothing) -index(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumnRowIndex(Nullable(collect(T, xs))) +index(xs::T...) where {T <: (Union{Int, Symbol})} = GroupedColumnRowIndex(collect(Union{Nothing,T}, xs)) end # module Row @@ -99,17 +98,17 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) vm = um grouped_columns = Set{Symbol}() for colgroup in colgroups - if isnull(colgroup.columns) # null => group all columns + if colgroup.columns===nothing # null => group all columns vm *= un grouped_columns = copy(allcolumns) else - for j in get(colgroup.columns) + for j in colgroup.columns if !isa(j, Symbol) error("DataFrame columns can only be grouped by (Symbol) names") end push!(grouped_columns, j) end - vm *= length(get(colgroup.columns)) + vm *= length(colgroup.columns) end end @@ -122,7 +121,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) # allocate vectors for grouped columns for (j, colgroup) in enumerate(colgroups) - cols = isnull(colgroup.columns) ? allcolumns : get(colgroup.columns) + cols = colgroup.columns===nothing ? allcolumns : colgroup.columns # figure the grouped common column type firstcol = U[first(cols)] @@ -135,7 +134,7 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) end end - push!(V, eltyp == Vector ? Array{eltyp}(vm) : Array{Union{Missing,eltyp}}(vm)) + push!(V, eltyp == Vector ? Array{eltyp}(undef, vm) : Array{Union{Nothing,eltyp}}(undef, vm)) name = gensym() push!(vnames, name) colmap[colgroup] = j @@ -149,15 +148,15 @@ function meltdata(U::AbstractDataFrame, colgroups_::Vector{Col.GroupedColumn}) end # Indicator columns for each colgroup - col_indicators = Array{Symbol}(vm, length(colgroups)) - row_indicators = Array{Int}(vm, length(colgroups)) + col_indicators = Array{Symbol}(undef, vm, length(colgroups)) + row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [isnull(colgroup.columns) ? collect(allcolumns) : get(colgroup.columns) + colidxs = [colgroup.columns===nothing ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 for ui in 1:um - for colidx in IterTools.product(colidxs...) + for colidx in Iterators.product(colidxs...) # copy grouped columns for (vj, uj) in enumerate(colidx) V[vj][vi] = U[ui, uj] @@ -182,10 +181,10 @@ end function meltdata(U::AbstractVector, colgroups_::Vector{Col.GroupedColumn}) colgroups = Set(colgroups_) - if length(colgroups) != 1 || !isnull(first(colgroups).columns) + if length(colgroups) != 1 || first(colgroups).columns!==nothing # if every column is of the same length, treat it as a matrix if length(Set([length(u for u in U)])) == 1 - return meltdata(cat(2, U...), colgroups_) + return meltdata(cat(U..., dims=2), colgroups_) end # otherwise it doesn't make much sense @@ -195,9 +194,9 @@ function meltdata(U::AbstractVector, colgroups_::Vector{Col.GroupedColumn}) colmap = Dict{Any, Int}() colmap[colgroup] = 1 - V = cat(1, U...) - col_indicators = Array{Int}(length(V)) - row_indicators = Array{Int}(length(V)) + V = cat(U..., dims=1) + col_indicators = Array{Int}(undef, length(V)) + row_indicators = Array{Int}(undef, length(V)) k = 1 for i in 1:length(U) for j in 1:length(U[i]) @@ -217,22 +216,22 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) colgroups = Set(colgroups_) # Figure out the size of the new melted matrix - allcolumns = IntSet() + allcolumns = BitSet() for i in 1:un push!(allcolumns, i) end vm = um - grouped_columns = IntSet() + grouped_columns = BitSet() for colgroup in colgroups - if isnull(colgroup.columns) + if colgroup.columns===nothing vm *= un grouped_columns = copy(allcolumns) else - for j in get(colgroup.columns) + for j in colgroup.columns push!(grouped_columns, j) end - vm *= length(get(colgroup.columns)) + vm *= length(colgroup.columns) end end @@ -241,14 +240,14 @@ function meltdata(U::AbstractMatrix, colgroups_::Vector{Col.GroupedColumn}) V = similar(U, (vm, vn)) # Indicator columns for each colgroup - col_indicators = Array{Int}((vm, length(colgroups))) - row_indicators = Array{Int}((vm, length(colgroups))) + col_indicators = Array{Int}(undef, vm, length(colgroups)) + row_indicators = Array{Int}(undef, vm, length(colgroups)) - colidxs = [isnull(colgroup.columns) ? collect(allcolumns) : get(colgroup.columns) + colidxs = [colgroup.columns===nothing ? collect(allcolumns) : colgroup.columns for colgroup in colgroups] vi = 1 - for ui in 1:um, colidx in IterTools.product(colidxs...) + for ui in 1:um, colidx in Iterators.product(colidxs...) # copy grouped columns for (vj, uj) in enumerate(colidx) V[vi, vj] = U[ui, uj] diff --git a/src/misc.jl b/src/misc.jl index 5cbc19da7..70fc7cb36 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -71,7 +71,7 @@ end function concrete_length(xs::Array{Union{Missing,T}}) where T n = 0 for i = 1:length(xs) - if !xs.na[i] && isconcrete(xs.data[i]::T) + if !ismissing(xs[i]) && isconcrete(xs[i]) n += 1 end end @@ -87,7 +87,7 @@ function concrete_length(xs::Iterators.Flatten) end function concrete_minimum(xs) - if done(xs, start(xs)) + if isempty(xs) error("argument must not be empty") end @@ -109,7 +109,7 @@ end function concrete_maximum(xs) - if done(xs, start(xs)) + if isempty(xs) error("argument must not be empty") end @@ -152,8 +152,8 @@ end function concrete_minmax(xs::Array{Union{Missing,TA}}, xmin::T, xmax::T) where {T<:Real, TA} for i = 1:length(xs) - if !xs.na[i] - x = xs.data[i]::TA + if !ismissing(xs[i]) + x = xs[i] xT = convert(T, x) if isnan(xmin) || xT < xmin xmin = xT @@ -185,8 +185,8 @@ end function concrete_minmax(xs::Array{Union{Missing,TA}}, xmin::T, xmax::T) where {T, TA} for i = 1:length(xs) - if !xs.na[i] - x = xs.data[i]::TA + if !ismissing(xs[i]) + x = xs[i] xT = convert(T, x) if xT < xmin xmin = xT @@ -266,8 +266,8 @@ end # Remove any markup or whitespace from a string. function escape_id(s::AbstractString) - s = replace(s, r"<[^>]*>", "") - s = replace(s, r"\s", "_") + s = replace(s, r"<[^>]*>" => "") + s = replace(s, r"\s" => "_") s end @@ -404,7 +404,7 @@ discretize_make_ia(values::CategoricalArray) = discretize_make_ia(values, intersect(push!(levels(values), missing), unique(values))) discretize_make_ia(values::CategoricalArray, ::Nothing) = discretize_make_ia(values) function discretize_make_ia(values::CategoricalArray{T}, levels::Vector) where {T} - mapping = coalesce.(indexin(CategoricalArrays.index(values.pool), levels), 0) + mapping = Union{Nothing,Int}[coalesce.(indexin(CategoricalArrays.index(values.pool), levels), 0)...] pushfirst!(mapping, coalesce(findfirst(ismissing, levels), 0)) index = [mapping[x+1] for x in values.refs] any(iszero, index) && throw(ArgumentError("values not in levels encountered")) diff --git a/src/poetry.jl b/src/poetry.jl index b89fca040..65f571956 100644 --- a/src/poetry.jl +++ b/src/poetry.jl @@ -132,7 +132,6 @@ left blank, and an error is thrown if all elements of `M` are `NaN`. See [`Geom.rectbin`](@ref) and [`Coord.cartesian(fixed=true)...)`](@ref Gadfly.Coord.cartesian). """ - function spy(M::AbstractMatrix, elements::ElementOrFunction...; mapping...) is, js, values = _findnz(x->!isnan(x), M) n,m = size(M) @@ -160,7 +159,7 @@ function _findnz(testf::Function, A::AbstractMatrix{T}) where T N = Base.count(testf, A) is = zeros(Int, N) js = zeros(Int, N) - zs = Array{T}(N) + zs = Array{T}(undef, N) if N == 0 return (is, js, zs) end diff --git a/src/scale.jl b/src/scale.jl index c17939f3f..647bd6953 100644 --- a/src/scale.jl +++ b/src/scale.jl @@ -8,6 +8,7 @@ using Gadfly using Showoff using IndirectArrays using CategoricalArrays +using Printf import Gadfly: element_aesthetics, isconcrete, concrete_length, discretize_make_ia, aes2str import Distributions: Distribution @@ -197,7 +198,8 @@ function apply_scale(scale::ContinuousScale, T = Measure end - ds = any(ismissing, vals) ? Array{Union{Missing,T}}(length(vals)) : Array{T}(length(vals)) + ds = any(ismissing, vals) ? Array{Union{Missing,T}}(undef,length(vals)) : + Array{T}(undef,length(vals)) apply_scale_typed!(ds, vals, scale) if var == :xviewmin || var == :xviewmax || @@ -215,7 +217,7 @@ function apply_scale(scale::ContinuousScale, label_var = Symbol(var, "_label") end - if in(label_var, Set(fieldnames(aes))) + if in(label_var, Set(fieldnames(typeof(aes)))) setfield!(aes, label_var, make_labeler(scale)) end end @@ -361,7 +363,7 @@ function apply_scale(scale::DiscreteScale, aess::Vector{Gadfly.Aesthetics}, data labeler = explicit_labeler end - in(label_var, Set(fieldnames(aes))) && setfield!(aes, label_var, labeler) + in(label_var, Set(fieldnames(typeof(aes)))) && setfield!(aes, label_var, labeler) end end end @@ -635,7 +637,7 @@ function apply_scale(scale::ContinuousColorScale, for (aes, data) in zip(aess, datas) data.color === nothing && continue - aes.color = Array{RGB{Float32}}(length(data.color)) + aes.color = Array{RGB{Float32}}(undef, length(data.color)) apply_scale_typed!(aes.color, data.color, scale, cmin, cspan) color_key_colors = Dict{Color, Float64}() diff --git a/src/shapes.jl b/src/shapes.jl index 5eb039ce6..081e529f3 100755 --- a/src/shapes.jl +++ b/src/shapes.jl @@ -17,7 +17,7 @@ function square(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) s = 1/sqrt(2) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) @@ -37,7 +37,7 @@ $(shape_docstr("diamonds")) function diamond(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[1 + i % length(xs)]) y = y_measure(ys[1 + i % length(ys)]) @@ -55,7 +55,7 @@ $(shape_docstr("crosses")) """ function cross(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) y = y_measure(ys[mod1(i, length(ys))]) @@ -85,7 +85,7 @@ $(shape_docstr("rotated crosses")) """ function xcross(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) s = 1/sqrt(5) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) @@ -110,7 +110,7 @@ $(shape_docstr("upward-pointing triangles")) """ function utriangle(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray, scalar = 1) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) @@ -143,7 +143,7 @@ $(shape_docstr("five-pointed stars")) """ function star1(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray, scalar = 1) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) # some magic scalars sx = 0.7 @@ -172,7 +172,7 @@ $(shape_docstr("four-pointed stars")) """ function star2(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray, scalar = 1) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) y = y_measure(ys[mod1(i, length(ys))]) @@ -197,7 +197,7 @@ $(shape_docstr("hexagons")) function hexagon(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) y = y_measure(ys[mod1(i, length(ys))]) @@ -223,7 +223,7 @@ $(shape_docstr("octagons")) function octagon(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - polys = Vector{Vector{Tuple{Measure, Measure}}}(n) + polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, n) for i in 1:n x = x_measure(xs[mod1(i, length(xs))]) y = y_measure(ys[mod1(i, length(ys))]) @@ -249,7 +249,7 @@ $(shape_docstr("horizontal lines")) function hline(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - line_ps = Vector{Vector{Tuple{Measure,Measure}}}(n) + line_ps = Vector{Vector{Tuple{Measure,Measure}}}(undef, n) for i in 1:n x = x_measure(xs[1 + i % length(xs)]) y = y_measure(ys[1 + i % length(ys)]) @@ -268,7 +268,7 @@ $(shape_docstr("vertical lines")) function vline(xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) n = max(length(xs), length(ys), length(rs)) - line_ps = Vector{Vector{Tuple{Measure,Measure}}}(n) + line_ps = Vector{Vector{Tuple{Measure,Measure}}}(undef, n) for i in 1:n x = x_measure(xs[1 + i % length(xs)]) y = y_measure(ys[1 + i % length(ys)]) diff --git a/src/statistics.jl b/src/statistics.jl index e115d0c64..a0a1ee71b 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -1,17 +1,20 @@ module Stat import Gadfly -import StatsBase import Contour using Colors using Compat using Compose using DataStructures +using Dates using Distributions using Hexagons using Loess using CoupledFields # It is registered in METADATA.jl using IndirectArrays +using Statistics +using LinearAlgebra +using Random import Gadfly: Scale, Coord, input_aesthetics, output_aesthetics, default_scales, isconcrete, setfield!, discretize_make_ia, aes2str @@ -73,8 +76,8 @@ function barminmax(vals, iscontinuous::Bool) barspan = minspan end position_type = promote_type(typeof(barspan/2.0), eltype(vals)) - minvals = Array{position_type}(length(vals)) - maxvals = Array{position_type}(length(vals)) + minvals = Array{position_type}(undef, length(vals)) + maxvals = Array{position_type}(undef, length(vals)) for (i, x) in enumerate(vals) minvals[i] = x - barspan/2.0 @@ -116,10 +119,10 @@ function apply_statistic(stat::RectbinStatistic, aes.ymax = ymaxvals if !isxcontinuous - aes.pad_categorical_x = Nullable(false) + aes.pad_categorical_x = false end if !isycontinuous - aes.pad_categorical_y = Nullable(false) + aes.pad_categorical_y = false end end @@ -222,9 +225,9 @@ function apply_statistic(stat::BarStatistic, if !iscontinuous if stat.orientation == :horizontal - aes.pad_categorical_y = Nullable(false) + aes.pad_categorical_y = false else - aes.pad_categorical_x = Nullable(false) + aes.pad_categorical_x = false end end end @@ -341,10 +344,10 @@ function apply_statistic(stat::HistogramStatistic, if aes.color === nothing T = typeof(x_min + 1*binwidth) - setfield!(aes, othervar, Array{Float64}(d)) - setfield!(aes, minvar, Array{T}(d)) - setfield!(aes, maxvar, Array{T}(d)) - setfield!(aes, var, Array{T}(d)) + setfield!(aes, othervar, Array{Float64}(undef, d)) + setfield!(aes, minvar, Array{T}(undef, d)) + setfield!(aes, maxvar, Array{T}(undef, d)) + setfield!(aes, var, Array{T}(undef, d)) for j in 1:d getfield(aes, minvar)[j] = x_min + (j - 1) * binwidth getfield(aes, maxvar)[j] = x_min + j * binwidth @@ -363,12 +366,12 @@ function apply_statistic(stat::HistogramStatistic, end end T = typeof(x_min + 1*binwidth) - setfield!(aes, minvar, Array{T}(d * length(groups))) - setfield!(aes, maxvar, Array{T}(d * length(groups))) - setfield!(aes, var, Array{T}(d * length(groups))) + setfield!(aes, minvar, Array{T}(undef, d * length(groups))) + setfield!(aes, maxvar, Array{T}(undef, d * length(groups))) + setfield!(aes, var, Array{T}(undef, d * length(groups))) - setfield!(aes, othervar, Array{Float64}(d * length(groups))) - colors = Array{RGB{Float32}}(d * length(groups)) + setfield!(aes, othervar, Array{Float64}(undef, d * length(groups))) + colors = Array{RGB{Float32}}(undef, d * length(groups)) x_span = x_max - x_min stack_height = zeros(Int, d) @@ -651,17 +654,17 @@ function apply_statistic(stat::Histogram2DStatistic, end if x_categorial - aes.x = Array{Int64}(n) + aes.x = Array{Int64}(undef, n) else - aes.xmin = Array{Float64}(n) - aes.xmax = Array{Float64}(n) + aes.xmin = Array{Float64}(undef, n) + aes.xmax = Array{Float64}(undef, n) end if y_categorial - aes.y = Array{Int64}(n) + aes.y = Array{Int64}(undef, n) else - aes.ymin = Array{Float64}(n) - aes.ymax = Array{Float64}(n) + aes.ymin = Array{Float64}(undef, n) + aes.ymax = Array{Float64}(undef, n) end k = 1 @@ -694,7 +697,7 @@ function apply_statistic(stat::Histogram2DStatistic, aes.color_key_title = "Count" data = Gadfly.Data() - data.color = Array{Int}(n) + data.color = Array{Int}(undef, n) k = 1 for cnt in transpose(bincounts) if cnt > 0 @@ -706,13 +709,13 @@ function apply_statistic(stat::Histogram2DStatistic, if x_categorial aes.xmin, aes.xmax = barminmax(aes.x, false) aes.x = discretize_make_ia(aes.x) - aes.pad_categorical_x = Nullable(false) + aes.pad_categorical_x = false end if y_categorial aes.ymin, aes.ymax = barminmax(aes.y, false) aes.y = discretize_make_ia(aes.y) - aes.pad_categorical_y = Nullable(false) + aes.pad_categorical_y = false end Scale.apply_scale(color_scale, [aes], data) @@ -908,8 +911,8 @@ function apply_statistic(stat::TickStatistic, multiticks = Gadfly.multilevel_ticks(viewmin - (viewmax - viewmin), viewmax + (viewmax - viewmin)) tickcount = length(ticks) + sum([length(ts) for ts in values(multiticks)]) - tickvisible = Array{Bool}(tickcount) - tickscale = Array{Float64}(tickcount) + tickvisible = Array{Bool}(undef, tickcount) + tickscale = Array{Float64}(undef, tickcount) i = 1 for t in ticks tickscale[i] = 1.0 @@ -967,9 +970,9 @@ function apply_statistic_typed(minval::T, maxval::T, vals::Array{Union{Missing,T lensize = length(size) lendsize = length(dsize) for i = 1:length(vals) - vals.na[i] && continue + ismissing(vals[i]) && continue - val::T = vals.data[i] + val = vals[i] s = size[mod1(i, lensize)] ds = dsize[mod1(i, lendsize)] @@ -1063,12 +1066,12 @@ function apply_statistic(stat::BoxplotStatistic, end m = length(groups) - aes.x = Array{eltype(aes.x)}(m) - aes.middle = Array{T}(m) - aes.lower_hinge = Array{T}(m) - aes.upper_hinge = Array{T}(m) - aes.lower_fence = Array{T}(m) - aes.upper_fence = Array{T}(m) + aes.x = Array{eltype(aes.x)}(undef, m) + aes.middle = Array{T}(undef, m) + aes.lower_hinge = Array{T}(undef, m) + aes.upper_hinge = Array{T}(undef, m) + aes.lower_fence = Array{T}(undef, m) + aes.upper_fence = Array{T}(undef, m) aes.outliers = Vector{T}[] for (i, ((x, c), ys)) in enumerate(groups) @@ -1207,7 +1210,7 @@ function apply_statistic(stat::SmoothStatistic, if stat.method == :loess smoothys = Loess.predict(loess(xs, ys, span=stat.smoothing), xsp) elseif stat.method == :lm - lmcoeff = linreg(xs,ys) + lmcoeff = reverse([xs ones(length(xs))] \ ys) smoothys = lmcoeff[2].*xsp .+ lmcoeff[1] end @@ -1267,10 +1270,10 @@ function apply_statistic(stat::HexBinStatistic, end N = length(counts) - aes.x = Array{Float64}(N) - aes.y = Array{Float64}(N) + aes.x = Array{Float64}(undef, N) + aes.y = Array{Float64}(undef, N) data = Gadfly.Data() - data.color = Array{Int}(N) + data.color = Array{Int}(undef, N) k = 1 for (idx, cnt) in counts x, y = center(HexagonOffsetOddR(idx[1], idx[2]), xsize, ysize, @@ -1409,8 +1412,8 @@ function apply_statistic(stat::FunctionStatistic, Gadfly.assert_aesthetics_defined("FunctionStatistic", aes, :xmax) Gadfly.assert_aesthetics_equal_length("FunctionStatistic", aes, :xmin, :xmax) - aes.x = Array{Float64}(length(aes.y) * stat.num_samples) - ys = Array{Float64}(length(aes.y) * stat.num_samples) + aes.x = Array{Float64}(undef, length(aes.y) * stat.num_samples) + ys = Array{Float64}(undef, length(aes.y) * stat.num_samples) i = 1 for (f, xmin, xmax) in zip(aes.y, cycle(aes.xmin), cycle(aes.xmax)) @@ -1424,21 +1427,21 @@ function apply_statistic(stat::FunctionStatistic, # color was bound explicitly if aes.color != nothing func_color = aes.color - aes.color = Array{eltype(aes.color)}(length(aes.y) * stat.num_samples) - groups = Array{Union{Missing,Int}}(length(aes.y) * stat.num_samples) + aes.color = Array{eltype(aes.color)}(undef, length(aes.y) * stat.num_samples) + groups = Array{Union{Missing,Int}}(undef, length(aes.y) * stat.num_samples) for i in 1:length(aes.y) - aes.color[1+(i-1)*stat.num_samples:i*stat.num_samples] = func_color[i] - groups[1+(i-1)*stat.num_samples:i*stat.num_samples] = i + aes.color[1+(i-1)*stat.num_samples:i*stat.num_samples] .= func_color[i] + groups[1+(i-1)*stat.num_samples:i*stat.num_samples] .= i end aes.group = discretize_make_ia(groups) elseif length(aes.y) > 1 && haskey(scales, :color) data = Gadfly.Data() - data.color = Array{AbstractString}(length(aes.y) * stat.num_samples) - groups = Array{Union{Missing,Int}}(length(aes.y) * stat.num_samples) + data.color = Array{AbstractString}(undef, length(aes.y) * stat.num_samples) + groups = Array{Union{Missing,Int}}(undef, length(aes.y) * stat.num_samples) for i in 1:length(aes.y) fname = "f$(i)" - data.color[1+(i-1)*stat.num_samples:i*stat.num_samples] = fname - groups[1+(i-1)*stat.num_samples:i*stat.num_samples] = i + data.color[1+(i-1)*stat.num_samples:i*stat.num_samples] .= fname + groups[1+(i-1)*stat.num_samples:i*stat.num_samples] .= i end Scale.apply_scale(scales[:color], [aes], data) aes.group = discretize_make_ia(groups) @@ -1513,7 +1516,7 @@ function apply_statistic(stat::ContourStatistic, as = sortslices(a, dims=1, by=x->(x[2],x[1])) xs = unique(as[:,1]) ys = unique(as[:,2]) - zs = Array{Float64}(length(xs), length(ys)) + zs = Array{Float64}(undef, length(xs), length(ys)) zs[:,:] = as[:,3] else error("Stat.contour requires either a matrix, function or dataframe") @@ -1736,8 +1739,8 @@ function apply_statistic(stat::JitterStatistic, rng = MersenneTwister(stat.seed) for var in stat.vars data = getfield(aes, var) - outdata = Array{Float64}(size(data)) - broadcast!(+, outdata, data, stat.range * (rand(rng, length(data)) - 0.5) .* span) + outdata = Array{Float64}(undef, size(data)) + broadcast!(+, outdata, data, stat.range * (rand(rng, length(data)) .- 0.5) .* span) setfield!(aes, var, outdata) end end @@ -2020,7 +2023,7 @@ function Gadfly.Stat.apply_statistic(stat::EllipseStatistic, for (g, data) in grouped_xy dfd = size(data,1)-1 dhat = fit(stat.distribution, data') - Σ½ = chol(cov(dhat)) + Σ½ = cholesky(cov(dhat)).U rv = sqrt.(dfn*[quantile(FDist(dfn,dfd), p) for p in stat.levels]) ellxy = [cos.(θ) sin.(θ)] * Σ½ μ = mean(dhat) diff --git a/src/theme.jl b/src/theme.jl index 936f8b8a0..67c10d0d6 100755 --- a/src/theme.jl +++ b/src/theme.jl @@ -44,7 +44,7 @@ end default_middle_color(fill_color::TransparentColor) = RGBA{Float32}( default_middle_color(color(fill_color)), fill_color.alpha) -get_stroke_vector(::Void) = [] +get_stroke_vector(::Nothing) = [] get_stroke_vector(vec::AbstractVector) = vec function get_stroke_vector(linestyle::Symbol) ldash = 6 * Compose.mm @@ -206,7 +206,7 @@ $(FIELDS) key_position, Symbol, :right "Color used to stroke bars in bar plots. If a function is given, it's used to transform the fill color of the bars to obtain a stroke color. (Function, Color, or Nothing)", - bar_highlight, Union{(Void), Function, Color}, nothing + bar_highlight, Union{Nothing, Function, Color}, nothing rug_size, Measure, 2.0mm diff --git a/src/ticks.jl b/src/ticks.jl index 36dffa85f..3eee01765 100644 --- a/src/ticks.jl +++ b/src/ticks.jl @@ -145,13 +145,13 @@ function optimize_ticks_typed(x_min::T, x_max::T, extend_ticks, span = q_best * 10.0^z_best * one_t if extend_ticks - S = Array{typeof(1.0 * one_t)}(Int(3 * k_best)) + S = Array{typeof(1.0 * one_t)}(undef, Int(3 * k_best)) for i in 0:(3*k_best - 1) S[i+1] = (r_best + i - k_best) * span end viewmin, viewmax = S[k_best + 1], S[2 * k_best] else - S = Array{typeof(1.0 * one_t)}(k_best) + S = Array{typeof(1.0 * one_t)}(undef, k_best) for i in 0:(k_best - 1) S[i+1] = (r_best + i) * span end diff --git a/src/varset.jl b/src/varset.jl index b4d017c47..7773a18ce 100644 --- a/src/varset.jl +++ b/src/varset.jl @@ -17,7 +17,7 @@ macro varset(name::Symbol, table) inherit_parameters_expr = Expr(:parameters) for row in table - isa(row, Expr) && row.head == :line && continue + isa(row, LineNumberNode) && continue hasdocstr = false if isa(row, Symbol) diff --git a/test/runtests.jl b/test/runtests.jl index b087661c1..96561ba4a 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,9 +5,9 @@ if haskey(ENV, "GADFLY_THEME") pop!(ENV, "GADFLY_THEME") end -using Test, Gadfly, Compat +using Test, Gadfly, Compat, LibGit2, Dates, Random, Compose, Cairo, Fontconfig -repo = LibGit2.GitRepo(dirname(@__DIR__)) +repo = GitRepo(dirname(@__DIR__)) branch = LibGit2.headname(repo) outputdir = joinpath(@__DIR__, mapreduce(x->startswith(branch,x), |, ["master","(detac"]) ? "master-output" : "devel-output") @@ -30,7 +30,7 @@ function mimic_git_log_n1(io::IO, head) commit = LibGit2.GitCommit(repo, hash) author = LibGit2.author(commit) println(io, "Author: ",author.name," <",author.email,">") - datetime = Dates.unix2datetime(author.time + 60*author.time_offset) + datetime = unix2datetime(author.time + 60*author.time_offset) println(io, "Date: ",Dates.format(datetime, "e u d HH:MM:SS YYYY")) println(io, " ",LibGit2.message(commit)) end @@ -74,7 +74,7 @@ testfiles = isempty(ARGS) ? @testset "Gadfly" begin for filename in testfiles, (backend_name, backend) in backends - info(filename,'.',backend_name) + @info string(filename,'.',backend_name) Random.seed!(1) p = evalfile(joinpath(testdir, "$(filename).jl")) @test typeof(p) in [Plot,Compose.Context] diff --git a/test/testscripts/Guide_colorkey.jl b/test/testscripts/Guide_colorkey.jl index 134cd10e9..d4e7e5455 100644 --- a/test/testscripts/Guide_colorkey.jl +++ b/test/testscripts/Guide_colorkey.jl @@ -1,4 +1,4 @@ -using Compose, Gadfly +using Compose, Gadfly, Random set_default_plot_size(6inch, 3inch) diff --git a/test/testscripts/Guide_shapekey.jl b/test/testscripts/Guide_shapekey.jl index 7e17f5343..6850ea27b 100644 --- a/test/testscripts/Guide_shapekey.jl +++ b/test/testscripts/Guide_shapekey.jl @@ -1,4 +1,4 @@ -using Compose, DataFrames, Gadfly +using Compose, DataFrames, Gadfly, Random set_default_plot_size(9inch, 3.3inch) diff --git a/test/testscripts/boxplot_no_aesy.jl b/test/testscripts/boxplot_no_aesy.jl index bd439a688..3b7985088 100644 --- a/test/testscripts/boxplot_no_aesy.jl +++ b/test/testscripts/boxplot_no_aesy.jl @@ -1,11 +1,11 @@ using Gadfly, DataFrames x = collect(11:20) -a = x.*3+4 -b = a-1 -c = a-2 -d = a-3 +a = x .* 3 .+ 4 +b = a .- 1 +c = a .- 2 +d = a .- 3 -df = DataFrame(x = x,a=a,b=b,c=c,d=d,s = repmat(["A"],10)) +df = DataFrame(x=x, a=a, b=b, c=c, d=d, s=repeat(["A"],inner=10)) plot(df, x="x", upper_fence="a", upper_hinge="b", lower_hinge="c", lower_fence="d", Geom.boxplot) diff --git a/test/testscripts/colored_smooth_lm.jl b/test/testscripts/colored_smooth_lm.jl index db35550b9..987270c10 100644 --- a/test/testscripts/colored_smooth_lm.jl +++ b/test/testscripts/colored_smooth_lm.jl @@ -3,9 +3,9 @@ using Gadfly set_default_plot_size(6inch, 8inch) x1 = rand(40) -y1 = 4.*x1 .+ 2 .+randn(40) +y1 = 4 .* x1 .+ 2 .+ randn(40) x2 = rand(40) -y2 = -6.*x2 .+ 3 .+ randn(40) +y2 = -6 .* x2 .+ 3 .+ randn(40) x = [x1;x2] y = [y1;y2] col = [fill("Slope 4",40); fill("Slope -6",40)] diff --git a/test/testscripts/density_dark.jl b/test/testscripts/density_dark.jl index bb3a94de6..52643c395 100644 --- a/test/testscripts/density_dark.jl +++ b/test/testscripts/density_dark.jl @@ -1,4 +1,4 @@ -using Gadfly, RDatasets, Distributions, Test +using Gadfly, RDatasets, Distributions, Test, Base64 set_default_plot_size(6inch, 3inch) @@ -9,18 +9,18 @@ p = Gadfly.with_theme(:dark) do end # prevent these tests from running more than once -if !isdefined(:density_dark_tested) +if ! @isdefined density_dark_tested svg_str_dark = stringmime(MIME("image/svg+xml"), p) - @test contains(svg_str_dark, hex(Gadfly.dark_theme.default_color)) - @test contains(svg_str_dark, hex(Gadfly.dark_theme.background_color)) - @test contains(svg_str_dark, hex(Gadfly.dark_theme.panel_fill)) + @test occursin(hex(Gadfly.dark_theme.default_color), svg_str_dark) + @test occursin(hex(Gadfly.dark_theme.background_color), svg_str_dark) + @test occursin(hex(Gadfly.dark_theme.panel_fill), svg_str_dark) # Test reset. p2 = plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut", Geom.density) svg_str_light = stringmime(MIME("image/svg+xml"), p2) - @test !contains(svg_str_light, hex(Gadfly.dark_theme.default_color)) - @test !contains(svg_str_light, hex(Gadfly.dark_theme.background_color)) - @test !contains(svg_str_light, hex(Gadfly.dark_theme.panel_fill)) + @test !occursin(hex(Gadfly.dark_theme.default_color), svg_str_light) + @test !occursin(hex(Gadfly.dark_theme.background_color), svg_str_light) + @test !occursin(hex(Gadfly.dark_theme.panel_fill), svg_str_light) density_dark_tested=true end diff --git a/test/testscripts/ellipse.jl b/test/testscripts/ellipse.jl index 494a57c43..28535ffb8 100644 --- a/test/testscripts/ellipse.jl +++ b/test/testscripts/ellipse.jl @@ -1,4 +1,4 @@ -using Distributions, Gadfly +using Distributions, Gadfly, Random set_default_plot_size(6.6inch, 3.3inch) Random.seed!(123) @@ -6,4 +6,4 @@ d = rand(MvNormal([2, 2],[1.0 0.7; 0.7 1.0]), 50)' pa= plot(x=d[:,1], y=d[:,2], Geom.point, layer(Stat.ellipse, Geom.polygon(preserve_order=true))) pb= plot(x=d[:,1], y=d[:,2], Geom.point, Geom.ellipse(levels=[0.95, 0.99])) -hstack(pa,pb) \ No newline at end of file +hstack(pa,pb) diff --git a/test/testscripts/issue177.jl b/test/testscripts/issue177.jl index 25dfa88c3..1504bec14 100644 --- a/test/testscripts/issue177.jl +++ b/test/testscripts/issue177.jl @@ -14,8 +14,8 @@ x = [2400:1:2500;] WiFiPlots = [2.0 * gaussian(ix, iy, 40.0) for ix=x, iy=WiFiFreqs] -BLEValues = [ ((findfirst(BLEFreqs, ix) > 0) ? 0.127 : 0/0) for ix=x] -BLEChannels = [findfirst(BLEFreqs, ix) for ix=x] +BLEValues = [ (findfirst(isequal(ix), BLEFreqs) !== nothing ? 0.127 : 0/0) for ix=x] +BLEChannels = [something(findfirst(isequal(ix), BLEFreqs),0) for ix=x] BLEChannelStrs = [(ix < 10) ? "0$ix" : "$ix" for ix=BLEChannels] df = DataFrame(frequency=x, value=BLEValues, channel=BLEChannels) diff --git a/test/testscripts/issue961.jl b/test/testscripts/issue961.jl index f60f1e7bc..82acfacb2 100644 --- a/test/testscripts/issue961.jl +++ b/test/testscripts/issue961.jl @@ -1,8 +1,8 @@ -using Gadfly, RDatasets +using Gadfly, RDatasets, Dates day = collect(Date("1960-01-01"):Dates.Day(1):Date("1999-12-31")) t = Dates.value.(day) w = 2π/365.25 -D1 = DataFrame(Day=day, y=2*rand(length(day)).*(1+sin.(w*t))) +D1 = DataFrame(Day=day, y=2*rand(length(day)) .* (1 .+ sin.(w*t))) hline = Geom.hline(color="red") plot(D1, x=:Day, y=:y, yintercept=[3.9], Geom.line, hline) diff --git a/test/testscripts/issue975.jl b/test/testscripts/issue975.jl index 19809ea3d..0253790e0 100644 --- a/test/testscripts/issue975.jl +++ b/test/testscripts/issue975.jl @@ -1,4 +1,4 @@ -using DataFrames, Gadfly +using DataFrames, Gadfly, Dates set_default_plot_size(6inch, 3inch) diff --git a/test/testscripts/line_linestyle.jl b/test/testscripts/line_linestyle.jl index 7b0b7221c..327204b85 100644 --- a/test/testscripts/line_linestyle.jl +++ b/test/testscripts/line_linestyle.jl @@ -3,7 +3,7 @@ using StatsBase: winsor set_default_plot_size(6inch, 3inch) labs = [ "exp", "sqrt", "log", "winsor", "linear"] -funcs = [ x->60*(1-exp.(-0.2*x)), x->sqrt.(x)*10, x->log.(x)*10, x->winsor(x, prop=0.15), x->x*0.6 ] +funcs = [ x->60*(1 .- exp.(-0.2*x)), x->sqrt.(x)*10, x->log.(x)*10, x->winsor(x, prop=0.15), x->x*0.6 ] x = [1.0:30;] D = vcat([DataFrame(x=x, y=f(x), linev=l) for (f,l) in zip(funcs, labs)]...) diff --git a/test/testscripts/log10_scale_range.jl b/test/testscripts/log10_scale_range.jl index 3bc9d4be4..66b4c61bc 100644 --- a/test/testscripts/log10_scale_range.jl +++ b/test/testscripts/log10_scale_range.jl @@ -3,6 +3,6 @@ using Gadfly set_default_plot_size(6inch, 3inch) n = 10 -plot(x=1+rand(n), y=1+rand(n), +plot(x=1 .+ rand(n), y=1 .+ rand(n), Scale.x_log10(minvalue=1.0, maxvalue=10), Scale.y_log10(minvalue=1.0, maxvalue=10)) diff --git a/test/testscripts/matrix_lines.jl b/test/testscripts/matrix_lines.jl index dda92b8cc..fec2833cb 100644 --- a/test/testscripts/matrix_lines.jl +++ b/test/testscripts/matrix_lines.jl @@ -1,4 +1,4 @@ -using Gadfly +using Gadfly, LinearAlgebra # wide-form plotting of matrices @@ -6,6 +6,6 @@ set_default_plot_size(6inch, 4inch) n = 20 m = 40 -X = randn(m, n) * diagm(1:n) +X = randn(m, n) * Matrix(Diagonal(1:n)) plot(X, x=Row.index, y=Col.value, color=Col.index, Geom.line) diff --git a/test/testscripts/scale_color_log.jl b/test/testscripts/scale_color_log.jl index 7b578d40c..b4749ca0f 100644 --- a/test/testscripts/scale_color_log.jl +++ b/test/testscripts/scale_color_log.jl @@ -3,5 +3,5 @@ using Gadfly set_default_plot_size(6inch, 3inch) n = 10 -plot(x=rand(n), y=rand(n), color=e.^rand(n), +plot(x=rand(n), y=rand(n), color=ℯ.^rand(n), Scale.color_log(minvalue=1)) diff --git a/test/testscripts/scale_color_log10.jl b/test/testscripts/scale_color_log10.jl index 4e1ff76d6..7cec2d84b 100644 --- a/test/testscripts/scale_color_log10.jl +++ b/test/testscripts/scale_color_log10.jl @@ -3,5 +3,5 @@ using Gadfly set_default_plot_size(6inch, 3inch) n = 10 -plot(x=rand(n), y=rand(n), color=1000.^rand(n), +plot(x=rand(n), y=rand(n), color=1000 .^ rand(n), Scale.color_log10(minvalue=1, maxvalue=1e3)) diff --git a/test/testscripts/scale_color_log2.jl b/test/testscripts/scale_color_log2.jl index aafc58d7d..928649d45 100644 --- a/test/testscripts/scale_color_log2.jl +++ b/test/testscripts/scale_color_log2.jl @@ -3,5 +3,5 @@ using Gadfly set_default_plot_size(6inch, 3inch) n = 10 -plot(x=rand(n), y=rand(n), color=8.^rand(n), +plot(x=rand(n), y=rand(n), color=8 .^ rand(n), Scale.color_log2(minvalue=1, maxvalue=8)) diff --git a/test/testscripts/smooth_lm.jl b/test/testscripts/smooth_lm.jl index a96faa89f..d37cf63d3 100644 --- a/test/testscripts/smooth_lm.jl +++ b/test/testscripts/smooth_lm.jl @@ -3,7 +3,7 @@ using Gadfly set_default_plot_size(6inch, 8inch) x = rand(40) -y = 4.*x .+ 2 .+randn(40) +y = 4 .* x .+ 2 .+ randn(40) plot(x=x,y=y, Geom.point, Geom.smooth(method=:lm)) diff --git a/test/testscripts/stat_qq.jl b/test/testscripts/stat_qq.jl index 93775e87d..cd5e40383 100644 --- a/test/testscripts/stat_qq.jl +++ b/test/testscripts/stat_qq.jl @@ -1,4 +1,4 @@ -using Gadfly, Distributions +using Gadfly, Distributions, Random set_default_plot_size(6inch, 16inch) diff --git a/test/testscripts/static_label_layout.jl b/test/testscripts/static_label_layout.jl index a18bb04cc..081c3f41c 100644 --- a/test/testscripts/static_label_layout.jl +++ b/test/testscripts/static_label_layout.jl @@ -1,4 +1,4 @@ -using Gadfly +using Gadfly, Random set_default_plot_size(6inch, 16inch) diff --git a/test/testscripts/timeseries_year_2.jl b/test/testscripts/timeseries_year_2.jl index 2a459eb9e..e0341201a 100644 --- a/test/testscripts/timeseries_year_2.jl +++ b/test/testscripts/timeseries_year_2.jl @@ -3,11 +3,4 @@ using Gadfly, RDatasets, Dates set_default_plot_size(6inch, 3inch) economics = dataset("HistData", "Prostitutes") - -if Pkg.installed("RData") < v"0.4.0" - # NOTE: I know these aren't unix times, but I'm not sure what they are, and this - # is just a test so it doesn't matter. - economics[:Date] = DateTime[unix2datetime(d) for d in economics[:Date]] -end - p = plot(economics, x=:Date, y=:Count, Geom.line) diff --git a/test/testscripts/vector.jl b/test/testscripts/vector.jl index 0ce541e7e..72f53a1c0 100644 --- a/test/testscripts/vector.jl +++ b/test/testscripts/vector.jl @@ -1,9 +1,9 @@ -using DataFrames, Gadfly +using DataFrames, Gadfly, Random set_default_plot_size(2*3.3inch, 2*3.3inch) Random.seed!(123) -D = convert(DataFrame, 99*rand(4, 4)+0.5) +D = convert(DataFrame, 99 * rand(4,4) .+ 0.5) xsc = Scale.x_continuous(minvalue=0.0, maxvalue=100) ysc = Scale.y_continuous(minvalue=0.0, maxvalue=100) @@ -19,7 +19,7 @@ p3 = plot(z=(x,y)->x*exp(-(x^2+y^2)), Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(title="z")); Z = fill(1.0, 5, 5) -Z[2:4, 2:4] = 2.0 +Z[2:4, 2:4] .= 2.0 Z[3,3] = 3.0 p4 = plot(z=Z,