Skip to content

Commit 31c0831

Browse files
authored
Support parentheses for lists in grammar (#312)
1 parent 8d43ffc commit 31c0831

27 files changed

Lines changed: 250 additions & 113 deletions

File tree

CLAUDE.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SELECT date, revenue, region FROM sales WHERE year = 2024
1111
VISUALISE date AS x, revenue AS y, region AS color
1212
DRAW line
1313
SCALE x VIA date
14-
SCALE y FROM [0, 100000]
14+
SCALE y FROM (0, 100000)
1515
LABEL title => 'Sales by Region', x => 'Date', y => 'Revenue'
1616
```
1717

@@ -1186,7 +1186,7 @@ Creates annotation layers with literal values only (no data mappings). All aesth
11861186
PLACE point SETTING x => 5, y => 10, color => 'red'
11871187

11881188
-- Multiple annotations (array recycling)
1189-
PLACE point SETTING x => [1, 2, 3], y => [10, 20, 30]
1189+
PLACE point SETTING x => (1, 2, 3), y => (10, 20, 30)
11901190

11911191
-- Reference line
11921192
PLACE rule SETTING x => 5, color => 'red'
@@ -1211,8 +1211,8 @@ SCALE [TYPE] <aesthetic> [FROM <input>] [TO <output>] [VIA <transform>]
12111211

12121212
**Subclauses**:
12131213

1214-
- **`FROM [...]`** - Input range specification (maps to Vega-Lite `scale.domain`)
1215-
- **`TO [...]`** or **`TO palette`** - Output range as array or named palette (maps to Vega-Lite `scale.range` or `scale.scheme`)
1214+
- **`FROM (...)`** - Input range specification (maps to Vega-Lite `scale.domain`). Square brackets `[...]` are also accepted.
1215+
- **`TO (...)`** or **`TO palette`** - Output range as array or named palette (maps to Vega-Lite `scale.range` or `scale.scheme`). Square brackets `[...]` are also accepted.
12161216
- **`VIA transform`** - Transformation method (reserved for future use)
12171217
- **`SETTING ...`** - Additional properties (e.g., `breaks`)
12181218

@@ -1234,10 +1234,10 @@ The `FROM` clause explicitly sets the input range for a scale:
12341234

12351235
```sql
12361236
-- Set range for discrete scale
1237-
SCALE DISCRETE color FROM ['A', 'B', 'C']
1237+
SCALE DISCRETE color FROM ('A', 'B', 'C')
12381238

12391239
-- Set range for continuous scale
1240-
SCALE CONTINUOUS x FROM [0, 100]
1240+
SCALE CONTINUOUS x FROM (0, 100)
12411241
```
12421242

12431243
**Range Specification** (TO clause):
@@ -1246,7 +1246,7 @@ The `TO` clause sets the output range - either explicit values or a named palett
12461246

12471247
```sql
12481248
-- Explicit color values
1249-
SCALE color FROM ['A', 'B'] TO ['red', 'blue']
1249+
SCALE color FROM ('A', 'B') TO ('red', 'blue')
12501250

12511251
-- Named palette
12521252
SCALE color TO viridis
@@ -1259,16 +1259,16 @@ SCALE color TO viridis
12591259
SCALE x VIA date
12601260

12611261
-- Continuous scale with input range
1262-
SCALE CONTINUOUS y FROM [0, 100]
1262+
SCALE CONTINUOUS y FROM (0, 100)
12631263

12641264
-- Discrete color scale with input range and output range
1265-
SCALE DISCRETE color FROM ['A', 'B', 'C'] TO ['red', 'green', 'blue']
1265+
SCALE DISCRETE color FROM ('A', 'B', 'C') TO ('red', 'green', 'blue')
12661266

12671267
-- Color scale with named palette
12681268
SCALE color TO viridis
12691269

12701270
-- Scale with input range and additional settings
1271-
SCALE x VIA date FROM ['2024-01-01', '2024-12-31']
1271+
SCALE x VIA date FROM ('2024-01-01', '2024-12-31')
12721272
SETTING breaks => '1 month'
12731273
```
12741274

@@ -1297,7 +1297,7 @@ FACET <row_vars> BY <col_vars>
12971297
- `null` or omitted (default) - Shared/fixed scales across all facets
12981298
- `'x'` - Independent x-axis, shared y-axis
12991299
- `'y'` - Shared x-axis, independent y-axis
1300-
- `['x', 'y']` - Independent scales for both axes
1300+
- `('x', 'y')` - Independent scales for both axes
13011301

13021302
**Customizing Strip Labels**:
13031303

@@ -1327,7 +1327,7 @@ SCALE panel
13271327

13281328
-- Combined grid with settings
13291329
FACET region BY category
1330-
SETTING free => ['x', 'y'], spacing => 10
1330+
SETTING free => ('x', 'y'), spacing => 10
13311331
```
13321332

13331333
### PROJECT Clause
@@ -1372,16 +1372,16 @@ PROJECT y, x TO cartesian
13721372

13731373
- `ratio => <number>` - Set aspect ratio (not yet implemented)
13741374

1375-
Note: For axis limits, use `SCALE x FROM [min, max]` or `SCALE y FROM [min, max]`.
1375+
Note: For axis limits, use `SCALE x FROM (min, max)` or `SCALE y FROM (min, max)`.
13761376

13771377
**Polar**:
13781378

13791379
- No special properties (angle/radius aesthetics are used directly)
13801380

13811381
**Important Notes**:
13821382

1383-
1. **Axis limits**: Use `SCALE x/y FROM [min, max]` to set axis limits
1384-
2. **Aesthetic domains**: Use `SCALE <aesthetic> FROM [...]` to set aesthetic domains
1383+
1. **Axis limits**: Use `SCALE x/y FROM (min, max)` to set axis limits
1384+
2. **Aesthetic domains**: Use `SCALE <aesthetic> FROM (...)` to set aesthetic domains
13851385
3. **Custom aesthetics**: User can define custom position names (e.g., `PROJECT a, b TO cartesian`)
13861386
4. **Multi-layer support**: All projection transforms apply to all layers
13871387

@@ -1421,8 +1421,8 @@ PROJECT TO cartesian
14211421
-- Combined with other clauses
14221422
DRAW bar
14231423
MAPPING category AS x, value AS y
1424-
SCALE x FROM [0, 100]
1425-
SCALE y FROM [0, 200]
1424+
SCALE x FROM (0, 100)
1425+
SCALE y FROM (0, 200)
14261426
PROJECT y, x TO cartesian
14271427
SETTING clip => true
14281428
LABEL x => 'Category', y => 'Count'

doc/gallery/examples/heatmap.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ FROM ggsql:airquality
5252
5353
VISUALISE Month AS y, Day AS x, centered AS fill
5454
DRAW rect
55-
SCALE fill FROM [-20, 20] TO vik
55+
SCALE fill FROM (-20, 20) TO vik
5656
```

doc/gallery/examples/minard.qmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
114114
DRAW path
115115
MAPPING direction AS stroke, survivors AS linewidth
116116
PARTITION BY direction, group
117-
SCALE stroke TO ['burlywood', 'black']
117+
SCALE stroke TO ('burlywood', 'black')
118118
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
119119
```
120120

121121
Now for a slightly more complicated scale, we're going to set one for the `linewidth` variable that represent the number of troops.
122122
If you want to build in some extra intuition for the scale, you can let 0 troops coincide with 0 linewidth.
123-
We define the output range using `TO [0, 20]` because for a continuous variable it expects the output limits.
124-
Slightly more elaborate is the input domain, where we use `FROM [0, null]` to state that the scale should start at 0 and go up to the largest value in the data.
123+
We define the output range using `TO (0, 20)` because for a continuous variable it expects the output limits.
124+
Slightly more elaborate is the input domain, where we use `FROM (0, null)` to state that the scale should start at 0 and go up to the largest value in the data.
125125
Because both the input and output ranges start at 0, we get a well-proportioned line.
126126

127127
```{ggsql}
128128
VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
129129
DRAW path
130130
MAPPING direction AS stroke, survivors AS linewidth
131131
PARTITION BY direction, group
132-
SCALE stroke TO ['burlywood', 'black']
132+
SCALE stroke TO ('burlywood', 'black')
133133
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
134-
SCALE linewidth FROM [0, null] TO [0, 20]
134+
SCALE linewidth FROM (0, null) TO (0, 20)
135135
```
136136

137137
## Polishing
@@ -153,9 +153,9 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
153153
DRAW text
154154
MAPPING city AS label FROM 'minard_cities.csv'
155155
SETTING fontsize => 6
156-
SCALE stroke TO ['burlywood', 'black']
156+
SCALE stroke TO ('burlywood', 'black')
157157
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
158-
SCALE linewidth FROM [0, null] TO [0, 30]
158+
SCALE linewidth FROM (0, null) TO (0, 30)
159159
```
160160

161161
An additional obvious way to polish your graphic is to add nicer titles for all your variables.
@@ -172,9 +172,9 @@ VISUALISE long AS x, lat AS y FROM 'minard_troops.csv'
172172
DRAW text
173173
MAPPING city AS label FROM 'minard_cities.csv'
174174
SETTING fontsize => 6
175-
SCALE stroke TO ['burlywood', 'black']
175+
SCALE stroke TO ('burlywood', 'black')
176176
RENAMING 'A' => 'Advance', 'R' => 'Retreat'
177-
SCALE linewidth FROM [0, null] TO [0, 20]
177+
SCALE linewidth FROM (0, null) TO (0, 20)
178178
LABEL
179179
title => 'Napoleon\'s Russian Campaign',
180180
subtitle => 'Inspired by the graphic of C.J. Minard',

doc/gallery/examples/scatterplot.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The color palette can be changed by detailing the `SCALE color` clause.
4747
```{ggsql}
4848
VISUALISE bill_len AS x, bill_dep AS y, species AS color FROM ggsql:penguins
4949
DRAW point
50-
SCALE color TO ['DeepSkyBlue', 'Fuchsia', 'Lime']
50+
SCALE color TO ('DeepSkyBlue', 'Fuchsia', 'Lime')
5151
LABEL
5252
title => 'Penguin Bill Dimensions by Species',
5353
x => 'Bill Length (mm)',

doc/get_started/anatomy.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ As [described above](#scales), ggsql automatically creates a default for mapped
6464
The clause allows you to set the type of scale, the input range, the output range, the transformation, and lets you control breaks and label formatting. So, the clause can end up with a lot of information but the syntax has been designed so it reads very natural. Further, every part is optional and can be left out if the default fits. An example of a rather complex `SCALE` clause could be:
6565

6666
```ggsql
67-
SCALE ORDINAL fill FROM ['Low', 'Mid', 'High'] TO viridis
67+
SCALE ORDINAL fill FROM ('Low', 'Mid', 'High') TO viridis
6868
SETTING breaks => 6
6969
```
7070

@@ -85,7 +85,7 @@ DRAW point
8585
DRAW smooth
8686
SETTING method => 'ols'
8787
SCALE stroke TO dark2
88-
SCALE BINNED size TO [4, 15]
88+
SCALE BINNED size TO (4, 15)
8989
SETTING breaks => 4
9090
```
9191

doc/get_started/the_rest.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ DRAW bar
9999
PROJECT TO polar
100100
FACET island
101101
SETTING free => 'angle'
102-
SCALE panel FROM ['Biscoe', 'Dream']
102+
SCALE panel FROM ('Biscoe', 'Dream')
103103
```
104104

105105
Above, we use the `free` parameter of facet to allow each facet to have their own angle scale. Further, we use `SCALE` on the panel aesthetic to only show panels for the Biscoe and Dream islands.
@@ -112,7 +112,7 @@ DRAW bar
112112
PROJECT TO polar
113113
FACET island
114114
SETTING free => 'angle'
115-
SCALE panel FROM ['Biscoe', 'Dream']
115+
SCALE panel FROM ('Biscoe', 'Dream')
116116
LABEL
117117
title => 'Distribution of penguin species between islands',
118118
subtitle => 'Compared across 344 penguins',

doc/syntax/layer/type/line.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ WITH data(x, y, z) AS (VALUES
7373
VISUALISE x, y FROM data
7474
DRAW line
7575
MAPPING z AS stroke
76-
SCALE stroke TO ['red', 'green', 'blue']
76+
SCALE stroke TO ('red', 'green', 'blue')
7777
```
7878

7979
The `linewidth` aesthetic can vary point to point.
@@ -88,5 +88,5 @@ WITH data(x, y, z) AS (VALUES
8888
VISUALISE x, y FROM data
8989
DRAW line
9090
MAPPING z AS linewidth
91-
SCALE linewidth TO [0, 30]
91+
SCALE linewidth TO (0, 30)
9292
```

doc/syntax/layer/type/path.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ WITH data(x, y, z) AS (VALUES
102102
VISUALISE x, y FROM data
103103
DRAW path
104104
MAPPING z AS stroke
105-
SCALE stroke TO ['red', 'green', 'blue']
105+
SCALE stroke TO ('red', 'green', 'blue')
106106
```
107107

108108
The `linewidth` aesthetic can vary point to point.
@@ -117,5 +117,5 @@ WITH data(x, y, z) AS (VALUES
117117
VISUALISE x, y FROM data
118118
DRAW path
119119
MAPPING z AS linewidth
120-
SCALE linewidth TO [0, 30]
120+
SCALE linewidth TO (0, 30)
121121
```

doc/syntax/layer/type/text.qmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ DRAW text
100100
opacity => 0.8,
101101
fontweight => 'bold',
102102
typeface => 'Times New Roman'
103-
SCALE fontsize TO [6, 20]
103+
SCALE fontsize TO (6, 20)
104104
```
105105

106106
The 'stroke' aesthetic is applied to the outline of the text.
@@ -120,7 +120,7 @@ VISUALISE island AS x, n AS y
120120
DRAW bar
121121
DRAW text
122122
MAPPING n AS label
123-
SETTING vjust => 'top', offset => [0, -11], fill => 'white'
123+
SETTING vjust => 'top', offset => (0, -11), fill => 'white'
124124
```
125125

126126
If you label bars at the extreme end, you may need to expand the scale to accommodate the labels.
@@ -131,8 +131,8 @@ VISUALISE island AS x, n AS y
131131
DRAW bar
132132
DRAW text
133133
MAPPING n AS label
134-
SETTING vjust => 'bottom', offset => [0, 11]
135-
SCALE y FROM [0, 200]
134+
SETTING vjust => 'bottom', offset => (0, 11)
135+
SCALE y FROM (0, 200)
136136
```
137137

138138
You can use `PLACE` to annotate a plot directly without needing to map data.
@@ -142,7 +142,7 @@ VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins
142142
DRAW point MAPPING species AS colour
143143
PLACE text
144144
SETTING
145-
label => ['Adelie', 'Chinstrap', 'Gentoo'],
146-
x => [40, 50, 50],
147-
y => [19, 19, 15]
145+
label => ('Adelie', 'Chinstrap', 'Gentoo'),
146+
x => (40, 50, 50),
147+
y => (19, 19, 15)
148148
```

doc/syntax/scale/aesthetic/1_color.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DRAW line
5050
when you define the output range of a fill or stroke scale manually, e.g.
5151

5252
```ggsql
53-
SCALE fill TO ['rgb(100%, 0%, 0%)', 'lemonchiffon']
53+
SCALE fill TO ('rgb(100%, 0%, 0%)', 'lemonchiffon')
5454
```
5555

5656
or when using an identity scale for color in which case the data values must be parsable as colors.
@@ -79,7 +79,7 @@ VISUALISE FROM ggsql:penguins
7979
DRAW point
8080
MAPPING bill_dep AS x, body_mass AS y, flipper_len AS fill
8181
SETTING stroke => null
82-
SCALE color TO ['antiquewhite', 'firebrick']
82+
SCALE color TO ('antiquewhite', 'firebrick')
8383
```
8484

8585
### Continuous palettes

0 commit comments

Comments
 (0)