Merge pull request #674 from mkborregaard/better-docs
WIP: lookup attributes at the console
This commit is contained in:
commit
a4549cbfa2
@ -99,7 +99,9 @@ export
|
|||||||
center,
|
center,
|
||||||
P2,
|
P2,
|
||||||
P3,
|
P3,
|
||||||
BezierCurve
|
BezierCurve,
|
||||||
|
|
||||||
|
plotattr
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
@ -127,6 +129,7 @@ include("animation.jl")
|
|||||||
include("output.jl")
|
include("output.jl")
|
||||||
include("examples.jl")
|
include("examples.jl")
|
||||||
include("arg_desc.jl")
|
include("arg_desc.jl")
|
||||||
|
include("plotattr.jl")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|||||||
56
src/plotattr.jl
Normal file
56
src/plotattr.jl
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
const _attribute_defaults = Dict(:Series => _series_defaults,
|
||||||
|
:Subplot => _subplot_defaults,
|
||||||
|
:Plot => _plot_defaults,
|
||||||
|
:Axis => _axis_defaults)
|
||||||
|
|
||||||
|
attrtypes() = join(keys(_attribute_defaults), ", ")
|
||||||
|
attributes(attrtype::Symbol) = sort(collect(keys(_attribute_defaults[attrtype])))
|
||||||
|
|
||||||
|
function lookup_aliases(attrtype, attribute)
|
||||||
|
attribute = Symbol(attribute)
|
||||||
|
attribute = in(attribute, keys(_keyAliases)) ? _keyAliases[attribute] : attribute
|
||||||
|
in(attribute, keys(_attribute_defaults[attrtype])) && return attribute
|
||||||
|
error("There is no attribute named $attribute in $attrtype")
|
||||||
|
end
|
||||||
|
|
||||||
|
function plotattr()
|
||||||
|
println("Specify an attribute type to get a list of supported attributes. Options are $(attrtypes())")
|
||||||
|
end
|
||||||
|
|
||||||
|
function plotattr(attrtype::Symbol)
|
||||||
|
in(attrtype, keys(_attribute_defaults)) || error("Viable options are $(attrtypes())")
|
||||||
|
println("Defined $attrtype attributes are:\n$(join(attributes(attrtype), ", "))")
|
||||||
|
end
|
||||||
|
|
||||||
|
function plotattr(attribute::AbstractString)
|
||||||
|
attribute = Symbol(attribute)
|
||||||
|
attribute = in(attribute, keys(_keyAliases)) ? _keyAliases[attribute] : attribute
|
||||||
|
for (k, v) in _attribute_defaults
|
||||||
|
if in(attribute, keys(v))
|
||||||
|
return plotattr(k, "$attribute")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error("There is no attribute named $attribute")
|
||||||
|
end
|
||||||
|
|
||||||
|
function plotattr(attrtype::Symbol, attribute::AbstractString)
|
||||||
|
in(attrtype, keys(_attribute_defaults)) || ArgumentError("`attrtype` must match one of $(attrtypes())")
|
||||||
|
|
||||||
|
attribute = Symbol(lookup_aliases(attrtype, attribute))
|
||||||
|
|
||||||
|
desc = get(_arg_desc, attribute, "")
|
||||||
|
first_period_idx = findfirst(desc, '.')
|
||||||
|
typedesc = desc[1:first_period_idx-1]
|
||||||
|
desc = strip(desc[first_period_idx+1:end])
|
||||||
|
als = keys(filter((_,v)->v==attribute, _keyAliases)) |> collect |> sort
|
||||||
|
als = join(map(string,als), ", ")
|
||||||
|
def = _attribute_defaults[attrtype][attribute]
|
||||||
|
|
||||||
|
|
||||||
|
# Looks up the different elements and plots them
|
||||||
|
println("$attribute ", typedesc == "" ? "" : "{$typedesc}", "\n",
|
||||||
|
als == "" ? "" : "$als\n",
|
||||||
|
"\n$desc\n",
|
||||||
|
"$(attrtype) attribute, ", def == "" ? "" : " default: $def")
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user