-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from davibarreira/plot!
Replot
- Loading branch information
Showing
8 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Vizagrams" | ||
uuid = "8c229dad-8b3a-4031-83d6-73545c88426d" | ||
authors = ["Davi Barreira <[email protected]> and contributors"] | ||
version = "0.2.2" | ||
version = "0.2.3" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# """ | ||
# replot(plt::Plot,graphic::Union{GeometricPrimitive,Prim,Mark,𝕋{Mark}}) | ||
# return Plot(plt.data, plt.spec,plt.graphic + graphic) | ||
# """ | ||
# function replot(plt::Plot, graphic::Union{GeometricPrimitive,Prim,Mark,𝕋{Mark}}) | ||
# return Plot(plt.data, plt.spec, plt.graphic + graphic) | ||
# end | ||
# function Base.:∘(plt::Plot, graphic::Union{GeometricPrimitive,Prim,Mark,𝕋{Mark}}) | ||
# return replot(plt, graphic) | ||
# end | ||
|
||
# """ | ||
# replot(plt::Plot, data::Union{StructArray,DataFrame,NamedTuple}; rescale=true) | ||
|
||
# It vertically concatenates `plt.data` and `data` and creates a new plot. | ||
# If `rescale` is true, it recomputes the scales, otherwise, it uses | ||
# the scales from the original plot. | ||
# """ | ||
# function replot( | ||
# plt::Plot, data::Union{StructArray,NamedTuple}; enc=nothing, rescale=true, fill=nothing | ||
# ) | ||
# # turn data into StructArray | ||
# data = StructArray(Tables.rowtable(data)) | ||
# data = vconcat(plt.data, data; fill=fill) | ||
# if !isnothing(enc) | ||
# scales = NamedTuple( | ||
# map(zip(keys(enc), values(enc))) do (k, v) | ||
# datatype = get(v, :datatype, infer_datatype(data)) | ||
# scale = infer_encoding_scale(; | ||
# data=data, | ||
# coordinate=plt.spec.config.coordinate, | ||
# framesize=plt.spec.config.figsize, | ||
# variable=k, | ||
# partial_encoding=v, | ||
# ) | ||
# return (k => (datatype=datatype, scale=scale)) | ||
# end, | ||
# ) | ||
# enc = NamedTupleTools.rec_merge(unzip(enc), scales) | ||
# else | ||
# enc = NamedTuple() | ||
# end | ||
# encodings = NamedTupleTools.rec_merge(plt.spec.encodings, enc) | ||
|
||
# if rescale | ||
# enc_no_scale = NamedTuple( | ||
# map(zip(keys(plt.spec.encodings), values(plt.spec.encodings))) do (k, v) | ||
# k => @delete v.scale | ||
# end, | ||
# ) | ||
|
||
# encodings = NamedTupleTools.rec_merge(enc_no_scale, enc) | ||
|
||
# return Plot(; data=data, encodings=encodings, graphic=plt.graphic) | ||
# end | ||
|
||
# spec = plt.spec | ||
# spec = @set spec.encodings = encodings | ||
# return Plot(data, spec, plt.graphic) | ||
# end | ||
# function Base.:∘(plt::Plot, data::Union{StructArray,NamedTuple}) | ||
# return replot(plt, data; rescale=true) | ||
# end | ||
|
||
""" | ||
replot(plt1::Plot, plt2::Plot) | ||
Place the graphic of `plt2` over `plt1`. | ||
""" | ||
function replot(plt1::Plot, plt2::Plot) | ||
encodings = NamedTupleTools.rec_merge(plt1.spec.encodings, plt2.spec.encodings) | ||
plt2 = @set plt2.spec.encodings = encodings | ||
plt2 = @set plt2.spec.config = (; guide=NilD()) | ||
return plt1 + plt2 | ||
end | ||
function Base.:∘(plt1::Plot, plt2::Plot) | ||
return replot(plt1, plt2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Vizagrams | ||
using StructArrays | ||
|
||
@testset "Helper Functions" begin | ||
@testset "vconcat" begin | ||
d1 = StructArray(x=[1, 2], c=["a", "b"]) | ||
d2 = StructArray(y=[10, 10, 10], x=[10, 10, 10], z=[1, 1, 1]) | ||
d = vconcat(d1, d2) | ||
|
||
d = vconcat(d1, d2) | ||
@test d.x == vcat(d1.x, d2.x) | ||
@test d.c == vcat(d1.c, [nothing, nothing, nothing]) | ||
@test d.y == vcat([nothing, nothing], d2.y) | ||
@test d.z == vcat([nothing, nothing], d2.z) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters