Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created October 8, 2018 16:25
Show Gist options
  • Save SimonDanisch/77107e6607a98da5cae43f376a320652 to your computer and use it in GitHub Desktop.
Save SimonDanisch/77107e6607a98da5cae43f376a320652 to your computer and use it in GitHub Desktop.
# Simple 1 to 1 conversion - can only be used to transform arguments + pass additional attributes
# and change the default plot type - but can't be used for complex plots!
# Name is up for debate!
function convert_arguments(args...)
# Return a named tuple with the optional fields:
return (
arguments = convert.(args),
plot = Scatter, # Optionally define the default plot type
attributes = (
labels = create_labels(args...),
color = :red
) # additional attributes
)
# or just return converted args
return convert.(args)
end
# Type recipe for MyType. Will be called when calling `plot(mytype)`
@recipe function plot!(p::Plot(MyType); attribute1::Node = attribute, attribute2::Node = blah)
mytype = p[1]::Node{MyType} # first argument is the type
# Arbitrary plotting commands:
plot!(p, color = attribute1)
plot!(p, ...)
end
# The recipe can be called via `myplot` and `myplot!` plot!(scene, MyPlot, args...)
# Which can be used when you don't own the argument types
@recipe function plot!(p::MyPlot; attribute1::Node = attribute, attribute2::Node = blah)
p[1:length(args)] # <- contains myname(arg1, arg2, ...)
plot!(p, ...)
plot!(p, ...)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment