Coder Social home page Coder Social logo

Background not set? about plotlyjs.jl HOT 6 CLOSED

juliaplots avatar juliaplots commented on May 12, 2024
Background not set?

from plotlyjs.jl.

Comments (6)

sglyon avatar sglyon commented on May 12, 2024

Yep, I know exactly what the problem is. When you try to set paper_bgcolor=x the PlotlyJS.jl underscore magic is applied and this gets applied and this is translated to Dict(:paper => Dict(:bgcolor => x)) instead of Dict(:paper_bgcolor => x)

I'll take a look at the backend code in Plots.jl and see if I can fix this.

from plotlyjs.jl.

sglyon avatar sglyon commented on May 12, 2024

Looks like you managed to hit on one of just a few trace attributes that have underscores:

julia> using JSON

julia> d = JSON.parsefile(Pkg.dir("PlotlyJS", "deps", "plotschema.json"));

julia> get_keys(x) = [];

julia> get_keys(d::Associative) = vcat(collect(keys(d)), map(get_keys, values(d))...);

julia> get_keys(d["schema"]["layout"]) |> unique |> length
180

julia> get_keys(d["schema"]["traces"]) |> unique |> length
249

julia> unique(filter(x->contains(x, "_") && !(x[1] == '_'), get_keys(d["schema"]["traces"])))
5-element Array{Any,1}:
 "error_y"
 "error_x"
 "copy_ystyle"
 "copy_zstyle"
 "error_z"

julia> unique(filter(x->contains(x, "_") && !(x[1] == '_'), get_keys(d["schema"]["layout"])))
2-element Array{Any,1}:
 "plot_bgcolor"
 "paper_bgcolor"

I'm not really sure what the best way around this is. I noticed that you set the layout attributes using the relayout! methods, which is great. The problem with those is that they end up calling setindex!, which is where the underscore magic gets applied.

Any suggestions on an elegant way to deal with this? I think you should still use relayout!, but I should maybe add a kwarg to that function that describes if we should do the underscore replacing or just operate directly with the keys that were handed to us?

from plotlyjs.jl.

sglyon avatar sglyon commented on May 12, 2024

Here's an idea...

What if arguments that are passed to relayout!s second argument in the dict are merged with the underlying layout dict without any processing. But, we continue to do _ processing for all attributes set via keyword arguments?

from plotlyjs.jl.

tbreloff avatar tbreloff commented on May 12, 2024

Good catch!

What if arguments that are passed to relayout!s second argument in the dict are merged with the underlying layout dict without any processing

This is the best option, if it doesn't break anything.

The other option is to keep a list valid_keys and only split if it's not in the list.

from plotlyjs.jl.

sglyon avatar sglyon commented on May 12, 2024

OK fixed on my sl/ijulia-comm branch.

Will leave open here until we merge into master

from plotlyjs.jl.

sglyon avatar sglyon commented on May 12, 2024

Done!

from plotlyjs.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.