Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lodash-es and upgrade to TS@4.4 #3589

Merged
merged 8 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/d3-selection-multi": "1.0.4",
"@types/lodash": "^4.14.109",
"@types/lodash-es": "^4.17.3",
"@types/mocha": "^2.2.27",
"@types/sinon": "^1.16.36",
"awesome-typescript-loader": "^3.4.1",
Expand All @@ -54,7 +56,7 @@
"requirejs": "2.1.18",
"sinon": "^2.1.0",
"tslint": "5.18.0",
"typescript": "~2.7",
"typescript": "~4.4",
"webpack": "2.6.1",
"webpack-dev-server": "2.11.1",
"webpack-merge": "^4.1.0"
Expand All @@ -63,13 +65,12 @@
"@types/d3": "^4.13.0",
"@types/d3-shape": "^1.2.5",
"@types/is-plain-object": "^0.0.2",
"@types/lodash": "^4.14.109",
"d3": "^4.13.0",
"d3-ease": "^1.0.0",
"d3-shape": "^1.0.0",
"is-plain-object": "^2.0.4",
"lodash": "^4.17.10",
"tslib": "~1.8.0",
"lodash-es": "^4.17.15",
"tslib": "~2.3.1",
"typesettable": "4.1.0"
}
}
2 changes: 1 addition & 1 deletion src/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Bounds, Point, SimpleSelection, SpaceRequest } from "../core/interfaces
import * as RenderController from "../core/renderController";
import * as Utils from "../utils";

import { isElement } from "lodash";
import { isElement } from "lodash-es";
import { coerceExternalD3 } from "../utils/coerceD3";
import { makeEnum } from "../utils/makeEnum";
import { ComponentContainer } from "./componentContainer";
Expand Down
2 changes: 1 addition & 1 deletion src/drawers/symbolDrawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function makeSymbolCanvasDrawStep(

// check attributes and symbol type
const attrsSame = isAttributeValuesEqual(prevAttrs, attrs, ContextStyleAttrs);
const symbolGenerator = symbolAccessor(datum, index, this._dataset);
const symbolGenerator = symbolAccessor(datum, index, dataset);
Copy link
Contributor Author

@michael-yx-wu michael-yx-wu Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this ever worked, since the this in a browser context refers to the window object and doesn't make any sense here. Maybe a transpilation bug that is surfacing now that we've upgraded typescript?

if (attrsSame && prevSymbolSize == symbolSize && prevSymbolGenerator == symbolGenerator) {
// no-op;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/memoize/memoizeProjectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { MapCache, memoize as lodashMemoize } from "lodash";
import type { MapCache } from "lodash";
import { memoize } from "lodash-es";

import { Dataset } from "../core/dataset";
import { AttributeToProjector, Projector } from "../core/interfaces";
Expand Down Expand Up @@ -76,7 +76,7 @@ class DatasetIndexCache implements MapCache {
}

export function memoizeProjector(projector: Projector): Projector {
const memo = lodashMemoize(projector, DatasetIndexCache.resolver);
const memo = memoize(projector, DatasetIndexCache.resolver);
(memo as any).cache = new DatasetIndexCache();
return memo;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plots/barPlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Bar<X, Y> extends XYPlot<X, Y> {
protected _isVertical: boolean;
private _labelFormatter: DatumFormatter = Formatters.identity();
private _labelsEnabled = false;
private _labelsPosition = LabelsPosition.end;
private _labelsPosition: LabelsPosition = LabelsPosition.end;
protected _labelFontSize = Label._DEFAULT_FONT_SIZE_PX;
private _hideBarsIfAnyAreTooWide = true;
private _labelConfig: Utils.Map<Dataset, LabelConfig>;
Expand Down Expand Up @@ -862,7 +862,7 @@ export class Bar<X, Y> extends XYPlot<X, Y> {
* same as the "pixel point" because they are always at the top/left of the
* bar.
*/
protected _pixelBounds(datum: any, index: number, dataset: Dataset) {
protected _pixelBounds(datum: any, index: number, dataset: Dataset): Pick<DOMRect, "x" | "y" | "width" | "height"> {
const attrToProjector = this._getAttrToProjector();
return {
x: attrToProjector["x"](datum, index, dataset),
Expand Down
2 changes: 1 addition & 1 deletion src/plots/rectanglePlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class Rectangle<X, Y> extends XYPlot<X, Y> {
return this._entityBBox(datum, index, dataset, this._getAttrToProjector());
}

private _entityBBox(datum: any, index: number, dataset: Dataset, attrToProjector: AttributeToProjector): SVGRect {
private _entityBBox(datum: any, index: number, dataset: Dataset, attrToProjector: AttributeToProjector): Pick<SVGRect, "x" | "y" | "width" | "height"> {
return {
x: attrToProjector["x"](datum, index, dataset),
y: attrToProjector["y"](datum, index, dataset),
Expand Down
2 changes: 1 addition & 1 deletion src/plots/scatterPlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class Scatter<X, Y> extends XYPlot<X, Y> {
};
}

protected _entityBounds(entity: ILightweightScatterPlotEntity) {
protected _entityBounds(entity: ILightweightScatterPlotEntity): Pick<DOMRect, "x" | "y"| "width" | "height"> {
return {
x: entity.position.x - entity.diameter / 2,
y: entity.position.y - entity.diameter / 2,
Expand Down
10 changes: 5 additions & 5 deletions src/scales/interpolatedColorScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as Utils from "../utils";

import { Scale } from "./scale";

type supportedScale = d3.ScaleLinear<number, string> | d3.ScaleLogarithmic<number, string> | d3.ScalePower<number, string>;
type SupportedScale = d3.ScaleLinear<number, string> | d3.ScaleLogarithmic<number, string> | d3.ScalePower<number, string>;

export class InterpolatedColor extends Scale<number, string> {
public static REDS = [
Expand Down Expand Up @@ -54,8 +54,8 @@ export class InterpolatedColor extends Scale<number, string> {
"#B10026", // red
];
private _colorRange: string[];
private _colorScale: supportedScale;
private _d3Scale: supportedScale;
private _colorScale: SupportedScale;
private _d3Scale: SupportedScale;

/**
* An InterpolatedColor Scale maps numbers to color hex values, expressed as strings.
Expand Down Expand Up @@ -96,8 +96,8 @@ export class InterpolatedColor extends Scale<number, string> {
/**
* Generates the converted QuantitativeScale.
*/
private _d3InterpolatedScale() {
return this._colorScale.range([0, 1]).interpolate(this._interpolateColors());
private _d3InterpolatedScale(): SupportedScale {
return (this._colorScale.range([0, 1]) as SupportedScale).interpolate(this._interpolateColors()) as SupportedScale;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/utils/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function contains(parent: Element, child: Element): boolean {
* @param {d3.Selection} element
* @returns {SVGRed} The bounding box.
*/
export function elementBBox(element: SimpleSelection<any>) {
let bbox: SVGRect;
export function elementBBox(element: SimpleSelection<any>): Pick<SVGRect, "x" | "y" | "width" | "height"> {
let bbox: Pick<SVGRect, "x" | "y" | "width" | "height">;
// HACKHACK: Firefox won't correctly measure nodes with style "display: none" or their descendents (FF Bug 612118).
try {
bbox = (<any> element.node()).getBBox();
Expand Down Expand Up @@ -186,7 +186,7 @@ export function expandRect(rect: ClientRect, amount: number) {
bottom: rect.bottom + amount,
width: rect.width + amount * 2,
height: rect.height + amount * 2,
};
} as ClientRect;
}

/**
Expand Down Expand Up @@ -219,7 +219,7 @@ export function clientRectInside(innerClientRect: ClientRect, outerClientRect: C
*/
export function intersectsBBox(xValOrRange: number | Range,
yValOrRange: number | Range,
bbox: SVGRect,
bbox: Pick<SVGRect, "x" | "y" | "width" | "height">,
tolerance = 0.5) {
const xRange = _parseRange(xValOrRange);
const yRange = _parseRange(yValOrRange);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/objectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* Polyfill for Object.assign
*/
export function assign<T extends Record<any, any>>(...objs: Partial<T>[]): T {
const result = {} as Partial<T>;
const result: Partial<T> = {};
for(const obj of objs) {
const keys = Object.keys(obj);
for (const key of keys) {
result[key] = obj[key];
result[key as keyof T] = obj[key];
}
}
return result as T;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/stackingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import * as d3 from "d3";
import { Dataset } from "../core/dataset";
import { IAccessor } from "../core/interfaces";

import { memoize, MemoizedFunction } from "lodash";
import type { MemoizedFunction } from "lodash";
import { memoize } from "lodash-es";
import * as Utils from "./";
import { makeEnum } from "./makeEnum";

Expand Down
2 changes: 1 addition & 1 deletion test/testMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function triggerFakeWheelEvent(type: string, target: SimpleSelection<void
let event: WheelEvent;
if (isIE()) {
event = document.createEvent("WheelEvent");
event.initWheelEvent("wheel", true, true, window, 1, xPos, yPos, xPos, yPos, 0, null, null, 0, deltaY, 0, 0);
(event as any).initWheelEvent("wheel", true, true, window, 1, xPos, yPos, xPos, yPos, 0, null, null, 0, deltaY, 0, 0);
} else {
// HACKHACK anycasting constructor to allow for the dictionary argument
// https://github.com/Microsoft/TypeScript/issues/2416
Expand Down
2 changes: 1 addition & 1 deletion test/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ declare interface Window {
Pixel_CloseTo_Requirement: number;
}

declare var window: Window;
declare var window: Window & typeof globalThis;
38 changes: 25 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,17 @@
resolved "https://registry.npmjs.org/@types/is-plain-object/-/is-plain-object-0.0.2.tgz#25bca7b656ba23fb03799a060dba201a7952103d"
integrity sha1-Jbyntla6I/sDeZoGDbogGnlSED0=

"@types/lodash@^4.14.109":
version "4.14.109"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.109.tgz#b1c4442239730bf35cabaf493c772b18c045886d"
integrity sha512-hop8SdPUEzbcJm6aTsmuwjIYQo1tqLseKCM+s2bBqTU2gErwI4fE+aqUVOlscPSQbKHKgtMMPoC+h4AIGOJYvw==
"@types/lodash-es@^4.17.3":
version "4.17.5"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.5.tgz#1c3fdd16849d84aea43890b1c60da379fb501353"
integrity sha512-SHBoI8/0aoMQWAgUHMQ599VM6ZiSKg8sh/0cFqqlQQMyY9uEplc0ULU5yQNzcvdR4ZKa0ey8+vFmahuRbOCT1A==
dependencies:
"@types/lodash" "*"

"@types/lodash@*", "@types/lodash@^4.14.109":
version "4.14.177"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.177.tgz#f70c0d19c30fab101cad46b52be60363c43c4578"
integrity sha512-0fDwydE2clKe9MNfvXHBHF9WEahRuj+msTuQqOmAApNORFvhMYZKNGGJdCzuhheVjMps/ti0Ak/iJPACMaevvw==

"@types/mocha@^2.2.27":
version "2.2.40"
Expand Down Expand Up @@ -4470,6 +4477,11 @@ locate-path@^2.0.0:
p-locate "^2.0.0"
path-exists "^3.0.0"

lodash-es@^4.17.15:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

michael-yx-wu marked this conversation as resolved.
Show resolved Hide resolved
lodash._arraycopy@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._arraycopy/-/lodash._arraycopy-3.0.0.tgz#76e7b7c1f1fb92547374878a562ed06a3e50f6e1"
Expand Down Expand Up @@ -4703,7 +4715,7 @@ lodash@^3.10.0, lodash@^3.3.1, lodash@^3.5.0, lodash@^3.7.0, lodash@^3.9.0, loda
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=

lodash@^4.14.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.4:
lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -7168,10 +7180,10 @@ tslib@^1.8.0, tslib@^1.8.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

tslib@~1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6"
integrity sha512-ymKWWZJST0/CkgduC2qkzjMOWr4bouhuURNXCn/inEX0L57BnRG6FhX76o7FOnsjHazCjfU2LKeSrlS2sIKQJg==
tslib@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==

tslint@5.18.0:
version "5.18.0"
Expand Down Expand Up @@ -7249,10 +7261,10 @@ typedarray@^0.0.6, typedarray@~0.0.5:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@~2.7:
version "2.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
integrity sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==
typescript@~4.4:
version "4.4.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==

typesettable@4.1.0:
version "4.1.0"
Expand Down