Published
Edited
Apr 23, 2020
Insert cell
md`# Primrose's field by Akiyoshi Kitaoka

As seen [here](http://www.ritsumei.ac.jp/~akitaoka/index-e.html).`
Insert cell
{
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font", "9px sans-serif");
var rectSize = 30;
const data = d3.range(17);
for(var row=0; row<data.length; row++) {
const parts = svg.append("g")
.selectAll('.element')
.data(data)
.join("g")
.attr("class", "element")
.attr("transform", (d,i) => `translate(${i*rectSize},${row*rectSize})`);
parts.append('rect')
.attr('fill', (d,i) => (i+row) % 2 ? '#A0D733' : '#4FBB81')
.attr('width', rectSize)
.attr('height', rectSize)
}
var series = [0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1]
for(var row=0; row<data.length-1; row++) {
const parts = svg.append("g")
.selectAll('.element')
.data(data)
.join("g")
.attr("class", "element")
.attr("opacity", (d,i) => (i < data.length - 1) ? 1 : 0)
.attr("transform", (d,i) => `translate(${i*rectSize},${row*rectSize})`);
const size = 20;
const offset = 4;
parts.append('path')
.attr('transform', `translate(${rectSize},${rectSize-offset})`)
.attr('fill' , (d,i) => series[i] ? '#CF0099' : 'white')
.attr('d', d3.symbol().type(d3.symbolDiamond).size(size));
parts.append('path')
.attr('transform', `translate(${rectSize},${rectSize+offset})`)
.attr('fill' , (d,i) => series[i] ? '#CF0099' : 'white')
.attr('d', d3.symbol().type(d3.symbolDiamond).size(size));
parts.append('path')
.attr('transform', `translate(${rectSize+offset},${rectSize}) rotate(-90)`)
.attr('fill' , (d,i) => series[i] ? '#CF0099' : 'white')
.attr('d', d3.symbol().type(d3.symbolDiamond).size(size));
parts.append('path')
.attr('transform', `translate(${rectSize-offset},${rectSize}) rotate(90)`)
.attr('fill' , (d,i) => series[i] ? '#CF0099' : 'white')
.attr('d', d3.symbol().type(d3.symbolDiamond).size(size));
series = arrayRotate(series, true);
}
return svg.node();
}
Insert cell
function arrayRotate(arr, reverse) {
if (reverse) arr.unshift(arr.pop());
else arr.push(arr.shift());
return arr;
}
Insert cell
style = html`
<style>
circle {
shape-rendering: geometricprecision;
}

</style>`
Insert cell
height = 600
Insert cell
d3 = require('d3@5')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more