mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Make pie graphs display correctly when switching between categories
This commit is contained in:
parent
681d82f5cc
commit
15123915a0
1 changed files with 21 additions and 16 deletions
|
@ -18,7 +18,7 @@ import type { GraphBounds } from "./graph-helpers";
|
||||||
import { cumsum } from "d3-array";
|
import { cumsum } from "d3-array";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
type Count = [string, number];
|
type Count = [string, number, boolean];
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
title: string;
|
title: string;
|
||||||
counts: Count[];
|
counts: Count[];
|
||||||
|
@ -79,16 +79,15 @@ function countCards(cards: pb.BackendProto.ICard[], separateInactive: boolean, i
|
||||||
|
|
||||||
|
|
||||||
const counts: Count[] = [
|
const counts: Count[] = [
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS), newCards],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS), newCards, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS), learn],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS), learn, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS), relearn],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS), relearn, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS), young],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS), young, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS), mature],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS), mature, true],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS), suspended],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS), suspended, separateInactive],
|
||||||
[i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS), buried],
|
[i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS), buried, separateInactive],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +118,8 @@ export interface SummedDatum {
|
||||||
label: string;
|
label: string;
|
||||||
// count of this particular item
|
// count of this particular item
|
||||||
count: number;
|
count: number;
|
||||||
|
// show up in the table
|
||||||
|
show: boolean,
|
||||||
// running total
|
// running total
|
||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
|
@ -141,6 +142,7 @@ export function renderCards(
|
||||||
return {
|
return {
|
||||||
label: count[0],
|
label: count[0],
|
||||||
count: count[1],
|
count: count[1],
|
||||||
|
show: count[2],
|
||||||
idx,
|
idx,
|
||||||
total: n,
|
total: n,
|
||||||
} as SummedDatum;
|
} as SummedDatum;
|
||||||
|
@ -185,14 +187,17 @@ export function renderCards(
|
||||||
|
|
||||||
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
||||||
|
|
||||||
const tableData = data.map((d, idx) => {
|
// @ts-ignore
|
||||||
|
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 {
|
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
|
||||||
|
: [];
|
||||||
});
|
});
|
||||||
|
|
||||||
return tableData;
|
return tableData;
|
||||||
|
|
Loading…
Reference in a new issue