vegaSpec = {
const hover = {"hover": { "type": "single", "fields": ["Horsepower", "Miles_per_Gallon"],
"nearest": true, "on": "mouseover", "empty": "none", "clear": "mouseout"
}
};
const fieldHP = {"field": "Horsepower", "type": "quantitative"};
const fieldMPG = {"field": "Miles_per_Gallon", "type": "quantitative"};
const points = { "mark": {"type": "point", "filled": true, "tooltip": true},
"encoding": { "x": fieldHP, "y": fieldMPG }, "selection": hover
};
const opacity = {"condition": {"value": 0.3, "selection": "hover"},"value": 0 };
const ruleMPG = { "mark": "rule", "encoding": {"y": fieldMPG,"opacity": opacity} };
const ruleHP = { "mark": "rule", "encoding": {"x": fieldHP, "opacity": opacity} };
const spec = { "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {values: cars},
"layer": [points]
.concat(rules.includes("ruleMPG") ? [ruleMPG] : [])
.concat(rules.includes("ruleHP") ? [ruleHP] : [])
};
const div = document.createElement("div");
const view = div.value = new vl.vega.View(vl.vega.parse(vl.vegalite.compile(spec).spec));
return view.initialize(div).runAsync().then(function() { return div; });
}