mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Satisfy formatter
This commit is contained in:
parent
15123915a0
commit
f5e90bb249
2 changed files with 31 additions and 30 deletions
|
@ -2,13 +2,10 @@
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
export let i18n: I18n;
|
export let i18n: I18n;
|
||||||
export let separateInactive: bool = false;
|
export let separateInactive: boolean = false;
|
||||||
|
|
||||||
const label = "Separate suspended/buried cards";
|
const label = "Separate suspended/buried cards";
|
||||||
const all = i18n.tr(i18n.TR.STATISTICS_RANGE_ALL_TIME);
|
const all = i18n.tr(i18n.TR.STATISTICS_RANGE_ALL_TIME);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label>
|
<label> <input type="checkbox" bind:checked={separateInactive} /> {label} </label>
|
||||||
<input type="checkbox" bind:checked={separateInactive} />
|
|
||||||
{label}
|
|
||||||
</label>
|
|
||||||
|
|
|
@ -35,7 +35,11 @@ const barColours = [
|
||||||
"grey" /* buried */,
|
"grey" /* buried */,
|
||||||
];
|
];
|
||||||
|
|
||||||
function countCards(cards: pb.BackendProto.ICard[], separateInactive: boolean, i18n: I18n): Count[] {
|
function countCards(
|
||||||
|
cards: pb.BackendProto.ICard[],
|
||||||
|
separateInactive: boolean,
|
||||||
|
i18n: I18n
|
||||||
|
): Count[] {
|
||||||
let newCards = 0;
|
let newCards = 0;
|
||||||
let learn = 0;
|
let learn = 0;
|
||||||
let relearn = 0;
|
let relearn = 0;
|
||||||
|
@ -77,16 +81,19 @@ function countCards(cards: pb.BackendProto.ICard[], separateInactive: boolean, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const counts: Count[] = [
|
const counts: Count[] = [
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS), newCards, true],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS), newCards, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS), learn, true],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS), learn, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS), relearn, true],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS), relearn, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS), young, true],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS), young, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS), mature, true],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS), mature, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS), suspended, separateInactive],
|
[
|
||||||
|
i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS),
|
||||||
|
suspended,
|
||||||
|
separateInactive,
|
||||||
|
],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS), buried, separateInactive],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS), buried, separateInactive],
|
||||||
]
|
];
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +104,7 @@ export function gatherData(
|
||||||
i18n: I18n
|
i18n: I18n
|
||||||
): GraphData {
|
): GraphData {
|
||||||
const totalCards = data.cards.length;
|
const totalCards = data.cards.length;
|
||||||
const counts = countCards(data.cards, separateInactive, i18n)
|
const counts = countCards(data.cards, separateInactive, i18n);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: i18n.tr(i18n.TR.STATISTICS_COUNTS_TITLE),
|
title: i18n.tr(i18n.TR.STATISTICS_COUNTS_TITLE),
|
||||||
|
@ -119,7 +126,7 @@ export interface SummedDatum {
|
||||||
// count of this particular item
|
// count of this particular item
|
||||||
count: number;
|
count: number;
|
||||||
// show up in the table
|
// show up in the table
|
||||||
show: boolean,
|
show: boolean;
|
||||||
// running total
|
// running total
|
||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +170,8 @@ export function renderCards(
|
||||||
.selectAll("path")
|
.selectAll("path")
|
||||||
.data(pieData)
|
.data(pieData)
|
||||||
.join(
|
.join(
|
||||||
(enter) => enter
|
(enter) =>
|
||||||
|
enter
|
||||||
.append("path")
|
.append("path")
|
||||||
.attr("fill", (_d, idx) => {
|
.attr("fill", (_d, idx) => {
|
||||||
return barColours[idx];
|
return barColours[idx];
|
||||||
|
@ -171,15 +179,12 @@ export function renderCards(
|
||||||
.attr("d", arcGen as any),
|
.attr("d", arcGen as any),
|
||||||
function (update) {
|
function (update) {
|
||||||
return update.call((d) =>
|
return update.call((d) =>
|
||||||
d
|
d.transition(trans).attrTween("d", (d) => {
|
||||||
.transition(trans)
|
|
||||||
.attrTween("d", (d) => {
|
|
||||||
const interpolator = interpolate(
|
const interpolator = interpolate(
|
||||||
{ startAngle: 0, endAngle: 0 },
|
{ startAngle: 0, endAngle: 0 },
|
||||||
d
|
d
|
||||||
);
|
);
|
||||||
return (t): string =>
|
return (t): string => arcGen(interpolator(t) as any) as string;
|
||||||
arcGen(interpolator(t) as any) as string;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -187,16 +192,15 @@ export function renderCards(
|
||||||
|
|
||||||
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
||||||
|
|
||||||
// @ts-ignore
|
const tableData = (data as any).flatMap((d: SummedDatum, idx: number) => {
|
||||||
const tableData = data.flatMap((d: SummedDatum, idx: number) => {
|
|
||||||
const percent = ((d.count / xMax) * 100).toFixed(1);
|
const percent = ((d.count / xMax) * 100).toFixed(1);
|
||||||
return d.show
|
return d.show
|
||||||
? {
|
? ({
|
||||||
label: d.label,
|
label: d.label,
|
||||||
count: d.count,
|
count: d.count,
|
||||||
percent: `${percent}%`,
|
percent: `${percent}%`,
|
||||||
colour: barColours[idx],
|
colour: barColours[idx],
|
||||||
} as TableDatum
|
} as TableDatum)
|
||||||
: [];
|
: [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue