mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
use short form for time units in graph axis
This commit is contained in:
parent
2ff1a27b04
commit
4b6033e17f
3 changed files with 51 additions and 39 deletions
|
@ -162,3 +162,16 @@ statistics-hours-subtitle = Review success rate for each hour of the day.
|
||||||
# shown when graph is empty
|
# shown when graph is empty
|
||||||
statistics-no-data = NO DATA
|
statistics-no-data = NO DATA
|
||||||
statistics-calendar-title = Calendar
|
statistics-calendar-title = Calendar
|
||||||
|
|
||||||
|
## An amount of elapsed time, used in the graphs to show the amount of
|
||||||
|
## time spent studying. For example, English would show "5s" for 5 seconds,
|
||||||
|
## "13.5m" for 13.5 minutes, and so on.
|
||||||
|
|
||||||
|
statistics-elapsed-time-seconds = {$amount}s
|
||||||
|
statistics-elapsed-time-minutes = {$amount}m
|
||||||
|
statistics-elapsed-time-hours = {$amount}h
|
||||||
|
statistics-elapsed-time-days = {$amount}d
|
||||||
|
statistics-elapsed-time-months = {$amount}mo
|
||||||
|
statistics-elapsed-time-years = {$amount}y
|
||||||
|
|
||||||
|
##
|
||||||
|
|
|
@ -169,7 +169,7 @@ export function renderReviews(
|
||||||
.tickSizeOuter(0)
|
.tickSizeOuter(0)
|
||||||
.tickFormat(((n: number): string => {
|
.tickFormat(((n: number): string => {
|
||||||
if (showTime) {
|
if (showTime) {
|
||||||
return timeSpan(i18n, n / 1000);
|
return timeSpan(i18n, n / 1000, true);
|
||||||
} else {
|
} else {
|
||||||
if (Math.round(n) != n) {
|
if (Math.round(n) != n) {
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -70,15 +70,6 @@ function unitAmount(unit: TimespanUnit, secs: number): number {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unitAmountRounded(unit: TimespanUnit, secs: number): number {
|
|
||||||
const value = unitAmount(unit, secs);
|
|
||||||
if (unit === TimespanUnit.Seconds || unit === TimespanUnit.Days) {
|
|
||||||
return Math.round(value);
|
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function studiedToday(i18n: I18n, cards: number, secs: number): string {
|
export function studiedToday(i18n: I18n, cards: number, secs: number): string {
|
||||||
const unit = naturalUnit(secs);
|
const unit = naturalUnit(secs);
|
||||||
const amount = unitAmount(unit, secs);
|
const amount = unitAmount(unit, secs);
|
||||||
|
@ -96,40 +87,48 @@ export function studiedToday(i18n: I18n, cards: number, secs: number): string {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function i18nKeyForUnit(i18n: I18n, unit: TimespanUnit, short: boolean): number {
|
||||||
|
if (short) {
|
||||||
|
switch (unit) {
|
||||||
|
case TimespanUnit.Seconds:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_SECONDS;
|
||||||
|
case TimespanUnit.Minutes:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_MINUTES;
|
||||||
|
case TimespanUnit.Hours:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_HOURS;
|
||||||
|
case TimespanUnit.Days:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_DAYS;
|
||||||
|
case TimespanUnit.Months:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_MONTHS;
|
||||||
|
case TimespanUnit.Years:
|
||||||
|
return i18n.TR.STATISTICS_ELAPSED_TIME_YEARS;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (unit) {
|
||||||
|
case TimespanUnit.Seconds:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_SECONDS;
|
||||||
|
case TimespanUnit.Minutes:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_MINUTES;
|
||||||
|
case TimespanUnit.Hours:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_HOURS;
|
||||||
|
case TimespanUnit.Days:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_DAYS;
|
||||||
|
case TimespanUnit.Months:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_MONTHS;
|
||||||
|
case TimespanUnit.Years:
|
||||||
|
return i18n.TR.SCHEDULING_TIME_SPAN_YEARS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Describe the given seconds using the largest appropriate unit.
|
/// Describe the given seconds using the largest appropriate unit.
|
||||||
/// If precise is true, show to two decimal places, eg
|
/// If precise is true, show to two decimal places, eg
|
||||||
/// eg 70 seconds -> "1.17 minutes"
|
/// eg 70 seconds -> "1.17 minutes"
|
||||||
/// If false, seconds and days are shown without decimals.
|
/// If false, seconds and days are shown without decimals.
|
||||||
export function timeSpan(i18n: I18n, seconds: number, precise = true): string {
|
export function timeSpan(i18n: I18n, seconds: number, short = false): string {
|
||||||
const unit = naturalUnit(seconds);
|
const unit = naturalUnit(seconds);
|
||||||
let amount: number;
|
const amount = unitAmount(unit, seconds);
|
||||||
if (precise) {
|
const key = i18nKeyForUnit(i18n, unit, short);
|
||||||
amount = unitAmount(unit, seconds);
|
|
||||||
} else {
|
|
||||||
amount = unitAmountRounded(unit, seconds);
|
|
||||||
}
|
|
||||||
let key: number;
|
|
||||||
switch (unit) {
|
|
||||||
case TimespanUnit.Seconds:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_SECONDS;
|
|
||||||
break;
|
|
||||||
case TimespanUnit.Minutes:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_MINUTES;
|
|
||||||
break;
|
|
||||||
case TimespanUnit.Hours:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_HOURS;
|
|
||||||
break;
|
|
||||||
case TimespanUnit.Days:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_DAYS;
|
|
||||||
break;
|
|
||||||
case TimespanUnit.Months:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_MONTHS;
|
|
||||||
break;
|
|
||||||
case TimespanUnit.Years:
|
|
||||||
key = i18n.TR.SCHEDULING_TIME_SPAN_YEARS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i18n.tr(key, { amount });
|
return i18n.tr(key, { amount });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue