Skip to content

Instantly share code, notes, and snippets.

@briehanlombaard
Last active March 15, 2016 14:45
Show Gist options
  • Select an option

  • Save briehanlombaard/d3d91c415ad5a86b86be to your computer and use it in GitHub Desktop.

Select an option

Save briehanlombaard/d3d91c415ad5a86b86be to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<style>
.chart {
background-color: #202020;
}
.chart rect {
shape-rendering: crispEdges;
stroke: none;
}
.chart rect.sq {
fill: lightsteelblue;
}
.chart rect.status {
fill: none;
stroke: #eee;
}
.chart rect.active {
fill: olivedrab;
stroke: none;
}
.chart text {
fill: #eee;
font-family: "Lucida Grande", sans-serif;
font-size: 10px;
stroke: none;
text-rendering: optimizeLegibility;
}
.chart line {
stroke-width: 1;
stroke: #333;
}
</style>
<script type="text/javascript" src="d3.min.js"></script>
</head>
<body>
<div id="viz"></div>
<script type="text/javascript">
var data = {
"1": ["04", "1", "9", "1"],
"2": ["17", "1", "9", "1"],
"3": ["08", "1", "4", "1"],
"4": ["24", "0", "0", "0"],
"5": ["20", "1", "5", "1"],
"6": ["00", "0", "S", "0"],
"7": ["32", "0", "S", "0"],
"8": ["00", "0", "S", "0"],
"9": ["09", "1", "8", "1"],
"10": ["11", "0", "S", "0"],
"11": ["01", "1", "8", "1"],
"12": ["28", "1", "9", "1"]
};
var keys = d3.keys(data),
w = 25 * keys.length + 50,
h = 150,
padding = 1,
scale = d3.scale.linear()
.domain([0, 9])
.range([0, h-20]);
var svg = d3.select('#viz')
.append('svg')
.attr('class', 'chart')
.attr('width', w)
.attr('height', h + 60);
// Signal quality bars.
var bars = svg.selectAll('rect.sq')
.data(keys.map(function(k) {
return data[k][2];
}))
.enter().append('rect')
.attr('class', 'sq')
.attr('x', function(d, i) {
return i * 25 + 50;
})
.attr('y', function(d) {
return (isNaN(d) || d == 0 ? h - 1 : h - scale(d));
})
.attr('width', 25 - padding)
.attr('height', function(d) {
return (isNaN(d) || d == 0 ? 1 : scale(d));
});
// Channel
svg.selectAll('text.channel')
.data(keys)
.enter().append('text')
.attr('x', function(d, i) {
return (i * 25 + 50) + (25 / 2);
})
.attr('y', 10)
.attr('text-anchor', 'middle')
.text(function(d) {
return d;
});
svg.append('line')
.attr('x1', 0)
.attr('y1', 15)
.attr('x2', w + 50)
.attr('y2', 15);
svg.append('text').text('Channel')
.attr('x', 50)
.attr('y', 10)
.attr('text-anchor', 'end');
// Satelites
svg.append('line')
.attr('x1', 0)
.attr('y1', h + 20)
.attr('x2', w + 50)
.attr('y2', h + 20);
svg.append('text').text('Satellite')
.attr('x', 50)
.attr('y', h + 15)
.attr('text-anchor', 'end');
svg.selectAll('text.prn')
.data(keys.map(function(k) {
return data[k][0];
}))
.enter().append('text')
.attr('x', function(d, i) {
return (i * 25 + 50) + (25 / 2);
})
.attr('y', h + 15)
.attr('text-anchor', 'middle')
.text(function(d) { return d; });
// Signal Quality
svg.append('line')
.attr('x1', 0)
.attr('y1', h + 40)
.attr('x2', w + 50)
.attr('y2', h + 40);
svg.append('text').text('SQ')
.attr('x', 50)
.attr('y', h + 35)
.attr('text-anchor', 'end');
svg.selectAll('text.prn')
.data(keys.map(function(k) {
return data[k][2];
}))
.enter().append('text')
.attr('x', function(d, i) {
return (i * 25 + 50) + (25 / 2);
})
.attr('y', h + 35)
.attr('text-anchor', 'middle')
.text(function(d) { return d; });
// Ephemeris
svg.append('line')
.attr('x1', 0)
.attr('y1', h + 60)
.attr('x2', w + 50)
.attr('y2', h + 60);
svg.append('text').text('EPH')
.attr('x', 50)
.attr('y', h + 55)
.attr('text-anchor', 'end');
svg.selectAll('rect.ephemeris')
.data(d3.keys(data).map(function(k) {
return data[k][3];
}))
.enter().append('rect')
.attr('class', function(d) {
return d == 1 ? 'status active' : 'status';
})
.attr('x', function(d, i) {
return (i * 25 + 50) + (15 / 2);
})
.attr('y', h + 45)
.attr('width', 10)
.attr('height', 10);
function redraw() {
bars = svg.selectAll('rect.sq')
.data(keys.map(function(k) {
return data[k][2];
}))
.transition()
.duration(1000)
.attr('y', function(d) {
return (isNaN(d) ? h - 1 : h - scale(d));
})
.attr('height', function(d) {
return (isNaN(d) || d == 0 ? 1 : scale(d));
});
}
setInterval(function() {
function random() {
return Math.random()*9;
}
data = {
"1": ["04", "1", random(), "1"],
"2": ["17", "1", random(), "1"],
"3": ["08", "1", random(), "1"],
"4": ["24", "0", random(), "0"],
"5": ["20", "1", random(), "1"],
"6": ["00", "0", random(), "0"],
"7": ["32", "0", random(), "0"],
"8": ["00", "0", random(), "0"],
"9": ["09", "1", random(), "1"],
"10": ["11", "0", random(), "0"],
"11": ["01", "1", random(), "1"],
"12": ["28", "1", random(), "1"]
};
redraw();
}, 1500);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment