Skip to content

Grouped stacked bar charts (offsetgroup + barmode="relative") export incorrectly #29

@abcdvvvv

Description

@abcdvvvv

Hi, and thanks for providing PlotlyKaleido!

I’ve run into an issue where grouped stacked bar charts (using barmode="relative" together with offsetgroup) render correctly in the interactive preview (VS Code / browser), but the static image exported via Kaleido is incorrect.

Minimal reproducible example

using PlotlyLight
using PlotlyKaleido

categories = ["A", "B"]

g1_layer1 = [2.0, 3.0]
g1_layer2 = [1.0, 1.5]

g2_layer1 = [1.5, 2.5]
g2_layer2 = [0.5, 1.0]

plt = Plot(
    [
        # Group 1 stack
        Config(
            type        = "bar",
            x           = categories,
            y           = g1_layer1,
            name        = "Group 1 – layer 1",
            offsetgroup = "g1",
            legendgroup = "g1"
        ),
        Config(
            type        = "bar",
            x           = categories,
            y           = g1_layer2,
            name        = "Group 1 – layer 2",
            offsetgroup = "g1",
            legendgroup = "g1"
        ),

        # Group 2 stack
        Config(
            type        = "bar",
            x           = categories,
            y           = g2_layer1,
            name        = "Group 2 – layer 1",
            offsetgroup = "g2",
            legendgroup = "g2"
        ),
        Config(
            type        = "bar",
            x           = categories,
            y           = g2_layer2,
            name        = "Group 2 – layer 2",
            offsetgroup = "g2",
            legendgroup = "g2"
        )
    ],
    Config(
        width       = 600,
        height      = 400,
        barmode     = "relative",  # stacked
        bargap      = 0.25,
        bargroupgap = 0.1,
        xaxis       = Config(
            type  = "category",
            title = Config(text = "Category")
        ),
        yaxis       = Config(
            title = Config(text = "Value")
        ),
        title = "Grouped stacked bar chart: preview vs. Kaleido export"
    )
)

# Interactive preview in VS Code / browser is correct:
display(plt)

# But the exported SVG is wrong:
savefig(plt, "grouped_stacked_kaleido_bug.svg")

Interactive preview in VS Code / browser is correct:
Image

But the exported SVG is wrong:
Image

Expected behavior

I would expect the SVG/PNG produced by savefig to look the same.

Actual behavior

The interactive preview (VS Code / browser) shows the expected grouped stacked structure.

The SVG exported by savefig(plt, "grouped_stacked_kaleido_bug.svg") instead shows only one stack per category: all four bar traces appear to be stacked together, as if offsetgroup was ignored when barmode="relative" is used.

So the layout rendered by Kaleido does not match what plotly.js produces in the browser for the same figure definition.

Environment

OS: Windows 11 x64
Julia: 1.12.1
PlotlyLight.jl: v0.13.0
PlotlyKaleido.jl: v2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions