Skip to content

Instantly share code, notes, and snippets.

@drewda
Last active March 23, 2017 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewda/3fdd43eff8db145a365f210a482f3914 to your computer and use it in GitHub Desktop.
Save drewda/3fdd43eff8db145a365f210a482f3914 to your computer and use it in GitHub Desktop.
height: 700
scrolling: yes
license: mit
<!DOCTYPE html>
<head>
<title>Transitland operators by country</title>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega/2.6.5/vega.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/1.3.1/vega-lite.js"></script>
<script src="https://vega.github.io/vega-editor/vendor/vega-embed.js" charset="utf-8"></script>
<style media="screen">
/* Add space between vega-embed links */
.vega-actions a {
margin-right: 5px;
}
#vis {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Transitland operators by country</h1>
<!-- Container for the visualization -->
<div id="vis"></div>
<script>
// Assign the specification to a local variable vlSpec.
var vlSpec = {
"data": {
"values": []
},
"mark": "bar",
"encoding": {
"y": {"field": "name", "type": "ordinal", "axis": {
"title": "country"
}},
"x": {
"field": "count",
"type": "quantitative",
"axis": {
"title": "# of operators"
}
}
},
"config": {"scale": {"bandSize": 15}}
};
d3.json("https://transit.land/api/v1/operators/aggregate", function(error, json) {
if (error) return console.warn(error);
vlSpec.data.values = Object.keys(json.country).map((country) => {
return {
name: country,
count: json.country[country].count
};
});
var embedSpec = {
mode: "vega-lite", // Instruct Vega-Embed to use the Vega-Lite compiler
spec: vlSpec
// You can add more vega-embed configuration properties here.
// See https://github.com/vega/vega/wiki/Embed-Vega-Web-Components#configuration-propeties for more information.
};
// Embed the visualization in the container with id `vis`
vg.embed("#vis", embedSpec, function(error, result) {
// Callback receiving the View instance and parsed Vega spec
// result.view is the View, which resides under the '#vis' element
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment