Skip to content

Instantly share code, notes, and snippets.

@saraquigley
Last active December 15, 2015 03:28
Show Gist options
  • Save saraquigley/5194141 to your computer and use it in GitHub Desktop.
Save saraquigley/5194141 to your computer and use it in GitHub Desktop.
Issue Breakdown
<!DOCTYPE html>
<meta charset="utf-8">
<title>CFV Issue Breakdown</title>
<style>
@import url(sankey.css);
</style>
<body>
<header>
<b>Student Financials: Breaking down the Issues </b>
<br>Sara Quigley March 18, 2013
<p>
</header>
<div class="columnHead">
<span class="lookingAtMyAccount">My Question as a Student</span>
<span class="whatsHappening">What's Going On</span>
<span class="whatsProblematic">What's Problematic</span>
<span class="proposedRemediation">Proposed Remediation</span>
<span class="ProcessDesignTech"></font>
<br>
<font color="#a55194">Design</font><font color="#7f7f7f"> | </font>
<font color="#ce6dbd">Process</font><font color="#7f7f7f"> | </font>
<font color="#de9ed6">Tech</font>
</span>
</div>
<p id="chart">
<footer>
</footer>
<script src="http://d3js.org/d3.v2.min.js"></script>
<script src="sankey.js"></script>
<script>
var margin = {top: 50, right: 30, bottom: 6, left: 1},
width = 1410 - margin.left - margin.right,
height = 700 - margin.top - margin.bottom;
var category20b_sq = ['#393b79', '#5254a3', '#6b6ecf', '#9c9ede', '#8c6d31', '#bd9e39', '#e7ba52', '#e7cb94',
'#843c39', '#ad494a', '#d6616b', '#e7969c', '#637939', '#8ca252', '#b5cf6b', '#cedb9c',
'#ce6dbd', '#a55194', '#de9ed6', '#7b4173']
var formatNumber = d3.format(",.0f"),
format = function(d) { return formatNumber(d); },
color = d3.scale.ordinal()
.range(category20b_sq);
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var sankey = d3.sankey()
.nodeWidth(15)
.nodePadding(15)
.size([width, height]);
var path = sankey.link();
d3.json("sankey.json", function(energy) {
sankey
.nodes(energy.nodes)
.links(energy.links)
.layout(20);
var link = svg.append("g").selectAll(".link")
.data(energy.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.sort(function(a, b) { return b.dy - a.dy; });
link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name; });
var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.call(d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", function() { this.parentNode.appendChild(this); })
.on("drag", dragmove));
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", function(d) { return color(d.category); })
.append("title")
.text(function(d) { return d.name; });
node.append("text")
.attr("x", 6 + sankey.nodeWidth())
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "start")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x > width * .9; })
.attr("class", function(d) { return d.category ; })
.attr("text-anchor", "end")
.attr("transform", function(d) { return "translate (" + ((d.dy / 2) + 30) + "," + (d.dy / 2) + ") rotate(90)"; });
function dragmove(d) {
d3.select(this)
.attr("transform", "translate(" + (
d.x = Math.max(0, Math.min(width - d.dx, d3.event.x))
) + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
sankey.relayout();
link.attr("d", path);
}
});
</script>
@import url(http://fonts.googleapis.com/css?family=PT+Serif|PT+Serif:b|PT+Serif:i|PT+Sans|PT+Sans:b);
html {
min-width: 1040px;
}
body {
background: #fcfcfa;
font-family: "PT Serif", serif;
margin: 1em auto 2em 1em;
position: relative;
width: 1100px;
}
header,
footer {
color: #000;
font-family: "PT Sans", sans-serif;
}
footer {
font-size: small;
margin-top: 8em;
}
a {
color: steelblue;
}
svg {
font: 500 14px "arial", sans-serif;
fill: #023858;
}
#chart {
height: 700px;
}
.columnHead {
font: 400 24px "helvetica neue";
}
.node rect {
cursor: move;
fill-opacity: .75;
shape-rendering: crispEdges;
}
.node text {
pointer-events: none;
text-shadow: 0 1px 0 #fff;
}
.link {
fill: none;
stroke: #969696;
stroke-opacity: .2;
}
.link:hover {
stroke-opacity: .5;
}
.lookingAtMyAccount {
fill: #1f77b4;
color: #1f77b4;
position: absolute;
width: 350px;
}
.whatsHappening {
fill: #bd9e39;
color: #bd9e39;
left: 350px;
position: absolute;
width: 350px;
}
.whatsProblematic {
fill: #ad494a;
color: #ad494a;
left: 700px;
position: absolute;
width: 350px;
}
.proposedRemediation {
fill: #637939;
color: #637939;
left: 1050px;
position: absolute;
width: 350px;
}
.businessProcess {
fill: #ce6dbd;
font: 400 18px "Helvetica Neue";
}
.uiDesign {
fill: #a55194;
font: 400 18px "Helvetica Neue";
}
.sysInfrastructure {
fill: #de9ed6;
font: 400 18px "Helvetica Neue";
}
.ProcessDesignTech {
left: 1050px;
position: absolute;
width: 350px;
font: 400 20px "Helvetica Neue";
}
d3.sankey = function() {
var sankey = {},
nodeWidth = 24,
nodePadding = 8,
size = [1, 1],
nodes = [],
links = [];
sankey.nodeWidth = function(_) {
if (!arguments.length) return nodeWidth;
nodeWidth = +_;
return sankey;
};
sankey.nodePadding = function(_) {
if (!arguments.length) return nodePadding;
nodePadding = +_;
return sankey;
};
sankey.nodes = function(_) {
if (!arguments.length) return nodes;
nodes = _;
return sankey;
};
sankey.links = function(_) {
if (!arguments.length) return links;
links = _;
return sankey;
};
sankey.size = function(_) {
if (!arguments.length) return size;
size = _;
return sankey;
};
sankey.layout = function(iterations) {
computeNodeLinks();
computeNodeValues();
computeNodeBreadths();
computeNodeDepths(iterations);
computeLinkDepths();
return sankey;
};
sankey.relayout = function() {
computeLinkDepths();
return sankey;
};
sankey.link = function() {
var curvature = .5;
function link(d) {
var x0 = d.source.x + d.source.dx,
x1 = d.target.x,
xi = d3.interpolateNumber(x0, x1),
x2 = xi(curvature),
x3 = xi(1 - curvature),
y0 = d.source.y + d.sy + d.dy / 2,
y1 = d.target.y + d.ty + d.dy / 2;
return "M" + x0 + "," + y0
+ "C" + x2 + "," + y0
+ " " + x3 + "," + y1
+ " " + x1 + "," + y1;
}
link.curvature = function(_) {
if (!arguments.length) return curvature;
curvature = +_;
return link;
};
return link;
};
// Populate the sourceLinks and targetLinks for each node.
// Also, if the source and target are not objects, assume they are indices.
function computeNodeLinks() {
nodes.forEach(function(node) {
node.sourceLinks = [];
node.targetLinks = [];
});
links.forEach(function(link) {
var source = link.source,
target = link.target;
if (typeof source === "number") source = link.source = nodes[link.source];
if (typeof target === "number") target = link.target = nodes[link.target];
source.sourceLinks.push(link);
target.targetLinks.push(link);
});
}
// Compute the value (size) of each node by summing the associated links.
function computeNodeValues() {
nodes.forEach(function(node) {
node.value = Math.max(
d3.sum(node.sourceLinks, value),
d3.sum(node.targetLinks, value)
);
});
}
// Iteratively assign the breadth (x-position) for each node.
// Nodes are assigned the maximum breadth of incoming neighbors plus one;
// nodes with no incoming links are assigned breadth zero, while
// nodes with no outgoing links are assigned the maximum breadth.
function computeNodeBreadths() {
var remainingNodes = nodes,
nextNodes,
x = 0;
while (remainingNodes.length) {
nextNodes = [];
remainingNodes.forEach(function(node) {
node.x = x;
node.dx = nodeWidth;
node.sourceLinks.forEach(function(link) {
nextNodes.push(link.target);
});
});
remainingNodes = nextNodes;
++x;
}
//
moveSinksRight(x);
scaleNodeBreadths((size[0] - nodeWidth) / (x - 1));
}
function moveSourcesRight() {
nodes.forEach(function(node) {
if (!node.targetLinks.length) {
node.x = d3.min(node.sourceLinks, function(d) { return d.target.x; }) - 1;
}
});
}
function moveSinksRight(x) {
nodes.forEach(function(node) {
if (!node.sourceLinks.length) {
node.x = x - 1;
}
});
}
function scaleNodeBreadths(kx) {
nodes.forEach(function(node) {
node.x *= kx;
});
}
function computeNodeDepths(iterations) {
var nodesByBreadth = d3.nest()
.key(function(d) { return d.x; })
.sortKeys(d3.ascending)
.entries(nodes)
.map(function(d) { return d.values; });
//
initializeNodeDepth();
resolveCollisions();
for (var alpha = 1; iterations > 0; --iterations) {
relaxRightToLeft(alpha *= .99);
resolveCollisions();
relaxLeftToRight(alpha);
resolveCollisions();
}
function initializeNodeDepth() {
var ky = d3.min(nodesByBreadth, function(nodes) {
return (size[1] - (nodes.length - 1) * nodePadding) / d3.sum(nodes, value);
});
nodesByBreadth.forEach(function(nodes) {
nodes.forEach(function(node, i) {
node.y = i;
node.dy = node.value * ky;
});
});
links.forEach(function(link) {
link.dy = link.value * ky;
});
}
function relaxLeftToRight(alpha) {
nodesByBreadth.forEach(function(nodes, breadth) {
nodes.forEach(function(node) {
if (node.targetLinks.length) {
var y = d3.sum(node.targetLinks, weightedSource) / d3.sum(node.targetLinks, value);
node.y += (y - center(node)) * alpha;
}
});
});
function weightedSource(link) {
return center(link.source) * link.value;
}
}
function relaxRightToLeft(alpha) {
nodesByBreadth.slice().reverse().forEach(function(nodes) {
nodes.forEach(function(node) {
if (node.sourceLinks.length) {
var y = d3.sum(node.sourceLinks, weightedTarget) / d3.sum(node.sourceLinks, value);
node.y += (y - center(node)) * alpha;
}
});
});
function weightedTarget(link) {
return center(link.target) * link.value;
}
}
function resolveCollisions() {
nodesByBreadth.forEach(function(nodes) {
var node,
dy,
y0 = 0,
n = nodes.length,
i;
// Push any overlapping nodes down.
nodes.sort(ascendingDepth);
for (i = 0; i < n; ++i) {
node = nodes[i];
dy = y0 - node.y;
if (dy > 0) node.y += dy;
y0 = node.y + node.dy + nodePadding;
}
// If the bottommost node goes outside the bounds, push it back up.
dy = y0 - nodePadding - size[1];
if (dy > 0) {
y0 = node.y -= dy;
// Push any overlapping nodes back up.
for (i = n - 2; i >= 0; --i) {
node = nodes[i];
dy = node.y + node.dy + nodePadding - y0;
if (dy > 0) node.y -= dy;
y0 = node.y;
}
}
});
}
function ascendingDepth(a, b) {
return a.y - b.y;
}
}
function computeLinkDepths() {
nodes.forEach(function(node) {
node.sourceLinks.sort(ascendingTargetDepth);
node.targetLinks.sort(ascendingSourceDepth);
});
nodes.forEach(function(node) {
var sy = 0, ty = 0;
node.sourceLinks.forEach(function(link) {
link.sy = sy;
sy += link.dy;
});
node.targetLinks.forEach(function(link) {
link.ty = ty;
ty += link.dy;
});
});
function ascendingSourceDepth(a, b) {
return a.source.y - b.source.y;
}
function ascendingTargetDepth(a, b) {
return a.target.y - b.target.y;
}
}
function center(node) {
return node.y + node.dy / 2;
}
function value(link) {
return link.value;
}
return sankey;
};
{
"nodes": [{"name": "Where is my aid?","category": "myAidIsQuestion"},
{"name": "How much aid am I getting?","category": "myAidIsQuestion"},
{"name": "Why am I not getting more aid?","category": "myAidIsQuestion"},
{"name": "Did my payment go through?","category": "lookingAtMyAccount"},
{"name": "What does T40SFLKOUTSIDE NP SPONSOR1/SP mean?","category": "whatDoesThisMean"},
{"name": "Why do I owe $190 for housing? ","category": "lookingAtMyAccount"},
{"name": "What makes up this large fee amount?","category": "whatDoesThisMean"},
{"name": "How much do I actually owe?","category": "lookingAtMyAccount"},
{"name": "What's the breakdown of my current balance?","category": "whatDoesThisMean"},
{"name": "BearFacts says X, MyFinAid says Y. Which is correct?","category": "lookingAtMyAccount"},
{"name": "Am I registered? Can I enroll in classes?","category": "lookingAtMyAccount"},
{"name": "I need a Financial Aid verification letter","category": "iAmTryingToDoSomething"},
{"name": "Stu is expecting cash","category": "expectingActivity"},
{"name": "Stu has an academic block","category": "blocked"},
{"name": "Stu has an administrative block","category": "blocked"},
{"name": "Stu has a financial block","category": "blocked"},
{"name": "Stu's aid package just changed","category": "whatsHappening"},
{"name": "Stu's aid eligibility changed","category": "whatsHappening"},
{"name": "Stu's aid withheld; missing documentation","category": "expectingActivity"},
{"name": "Stu's aid withheld; aid will pay past charges","category": "whatsHappening"},
{"name": "Stu expects to see a fee remission on account","category": "expectingActivity"},
{"name": "Stu's account has 2 competing awards","category": "whatsHappening"},
{"name": "Stu submitted online payment via Sallie Mae","category": "whatsHappening"},
{"name": "Stu is viewing account","category": "whatsHappening"},
{"name": "3rd party requires Financial Aid eligibility proof","category": "makingARequest"},
{"name": "Awards are not dibursed daily (SuTuTh)","category": "whatsProblematic"},
{"name": "Stus aren't receiving notifications","category": "whatsProblematic"},
{"name": "Stus can't view upcoming refunds","category": "whatsMissing"},
{"name": "Stus can't see previous aid packages","category": "whatsMissing"},
{"name": "Awards paid late in term --> confusing transactions","category": "whatsConfusing"},
{"name": "Confusing to track one's aid & budget/plan ","category": "whatsConfusing"},
{"name": "Confusing to see how awards are applied to charges","category": "whatsConfusing"},
{"name": "Multi-system data flow leads to delays","category": "whatsProblematic"},
{"name": "Competing grad awards result in confusing transactions","category": "whatsConfusing"},
{"name": "Transaction descriptions are cryptic","category": "whatsBaffling"},
{"name": "Stus see aggregated transaction amounts","category": "whatsMissing"},
{"name": "Transaction details are scattered in time & space","category": "whatsConfusing"},
{"name": "Future-due charges are included in account balance","category": "whatsConfusing"},
{"name": "Systems are often a day behind each other","category": "whatsMissing"},
{"name": "Imperfect CARS <--> BearFacts interface","category": "whatsProblematic"},
{"name": "Imperfect GLOW <--> MyFinAid interface","category": "whatsProblematic"},
{"name": "Confusing to know how to release one's block ","category": "whatsBaffling"},
{"name": "Incomplete messaging around Reg status","category": "whatsBaffling"},
{"name": "BearFacts refund data is incomplete","category": "whatsMissing"},
{"name": "Stus request verification letter in-person","category": "whatsProblematic"},
{"name": "No systematic way to release aid despite financial block","category": "whatsProblematic"},
{"name": "Pay awards daily from ProSAM --> CARS","category": "Tech"},
{"name": "Display aid packaging history to students","category": "Tech"},
{"name": "Revise and streamine messaging to students","category": "Design"},
{"name": "Display aid amounts and status wrt budget","category": "Design"},
{"name": "Display how aid/payments were applied to charges/fees","category": "Design"},
{"name": "Improve unapplieds process in CARS","category": "Process"},
{"name": "Clearly indicate pending payments to account balance","category": "Design "},
{"name": "Display clear & descriptive transactions to Students","category": "Design"},
{"name": "Pay all aid to Student AR via a central packaging engine","category": "Process"},
{"name": "Standardize award entry processes & nomenclature","category": "Process"},
{"name": "Display timely Stu account activity detail in one place","category": "Tech"},
{"name": "Display future-dated dept awards to students","category": "Process"},
{"name": "Hide the BearFacts Awards screen","category": "Tech"},
{"name": "Display refund data for prior terms","category": "Tech"},
{"name": "Provide self-service FinAid Verification letter generation","category": "Process"},
{"name": "Reduce the number of interfaces in the data flow","category": "Tech"},
{"name": "Clearly distinguish btw future & current charges","category": "Design"},
{"name": "Release hold due to financial block for select students","category": "Tech"},
{"name": "Display future refunds to Students","category": "Design"},
{"name": "Process","category": "businessProcess"},
{"name": "Design","category": "uiDesign"},
{"name": "Tech","category": "sysInfrastructure"}
],
"links": [{"source": 0,"target": 12,"value": 240},
{"source": 0,"target": 13,"value": 60},
{"source": 0,"target": 14,"value": 60},
{"source": 0,"target": 15,"value": 100},
{"source": 0,"target": 18,"value": 90},
{"source": 1,"target": 16,"value": 260},
{"source": 1,"target": 17,"value": 60},
{"source": 2,"target": 17,"value": 60},
{"source": 0,"target": 19,"value": 270},
{"source": 0,"target": 20,"value": 110},
{"source": 1,"target": 21,"value": 80},
{"source": 2,"target": 21,"value": 60},
{"source": 3,"target": 22,"value": 60},
{"source": 4,"target": 23,"value": 120},
{"source": 5,"target": 23,"value": 120},
{"source": 6,"target": 23,"value": 120},
{"source": 7,"target": 23,"value": 120},
{"source": 8,"target": 23,"value": 120},
{"source": 9,"target": 23,"value": 120},
{"source": 10,"target": 23,"value": 120},
{"source": 11,"target": 24,"value": 80},
{"source": 12,"target": 25,"value": 80},
{"source": 12,"target": 27,"value": 160},
{"source": 13,"target": 26,"value": 60},
{"source": 13,"target": 41,"value": 60},
{"source": 14,"target": 41,"value": 60},
{"source": 14,"target": 26,"value": 80},
{"source": 15,"target": 41,"value": 60},
{"source": 15,"target": 26,"value": 100},
{"source": 16,"target": 28,"value": 80},
{"source": 16,"target": 29,"value": 260},
{"source": 17,"target": 26,"value": 120},
{"source": 18,"target": 26,"value": 100},
{"source": 19,"target": 30,"value": 200},
{"source": 19,"target": 45,"value": 70},
{"source": 20,"target": 32,"value": 60},
{"source": 20,"target": 31,"value": 60},
{"source": 21,"target": 33,"value": 80},
{"source": 22,"target": 26,"value": 60},
{"source": 23,"target": 34,"value": 200},
{"source": 23,"target": 35,"value": 60},
{"source": 23,"target": 36,"value": 100},
{"source": 23,"target": 37,"value": 60},
{"source": 23,"target": 38,"value": 90},
{"source": 23,"target": 39,"value": 100},
{"source": 23,"target": 40,"value": 60},
{"source": 23,"target": 41,"value": 60},
{"source": 23,"target": 42,"value": 70},
{"source": 23,"target": 43,"value": 60},
{"source": 24,"target": 44,"value": 60},
{"source": 25,"target": 46,"value": 100},
{"source": 26,"target": 48,"value": 400},
{"source": 27,"target": 48,"value": 110},
{"source": 26,"target": 52,"value": 60},
{"source": 27,"target": 64,"value": 110},
{"source": 28,"target": 47,"value": 60},
{"source": 29,"target": 50,"value": 60},
{"source": 29,"target": 53,"value": 60},
{"source": 29,"target": 55,"value": 80},
{"source": 29,"target": 54,"value": 60},
{"source": 30,"target": 49,"value": 200},
{"source": 29,"target": 57,"value": 90},
{"source": 31,"target": 50,"value": 70},
{"source": 32,"target": 61,"value": 110},
{"source": 33,"target": 50,"value": 60},
{"source": 33,"target": 51,"value": 60},
{"source": 33,"target": 54,"value": 60},
{"source": 34,"target": 51,"value": 60},
{"source": 34,"target": 53,"value": 110},
{"source": 34,"target": 55,"value": 60},
{"source": 35,"target": 56,"value": 90},
{"source": 36,"target": 56,"value": 90},
{"source": 37,"target": 62,"value": 70},
{"source": 38,"target": 61,"value": 140},
{"source": 39,"target": 58,"value": 60},
{"source": 40,"target": 54,"value": 80},
{"source": 41,"target": 48,"value": 200},
{"source": 42,"target": 48,"value": 100},
{"source": 43,"target": 59,"value": 60},
{"source": 44,"target": 60,"value": 60},
{"source": 45,"target": 63,"value": 60},
{"source": 46,"target": 67,"value": 100},
{"source": 47,"target": 66,"value": 60},
{"source": 48,"target": 66,"value": 810},
{"source": 49,"target": 66,"value": 200},
{"source": 50,"target": 66,"value": 60},
{"source": 51,"target": 65,"value": 60},
{"source": 51,"target": 67,"value": 60},
{"source": 52,"target": 66,"value": 60},
{"source": 53,"target": 66,"value": 85},
{"source": 53,"target": 65,"value": 85},
{"source": 54,"target": 65,"value": 90},
{"source": 54,"target": 67,"value": 90},
{"source": 55,"target": 65,"value": 140},
{"source": 56,"target": 65,"value": 60},
{"source": 56,"target": 66,"value": 60},
{"source": 56,"target": 67,"value": 60},
{"source": 57,"target": 65,"value": 45},
{"source": 57,"target": 67,"value": 45},
{"source": 58,"target": 67,"value": 30},
{"source": 58,"target": 66,"value": 30},
{"source": 59,"target": 67,"value": 60},
{"source": 60,"target": 65,"value": 20},
{"source": 60,"target": 66,"value": 20},
{"source": 60,"target": 67,"value": 20},
{"source": 61,"target": 65,"value": 80},
{"source": 61,"target": 66,"value": 80},
{"source": 61,"target": 67,"value": 80},
{"source": 62,"target": 66,"value": 70},
{"source": 63,"target": 67,"value": 60},
{"source": 64,"target": 65,"value": 60},
{"source": 64,"target": 66,"value": 50}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment