Skip to content

Commit

Permalink
Merge pull request #89 from hhaensel/patch-1
Browse files Browse the repository at this point in the history
enhancing json3 for traces
  • Loading branch information
sglyon authored Jan 15, 2022
2 parents af53af3 + 1bcda7b commit b967a15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/json3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ const StructTypes = JSON3.StructTypes

StructTypes.StructType(::Type{<:PlotlyBase.Plot}) = JSON3.RawType()
JSON3.rawbytes(plot::PlotlyBase.Plot) = codeunits(JSON.json(plot))

StructTypes.StructType(::Type{<:HasFields}) = JSON3.RawType()
JSON3.rawbytes(x::HasFields) = codeunits(JSON.json(x))
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
13 changes: 13 additions & 0 deletions test/json.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

gt = PlotlyBase.GenericTrace("scatter"; x=1:10, y=(1:10).^2)
pplot = PlotlyBase.Plot(gt)
layout = PlotlyBase.Layout()

using PlotlyBase.JSON, JSON3

@testset "Convert to json" begin
@test JSON.json(gt) == "{\"y\":[1,4,9,16,25,36,49,64,81,100],\"type\":\"scatter\",\"x\":[1,2,3,4,5,6,7,8,9,10]}"
@test JSON.json(gt) == JSON3.write(gt)
@test JSON.json(pplot) == JSON3.write(pplot)
@test JSON.json(layout) == JSON3.write(layout)
end

0 comments on commit b967a15

Please sign in to comment.