{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "values": [ {"Name": "Peter", "Score": 3}, {"Name": "Paul", "Score": 1}, {"Name": "Mary", "Score": 5} ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "formula", "expr": "datum[\"Name\"]===\"Peter\" ? 0 : datum[\"Name\"]===\"Mary\" ? 1 : datum[\"Name\"]===\"Paul\" ? 2 : 3", "as": "x_Name_sort_index" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 1, 0.5) * x_step" } ], "marks": [ { "name": "marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"x_Name_sort_index\"]"}, "from": {"data": "data_0"}, "encode": { "update": { "stroke": {"value": "#4c78a8"}, "description": { "signal": "\"Name: \" + (isValid(datum[\"Name\"]) ? datum[\"Name\"] : \"\"+datum[\"Name\"]) + \"; Score: \" + (format(datum[\"Score\"], \"\"))" }, "x": {"scale": "x", "field": "Name"}, "y": {"scale": "y", "field": "Score"}, "defined": { "signal": "isValid(datum[\"Score\"]) && isFinite(+datum[\"Score\"])" } } } } ], "scales": [ { "name": "x", "type": "point", "domain": { "data": "data_0", "field": "Name", "sort": {"op": "min", "field": "x_Name_sort_index"} }, "range": {"step": {"signal": "x_step"}}, "padding": 0.5 }, { "name": "y", "type": "linear", "domain": {"data": "data_0", "field": "Score"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "axes": [ { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Name", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Score", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }