Skip to content

Commit a64310f

Browse files
committed
Add gridded heatmap guidance to VegaLiteAgent prompt
1 parent 43e7574 commit a64310f

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

lumen/ai/prompts/VegaLiteAgent/main.jinja2

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Legends appear when you map data to `color`, `size`, or `shape` in encoding.
5858
**Geographic maps**: Use `longitude`/`latitude` encodings (NOT `x`/`y`) with `projection: {type: mercator}` at top level. Base map added automatically.
5959

6060
**Choropleth maps**: Join data to map boundaries - `lookup: <map_field>`, `from: {data: {...}, key: <your_field>, fields: [...]}` (key/fields inside from!)
61+
{%- if gridded is defined and gridded %}
62+
63+
**Gridded xarray data**: The data is a long-form grid from an xarray dataset.
64+
- dimensions: {{ gridded.dims | join(', ') }}
65+
- data variables: {{ gridded.data_vars | join(', ') }}
66+
Use `mark: rect` with x/y mapped to coordinate dimensions and color mapped to the value column.
67+
Do not use `longitude`/`latitude` encodings or geographic projections for this data.
68+
{%- endif %}
6169
{% endblock %}
6270

6371
{% block examples %}
@@ -203,6 +211,26 @@ layer:
203211
color: {field: category, type: nominal, legend: {title: "Category", orient: "right"}}
204212
```
205213

214+
{%- if gridded is defined and gridded %}
215+
Gridded heatmap (xarray-derived long-form data):
216+
```yaml
217+
data:
218+
name: <TABLE_NAME>
219+
layer:
220+
- mark: rect
221+
encoding:
222+
x: {field: {{ gridded.dims[1] if gridded.dims | length > 1 else gridded.dims[0] }}, type: ordinal}
223+
y: {field: {{ gridded.dims[0] }}, type: ordinal}
224+
color:
225+
field: {{ gridded.data_vars[0] }}
226+
type: quantitative
227+
scale: {scheme: viridis}
228+
legend: {title: "{{ gridded.data_vars[0] }}"}
229+
config:
230+
view: {stroke: null}
231+
```
232+
{%- endif %}
233+
206234
Choropleth map:
207235
```yaml
208236
data:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import datetime
2+
3+
from lumen.ai.config import PROMPTS_DIR
4+
from lumen.ai.utils import render_template
5+
6+
7+
def _base_context(gridded=None):
8+
class _FakeSource:
9+
dialect = None
10+
11+
class _FakePipeline:
12+
table = "air"
13+
source = _FakeSource()
14+
15+
class _FakeMemory(dict):
16+
pass
17+
18+
memory = _FakeMemory({
19+
"pipeline": _FakePipeline(),
20+
"data": "lat,lon,air\n0,10,1.0",
21+
"table": "air",
22+
})
23+
return dict(
24+
memory=memory,
25+
doc="VegaLiteView description",
26+
gridded=gridded,
27+
current_datetime=datetime.datetime(2026, 1, 1),
28+
actor_name="VegaLiteAgent",
29+
)
30+
31+
32+
def test_vegalite_prompt_includes_gridded_block():
33+
gridded = {
34+
"source_type": "xarray",
35+
"dims": ["lat", "lon"],
36+
"coords": {"lat": [3], "lon": [4]},
37+
"data_vars": ["air"],
38+
}
39+
rendered = render_template(
40+
PROMPTS_DIR / "VegaLiteAgent" / "main.jinja2",
41+
**_base_context(gridded=gridded),
42+
)
43+
assert "mark: rect" in rendered
44+
assert "viridis" in rendered
45+
assert "lat" in rendered
46+
assert "air" in rendered
47+
48+
49+
def test_vegalite_prompt_no_gridded_block_for_tabular():
50+
rendered = render_template(
51+
PROMPTS_DIR / "VegaLiteAgent" / "main.jinja2",
52+
**_base_context(gridded=None),
53+
)
54+
assert "Gridded xarray data" not in rendered
55+
assert "Gridded heatmap" not in rendered

0 commit comments

Comments
 (0)