Skip to content

Commit fcf8c82

Browse files
authored
Fix vegalite legends (#119)
1 parent 4f8f280 commit fcf8c82

4 files changed

Lines changed: 1053 additions & 33 deletions

File tree

doc/syntax/scale/type/binned.qmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ Besides direct renaming you can also provide a formatting string if you want the
155155

156156
You can combine formatting with direct renaming in which case the direct renaming has priority over the formatting.
157157

158+
### Labels in binned legends
159+
With some writers the legend for binned scales looks like the standard legend but with the label showing the range of the bin. In these situations the renaming is applied before the range label is being created. For example, if you have a `RENAMING 0 => 'zero'`, then the final label will become "zero – 10" (assuming the upper end of the bin is 10). There is currently no way to take control over the format of the range label.
160+
161+
If `oob => 'squish'` then the terminal labels are formatted as e.g. "≥ 10" to reflect the terminal bins are open-ended. It still applies that the renaming is applied before constructing the final label
162+
158163
### Examples
159164

160165
#### Rename a select break

ggsql-jupyter/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn format_vegalite(spec: String) -> Value {
6969
paths: {{
7070
'dom-ready': 'https://cdn.jsdelivr.net/npm/domready@1/ready.min',
7171
'vega': 'https://cdn.jsdelivr.net/npm/vega@6/build/vega.min',
72-
'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@6/build/vega-lite.min',
72+
'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@6.4.1/build/vega-lite.min',
7373
'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@7/build/vega-embed.min'
7474
}}
7575
}});
@@ -101,7 +101,7 @@ fn format_vegalite(spec: String) -> Value {
101101
102102
Promise.all([
103103
loadScript('https://cdn.jsdelivr.net/npm/vega@6'),
104-
loadScript('https://cdn.jsdelivr.net/npm/vega-lite@6'),
104+
loadScript('https://cdn.jsdelivr.net/npm/vega-lite@6.4.1'),
105105
loadScript('https://cdn.jsdelivr.net/npm/vega-embed@7')
106106
])
107107
.then(() => {{

src/plot/scale/scale_type/binned.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,14 @@ impl ScaleTypeTrait for Binned {
429429
breaks.first().unwrap().clone(),
430430
breaks.last().unwrap().clone(),
431431
];
432-
let expanded = expand_numeric_range(&terminal_range, mult, add);
433-
new_input_range = Some(expanded);
432+
// Only expand for positional aesthetics (x, y, etc.)
433+
// Non-positional aesthetics (color, fill, size) don't get expansion
434+
let final_range = if super::is_positional_aesthetic(aesthetic) {
435+
expand_numeric_range(&terminal_range, mult, add)
436+
} else {
437+
terminal_range
438+
};
439+
new_input_range = Some(final_range);
434440
}
435441

436442
// Update the breaks in the scale

0 commit comments

Comments
 (0)