mirror of
https://github.com/ankitects/anki.git
synced 2026-01-09 03:53:55 -05:00
reviewed code and simplified functions in review.ts
This commit is contained in:
parent
30d3ab1b9a
commit
6ebe80775e
1 changed files with 8 additions and 8 deletions
|
|
@ -90,37 +90,37 @@ export function renderReviews(
|
||||||
): TableDatum[] {
|
): TableDatum[] {
|
||||||
const svg = select(svgElem);
|
const svg = select(svgElem);
|
||||||
const trans = svg.transition().duration(600) as any;
|
const trans = svg.transition().duration(600) as any;
|
||||||
|
|
||||||
let xMax = 1;
|
let xMax = 0;
|
||||||
let xMin = 0;
|
let xMin = 0;
|
||||||
// cap max to selected range
|
// cap max to selected range
|
||||||
switch (range) {
|
switch (range) {
|
||||||
case GraphRange.Month:
|
case GraphRange.Month:
|
||||||
xMin = -30;
|
xMin = -30;
|
||||||
xMax = 0;
|
|
||||||
break;
|
break;
|
||||||
case GraphRange.ThreeMonths:
|
case GraphRange.ThreeMonths:
|
||||||
xMin = -89;
|
xMin = -89;
|
||||||
xMax = 0;
|
|
||||||
break;
|
break;
|
||||||
case GraphRange.Year:
|
case GraphRange.Year:
|
||||||
xMin = -364;
|
xMin = -364;
|
||||||
xMax = 0;
|
|
||||||
break;
|
break;
|
||||||
case GraphRange.AllTime:
|
case GraphRange.AllTime:
|
||||||
xMin = min(sourceData.reviewCount.keys())!;
|
xMin = min(sourceData.reviewCount.keys())!;
|
||||||
|
xMax = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const desiredBars = Math.min(70, Math.abs(xMin!));
|
const desiredBars = Math.min(70, Math.abs(xMin!));
|
||||||
|
|
||||||
|
// Create initial scale to determine tick spacing
|
||||||
let x = scaleLinear().domain([xMin!, xMax]);
|
let x = scaleLinear().domain([xMin!, xMax]);
|
||||||
let thresholds = x.ticks(desiredBars);
|
let thresholds = x.ticks(desiredBars);
|
||||||
|
// Adjust xMin to align with tick spacing so the oldest bin has the same width as others
|
||||||
if (thresholds.length >= 2) {
|
if (thresholds.length >= 2) {
|
||||||
const spacing = thresholds[1] - thresholds[0];
|
const spacing = thresholds[1] - thresholds[0];
|
||||||
const partial = thresholds[0] - x.domain()[0];
|
const partial = thresholds[0] - xMin!;
|
||||||
if (spacing > 0 && partial > 0 && partial < spacing) {
|
if (spacing > 0 && partial > 0 && partial < spacing) {
|
||||||
const adjustedMin = thresholds[0] - spacing;
|
xMin = thresholds[0] - spacing;
|
||||||
x = scaleLinear().domain([adjustedMin, xMax]);
|
x = scaleLinear().domain([xMin, xMax]);
|
||||||
thresholds = x.ticks(desiredBars);
|
thresholds = x.ticks(desiredBars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue