diff --git a/ts/src/stats/GraphsPage.svelte b/ts/src/stats/GraphsPage.svelte index d8333ace0..22649d14f 100644 --- a/ts/src/stats/GraphsPage.svelte +++ b/ts/src/stats/GraphsPage.svelte @@ -7,7 +7,7 @@ @@ -37,22 +51,26 @@ Time - - - - + {#if revlogRange >= RevlogRange.Year} + + + + {/if} + {#if revlogRange === RevlogRange.All} + + {/if} @@ -65,4 +83,6 @@ +
+
diff --git a/ts/src/stats/future-due.ts b/ts/src/stats/future-due.ts index 0ea76177f..a52ed3111 100644 --- a/ts/src/stats/future-due.ts +++ b/ts/src/stats/future-due.ts @@ -26,7 +26,7 @@ export enum FutureDueRange { export function gatherData(data: pb.BackendProto.GraphsOut): GraphData { const due = (data.cards as pb.BackendProto.Card[]) - .filter((c) => c.queue == CardQueue.Review) // && c.due >= data.daysElapsed) + .filter((c) => c.queue == CardQueue.Review && c.due >= data.daysElapsed) .map((c) => c.due - data.daysElapsed); const dueCounts = rollup( due, diff --git a/ts/src/stats/graphs.css b/ts/src/stats/graphs.css index 55db1b93e..9587fcecc 100644 --- a/ts/src/stats/graphs.css +++ b/ts/src/stats/graphs.css @@ -7,7 +7,7 @@ background-color: white; padding: 15px; border-radius: 5px; - font-size: 20px; + font-size: 15px; opacity: 0; pointer-events: none; transition: opacity 0.3s; @@ -48,6 +48,7 @@ .range-box { position: fixed; + z-index: 1; top: 0; width: 100%; height: 4em; @@ -85,6 +86,11 @@ pointer-events: all; } +.hoverzone rect:hover { + fill: grey; + opacity: 0.05; +} + @keyframes spin { 0% { -webkit-transform: rotate(0deg); @@ -108,3 +114,22 @@ opacity: 0.5; transition: opacity 1s; } + +.tooltip-area { + height: 4em; +} + +.tooltip-area > * { + flex: 1 100%; + justify-content: center; + display: flex; +} + +.legend-outer { + display: flex; + justify-content: center; +} + +.legend-outer div { + padding-left: 1em; +} diff --git a/ts/src/stats/graphs.ts b/ts/src/stats/graphs.ts index eb8e59267..c5ccfd0b3 100644 --- a/ts/src/stats/graphs.ts +++ b/ts/src/stats/graphs.ts @@ -34,7 +34,7 @@ export async function getGraphData( return pb.BackendProto.GraphsOut.decode(bytes); } -export enum GraphRange { +export enum RevlogRange { Month = 1, Year = 2, All = 3, diff --git a/ts/src/stats/reviews.ts b/ts/src/stats/reviews.ts index 1c4ad1b4f..c107da39a 100644 --- a/ts/src/stats/reviews.ts +++ b/ts/src/stats/reviews.ts @@ -106,19 +106,14 @@ function cumulativeBinValue(bin: BinType, idx: number): number { return sum(totalsForBin(bin).slice(0, idx + 1)); } -function tooltipText(d: BinType, cumulative: number): string { - return `bin: ${JSON.stringify(totalsForBin(d))}
cumulative: ${cumulative}`; -} - export function renderReviews( svgElem: SVGElement, bounds: GraphBounds, sourceData: GraphData, range: ReviewRange, - showTime: boolean + showTime: boolean, + tooltipArea: HTMLDivElement ): void { - console.log(sourceData); - const xMax = 0; let xMin = 0; // cap max to selected range @@ -137,7 +132,6 @@ export function renderReviews( break; } const desiredBars = Math.min(70, Math.abs(xMin!)); - console.log(`xmin ${xMin}`); const x = scaleLinear().domain([xMin!, xMax]); const sourceMap = showTime ? sourceData.reviewTime : sourceData.reviewCount; @@ -159,7 +153,6 @@ export function renderReviews( // y scale const yMax = max(bins, (b: Bin) => cumulativeBinValue(b, 4))!; - console.log(`ymax ${yMax}`); const y = scaleLinear() .range([bounds.height - bounds.marginBottom, bounds.marginTop]) .domain([0, yMax]); @@ -196,6 +189,23 @@ export function renderReviews( x.domain() as any ); + function tooltipText(d: BinType, cumulative: number): string { + let buf = `
day ${d.x0}-${d.x1}
`; + const totals = totalsForBin(d); + const lines = [ + [darkerGreens(1), `Mature: ${totals[0]}`], + [lighterGreens(1), `Young: ${totals[1]}`], + [blues(1), `New/learn: ${totals[2]}`], + [reds(1), `Relearn: ${totals[3]}`], + [oranges(1), `Early: ${totals[4]}`], + ["grey", `Total: ${cumulative}`], + ]; + for (const [colour, text] of lines) { + buf += `
${text}
`; + } + return buf; + } + const updateBar = (sel: any, idx: number): any => { return sel .attr("width", barWidth) diff --git a/ts/src/stats/tooltip.ts b/ts/src/stats/tooltip.ts index be905e19d..afc80082d 100644 --- a/ts/src/stats/tooltip.ts +++ b/ts/src/stats/tooltip.ts @@ -12,8 +12,8 @@ function showTooltipInner(msg: string, x: number, y: number): void { document.body.appendChild(tooltipDiv); } tooltipDiv.innerHTML = msg; - tooltipDiv.style.left = `${x - 50}px`; - tooltipDiv.style.top = `${y - 50}px`; + tooltipDiv.style.right = `${document.body.clientWidth - x + 10}px`; + tooltipDiv.style.top = `${y + 20}px`; tooltipDiv.style.opacity = "1"; }