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

Layout axis system layout.xAxis/yAxis properties are missing from JSON if figure contains more than one trace #18

Closed
vojtamolda opened this issue Feb 6, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@vojtamolda
Copy link
Owner

The following code snippet:

Figure(
    data: [
        Scatter(x: [1, 2], y: [3, 4]),
        Scatter(x: [1, 2], y: [4, 5])
    ],
    layout: Layout(
        xAxis: [ Layout.XAxis(title: "X Label") ],
        yAxis: [ Layout.YAxis(title: "Y Label") ]
   )
)

Produces incorrect JSON representation. The xaxis1 and yaxis1 attributes of the layout are empty. The titles on the axes therefore don't show up when the figure is rendered.

Here's the invalid JSON that gets produced in v0.4.0:

{
    "data": [
        {"trace": "scatter", "x": [1, 2], "y": [3, 4] },
        {"trace": "scatter", "x": [1, 2], "y": [4, 5] }
    ],
    "layout": {
        "xaxis1": { },
        "yaxis1": { }
    }
}

The reason why it happens is that each trace gets its own instance of the Layout.XAxis(uid: 1) assigned to the xAxis property. The Figure constructors does a little "dance" and collects these properties from all traces and adds them to the layout.

This way the layout ends up with multiple XAxis objects that don't have unique uid. When the entire figure gets encoded to JSON, the encoder keeps overwriting the value for the xaxis1 key over and over the value that is acually visible is the one that happens to be stored the last.

@vojtamolda vojtamolda added the bug Something isn't working label Feb 6, 2021
@vojtamolda vojtamolda added this to the Plotly.swift 0.5.0 milestone Feb 6, 2021
@vojtamolda vojtamolda self-assigned this Feb 6, 2021
vojtamolda added a commit that referenced this issue Feb 10, 2021
#18)

- Redesigned init of Figure that associates trace subplot axis to layout
- Add preset static member to all subplot axis types
- Refactor subplot protocols into a separate file
- Add extensibility modifier for generated structs
- Make .animatable property of all traces computed and static
- Remove Shared namespace
@vojtamolda vojtamolda changed the title Layout axis system (XAxis, YAxis, ...) and subplots don't work figure contains more than one trace Layout axis system layout.xAxis/yAxis properties are missing from JSON if figure contains more than one trace Feb 10, 2021
@vojtamolda
Copy link
Owner Author

Fixed in release 0.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant