Skip to content

Commit

Permalink
perf(sheet): statistic and formula perf (#1583)
Browse files Browse the repository at this point in the history
* perf(sheet): status bar

* fix(sheet): remove

* fix(sheet): type error

* refactor(formula): create value object cache

* fix(formula): type error
  • Loading branch information
DR-Univer committed Mar 15, 2024
1 parent 75d0dca commit 9e63af7
Show file tree
Hide file tree
Showing 133 changed files with 1,187 additions and 1,086 deletions.
5 changes: 4 additions & 1 deletion packages/design/src/components/tooltip/Tooltip.tsx
Expand Up @@ -33,10 +33,12 @@ export interface ITooltipProps {
children: React.ReactElement;

onVisibleChange?: (visible: boolean) => void;

style?: React.CSSProperties;
}

export const Tooltip = forwardRef((props: ITooltipProps, ref: Ref<TooltipRef>) => {
const { children, visible, placement = 'top', title, onVisibleChange } = props;
const { children, visible, placement = 'top', title, onVisibleChange, style } = props;

const { mountContainer } = useContext(ConfigContext);

Expand All @@ -53,6 +55,7 @@ export const Tooltip = forwardRef((props: ITooltipProps, ref: Ref<TooltipRef>) =
showArrow
destroyTooltipOnHide
onVisibleChange={onVisibleChange}
overlayStyle={style}
>
{children}
</RcTooltip>
Expand Down
6 changes: 5 additions & 1 deletion packages/design/src/components/tooltip/index.module.less
Expand Up @@ -8,10 +8,14 @@

display: block;

font-size: var(--font-size-base);
font-size: var(--font-size-xxs);

visibility: visible;

&-no-events {
pointer-events: none;
}

&-hidden {
display: none;
}
Expand Down
Expand Up @@ -195,7 +195,7 @@ export class FunctionNode extends BaseAstNode {
} else {
const arrayValues = transformToValueObject(resultVariantCustom);

resultVariant = new ArrayValueObject({
resultVariant = ArrayValueObject.create({
calculateValueList: arrayValues,
rowCount: arrayValues.length,
columnCount: arrayValues[0]?.length || 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/engine-formula/src/engine/ast-node/lambda-node.ts
Expand Up @@ -69,7 +69,7 @@ export class LambdaNode extends BaseAstNode {

override execute() {
if (this.isEmptyParamFunction()) {
this.setValue(new LambdaValueObjectObject(this, this._interpreter, this._lambdaPrivacyVarKeys));
this.setValue(LambdaValueObjectObject.create(this, this._interpreter, this._lambdaPrivacyVarKeys));
} else {
const children = this.getChildren();
const childrenCount = children.length;
Expand All @@ -79,7 +79,7 @@ export class LambdaNode extends BaseAstNode {

// override async executeAsync() {
// if (this.isEmptyParamFunction()) {
// await this.setValue(new LambdaValueObjectObject(this, this._interpreter, this._lambdaPrivacyVarKeys));
// await this.setValue(LambdaValueObjectObject.create(this, this._interpreter, this._lambdaPrivacyVarKeys));
// } else {
// const children = this.getChildren();
// const childrenCount = children.length;
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-formula/src/engine/ast-node/null-node.ts
Expand Up @@ -28,6 +28,6 @@ export class NullNode extends BaseAstNode {
}

override execute() {
this.setValue(new NullValueObject(0));
this.setValue(NullValueObject.create());
}
}
4 changes: 2 additions & 2 deletions packages/engine-formula/src/engine/ast-node/operator-node.ts
Expand Up @@ -59,11 +59,11 @@ export class OperatorNode extends BaseAstNode {
}

if (object1 == null) {
object1 = new NullValueObject(0);
object1 = NullValueObject.create();
}

if (object2 == null) {
object2 = new NullValueObject(0);
object2 = NullValueObject.create();
}

if (object1.isReferenceObject()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-formula/src/engine/ast-node/prefix-node.ts
Expand Up @@ -60,7 +60,7 @@ export class PrefixNode extends BaseAstNode {

if (this._operatorString === prefixToken.MINUS) {
result = this._functionExecutor!.calculate(
new NumberValueObject(0),
NumberValueObject.create(0),
value as BaseValueObject
) as FunctionVariantType;
} else if (this._operatorString === prefixToken.AT) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-formula/src/engine/ast-node/suffix-node.ts
Expand Up @@ -61,7 +61,7 @@ export class SuffixNode extends BaseAstNode {
}
result = this._functionExecutor!.calculate(
value as BaseValueObject,
new NumberValueObject(100)
NumberValueObject.create(100)
) as FunctionVariantType;

// set number format
Expand Down
Expand Up @@ -21,13 +21,11 @@ import { FormulaAstLRU } from '../../basics/cache-lru';
import type { INumfmtItemMap, IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap } from '../../basics/common';
import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';
import { ObjectClassType } from '../../basics/object-class-type';
import { ArrayValueObject, ValueObjectFactory } from '../value-object/array-value-object';
import { ArrayValueObject, createBooleanValueObjectByRawValue, createNumberValueObjectByRawValue, createStringValueObjectByRawValue, ValueObjectFactory } from '../value-object/array-value-object';
import { type BaseValueObject, ErrorValueObject, type IArrayValueObject } from '../value-object/base-value-object';
import {
BooleanValueObject,
NullValueObject,
NumberValueObject,
StringValueObject,
} from '../value-object/primitive-object';
import { getCellValue } from '../utils/cell';

Expand Down Expand Up @@ -181,7 +179,7 @@ export class BaseReferenceObject extends ObjectClassType {
const cell = this.getCellData(startRow, startColumn);

if (!cell) {
return new NumberValueObject(0, true);
return NumberValueObject.create(0);
}

const cellValueObject = this.getCellValueObject(cell);
Expand Down Expand Up @@ -367,17 +365,17 @@ export class BaseReferenceObject extends ObjectClassType {
getCellValueObject(cell: ICellData) {
const value = getCellValue(cell);
if (ERROR_TYPE_SET.has(value as ErrorType)) {
return new ErrorValueObject(value as ErrorType);
return ErrorValueObject.create(value as ErrorType);
}

if (cell.t === CellValueType.NUMBER) {
return new NumberValueObject(value);
return createNumberValueObjectByRawValue(value);
}
if (cell.t === CellValueType.STRING || cell.t === CellValueType.FORCE_STRING) {
return new StringValueObject(value);
return createStringValueObjectByRawValue(value);
}
if (cell.t === CellValueType.BOOLEAN) {
return new BooleanValueObject(value);
return createBooleanValueObjectByRawValue(value);
}

return ValueObjectFactory.create(value);
Expand Down Expand Up @@ -490,7 +488,7 @@ export class BaseReferenceObject extends ObjectClassType {
}

if (valueObject == null) {
valueObject = new NullValueObject(0);
valueObject = NullValueObject.create();
}

arrayValueList[row][column] = valueObject;
Expand All @@ -506,7 +504,7 @@ export class BaseReferenceObject extends ObjectClassType {
column: startColumn,
};

const arrayValueObject = new ArrayValueObject(arrayValueObjectData);
const arrayValueObject = ArrayValueObject.create(arrayValueObjectData);

useCache && FORMULA_REF_TO_ARRAY_CACHE.set(key, arrayValueObject);

Expand Down Expand Up @@ -539,7 +537,7 @@ export class BaseReferenceObject extends ObjectClassType {
column: 0,
};

return new ArrayValueObject(arrayValueObjectData);
return ArrayValueObject.create(arrayValueObjectData);
}
}

Expand Down Expand Up @@ -594,6 +592,6 @@ export class AsyncArrayObject extends ObjectClassType {
column: 0,
};

return new ArrayValueObject(arrayValueObjectData);
return ArrayValueObject.create(arrayValueObjectData);
}
}
Expand Up @@ -21,7 +21,7 @@ import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../
import { valueObjectCompare } from '../object-compare';
import { compareToken } from '../../../basics/token';

const range = new ArrayValueObject(/*ts*/ `{
const range = ArrayValueObject.create(/*ts*/ `{
Ada;
test1;
test12;
Expand All @@ -31,14 +31,14 @@ const range = new ArrayValueObject(/*ts*/ `{
describe('Test object compare', () => {
describe('Test valueObjectCompare', () => {
it('Range and criteria', () => {
const rangeNumber = new ArrayValueObject(/*ts*/ `{
const rangeNumber = ArrayValueObject.create(/*ts*/ `{
1;
4;
44;
444
}`);

const criteria = new StringValueObject('>40');
const criteria = StringValueObject.create('>40');

const resultObjectValue = transformToValue(valueObjectCompare(rangeNumber, criteria).getArrayValue());
expect(resultObjectValue).toStrictEqual([[false], [false], [true], [true]]);
Expand Down Expand Up @@ -76,16 +76,16 @@ describe('Test object compare', () => {
];

criteriaList.forEach((criteriaValue, i) => {
const criteria = new StringValueObject(criteriaValue);
const criteria = StringValueObject.create(criteriaValue);

const value = transformToValue(valueObjectCompare(range, criteria).getArrayValue());
expect(value).toStrictEqual(result[i]);
});
});

it('String and string', () => {
const str1 = new StringValueObject('a');
const str2 = new StringValueObject('中文');
const str1 = StringValueObject.create('a');
const str2 = StringValueObject.create('中文');

const compareTokenList = [
compareToken.EQUALS,
Expand All @@ -105,8 +105,8 @@ describe('Test object compare', () => {
});

it('String and number', () => {
const str = new StringValueObject('a');
const num = new NumberValueObject(1);
const str = StringValueObject.create('a');
const num = NumberValueObject.create(1);

const compareTokenList = [
compareToken.EQUALS,
Expand All @@ -126,8 +126,8 @@ describe('Test object compare', () => {
});

it('String and boolean', () => {
const str = new StringValueObject('a');
const bool = new BooleanValueObject(true);
const str = StringValueObject.create('a');
const bool = BooleanValueObject.create(true);

const compareTokenList = [
compareToken.EQUALS,
Expand All @@ -147,8 +147,8 @@ describe('Test object compare', () => {
});

it('Number and string', () => {
const num = new NumberValueObject(1);
const str = new StringValueObject('a');
const num = NumberValueObject.create(1);
const str = StringValueObject.create('a');

const compareTokenList = [
compareToken.EQUALS,
Expand All @@ -168,8 +168,8 @@ describe('Test object compare', () => {
});

it('Number and number', () => {
const num1 = new NumberValueObject(1);
const num2 = new NumberValueObject(2);
const num1 = NumberValueObject.create(1);
const num2 = NumberValueObject.create(2);

const compareTokenList = [
compareToken.EQUALS,
Expand All @@ -189,8 +189,8 @@ describe('Test object compare', () => {
});

it('Number and boolean', () => {
const num = new NumberValueObject(1);
const bool = new BooleanValueObject(true);
const num = NumberValueObject.create(1);
const bool = BooleanValueObject.create(true);

const compareTokenList = [
compareToken.EQUALS,
Expand Down
Expand Up @@ -21,7 +21,7 @@ import { BooleanValueObject } from '../../value-object/primitive-object';

describe('Test object cover', () => {
it('Function convertTonNumber', () => {
expect(convertTonNumber(new BooleanValueObject(true)).getValue()).toBe(1);
expect(convertTonNumber(new BooleanValueObject(false)).getValue()).toBe(0);
expect(convertTonNumber(BooleanValueObject.create(true)).getValue()).toBe(1);
expect(convertTonNumber(BooleanValueObject.create(false)).getValue()).toBe(0);
});
});
8 changes: 4 additions & 4 deletions packages/engine-formula/src/engine/utils/array-object.ts
Expand Up @@ -38,7 +38,7 @@ export function expandArrayValueObject(rowCount: number, columnCount: number, va
for (let r = 0; r < rowCount; r++) {
const row = [];
for (let c = 0; c < columnCount; c++) {
const v = (valueObject as ArrayValueObject).getRealValue(0, c) as BaseValueObject || (defaultValue ?? new NullValueObject(0));
const v = (valueObject as ArrayValueObject).getRealValue(0, c) as BaseValueObject || (defaultValue ?? NullValueObject.create());
row.push(v);
}
result.push(row);
Expand All @@ -47,7 +47,7 @@ export function expandArrayValueObject(rowCount: number, columnCount: number, va
for (let r = 0; r < rowCount; r++) {
const row = [];
for (let c = 0; c < columnCount; c++) {
const v = (valueObject as ArrayValueObject).getRealValue(r, 0) as BaseValueObject || (defaultValue ?? new NullValueObject(0));
const v = (valueObject as ArrayValueObject).getRealValue(r, 0) as BaseValueObject || (defaultValue ?? NullValueObject.create());
row.push(v);
}
result.push(row);
Expand All @@ -56,7 +56,7 @@ export function expandArrayValueObject(rowCount: number, columnCount: number, va
for (let r = 0; r < rowCount; r++) {
const row = [];
for (let c = 0; c < columnCount; c++) {
const v = (valueObject as ArrayValueObject).getRealValue(r, c) as BaseValueObject || (defaultValue ?? new NullValueObject(0));
const v = (valueObject as ArrayValueObject).getRealValue(r, c) as BaseValueObject || (defaultValue ?? NullValueObject.create());
row.push(v);
}
result.push(row);
Expand Down Expand Up @@ -90,5 +90,5 @@ export function createNewArray(
column: -1,
};

return new ArrayValueObject(arrayValueObjectData);
return ArrayValueObject.create(arrayValueObjectData);
}
7 changes: 3 additions & 4 deletions packages/engine-formula/src/engine/utils/object-compare.ts
Expand Up @@ -16,7 +16,7 @@

import { compareToken } from '../../basics/token';
import type { ArrayValueObject } from '../value-object/array-value-object';
import { ValueObjectFactory } from '../value-object/array-value-object';
import { createBooleanValueObjectByRawValue, ValueObjectFactory } from '../value-object/array-value-object';
import type { BaseValueObject } from '../value-object/base-value-object';
import { BooleanValueObject } from '../value-object/primitive-object';
import { expandArrayValueObject } from './array-object';
Expand Down Expand Up @@ -68,7 +68,6 @@ export function valueObjectCompare(range: BaseValueObject, criteria: BaseValueOb
* Find the Boolean intersection of two ArrayValueObjects
* @param valueObject1
* @param valueObject2
* @returns
*/
export function booleanObjectIntersection(valueObject1: BaseValueObject, valueObject2: BaseValueObject) {
const maxRowLength = Math.max(valueObject1.isArray() ? (valueObject1 as ArrayValueObject).getRowCount() : 1, valueObject2.isArray() ? (valueObject2 as ArrayValueObject).getRowCount() : 1);
Expand All @@ -89,9 +88,9 @@ export function booleanObjectIntersection(valueObject1: BaseValueObject, valueOb
}

if (valueObject1?.isBoolean() && valueObject2?.isBoolean()) {
return new BooleanValueObject(valueObject1.getValue() && valueObject2.getValue());
return createBooleanValueObjectByRawValue(valueObject1.getValue() && valueObject2.getValue());
}

return new BooleanValueObject(false);
return BooleanValueObject.create(false);
});
}
2 changes: 1 addition & 1 deletion packages/engine-formula/src/engine/utils/object-covert.ts
Expand Up @@ -23,5 +23,5 @@ export function convertTonNumber(valueObject: BaseValueObject) {
if (currentValue) {
result = 1;
}
return new NumberValueObject(result, true);
return NumberValueObject.create(result);
}
Expand Up @@ -19,7 +19,7 @@ import { describe, expect, it } from 'vitest';
import { ArrayValueObject, transformToValueObject } from '../array-value-object';

describe('arrayValueObject abs method test', () => {
const originArrayValueObject = new ArrayValueObject({
const originArrayValueObject = ArrayValueObject.create({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false],
[0, '100', '2.34', 'test', -3],
Expand Down
Expand Up @@ -21,7 +21,7 @@ import { ArrayValueObject, transformToValueObject } from '../array-value-object'
describe('arrayValueObject acos method test', () => {
describe('acos', () => {
it('origin nm, param nm', () => {
const tanArrayValueObject = new ArrayValueObject({
const tanArrayValueObject = ArrayValueObject.create({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false],
[0, '100', '2.34', 'test', -3],
Expand Down
Expand Up @@ -21,7 +21,7 @@ import { ArrayValueObject, transformToValueObject } from '../array-value-object'
describe('arrayValueObject acosh method test', () => {
describe('acosh', () => {
it('origin nm, param nm', () => {
const tanArrayValueObject = new ArrayValueObject({
const tanArrayValueObject = ArrayValueObject.create({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false],
[0, '100', '2.34', 'test', -3],
Expand Down

0 comments on commit 9e63af7

Please sign in to comment.