Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to store config in variable for reuse across plots? #442

Open
rtedwards opened this issue Sep 3, 2023 · 0 comments
Open

How to store config in variable for reuse across plots? #442

rtedwards opened this issue Sep 3, 2023 · 0 comments

Comments

@rtedwards
Copy link

I have a decent size config for customizing my charts. Currently I'm copy-pasting the config into each plot. Is there a way to store the config to a variable for easy reuse?

I've tried to store config as a dictionary and directly how it's defined within vplot without success. This is very likely already possibly, I'm just missing something.

Current

fitted_normalized_combined = fitted_normalized_combined_df |>
    @vlplot(
        :line,
        transform=[
            {density="data", bandwidth=0.25, groupby=["distribution"], counts=true, steps=50}
        ],
        title="Fitted Normal Distributions Densities from Other Distributions",
        x={
            "value:q", 
            title="Distribution",
        },
        y={"density:q", title="Density"},
        params=[{
            name= "moust-event",
            select= {type= "point", fields= ["distribution"]},
            bind= "legend"
        }],
        color={
            "distribution:n",
            legend={orient="top-right"},
            scale={range=colorscheme}
        },
        opacity={
          condition={param="moust-event", value= 1},
          value=0.25
        },
        padding=20,
        tooltip={:distribution},
        height=300,
        width=600,
        config={  # need to paste into every new chart
            background="#202124",
            view={stroke=:transparent},
            axis={
                labelFont=FONT,
                titleFont=FONT,
                titleColor="white",
                labelColor="white",
                tickColor="white",
                gridColor="grey",
                domainColor="white",
            },
            legend={
                labelFont=FONT,
                titleFont=FONT,
                labelColor="white",
                titleColor="white",
            },
            title={
                font=FONT,
                subtitleFont=FONT,
                color="white",
            },
            mark={
                font=FONT,
            },
            header={
                labelFont=FONT,
                titleFont=FONT,
                labelColor="white",
                titleColor="white",
            },
        },
    )

What I'd like to do

# would like to store into a variable
config=Dict(
    "background"=>"#202124",
    "view"=>Dict("stroke"=>:transparent),
    "axis"=>Dict(
        "labelFont"=>FONT,
        "titleFont"=>FONT,
        "titleColor"=>"white",
        "labelColor"=>"white",
        "tickColor"=>"white",
        "gridColor"=>"grey",
        "domainColor"=>"white",
    ),
    "legend"=>Dict(
        "labelFont"=>FONT,
        "titleFont"=>FONT,
        "labelColor"=>"white",
        "titleColor"=>"white",
    ),
    "title"=>Dict(
        "font"=>FONT,
        "subtitleFont"=>FONT,
        "color"=>"white",
    ),
    "mark"=>Dict(
        "font"=>FONT,
    ),
    "header"=>Dict(
        "labelFont"=>FONT,
        "titleFont"=>FONT,
        "labelColor"=>"white",
        "titleColor"=>"white",
    ),
)

fitted_normalized_combined = fitted_normalized_combined_df |>
    @vlplot(
        :line,
        transform=[
            {density="data", bandwidth=0.25, groupby=["distribution"], counts=true, steps=50}
        ],
        title="Fitted Normal Distributions Densities from Other Distributions",
        x={
            "value:q", 
            title="Distribution",
        },
        y={"density:q", title="Density"},
        params=[{
            name= "moust-event",
            select= {type= "point", fields= ["distribution"]},
            bind= "legend"
        }],
        color={
            "distribution:n",
            legend={orient="top-right"},
            scale={range=colorscheme}
        },
        opacity={
          condition={param="moust-event", value= 1},
          value=0.25
        },
        padding=20,
        tooltip={:distribution},
        height=300,
        width=600,
        config=config # pass variable
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant