Genie Discord forum

Author AvatarBoris Kaus
8/7/2023, 2:08:12 PM

I would like to activate interactive drawing within GenieBuilder plots, as described in the Plotly user manual:

using PlotlyJS

text="Click and drag<br> to draw a rectangle <br><br> or select another shape <br>in the modebar"

fig = plot(
    Layout(
        annotations=[
            attr(
                x=0.5,
                y=0.5,
                text=text,
                xref="paper",
                yref="paper",
                showarrow=false,
                font_size=20
            )
        ],
        shapes=[
            attr(
                line_color="yellow",
                fillcolor="turquoise",
                opacity=0.4,
                editable=true,
                x0=0, x1=1, y0=2, y1=3,
                xref="x", yref="y"
            )
        ],

        dragmode="drawrect",
        # style of new shapes
        newshape=attr(
            line_color="yellow",
            fillcolor="turquoise",
            opacity=0.5
        )
    ),
    config=PlotConfig(
        modeBarButtonsToAdd=[
            "drawline",
            "drawopenpath",
            "drawclosedpath",
            "drawcircle",
            "drawrect",
            "eraseshape"
        ]
    )
)

Can that be done, and if yes: how?

My attempts with adding config as:

config_user = GenieFramework.PlotConfig(staticplot = false, displaymodebar="drawcircle")

and

 plot(:appData, layout=:appLayout, config=config_user)

did not add any menu bar items. It would be very useful to have this possibility.

Author AvatarGenerallyClueless
8/7/2023, 2:26:40 PM

It looks like a lot of these attributes are added, but I have never tried to implement this:

Author AvatarGenerallyClueless
8/7/2023, 2:31:39 PM

That looks like a really neat feature of PlotlyJS that I have never played around with ๐Ÿ˜ณ

Author AvatarBoris Kaus
8/7/2023, 2:33:27 PM

thanks. modeBarButtonsToAdd should be the correct option (I suppose const CONGIG_DEFAULTS should be renamed to CONFIG_DEFAULTS). What is the API to change values?

Author AvatarGenerallyClueless
8/7/2023, 2:41:05 PM

Yes, it is contained in the dict CONFIG_DEFAULTS, and I think the right way to change this would be using Charts.PlotConfig()

Author AvatarGenerallyClueless
8/7/2023, 2:41:52 PM

Look closely... it seems like a bug... const CONGIG_DEFAULTS... not CONFIG_DEFAULTS

Author AvatarGenerallyClueless
8/7/2023, 2:43:44 PM

๐Ÿ‘† ๐Ÿ‘† ๐Ÿ‘† @abhimanyuaryan @Pere or anyone else more experienced than me (practically everyone here) ๐Ÿ˜ณ

Author AvatarGenerallyClueless
8/7/2023, 2:44:30 PM

This looks like a typo in charts.jl line #587... but perhaps I am mistaken. The CONGIG_DEFAULTS is properly referenced later (line 845, 846)

Author AvatarGenerallyClueless
8/7/2023, 2:46:26 PM

I submitted it as possible issue in github ๐Ÿค”

Author AvatarBoris Kaus
8/7/2023, 2:50:49 PM

brilliant - thanks a lot!

Author AvatarGenerallyClueless
8/7/2023, 2:51:25 PM

I hope it helps. I'm new so take my advice with a bit of salt ๐Ÿซข

Author AvatarBoris Kaus
8/7/2023, 4:47:25 PM

ok, so here a MWE that illustrates the issue:

using GenieFramework
using PlotlyBase

data = scatter(Dict(
    :name => "",
    :x => [0, 1],
    :y => [0, 0.5],
    :marker => Dict(:color => "red")
))

myconfig = PlotlyBase.PlotConfig( displaylogo=true,
    modeBarButtonsToAdd=["drawline", "drawopenpath", "drawcircle","eraseshape"]
)

function ui()
    [
        h1("StipplePlotly ๐Ÿงž interactive example")
        plot(:appData, config=:appConfig)
    ]
end

@app begin
    @out appData = [ data]
    @out appConfig = myconfig
end

@page("/", ui)

up()
Author AvatarBoris Kaus
8/7/2023, 4:48:14 PM

If displaylogo=false, it indeed removes the Plotly logo. Yet the modeBarButtonsToAdd does not seem to have an effect, so it seems that some options are propagated, but not all.

Author AvatarGenerallyClueless
8/7/2023, 6:20:42 PM

Do you maybe have to add StipplePlotly instead of PlotlyBase?

Author AvatarPere
8/7/2023, 8:57:53 PM

@Boris Kaus I havent tried with such plot options, but will take a look when I get back form vacation in a few days