Skip to content

BUG: Annotations.draggable property should accept an empty string as a valid value #71

@bgreenawald-vt

Description

@bgreenawald-vt

Describe the bug
The Chart.to_dict() method ignores keys which have a value of an empty string, but a value of empty string means something for the Annotations.draggable parameter (https://api.highcharts.com/highcharts/annotations.draggable) meaning that, in practice, you can't disable draggable annotations using that parameter.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Chart that has annotations, including the draggable parameter set to a value of ""
chart_options = { 
        "title": {"text": "Chart title"},
        "annotations": [
            {
                "labels": annotations,  # List of annotations
                "draggable": "",
                "labelOptions": {
                    "backgroundColor": "rgba(252, 255, 255, 0.0)",
                    "borderColor": "rgba(252, 255, 255, 0.0)",
                    "allowOverlap": True,
                    "y": -2,
                    "overflow": "justify"
                },
            }
        ]
    }

chart = Chart.from_options(chart_options)
  1. Export the Chart to a dictionary using the to_dict method and inspect the userOptions in the result. Note in the picture below that all parameters have been preserved except draggable:
chart.to_dict()["userOptions"]

image

Expected behavior
The draggable parameter should be preserved, even when the value is an empty string.

Your Environment:

  • OS: Windows 11
  • Python Version: 3.11
  • Highcharts JavaScript Version: highcharts-core==1.2.4

Additional context
Tracing the issue with the debugger, I isolated the following line as the problem. metaclasses.py -> lines 253, 254

elif value in [0, 0., False]:
    as_dict[key] = value

Locally, I was able to correct the issue by adding an empty string in the list of permitted values, though I don't know what other affects this might have.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions