Skip to content

Commit b782b48

Browse files
authored
Merge pull request #23 from andreasKroepelin/master
Prevent setting layout/config options affect global defaults
2 parents 22be833 + aae3e20 commit b782b48

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/PlotlyLight.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ mutable struct Plot
116116

117117
function Plot(
118118
data::Union{Config, Vector{Config}},
119-
layout::Config = Defaults.layout[],
120-
config::Config = Defaults.config[];
119+
layout::Config = copy(Defaults.layout[]),
120+
config::Config = copy(Defaults.config[]);
121121
# kw
122122
id::AbstractString = randstring(10),
123123
js::Cobweb.Javascript = Cobweb.Javascript("console.log('plot created!')")

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using PlotlyLight
2+
using PlotlyLight.Defaults
23
using JSON3
34
using Test
45

@@ -12,6 +13,18 @@ using Test
1213
p(Config(x=1:10,y=rand(10)))
1314
@test length(p.data) == 2
1415
end
16+
#-----------------------------------------------------------------------------# defaults
17+
@testset "defaults" begin
18+
old_layout_default = copy(Defaults.layout[])
19+
old_config_default = copy(Defaults.config[])
20+
p = Plot()
21+
p.layout.xaxis.showgrid = false
22+
p.config.editable = true
23+
# make sure that mutation of layout and config of one plot has no effect on
24+
# global defaults
25+
@test Defaults.layout[] == old_layout_default
26+
@test Defaults.config[] == old_config_default
27+
end
1528
#-----------------------------------------------------------------------------# src
1629
@testset "src" begin
1730
p = Plot(Config(y=1:10))

0 commit comments

Comments
 (0)