Built with blockbuilder.org
Created
September 20, 2017 08:01
-
-
Save mtranggit/3e68b786e5b587afea6ce6359f8616bd to your computer and use it in GitHub Desktop.
Margin Convention with D3
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: 425px; | |
height: 625px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="chart"></div> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var margin = { top: 10, right: 10, bottom: 25, left: 25} | |
var width = 425 - margin.left - margin.right | |
var height = 625 - margin.top - margin.bottom | |
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})`) | |
svg.append('rect') | |
.attr('width', width/2) | |
.attr('height', height) | |
.style('fill', 'lightblue') | |
.style('stroke', 'lightgreen') | |
svg.append('rect') | |
.attr('x', width/2) | |
.attr('width', width/2) | |
.attr('height', height) | |
.style('fill', 'lightyellow') | |
.style('stroke', 'lightgreen') | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment