Created
July 23, 2025 21:13
-
-
Save damonbayer/f0bf2a5b7d51167e9e4bfd131cfdec95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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