1010SELECT date , revenue, region FROM sales WHERE year = 2024
1111VISUALISE date AS x, revenue AS y, region AS color
1212DRAW line
13- SCALE x SETTING type => ' date'
13+ SCALE x VIA date
1414COORD cartesian SETTING ylim => [0 , 100000 ]
1515LABEL title => ' Sales by Region' , x => ' Date' , y => ' Revenue'
1616THEME minimal
@@ -243,7 +243,7 @@ For detailed API documentation, see [`src/doc/API.md`](src/doc/API.md).
243243
244244- Uses ` tree-sitter-ggsql ` grammar (507 lines, simplified approach)
245245- Parses ** full query** (SQL + VISUALISE) into concrete syntax tree (CST)
246- - Grammar supports: PLOT/TABLE/MAP types, DRAW/SCALE/FACET/COORD/LABEL/GUIDE/ THEME clauses
246+ - Grammar supports: PLOT/TABLE/MAP types, DRAW/SCALE/FACET/COORD/LABEL/THEME clauses
247247- British and American spellings: ` VISUALISE ` / ` VISUALIZE `
248248- ** SQL portion parsing** : Basic SQL structure (SELECT, WITH, CREATE, INSERT, subqueries)
249249- ** Recursive subquery support** : Fully recursive grammar for complex SQL
@@ -288,7 +288,6 @@ pub struct Plot {
288288 pub facet : Option <Facet >, // FACET clause
289289 pub coord : Option <Coord >, // COORD clause
290290 pub labels : Option <Labels >, // LABEL clause
291- pub guides : Vec <Guide >, // GUIDE clauses
292291 pub theme : Option <Theme >, // THEME clause
293292}
294293
@@ -395,19 +394,6 @@ pub struct Labels {
395394 pub labels : HashMap <String , String >, // label type → text
396395}
397396
398- pub struct Guide {
399- pub aesthetic : String ,
400- pub guide_type : Option <GuideType >,
401- pub properties : HashMap <String , ParameterValue >,
402- }
403-
404- pub enum GuideType {
405- Legend ,
406- ColorBar ,
407- Axis ,
408- None ,
409- }
410-
411397pub struct Theme {
412398 pub style : Option <String >,
413399 pub properties : HashMap <String , ParameterValue >,
@@ -421,7 +407,6 @@ pub struct Theme {
421407- ` Plot::new() ` - Create a new empty Plot
422408- ` Plot::with_global_mapping(mapping) ` - Create Plot with a global mapping
423409- ` Plot::find_scale(aesthetic) ` - Look up scale specification for an aesthetic
424- - ` Plot::find_guide(aesthetic) ` - Find a guide specification for an aesthetic
425410- ` Plot::has_layers() ` - Check if Plot has any layers
426411- ` Plot::layer_count() ` - Get the number of layers
427412
@@ -781,7 +766,7 @@ SELECT * FROM (VALUES
781766SELECT * FROM sales
782767VISUALISE
783768DRAW line MAPPING date AS x, revenue AS y, region AS color
784- SCALE x SETTING type => ' date'
769+ SCALE x VIA date
785770LABEL title => ' Sales Trends'
786771```
787772
@@ -1093,16 +1078,15 @@ Where `<global_mapping>` can be:
10931078
10941079### Clause Types
10951080
1096- | Clause | Repeatable | Purpose | Example |
1097- | ----------- | ---------- | ------------------ | ----------------------------------------- |
1098- | ` VISUALISE ` | ✅ Yes | Entry point | ` VISUALISE date AS x, revenue AS y ` |
1099- | ` DRAW ` | ✅ Yes | Define layers | ` DRAW line MAPPING date AS x, value AS y ` |
1100- | ` SCALE ` | ✅ Yes | Configure scales | ` SCALE x SETTING type => 'date' ` |
1101- | ` FACET ` | ❌ No | Small multiples | ` FACET WRAP region ` |
1102- | ` COORD ` | ❌ No | Coordinate system | ` COORD cartesian SETTING xlim => [0,100] ` |
1103- | ` LABEL ` | ❌ No | Text labels | ` LABEL title => 'My Chart', x => 'Date' ` |
1104- | ` GUIDE ` | ✅ Yes | Legend/axis config | ` GUIDE color SETTING position => 'right' ` |
1105- | ` THEME ` | ❌ No | Visual styling | ` THEME minimal ` |
1081+ | Clause | Repeatable | Purpose | Example |
1082+ | -------------- | ---------- | ------------------ | ------------------------------------ |
1083+ | ` VISUALISE ` | ✅ Yes | Entry point | ` VISUALISE date AS x, revenue AS y ` |
1084+ | ` DRAW ` | ✅ Yes | Define layers | ` DRAW line MAPPING date AS x, value AS y ` |
1085+ | ` SCALE ` | ✅ Yes | Configure scales | ` SCALE x VIA date ` |
1086+ | ` FACET ` | ❌ No | Small multiples | ` FACET WRAP region ` |
1087+ | ` COORD ` | ❌ No | Coordinate system | ` COORD cartesian SETTING xlim => [0,100] ` |
1088+ | ` LABEL ` | ❌ No | Text labels | ` LABEL title => 'My Chart', x => 'Date' ` |
1089+ | ` THEME ` | ❌ No | Visual styling | ` THEME minimal ` |
11061090
11071091### DRAW Clause (Layers)
11081092
@@ -1214,49 +1198,79 @@ DRAW line
12141198** Syntax** :
12151199
12161200``` sql
1217- SCALE < aesthetic> SETTING
1218- [type => < scale_type> ]
1219- [limits => [min, max]]
1220- [breaks => < array | interval> ]
1221- [palette => < name> ]
1222- [domain => [values ...]]
1201+ SCALE [TYPE] < aesthetic> [FROM < input> ] [TO < output> ] [VIA < transform> ] [SETTING < properties> ]
12231202```
12241203
1225- ** Scale Types ** :
1204+ ** Type Modifiers ** (optional, placed before aesthetic) :
12261205
1227- - ** Continuous** : ` linear ` , ` log10 ` , ` log ` , ` log2 ` , ` sqrt ` , ` reverse `
1228- - ** Discrete** : ` categorical ` , ` ordinal `
1229- - ** Temporal** : ` date ` , ` datetime ` , ` time `
1230- - ** Color Palettes** : ` viridis ` , ` plasma ` , ` magma ` , ` inferno ` , ` cividis ` , ` diverging ` , ` sequential `
1206+ - ** ` CONTINUOUS ` ** - Continuous numeric data
1207+ - ** ` DISCRETE ` ** - Categorical/discrete data
1208+ - ** ` BINNED ` ** - Binned/bucketed data
1209+ - ** ` DATE ` ** - Date data (maps to Vega-Lite temporal type)
1210+ - ** ` DATETIME ` ** - Datetime data (maps to Vega-Lite temporal type)
1211+
1212+ ** Subclauses** :
1213+
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 ` )
1216+ - ** ` VIA transform ` ** - Transformation method (reserved for future use)
1217+ - ** ` SETTING ... ` ** - Additional properties (e.g., ` breaks ` )
1218+
1219+ ** Named Palettes** (used with ` TO ` ):
1220+
1221+ - ` viridis ` , ` plasma ` , ` magma ` , ` inferno ` , ` cividis ` , ` diverging ` , ` sequential `
12311222
12321223** Critical for Date Formatting** :
12331224
12341225``` sql
1235- SCALE x SETTING type => ' date'
1226+ SCALE x VIA date
12361227-- Maps to Vega-Lite field type = "temporal"
12371228-- Enables proper date axis formatting
12381229```
12391230
1240- ** Domain Property ** :
1231+ ** Input Range Specification ** (FROM clause) :
12411232
1242- The ` domain ` property explicitly sets the input domain for a scale:
1233+ The ` FROM ` clause explicitly sets the input range for a scale:
12431234
12441235``` sql
1245- -- Set domain for discrete scale
1246- SCALE color SETTING domain => [ ' red ' , ' green ' , ' blue ' ]
1236+ -- Set range for discrete scale
1237+ SCALE DISCRETE color FROM [ ' A ' , ' B ' , ' C ' ]
12471238
1248- -- Set domain for continuous scale
1249- SCALE x SETTING domain => [0 , 100 ]
1239+ -- Set range for continuous scale
1240+ SCALE CONTINUOUS x FROM [0 , 100 ]
12501241```
12511242
1252- ** Note ** : Cannot specify domain in both SCALE and COORD for the same aesthetic (will error).
1243+ ** Range Specification ** (TO clause):
12531244
1254- ** Example ** :
1245+ The ` TO ` clause sets the output range - either explicit values or a named palette :
12551246
12561247``` sql
1257- SCALE x SETTING type => ' date' , breaks => ' 2 months'
1258- SCALE y SETTING type => ' log10' , limits => [1 , 1000 ]
1259- SCALE color SETTING palette => ' viridis' , domain => [' A' , ' B' , ' C' ]
1248+ -- Explicit color values
1249+ SCALE color FROM [' A' , ' B' ] TO [' red' , ' blue' ]
1250+
1251+ -- Named palette
1252+ SCALE color TO viridis
1253+ ```
1254+
1255+ ** Note** : Cannot specify range in both SCALE and COORD for the same aesthetic (will error).
1256+
1257+ ** Examples** :
1258+
1259+ ``` sql
1260+ -- Date scale
1261+ SCALE x VIA date
1262+
1263+ -- Continuous scale with input range
1264+ SCALE CONTINUOUS y FROM [0 , 100 ]
1265+
1266+ -- Discrete color scale with input range and output range
1267+ SCALE DISCRETE color FROM [' A' , ' B' , ' C' ] TO [' red' , ' green' , ' blue' ]
1268+
1269+ -- Color scale with named palette
1270+ SCALE color TO viridis
1271+
1272+ -- Scale with input range and additional settings
1273+ SCALE x VIA date FROM [' 2024-01-01' , ' 2024-12-31' ] SETTING breaks => ' 1 month'
12601274```
12611275
12621276### FACET Clause
@@ -1313,22 +1327,22 @@ COORD SETTING <properties>
13131327
13141328- ` xlim => [min, max] ` - Set x-axis limits
13151329- ` ylim => [min, max] ` - Set y-axis limits
1316- - ` <aesthetic> => [values...] ` - Set domain for any aesthetic (color, fill, size, etc.)
1330+ - ` <aesthetic> => [values...] ` - Set range for any aesthetic (color, fill, size, etc.)
13171331
13181332** Flip** :
13191333
1320- - ` <aesthetic> => [values...] ` - Set domain for any aesthetic
1334+ - ` <aesthetic> => [values...] ` - Set range for any aesthetic
13211335
13221336** Polar** :
13231337
13241338- ` theta => <aesthetic> ` - Which aesthetic maps to angle (defaults to ` y ` )
1325- - ` <aesthetic> => [values...] ` - Set domain for any aesthetic
1339+ - ` <aesthetic> => [values...] ` - Set range for any aesthetic
13261340
13271341** Important Notes** :
13281342
132913431 . ** Axis limits auto-swap** : ` xlim => [100, 0] ` automatically becomes ` [0, 100] `
133013442 . ** ggplot2 compatibility** : ` coord_flip ` preserves axis label names (labels stay with aesthetic names, not visual position)
1331- 3 . ** Domain conflicts** : Error if same aesthetic has domain in both SCALE and COORD
1345+ 3 . ** Range conflicts** : Error if same aesthetic has input range in both SCALE and COORD
133213464 . ** Multi-layer support** : All coordinate transforms apply to all layers
13331347
13341348** Status** :
@@ -1344,7 +1358,7 @@ COORD SETTING <properties>
13441358-- Cartesian with axis limits
13451359COORD cartesian SETTING xlim => [0 , 100 ], ylim => [0 , 50 ]
13461360
1347- -- Cartesian with aesthetic domain
1361+ -- Cartesian with aesthetic range
13481362COORD cartesian SETTING color => O [' red' , ' green' , ' blue' ]
13491363
13501364-- Cartesian shorthand (type optional when using SETTING)
@@ -1353,7 +1367,7 @@ COORD SETTING xlim => [0, 100]
13531367-- Flip coordinates for horizontal bar chart
13541368COORD flip
13551369
1356- -- Flip with aesthetic domain
1370+ -- Flip with aesthetic range
13571371COORD flip SETTING color => [' A' , ' B' , ' C' ]
13581372
13591373-- Polar for pie chart (theta defaults to y)
@@ -1427,7 +1441,7 @@ DRAW line
14271441 MAPPING sale_date AS x, total AS y, region AS color
14281442DRAW point
14291443 MAPPING sale_date AS x, total AS y, region AS color
1430- SCALE x SETTING type => ' date'
1444+ SCALE x VIA date
14311445FACET WRAP region
14321446LABEL title => ' Sales Trends by Region' , x => ' Date' , y => ' Total Quantity'
14331447THEME minimal
0 commit comments