Which fields can contain param references when using parseSpec? #261
-
I try to dynamically update the const kpi = vg.Param.value("visits")
const globalSelection = vg.Selection.single();
const specs = {
mark: "lineY",
data: {
from: "kpis",
filterBy: "$global",
},
x: "date",
y: "$kpi",
stroke: "steelblue"
}
vg.parseSpec(
specs,
{
params: [["global", globalSelection], ["kpi", kpi]],
}
).then((plot) => {
containerRef.current?.replaceChildren(plot);
}); My |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@jheer sorry for tagging you but I was wondering if you know |
Beta Was this translation helpful? Give feedback.
-
Good question! Currently the mark logic treats Here is an alternative setup: {
await vg.coordinator().exec(
vg.loadObjects('kpis', [
{ date: 1, visits: 5, clicks: 3 },
{ date: 2, visits: 10, clicks: 5 },
{ date: 3, visits: 7, clicks: 4 }
])
);
const globalSelection = vg.Selection.single();
const kpi = vg.Param.value(vg.column('visits')); // value is explicitly a column
const color = vg.Param.value('steelblue');
return vg.plot(
vg.lineY(vg.from('kpis', { filterBy: globalSelection }), {
x: 'date',
y: vg.sql`${kpi}`, // dynamic SQL expression provides column dependency logic
stroke: color // works directly as params are treated as scalar values
})
);
} There are two awkward pieces above. First, the I'll have to think more about potential changes to make this smoother... one idea is to extend |
Beta Was this translation helpful? Give feedback.
Good question! Currently the mark logic treats
Param
values as scalars, so a string value is interpreted as a string literal as opposed to a column name. I think that is why you are seeing an error here.Here is an alternative setup: