Skip to content

Instantly share code, notes, and snippets.

@henryjameslau
Last active January 15, 2019 17:57
Show Gist options
  • Save henryjameslau/e03a5289d151bf25bdbbb762471996d3 to your computer and use it in GitHub Desktop.
Save henryjameslau/e03a5289d151bf25bdbbb762471996d3 to your computer and use it in GitHub Desktop.
ONS colours for graphs
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script src="https://npmcdn.com/[email protected]/browser.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/gka/chroma.js/master/chroma.min.js"></script>
<style>
svg {
width: 800px;
height: 2000px;
}
</style>
</head>
<body>
<svg></svg>
<script>
var threeColours=['#53759e','#9ad859','#79c6c1'];
var fourColours=["#a0e85b", "#9d6190", "#569160", "#f33bea"]
var fiveColours=["#8c75d2", "#758c45", "#891b9b", "#abd533", "#552a61"]
var sixColours=["#3e76ad","#339a59","#e2bc22","#74abc5","#601552","#dc98ff"]
var colors = [];
threeColours.forEach(function(d){makecolours(d)})
fourColours.forEach(function(d){makecolours(d)})
fiveColours.forEach(function(d){makecolours(d)})
sixColours.forEach(function(d){makecolours(d)})
var svg = d3.select('svg');
var perRow = 2;
var size = 90;
var g = svg.selectAll('g')
.data(colors).enter().append('g')
.attr('transform', (d, i) => {
var x = (i % perRow + 1) * size;
var y = (Math.floor(i / perRow) + 1) * size;
return 'translate(' + [x, y] + ')';
}).attr('fill', d => d);
g.append('circle')
.attr('r', size / 4);
g.append('text')
.attr('y', size / 4 + 15)
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.text((d, i) => d);
function makecolours(d){
// colors.push(chroma(d).darken(0.5).desaturate(0.5).hex())
// colors.push(chroma(d).darken(0.5).hex())
colors.push(chroma(d).darken(0.5).saturate(0.5).hex())
// colors.push(chroma(d).desaturate(1).hex())
colors.push(chroma(d).hex())
// colors.push(chroma(d).saturate(1).hex())
// colors.push(chroma(d).brighten(0.5).desaturate(0.5).hex())
// colors.push(chroma(d).brighten(0.5).hex())
// colors.push(chroma(d).brighten(0.5).saturate(0.5).hex())
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment