Skip to content

Commit

Permalink
Apply limit to text width measurements (#153)
Browse files Browse the repository at this point in the history
* ignore pixi config

* limit measured text width to configured limit

* update osm baselines
  • Loading branch information
jonmmease authored Feb 26, 2024
1 parent 651da69 commit 54acd94
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion vl-convert-rs/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}};
}})
"#,
Expand Down
1 change: 1 addition & 0 deletions vl-convert-rs/tests/test_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file modified vl-convert-rs/tests/vl-specs/expected/v5_8/geoScale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions vl-convert-rs/tests/vl-specs/long_text_lable.vl.json
Original file line number Diff line number Diff line change
@@ -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}
}
}

0 comments on commit 54acd94

Please sign in to comment.