mirror of
https://github.com/ankitects/anki.git
synced 2026-01-10 12:33:55 -05:00
simplified code in time.ts and review.rs and pass bin boundaries directly to time.ts
This commit is contained in:
parent
c457b43a87
commit
0c2c5c6a1c
2 changed files with 14 additions and 31 deletions
|
|
@ -177,28 +177,18 @@ export function dayLabel(daysStart: number, daysEnd: number): string {
|
||||||
daysStart,
|
daysStart,
|
||||||
daysEnd: daysEnd - 1,
|
daysEnd: daysEnd - 1,
|
||||||
});
|
});
|
||||||
|
} else if (daysEnd <= 0) {
|
||||||
|
// Past: [-10, -5) -> "5-9 days ago"
|
||||||
|
return tr.statisticsDaysAgoRange({
|
||||||
|
daysStart: Math.abs(daysEnd),
|
||||||
|
daysEnd: Math.abs(daysStart) - 1,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// For bins that cross or end at day 0, we need special handling
|
// Crosses zero: [-5, 1) -> "0-4 days ago"
|
||||||
if (daysEnd > 0) {
|
|
||||||
// Bin crosses day 0: show from 0 to the oldest day (exclusive of endDay)
|
|
||||||
// If bin is [-5, 1), we want "0-4 days ago"
|
|
||||||
return tr.statisticsDaysAgoRange({
|
return tr.statisticsDaysAgoRange({
|
||||||
daysStart: 0,
|
daysStart: 0,
|
||||||
daysEnd: -daysStart - 1,
|
daysEnd: Math.abs(daysStart) - 1,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// Bin is entirely in the past: show from newest to oldest
|
|
||||||
// For a bin [startDay, endDay), to show consecutive ranges like "0-4", "5-9", "10-14",
|
|
||||||
// we use endDay as the start of the range
|
|
||||||
// The bin width is daysEnd - daysStart, so daysEnd = daysStart + (width - 1)
|
|
||||||
// Example: bin [-10, -5) has width 5, should show "5-9 days ago"
|
|
||||||
const binWidth = Math.abs(daysEnd - daysStart);
|
|
||||||
const daysStartAbs = Math.abs(daysEnd);
|
|
||||||
return tr.statisticsDaysAgoRange({
|
|
||||||
daysStart: daysStartAbs,
|
|
||||||
daysEnd: daysStartAbs + binWidth - 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -234,17 +234,10 @@ export function renderReviews(
|
||||||
}
|
}
|
||||||
|
|
||||||
function tooltipText(d: BinType, cumulative: number): string {
|
function tooltipText(d: BinType, cumulative: number): string {
|
||||||
|
// Convert bin boundaries [x0, x1) for dayLabel
|
||||||
|
// If bin ends at 0, treat it as crossing zero so day 0 is included
|
||||||
const startDay = Math.floor(d.x0!);
|
const startDay = Math.floor(d.x0!);
|
||||||
// If bin ends at 0, treat it as including day 0 (so use 1 as endDay for dayLabel)
|
const endDay = d.x1! === 0 ? 1 : d.x1!;
|
||||||
// For negative bins, use the bin end directly (dayLabel will handle the conversion)
|
|
||||||
let endDay: number;
|
|
||||||
if (d.x1! === 0) {
|
|
||||||
endDay = 1;
|
|
||||||
} else if (d.x1! < 0) {
|
|
||||||
endDay = d.x1!;
|
|
||||||
} else {
|
|
||||||
endDay = Math.ceil(d.x1!);
|
|
||||||
}
|
|
||||||
const day = dayLabel(startDay, endDay);
|
const day = dayLabel(startDay, endDay);
|
||||||
const totals = totalsForBin(d);
|
const totals = totalsForBin(d);
|
||||||
const dayTotal = valueLabel(sum(totals));
|
const dayTotal = valueLabel(sum(totals));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue