Skip to content

Commit 2ae4d07

Browse files
Use lodash-es and upgrade to [email protected] (#3589)
1 parent 2db30e4 commit 2ae4d07

14 files changed

+54
-40
lines changed

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"devDependencies": {
3333
"@types/chai": "^3.4.34",
3434
"@types/d3-selection-multi": "1.0.4",
35+
"@types/lodash": "^4.14.109",
36+
"@types/lodash-es": "^4.17.3",
3537
"@types/mocha": "^2.2.27",
3638
"@types/sinon": "^1.16.36",
3739
"awesome-typescript-loader": "^3.4.1",
@@ -54,7 +56,7 @@
5456
"requirejs": "2.1.18",
5557
"sinon": "^2.1.0",
5658
"tslint": "5.18.0",
57-
"typescript": "~2.7",
59+
"typescript": "~4.4",
5860
"webpack": "2.6.1",
5961
"webpack-dev-server": "2.11.1",
6062
"webpack-merge": "^4.1.0"
@@ -63,13 +65,12 @@
6365
"@types/d3": "^4.13.0",
6466
"@types/d3-shape": "^1.2.5",
6567
"@types/is-plain-object": "^0.0.2",
66-
"@types/lodash": "^4.14.109",
6768
"d3": "^4.13.0",
6869
"d3-ease": "^1.0.0",
6970
"d3-shape": "^1.0.0",
7071
"is-plain-object": "^2.0.4",
71-
"lodash": "^4.17.10",
72-
"tslib": "~1.8.0",
72+
"lodash-es": "^4.17.15",
73+
"tslib": "~2.3.1",
7374
"typesettable": "4.1.0"
7475
}
7576
}

src/components/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Bounds, Point, SimpleSelection, SpaceRequest } from "../core/interfaces
99
import * as RenderController from "../core/renderController";
1010
import * as Utils from "../utils";
1111

12-
import { isElement } from "lodash";
12+
import { isElement } from "lodash-es";
1313
import { coerceExternalD3 } from "../utils/coerceD3";
1414
import { makeEnum } from "../utils/makeEnum";
1515
import { ComponentContainer } from "./componentContainer";

src/drawers/symbolDrawer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function makeSymbolCanvasDrawStep(
5656

5757
// check attributes and symbol type
5858
const attrsSame = isAttributeValuesEqual(prevAttrs, attrs, ContextStyleAttrs);
59-
const symbolGenerator = symbolAccessor(datum, index, this._dataset);
59+
const symbolGenerator = symbolAccessor(datum, index, dataset);
6060
if (attrsSame && prevSymbolSize == symbolSize && prevSymbolGenerator == symbolGenerator) {
6161
// no-op;
6262
} else {

src/memoize/memoizeProjectors.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
2-
import { MapCache, memoize as lodashMemoize } from "lodash";
1+
import type { MapCache } from "lodash";
2+
import { memoize } from "lodash-es";
33

44
import { Dataset } from "../core/dataset";
55
import { AttributeToProjector, Projector } from "../core/interfaces";
@@ -76,7 +76,7 @@ class DatasetIndexCache implements MapCache {
7676
}
7777

7878
export function memoizeProjector(projector: Projector): Projector {
79-
const memo = lodashMemoize(projector, DatasetIndexCache.resolver);
79+
const memo = memoize(projector, DatasetIndexCache.resolver);
8080
(memo as any).cache = new DatasetIndexCache();
8181
return memo;
8282
}

src/plots/barPlot.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Bar<X, Y> extends XYPlot<X, Y> {
7373
protected _isVertical: boolean;
7474
private _labelFormatter: DatumFormatter = Formatters.identity();
7575
private _labelsEnabled = false;
76-
private _labelsPosition = LabelsPosition.end;
76+
private _labelsPosition: LabelsPosition = LabelsPosition.end;
7777
protected _labelFontSize = Label._DEFAULT_FONT_SIZE_PX;
7878
private _hideBarsIfAnyAreTooWide = true;
7979
private _labelConfig: Utils.Map<Dataset, LabelConfig>;
@@ -862,7 +862,7 @@ export class Bar<X, Y> extends XYPlot<X, Y> {
862862
* same as the "pixel point" because they are always at the top/left of the
863863
* bar.
864864
*/
865-
protected _pixelBounds(datum: any, index: number, dataset: Dataset) {
865+
protected _pixelBounds(datum: any, index: number, dataset: Dataset): Pick<DOMRect, "x" | "y" | "width" | "height"> {
866866
const attrToProjector = this._getAttrToProjector();
867867
return {
868868
x: attrToProjector["x"](datum, index, dataset),

src/plots/rectanglePlot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class Rectangle<X, Y> extends XYPlot<X, Y> {
270270
return this._entityBBox(datum, index, dataset, this._getAttrToProjector());
271271
}
272272

273-
private _entityBBox(datum: any, index: number, dataset: Dataset, attrToProjector: AttributeToProjector): SVGRect {
273+
private _entityBBox(datum: any, index: number, dataset: Dataset, attrToProjector: AttributeToProjector): Pick<SVGRect, "x" | "y" | "width" | "height"> {
274274
return {
275275
x: attrToProjector["x"](datum, index, dataset),
276276
y: attrToProjector["y"](datum, index, dataset),

src/plots/scatterPlot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class Scatter<X, Y> extends XYPlot<X, Y> {
188188
};
189189
}
190190

191-
protected _entityBounds(entity: ILightweightScatterPlotEntity) {
191+
protected _entityBounds(entity: ILightweightScatterPlotEntity): Pick<DOMRect, "x" | "y"| "width" | "height"> {
192192
return {
193193
x: entity.position.x - entity.diameter / 2,
194194
y: entity.position.y - entity.diameter / 2,

src/scales/interpolatedColorScale.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as Utils from "../utils";
99

1010
import { Scale } from "./scale";
1111

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

1414
export class InterpolatedColor extends Scale<number, string> {
1515
public static REDS = [
@@ -54,8 +54,8 @@ export class InterpolatedColor extends Scale<number, string> {
5454
"#B10026", // red
5555
];
5656
private _colorRange: string[];
57-
private _colorScale: supportedScale;
58-
private _d3Scale: supportedScale;
57+
private _colorScale: SupportedScale;
58+
private _d3Scale: SupportedScale;
5959

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

103103
/**

src/utils/domUtils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function contains(parent: Element, child: Element): boolean {
2727
* @param {d3.Selection} element
2828
* @returns {SVGRed} The bounding box.
2929
*/
30-
export function elementBBox(element: SimpleSelection<any>) {
31-
let bbox: SVGRect;
30+
export function elementBBox(element: SimpleSelection<any>): Pick<SVGRect, "x" | "y" | "width" | "height"> {
31+
let bbox: Pick<SVGRect, "x" | "y" | "width" | "height">;
3232
// HACKHACK: Firefox won't correctly measure nodes with style "display: none" or their descendents (FF Bug 612118).
3333
try {
3434
bbox = (<any> element.node()).getBBox();
@@ -186,7 +186,7 @@ export function expandRect(rect: ClientRect, amount: number) {
186186
bottom: rect.bottom + amount,
187187
width: rect.width + amount * 2,
188188
height: rect.height + amount * 2,
189-
};
189+
} as ClientRect;
190190
}
191191

192192
/**
@@ -219,7 +219,7 @@ export function clientRectInside(innerClientRect: ClientRect, outerClientRect: C
219219
*/
220220
export function intersectsBBox(xValOrRange: number | Range,
221221
yValOrRange: number | Range,
222-
bbox: SVGRect,
222+
bbox: Pick<SVGRect, "x" | "y" | "width" | "height">,
223223
tolerance = 0.5) {
224224
const xRange = _parseRange(xValOrRange);
225225
const yRange = _parseRange(yValOrRange);

src/utils/objectUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* Polyfill for Object.assign
88
*/
99
export function assign<T extends Record<any, any>>(...objs: Partial<T>[]): T {
10-
const result = {} as Partial<T>;
10+
const result: Partial<T> = {};
1111
for(const obj of objs) {
1212
const keys = Object.keys(obj);
1313
for (const key of keys) {
14-
result[key] = obj[key];
14+
result[key as keyof T] = obj[key];
1515
}
1616
}
1717
return result as T;

src/utils/stackingUtils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import * as d3 from "d3";
88
import { Dataset } from "../core/dataset";
99
import { IAccessor } from "../core/interfaces";
1010

11-
import { memoize, MemoizedFunction } from "lodash";
11+
import type { MemoizedFunction } from "lodash";
12+
import { memoize } from "lodash-es";
1213
import * as Utils from "./";
1314
import { makeEnum } from "./makeEnum";
1415

test/testMethods.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function triggerFakeWheelEvent(type: string, target: SimpleSelection<void
223223
let event: WheelEvent;
224224
if (isIE()) {
225225
event = document.createEvent("WheelEvent");
226-
event.initWheelEvent("wheel", true, true, window, 1, xPos, yPos, xPos, yPos, 0, null, null, 0, deltaY, 0, 0);
226+
(event as any).initWheelEvent("wheel", true, true, window, 1, xPos, yPos, xPos, yPos, 0, null, null, 0, deltaY, 0, 0);
227227
} else {
228228
// HACKHACK anycasting constructor to allow for the dictionary argument
229229
// https://github.com/Microsoft/TypeScript/issues/2416

test/window.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ declare interface Window {
44
Pixel_CloseTo_Requirement: number;
55
}
66

7-
declare var window: Window;
7+
declare var window: Window & typeof globalThis;

yarn.lock

+25-13
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,17 @@
248248
resolved "https://registry.npmjs.org/@types/is-plain-object/-/is-plain-object-0.0.2.tgz#25bca7b656ba23fb03799a060dba201a7952103d"
249249
integrity sha1-Jbyntla6I/sDeZoGDbogGnlSED0=
250250

251-
"@types/lodash@^4.14.109":
252-
version "4.14.109"
253-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.109.tgz#b1c4442239730bf35cabaf493c772b18c045886d"
254-
integrity sha512-hop8SdPUEzbcJm6aTsmuwjIYQo1tqLseKCM+s2bBqTU2gErwI4fE+aqUVOlscPSQbKHKgtMMPoC+h4AIGOJYvw==
251+
"@types/lodash-es@^4.17.3":
252+
version "4.17.5"
253+
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.5.tgz#1c3fdd16849d84aea43890b1c60da379fb501353"
254+
integrity sha512-SHBoI8/0aoMQWAgUHMQ599VM6ZiSKg8sh/0cFqqlQQMyY9uEplc0ULU5yQNzcvdR4ZKa0ey8+vFmahuRbOCT1A==
255+
dependencies:
256+
"@types/lodash" "*"
257+
258+
"@types/lodash@*", "@types/lodash@^4.14.109":
259+
version "4.14.177"
260+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.177.tgz#f70c0d19c30fab101cad46b52be60363c43c4578"
261+
integrity sha512-0fDwydE2clKe9MNfvXHBHF9WEahRuj+msTuQqOmAApNORFvhMYZKNGGJdCzuhheVjMps/ti0Ak/iJPACMaevvw==
255262

256263
"@types/mocha@^2.2.27":
257264
version "2.2.40"
@@ -4470,6 +4477,11 @@ locate-path@^2.0.0:
44704477
p-locate "^2.0.0"
44714478
path-exists "^3.0.0"
44724479

4480+
lodash-es@^4.17.15:
4481+
version "4.17.15"
4482+
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
4483+
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
4484+
44734485
lodash._arraycopy@^3.0.0:
44744486
version "3.0.0"
44754487
resolved "https://registry.yarnpkg.com/lodash._arraycopy/-/lodash._arraycopy-3.0.0.tgz#76e7b7c1f1fb92547374878a562ed06a3e50f6e1"
@@ -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
47034715
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
47044716
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=
47054717

4706-
lodash@^4.14.0, lodash@^4.17.10, lodash@^4.17.2, lodash@^4.17.4:
4718+
lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4:
47074719
version "4.17.21"
47084720
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
47094721
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -7168,10 +7180,10 @@ tslib@^1.8.0, tslib@^1.8.1:
71687180
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
71697181
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
71707182

7171-
tslib@~1.8.0:
7172-
version "1.8.0"
7173-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6"
7174-
integrity sha512-ymKWWZJST0/CkgduC2qkzjMOWr4bouhuURNXCn/inEX0L57BnRG6FhX76o7FOnsjHazCjfU2LKeSrlS2sIKQJg==
7183+
tslib@~2.3.1:
7184+
version "2.3.1"
7185+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
7186+
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
71757187

71767188
71777189
version "5.18.0"
@@ -7249,10 +7261,10 @@ typedarray@^0.0.6, typedarray@~0.0.5:
72497261
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
72507262
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
72517263

7252-
typescript@~2.7:
7253-
version "2.7.2"
7254-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
7255-
integrity sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==
7264+
typescript@~4.4:
7265+
version "4.4.4"
7266+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
7267+
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
72567268

72577269
72587270
version "4.1.0"

0 commit comments

Comments
 (0)