Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(formula): array formula border

Dushusir364a66565d58
diff --git a/packages/base-render/src/Layer.ts b/packages/base-render/src/Layer.ts
index ee79a7cab2..fab6ae3636 100644
--- a/packages/base-render/src/Layer.ts
+++ b/packages/base-render/src/Layer.ts
@@ -101,15 +101,18 @@ export class Layer {
const allObjects = this.getObjects();
const allObjectsLength = allObjects.length;
- for (let i = allObjectsLength; i >= 0; i--) {
+ for (let i = allObjectsLength - 1; i >= 0; i--) {
let o: BaseObject | string = allObjects[i];
const objectsLength = objects.length;
+
+ if (objectsLength === 0) break;
+
for (let j = 0; j < objectsLength; j++) {
const object = objects[j];
o = object instanceof BaseObject ? o : (o as BaseObject).oKey;
if (o === object) {
allObjects.splice(i, 1);
- objects.splice(j, 1);
+ // objects.splice(j, 1);
break;
}
}
diff --git a/packages/core/src/Const/CONST.ts b/packages/core/src/Const/CONST.ts
index 8d6b10cc4a..e063dcad46 100644
--- a/packages/core/src/Const/CONST.ts
+++ b/packages/core/src/Const/CONST.ts
@@ -72,7 +72,7 @@ export const DEFAULT_WORKBOOK: IWorkbookConfig = {
*/
export const DEFAULT_WORKSHEET: IWorksheetConfig = {
type: SheetTypes.GRID,
- name: '',
+ name: 'Sheet1',
id: 'sheet-01',
tabColor: '',
hidden: BooleanNumber.FALSE,
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
index b7c0b5c8b0..a74cbd0c36 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
@@ -110,7 +110,7 @@ export class FormulaActionExtension extends BaseActionExtension<FormulaPlugin> {
}
if (arrayFormulaData) {
- this._plugin.getFormulaController().setArrayFormulaData(arrayFormulaData);
+ this._plugin.getFormulaController().addArrayFormulaData(arrayFormulaData);
}
const sheetIds = Object.keys(sheetData);
diff --git a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts b/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
index 82be5a050a..8a94c59933 100644
--- a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
@@ -1,6 +1,7 @@
import { PLUGIN_NAMES, Workbook } from '@univer/core';
-import { Path, Scene } from '@univer/base-render';
+import { Rect, Scene } from '@univer/base-render';
import { SheetPlugin, SheetView } from '@univer/base-sheets';
+import { ArrayFormulaDataType } from '@univer/base-formula-engine';
import { ArrayFormLine, ArrayFormLineModel, IArrayFormLineRange } from '../Model/ArrayFormLineModel';
import { FormulaPlugin } from '../FormulaPlugin';
@@ -11,6 +12,7 @@ enum ARRAY_FORM_LINE_MANAGER_KEY {
right = '__ArrayFormLineRightControl__',
}
+const LINE_COLOR = '#3969b9';
/**
* Ant Line Controller
*/
@@ -58,11 +60,11 @@ export class ArrayFormLineControl {
}
/**
- * Create A Sheet ArrayFormLine Path
+ * Create A Sheet ArrayFormLine Rect
* @param sheetId
* @param range
*/
- private _createArrayFormLinePathBySheetIdAndRange(sheetId: string, range: IArrayFormLineRange): Path[] {
+ private _createArrayFormLinePathBySheetIdAndRange(sheetId: string, range: IArrayFormLineRange): Rect[] {
let workbook = this.getWorkBook();
let worksheet = workbook.getSheetBySheetId(sheetId);
@@ -94,49 +96,52 @@ export class ArrayFormLineControl {
offsetLeft += columnManager.getColumnWidth(i);
}
+ // TODO: Gradient shadows
+ // dark gray #ebebeb
+ // light gray #fefefe
return [
- new Path(ARRAY_FORM_LINE_MANAGER_KEY.left, {
- stroke: 'yellow',
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.left, {
+ stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
top: offsetTop + columnTitleHeight,
height: totalHeight,
- width: 1,
+ width: 0.1,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Path(ARRAY_FORM_LINE_MANAGER_KEY.top, {
- stroke: 'green',
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.top, {
+ stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
- top: offsetTop + columnTitleHeight + totalHeight,
- height: 1,
+ top: offsetTop + columnTitleHeight,
+ height: 0.1,
width: totalWidth,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Path(ARRAY_FORM_LINE_MANAGER_KEY.right, {
- stroke: 'yellow',
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.right, {
+ stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth + totalWidth,
top: offsetTop + columnTitleHeight,
height: totalHeight,
- width: 1,
+ width: 0.1,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Path(ARRAY_FORM_LINE_MANAGER_KEY.bottom, {
- stroke: 'green',
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.bottom, {
+ stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
top: offsetTop + columnTitleHeight + totalHeight,
- height: 1,
+ height: 0.1,
width: totalWidth,
shadowOffsetX: 10,
shadowOffsetY: 10,
@@ -178,7 +183,6 @@ export class ArrayFormLineControl {
let arrayFormLine = arrayFormLineList[j];
let antPath = this._createArrayFormLinePathBySheetIdAndRange(arrayFormLineModel.getSheetId(), arrayFormLine.getRange());
arrayFormLine.setPath(antPath);
- console.log(antPath);
this.getSheetViewScene().addObjects(antPath);
}
}
@@ -229,6 +233,21 @@ export class ArrayFormLineControl {
this._makeUpdateSceneArrayFormLinePath();
}
+ refreshArrayFormLine(value: ArrayFormulaDataType) {
+ this._arrayFormLineModelList.length = 0;
+
+ Object.keys(value).forEach((sheetId) => {
+ const arrayFormula = value[sheetId];
+ arrayFormula.forValue((r, c, v) => {
+ const arrayFormLineModel = new ArrayFormLineModel(sheetId);
+ arrayFormLineModel.addArrayFormLine(new ArrayFormLine(v));
+ this._arrayFormLineModelList.push(arrayFormLineModel);
+ });
+ });
+
+ this._makeUpdateSceneArrayFormLinePath();
+ }
+
/**
* Return SheetView
* @returns
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
index 1d070ff942..310b38f8d9 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
@@ -1,6 +1,6 @@
import { FormulaEnginePlugin, IInterpreterDatasetConfig, SheetDataType, UnitDataType, SheetNameMapType, ArrayFormulaDataType } from '@univer/base-formula-engine';
import { SheetPlugin } from '@univer/base-sheets';
-import { PLUGIN_NAMES, SheetContext } from '@univer/core';
+import { ObjectMatrix, PLUGIN_NAMES, SheetContext } from '@univer/core';
import { FORMULA_PLUGIN_NAME, CONFIG } from '../Basic';
import { IFormulaConfig } from '../Basic/Interfaces/IFormula';
import { FormulaPlugin } from '../FormulaPlugin';
@@ -10,7 +10,7 @@ import { FormulaLabel } from '../View/UI/FormulaLabel';
export class FormulaController {
private _formulaDataModel: FormulaDataModel;
- private _arrayFormulaData: ArrayFormulaDataType;
+ private _arrayFormulaData: ArrayFormulaDataType = {};
private _formulaEngine: FormulaEnginePlugin;
@@ -148,7 +148,17 @@ export class FormulaController {
return this._arrayFormulaData;
}
- setArrayFormulaData(value: ArrayFormulaDataType) {
- this._arrayFormulaData = value;
+ addArrayFormulaData(value: ArrayFormulaDataType) {
+ Object.keys(value).forEach((sheetId) => {
+ const arrayFormula = value[sheetId];
+ if (!this._arrayFormulaData[sheetId]) {
+ this._arrayFormulaData[sheetId] = new ObjectMatrix();
+ }
+ arrayFormula.forValue((r, c, v) => {
+ this._arrayFormulaData[sheetId].setValue(r, c, v);
+ });
+ });
+ const arrayFormLineControl = this._plugin.getArrayFormLineControl();
+ arrayFormLineControl.refreshArrayFormLine(this._arrayFormulaData);
}
}
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index dd690164c6..f115592b08 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -68,15 +68,33 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
this._arrayFormLineControl = new ArrayFormLineControl(this);
- this._arrayFormLineControl.addArrayFormLineToSheet(
- {
- startRow: 1,
- endRow: 3,
- startColumn: 1,
- endColumn: 3,
- },
- 'sheet-0004'
- );
+ // this._arrayFormLineControl.addArrayFormLineToSheet(
+ // {
+ // startRow: 1,
+ // endRow: 3,
+ // startColumn: 1,
+ // endColumn: 3,
+ // },
+ // 'sheet-0004'
+ // );
+ // this._arrayFormLineControl.addArrayFormLineToSheet(
+ // {
+ // startRow: 4,
+ // endRow: 5,
+ // startColumn: 4,
+ // endColumn: 5,
+ // },
+ // 'sheet-0004'
+ // );
+ // this._arrayFormLineControl.addArrayFormLineToSheet(
+ // {
+ // startRow: 5,
+ // endRow: 6,
+ // startColumn: 5,
+ // endColumn: 6,
+ // },
+ // 'sheet-0003'
+ // );
}
onMapping(IOC: IOCContainer): void {}
@@ -119,4 +137,8 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
getFormulaPromptController() {
return this._formulaPromptController;
}
+
+ getArrayFormLineControl() {
+ return this._arrayFormLineControl;
+ }
}
diff --git a/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts b/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts
index c832bed057..0d6ec7a39c 100644
--- a/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts
+++ b/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts
@@ -1,4 +1,4 @@
-import { Path } from '@univer/base-render';
+import { Rect } from '@univer/base-render';
import { IRangeData, Nullable } from '@univer/core';
export interface IArrayFormLineRange extends IRangeData {
@@ -8,7 +8,7 @@ export interface IArrayFormLineRange extends IRangeData {
export class ArrayFormLine {
private _range: IArrayFormLineRange;
- private _rect: Nullable<Path[]>;
+ private _rect: Nullable<Rect[]>;
constructor(range: IArrayFormLineRange) {
this._range = range;
@@ -18,11 +18,11 @@ export class ArrayFormLine {
return this._range;
}
- getPath(): Nullable<Path[]> {
+ getPath(): Nullable<Rect[]> {
return this._rect;
}
- setPath(rect: Path[]): void {
+ setPath(rect: Rect[]): void {
this._rect = rect;
}