Skip to content

Commit

Permalink
fix(formula): fix progress bar not loaded (#3790)
Browse files Browse the repository at this point in the history
Co-authored-by: Dushusir <1414556676@qq.com>
Co-authored-by: DR-Univer <wbfsa@qq.com>
  • Loading branch information
3 people authored Oct 26, 2024
1 parent 1ab5eff commit 065dadc
Show file tree
Hide file tree
Showing 38 changed files with 458 additions and 717 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: 🚀 Deploy to Vercel
uses: amondnet/vercel-action@v25
if: failure()
id: vercel-e2e-report
id: vercel-e2e-report # we only need to upload to Vercel if this CI fails
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.ORG_ID }}
Expand Down
3 changes: 0 additions & 3 deletions packages-experimental/uniui/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
IMessageService,
INotificationService,
IPlatformService,
IProgressService,
IShortcutService,
ISidebarService,
IUIController,
Expand All @@ -61,7 +60,6 @@ import {
MenuManagerService,
MenuService,
PlatformService,
ProgressService,
SharedController,
ShortcutPanelController,
ShortcutPanelService,
Expand Down Expand Up @@ -127,7 +125,6 @@ export class UniverUniUIPlugin extends Plugin {
[IBeforeCloseService, { useClass: DesktopBeforeCloseService }],
[ILocalFileService, { useClass: DesktopLocalFileService }],
[ICanvasPopupService, { useClass: CanvasPopupService }],
[IProgressService, { useClass: ProgressService }],
[CanvasFloatDomService],
[IUIController, {
useFactory: () => this._injector.createInstance(UniverUniUIController, this._config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle, CloseSingle, FxSingle } from '@univerjs/icons';
import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { IEditorBridgeService, IFormulaEditorManagerService, useActiveWorkbook } from '@univerjs/sheets-ui';
import { KeyCode, ProgressBar } from '@univerjs/ui';
import { KeyCode } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useCallback, useLayoutEffect, useState } from 'react';
import { EMPTY, merge, switchMap } from 'rxjs';
Expand Down Expand Up @@ -230,7 +230,6 @@ export function FormulaBar() {
<CheckMarkSingle />
</span>
</div>
<ProgressBar barColor={progressBarColor} />
</div>
);
}
43 changes: 26 additions & 17 deletions packages/core/src/shared/r-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ import type { IUnitRange } from '../sheets/typedef';
import KDBush from 'kdbush';
import RBush from 'rbush';

type StringOrNumber = string | number;

export interface IRTreeItem extends IUnitRange {
id: string;
id: StringOrNumber;
}

interface IRBushItem extends BBox {
id: string;
id: StringOrNumber;
}

interface IRdTreeItem {
x: number;
y: number;
ids: Set<string>;
ids: Set<StringOrNumber>;
}

export interface IRTreeData {
Expand All @@ -43,7 +45,7 @@ export class RTree {
private _tree: Map<string, Map<string, RBush<IRBushItem>>> = new Map();

// unitId -> subUnitId -> row -> column -> ids
private _oneCellCache = new Map<string, Map<string, Map<number, Map<number, Set<string>>>>>();
private _oneCellCache = new Map<string, Map<string, Map<number, Map<number, Set<StringOrNumber>>>>>();

private _kdTree: Map<string, Map<string, { tree: KDBush; items: IRdTreeItem[] } | undefined>> = new Map();

Expand All @@ -68,7 +70,7 @@ export class RTree {
return this._tree.get(unitId)!.get(subUnitId)!;
}

private _getOneCellCache(unitId: string, subUnitId: string, row: number, column: number): Set<string> {
private _getOneCellCache(unitId: string, subUnitId: string, row: number, column: number): Set<StringOrNumber> {
if (!this._oneCellCache.has(unitId)) {
this._oneCellCache.set(unitId, new Map());
}
Expand All @@ -85,7 +87,7 @@ export class RTree {
return this._oneCellCache.get(unitId)!.get(subUnitId)!.get(row)!.get(column)!;
}

private _removeOneCellCache(unitId: string, subUnitId: string, row: number, column: number, id: string) {
private _removeOneCellCache(unitId: string, subUnitId: string, row: number, column: number, id: StringOrNumber) {
const unitCache = this._oneCellCache.get(unitId);
if (!unitCache) return;

Expand All @@ -101,11 +103,11 @@ export class RTree {
cellCache.delete(id);
}

private _insertOneCellCache(unitId: string, subUnitId: string, row: number, column: number, id: string) {
private _insertOneCellCache(unitId: string, subUnitId: string, row: number, column: number, id: StringOrNumber) {
this._getOneCellCache(unitId, subUnitId, row, column).add(id);
}

private _getRdTreeItems(map: Map<number, Map<number, Set<string>>>) {
private _getRdTreeItems(map: Map<number, Map<number, Set<StringOrNumber>>>) {
const items: IRdTreeItem[] = [];

for (const [y, innerMap] of map) {
Expand All @@ -121,7 +123,7 @@ export class RTree {
return items;
}

private _searchByOneCellCache(search: IUnitRange): string[] {
private _searchByOneCellCache(search: IUnitRange): StringOrNumber[] {
const { unitId, sheetId: subUnitId, range } = search;
const { startRow, startColumn, endRow, endColumn } = range;
const searchObject = this._kdTree.get(unitId)?.get(subUnitId);
Expand All @@ -133,7 +135,7 @@ export class RTree {

const indexes = tree.range(startColumn, startRow, endColumn, endRow);

const result: string[] = [];
const result: StringOrNumber[] = [];

for (const index of indexes) {
const item = items[index];
Expand Down Expand Up @@ -221,32 +223,39 @@ export class RTree {
}
}

search(search: IUnitRange): string[] {
search(search: IUnitRange): StringOrNumber[] {
const { unitId, sheetId: subUnitId, range } = search;

const results: string[] = [];
const results: StringOrNumber[] = [];

if (this._enableOneCellCache && this._enableOneCellCache) {
results.push(...this._searchByOneCellCache(search));
const oneCellResults = this._searchByOneCellCache(search);
for (const result of oneCellResults) {
results.push(result);
}
}

const tree = this._tree.get(unitId)?.get(subUnitId);
if (!tree) {
return results;
}

results.push(...(tree.search({
const searchData = tree.search({
minX: range.startColumn,
minY: range.startRow,
maxX: range.endColumn,
maxY: range.endRow,
}) as unknown as IRTreeItem[]).map((item) => item.id));
}) as unknown as IRTreeItem[];

for (const item of searchData) {
results.push(item.id);
}

return results;
}

bulkSearch(searchList: IUnitRange[]): Set<string> {
const result = new Set<string>();
bulkSearch(searchList: IUnitRange[]): Set<StringOrNumber> {
const result = new Set<StringOrNumber>();
for (const search of searchList) {
const items = this.search(search);
for (const item of items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { CommandType } from '@univerjs/core';

export interface ISetFormulaCalculationStartMutation extends IFormulaDirtyData {
options: Nullable<IExecutionOptions>;
forceCalculation: boolean;
}
/**
* TODO: @DR-Univer
Expand Down
29 changes: 7 additions & 22 deletions packages/engine-formula/src/controller/calculate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import type { ICommandInfo, IUnitRange } from '@univerjs/core';
import type { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFormulaData } from '../basics/common';
import type { ICommandInfo } from '@univerjs/core';
import type { IFormulaData } from '../basics/common';

import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import type { IAllRuntimeData } from '../services/runtime.service';
import type { IFormulaDirtyData } from '../services/current-data.service';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { convertRuntimeToUnitData } from '../basics/runtime';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
Expand All @@ -33,7 +33,7 @@ import {
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
import { FormulaDataModel } from '../models/formula-data.model';
import { CalculateFormulaService } from '../services/calculate-formula.service';
import { FormulaExecutedStateType } from '../services/runtime.service';
import { FormulaExecutedStateType, type IAllRuntimeData } from '../services/runtime.service';

export class CalculateController extends Disposable {
constructor(
Expand All @@ -49,8 +49,6 @@ export class CalculateController extends Disposable {
private _initialize(): void {
this._commandExecutedListener();
this._initialExecuteFormulaListener();

this._initialExecuteFormulaProcessListener();
}

private _commandExecutedListener() {
Expand All @@ -66,13 +64,7 @@ export class CalculateController extends Disposable {
} else if (command.id === SetFormulaCalculationStartMutation.id) {
const params = command.params as ISetFormulaCalculationStartMutation;

if (params.forceCalculation === true) {
this._calculate(true);
} else {
const { dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, clearDependencyTreeCache } = params;

this._calculate(false, dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, clearDependencyTreeCache);
}
this._calculate(params);
} else if (command.id === SetArrayFormulaDataMutation.id) {
const params = command.params as ISetArrayFormulaDataMutationParams;

Expand All @@ -90,14 +82,9 @@ export class CalculateController extends Disposable {
}

private async _calculate(
forceCalculate: boolean = false,
dirtyRanges: IUnitRange[] = [],
dirtyNameMap: IDirtyUnitSheetNameMap = {},
dirtyDefinedNameMap: IDirtyUnitSheetDefinedNameMap = {},
dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {},
dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {},
clearDependencyTreeCache: IDirtyUnitSheetNameMap = {}
formulaDirtyData: Partial<IFormulaDirtyData>
) {
const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {} } = formulaDirtyData;
if (
dirtyRanges.length === 0 &&
Object.keys(dirtyNameMap).length === 0 &&
Expand Down Expand Up @@ -159,9 +146,7 @@ export class CalculateController extends Disposable {
}
);
});
}

private _initialExecuteFormulaProcessListener() {
/**
* Assignment operation after formula calculation.
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/engine-formula/src/controller/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import type { Ctor } from '@univerjs/core';
import type { BaseFunction } from '../functions/base-function';
import type { IFunctionNames } from '../basics/function';
import type { BaseFunction } from '../functions/base-function';

export const PLUGIN_CONFIG_KEY = 'engine-formula.config';

Expand All @@ -25,6 +25,12 @@ export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverEngineFormulaConfig {
notExecuteFormula?: boolean;
function?: Array<[Ctor<BaseFunction>, IFunctionNames]>;

/**
* The formula calculation quantity interval for waiting for the main thread message in the worker. Each time the formula calculates the `intervalCount` quantity, it will receive a main thread message to support stopping the calculation. Default is 500
*/
intervalCount?: number;

}

export const defaultPluginConfig: IUniverEngineFormulaConfig = {};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
DEFAULT_TOKEN_TYPE_PARAMETER,
DEFAULT_TOKEN_TYPE_ROOT,
} from '../../basics/token-type';
import { deserializeRangeWithSheet, isReferenceStringWithEffectiveColumn, replaceRefPrefixString, serializeRangeToRefString } from '../utils/reference';
import { isReferenceStringWithEffectiveColumn, replaceRefPrefixString, serializeRangeToRefString } from '../utils/reference';
import { deserializeRangeWithSheetWithCache } from '../utils/reference-cache';
import { generateStringWithSequence, sequenceNodeType } from '../utils/sequence';
import { LexerNode } from './lexer-node';

Expand Down Expand Up @@ -281,7 +282,7 @@ export class LexerTreeBuilder extends Disposable {

if (node.nodeType === sequenceNodeType.REFERENCE) {
const { token, endIndex } = node;
const sequenceGrid = deserializeRangeWithSheet(token);
const sequenceGrid = deserializeRangeWithSheetWithCache(token);
if (sequenceGrid == null) {
continue;
}
Expand Down Expand Up @@ -344,7 +345,7 @@ export class LexerTreeBuilder extends Disposable {

const { token } = node;

const sequenceGrid = deserializeRangeWithSheet(token);
const sequenceGrid = deserializeRangeWithSheetWithCache(token);

const { sheetName, unitId: sequenceUnitId } = sequenceGrid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { NodeType } from './node-type';
interface IAstNodeNodeJson {
token: string;
children?: IAstNodeNodeJson[];
nodeType: string;
nodeType: number;
}

export type LambdaPrivacyVarType = Map<string, Nullable<BaseAstNode>>;
Expand Down
26 changes: 13 additions & 13 deletions packages/engine-formula/src/engine/ast-node/node-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
*/

export enum NodeType {
REFERENCE = 'ReferenceNode',
VALUE = 'ValueNode',
OPERATOR = 'OperatorNode',
FUNCTION = 'FunctionNode',
LAMBDA = 'LambdaNode',
LAMBDA_PARAMETER = 'LambdaNodeParameter',
ERROR = 'ErrorNode',
BASE = 'Base',
ROOT = 'Root',
UNION = 'UnionNode',
PREFIX = 'PrefixNode',
SUFFIX = 'SuffixNode',
NULL = 'NullNode',
REFERENCE = 1,
VALUE = 2,
OPERATOR = 3,
FUNCTION = 4,
LAMBDA = 5,
LAMBDA_PARAMETER = 6,
ERROR = 7,
BASE = 8,
ROOT = 9,
UNION = 10,
PREFIX = 11,
SUFFIX = 12,
NULL = 13,
}

export const NODE_ORDER_MAP = new Map([
Expand Down
Loading

0 comments on commit 065dadc

Please sign in to comment.