-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break out aes operators into separate file, fix mistakes in subtract …
…and divide implementations
- Loading branch information
Showing
5 changed files
with
140 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "TidierPlots" | ||
uuid = "337ecbd1-5042-4e2a-ae6f-ca776f97570a" | ||
authors = ["Randall Boyes <[email protected]> and contributors"] | ||
version = "0.6.3" | ||
version = "0.6.4" | ||
|
||
[deps] | ||
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import Base.:>> | ||
|
||
Base.:>>(sym::Symbol, fn::Function) = aesthetics_function(fn)(sym) | ||
|
||
# 'rithm'tic (dubious implementation) | ||
|
||
import Base.:+ | ||
|
||
function add_cols_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] .+ data[!, source[2]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, | ||
identity, | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
|
||
function make_add_const_function(constant::Real) | ||
return function add_const_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] .+ constant | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, # get the column out of the dataframe | ||
identity, # apply generic_fn to it | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
end | ||
|
||
Base.:+(s1::Symbol, s2::Symbol) = [s1, s2] => AesTransform(add_cols_fn) | ||
Base.:+(s1::Symbol, s2::Real) = [s1] => AesTransform(make_add_const_function(s2)) | ||
Base.:+(s2::Real, s1::Symbol) = [s1] => AesTransform(make_add_const_function(s2)) | ||
|
||
import Base.:- | ||
|
||
function subtract_cols_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] .- data[!, source[2]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, | ||
identity, | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
|
||
function make_subtract_const_function(constant::Real) | ||
return function add_const_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = constant .- data[!, source[1]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, # get the column out of the dataframe | ||
identity, # apply generic_fn to it | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
end | ||
|
||
Base.:-(s1::Symbol, s2::Symbol) = [s1, s2] => AesTransform(subtract_cols_fn) | ||
Base.:-(s1::Symbol, s2::Real) = [s1] => AesTransform(make_add_const_function(-s2)) | ||
Base.:-(s2::Real, s1::Symbol) = [s1] => AesTransform(make_subtract_const_function(s2)) | ||
|
||
import Base.:* | ||
|
||
function multiply_cols_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] .* data[!, source[2]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, | ||
identity, | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
|
||
function make_multiply_const_function(constant::Real) | ||
return function add_const_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] .* constant | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, # get the column out of the dataframe | ||
identity, # apply generic_fn to it | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
end | ||
|
||
Base.:*(s1::Symbol, s2::Symbol) = [s1, s2] => AesTransform(multiply_cols_fn) | ||
Base.:*(s1::Symbol, s2::Real) = [s1] => AesTransform(make_multiply_const_function(s2)) | ||
Base.:*(s2::Real, s1::Symbol) = [s1] => AesTransform(make_multiply_const_function(s2)) | ||
|
||
|
||
import Base.:/ | ||
|
||
function divide_cols_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = data[!, source[1]] ./ data[!, source[2]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, | ||
identity, | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
|
||
function make_divide_const_function(constant::Real) | ||
return function add_const_fn(target::Symbol, source::Vector{Symbol}, data::DataFrame) | ||
result = constant ./ data[!, source[1]] | ||
return Dict{Symbol, PlottableData}( | ||
target => PlottableData( | ||
result, # get the column out of the dataframe | ||
identity, # apply generic_fn to it | ||
nothing, | ||
nothing | ||
) | ||
) | ||
end | ||
end | ||
|
||
Base.:/(s1::Symbol, s2::Symbol) = [s1, s2] => AesTransform(divide_cols_fn) | ||
Base.:/(s1::Symbol, s2::Real) = [s1] => AesTransform(make_multiply_const_function(1/s2)) | ||
Base.:/(s2::Real, s1::Symbol) = [s1] => AesTransform(make_divide_const_function(s2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters