Skip to content

Commit

Permalink
DataFrames.jl is loaded dynamically.
Browse files Browse the repository at this point in the history
Since the package is only needed to implement wrappers around the actual functions, there's no immediate drawback of loading it dynamically; any user will only need the wrappers after loading DataFrames, too. Perfect use case for Requires.jl.
  • Loading branch information
mirkobunse committed Aug 16, 2020
1 parent 44ce4ad commit fe1a2e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"

[compat]
Contour = "0.5"
ColorBrewer = "0.4"
Colors = "0.12"
ColorSchemes = "3.9"
Colors = "0.12"
Contour = "0.5"
DataFrames = "0.21"
Discretizers = "3.2"
ImageMagick = "0.7.3, 1"
Expand Down
15 changes: 6 additions & 9 deletions src/PGFPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ export pushPGFPlots, popPGFPlots
import Colors: RGB
import Contour: contours, levels

using Requires
using Discretizers
using DataFrames
using Printf

# load dynamic dependencies
function __init__()
@require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" include("dataframes.jl")
end

mutable struct ErrorBars
data::AbstractMatrix{Real}
style
Expand Down Expand Up @@ -42,14 +47,6 @@ end
include("colormaps.jl")
include("plots.jl")

Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Linear(df[!,x], df[!,y]; kwargs...)
Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) = Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...)
Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) = Plots.Histogram(df[!,x]; kwargs...)
Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Scatter(df[!,x], df[!,y]; kwargs...)
Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) = Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...)
Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...)
Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...)

import TikzPictures: TikzPicture, PDF, TEX, TIKZ, SVG, save, LaTeXString, @L_str, @L_mstr

_pgfplotsoptions = Any[""]
Expand Down
22 changes: 22 additions & 0 deletions src/dataframes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using DataFrames

Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Linear(df[!,x], df[!,y]; kwargs...)

Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) =
Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...)

Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) =
Plots.Histogram(df[!,x]; kwargs...)

Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Scatter(df[!,x], df[!,y]; kwargs...)

Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) =
Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...)

Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) =
Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...)

Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} =
Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...)

0 comments on commit fe1a2e4

Please sign in to comment.