-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefline.jl
56 lines (47 loc) · 2.16 KB
/
refline.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
RefLine(args...)
Represent a Refline with given arguments.
$(print_doc(REFLINE_DEFAULT))
"""
mutable struct RefLine <: SGMarks
opts
function RefLine(;opts...)
optsd = val_opts(opts)
cp_REFLINE_DEFAULT = update_default_opts!(deepcopy(REFLINE_DEFAULT), optsd)
if cp_REFLINE_DEFAULT[:axis] === nothing
throw(ArgumentError("RefLine needs the axis keyword arguments"))
end
new(cp_REFLINE_DEFAULT)
end
end
# RefLine graphic produce a reference line / if more than one value is passed, the _push_plots! function create one mark for each value
# It requires two keyword arguments; values and axis
# It does not need any data
function _push_plots!(vspec, plt::RefLine, all_args; idx=1)
opts = plt.opts
if opts[:values] isa AbstractVector
vals = opts[:values]
else
vals = [opts[:values]]
end
for val in vals
s_spec = Dict{Symbol,Any}()
s_spec[:type] = "rule"
s_spec[:clip] = something(opts[:clip], all_args.opts[:clip])
s_spec[:encode] = Dict{Symbol,Any}()
s_spec[:encode][:enter] = Dict{Symbol,Any}()
if opts[:axis] in (:xaxis, :x2axis)
# _convert_values_for_js is needed to properly handle TimeType , Bool, ...
s_spec[:encode][:enter][:x] = Dict{Symbol, Any}(:scale => opts[:axis] == :xaxis ? "x1" : "x2", :value => _convert_values_for_js(val))
s_spec[:encode][:enter][:y2] = Dict{Symbol, Any}(:signal => "height")
elseif opts[:axis] in (:yaxis, :y2axis)
s_spec[:encode][:enter][:y] = Dict{Symbol, Any}(:scale => opts[:axis] == :yaxis ? "y1" : "y2", :value => _convert_values_for_js(val))
s_spec[:encode][:enter][:x2] = Dict{Symbol, Any}(:signal => "width")
end
s_spec[:encode][:enter][:stroke] = Dict{Symbol, Any}(:value=>opts[:color])
s_spec[:encode][:enter][:strokeWidth]= Dict{Symbol, Any}(:value=>opts[:thickness])
s_spec[:encode][:enter][:opacity]= Dict{Symbol, Any}(:value=>opts[:opacity])
s_spec[:encode][:enter][:strokeDash]= Dict{Symbol, Any}(:value=>opts[:dash])
push!(vspec[:marks], s_spec)
end
end