Published
Edited
Dec 9, 2020
3 stars
Insert cell
Insert cell
elements = 'change this variable to colour' // this triggers an update
Insert cell
Insert cell
mutable e = []
Insert cell
updatefill = {
const t1 = 900;
const t2 = 1500;

mutable e
.transition() //
.duration(t1)
.attr('opacity', 0)
.attr('fill', 'white')
.delay(t1 / 2)
.duration(t2)
.attr("fill", function(d) {
try {
return getcol(d.properties.GEOCODIGO);
} catch (e) {
return 'white';
}
})
.attr('opacity', 1);

// .attrTween("fill", function(d) {
// //console.log(d.properties.Geocod);
// return d3.interpolateRgb(
// '#333', //d3.color(this.getAttribute("fill")),
// d3.color(
// getcol(d.properties.Geocod)

// //cmap[Math.round(Math.random() * cmap.length)]
// )
// );
// });

return elements.length;
}
Insert cell
Insert cell
getcol = function(id) {
var info = elements[id];
var x = info[col[0]] + 1;
var y = info[col[1]] + 1;

const step = .6;

if (x + y === 0) {
return 'white';
} else if (x > 3) {
return d3.color(cmap[3 * 3 + y]).darker(step);
} else if (y > 3) {
return d3.color(cmap[x * 3 + 3]).darker(step);
}

return cmap[x * 4 + y];
}
Insert cell
col=['vhi','spi3']
Insert cell
data = null
Insert cell
transition = d3
.transition()
.duration(750)
.ease(d3.easeLinear)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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