single graph
This commit is contained in:
@@ -299,14 +299,18 @@ export default function Home() {
|
|||||||
[ammoPageCaliberIds, enabledCalibers],
|
[ammoPageCaliberIds, enabledCalibers],
|
||||||
);
|
);
|
||||||
const ammoChartData = useMemo(() => {
|
const ammoChartData = useMemo(() => {
|
||||||
const withRounds = enabledAmmoInventory
|
const sortedInventory = [...enabledAmmoInventory].sort((left, right) => {
|
||||||
.filter((inventory) => inventory.roundsOnHand > 0)
|
if (right.roundsOnHand !== left.roundsOnHand) {
|
||||||
.sort((left, right) => right.roundsOnHand - left.roundsOnHand);
|
return right.roundsOnHand - left.roundsOnHand;
|
||||||
const maxRounds = withRounds[0]?.roundsOnHand ?? 0;
|
}
|
||||||
|
|
||||||
return withRounds.map((inventory) => ({
|
return left.caliber.localeCompare(right.caliber);
|
||||||
|
});
|
||||||
|
const maxRounds = sortedInventory[0]?.roundsOnHand ?? 0;
|
||||||
|
|
||||||
|
return sortedInventory.map((inventory) => ({
|
||||||
...inventory,
|
...inventory,
|
||||||
widthPercent: maxRounds > 0 ? Math.max((inventory.roundsOnHand / maxRounds) * 100, 8) : 0,
|
widthPercent: maxRounds > 0 ? Math.max((inventory.roundsOnHand / maxRounds) * 100, inventory.roundsOnHand > 0 ? 8 : 0) : 0,
|
||||||
}));
|
}));
|
||||||
}, [enabledAmmoInventory]);
|
}, [enabledAmmoInventory]);
|
||||||
const firearmCategoryCounts = useMemo(
|
const firearmCategoryCounts = useMemo(
|
||||||
@@ -1291,7 +1295,7 @@ export default function Home() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{ammoChartData.length === 0 ? (
|
{ammoChartData.length === 0 ? (
|
||||||
<p className="placeholder-copy">Add rounds to a caliber to see how your inventory stacks up.</p>
|
<p className="placeholder-copy">Enable calibers in Settings to see your ammo inventory chart.</p>
|
||||||
) : (
|
) : (
|
||||||
<div className="ammo-chart">
|
<div className="ammo-chart">
|
||||||
{ammoChartData.map((inventory) => (
|
{ammoChartData.map((inventory) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user