Skip to content

Commit

Permalink
Fixes for optional props and options
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Aug 18, 2021
1 parent 52501ad commit 57b4c65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StippleCharts"
uuid = "30ddb3f0-912f-4f34-9804-e4bb31290777"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.11"
version = "0.12"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
33 changes: 27 additions & 6 deletions src/Charts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ Base.@kwdef mutable struct PlotOptions
title_text::String = ""
title_align::Union{String,Symbol} = :left
title_margin::Int = 10
title_style_font_family::Union{String,Undefined} = UNDEFINED
title_style_font_size::String = "14px"
title_style_font_weight::Union{Int,Symbol,String} = :bold
title_style_color::String = "#263238"

tooltip_enable::Bool = true

xaxis_type::Union{String,Symbol} = :category
xaxis_categories::Union{Vector{String},Vector{Float64}} = String[]
xaxis_tick_amount::Union{Int,Float64,String,Undefined} = UNDEFINED
xaxis_tick_placement::Union{String,Symbol} = :between # :on
xaxis_decimals_in_float::Union{Int,Undefined} = UNDEFINED
xaxis_labels_show::Bool = true
xaxis_max::Union{Int,Float64,String,Undefined} = UNDEFINED
xaxis_min::Union{Int,Float64,String,Undefined} = UNDEFINED
xaxis_labels_show::Bool = true
xaxis_tick_amount::Union{Int,Float64,String,Undefined} = UNDEFINED
xaxis_tick_placement::Union{String,Symbol} = :between # :on
xaxis_type::Union{String,Symbol} = :category

yaxis_decimals_in_float::Union{Int,Undefined} = UNDEFINED
yaxis_labels_show::Bool = true
Expand Down Expand Up @@ -203,6 +205,7 @@ end

function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = nothing)
val = Dict(
# chart
:chart => Dict(
:animations => Dict(
:enabled => po.chart_animations_enabled,
Expand Down Expand Up @@ -234,10 +237,13 @@ function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = noth
:type => po.chart_zoom_type
)
),

:colors => po.colors,

:dataLabels => Dict(
:enabled => po.data_labels_enabled
),

:fill => Dict(
:opacity => po.fill_opacity
),
Expand All @@ -262,47 +268,57 @@ function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = noth
),

:labels => po.labels,

:legend => Dict(
:position => po.legend_position,
:fontFamily => po.legend_font_family,
:fontSize => po.legend_font_size,
:show => po.legend_show
),

:noData => Dict(
:text => po.no_data_text
),

:stroke => Dict(
:curve => po.stroke_curve,
:show => po.stroke_show,
:width => po.stroke_width,
:colors => po.stroke_colors
),

:subtitle => Dict(
:align => po.subtitle_align,
:text => po.subtitle_text,
:style => Dict(
:fontSize => po.subtitle_style_font_size
)
),

:theme => Dict(
:mode => po.theme_mode,
:palette => po.theme_palette
),

:title => Dict(
:text => po.title_text,
:align => po.title_align,
:margin => po.title_margin,
:style => Dict(
:color => po.title_style_color,
:fontFamily => po.title_style_font_family,
:fontSize => po.title_style_font_size,
:fontWeight => po.title_style_font_weight
)
),

:tooltip => Dict(
:enable => po.tooltip_enable
),

:xaxis => Dict(
:categories => po.xaxis_categories,
:decimalsInFloat => po.xaxis_decimals_in_float,
:tickAmount => po.xaxis_tick_amount,
:tickPlacement => po.xaxis_tick_placement,
:type => po.xaxis_type,
Expand All @@ -312,6 +328,7 @@ function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = noth
:show => po.xaxis_labels_show
)
),

:yaxis => Dict(
:decimalsInFloat => po.yaxis_decimals_in_float,
:labels => Dict(
Expand All @@ -324,7 +341,7 @@ function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = noth
)
)

isempty(po.extra_properties) || (val = merge(po.extra_properties, val))
isempty(po.extra_properties) || (val = recursive_merge(val, po.extra_properties))

plot_options = if po.chart_type == :area
Dict(
Expand Down Expand Up @@ -383,13 +400,17 @@ function Stipple.render(po::PlotOptions, fieldname::Union{Symbol,Nothing} = noth
Dict()
end

isempty(po.extra_options) || (plot_options = merge(po.extra_options, plot_options))
plot_options = recursive_merge(plot_options, get(po.extra_properties, :plotOptions, Dict()))
isempty(po.extra_options) || (plot_options = recursive_merge(plot_options, po.extra_options))
isempty(plot_options) || (val[:plotOptions] = plot_options)

val
end

# #===#

recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)
recursive_merge(x...) = x[end]


end

2 comments on commit 57b4c65

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/43091

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" 57b4c65c228521abb0b755899edec462cb572b21
git push origin v0.12.0

Please sign in to comment.