Public
Edited
Feb 26, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(null, context).projection(projection);
context.canvas.style.maxWidth = "100%";
context.lineJoin = "round";
context.lineCap = "round";
context.beginPath();
path(italyBorders);
context.fillStyle = '#f9f9f9'
context.fill();

context.beginPath();
path(subRegionBorders);
context.lineWidth = 0.5;
context.strokeStyle = "#aaa";
context.stroke();

context.beginPath();
path(regionBorders);
context.lineWidth = 1;
context.strokeStyle = "#888";
context.stroke();

context.beginPath();
path(italyBorders);
context.lineWidth = 1;
context.strokeStyle = "#000";
context.stroke();

context.save();

for (const gasStation of selectedGasStations) {
const point = gasStation.point

const detail = gasStation.pricesMap?.get(fuelType)?.get(isSelf)
context.beginPath();
context.moveTo(point[0], point[1]);
context.arc(point[0], point[1], 1.5, 0, 2 * Math.PI);
context.fillStyle = detail ? colorScale(priceAccessor(detail)) : 'none';
context.fill();
}

context.restore()
return context.canvas;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gasStationPricesIndex = d3.index(gasStationPrices, idAccessor, fuelTypeAccessor, isSelfAccessor)
Insert cell
idAccessor = d => d.idImpianto
Insert cell
fuelTypeAccessor = d => d.descCarburante
Insert cell
isSelfAccessor = d => d.isSelf
Insert cell
priceAccessor = d => +d.prezzo
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