mirror of
https://github.com/ankitects/anki.git
synced 2025-12-12 22:36:55 -05:00
Remove modular d3 imports for imports from d3 bundle
This commit is contained in:
parent
ecbfd898d3
commit
3290e5373b
13 changed files with 132 additions and 81 deletions
|
|
@ -35,11 +35,6 @@ ts_library(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
ts_library(
|
|
||||||
name = "types",
|
|
||||||
srcs = ["d3_missing.d.ts"],
|
|
||||||
)
|
|
||||||
|
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "lib",
|
name = "lib",
|
||||||
srcs = glob(
|
srcs = glob(
|
||||||
|
|
@ -47,7 +42,6 @@ ts_library(
|
||||||
exclude = ["bootstrap.ts"],
|
exclude = ["bootstrap.ts"],
|
||||||
),
|
),
|
||||||
deps = [
|
deps = [
|
||||||
"types",
|
|
||||||
"//ts/lib",
|
"//ts/lib",
|
||||||
"//ts/lib:backend_proto",
|
"//ts/lib:backend_proto",
|
||||||
"@npm//@types/d3",
|
"@npm//@types/d3",
|
||||||
|
|
@ -96,7 +90,6 @@ eslint_test(
|
||||||
[
|
[
|
||||||
"*.ts",
|
"*.ts",
|
||||||
],
|
],
|
||||||
exclude = ["d3_missing.d.ts"],
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import { extent, histogram, sum, Bin } from "d3-array";
|
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
import {
|
||||||
|
extent,
|
||||||
|
histogram,
|
||||||
|
sum,
|
||||||
|
scaleLinear,
|
||||||
|
scaleSequential,
|
||||||
|
interpolateBlues,
|
||||||
|
} from "d3";
|
||||||
|
import type { Bin } from "d3";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import { dayLabel } from "anki/time";
|
import { dayLabel } from "anki/time";
|
||||||
import { GraphRange } from "./graph-helpers";
|
import { GraphRange } from "./graph-helpers";
|
||||||
|
|
@ -52,7 +59,7 @@ export function buildHistogram(
|
||||||
return [null, []];
|
return [null, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
const [xMinOrig, _xMax] = extent(data.daysAdded);
|
const [xMinOrig] = extent(data.daysAdded);
|
||||||
let xMin = xMinOrig;
|
let xMin = xMinOrig;
|
||||||
|
|
||||||
// cap max to selected range
|
// cap max to selected range
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
import {
|
||||||
import "d3-transition";
|
interpolateRdYlGn,
|
||||||
import { select, mouse } from "d3-selection";
|
select,
|
||||||
import { scaleLinear, scaleBand, scaleSequential } from "d3-scale";
|
pointer,
|
||||||
import { axisBottom, axisLeft } from "d3-axis";
|
scaleLinear,
|
||||||
|
scaleBand,
|
||||||
|
scaleSequential,
|
||||||
|
axisBottom,
|
||||||
|
axisLeft,
|
||||||
|
sum,
|
||||||
|
} from "d3";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import {
|
import {
|
||||||
GraphBounds,
|
GraphBounds,
|
||||||
|
|
@ -20,7 +26,6 @@ import {
|
||||||
millisecondCutoffForRange,
|
millisecondCutoffForRange,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import { sum } from "d3-array";
|
|
||||||
|
|
||||||
type ButtonCounts = [number, number, number, number];
|
type ButtonCounts = [number, number, number, number];
|
||||||
|
|
||||||
|
|
@ -251,8 +256,8 @@ export function renderButtons(
|
||||||
.attr("y", () => y(yMax!)!)
|
.attr("y", () => y(yMax!)!)
|
||||||
.attr("width", xButton.bandwidth())
|
.attr("width", xButton.bandwidth())
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", function (this: any, d: Datum) {
|
.on("mousemove", (event: MouseEvent, d: Datum) => {
|
||||||
const [x, y] = mouse(document.body);
|
const [x, y] = pointer(event);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
import {
|
||||||
import "d3-transition";
|
interpolateBlues,
|
||||||
import { select, mouse } from "d3-selection";
|
select,
|
||||||
import { scaleLinear, scaleSequentialSqrt } from "d3-scale";
|
pointer,
|
||||||
|
scaleLinear,
|
||||||
|
scaleSequentialSqrt,
|
||||||
|
timeDay,
|
||||||
|
timeYear,
|
||||||
|
timeSunday,
|
||||||
|
timeMonday,
|
||||||
|
timeFriday,
|
||||||
|
timeSaturday,
|
||||||
|
} from "d3";
|
||||||
|
import type { CountableTimeInterval } from "d3";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import {
|
import {
|
||||||
GraphBounds,
|
GraphBounds,
|
||||||
|
|
@ -18,15 +28,6 @@ import {
|
||||||
RevlogRange,
|
RevlogRange,
|
||||||
SearchDispatch,
|
SearchDispatch,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import {
|
|
||||||
timeDay,
|
|
||||||
timeYear,
|
|
||||||
timeSunday,
|
|
||||||
timeMonday,
|
|
||||||
timeFriday,
|
|
||||||
timeSaturday,
|
|
||||||
} from "d3-time";
|
|
||||||
import type { CountableTimeInterval } from "d3-time";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
|
|
@ -206,8 +207,8 @@ export function renderCalendar(
|
||||||
.attr("height", height - 2)
|
.attr("height", height - 2)
|
||||||
.attr("x", (d) => x(d.weekNumber + 1)!)
|
.attr("x", (d) => x(d.weekNumber + 1)!)
|
||||||
.attr("y", (d) => bounds.marginTop + d.weekDay * height)
|
.attr("y", (d) => bounds.marginTop + d.weekDay * height)
|
||||||
.on("mousemove", function (this: any, d: any) {
|
.on("mousemove", (event: MouseEvent, d: DayDatum) => {
|
||||||
const [x, y] = mouse(document.body);
|
const [x, y] = pointer(event);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip)
|
.on("mouseout", hideTooltip)
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ import {
|
||||||
schemeBlues,
|
schemeBlues,
|
||||||
schemeOranges,
|
schemeOranges,
|
||||||
schemeReds,
|
schemeReds,
|
||||||
} from "d3-scale-chromatic";
|
select,
|
||||||
import "d3-transition";
|
scaleLinear,
|
||||||
import { select } from "d3-selection";
|
pie,
|
||||||
import { scaleLinear } from "d3-scale";
|
arc,
|
||||||
import { pie, arc } from "d3-shape";
|
interpolate,
|
||||||
import { interpolate } from "d3-interpolate";
|
cumsum,
|
||||||
|
} from "d3";
|
||||||
import type { GraphBounds } from "./graph-helpers";
|
import type { GraphBounds } from "./graph-helpers";
|
||||||
import { cumsum } from "d3-array";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
type Count = [string, number, boolean, string];
|
type Count = [string, number, boolean, string];
|
||||||
|
|
|
||||||
4
ts/graphs/d3_missing.d.ts
vendored
4
ts/graphs/d3_missing.d.ts
vendored
|
|
@ -1,4 +0,0 @@
|
||||||
import "d3-array";
|
|
||||||
declare module "d3-array" {
|
|
||||||
export function cumsum(arg0: any[], arg1?: (any) => number): Float64Array;
|
|
||||||
}
|
|
||||||
|
|
@ -7,11 +7,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import { extent, histogram, sum, Bin } from "d3-array";
|
import {
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
extent,
|
||||||
|
histogram,
|
||||||
|
sum,
|
||||||
|
scaleLinear,
|
||||||
|
scaleSequential,
|
||||||
|
interpolateRdYlGn,
|
||||||
|
} from "d3";
|
||||||
|
import type { Bin } from "d3";
|
||||||
import { CardType } from "anki/cards";
|
import { CardType } from "anki/cards";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import { extent, histogram, rollup, sum, Bin } from "d3-array";
|
import {
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
extent,
|
||||||
|
histogram,
|
||||||
|
rollup,
|
||||||
|
sum,
|
||||||
|
scaleLinear,
|
||||||
|
scaleSequential,
|
||||||
|
interpolateGreens,
|
||||||
|
} from "d3";
|
||||||
|
import type { Bin } from "d3";
|
||||||
import { CardQueue } from "anki/cards";
|
import { CardQueue } from "anki/cards";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateGreens } from "d3-scale-chromatic";
|
|
||||||
import { dayLabel } from "anki/time";
|
import { dayLabel } from "anki/time";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import { GraphRange } from "./graph-helpers";
|
import { GraphRange } from "./graph-helpers";
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
@typescript-eslint/ban-ts-ignore: "off" */
|
@typescript-eslint/ban-ts-ignore: "off" */
|
||||||
|
|
||||||
import pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
import type { Selection } from "d3-selection";
|
import type { Selection } from "d3";
|
||||||
import type { PreferencePayload } from "./preferences";
|
import type { PreferencePayload } from "./preferences";
|
||||||
import { postRequest } from "anki/postrequest";
|
import { postRequest } from "anki/postrequest";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,20 @@
|
||||||
@typescript-eslint/no-explicit-any: "off",
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "d3-transition";
|
import {
|
||||||
import { select, mouse } from "d3-selection";
|
select,
|
||||||
import { cumsum, max, Bin } from "d3-array";
|
pointer,
|
||||||
import { scaleLinear, ScaleLinear, ScaleSequential } from "d3-scale";
|
cumsum,
|
||||||
import { axisBottom, axisLeft, axisRight } from "d3-axis";
|
max,
|
||||||
import { area, curveBasis } from "d3-shape";
|
scaleLinear,
|
||||||
|
axisBottom,
|
||||||
|
axisLeft,
|
||||||
|
axisRight,
|
||||||
|
area,
|
||||||
|
curveBasis,
|
||||||
|
} from "d3";
|
||||||
|
|
||||||
|
import type { ScaleLinear, ScaleSequential, Bin } from "d3";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import { GraphBounds, setDataAvailable } from "./graph-helpers";
|
import { GraphBounds, setDataAvailable } from "./graph-helpers";
|
||||||
|
|
||||||
|
|
@ -154,8 +162,10 @@ export function histogramGraph(
|
||||||
.attr("y", () => y(yMax!)!)
|
.attr("y", () => y(yMax!)!)
|
||||||
.attr("width", barWidth)
|
.attr("width", barWidth)
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", function (this: any, _d: any, idx: number) {
|
.on("mousemove", (event: MouseEvent, _d: Bin<number, number>) => {
|
||||||
const [x, y] = mouse(document.body);
|
const [x, y] = pointer(event);
|
||||||
|
// TODO
|
||||||
|
const idx = 0;
|
||||||
const pct = data.showArea ? (areaData[idx + 1] / data.total) * 100 : 0;
|
const pct = data.showArea ? (areaData[idx + 1] / data.total) * 100 : 0;
|
||||||
showTooltip(data.hoverText(data, idx, areaData[idx + 1], pct), x, y);
|
showTooltip(data.hoverText(data, idx, areaData[idx + 1], pct), x, y);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import pb from "anki/backend_proto";
|
import pb from "anki/backend_proto";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
import {
|
||||||
import "d3-transition";
|
interpolateBlues,
|
||||||
import { select, mouse } from "d3-selection";
|
select,
|
||||||
import { scaleLinear, scaleBand, scaleSequential } from "d3-scale";
|
pointer,
|
||||||
import { axisBottom, axisLeft, axisRight } from "d3-axis";
|
scaleLinear,
|
||||||
|
scaleBand,
|
||||||
|
scaleSequential,
|
||||||
|
axisBottom,
|
||||||
|
axisLeft,
|
||||||
|
axisRight,
|
||||||
|
area,
|
||||||
|
curveBasis,
|
||||||
|
} from "d3";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import {
|
import {
|
||||||
GraphBounds,
|
GraphBounds,
|
||||||
|
|
@ -19,7 +27,6 @@ import {
|
||||||
GraphRange,
|
GraphRange,
|
||||||
millisecondCutoffForRange,
|
millisecondCutoffForRange,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import { area, curveBasis } from "d3-shape";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
type ButtonCounts = [number, number, number, number];
|
type ButtonCounts = [number, number, number, number];
|
||||||
|
|
@ -197,8 +204,8 @@ export function renderHours(
|
||||||
.attr("y", () => y(yMax)!)
|
.attr("y", () => y(yMax)!)
|
||||||
.attr("width", x.bandwidth())
|
.attr("width", x.bandwidth())
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", function (this: any, d: Hour) {
|
.on("mousemove", (event: MouseEvent, d: Hour) => {
|
||||||
const [x, y] = mouse(document.body);
|
const [x, y] = pointer(event);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import { extent, histogram, quantile, sum, mean, Bin } from "d3-array";
|
import {
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
extent,
|
||||||
|
histogram,
|
||||||
|
quantile,
|
||||||
|
sum,
|
||||||
|
mean,
|
||||||
|
scaleLinear,
|
||||||
|
scaleSequential,
|
||||||
|
interpolateBlues,
|
||||||
|
} from "d3";
|
||||||
|
import type { Bin } from "d3";
|
||||||
import { CardType } from "anki/cards";
|
import { CardType } from "anki/cards";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateBlues } from "d3-scale-chromatic";
|
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
import { timeSpan } from "anki/time";
|
import { timeSpan } from "anki/time";
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,26 @@ import {
|
||||||
interpolateReds,
|
interpolateReds,
|
||||||
interpolateOranges,
|
interpolateOranges,
|
||||||
interpolatePurples,
|
interpolatePurples,
|
||||||
} from "d3-scale-chromatic";
|
select,
|
||||||
import "d3-transition";
|
pointer,
|
||||||
import { select, mouse } from "d3-selection";
|
scaleLinear,
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
scaleSequential,
|
||||||
import { axisBottom, axisLeft, axisRight } from "d3-axis";
|
axisBottom,
|
||||||
|
axisLeft,
|
||||||
|
axisRight,
|
||||||
|
area,
|
||||||
|
curveBasis,
|
||||||
|
min,
|
||||||
|
histogram,
|
||||||
|
sum,
|
||||||
|
max,
|
||||||
|
cumsum,
|
||||||
|
} from "d3";
|
||||||
|
import type { Bin } from "d3";
|
||||||
|
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers";
|
import { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers";
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum } from "./graph-helpers";
|
||||||
import { area, curveBasis } from "d3-shape";
|
|
||||||
import { min, histogram, sum, max, Bin, cumsum } from "d3-array";
|
|
||||||
import { timeSpan, dayLabel } from "anki/time";
|
import { timeSpan, dayLabel } from "anki/time";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
|
||||||
|
|
@ -357,9 +367,10 @@ export function renderReviews(
|
||||||
.attr("y", () => y(yMax!)!)
|
.attr("y", () => y(yMax!)!)
|
||||||
.attr("width", barWidth)
|
.attr("width", barWidth)
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", function (this: any, d: any, idx) {
|
.on("mousemove", (event: MouseEvent, d) => {
|
||||||
const [x, y] = mouse(document.body);
|
const idx = 0; // TODO
|
||||||
showTooltip(tooltipText(d, areaData[idx + 1]), x, y);
|
const [x, y] = pointer(event);
|
||||||
|
showTooltip(tooltipText(d as any /* TODO */, areaData[idx + 1]), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue