diff --git a/ts/src/stats/FutureDue.svelte b/ts/src/stats/FutureDue.svelte index 9817e59c7..a0773e1c2 100644 --- a/ts/src/stats/FutureDue.svelte +++ b/ts/src/stats/FutureDue.svelte @@ -14,6 +14,7 @@ let graphData = null as GraphData | null; let histogramData = null as HistogramData | null; let tableData: TableDatum[] = [] as any; + let haveBacklog: boolean = false; let backlog: boolean = true; let graphRange: GraphRange = GraphRange.Month; @@ -22,12 +23,12 @@ } $: if (graphData) { - [histogramData, tableData] = buildHistogram( + ({ histogramData, tableData } = buildHistogram( graphData, graphRange, backlog, i18n - ); + )); } const title = i18n.tr(i18n.TR.STATISTICS_FUTURE_DUE_TITLE); @@ -41,10 +42,12 @@
{subtitle}
- + {#if graphData && graphData.haveBacklog} + + {/if}
diff --git a/ts/src/stats/future-due.ts b/ts/src/stats/future-due.ts index abc16e2b1..13d6a46bc 100644 --- a/ts/src/stats/future-due.ts +++ b/ts/src/stats/future-due.ts @@ -18,11 +18,13 @@ import { GraphRange, TableDatum } from "./graphs"; export interface GraphData { dueCounts: Map; + haveBacklog: boolean; } export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { const isLearning = (queue: number): boolean => [CardQueue.Learn, CardQueue.PreviewRepeat].includes(queue); + let haveBacklog = false; const due = (data.cards as pb.BackendProto.Card[]) .filter( (c) => @@ -39,7 +41,11 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { // - testing just odid fails on lapsed cards that // have due calculated at regraduation time const due = c.odid && c.odue ? c.odue : c.due; - return due - data.daysElapsed; + const dueDay = due - data.daysElapsed; + if (dueDay < 0) { + haveBacklog = true; + } + return dueDay; } }); @@ -48,23 +54,29 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { (v) => v.length, (d) => d ); - return { dueCounts }; + return { dueCounts, haveBacklog }; } function binValue(d: Bin, number>): number { return sum(d, (d) => d[1]); } +export interface FutureDueOut { + histogramData: HistogramData | null; + tableData: TableDatum[]; +} + export function buildHistogram( sourceData: GraphData, range: GraphRange, backlog: boolean, i18n: I18n -): [HistogramData | null, TableDatum[]] { +): FutureDueOut { + const output = { histogramData: null, tableData: [] }; // get min/max const data = sourceData.dueCounts; if (!data) { - return [null, []]; + return output; } const [xMinOrig, origXMax] = extent(data.keys()); @@ -101,7 +113,7 @@ export function buildHistogram( // empty graph? if (!sum(bins, (bin) => bin.length)) { - return [null, []]; + return output; } const adjustedRange = scaleLinear().range([0.7, 0.3]); @@ -147,8 +159,8 @@ export function buildHistogram( }, ]; - return [ - { + return { + histogramData: { scale: x, bins, total, @@ -158,5 +170,5 @@ export function buildHistogram( binValue, }, tableData, - ]; + }; }