2020-06-22 07:00:45 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
/* eslint
|
|
|
|
@typescript-eslint/no-explicit-any: "off",
|
2021-04-22 19:19:39 +02:00
|
|
|
@typescript-eslint/ban-ts-comment: "off" */
|
2020-06-22 07:00:45 +02:00
|
|
|
|
2021-01-30 01:13:47 +01:00
|
|
|
import type { Selection } from "d3";
|
2021-01-21 16:16:58 +01:00
|
|
|
|
2022-02-04 09:36:34 +01:00
|
|
|
import type { Cards, Stats } from "../lib/proto";
|
|
|
|
|
2020-07-17 05:46:06 +02:00
|
|
|
// amount of data to fetch from backend
|
2020-06-27 07:35:34 +02:00
|
|
|
export enum RevlogRange {
|
2020-07-06 10:29:35 +02:00
|
|
|
Year = 1,
|
|
|
|
All = 2,
|
2020-06-22 07:00:45 +02:00
|
|
|
}
|
2020-06-23 05:43:23 +02:00
|
|
|
|
2021-01-23 13:54:21 +01:00
|
|
|
export function daysToRevlogRange(days: number): RevlogRange {
|
|
|
|
return days > 365 || days === 0 ? RevlogRange.All : RevlogRange.Year;
|
|
|
|
}
|
|
|
|
|
2020-07-17 05:46:06 +02:00
|
|
|
// period a graph should cover
|
|
|
|
export enum GraphRange {
|
|
|
|
Month = 0,
|
|
|
|
ThreeMonths = 1,
|
|
|
|
Year = 2,
|
|
|
|
AllTime = 3,
|
|
|
|
}
|
|
|
|
|
2020-06-30 08:23:46 +02:00
|
|
|
export interface GraphsContext {
|
2021-07-10 11:52:31 +02:00
|
|
|
cards: Cards.Card[];
|
2021-07-10 13:58:34 +02:00
|
|
|
revlog: Stats.RevlogEntry[];
|
2020-06-30 08:23:46 +02:00
|
|
|
revlogRange: RevlogRange;
|
|
|
|
nightMode: boolean;
|
|
|
|
}
|
|
|
|
|
2020-06-23 05:43:23 +02:00
|
|
|
export interface GraphBounds {
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
marginLeft: number;
|
|
|
|
marginRight: number;
|
|
|
|
marginTop: number;
|
|
|
|
marginBottom: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function defaultGraphBounds(): GraphBounds {
|
|
|
|
return {
|
|
|
|
width: 600,
|
|
|
|
height: 250,
|
2020-06-28 09:44:51 +02:00
|
|
|
marginLeft: 70,
|
2020-08-05 06:49:57 +02:00
|
|
|
marginRight: 70,
|
2020-06-23 05:43:23 +02:00
|
|
|
marginTop: 20,
|
2020-08-10 07:33:19 +02:00
|
|
|
marginBottom: 25,
|
2020-06-23 05:43:23 +02:00
|
|
|
};
|
|
|
|
}
|
2020-07-06 06:01:49 +02:00
|
|
|
|
|
|
|
export function setDataAvailable(
|
|
|
|
svg: Selection<SVGElement, any, any, any>,
|
2021-10-19 01:06:00 +02:00
|
|
|
available: boolean,
|
2020-07-06 06:01:49 +02:00
|
|
|
): void {
|
|
|
|
svg.select(".no-data")
|
|
|
|
.attr("pointer-events", available ? "none" : "all")
|
|
|
|
.transition()
|
|
|
|
.duration(600)
|
|
|
|
.attr("opacity", available ? 0 : 1);
|
|
|
|
}
|
2020-07-17 05:46:06 +02:00
|
|
|
|
|
|
|
export function millisecondCutoffForRange(
|
|
|
|
range: GraphRange,
|
2021-10-19 01:06:00 +02:00
|
|
|
nextDayAtSecs: number,
|
2020-07-17 05:46:06 +02:00
|
|
|
): number {
|
|
|
|
let days;
|
|
|
|
switch (range) {
|
|
|
|
case GraphRange.Month:
|
|
|
|
days = 31;
|
|
|
|
break;
|
|
|
|
case GraphRange.ThreeMonths:
|
|
|
|
days = 90;
|
|
|
|
break;
|
|
|
|
case GraphRange.Year:
|
|
|
|
days = 365;
|
|
|
|
break;
|
|
|
|
case GraphRange.AllTime:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (nextDayAtSecs - 86400 * days) * 1000;
|
|
|
|
}
|
2020-08-04 06:37:21 +02:00
|
|
|
|
|
|
|
export interface TableDatum {
|
|
|
|
label: string;
|
|
|
|
value: string;
|
|
|
|
}
|
2021-01-26 12:41:22 +01:00
|
|
|
|
|
|
|
export type SearchEventMap = { search: { query: string } };
|
|
|
|
export type SearchDispatch = <EventKey extends Extract<keyof SearchEventMap, string>>(
|
|
|
|
type: EventKey,
|
2021-10-19 01:06:00 +02:00
|
|
|
detail: SearchEventMap[EventKey],
|
2021-01-26 12:41:22 +01:00
|
|
|
) => void;
|