mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
hide backlog button when there's no backlog
This commit is contained in:
parent
ceb342cbc2
commit
4b14ff8c8e
2 changed files with 29 additions and 14 deletions
|
@ -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 @@
|
|||
<div class="subtitle">{subtitle}</div>
|
||||
|
||||
<div class="range-box-inner">
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={backlog} />
|
||||
{backlogLabel}
|
||||
</label>
|
||||
{#if graphData && graphData.haveBacklog}
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={backlog} />
|
||||
{backlogLabel}
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<GraphRangeRadios bind:graphRange {i18n} revlogRange={RevlogRange.All} />
|
||||
</div>
|
||||
|
|
|
@ -18,11 +18,13 @@ import { GraphRange, TableDatum } from "./graphs";
|
|||
|
||||
export interface GraphData {
|
||||
dueCounts: Map<number, number>;
|
||||
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<Map<number, number>, 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<number>(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,
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue