Commit f5cff40
Rectangles (#168)
* add resolution helper
* Add rect geom with flexible parameter specification
Implements a new rect geom that supports flexible rectangle specification:
- X-direction: any 2 of {x (center), width, xmin, xmax}
- Y-direction: any 2 of {y (center), height, ymin, ymax}
Key features:
- Stat-based parameter consolidation via SQL generation
- Automatic discrete vs continuous scale detection using Schema
- Validates exactly 2 params per direction
- Generates appropriate SQL for all 6 parameter combinations per axis
- Returns different stat columns based on scale type:
- Continuous: pos1min, pos1max, pos2min, pos2max
- Discrete: pos1, pos2 (for band-based rendering)
Implementation follows existing patterns from histogram and bar geoms.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Add rect to grammar and parser
- Add 'rect' to tree-sitter grammar geom_type rule
- Add "rect" case to parser builder geom type mapping
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Fix rect geom: width/height as aesthetics only
Changes:
- Remove width/height from default_params() (use trait default)
- Treat width/height as aesthetics (columns or literals), not parameters
- RectRenderer handles x and y directions independently
- For discrete scales: extract literal width/height from encoding or default to 0.9
- Error if width/height are mapped to variable columns on discrete scales
- Support mixed continuous/discrete (e.g., continuous x + discrete y)
- Extract band size logic into helper function with early returns
- Early return from modify_spec when both directions are continuous
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix: enable scale training for width/height in rect geom
Key changes:
- Add width/height to gets_default_scale() so they get proper scales with domains
instead of Identity scales (which have scale: null)
- Simplify rect.rs stat transform using get_column_name() directly
- Merge discrete checking blocks to build SELECT and stat_columns together
- Refactor RectRenderer to avoid Result<Option<>> anti-pattern
- Flatten nesting with early exits and error closure for DRY
This fixes discrete rect layers with literal width/height (e.g., 0.7 AS width)
by ensuring scales are trained and domains are available for constant detection.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* test: add comprehensive tests for rect geom
Add 10 parameterized tests covering:
- All 6 x-direction parameter combinations (continuous)
- All 6 y-direction parameter combinations (continuous)
- Discrete scales with width/height
- Validation errors (param count, discrete+min/max)
- Group by filtering for width/height
Tests use a grid/loop approach to systematically verify all
rect parameter combinations and error cases.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* tests for the rectrenderer
* fix(rect): preserve non-positional aesthetics in stat transform
The rect stat transform was only including group_by columns in its
SELECT list, causing non-positional aesthetics like fill and color
to be dropped unless they were literal values.
Now uses the schema to determine which columns to pass through:
- Defines consumed aesthetics once (positional params that get transformed)
- Iterates through schema and includes all non-consumed columns
- Eliminates duplicate "consumed columns" logic
Also increases default rect opacity from 0.5 to 0.8 for better visibility.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Revert "add resolution helper"
This reverts commit a0c7092.
* delete tile layer
* feat: default width/height to 1.0 for rect geom
Allow rect to work with just x (or y) specified, defaulting width (or
height) to 1.0 for both discrete and continuous scales.
Changes:
- Split position expression generation into discrete and continuous variants
- generate_discrete_position_expressions: returns (center, size) with
size defaulting to "1.0" when not provided
- generate_continuous_position_expressions: returns (min_expr, max_expr)
with 7 valid parameter combinations including center-only
- Discrete scales: center-only specification defaults to 1.0 bandwidth
- Continuous scales: center-only specification defaults to width=1.0
(xmin = x - 0.5, xmax = x + 0.5)
- Improved variable naming: x_expr_1/x_expr_2 instead of x_expr_min/x_expr_max
to reflect dual usage (center/size for discrete, min/max for continuous)
- Updated tests to verify default behavior
All 18 rect tests passing.
* feat: support SETTING width/height for rect geom
Add support for specifying width/height via SETTING clause in addition to
MAPPING. Implements precedence: MAPPING > SETTING > default 1.0.
Changes:
- stat_rect now checks both aesthetics (MAPPING) and parameters (SETTING)
for width/height values
- Uses ParameterValue::to_string() to convert SETTING values to SQL literals
- Precedence order ensures MAPPING columns take priority over SETTING literals,
which take priority over default 1.0
- Stat transform happens before resolve_aesthetics(), so we check parameters
directly rather than relying on aesthetic resolution
Example usage:
DRAW rect MAPPING x AS x, ymin AS ymin, ymax AS ymax SETTING width => 0.8
All 19 rect tests passing.
* refactor: unify x/y direction logic in rect stat transform
Extract duplicated x and y direction logic into a single process_direction
helper function that handles both axes.
Changes:
- New process_direction() function processes a single direction
- Takes only axis ("x" or "y"), derives all aesthetic names from it
- Returns SELECT parts and stat column names
- Handles both discrete and continuous cases
- Determine stat_cols first, then format SELECT parts outside if-block
to eliminate duplication of format! calls
- stat_rect() now calls process_direction() twice (once for x, once for y)
- Eliminates ~100 lines of duplicated logic
Call sites simplified from:
process_direction("pos1", "pos1min", "pos1max", "width", "width", "x", ...)
to:
process_direction("x", aesthetics, parameters, schema)
Net reduction: 26 lines (114 deletions, 88 additions)
All 19 rect tests passing.
* add docs
* cargo fmt
* add position parameter
* update docs
* simplify discrete variable widths
* remove accidentally committed file
* cargo fmt
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 63492a8 commit f5cff40
15 files changed
Lines changed: 1343 additions & 68 deletions
File tree
- doc
- syntax/layer/type
- ggsql-vscode/syntaxes
- src
- parser
- plot
- layer/geom
- scale
- reader
- writer/vegalite
- tree-sitter-ggsql
- queries
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| |||
1200 | 1200 | | |
1201 | 1201 | | |
1202 | 1202 | | |
1203 | | - | |
| 1203 | + | |
1204 | 1204 | | |
1205 | 1205 | | |
1206 | 1206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
605 | | - | |
| 605 | + | |
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
0 commit comments