Skip to content

Commit

Permalink
chore: chore
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Sep 11, 2024
1 parent 432494e commit c0c2bf1
Show file tree
Hide file tree
Showing 13 changed files with 58,410 additions and 913,510 deletions.
23,798 changes: 23,792 additions & 6 deletions examples/src/data/sheets/demo/default-workbook-data-demo.ts

Large diffs are not rendered by default.

948,002 changes: 34,581 additions & 913,421 deletions examples/src/data/sheets/demo/testdata.json

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions packages/core/src/sheets/view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ export interface IRowFilteredInterceptor {
export class SheetViewModel extends Disposable {
private _cellContentInterceptor: Nullable<ICellContentInterceptor> = null;
private _rowFilteredInterceptor: Nullable<IRowFilteredInterceptor> = null;
_commandService: any;
_univerInstanceService: any;

constructor(
private readonly getRawCell: (row: number, col: number) => Nullable<ICellData>
) {
super();
window.vm = this;
}

override dispose(): void {
Expand All @@ -72,22 +69,9 @@ export class SheetViewModel extends Disposable {
this._rowFilteredInterceptor = null;
}

// _cellDataCacheMap: Map<number, Map<number, Nullable<ICellDataForSheetInterceptor>>> = new Map();
getCell(row: number, col: number): Nullable<ICellDataForSheetInterceptor> {
if (this._cellContentInterceptor) {
return this._cellContentInterceptor.getCell(row, col);

// if (this._cellDataCacheMap.get(row)) {
// if (!this._cellDataCacheMap.get(row)?.get(col)) {
// this._cellDataCacheMap.get(row)?.set(col, this._cellContentInterceptor.getCell(row, col));
// // return this._cellDataCacheMap.get(row)?.get(col);
// }
// } else {
// this._cellDataCacheMap.set(row, new Map());
// this._cellDataCacheMap.get(row)?.set(col, this._cellContentInterceptor.getCell(row, col));
// // return this._cellDataCacheMap.get(row)?.get(col);
// }
// return this._cellDataCacheMap.get(row)?.get(col);
}

return this.getRawCell(row, col);
Expand Down
38 changes: 16 additions & 22 deletions packages/core/src/sheets/worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Worksheet {
protected _columnManager: ColumnManager;

protected readonly _viewModel: SheetViewModel;
private _filteredRowCacheMap: Map<number, boolean> = new Map();

constructor(
public readonly unitId: string,
Expand All @@ -54,8 +55,6 @@ export class Worksheet {
this._viewModel = new SheetViewModel((row, col) => this.getCellRaw(row, col));
this._rowManager = new RowManager(this._snapshot, this._viewModel, rowData);
this._columnManager = new ColumnManager(this._snapshot, columnData);

window.ws = this; // for debug
}

/**
Expand Down Expand Up @@ -240,7 +239,6 @@ export class Worksheet {
return null;
}

_cellDataCacheMap: Map<number, Map<number, Nullable<ICellDataForSheetInterceptor>>> = new Map();
/**
* Get cellData, includes cellData, customRender, markers, dataValidate, etc.
*
Expand All @@ -255,18 +253,8 @@ export class Worksheet {
if (row < 0 || col < 0) {
return null;
}

return this._viewModel.getCell(row, col);
// if (this._cellDataCacheMap.get(row)) {
// if (!this._cellDataCacheMap.get(row)?.get(col)) {
// this._cellDataCacheMap.get(row)?.set(col, this._viewModel.getCell(row, col));
// // return this._cellDataCacheMap.get(row)?.get(col);
// }
// } else {
// this._cellDataCacheMap.set(row, new Map());
// this._cellDataCacheMap.get(row)?.set(col, this._viewModel.getCell(row, col));
// // return this._cellDataCacheMap.get(row)?.get(col);
// }
// return this._cellDataCacheMap.get(row)?.get(col);
}

getCellRaw(row: number, col: number): Nullable<ICellData> {
Expand Down Expand Up @@ -475,25 +463,31 @@ export class Worksheet {
return this.getRowManager().getRowHeight(row);
}

_filteredRowCacheMap: Map<number, boolean> = new Map();
/**
* Get if the row is visible. It may be affected by features like filter and view.
* @param row the row index
* @returns if the row in visible to the user
* Row is filtered out, that means this row is invisible.
* @param row
* @returns {boolean}
*/
getRowVisible(row: number): boolean {
isRowFiltered(row: number): boolean {
if (!this._filteredRowCacheMap.has(row)) {
this._filteredRowCacheMap.set(row, this._viewModel.getRowFiltered(row));
}
const filtered = this._filteredRowCacheMap.get(row);
if (filtered) return false;
return this.getRowRawVisible(row);
return !!this._filteredRowCacheMap.get(row);
}

clearFilteredRowCacheMap() {
this._filteredRowCacheMap.clear();
}

/**
* Get if the row is visible. It may be affected by features like filter and view.
* @param row the row index
* @returns if the row in visible to the user
*/
getRowVisible(row: number): boolean {
return !this.isRowFiltered(row) && this.getRowRawVisible(row);
}

/**
* Get if the row does not have `hidden` property. This value won't affected by features like filter and view.
* @param row the row index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class Background extends SheetExtension {
return (this.parent as Spreadsheet)?.isPrinting ? this.PRINTING_Z_INDEX : this.Z_INDEX;
}

//eslint-disable-next-line max-lines-per-function
override draw(
ctx: UniverRenderingContext,
_parentScale: IScale,
Expand All @@ -71,11 +70,8 @@ export class Background extends SheetExtension {
const backgroundCache = background[rgb];
ctx.fillStyle = rgb || getColor([255, 255, 255])!;

// console.group('backgroundext');
const backgroundPaths = new Path2D();
// let count = 0;
backgroundCache.forValue((rowIndex, columnIndex) => {
// checkOutOfViewBound = false;
if (!checkOutOfViewBound && !inViewRanges(viewRanges, rowIndex, columnIndex)) {
return true;
}
Expand Down Expand Up @@ -104,9 +100,6 @@ export class Background extends SheetExtension {
if (!visibleRow || !visibleCol) return true;
}

// console.log('background', rowIndex, columnIndex);
// count++;

// For merged cells, and the current cell is the top-left cell in the merged region.
if (isMergedMainCell) {
startY = mergeInfo.startY;
Expand All @@ -122,8 +115,6 @@ export class Background extends SheetExtension {
backgroundPaths.rect(startXPrecise, startYPrecise, endXPrecise - startXPrecise, endYPrecise - startYPrecise);
});
ctx.fill(backgroundPaths);
// if (count > 500) debugger;
// console.groupEnd('backgroundext');
};

Object.keys(background).forEach(renderBGByCell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ColumnHeaderLayout extends SheetExtension {
curColSpecCfg = columnsCfg[colIndex] as IColumnStyleCfg & { text: string };
mergeWithSpecCfg = { ...this.headerStyle, ...curColSpecCfg };
} else {
mergeWithSpecCfg = { ...this.headerStyle, text: colIndex };
mergeWithSpecCfg = { ...this.headerStyle, text: numberToABC(colIndex) };
}
const specStyle = Object.keys(curColSpecCfg || {}).length > 1; // if cfg have more keys than 'text', means there would be special style config for this column.
return [mergeWithSpecCfg, specStyle] as [IAColumnCfgObj, boolean];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ export class Font extends SheetExtension {
// so that the divide will be aligned when the skeleton is calculated.
const overflowRectangle = overflowCache.getValue(row, column);

if (row === 150 && column === 55) {
debugger;
}
const isOverflow = !(wrapStrategy === WrapStrategy.WRAP && !overflowRectangle && vertexAngle === 0);
if (isOverflow) {
const contentSize = getDocsSkeletonPageSize(documentSkeleton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class Marker extends SheetExtension {
cellData = worksheet.getCell(mainCell.row, mainCell.col);
}

if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) {
return true;
}

if (cellInfo.isMerged || cellInfo.isMergedMainCell) {
const rangeStr = stringifyRange(mergeInfo);
if (mergeCellRendered.has(rangeStr)) {
Expand Down
20 changes: 9 additions & 11 deletions packages/engine-render/src/components/sheets/sheet-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import type {
IRange,
IRowAutoHeightInfo,
IRowData,
ISelectionCell,
IRowRange,
ISelectionCell,
ISelectionCellWithMergeInfo,
ISize,
IStyleBase,
Expand Down Expand Up @@ -265,7 +265,6 @@ export class SpreadsheetSkeleton extends Skeleton {

this._updateLayout();
this._initContextListener();
window.sk = this;
// this.updateDataMerge();
}

Expand Down Expand Up @@ -1626,16 +1625,15 @@ export class SpreadsheetSkeleton extends Skeleton {
}

// Calculate the text length for overflow situations, focusing on the leftmost column within the visible range.
for (let c = Math.max(startColumn - 20, 0); c < startColumn; c++) {
// for (let c = 0; c < startColumn; c++) {
// for (let c = Math.max(startColumn - 20, 0); c < startColumn; c++) {
for (let c = 0; c < startColumn; c++) {
this._setStylesCache(r, c, { cacheItem: { bg: false, border: false } });
// if (r === 150 && c === 55) debugsger;
}
if (endColumn === 0) continue;

// Calculate the text length for overflow situations, focusing on the rightmost column within the visible range.
for (let c = endColumn + 1; c < Math.min(endColumn + 20, columnWidthAccumulation.length); c++) {
// for (let c = endColumn + 1; c < columnWidthAccumulation.length; c++) {
// for (let c = endColumn + 1; c < Math.min(endColumn + 20, columnWidthAccumulation.length); c++) {
for (let c = endColumn + 1; c < columnWidthAccumulation.length; c++) {
this._setStylesCache(r, c, { cacheItem: { bg: false, border: false } });
}
}
Expand Down Expand Up @@ -1705,17 +1703,17 @@ export class SpreadsheetSkeleton extends Skeleton {
const hidden = this.worksheet.getColVisible(col) === false || this.worksheet.getRowVisible(row) === false;
if (hidden) {
const { isMerged, isMergedMainCell } = this._getCellMergeInfo(
r,
c,
row,
col,
this._dataMergeCache
);

if (isMerged && !isMergedMainCell) {
// If the cell is merged and is not the main cell, the cell is not rendered.
return true;
return;
} else if (!isMergedMainCell) {
// If the cell no merged, the cell is not rendered.
return true;
return;
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/engine-render/src/components/sheets/spreadsheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class Spreadsheet extends SheetComponent {
cacheCtx.save();
cacheCtx.beginPath();
cacheCtx.rectByPrecision(x, y, w, h);
cacheCtx.closePathByEnv();
cacheCtx.closePath();
// The reason for clipping here is to avoid duplicate drawing (otherwise the text would be jagged, especially on Windows)
cacheCtx.clip();
this.draw(cacheCtx, {
Expand Down Expand Up @@ -665,7 +665,7 @@ export class Spreadsheet extends SheetComponent {
ctx.lineToByPrecision(startX, endY);
ctx.lineToByPrecision(startX, startY);
ctx.stroke();
ctx.closePathByEnv();
ctx.closePath();
}
}

Expand Down Expand Up @@ -724,15 +724,15 @@ export class Spreadsheet extends SheetComponent {
cacheCtx.moveTo(i - rowHeaderWidth, top - columnHeaderHeight);
cacheCtx.lineTo(i - rowHeaderWidth, bottom - columnHeaderHeight);
cacheCtx.stroke();
cacheCtx.closePathByEnv();
cacheCtx.closePath();
}
for (let j = startY; j <= endY; j += 50) {
cacheCtx.beginPath();
cacheCtx.strokeStyle = (j % 100 === 0) ? 'red' : '#aaa';
cacheCtx.moveTo(left - rowHeaderWidth, j - columnHeaderHeight);
cacheCtx.lineTo(right - rowHeaderWidth, j - columnHeaderHeight);
cacheCtx.stroke();
cacheCtx.closePathByEnv();
cacheCtx.closePath();
}
cacheCtx.fillStyle = '#666';
for (let i = startX; i <= endX; i += 100) {
Expand All @@ -746,7 +746,7 @@ export class Spreadsheet extends SheetComponent {
// cacheCtx.clearRect(left - rowHeaderWidth, j - columnHeaderHeight - 15, 30, 30);
// cacheCtx.fillText(`${left}`, left - rowHeaderWidth, j - columnHeaderHeight);
// }
cacheCtx.closePathByEnv();
cacheCtx.closePath();
cacheCtx.restore();
}

Expand Down
8 changes: 0 additions & 8 deletions packages/engine-render/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { Tools } from '@univerjs/core';
import { Transform } from './basics';
import { fixLineWidthByScale, getColor } from './basics/tools';

export class UniverRenderingContext2D implements CanvasRenderingContext2D {
Expand Down Expand Up @@ -293,13 +292,6 @@ export class UniverRenderingContext2D implements CanvasRenderingContext2D {
scaleX: m.a,
scaleY: m.d,
};
// const transformer = Transform.create([m.a, m.b, m.c, m.d, m.e, m.f]);
// const { scaleX, scaleY } = transformer.decompose();

// return {
// scaleX,// why not m.a & m.d
// scaleY,
// };
}

getScale() {
Expand Down
7 changes: 1 addition & 6 deletions packages/engine-render/src/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,13 +734,11 @@ export class Viewport {
if (viewportScrollX !== undefined) {
this._preViewportScrollX = this.viewportScrollX;
this.viewportScrollX = viewportScrollX;
// this._deltaViewportScrollX = viewportScrollX - this._preViewportScrollX;
}

if (viewportScrollY !== undefined) {
this._preViewportScrollY = this.viewportScrollY;
this.viewportScrollY = viewportScrollY;
// this._deltaViewportScrollY = viewportScrollY - this._preViewportScrollY;
}
return this;
}
Expand Down Expand Up @@ -1349,7 +1347,6 @@ export class Viewport {

private _emitScrollEnd$(scrollSubParam: IScrollObserverParam) {
clearTimeout(this._scrollStopNum);
console.log('emitScrollEnd$');
this._scrollStopNum = setTimeout(() => {
this.onScrollEnd$.emitEvent({
rawScrollX: scrollSubParam.rawScrollX,
Expand All @@ -1363,7 +1360,7 @@ export class Viewport {
limitY: this._scrollBar?.limitY,
isTrigger: false,
});
}, 16);
}, 2);
}

/**
Expand Down Expand Up @@ -1447,8 +1444,6 @@ export class Viewport {
this.viewportScrollX = viewportScrollX;
this.viewportScrollY = viewportScrollY;

console.log('viewportScrollY', viewportScrollY, 'delta', this._deltaViewportScrollY);

const scrollSubParam: IScrollObserverParam = {
isTrigger,
viewport: this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export class SheetRenderController extends RxDisposable implements IRenderModule
const bufferEdgeX = 100;
const bufferEdgeY = 100;

window.sc = scene;
const viewMain = new Viewport(SHEET_VIEWPORT_KEY.VIEW_MAIN, scene, {
left: rowHeader.width,
top: columnHeader.height,
Expand Down Expand Up @@ -560,7 +559,7 @@ export class SheetRenderController extends RxDisposable implements IRenderModule

let offsetX = 0;
let offsetY = 0;
console.log('mouse wheel event');

const isLimitedStore = viewMain.limitedScroll();
if (evt.inputIndex === PointerInput.MouseWheelX) {
const deltaFactor = Math.abs(evt.deltaX);
Expand Down

0 comments on commit c0c2bf1

Please sign in to comment.