mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-30 06:48:12 +08:00
chore: type general utils (#2381)
* type camera
* type reducer store
* type actionhelpers
* type catchErrorsWrap callsite
* missed camera member var
* type nameCreators
* type makeContinousDimensionName callsite
* type promise limit
* type quantile
* type range
* introduce TypedArray + NumericArray
* type range
* cleanup test
* fix call sites
* type plimit call site
* finish typing camera
* use our TypedArray
* type scientific and sigFig utils and callsites
* simple typings
* type catLabelSort
* type callsite
* type
* callsites
* type camera methods
* swap back to strings, set defaults accordingly
* partially type centroid
* explicit tuple and undefined check
* fix references to this
* call constructor with new and casting
* Revert "introduce TypedArray + NumericArray"
This reverts commit cf21538717.
* explicit tuple
* generics and import fixes
* add unsigned 8 clamped arrray
* back to literals
* use arraytypes
* fix return state
* type more actions
* Update client/src/util/actionHelpers.ts
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
* properly type dispatch
* properly type thunk
* use new dispatch
* remove nullish coallescer
* use AppDispatch
* generic jsonrequest
* use dispatch again
* lint
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
This commit is contained in:
co-authored by
Timmy Huang
parent
45cecad76a
commit
08b03ace60
@@ -1,15 +1,14 @@
|
||||
import sortBy from "lodash.sortby";
|
||||
/* XXX: cough, cough, ... */
|
||||
import { postNetworkErrorToast } from "../components/framework/toasters";
|
||||
import type { AppDispatch, RootState } from "../reducers";
|
||||
|
||||
/*
|
||||
dispatch an action error to the user. Currently we use
|
||||
async toasts.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
let networkErrorToastKey: any = null;
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const dispatchNetworkErrorMessageToUser = (message: any) => {
|
||||
let networkErrorToastKey: string | null = null;
|
||||
export const dispatchNetworkErrorMessageToUser = (message: string): void => {
|
||||
if (!networkErrorToastKey) {
|
||||
networkErrorToastKey = postNetworkErrorToast(message);
|
||||
} else {
|
||||
@@ -20,12 +19,12 @@ export const dispatchNetworkErrorMessageToUser = (message: any) => {
|
||||
/*
|
||||
Catch unexpected errors and make sure we don't lose them!
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export function catchErrorsWrap(fn: any, dispatchToUser = false) {
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
return (dispatch: any, getState: any) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
fn(dispatch, getState).catch((error: any) => {
|
||||
export function catchErrorsWrap(
|
||||
fn: (dispatch: AppDispatch, getState: () => RootState) => Promise<void>,
|
||||
dispatchToUser = false
|
||||
) {
|
||||
return (dispatch: AppDispatch, getState: () => RootState): void => {
|
||||
fn(dispatch, getState).catch((error: Error) => {
|
||||
console.error(error);
|
||||
if (dispatchToUser) {
|
||||
dispatchNetworkErrorMessageToUser(error.message);
|
||||
@@ -39,8 +38,10 @@ export function catchErrorsWrap(fn: any, dispatchToUser = false) {
|
||||
* Wrapper to perform async fetch with some modest error handling
|
||||
* and decoding. Arguments are identical to standard fetch.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const doFetch = async (url: any, init = {}) => {
|
||||
export const doFetch = async (
|
||||
url: string,
|
||||
init?: RequestInit
|
||||
): Promise<Response> => {
|
||||
try {
|
||||
// add defaults to the fetch init param.
|
||||
init = {
|
||||
@@ -48,13 +49,11 @@ export const doFetch = async (url: any, init = {}) => {
|
||||
credentials: "include",
|
||||
...init,
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const acceptType = (init as any).headers?.get("Accept");
|
||||
const acceptType = (init.headers as Headers)?.get("Accept");
|
||||
const res = await fetch(url, init);
|
||||
if (
|
||||
res.ok &&
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
(!acceptType || res.headers.get("Content-Type").includes(acceptType))
|
||||
(!acceptType || res.headers?.get("Content-Type")?.includes(acceptType))
|
||||
) {
|
||||
return res;
|
||||
}
|
||||
@@ -74,8 +73,10 @@ export const doFetch = async (url: any, init = {}) => {
|
||||
/*
|
||||
Wrapper to perform an async fetch and JSON decode response.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const doJsonRequest = async (url: any, init = {}) => {
|
||||
export const doJsonRequest = async <T = unknown>(
|
||||
url: string,
|
||||
init?: RequestInit
|
||||
): Promise<T> => {
|
||||
const res = await doFetch(url, {
|
||||
...init,
|
||||
headers: new Headers({ Accept: "application/json" }),
|
||||
@@ -86,8 +87,10 @@ export const doJsonRequest = async (url: any, init = {}) => {
|
||||
/*
|
||||
Wrapper to perform an async fetch for binary data.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const doBinaryRequest = async (url: any, init = {}) => {
|
||||
export const doBinaryRequest = async (
|
||||
url: string,
|
||||
init?: RequestInit
|
||||
): Promise<ArrayBuffer> => {
|
||||
const res = await doFetch(url, {
|
||||
...init,
|
||||
headers: new Headers({ Accept: "application/octet-stream" }),
|
||||
@@ -110,13 +113,11 @@ Parameters:
|
||||
|
||||
So [1, 2, 3, 4, 10, 11, 14] -> [ [1, 4], [10, 11], 14]
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export const rangeEncodeIndices = (
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
indices: any,
|
||||
indices: Array<number>,
|
||||
minRangeLength = 3,
|
||||
sorted = false
|
||||
) => {
|
||||
): Array<number | [number, number]> => {
|
||||
if (indices.length === 0) {
|
||||
return indices;
|
||||
}
|
||||
|
||||
+31
-39
@@ -1,4 +1,5 @@
|
||||
import { vec2, mat3 } from "gl-matrix";
|
||||
import clamp from "./clamp";
|
||||
|
||||
const EPSILON = 0.000001;
|
||||
|
||||
@@ -11,56 +12,49 @@ const panBound = 0.8;
|
||||
const scratch0 = new Float32Array(16);
|
||||
const scratch1 = new Float32Array(16);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
function clamp(val: any, rng: any) {
|
||||
return Math.max(Math.min(val, rng[1]), rng[0]);
|
||||
}
|
||||
|
||||
class Camera {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
canvas: any;
|
||||
canvas: HTMLCanvasElement;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
prevEvent: any;
|
||||
prevEvent: {
|
||||
clientX: number;
|
||||
clientY: number;
|
||||
type: string;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
viewMatrix: any;
|
||||
viewMatrix: mat3;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
viewMatrixInv: any;
|
||||
viewMatrixInv: mat3;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
constructor(canvas: any) {
|
||||
constructor(canvas: HTMLCanvasElement) {
|
||||
this.prevEvent = {
|
||||
clientX: 0,
|
||||
clientY: 0,
|
||||
type: 0,
|
||||
type: "",
|
||||
};
|
||||
this.canvas = canvas;
|
||||
this.viewMatrix = mat3.create();
|
||||
this.viewMatrixInv = mat3.create();
|
||||
}
|
||||
|
||||
view() {
|
||||
view(): mat3 {
|
||||
return this.viewMatrix;
|
||||
}
|
||||
|
||||
invView() {
|
||||
invView(): mat3 {
|
||||
return this.viewMatrixInv;
|
||||
}
|
||||
|
||||
distance() {
|
||||
distance(): number {
|
||||
return this.viewMatrix[0];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
pan(dx: any, dy: any) {
|
||||
pan(dx: number, dy: number): void {
|
||||
const m = this.viewMatrix;
|
||||
const dyRange = [
|
||||
const dyRange: [number, number] = [
|
||||
-panBound - (m[7] + 1) / m[4],
|
||||
panBound - (m[7] - 1) / m[4],
|
||||
];
|
||||
const dxRange = [
|
||||
const dxRange: [number, number] = [
|
||||
-panBound - (m[6] + 1) / m[0],
|
||||
panBound - (m[6] - 1) / m[0],
|
||||
];
|
||||
@@ -74,13 +68,12 @@ class Camera {
|
||||
mat3.invert(this.viewMatrixInv, m);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
zoomAt(d: any, x = 0, y = 0) {
|
||||
zoomAt(d: number, x = 0, y = 0): void {
|
||||
/*
|
||||
Camera zoom at [x,y]
|
||||
*/
|
||||
const m = this.viewMatrix;
|
||||
const bounds = [-panBound, panBound];
|
||||
const bounds: [number, number] = [-panBound, panBound];
|
||||
x = clamp(x, bounds);
|
||||
y = clamp(y, bounds);
|
||||
|
||||
@@ -98,15 +91,18 @@ class Camera {
|
||||
Event handling
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
flush(e: any) {
|
||||
flush(e: MouseEvent) {
|
||||
this.prevEvent.type = e.type;
|
||||
this.prevEvent.clientX = e.clientX;
|
||||
this.prevEvent.clientY = e.clientY;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
localPosition(target: any, canvasX: any, canvasY: any, projectionInvTF: any) {
|
||||
localPosition(
|
||||
target: HTMLCanvasElement,
|
||||
canvasX: number,
|
||||
canvasY: number,
|
||||
projectionInvTF: mat3
|
||||
): vec2 {
|
||||
/*
|
||||
Convert mouse position to local
|
||||
*/
|
||||
@@ -126,8 +122,7 @@ class Camera {
|
||||
return pos;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
mousePan(e: any, projectionTF: any) {
|
||||
mousePan(e: MouseEvent, projectionTF: mat3): true {
|
||||
const projectionInvTF = mat3.invert(scratch0, projectionTF);
|
||||
const pos = this.localPosition(
|
||||
this.canvas,
|
||||
@@ -147,8 +142,7 @@ class Camera {
|
||||
return true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
wheelZoom(e: any, projectionTF: any) {
|
||||
wheelZoom(e: WheelEvent, projectionTF: mat3): true {
|
||||
const { height } = this.canvas;
|
||||
const { deltaY, deltaMode, clientX, clientY } = e;
|
||||
const scale = scaleSpeed * (deltaMode === 1 ? 12 : 1) * (deltaY || 0);
|
||||
@@ -164,8 +158,7 @@ class Camera {
|
||||
return true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
handleEvent(e: any, projectionTF: any) {
|
||||
handleEvent(e: MouseEvent, projectionTF: mat3): boolean {
|
||||
/*
|
||||
process the event, and return true if camera view changed
|
||||
*/
|
||||
@@ -181,7 +174,7 @@ class Camera {
|
||||
}
|
||||
|
||||
case "wheel": {
|
||||
viewChanged = this.wheelZoom(e, projectionTF);
|
||||
viewChanged = this.wheelZoom(e as WheelEvent, projectionTF);
|
||||
this.flush(e);
|
||||
break;
|
||||
}
|
||||
@@ -194,8 +187,7 @@ class Camera {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
function attachCamera(canvas: any) {
|
||||
function attachCamera(canvas: HTMLCanvasElement): Camera {
|
||||
return new Camera(canvas);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,24 +11,23 @@ TL;DR: sort order is:
|
||||
import isNumber from "is-number";
|
||||
import * as globals from "../globals";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
function caseInsensitiveCompare(a: any, b: any) {
|
||||
function caseInsensitiveCompare(a: string, b: string): number {
|
||||
const textA = String(a).toUpperCase();
|
||||
const textB = String(b).toUpperCase();
|
||||
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const catLabelSort = (isUserAnno: boolean, values: any[]): any[] => {
|
||||
const catLabelSort = (
|
||||
isUserAnno: boolean,
|
||||
values: Array<string>
|
||||
): Array<string> => {
|
||||
/* this sort could be memoized for perf */
|
||||
|
||||
const strings: string[] = [];
|
||||
const ints: number[] = [];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const unassignedOrNaN: any = [];
|
||||
const ints: string[] = [];
|
||||
const unassignedOrNaN: string[] = [];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
values.forEach((v: any) => {
|
||||
values.forEach((v: string) => {
|
||||
if (isUserAnno && v === globals.unassignedCategoryLabel) {
|
||||
unassignedOrNaN.push(v);
|
||||
} else if (String(v).toLowerCase() === "nan") {
|
||||
@@ -44,8 +43,7 @@ const catLabelSort = (isUserAnno: boolean, values: any[]): any[] => {
|
||||
ints.sort((a, b) => +a - +b);
|
||||
unassignedOrNaN.sort(caseInsensitiveCompare);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
return (<any>ints).concat(strings, unassignedOrNaN);
|
||||
return ints.concat(strings, unassignedOrNaN);
|
||||
};
|
||||
|
||||
export default catLabelSort;
|
||||
|
||||
@@ -26,8 +26,7 @@ label -> {
|
||||
const getCoordinatesByLabel = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
schema: any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
categoryName: any,
|
||||
categoryName: string,
|
||||
categoryDf: Dataframe,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
layoutChoice: any,
|
||||
@@ -73,7 +72,7 @@ const getCoordinatesByLabel = (
|
||||
let coords = coordsByCategoryLabel.get(label);
|
||||
if (coords === undefined) {
|
||||
// Get the number of cells which are in the label
|
||||
// @ts-expect-error ts-migrate(2538) FIXME: Type 'unknown' cannot be used as an index type.
|
||||
// @ts-expect-error ts-migrate(2538) FIXME: Blocked by StateManager/ControlsHelpers
|
||||
const numInLabel = categoryValueCounts[labelIndex];
|
||||
coords = {
|
||||
hasFinite: false,
|
||||
@@ -99,7 +98,7 @@ const getCoordinatesByLabel = (
|
||||
return coordsByCategoryLabel;
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
calcMedianCentroid calculates the median coordinates for labels in a given category
|
||||
|
||||
label -> [x-Coordinate, y-Coordinate]
|
||||
@@ -108,8 +107,7 @@ const getCoordinatesByLabel = (
|
||||
const calcMedianCentroid = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
schema: any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
categoryName: any,
|
||||
categoryName: string,
|
||||
categoryDf: Dataframe,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
layoutChoice: any,
|
||||
@@ -151,8 +149,7 @@ const hashMedianCentroid = (
|
||||
// @ts-expect-error ts-migrate(6133) FIXME: 'schema' is declared but its value is never read.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
schema: any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
categoryName: any,
|
||||
categoryName: string,
|
||||
categoryDf: Dataframe,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
layoutChoice: any,
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* @returns a number
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default function clamp(val: any, rng: any) {
|
||||
export default function clamp(val: number, rng: [number, number]): number {
|
||||
return Math.max(Math.min(val, rng[1]), rng[0]);
|
||||
}
|
||||
|
||||
+10
-4
@@ -1,17 +1,23 @@
|
||||
import { NumberArray } from "../common/types/arraytypes";
|
||||
|
||||
/*
|
||||
clip - clip all values in a Array or TypedArray, IN PLACE.
|
||||
|
||||
Values in array are clipped if less than `lower` or greater than `upper`.
|
||||
|
||||
If `setTo` is undefined, values less than `lower` will be set to `lower`,
|
||||
and values greater than `upper` will be set to `upper`.
|
||||
and values greater than `upper` will be set to `upper`.
|
||||
|
||||
If `setTo` is not undefined, values outside the [lower, upper] range will be set to
|
||||
If `setTo` is not undefined, values outside the [lower, upper] range will be set to
|
||||
`setTo`.
|
||||
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default function clip(arr: any, lower: any, upper: any, setTo: any) {
|
||||
export default function clip(
|
||||
arr: NumberArray,
|
||||
lower: number,
|
||||
upper: number,
|
||||
setTo?: number
|
||||
): NumberArray {
|
||||
const lowerSet = setTo === undefined ? lower : setTo;
|
||||
const upperSet = setTo === undefined ? upper : setTo;
|
||||
for (let i = 0, l = arr.length; i < l; i += 1) {
|
||||
|
||||
@@ -6,8 +6,11 @@ If undefined or empty array, or array contains only non-finite numbers,
|
||||
will return [undefined, undefined]
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
function finiteExtent(tarr: any) {
|
||||
import type { TypedArray } from "../common/types/arraytypes";
|
||||
|
||||
function finiteExtent(
|
||||
tarr: TypedArray
|
||||
): [number, number] | [undefined, undefined] {
|
||||
let min;
|
||||
let max;
|
||||
let i;
|
||||
@@ -21,14 +24,17 @@ function finiteExtent(tarr: any) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; i < tarr.length; i += 1) {
|
||||
const val = tarr[i];
|
||||
if (Number.isFinite(val)) {
|
||||
if (min > val) min = val;
|
||||
if (max < val) max = val;
|
||||
if (min !== undefined && max !== undefined) {
|
||||
for (; i < tarr.length; i += 1) {
|
||||
const val = tarr[i];
|
||||
if (Number.isFinite(val)) {
|
||||
if (min > val) min = val;
|
||||
if (max < val) max = val;
|
||||
}
|
||||
}
|
||||
return [min, max];
|
||||
}
|
||||
return [min, max];
|
||||
return [undefined, undefined];
|
||||
}
|
||||
|
||||
export default finiteExtent;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ScaleLinear } from "d3";
|
||||
import significantDigits from "./significantDigits";
|
||||
|
||||
/**
|
||||
@@ -10,14 +11,14 @@ import significantDigits from "./significantDigits";
|
||||
* @returns - the number formatted as scientific, if it's big enough
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default function maybeScientific(x: any) {
|
||||
export default function maybeScientific(
|
||||
x: ScaleLinear<number, number, never>
|
||||
): string {
|
||||
let format = ",";
|
||||
const _ticks = x.ticks(4);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
if (x.domain().some((n: any) => Math.abs(n) >= 10000)) {
|
||||
/*
|
||||
if (x.domain().some((n: number) => Math.abs(n) >= 10000)) {
|
||||
/*
|
||||
heuristic: if the last tick d3 wants to render has one significant
|
||||
digit ie., 2000, render 2e+3, but if it's anything else ie., 42000000 render
|
||||
4.20e+n
|
||||
|
||||
@@ -13,43 +13,40 @@ anno matrix namespaces. It is still used by the component tier.
|
||||
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const makeDimensionName = (namespace: any, key: any) => `${namespace}_${key}`;
|
||||
const makeDimensionName = (namespace: string, key: string): string =>
|
||||
`${namespace}_${key}`;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const layoutDimensionName = (key: any) =>
|
||||
export const layoutDimensionName = (key: string): string =>
|
||||
makeDimensionName("layout", key);
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const obsAnnoDimensionName = (key: any) =>
|
||||
|
||||
export const obsAnnoDimensionName = (key: string): string =>
|
||||
makeDimensionName("obsAnno", key);
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const diffexpDimensionName = (key: any) =>
|
||||
|
||||
export const diffexpDimensionName = (key: string): string =>
|
||||
makeDimensionName("varData_diffexp", key);
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const userDefinedDimensionName = (key: any) =>
|
||||
|
||||
export const userDefinedDimensionName = (key: string): string =>
|
||||
makeDimensionName("varData_userDefined", key);
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export const geneSetSummaryDimensionName = (key: any) =>
|
||||
|
||||
export const geneSetSummaryDimensionName = (key: string): string =>
|
||||
makeDimensionName("geneSetSummary", key);
|
||||
|
||||
export interface ContinuousNamespace {
|
||||
isObs?: boolean;
|
||||
isDiffExp?: boolean;
|
||||
isUserDefined?: boolean;
|
||||
isGeneSetSummary?: boolean;
|
||||
}
|
||||
|
||||
/*
|
||||
continuousNamespace = {
|
||||
isObs: true,
|
||||
isDiffExp: false,
|
||||
isUserDefined: false,
|
||||
isGeneSet: false,
|
||||
}
|
||||
|
||||
ie., makeContinuousDimensionName(continuousNamespace = {isObs: true}, "total_reads")
|
||||
see: histogram brush, as it doesn't know what type of continuous it was with only field
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export const makeContinuousDimensionName = (
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
continuousNamespace: any,
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
key: any
|
||||
) => {
|
||||
continuousNamespace: ContinuousNamespace,
|
||||
key: string
|
||||
): string => {
|
||||
let name;
|
||||
if (continuousNamespace.isObs) {
|
||||
name = obsAnnoDimensionName(key);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import pull from "lodash.pull";
|
||||
import uniq from "lodash.uniq";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default function parseBulkGeneString(geneString: any) {
|
||||
export default function parseBulkGeneString(geneString: string): Array<string> {
|
||||
return pull(uniq(geneString.split(/[ ,]+/)), "");
|
||||
}
|
||||
|
||||
@@ -4,32 +4,27 @@ import scaleRGB from "./scaleRGB";
|
||||
// to do this operation. This lets us have speed, but keep the pleasant ability
|
||||
// to talk about colors by their text description eg, 'rgb(0,0,1)'
|
||||
//
|
||||
const colorCache = {};
|
||||
const colorCache = {} as { [key: string]: [number, number, number] };
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
function parseColorName(c: any) {
|
||||
function parseColorName(c: string): [number, number, number] {
|
||||
if (c[0] !== "#") {
|
||||
const _c = c.replace(/[^\d,.]/g, "").split(",");
|
||||
return [scaleRGB(+_c[0]), scaleRGB(+_c[1]), scaleRGB(+_c[2])];
|
||||
}
|
||||
const parsedHex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(c);
|
||||
if (!parsedHex || parsedHex.length < 4)
|
||||
throw new Error(`Invalid hex color: ${c}`);
|
||||
return [
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
scaleRGB(parseInt(parsedHex[1], 16)),
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
scaleRGB(parseInt(parsedHex[2], 16)),
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
scaleRGB(parseInt(parsedHex[3], 16)),
|
||||
];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default (c: any) => {
|
||||
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
||||
export default (c: string): [number, number, number] => {
|
||||
let cv = colorCache[c];
|
||||
if (!cv) {
|
||||
cv = parseColorName(c);
|
||||
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
||||
colorCache[c] = cv;
|
||||
}
|
||||
return cv;
|
||||
|
||||
@@ -28,37 +28,55 @@ Priority is a numeric value. Lower first. Stable ordering.
|
||||
|
||||
import TinyQueue from "tinyqueue";
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'a' implicitly has an 'any' type.
|
||||
function compare(a, b) {
|
||||
function compare<T>(
|
||||
a: PromiseLimitQueueItem<T>,
|
||||
b: PromiseLimitQueueItem<T>
|
||||
): number {
|
||||
const diff = a.priority - b.priority;
|
||||
if (diff) return diff;
|
||||
return a.order - b.order;
|
||||
}
|
||||
|
||||
export default class PromiseLimit {
|
||||
interface PromiseLimitQueueItem<T> {
|
||||
priority: number;
|
||||
order: number;
|
||||
resolve: (value: T | PromiseLike<T>) => void;
|
||||
reject: (reason?: unknown) => void;
|
||||
fn: (...args: Array<unknown>) => Promise<T>;
|
||||
args: Array<unknown>;
|
||||
}
|
||||
|
||||
export default class PromiseLimit<T> {
|
||||
queue: TinyQueue<PromiseLimitQueueItem<T>>;
|
||||
|
||||
maxConcurrency: number;
|
||||
|
||||
pending: number;
|
||||
|
||||
insertCounter: number;
|
||||
|
||||
constructor(maxConcurrency = 5) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).queue = new TinyQueue([], compare);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).maxConcurrency = maxConcurrency;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).pending = 0;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).insertCounter = 0;
|
||||
this.queue = new TinyQueue<PromiseLimitQueueItem<T>>(
|
||||
new Array<PromiseLimitQueueItem<T>>(),
|
||||
compare
|
||||
);
|
||||
this.maxConcurrency = maxConcurrency;
|
||||
this.pending = 0;
|
||||
this.insertCounter = 0;
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'p' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
priorityAdd(p, fn, ...args) {
|
||||
priorityAdd(
|
||||
p: number,
|
||||
fn: () => Promise<T>,
|
||||
...args: Array<unknown>
|
||||
): Promise<T> {
|
||||
// p - numermic priority (lower first)
|
||||
// fn - must return a promise
|
||||
// args - will be passed to fn
|
||||
return this._push(p, fn, args);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'fn' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
add(fn, ...args) {
|
||||
add(fn: () => Promise<T>, ...args: Array<unknown>): Promise<T> {
|
||||
// fn - must return a promise
|
||||
// args - will be passed to fn
|
||||
return this._push(0, fn, args);
|
||||
@@ -68,35 +86,25 @@ export default class PromiseLimit {
|
||||
Private below
|
||||
**/
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'priority' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
_push(priority, fn, args) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const order = (this as any).insertCount;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).insertCount += 1;
|
||||
_push(
|
||||
priority: number,
|
||||
fn: () => Promise<T>,
|
||||
args: Array<unknown>
|
||||
): Promise<T> {
|
||||
const order = this.insertCounter;
|
||||
this.insertCounter += 1;
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).queue.push({ priority, order, fn, args, resolve, reject });
|
||||
this.queue.push({ priority, order, fn, args, resolve, reject });
|
||||
this._resolveNext(false);
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
_resolveNext = (completed = true) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
if (completed) (this as any).pending -= 1;
|
||||
_resolveNext = (completed = true): void => {
|
||||
if (completed) this.pending -= 1;
|
||||
|
||||
while (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).queue.length > 0 &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).pending < (this as any).maxConcurrency
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const task = (this as any).queue.pop(); // order of insertion
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(this as any).pending += 1;
|
||||
while (this.queue.length > 0 && this.pending < this.maxConcurrency) {
|
||||
const task = this.queue.pop() as PromiseLimitQueueItem<T>; // order of insertion
|
||||
this.pending += 1;
|
||||
const { resolve, reject, fn, args } = task;
|
||||
|
||||
try {
|
||||
|
||||
+21
-15
@@ -22,38 +22,44 @@ rangeFill(array, start, step) -> array
|
||||
|
||||
*/
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type.
|
||||
function _doFill(arr, start, step, count) {
|
||||
import { TypedArray, NumberArray } from "../common/types/arraytypes";
|
||||
|
||||
function _doFill<T extends NumberArray>(
|
||||
arr: T,
|
||||
start: number,
|
||||
step: number,
|
||||
count: number
|
||||
): T {
|
||||
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
|
||||
arr[idx] = val;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function rangeFill(arr, start = 0, step = 1) {
|
||||
export function rangeFill(arr: NumberArray, start = 0, step = 1): NumberArray {
|
||||
return _doFill(arr, start, step, arr.length);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function range(start, stop, step) {
|
||||
export function range(
|
||||
start: number,
|
||||
stop?: number,
|
||||
step?: number
|
||||
): Array<number> {
|
||||
if (start === undefined) return [];
|
||||
if (stop === undefined) {
|
||||
stop = start;
|
||||
start = 0;
|
||||
}
|
||||
step = step || 1; // catch undefind and zero
|
||||
step = step || 1; // catch undefined and zero
|
||||
const len = Math.max(Math.ceil((stop - start) / step), 0);
|
||||
return _doFill(new Array(len), start, step, len);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function linspace(start, stop, nsteps) {
|
||||
// @ts-expect-error ts-migrate(2363) FIXME: The right-hand side of an arithmetic operation mus... Remove this comment to see the full error message
|
||||
const delta = (stop - start) / (nsteps - 1).toFixed();
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'i' implicitly has an 'any' type.
|
||||
export function linspace(
|
||||
start: number,
|
||||
stop: number,
|
||||
nsteps: number
|
||||
): Array<number> {
|
||||
const delta = (stop - start) / Number((nsteps - 1).toFixed());
|
||||
return range(0, nsteps, 1).map((i) => start + i * delta);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default function renderThrottle(callback: any) {
|
||||
export default function renderThrottle<T>(
|
||||
callback: (this: T) => void
|
||||
): (this: T) => void {
|
||||
/*
|
||||
This wraps a call to requestAnimationFrame(), enforcing a single
|
||||
render callback at any given time (ie, you can call this any number
|
||||
of times, and it will coallesce multiple inter-frame calls into a
|
||||
single render).
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
let rafCurrentlyInProgress: any = null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
return function f(this: any) {
|
||||
if (rafCurrentlyInProgress) return;
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias --- FIXME: disabled temporarily on migrate to TS.
|
||||
const context = this;
|
||||
let rafCurrentlyInProgress: number | null = null;
|
||||
return function f(this: T) {
|
||||
if (rafCurrentlyInProgress) return; // eslint-disable-next-line @typescript-eslint/no-this-alias --- required for functionality
|
||||
rafCurrentlyInProgress = window.requestAnimationFrame(() => {
|
||||
callback.apply(context);
|
||||
callback.call<T, never, void>(this);
|
||||
rafCurrentlyInProgress = null;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
// myScale(0) === -1
|
||||
// this is is equivalent to d3.scaleLinear().domain([0,1]).range([-1,1])
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default (domain: any, range: any) => {
|
||||
export default (
|
||||
domain: [number, number],
|
||||
range: [number, number]
|
||||
): ((value: number) => number) => {
|
||||
const domainStart = domain[0];
|
||||
const scale = (range[1] - range[0]) / (domain[1] - domain[0]);
|
||||
const invScale = 1 / scale;
|
||||
const rangeStart = range[0];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
const f = (value: any) => (value - domainStart) * scale + rangeStart;
|
||||
const f = (value: number) => (value - domainStart) * scale + rangeStart;
|
||||
|
||||
// inverter
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
f.invert = (value: any) => (value - rangeStart) * invScale + domainStart;
|
||||
f.invert = (value: number) => (value - rangeStart) * invScale + domainStart;
|
||||
|
||||
return f;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default (input: any) => {
|
||||
export default (input: number): number => {
|
||||
const outputMax = 1;
|
||||
const outputMin = 0;
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
/*
|
||||
via https://github.com/nodef/extra-number/blob/master/scripts/significantDigits.js
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
|
||||
export default (n: any) =>
|
||||
const significantDigits = (n: number): number =>
|
||||
n
|
||||
.toExponential()
|
||||
.replace(/e[+\-0-9]*$/, "")
|
||||
.replace(/^0\.?0*|\./, "").length;
|
||||
|
||||
export default significantDigits;
|
||||
|
||||
Reference in New Issue
Block a user