From 51a47cb2b1d231b560d8363d9ece9b510b13d3d2 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 8 Feb 2017 23:51:15 +0100 Subject: [PATCH 1/4] Added basic support for searching attributes at the console --- src/Plots.jl | 5 ++++- src/plotattr.jl | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/plotattr.jl diff --git a/src/Plots.jl b/src/Plots.jl index c957ab8a..337880da 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -99,7 +99,9 @@ export center, P2, P3, - BezierCurve + BezierCurve, + + plotattr # --------------------------------------------------------- @@ -127,6 +129,7 @@ include("animation.jl") include("output.jl") include("examples.jl") include("arg_desc.jl") +include("plotattr.jl") # --------------------------------------------------------- diff --git a/src/plotattr.jl b/src/plotattr.jl new file mode 100644 index 00000000..0562a70c --- /dev/null +++ b/src/plotattr.jl @@ -0,0 +1,56 @@ + +const _attribute_defaults = Dict(:Series => Plots._series_defaults, + :Subplot => Plots._subplot_defaults, + :Plot => Plots._plot_defaults, + :Axis => Plots._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), ", ") + + + # Looks up the different elements and plots them + println("$attribute ($attrtype attribute)") + println("Aliases: $als \n") + println("Default: $(_attribute_defaults[attrtype][attribute])\t(Type: $typedesc)\n") + println("Description: ") + println(desc) +end From 82161e60bcd8c5ea9726e9bf59ab69c2eb6ed4da Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 9 Feb 2017 00:12:16 +0100 Subject: [PATCH 2/4] removed unnecessary Plots qualifier --- src/plotattr.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plotattr.jl b/src/plotattr.jl index 0562a70c..4272990d 100644 --- a/src/plotattr.jl +++ b/src/plotattr.jl @@ -1,8 +1,8 @@ -const _attribute_defaults = Dict(:Series => Plots._series_defaults, - :Subplot => Plots._subplot_defaults, - :Plot => Plots._plot_defaults, - :Axis => Plots._axis_defaults) +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]))) From 35a56962fc2d087a4caabda90568821155d4fd1e Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 9 Feb 2017 10:40:08 +0100 Subject: [PATCH 3/4] more concise output --- src/plotattr.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plotattr.jl b/src/plotattr.jl index 4272990d..b815adef 100644 --- a/src/plotattr.jl +++ b/src/plotattr.jl @@ -45,12 +45,12 @@ function plotattr(attrtype::Symbol, attribute::AbstractString) 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 ($attrtype attribute)") - println("Aliases: $als \n") - println("Default: $(_attribute_defaults[attrtype][attribute])\t(Type: $typedesc)\n") - println("Description: ") - println(desc) + println("$attribute ", typedesc == "" ? "" : "{$typedesc}") + als == "" || println("$als") + println("\n",desc) + println("$(attrtype) attribute, ", def == "" ? "" : " default: $def") end From d663267cde22d18e74fdc10d345073df83135c42 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 9 Feb 2017 11:12:46 +0100 Subject: [PATCH 4/4] improved println call --- src/plotattr.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plotattr.jl b/src/plotattr.jl index b815adef..cc8d053b 100644 --- a/src/plotattr.jl +++ b/src/plotattr.jl @@ -49,8 +49,8 @@ function plotattr(attrtype::Symbol, attribute::AbstractString) # Looks up the different elements and plots them - println("$attribute ", typedesc == "" ? "" : "{$typedesc}") - als == "" || println("$als") - println("\n",desc) - println("$(attrtype) attribute, ", def == "" ? "" : " default: $def") + println("$attribute ", typedesc == "" ? "" : "{$typedesc}", "\n", + als == "" ? "" : "$als\n", + "\n$desc\n", + "$(attrtype) attribute, ", def == "" ? "" : " default: $def") end