Skip to content

Instantly share code, notes, and snippets.

@mikelotis
Last active December 22, 2018 20:35
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 mikelotis/4141d2ac147bb523d4736e287786014f to your computer and use it in GitHub Desktop.
Save mikelotis/4141d2ac147bb523d4736e287786014f to your computer and use it in GitHub Desktop.
Edmonton Traffic Disruption - Sankey (echarts.js)
border: yes
width: 1000
height: 700

Flow order for sankey is as follows: Disruptions → Status → Impact → Activity Type → Traffic District → Infrastructure
Date obtained data from Open Data (City of Edmonton) : July-23-2018

Help to read the sankey: Link

Some observations

  1. All special events are central
  2. Most of the disruptions activity type is construction
  3. Central has the highest number construction - (44 + 16) 60 disruptions
  4. Southeast and Northwest have the lowest number of construction - 20 disruptions
  5. Total closure is the only impact with two activity types

Some questions that I have
Can be answered by researching online or asking a Subject Matter Expert.

  1. Why are some disruptions revised?
  2. Why is there a high number of road construction on the Northeast traffic district?

Mouseover the thick lines to get link stats

Compare code with d3.js version

References

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Sankey</title>
<style>
div#main {
margin: 0 auto;
padding-top: 30px;
}
</style>
</head>
<body>
<div id="main" style="width:964px; height:600px;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.1.0/echarts.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script src="nodesAndLinks.js" lang="babel" type="text/babel"></script>
<script lang="babel" type="text/babel">
const log = console.log;
const url = "https://gist.githubusercontent.com/mikelotis/" +
"98000626c7332958b47fe4f4fc0cf4fc/raw/0b08cdabf738b1dc41de1e04072e57cfdfe214ea/"+
"Traffic_Disruptions(July-23-2018).csv";
const myChart = echarts.init(document.getElementById('main'));
d3.csv(url)
.then(makeSankey);
function makeSankey(csv) {
//-----------------Data prep
// use only required attributes
const data = csv.map(element => {
return {
"Disruptions": "Disruptions",
"Status": element["Status"],
"Impact": element["Impact"],
"Activity Type" : element["Activity Type"],
"Traffic District": element["Traffic District"],
"Infrastructure": element["Infrastructure"]
};
});
//-----------------Data prep
//---------------------------Data Viz
// sankey flow order
// Disruptions → Status → Impact → Activity Type → Traffic District → Infrastructure
const order = [
"Disruptions", "Status", "Impact",
"Activity Type", "Traffic District", "Infrastructure"
];
//Chart margin, data for sankey series, and option for myChart
const margin = {top: 30, right: 30, bottom: 30, left: 70};
const sankeyData = nodesAndLinks(data, order);
const option = {
title: {
text: "Edmonton Traffic Disruptions",
x: "center"
},
tooltip: {},
series: [
{
type: "sankey",
top: margin.top,
right: margin.right,
bottom: margin.bottom,
left: margin.left,
width: 964 - margin.left - margin.right,
height: 600 - margin.top - margin.bottom,
nodeWidth: 15,
nodeGap: 30,
layoutIterations: 100,
nodes: sankeyData.nodes,
links: sankeyData.links,
draggable: false,
label: {
position: "left"
},
itemStyle: {
normal: {
borderWidth: 1,
borderColor: "#aaa"
}
}
}
]
};
//---------------------------Data Viz
myChart.setOption(option);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment