mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
add separate histogram graph component
This commit is contained in:
parent
d0d675609d
commit
e213ffc82a
3 changed files with 42 additions and 29 deletions
25
ts/src/stats/HistogramGraph.svelte
Normal file
25
ts/src/stats/HistogramGraph.svelte
Normal file
|
@ -0,0 +1,25 @@
|
|||
<script lang="typescript">
|
||||
import { HistogramData, histogramGraph } from "./histogram-graph";
|
||||
import AxisLabels from "./AxisLabels.svelte";
|
||||
import AxisTicks from "./AxisTicks.svelte";
|
||||
import { defaultGraphBounds } from "./graphs";
|
||||
|
||||
export let data: HistogramData | null = null;
|
||||
export let xText: string;
|
||||
export let yText: string;
|
||||
|
||||
let bounds = defaultGraphBounds();
|
||||
let svg = null as HTMLElement | SVGElement | null;
|
||||
|
||||
$: if (data) {
|
||||
histogramGraph(svg as SVGElement, bounds, data);
|
||||
}
|
||||
</script>
|
||||
|
||||
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
|
||||
<g class="bars" />
|
||||
<g class="hoverzone" />
|
||||
<path class="area" />
|
||||
<AxisTicks {bounds} />
|
||||
<AxisLabels {bounds} {xText} {yText} />
|
||||
</svg>
|
|
@ -1,18 +1,19 @@
|
|||
<script lang="typescript">
|
||||
import AxisLabels from "./AxisLabels.svelte";
|
||||
import AxisTicks from "./AxisTicks.svelte";
|
||||
|
||||
import { defaultGraphBounds } from "./graphs";
|
||||
import { gatherIntervalData, intervalGraph, IntervalRange } from "./intervals";
|
||||
import type { IntervalGraphData } from "./intervals";
|
||||
import { HistogramData } from "./histogram-graph";
|
||||
import {
|
||||
gatherIntervalData,
|
||||
IntervalRange,
|
||||
prepareIntervalData,
|
||||
IntervalGraphData,
|
||||
} from "./intervals";
|
||||
import pb from "../backend/proto";
|
||||
import HistogramGraph from "./HistogramGraph.svelte";
|
||||
|
||||
export let data: pb.BackendProto.GraphsOut | null = null;
|
||||
|
||||
const bounds = defaultGraphBounds();
|
||||
|
||||
let svg = null as HTMLElement | SVGElement | null;
|
||||
let range = IntervalRange.Percentile95;
|
||||
let histogramData = null as HistogramData | null;
|
||||
|
||||
let intervalData: IntervalGraphData | null = null;
|
||||
$: if (data) {
|
||||
|
@ -21,7 +22,8 @@
|
|||
}
|
||||
|
||||
$: if (intervalData) {
|
||||
intervalGraph(svg as SVGElement, bounds, intervalData, range);
|
||||
console.log("preparing data");
|
||||
histogramData = prepareIntervalData(intervalData, range);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -54,11 +56,8 @@
|
|||
</label>
|
||||
</div>
|
||||
|
||||
<svg bind:this={svg} viewBox={`0 0 ${bounds.width} ${bounds.height}`}>
|
||||
<g class="bars" />
|
||||
<g class="hoverzone" />
|
||||
<path class="area" />
|
||||
<AxisTicks {bounds} />
|
||||
<AxisLabels {bounds} xText="Interval (days)" yText="Number of cards" />
|
||||
</svg>
|
||||
<HistogramGraph
|
||||
data={histogramData}
|
||||
xText="Interval (days)"
|
||||
yText="Number of cards" />
|
||||
</div>
|
||||
|
|
|
@ -10,8 +10,7 @@ import pb from "../backend/proto";
|
|||
import { extent, histogram, quantile } from "d3-array";
|
||||
import { scaleLinear } from "d3-scale";
|
||||
import { CardQueue } from "../cards";
|
||||
import { HistogramData, histogramGraph } from "./histogram-graph";
|
||||
import { GraphBounds } from "./graphs";
|
||||
import { HistogramData } from "./histogram-graph";
|
||||
|
||||
export interface IntervalGraphData {
|
||||
intervals: number[];
|
||||
|
@ -44,7 +43,7 @@ function hoverText(data: HistogramData, binIdx: number, percent: number): string
|
|||
);
|
||||
}
|
||||
|
||||
function prepareIntervalData(
|
||||
export function prepareIntervalData(
|
||||
data: IntervalGraphData,
|
||||
range: IntervalRange
|
||||
): HistogramData {
|
||||
|
@ -83,13 +82,3 @@ function prepareIntervalData(
|
|||
|
||||
return { scale, bins, total, hoverText };
|
||||
}
|
||||
|
||||
export function intervalGraph(
|
||||
svgElem: SVGElement,
|
||||
bounds: GraphBounds,
|
||||
data: IntervalGraphData,
|
||||
range: IntervalRange
|
||||
): void {
|
||||
const histogram = prepareIntervalData(data, range);
|
||||
histogramGraph(svgElem, bounds, histogram);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue