Plot.plot({
width,
height: 500,
marginBottom: 70,
marginTop: 30,
y: {
inset: 5,
grid: true,
tickFormat: (x => `${x}`+ ((data_vis.name).includes("USA") ? " $" : " €")),
label: "↑ prices",
},
x: {
tickRotate: 45,
label: ((data_vis.name).includes("iPhone") ? "→ iPhones" : "→ Galaxys"),
inset: 25,
tickFormat: x => `${x.replace(/\d\d iPhone|\d\d Galaxy /i,'')}`,
labelAnchor: "right"
},
color: {
range: colorRange,
type: "ordinal",
domain: data.year,
},
marks: [
Plot.ruleX(data,
Plot.groupX({y1: "min", y2: "max"},
{y: "price", x: "model", stroke: 'year', strokeWidth: 2.5})),
Plot.ruleY([0,2300]),
Plot.dot(data, {x: 'model',
y: 'price',
title: (d) =>`${d.model.replace(/\d\d/i,'')} \n Announce: ${moment(d.release).format('ll')} \n Price: ${d.price}${(data_vis.name).includes("USA") ? " $" : " €"} \n Storage: ${d.storage} GB`,
fill: "year",
r: 4 }),
],
tooltip: {
fill: "red",
stroke: "blue",
r: 8
}
})