Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Plots.jl recipes #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
docs/build
docs/site
docs/Manifest.toml
Manifest.toml
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
authors = ["Andy Ferris <[email protected]>"]
name = "TypedTables"
uuid = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
authors = ["Andy Ferris <[email protected]>"]
version = "1.4.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Indexing = "313cdc1a-70c2-5d6a-ae34-0150d3930a38"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
julia = "1"
Adapt = "1, 2, 3"
Dictionaries = "0.3"
Indexing = "1"
SplitApplyCombine = "1"
Tables = "1"
Dictionaries = "0.3"
julia = "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to add a compat entry here for RecipesBase or the General registry will reject a new release


[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
2 changes: 2 additions & 0 deletions src/TypedTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using SplitApplyCombine
import Adapt
using Dictionaries
using Indexing
using RecipesBase

using Base: @propagate_inbounds, @pure, OneTo, Fix2
import Tables.columns, Tables.rows
Expand Down Expand Up @@ -52,5 +53,6 @@ include("FlexTable.jl")
include("DictTable.jl")
include("columnops.jl")
include("show.jl")
include("plot.jl")

end # module
33 changes: 33 additions & 0 deletions src/plot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@recipe function f(tt::Table; indices = [1,2])
if length(indices) == 2
x_name, y_name = propertynames(tt)[indices]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generic Tables.jl, this would be: x_name, y_name = Tables.columnnames(tt)[indices]

xguide --> string(x_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the --> operator do here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's "use this value if the user didn't provide a different value"

yguide --> string(y_name)
return getproperty(tt, x_name), getproperty(tt, y_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generic Tables.jl, these would be Tables.getcolumn(tt, x_name), Tables.getcolumn(tt, y_name)

elseif length(indices) == 3
x_name, y_name, z_name = propertynames(tt)[indices]
xguide --> string(x_name)
yguide --> string(y_name)
zguide --> string(z_name)
return getproperty(tt, x_name), getproperty(tt, y_name), getproperty(tt, z_name)
else
throw(ArgumentError("Keyword argument `indices` needs to be an integer array of length 2 or 3."))
end
end

@recipe function f(tt::Table, column_names)
if length(column_names) == 2
x_name, y_name = column_names
xguide --> string(x_name)
yguide --> string(y_name)
return getproperty(tt, x_name), getproperty(tt, y_name)
elseif length(column_names) == 3
x_name, y_name, z_name = column_names
xguide --> string(x_name)
yguide --> string(y_name)
zguide --> string(z_name)
return getproperty(tt, x_name), getproperty(tt, y_name), getproperty(tt, z_name)
else
throw(ArgumentError("The second argument `column_names` needs to be of length 2 or 3."))
end
end