mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #906 from hgiesel/nozerointervals
Omit zero interval, and don't nice the values in Review intervals graph
This commit is contained in:
commit
c8373f1ced
3 changed files with 24 additions and 9 deletions
|
@ -197,7 +197,7 @@ export function renderCards(
|
||||||
|
|
||||||
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
||||||
|
|
||||||
const tableData = (data as any).flatMap((d: SummedDatum, idx: number) => {
|
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 d.show
|
return d.show
|
||||||
? ({
|
? ({
|
||||||
|
|
|
@ -67,33 +67,48 @@ export function prepareIntervalData(
|
||||||
return [null, []];
|
return [null, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
const [_xMinOrig, origXMax] = extent(allIntervals);
|
const xMin = 0;
|
||||||
let xMax = origXMax;
|
let [, xMax] = extent(allIntervals);
|
||||||
|
let niceNecessary = false;
|
||||||
|
|
||||||
// cap max to selected range
|
// cap max to selected range
|
||||||
switch (range) {
|
switch (range) {
|
||||||
case IntervalRange.Month:
|
case IntervalRange.Month:
|
||||||
xMax = Math.min(xMax!, 31);
|
xMax = Math.min(xMax!, 30);
|
||||||
break;
|
break;
|
||||||
case IntervalRange.Percentile50:
|
case IntervalRange.Percentile50:
|
||||||
xMax = quantile(allIntervals, 0.5);
|
xMax = quantile(allIntervals, 0.5);
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
case IntervalRange.Percentile95:
|
case IntervalRange.Percentile95:
|
||||||
xMax = quantile(allIntervals, 0.95);
|
xMax = quantile(allIntervals, 0.95);
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
case IntervalRange.All:
|
case IntervalRange.All:
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const xMin = 0;
|
|
||||||
xMax = xMax! + 1;
|
xMax = xMax! + 1;
|
||||||
|
|
||||||
|
// do not show the zero interval
|
||||||
|
const increment = (x: number): number => x + 1;
|
||||||
|
|
||||||
|
const adjustTicks = (x: number, idx: number, ticks: number[]): number[] =>
|
||||||
|
idx === ticks.length - 1 ? [x - (ticks[0] - 1), x + 1] : [x - (ticks[0] - 1)];
|
||||||
|
|
||||||
// cap bars to available range
|
// cap bars to available range
|
||||||
const desiredBars = Math.min(70, xMax! - xMin!);
|
const desiredBars = Math.min(70, xMax! - xMin!);
|
||||||
|
|
||||||
const scale = scaleLinear().domain([xMin!, xMax!]).nice();
|
const prescale = scaleLinear().domain([xMin!, xMax!]);
|
||||||
|
|
||||||
|
const scale = scaleLinear().domain(
|
||||||
|
(niceNecessary ? prescale.nice() : prescale).domain().map(increment)
|
||||||
|
);
|
||||||
|
|
||||||
const bins = histogram()
|
const bins = histogram()
|
||||||
.domain(scale.domain() as any)
|
.domain(scale.domain() as [number, number])
|
||||||
.thresholds(scale.ticks(desiredBars))(allIntervals);
|
.thresholds(scale.ticks(desiredBars).flatMap(adjustTicks))(allIntervals);
|
||||||
|
|
||||||
// empty graph?
|
// empty graph?
|
||||||
const totalInPeriod = sum(bins, (bin) => bin.length);
|
const totalInPeriod = sum(bins, (bin) => bin.length);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "es6",
|
"module": "es6",
|
||||||
"lib": ["es2016", "dom"],
|
"lib": ["es2016", "es2019.array", "dom"],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"anki/*": ["../bazel-bin/ts/lib/*"]
|
"anki/*": ["../bazel-bin/ts/lib/*"]
|
||||||
|
|
Loading…
Reference in a new issue