Skip to content

Instantly share code, notes, and snippets.

@dsaffo
Forked from jakevdp/.block
Last active October 15, 2020 19:27
Show Gist options
  • Save dsaffo/a408826831cb154a2a8df90ff4ff0b13 to your computer and use it in GitHub Desktop.
Save dsaffo/a408826831cb154a2a8df90ff4ff0b13 to your computer and use it in GitHub Desktop.
VisConnect X Vega: Interactive Exploration of Seattle Weather
license: MIT

VisConnect X Vega

This VisConnect example is adapted from this block. This is a expermental example of VisConnect working with Vega and Vega-Lite. This integration is still in its early stages and support across different version is not guaranteed. The only changes are adding the PeerJS and VisConnect script tags. Click the visconnect logo on the bottom right and send the coppied URL to a friend. Once they open the link all your interactions will be synchronized!

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/peerjs@1.0.4/dist/peerjs.min.js"></script>
<script src="https://unpkg.com/visconnect@latest/visconnect-bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega/3.0.0-rc5/vega.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/2.0.0-beta.11/vega-lite.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-embed/3.0.0-beta.19/vega-embed.js"></script>
<style>
body {
font-family: sans-serif;
}
.vega-actions a {
padding: 0.2em;
}
</style>
</head>
<body>
<div id="vis"></div>
<script>
const spec = "spec.json";
vega.embed('#vis', spec).catch(console.warn);
</script>
</body>
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"title": "Seattle Weather, 2012-2015",
"data": {
"url": "https://vega.github.io/vega-datasets/data/seattle-weather.csv"
},
"vconcat": [
{
"encoding": {
"color": {
"condition": {
"field": "weather",
"scale": {
"domain": ["sun", "fog", "drizzle", "rain", "snow"],
"range": ["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"]
},
"selection": "brush",
"type": "nominal"
},
"value": "lightgray"
},
"size": {
"field": "precipitation",
"scale": {
"domain": [-1, 50]
},
"type": "quantitative"
},
"x": {
"axis": {
"title": "Date"
},
"field": "date",
"timeUnit": "monthdate",
"type": "temporal"
},
"y": {
"axis": {
"title": "Maximum Daily Temperature (C)"
},
"field": "temp_max",
"scale": {"domain": [-5, 40]},
"type": "quantitative"
}
},
"height": 300,
"mark": "point",
"selection": {
"brush": {
"encodings": ["x"],
"type": "interval"
}
},
"transform": [
{
"filter": {
"selection": "click"
}
}
],
"width": 600
},
{
"encoding": {
"color": {
"condition": {
"field": "weather",
"scale": {
"domain": ["sun", "fog", "drizzle", "rain", "snow"],
"range": ["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"]
},
"selection": "click",
"type": "nominal"
},
"value": "lightgray"
},
"x": {
"aggregate": "count",
"field": "*",
"type": "quantitative"
},
"y": {
"field": "weather",
"type": "nominal"
}
},
"mark": "bar",
"selection": {
"click": {
"encodings": ["color"],
"type": "multi"
}
},
"transform": [
{
"filter": {
"selection": "brush"
}
}
],
"width": 600
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment