Skip to content

Commit

Permalink
fix: remove lodash es
Browse files Browse the repository at this point in the history
  • Loading branch information
da730 committed May 22, 2024
1 parent a1a7da1 commit b1a48d9
Show file tree
Hide file tree
Showing 35 changed files with 122 additions and 83 deletions.
26 changes: 4 additions & 22 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"ts-pattern": "~4.1.4",
"node-sql-parser": "~4.17.0",
"lodash-es": "~4.17.21"
"@visactor/vutils": "~0.17.4"
},
"devDependencies": {
"@types/jest": "^26.0.0",
Expand All @@ -44,7 +44,6 @@
"typescript": "4.9.5",
"@internal/ts-config": "workspace:*",
"@internal/eslint-config": "workspace:*",
"@internal/bundler": "workspace:*",
"@types/lodash-es": "~4.17.12"
"@internal/bundler": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/calculator/src/astParser/astPipes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray } from 'lodash-es';
import { isArray } from '@visactor/vutils';
import type { AggrFunc, ColumnRef, Expr, Param, Value } from 'node-sql-parser';

import type { ASTParserContext, ASTParserPipe, SimpleFieldInfo } from './type';
Expand Down
2 changes: 1 addition & 1 deletion packages/calculator/src/astParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SQLAst, SimpleFieldInfo } from './type';
import { Query, TableData } from '../types';
import { parseRespondField, preprocessSQL } from './utils';
import { parseSqlAST } from './parseSqlAST';
import { isArray } from 'lodash-es';
import { isArray } from '@visactor/vutils';

/**
* query the source dataset according to user's input and fieldInfo to get aggregated dataset
Expand Down
3 changes: 2 additions & 1 deletion packages/calculator/src/astParser/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isInteger, isString } from 'lodash-es';
import { isString } from '@visactor/vutils';
import { ASTParserContext, ASTParserPipe, DataType, ROLE, SimpleFieldInfo } from './type';
import { Query, TableData } from '../types';
import { isInteger } from '../utils';

export const execPipeline = (src: Partial<Query>, pipes: ASTParserPipe[], context: ASTParserContext) =>
pipes.reduce((pre: Partial<Query>, pipe: ASTParserPipe) => {
Expand Down
13 changes: 6 additions & 7 deletions packages/calculator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './types'
export * from './query'
export * from './join'
export {
getSelectColumnName,
getColumnIdentityName,
} from './pipes/select'
export * from './types';
export * from './query';
export * from './join';
export { getSelectColumnName, getColumnIdentityName } from './pipes/select';

export * from './utils/typeCheck';
5 changes: 3 additions & 2 deletions packages/calculator/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ordered'
export * from './includes'
export * from './ordered';
export * from './includes';
export * from './typeCheck';
12 changes: 12 additions & 0 deletions packages/calculator/src/utils/typeCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { isNumber } from '@visactor/vutils';

export function isInteger(value: any) {
return typeof value == 'number' && Number.isInteger(value);
}

export function isNaN(value: any) {
// An `NaN` primitive is the only value that is not equal to itself.
// Perform the `toStringTag` check first to avoid errors with some
// ActiveX objects in IE.
return isNumber(value) && value != +value;
}
5 changes: 2 additions & 3 deletions packages/chart-advisor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"lodash-es": "~4.17.21"
"@visactor/vutils": "~0.17.4"
},
"devDependencies": {
"@types/jest": "^26.0.0",
Expand All @@ -46,7 +46,6 @@
"@internal/ts-config": "workspace:*",
"@internal/eslint-config": "workspace:*",
"@internal/bundler": "workspace:*",
"@rushstack/eslint-patch": "~1.1.4",
"@types/lodash-es": "~4.17.12"
"@rushstack/eslint-patch": "~1.1.4"
}
}
12 changes: 10 additions & 2 deletions packages/chart-advisor/src/dataUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { cloneDeep, isNil, uniq, isNaN } from 'lodash-es';
import { cloneDeep, isNil, isNumber, uniqArray } from '@visactor/vutils';
import { DataTypeName } from './type';

export function isNaN(value: any) {
// An `NaN` primitive is the only value that is not equal to itself.
// Perform the `toStringTag` check first to avoid errors with some
// ActiveX objects in IE.
return isNumber(value) && value != +value;
}

//将vizData中的dataset数组展开 后端版本可直接获取到dataSource,不用执行此方法
const restoreDataItem = item => {
if (!Array.isArray(item)) {
Expand Down Expand Up @@ -65,6 +73,6 @@ export const calQuantile = (dataset, q) => {
};

//数组去重
export const unique = arr => uniq(arr);
export const unique = arr => uniqArray(arr);

export const isTemporal = (type: DataTypeName) => type === 'date';
2 changes: 1 addition & 1 deletion packages/chart-advisor/src/fieldAssign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clone, cloneDeep } from 'lodash-es';
import { cloneDeep } from '@visactor/vutils';
import { AutoChartCell } from './type';
import * as dataUtils from './dataUtil';

Expand Down
15 changes: 12 additions & 3 deletions packages/chart-advisor/src/fieldUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { uniq, pick, omit } from 'lodash-es';
import { uniqArray, pick, isNumber, isNil } from '@visactor/vutils';
import { FoldInfo } from './type';
import { Dataset, UniqueId, DataItem, AliasMap } from './type';

export function omit(obj: any, arr: string[]) {
if (isNil(obj) || isNil(arr)) {
return obj;
}
return Object.keys(obj)
.filter(k => !arr.includes(k))
.reduce((res, key) => ((res[key] = obj[key]), res), {});
}

/**
* 输入二维数组,输出笛卡尔积长度
* @param list
Expand Down Expand Up @@ -48,12 +57,12 @@ const product = (list: any[][]) =>
// 从数据集中获取 domain map
export const getDomainFromDataset = (dataset: Dataset, dim: UniqueId): string[] => {
const values: string[] = dataset.map((d: DataItem) => String(d[dim]));
return uniq(values);
return uniqArray(values) as string[];
};

// 保留dataset中的某些字段
export const retainDatasetField = (dataset: Dataset, fields: UniqueId[]): Dataset =>
dataset.map((data: DataItem) => pick(data, fields)) as Dataset;
dataset.map((data: DataItem) => pick(data, fields as any)) as Dataset;

// 移除dataset中的某些字段
export const removeDatasetField = (dataset: Dataset, fields: UniqueId[]): Dataset =>
Expand Down
5 changes: 3 additions & 2 deletions packages/chart-advisor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import type {
} from './type';
import { scorer as defaultScorer } from './score';
import * as dataUtils from './dataUtil';
import { isNil, isNaN } from 'lodash-es';
import { isNil } from '@visactor/vutils';
import { isNaN } from './dataUtil';

export { fold } from './fieldUtils';
export { fold, omit } from './fieldUtils';
export { FOLD_NAME, FOLD_VALUE } from './constant';

export function chartAdvisor(params: AdviserParams): AdviseResult {
Expand Down
4 changes: 2 additions & 2 deletions packages/chart-advisor/src/pivot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil, range, uniq } from 'lodash-es';
import { isNil, range, uniqArray } from '@visactor/vutils';

import { getDomainFromDataset } from './fieldUtils';
import { UniqueId, Dataset, Datasets, DataItem, PivotTree } from './type';
Expand Down Expand Up @@ -157,7 +157,7 @@ const pivotTree = (keys: UniqueId[], pathList: Path[], deep = 0): PivotTree => {
}
const getDomainFromPath = () => {
const nodes: string[] = pathList.map((path: Path) => path[deep]);
return uniq(nodes);
return uniqArray(nodes) as string[];
};
const field: UniqueId = keys[deep];
const domain: string[] = getDomainFromPath();
Expand Down
11 changes: 1 addition & 10 deletions packages/chart-advisor/src/score.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTemporal } from './dataUtil';
import { cloneDeep, uniq } from 'lodash-es';
import { cloneDeep } from '@visactor/vutils';
import {
ChartType,
MeasureDataset,
Expand Down Expand Up @@ -462,10 +462,6 @@ export const scorer: Scorer = params => {
const combineDatasets: Dataset[] = combineMetadata.map(metaData => metaData.dataset);
const combineCells: any[] = combineMetadata.map(metaData => metaData.cell);

const combineColorItems: string[] = uniq(
combineMetadata.map(metaData => metaData.colorItems).reduce((pre: string[], cur: string[]) => pre.concat(cur), [])
);

// 透视分析
const {
datasets: combinePivotDataSet,
Expand Down Expand Up @@ -738,11 +734,6 @@ export const scorer: Scorer = params => {
);

const combineDatasets: Dataset[] = combineMetadata.map(metaData => metaData.dataset);
const combineCells: any[] = combineMetadata.map(metaData => metaData.cell);

const combineColorItems: string[] = uniq(
combineMetadata.map(metaData => metaData.colorItems).reduce((pre: string[], cur: string[]) => pre.concat(cur), [])
);

// 透视分析
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ManualTicker, defaultTimeline } from '@visactor/vrender-core';
import VMind from '../../../../../src';
import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg';
import { createCanvas } from 'canvas';
import { isNil } from 'lodash-es';
import { isNil } from '@visactor/vutils';

const TextArea = Input.TextArea;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
} from '../../constants/mockData';
import VMind, { ArcoTheme } from '../../../../../src/index';
import { Model } from '../../../../../src/index';
import { isArray } from 'lodash-es';
import { isArray } from '@visactor/vutils';

const TextArea = Input.TextArea;
const Option = Select.Option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useCallback, useEffect, useRef } from 'react';
import './index.scss';
import { Button, Input, Card, Space, Modal, Spin } from '@arco-design/web-react';
import VChart from '@visactor/vchart';
import { isNil } from 'lodash-es';
import { isNil } from '@visactor/vutils';

const TextArea = Input.TextArea;

Expand Down
6 changes: 2 additions & 4 deletions packages/vmind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
"dotenv": "~16.3.1",
"@ffmpeg/ffmpeg": "^0.11.6",
"@visactor/vrender-core": "^0.17.23",
"canvas": "^2.11.2",
"@types/lodash-es": "~4.17.12"
"canvas": "^2.11.2"
},
"dependencies": {
"@visactor/chart-advisor": "workspace:1.2.11",
Expand All @@ -95,7 +94,6 @@
"dayjs": "~1.11.10",
"js-yaml": "~4.1.0",
"@visactor/calculator": "workspace:1.2.11",
"alasql": "~4.3.2",
"lodash-es": "~4.17.21"
"alasql": "~4.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray } from 'lodash-es';
import { isArray } from '@visactor/vutils';
import type { DataTypeName } from '@visactor/chart-advisor';
import { ChartType } from '@visactor/chart-advisor';
import type { Cell } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Transformer } from '../../../../../../base/tools/transformer';
import type { GenerateFieldMapContext, GenerateFieldMapOutput } from '../../types';
import { isArray, isString } from 'lodash-es';
import { isArray, isString } from '@visactor/vutils';
import { matchFieldWithoutPunctuation } from './utils';
import { ChartType } from '../../../../../../common/typings';
import { DataType, ROLE } from '../../../../../../common/typings';
Expand Down
Loading

0 comments on commit b1a48d9

Please sign in to comment.