Thursday, December 27, 2012

D3GL Tutorials 00: Getting started

In this tutorial, we will go over how to incorporate D3GL into your webpage.

Linking D3GL


To get started with D3GL, first download D3GL here, by right-clicking the link and choosing "Save as..." or something similar.

Alternatively, you can add the following line between
<head>
and
</head>
:
<script type="text/javascript" src="http://dcpos.ch/d3gl/js/d3gl.min.js"></script>

I will keep the above links updated, but keep in mind that D3GL is under heavy development, so the latest (un-minified) version lives here on Github.

Running a local server


When you are developing locally, your browser may raise something along the lines of
XMLHttpRequest cannot load the url Origin null is not allowed by Access-Control-Allow-Origin
when you try to read files out of the local file system. To avoid this, you can run a local web server. I find that a simple solution is to run Python's built-in server:
python -m SimpleHTTPServer 8888 &

... after which you can access
http://localhost:8888/
.

If you are using a Mac, I find that MAMP works beautifully.

Using D3GL


Now that you have linked D3GL and run a local server, you can use
d3.gl.globe
in your code:
<script type="text/javascript">
$(function(){
  // use d3.gl to create a beautiful visualization
});
</script>

Next →

No comments:

Post a Comment