hide backlog button when there's no backlog

This commit is contained in:
Damien Elmes 2020-08-10 14:37:23 +10:00
parent ceb342cbc2
commit 4b14ff8c8e
2 changed files with 29 additions and 14 deletions

View file

@ -14,6 +14,7 @@
let graphData = null as GraphData | null; let graphData = null as GraphData | null;
let histogramData = null as HistogramData | null; let histogramData = null as HistogramData | null;
let tableData: TableDatum[] = [] as any; let tableData: TableDatum[] = [] as any;
let haveBacklog: boolean = false;
let backlog: boolean = true; let backlog: boolean = true;
let graphRange: GraphRange = GraphRange.Month; let graphRange: GraphRange = GraphRange.Month;
@ -22,12 +23,12 @@
} }
$: if (graphData) { $: if (graphData) {
[histogramData, tableData] = buildHistogram( ({ histogramData, tableData } = buildHistogram(
graphData, graphData,
graphRange, graphRange,
backlog, backlog,
i18n i18n
); ));
} }
const title = i18n.tr(i18n.TR.STATISTICS_FUTURE_DUE_TITLE); const title = i18n.tr(i18n.TR.STATISTICS_FUTURE_DUE_TITLE);
@ -41,10 +42,12 @@
<div class="subtitle">{subtitle}</div> <div class="subtitle">{subtitle}</div>
<div class="range-box-inner"> <div class="range-box-inner">
<label> {#if graphData && graphData.haveBacklog}
<input type="checkbox" bind:checked={backlog} /> <label>
{backlogLabel} <input type="checkbox" bind:checked={backlog} />
</label> {backlogLabel}
</label>
{/if}
<GraphRangeRadios bind:graphRange {i18n} revlogRange={RevlogRange.All} /> <GraphRangeRadios bind:graphRange {i18n} revlogRange={RevlogRange.All} />
</div> </div>

View file

@ -18,11 +18,13 @@ import { GraphRange, TableDatum } from "./graphs";
export interface GraphData { export interface GraphData {
dueCounts: Map<number, number>; dueCounts: Map<number, number>;
haveBacklog: boolean;
} }
export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
const isLearning = (queue: number): boolean => const isLearning = (queue: number): boolean =>
[CardQueue.Learn, CardQueue.PreviewRepeat].includes(queue); [CardQueue.Learn, CardQueue.PreviewRepeat].includes(queue);
let haveBacklog = false;
const due = (data.cards as pb.BackendProto.Card[]) const due = (data.cards as pb.BackendProto.Card[])
.filter( .filter(
(c) => (c) =>
@ -39,7 +41,11 @@ export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
// - testing just odid fails on lapsed cards that // - testing just odid fails on lapsed cards that
// have due calculated at regraduation time // have due calculated at regraduation time
const due = c.odid && c.odue ? c.odue : c.due; 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, (v) => v.length,
(d) => d (d) => d
); );
return { dueCounts }; return { dueCounts, haveBacklog };
} }
function binValue(d: Bin<Map<number, number>, number>): number { function binValue(d: Bin<Map<number, number>, number>): number {
return sum(d, (d) => d[1]); return sum(d, (d) => d[1]);
} }
export interface FutureDueOut {
histogramData: HistogramData | null;
tableData: TableDatum[];
}
export function buildHistogram( export function buildHistogram(
sourceData: GraphData, sourceData: GraphData,
range: GraphRange, range: GraphRange,
backlog: boolean, backlog: boolean,
i18n: I18n i18n: I18n
): [HistogramData | null, TableDatum[]] { ): FutureDueOut {
const output = { histogramData: null, tableData: [] };
// get min/max // get min/max
const data = sourceData.dueCounts; const data = sourceData.dueCounts;
if (!data) { if (!data) {
return [null, []]; return output;
} }
const [xMinOrig, origXMax] = extent<number>(data.keys()); const [xMinOrig, origXMax] = extent<number>(data.keys());
@ -101,7 +113,7 @@ export function buildHistogram(
// empty graph? // empty graph?
if (!sum(bins, (bin) => bin.length)) { if (!sum(bins, (bin) => bin.length)) {
return [null, []]; return output;
} }
const adjustedRange = scaleLinear().range([0.7, 0.3]); const adjustedRange = scaleLinear().range([0.7, 0.3]);
@ -147,8 +159,8 @@ export function buildHistogram(
}, },
]; ];
return [ return {
{ histogramData: {
scale: x, scale: x,
bins, bins,
total, total,
@ -158,5 +170,5 @@ export function buildHistogram(
binValue, binValue,
}, },
tableData, tableData,
]; };
} }