there is no documentation on conditionals that I can find
jjwAmtelco opened this issue · comments
this json works fine in the editor but there are no examples of it in the documentation; or anywhere else that I can find. I know this is not a bug per say, But I would be glad to add documentation if I could figure this one out...
`{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"name": "data",
"values": [
{
"agent": "bart",
"avg_score": "3.0000000000000000",
"call_count": 5,
"label": "Answer Time",
"max_score": 5,
"percentage": "0.60000000000000000000",
"score_average": "3.0000000000000000",
"score_calc": "0.00",
"score_desc": "agent % from avg",
"score_percentage": "0.60000000000000000000"
},
{
"agent": "mabel",
"avg_score": "3.0000000000000000",
"call_count": 5,
"label": "Answer Time",
"max_score": 5,
"percentage": "0.60000000000000000000",
"score_average": "3.0000000000000000",
"score_calc": "0.00",
"score_desc": "agent % from avg",
"score_percentage": "0.60000000000000000000"
},
{
"agent": "bart",
"avg_score": "5.8000000000000000",
"call_count": 5,
"label": "Negative Words",
"max_score": 10,
"percentage": "0.58000000000000000000",
"score_average": "5.8000000000000000",
"score_calc": "0.00",
"score_desc": "agent % from avg",
"score_percentage": "0.58000000000000000000"
},
{
"agent": "mabel",
"avg_score": "5.8000000000000000",
"call_count": 5,
"label": "Negative Words",
"max_score": 10,
"percentage": "0.58000000000000000000",
"score_average": "5.8000000000000000",
"score_calc": "0.00",
"score_desc": "agent % from avg",
"score_percentage": "0.58000000000000000000"
}
]
},
"description": "",
"encoding": {
"y": {
"axis": {
"labels": true,
"tickBand": "center",
"tickOpacity": 0,
"title": ""
},
"field": "agent",
"type": "nominal"
}
},
"height": {"step": 16},
"layer": [
{
"encoding": {
"tooltip": [
{"field": "AgentCalls", "title": "calls", "type": "quantitative"},
{"field": "AvgAgtScore", "title": "avg score", "type": "quantitative"}
],
"x": {
"aggregate": "average",
"axis": null,
"field": "percentage",
"scale": {"domain": [0, 1]}
}
},
"mark": {"color": "#ddd", "tooltip": true, "type": "bar"},
"transform": [
{
"groupby": ["agent"],
"joinaggregate": [
{"as": "AvgAgtScore", "field": "avg_score", "op": "average"}
]
},
{
"groupby": ["agent"],
"joinaggregate": [
{"as": "AgentCalls", "field": "call_count", "op": "average"}
]
}
]
},
{
"encoding": {"text": {"field": "AgentPercentage", "format": ".2%"}},
"mark": {
"align": "left",
"tooltip": "the agent percentage",
"type": "text",
"x": 5
},
"transform": [
{
"groupby": ["agent"],
"joinaggregate": [
{"as": "AgentPercentage", "field": "percentage", "op": "average"}
]
}
]
},
{
"encoding": {
"color": {
"condition": {"test": "datum['ScorePercentageCalc'] < 0 ", "value": "Red"},
"value": "Green"
},
"text": {
"field": "ScorePercentageCalc",
"format": ".2%",
"type": "quantitative"
},
"tooltip": [
{"field": "score_desc", "title": "description"},
{
"field": "ScorePercentage",
"format": ".2%",
"title": "avg for all scores",
"type": "quantitative"
}
]
},
"mark": {
"align": "left",
"baseline": "middle",
"dx": 24,
"fontWeight": "bold",
"tooltip": "test",
"type": "text"
},
"transform": [
{
"joinaggregate": [
{
"as": "ScorePercentageCalc",
"field": "score_calc",
"op": "average"
}
]
},
{
"joinaggregate": [
{
"as": "ScorePercentage",
"field": "score_percentage",
"op": "average"
}
]
}
]
}
],
"title": "Agent Scores",
"width": 200
}`
In most cases we transform options from snake case to camel case and everything from Vega-Lite is supported. The idea is that mirroring examples from Vega-Lite docs should be fairly automatic, in this case you could do:
|> Vl.encode(:color,
value: "green",
condition: [test: "datum['ScorePercentageCalc'] < 0", value: "red"]
)
It's not practical to cover all examples from Vega-Lite docs, but a PR to the docs is welcome :)
just one tiny change; its 'test' not 'text' :-)
@jjwAmtelco yeah, I edited on GitHub, but this doesn't propagate to email notifications :D