Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: add professional config #2275

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "feat: add professional config",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
233 changes: 233 additions & 0 deletions packages/vtable/examples/custom/custom-perf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import * as VTable from '../../src';
import { bindDebugTool } from '../../src/scenegraph/debug-tool';
import { InputEditor } from '@visactor/vtable-editors';
import { bearImageUrl, birdImageUrl, catImageUrl, flowerImageUrl, rabbitImageUrl, wolfImageUrl } from '../resource-url';
const ListTable = VTable.ListTable;
const input_editor = new InputEditor({});
VTable.register.editor('input', input_editor);
const CONTAINER_ID = 'vTable';

function createRecords(length) {
const records: any[] = [];
for (let i = 0; i < length; i++) {
records.push({
id: i,
text: 'text'
});
}

return records;
}

function createColumns(length) {
const columns: any[] = [];
for (let i = 0; i < length; i++) {
columns.push({
field: 'text',
title: 'custom',
width: 120,
customLayout
});
}

return columns;
}

function customLayout(args: VTable.TYPES.CustomRenderFunctionArg) {
const { table, row, col, rect } = args;
const record = table.getRecordByCell(col, row);
const { height, width } = rect ?? table.getCellRect(col, row);

const container = new VTable.CustomLayout.Group({
height,
width
// display: 'flex',
// flexDirection: 'row',
// flexWrap: 'wrap'
});

const tag = new VTable.CustomLayout.Text({
text: 'tag1',
textStyle: {
fontSize: 10,
fontFamily: 'sans-serif',
fill: 'rgb(51, 101, 238)'
},
panel: {
visible: true,
fill: '#f4f4f2',
cornerRadius: 5
},
space: 5,
marginLeft: 5
});
const tag2 = new VTable.CustomLayout.Text({
x: 50,
text: 'tag2',
textStyle: {
fontSize: 10,
fontFamily: 'sans-serif',
fill: 'rgb(51, 101, 238)'
},
panel: {
visible: true,
fill: '#f4f4f2',
cornerRadius: 5
},
space: 5,
marginLeft: 5
});
container.appendChild(tag);
container.appendChild(tag2);

return {
rootContainer: container,
renderDefault: false
};
}

export function createTable() {
const columns = createColumns(20);
const records = createRecords(3000);
const option: VTable.ListTableConstructorOptions = {
container: document.getElementById(CONTAINER_ID),
columns: [
{
field: 'id',
title: 'id'
},
...columns
],
records,
// editor: 'input',
defaultRowHeight: 40,
defaultColWidth: 120,
// customMergeCell: (col, row, table) => {
// if (col >= 0 && col < table.colCount && row === table.rowCount - 2) {
// return {
// range: {
// start: {
// col: 0,
// row: table.rowCount - 2
// },
// end: {
// col: table.colCount - 1,
// row: table.rowCount - 2
// }
// },
// customLayout: args => {
// const { table, row, col, rect } = args;
// const { height, width } = rect || table.getCellRect(col, row);
// const percentCalc = VTable.CustomLayout.percentCalc;
// const container = new VTable.CustomLayout.Group({
// height,
// width,
// display: 'flex',
// flexDirection: 'row',
// flexWrap: 'nowrap'
// });
// const containerLeft = new VTable.CustomLayout.Group({
// height: percentCalc(100),
// width: 160,
// display: 'flex',
// direction: 'column',
// alignContent: 'center',
// alignItems: 'center',
// justifyContent: 'space-around',
// fill: 'blue',
// // dx: 200
// x: 200
// });
// container.add(containerLeft);

// containerLeft.addEventListener('click', () => {
// containerLeft.setAttributes({ fill: 'red' });
// });

// const containerRight = new VTable.CustomLayout.Group({
// height: percentCalc(100),
// width: percentCalc(100, -50),
// display: 'flex',
// direction: 'column'
// // justifyContent: 'center'
// });
// container.add(containerRight);

// const containerRightTop = new VTable.CustomLayout.Group({
// id: 'containerRightTop',
// height: percentCalc(50),
// width: percentCalc(100),
// display: 'flex',
// alignItems: 'center',
// flexWrap: 'nowrap'
// });

// const containerRightBottom = new VTable.CustomLayout.Group({
// height: percentCalc(50),
// width: percentCalc(100),
// display: 'flex',
// alignItems: 'center'
// });

// containerRight.add(containerRightTop);
// containerRight.add(containerRightBottom);

// const bloggerName = new VTable.CustomLayout.Text({
// text: 'record.bloggerName',
// fontSize: 13,
// fontFamily: 'sans-serif',
// fill: 'black',
// marginLeft: 10
// });
// containerRightTop.add(bloggerName);

// const location = new VTable.CustomLayout.Icon({
// id: 'location',
// iconName: 'location',
// width: 15,
// height: 15,
// marginLeft: 10
// });
// containerRightTop.add(location);

// const locationName = new VTable.CustomLayout.Text({
// text: 'record.city',
// fontSize: 11,
// fontFamily: 'sans-serif',
// fill: '#6f7070',
// boundsPadding: [0, 10, 0, 0]
// });
// containerRightTop.add(locationName);

// return {
// rootContainer: container,
// renderDefault: false
// };
// }
// };
// }
// },

rowUpdateBufferCount: 0.1, // 行更新时,同步更新范围buffer系数;默认为1,同步更新为三倍屏幕预计行数(上下buffer各为1)
columnUpdateBufferCount: 0.1, // 列更新时,同步更新范围buffer系数;默认为1,同步更新为三倍屏幕预计列数(左右buffer各为1)
progressRowUpdateCount: 5, // 渐进更新行时,每个异步任务更新的行数;默认为屏幕预计行数
progressColumnUpdateCount: 5, // 渐进更新列时,每个异步任务更新的列数;默认为屏幕预计列数

renderOption: {
// disableDirtyBounds: true
}
};

const instance = new ListTable(option);
// bindDebugTool(instance.scenegraph.stage as any, {
// customGrapicKeys: ['col', 'row', 'role']
// });

// const { MOUSEMOVE_CELL } = VTable.ListTable.EVENT_TYPE;
// instance.addEventListener(MOUSEMOVE_CELL, (...args) => {
// console.log('MOUSEMOVE_CELL', args[0]?.target);
// });

// 只为了方便控制太调试用,不要拷贝
window.tableInstance = instance;
}
4 changes: 4 additions & 0 deletions packages/vtable/examples/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ export const menus = [
{
path: 'custom',
name: 'custom-render'
},
{
path: 'custom',
name: 'custom-perf'
}
]
},
Expand Down
14 changes: 13 additions & 1 deletion packages/vtable/src/scenegraph/graphic/contributions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
SplitRectAfterRenderContribution,
ContainerModule,
DrawItemInterceptor,
TextRenderContribution
TextRenderContribution,
RenderService,
DefaultRenderService
} from '@src/vrender';
import { ChartRender, DefaultCanvasChartRender } from './chart-render';
import { AfterImageRenderContribution, BeforeImageRenderContribution } from './image-contribution-render';
Expand All @@ -29,6 +31,7 @@ import {
} from './group-contribution-render';
import { VTableDrawItemInterceptorContribution } from './draw-interceptor';
import { SuffixTextBeforeRenderContribution } from './text-contribution-render';
import { VTableDefaultRenderService } from './render';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
// rect 渲染器注入contributions
Expand Down Expand Up @@ -89,4 +92,13 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
// text 渲染器注入contributions
bind(SuffixTextBeforeRenderContribution).toSelf().inSingletonScope();
bind(TextRenderContribution).toService(SuffixTextBeforeRenderContribution);

// render
if (isBound(RenderService)) {
unbind(RenderService);
rebind(RenderService).to(VTableDefaultRenderService);
} else {
unbind(RenderService);
bind(RenderService).to(VTableDefaultRenderService);
}
});
12 changes: 12 additions & 0 deletions packages/vtable/src/scenegraph/graphic/contributions/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { IGraphic } from '@src/vrender';
import { DefaultRenderService } from '@src/vrender';

export class VTableDefaultRenderService extends DefaultRenderService {
protected _prepare(g: IGraphic, updateBounds: boolean) {
g.role !== 'cell' &&
g.forEachChildren(g => {
this._prepare(g as IGraphic, updateBounds);
});
g.update({ bounds: updateBounds, trans: true });
}
}
14 changes: 10 additions & 4 deletions packages/vtable/src/scenegraph/group-creater/progress/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ export class SceneProxy {
} else if (this.table.isPivotTable()) {
this.mode = 'pivot';
}
if (this.table.options.maintainedDataCount) {
this.rowLimit = this.table.options.maintainedDataCount;

if (this.table.options.maintainedDataCount || this.table.options.maintainedRowCount) {
this.rowLimit = this.table.options.maintainedDataCount || this.table.options.maintainedRowCount;
}
if (this.table.options.maintainedColumnCount) {
this.colLimit = this.table.options.maintainedColumnCount;
}
}

Expand All @@ -110,7 +114,8 @@ export class SceneProxy {
this.colEnd = this.totalCol; // temp for first screen, will replace in createGroupForFirstScreen()
const defaultColWidth = this.table.defaultColWidth;
// const defaultColWidth = getDefaultHeight(this.table);
this.taskColCount = Math.ceil(this.table.tableNoFrameWidth / defaultColWidth) * 1;
this.taskColCount =
this.table.options.progressColumnUpdateCount ?? Math.ceil(this.table.tableNoFrameWidth / defaultColWidth) * 1;

// 确定动态更新限制
const totalBodyWidth = defaultColWidth * totalActualBodyColCount;
Expand Down Expand Up @@ -144,7 +149,8 @@ export class SceneProxy {
this.rowEnd = this.totalRow; // temp for first screen, will replace in createGroupForFirstScreen()
const defaultRowHeight = this.table.defaultRowHeight;
// const defaultRowHeight = getDefaultWidth(this.table);
this.taskRowCount = Math.ceil(this.table.tableNoFrameHeight / defaultRowHeight) * 1;
this.taskRowCount =
this.table.options.progressRowUpdateCount ?? Math.ceil(this.table.tableNoFrameHeight / defaultRowHeight) * 1;

// 确定动态更新限制
const totalBodyHeight = defaultRowHeight * totalActualBodyRowCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,14 @@ function updateColGroupContentAsync(colGroup: Group, proxy: SceneProxy) {
return;
}
const screenTopRow = proxy.screenTopRow;
const topRow = Math.max(proxy.bodyTopRow, screenTopRow - proxy.screenRowCount * 1);
const bottomRow = Math.min(proxy.bodyBottomRow, screenTopRow + proxy.screenRowCount * 2);
const topRow = Math.max(
proxy.bodyTopRow,
screenTopRow - Math.ceil(proxy.screenRowCount * (proxy.table.options.rowUpdateBufferCount ?? 1))
);
const bottomRow = Math.min(
proxy.bodyBottomRow,
screenTopRow + Math.ceil(proxy.screenRowCount * (1 + (proxy.table.options.rowUpdateBufferCount ?? 1)))
);

for (let row = topRow; row <= bottomRow; row++) {
// const cellGroup = proxy.table.scenegraph.getCell(col, row);
Expand Down
Loading
Loading