Skip to content

Instantly share code, notes, and snippets.

@keizer619
Created December 3, 2015 05:49
Show Gist options
  • Save keizer619/7dcd23cea62984763261 to your computer and use it in GitHub Desktop.
Save keizer619/7dcd23cea62984763261 to your computer and use it in GitHub Desktop.
{
"width": 400,
"height": 200,
"padding": {"top": 10, "left": 30, "bottom": 20, "right": 10},
"data": [
{
"name": "table",
"values": [
{"category":"A", "amount":28},
{"category":"B", "amount":55},
{"category":"C", "amount":43},
{"category":"D", "amount":91},
{"category":"E", "amount":81},
{"category":"F", "amount":53},
{"category":"G", "amount":19},
{"category":"H", "amount":87},
{"category":"I", "amount":52}
]
}
],
"signals": [
{
"name": "tooltip",
"init": {},
"streams": [
{"type": "symbol:mouseover", "expr": "datum"},
{"type": "symbol:mouseout", "expr": "{}"}
]
}
],
"predicates": [
{
"name": "tooltip", "type": "==",
"operands": [{"signal": "tooltip._id"}, {"arg": "id"}]
}
],
"scales": [
{ "name": "xscale", "type": "ordinal", "range": "width",
"domain": {"data": "table", "field": "category"} },
{ "name": "yscale", "range": "height", "nice": true,
"domain": {"data": "table", "field": "amount"} }
],
"axes": [
{ "type": "x", "scale": "xscale" },
{ "type": "y", "scale": "yscale" }
],
"marks": [
{
"type": "line",
"from": {"data":"table"},
"properties": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"y": {"scale": "yscale", "field": "amount"},
"stroke":{"value":"steelblue"},
"strokeWidth": {"value": 2}
}
}
},
{
"type": "symbol",
"from": {"data":"table"},
"properties": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"y": {"scale": "yscale", "field": "amount"},
"fill":{"value":"orange"},
"stroke":{"value":"black"},
"strokeWidth": {"value": 2}
},
"update": { "stroke":{"value":"steelblue"}},
"hover": { "stroke":{"value":"red"} }
}
},
{
"type": "text",
"properties": {
"enter": {
"align": {"value": "center"},
"fill": {"value": "#333"}
},
"update": {
"x": {"scale": "xscale", "signal": "tooltip.category"},
"dx": {"scale": "xscale", "band": true, "mult": 0.5},
"y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -5},
"text": {"signal": "tooltip.amount"},
"fillOpacity": {
"rule": [
{
"predicate": {"name": "tooltip", "id": {"value": null}},
"value": 0
},
{"value": 1}
]
}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment