{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "An example showing how to use argmin in tooltips with fields with spaces", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "values": [ {"Fighter Name": "liukang", "Place Rank": 1, "Fighting Style": "tiger"}, { "Fighter Name": "liukang", "Place Rank": 10, "Fighting Style": "crane" }, { "Fighter Name": "liukang", "Place Rank": 3, "Fighting Style": "shaolin" }, { "Fighter Name": "johnnycage", "Place Rank": 6, "Fighting Style": "tiger" }, { "Fighter Name": "johnnycage", "Place Rank": 5, "Fighting Style": "crane" }, { "Fighter Name": "johnnycage", "Place Rank": 4, "Fighting Style": "shaolin" }, {"Fighter Name": "raiden", "Place Rank": 8, "Fighting Style": "tiger"}, {"Fighter Name": "raiden", "Place Rank": 12, "Fighting Style": "crane"}, {"Fighter Name": "raiden", "Place Rank": 2, "Fighting Style": "shaolin"} ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "formula", "expr": "toNumber(datum[\"Place Rank\"])", "as": "Place Rank" }, { "type": "aggregate", "groupby": ["Fighter Name"], "ops": ["min", "argmin"], "fields": ["Place Rank", "Place Rank"], "as": ["min_Place Rank", "argmin_Place Rank"] }, { "type": "filter", "expr": "isValid(datum[\"min_Place Rank\"]) && isFinite(+datum[\"min_Place Rank\"])" } ] } ], "signals": [ {"name": "y_step", "value": 20}, { "name": "height", "update": "bandspace(domain('y').length, 1, 0.5) * y_step" } ], "marks": [ { "name": "marks", "type": "symbol", "style": ["point"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "transparent"}, "stroke": {"value": "#4c78a8"}, "tooltip": { "signal": "{\"Fighter Name\": isValid(datum[\"Fighter Name\"]) ? datum[\"Fighter Name\"] : \"\"+datum[\"Fighter Name\"], \"Min of Place Rank\": format(datum[\"min_Place Rank\"], \"\"), \"Fighting Style for min Place Rank\": isValid(datum[\"argmin_Place Rank\"][\"Fighting Style\"]) ? datum[\"argmin_Place Rank\"][\"Fighting Style\"] : \"\"+datum[\"argmin_Place Rank\"][\"Fighting Style\"]}" }, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"Min of Place Rank: \" + (format(datum[\"min_Place Rank\"], \"\")) + \"; Fighter Name: \" + (isValid(datum[\"Fighter Name\"]) ? datum[\"Fighter Name\"] : \"\"+datum[\"Fighter Name\"]) + \"; Fighting Style for min Place Rank: \" + (isValid(datum[\"argmin_Place Rank\"][\"Fighting Style\"]) ? datum[\"argmin_Place Rank\"][\"Fighting Style\"] : \"\"+datum[\"argmin_Place Rank\"][\"Fighting Style\"])" }, "x": {"scale": "x", "field": "min_Place Rank"}, "y": {"scale": "y", "field": "Fighter Name"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "data_0", "field": "min_Place Rank"}, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "point", "domain": {"data": "data_0", "field": "Fighter Name", "sort": true}, "range": {"step": {"signal": "y_step"}}, "padding": 0.5 } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Min of Place Rank", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Fighter Name", "zindex": 0 } ] }