{
let c = DOM.canvas(width, width / 2.4);
new Chart(c.getContext("2d"), {
type: 'bar',
data: {
labels: ["Seattle", "San-Diego", "New-York", "Chicago", "Los-Angeles"],
datasets: [
{
label: "Supply capacity of plants (cases)",
backgroundColor: "#3e95cd",
data: [mutable supply.Seattle, mutable supply['San-Diego']]
},
{
label: "Demand of markets (cases)",
backgroundColor: "#cd3e5c",
data: [
0,
0,
mutable demand['New-York'],
mutable demand.Chicago,
mutable demand['Los-Angeles']
]
}
]
},
options: {
dragData: true,
dragDataRound: -1,
dragOptions: {
showTooltip: true
},
onDragEnd: (e, datasetIndex, index, value) => {
e.target.style.cursor = 'default';
if (datasetIndex === 0) {
if (index === 0) {
mutable supply = { ...mutable supply, Seattle: value };
} else {
mutable supply = { ...mutable supply, 'San-Diego': value };
}
} else {
if (index === 2) {
mutable demand = { ...mutable demand, 'New-York': value };
} else if (index === 3) {
mutable demand = { ...mutable demand, Chicago: value };
} else {
mutable demand = { ...mutable demand, 'Los-Angeles': value };
}
}
},
hover: {
onHover: function(e) {
const point = this.getElementAtEvent(e);
if (point.length) e.target.style.cursor = 'grab';
else e.target.style.cursor = 'default';
}
},
scales: {
xAxes: [
{
stacked: true,
barPercentage: 1,
categoryPercentage: 0.8,
barThickness: 'flex'
}
],
yAxes: [
{
stacked: true,
ticks: {
max: 800,
min: 0
}
}
]
}
}
});
return c;
}