Repository: vega/vl-convert (language: python)

Issue:
axis label limit cutoff not considered when saving as file
See https://github.com/altair-viz/altair/discussions/3336

```python
import vl_convert as vlc
from IPython.display import Image
vl_spec = '''
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"a": "J", "b": 28, "c": "I'm a very long axis label and eventhough my axis label is cutoff, I'm still rendered in the png"},
      {"a": "B", "b": 55},
      {"a": "C", "b": 43},
      {"a": "D", "b": 91},
      {"a": "E", "b": 81},
      {"a": "F", "b": 53},
      {"a": "G", "b": 19},
      {"a": "H", "b": 87},
      {"a": "I", "b": 52}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "a", "type": "nominal"},
    "y": {"field": "c", "type": "nominal"},
    "color": {"field": "c", "legend": null}
  }
}
'''
png_data = vlc.vegalite_to_png(vl_spec=vl_spec)
Image(png_data)
```
![Screenshot 2024-02-23 162713](https://github.com/vega/vl-convert/assets/5186265/7cd76983-3172-4d74-80b1-dd4f967b493f)





Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 0ca02cb..e78d145 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,7 @@ __pycache__/
 /vl-convert-python/notebooks/output/
 /vl-convert/tests/output/
 /vl-convert-rs/tests/vl-specs/failed/
+
+.pixi/
+pixi.lock
+pixi.toml
\ No newline at end of file
diff --git a/vl-convert-rs/src/converter.rs b/vl-convert-rs/src/converter.rs
index 8f1f21d..3a710ed 100644
--- a/vl-convert-rs/src/converter.rs
+++ b/vl-convert-rs/src/converter.rs
@@ -331,7 +331,8 @@ import('{url}').then((sg) => {{
             style, variant, weight, size, family, text
         }}, null, 2);
 
-        return Deno[Deno.internal].core.ops.op_text_width(text_info)
+        let fullWidth = Deno[Deno.internal].core.ops.op_text_width(text_info);
+        return Math.min(fullWidth, item.limit ?? fullWidth)
     }};
 }})
 "#,


Test patch:
diff --git a/vl-convert-rs/tests/test_specs.rs b/vl-convert-rs/tests/test_specs.rs
index 7e675f9..79b885f 100644
--- a/vl-convert-rs/tests/test_specs.rs
+++ b/vl-convert-rs/tests/test_specs.rs
@@ -648,6 +648,7 @@ mod test_png_no_theme {
         case("quakes_initial_selection", 1.0),
         case("geoScale", 1.0),
         case("table_heatmap", 1.0),
+        case("long_text_lable", 1.0),
     )]
     fn test(
         name: &str,
diff --git a/vl-convert-rs/tests/vl-specs/expected/v5_8/geoScale.png b/vl-convert-rs/tests/vl-specs/expected/v5_8/geoScale.png
index 8da804f..d52b9bb 100644
Binary files a/vl-convert-rs/tests/vl-specs/expected/v5_8/geoScale.png and b/vl-convert-rs/tests/vl-specs/expected/v5_8/geoScale.png differ
diff --git a/vl-convert-rs/tests/vl-specs/expected/v5_8/long_text_lable.png b/vl-convert-rs/tests/vl-specs/expected/v5_8/long_text_lable.png
new file mode 100644
index 0000000..ab10a53
Binary files /dev/null and b/vl-convert-rs/tests/vl-specs/expected/v5_8/long_text_lable.png differ
diff --git a/vl-convert-rs/tests/vl-specs/expected/v5_8/maptile_background.png b/vl-convert-rs/tests/vl-specs/expected/v5_8/maptile_background.png
index 1a1566b..0203546 100644
Binary files a/vl-convert-rs/tests/vl-specs/expected/v5_8/maptile_background.png and b/vl-convert-rs/tests/vl-specs/expected/v5_8/maptile_background.png differ
diff --git a/vl-convert-rs/tests/vl-specs/long_text_lable.vl.json b/vl-convert-rs/tests/vl-specs/long_text_lable.vl.json
new file mode 100644
index 0000000..d2c35af
--- /dev/null
+++ b/vl-convert-rs/tests/vl-specs/long_text_lable.vl.json
@@ -0,0 +1,22 @@
+{
+  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
+  "data": {
+    "values": [
+      {"a": "J", "b": 28, "c": "I'm a very long axis label and eventhough my axis label is cutoff, I'm still rendered in the png"},
+      {"a": "B", "b": 55},
+      {"a": "C", "b": 43},
+      {"a": "D", "b": 91},
+      {"a": "E", "b": 81},
+      {"a": "F", "b": 53},
+      {"a": "G", "b": 19},
+      {"a": "H", "b": 87},
+      {"a": "I", "b": 52}
+    ]
+  },
+  "mark": "bar",
+  "encoding": {
+    "x": {"field": "a", "type": "nominal"},
+    "y": {"field": "c", "type": "nominal"},
+    "color": {"field": "c", "legend": null}
+  }
+}