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

Incorrect Validation Error for layout.grid.subplots attribute #1220

Closed
michaelbabyn opened this issue Oct 10, 2018 · 2 comments · Fixed by #1240
Closed

Incorrect Validation Error for layout.grid.subplots attribute #1220

michaelbabyn opened this issue Oct 10, 2018 · 2 comments · Fixed by #1240
Labels
Milestone

Comments

@michaelbabyn
Copy link
Contributor

I'm getting a validation ValueError when I try to set the layout.grid.subplots attribute. This attribute should accept a 2d list of the enumerated values (see here) but it is being limited to a single dimensional list of one element.

ValueError: 
    Invalid value of type 'builtins.list' received for the 'subplots' property of layout.grid
        Received value: [['xy', 'x2y'], ['xy3', 'x4y4']]

    The 'subplots' property is an info array that may be specified as a
    list or tuple of up to 1 elements where:

(0) The 'subplots[0]' property is an enumeration that may be specified as:
      - One of the following enumeration values:
            ['']
      - A string that matches one of the following regular expressions:
            ['^x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?$']

Here is an example demonstrating the problem which works if I use dicts and validate=False

import plotly.offline as py
import plotly.graph_objs as go

py.init_notebook_mode()

trace1 = go.Scatter(
    x=[1, 2, 3],
    y=[2, 3, 4]
)
trace2 = go.Scatter(
    x=[20, 30, 40],
    y=[5, 5, 5],
    xaxis='x2',
    yaxis='y'
)
trace3 = go.Scatter(
    x=[2, 3, 4],
    y=[600, 700, 800],
    xaxis='x',
    yaxis='y3'
)
trace4 = go.Scatter(
    x=[4000, 5000, 6000],
    y=[7000, 8000, 9000],
    xaxis='x4',
    yaxis='y4'
)
data = [trace1, trace2, trace3, trace4]
layout = go.Layout(
    grid = go.layout.Grid(
        rows=2, 
        columns=2,
        subplots=[['xy','x2y'],['xy3','x4y4']], 
        )
    )
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='shared-axes-subplots')
@jonmmease
Copy link
Contributor

Thanks for the report @michaelbabyn

Technical notes:

Here's the schema for layout.grid.subplots:

                "subplots": {
                    "valType": "info_array",
                    "freeLength": true,
                    "dimensions": 2,
                    "items": {
                        "valType": "enumerated",
                        "values": [
                            "/^x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?$/",
                            ""
                        ],
                        "editType": "plot"
                    },
                    "role": "info",
                    "editType": "plot",
                    "description": "Used for freeform grids, ..."
                },

Looks like we need to add support for the dimensions attribute of "info_array". Elsewhere, dimensions is also set to a string specifying a range of values.

                            "constraintrange": {
                                "valType": "info_array",
                                "role": "info",
                                "freeLength": true,
                                "dimensions": "1-2",
                                "items": [
                                    {
                                        "valType": "number",
                                        "editType": "calc"
                                    },
                                    {
                                        "valType": "number",
                                        "editType": "calc"
                                    }
                                ],
                                "editType": "calc",
                                "description": "The domain range to ..."
                            },

Additionally, to this point we have treated freeLength to mean that only a subset of the specified items are required. For example, in layout.updatemenus.buttons.button.args...

                                    "args": {
                                        "valType": "info_array",
                                        "role": "info",
                                        "freeLength": true,
                                        "items": [
                                            {
                                                "valType": "any",
                                                "editType": "arraydraw"
                                            },
                                            {
                                                "valType": "any",
                                                "editType": "arraydraw"
                                            },
                                            {
                                                "valType": "any",
                                                "editType": "arraydraw"
                                            }
                                        ],
                                        "description": "Sets the arguments values ...",
                                        "editType": "arraydraw"
                                    },

we interpreted this to mean that zero to 3 values with type any could be specified, but not more than 3. But in the case of subplots and constraintrange the freeLength attribute seems to mean that any number of the specified items can be included.

@alexcjohnson or @etpinard , could you clarify the intent of freeLength: true? Thanks!

@jonmmease jonmmease added the bug label Oct 12, 2018
@jonmmease jonmmease added this to the v3.4.0 milestone Oct 12, 2018
@etpinard
Copy link
Contributor

could you clarify the intent of freeLength: true?

It corresponds to no restriction on the number of items in the "info" array.

https://github.com/plotly/plotly.js/blob/d34015066c8d339f041c9ac5ae68762a342d5d86/src/lib/coerce.js#L329-L355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment