Skip to content

Instantly share code, notes, and snippets.

@damonbayer
Created July 23, 2025 21:13
Show Gist options
  • Select an option

  • Save damonbayer/f0bf2a5b7d51167e9e4bfd131cfdec95 to your computer and use it in GitHub Desktop.

Select an option

Save damonbayer/f0bf2a5b7d51167e9e4bfd131cfdec95 to your computer and use it in GitHub Desktop.
def is_empty_chart(ch):
spec = ch.to_dict()
# Unit chart: no data, no mark, no encoding
if "layer" not in spec:
return not (spec.get("data") or spec.get("mark") or spec.get("encoding"))
# LayerChart: check each sub-layer recursively
# Check if the layer list is empty or all sub-layers are empty
if not spec["layer"]:
return True
# For each sub-layer, check if it's empty by examining its dict directly
# instead of converting back to Chart object (which can cause validation errors)
return all(
not (sub.get("data") or sub.get("mark") or sub.get("encoding"))
for sub in spec["layer"]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment