Built with blockbuilder.org
Last active
November 15, 2017 15:44
-
-
Save aaronbalthaser/12ce9c51514dfb406488c1ed1c1f93c5 to your computer and use it in GitHub Desktop.
fresh block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
.chart { | |
background: lightgray; | |
border: 1px solid black; | |
width: 600px; | |
height: 400px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="chart"></div> | |
<script> | |
var data = [ | |
{"name": 'E2E Tests', "passed": 4, "notRun": 4, "failed": 0, "blocked": 0, "notApplicable": 0 }, | |
{"name": '868: Services', "passed": 3, "notRun": 3, "failed": 1, "blocked": 0, "notApplicable": 0 }, | |
{"name": '869: Services', "passed": 2, "notRun": 1, "failed": 2, "blocked": 1, "notApplicable": 0 }, | |
{"name": 'Bugs fixed', "passed": 1, "notRun": 1, "failed": 0, "blocked": 2, "notApplicable": 0 }, | |
{"name": '870: Services', "passed": 2, "notRun": 0, "failed": 1, "blocked": 0, "notApplicable": 1 }, | |
{"name": '867: Local', "passed": 3, "notRun": 0, "failed": 1, "blocked": 0, "notApplicable": 0 }, | |
{"name": '866: Local', "passed": 3, "notRun": 1, "failed": 0, "blocked": 0, "notApplicable": 0 } | |
]; | |
var keys = ["passed", "notRun", "failed", "failed", "blocked", "notApplicable"]; | |
var margin = { top: 10, right: 25, bottom: 30, left: 80 }; | |
var width = 600 - margin.left - margin.right; | |
var height = 400 - margin.top - margin.bottom; | |
var color = d3.scaleOrdinal(d3.schemeCategory20); | |
var svg = d3.select('.chart') | |
.append('svg') | |
.attr('width', width + margin.left + margin.right) | |
.attr('height', height + margin.top + margin.bottom) | |
.call(responsivefy) | |
.append('g') | |
.attr('transform', `translate(${margin.left}, ${margin.top})`); | |
// Y Axis | |
var yScale = d3.scaleBand() | |
.domain(data.map(d => d.name)) | |
.range([height, 0]) | |
var yAxis = d3.axisLeft(yScale); | |
svg.call(yAxis); | |
// X Axis | |
var xScale = d3.scaleLinear() | |
.domain([0, 8]) | |
.range([0, width]); | |
var xAxis = d3.axisBottom(xScale) | |
.ticks(8) | |
.tickFormat(d3.format("d")); | |
svg.append('g') | |
.attr('transform', `translate(0, ${height})`) | |
.call(xAxis); | |
function responsivefy(svg) { | |
var container = d3.select(svg.node().parentNode); | |
var width = parseInt(svg.style('width')); | |
var height = parseInt(svg.style('height')); | |
var aspect = width / height; | |
svg.attr('viewBox', '0 0 ' + width + ' ' + height) | |
.attr('preserveAspectRatio', 'xMinYMid') | |
.call(resize); | |
d3.select(window).on('resize.' + container.attr('id'), resize); | |
function resize() { | |
var targetWidth = parseInt(container.style('width')); | |
svg.attr('width', targetWidth); | |
svg.attr('height', Math.round(targetWidth / aspect)); | |
} | |
} | |
</script> | |
</body> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment