Skip to content

Commit

Permalink
Merge pull request #210 from VisActor/209-refactor-optimize-performance
Browse files Browse the repository at this point in the history
refactor: optimize compute row height performance and measure text wi…
  • Loading branch information
fangsmile committed Aug 14, 2023
2 parents 2a43b0f + ea84fe5 commit 1a23b7d
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 141 deletions.
235 changes: 235 additions & 0 deletions packages/vtable/examples/business/testPerformanceMoreColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/* eslint-disable */
import * as VTable from '../../src';
import { bindDebugTool } from '../../src/scenegraph/debug-tool';
const PivotTable = VTable.PivotTable;
const Table_CONTAINER_DOM_ID = 'vTable';

export function createTable() {
fetch('https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/performanceMoreColumn.json')
.then(res => res.json())
.then(data => {
const { records, rowTree, columnTree } = data;
const option: VTable.PivotTableConstructorOptions = {
rowTree,
columnTree,
rows: [
{
dimensionKey: 'job_typee6810c80_7e60_4991_9ab3_1bf46fba2cb9',
dimensionTitle: '职位类别',
headerStyle: {
textStick: true
},
width: 100,
showSort: false,
drillDown: false,
drillUp: false
},
{
dimensionKey: 'job_idcb651b6d_20c2_4660_9d31_1da23111a0e6',
dimensionTitle: '职位名称',
headerStyle: {
textStick: true
},
width: 100,
showSort: false,
drillDown: false,
drillUp: false
}
],
columns: [
{
dimensionKey: '__BI__col_header_id__',
dimensionTitle: '职位名称',
headerStyle: {
textStick: true,
textAlign: 'center'
},
showSort: false,
drillDown: false,
drillUp: false
},
{
dimensionKey: 'job_id6b5ab4f7_597c_4d89_b79a_fe4ce3312845',
dimensionTitle: '职位名称',
headerStyle: {
textStick: true
},
showSort: false,
drillDown: false,
drillUp: false
}
],
indicators: [
{
indicatorKey: 'talent_basic_age4f8cb265_955c_442f_bf86_af4fb0776b67',
value: '年龄',
width: 'auto',
showSort: true,
style: {}
},
{
indicatorKey: 'job_status57737112_93d0_4252_adba_1e6986d622c7',
value: '职位状态',
width: 'auto',
showSort: true,
style: {}
}
],

corner: {
titleOnDimension: 'row'
},
showColumnHeader: true,
showRowHeader: true,
hideIndicatorName: false,

theme: {
headerStyle: {
borderColor: ['rgb(224, 224, 224)', 'rgb(224, 224, 224)'],
borderLineWidth: 1,
padding: [8.6, 19, 8.6, 19],
textAlign: 'center',
hover: {
cellBgColor: 'rgba(0, 100, 250, 0.16)',
inlineRowBgColor: 'rgba(255, 255, 255, 0)',
inlineColumnBgColor: 'rgba(255, 255, 255, 0)'
},
click: {
cellBorderColor: ['rgb(224, 224, 224)', 'rgb(224, 224, 224)', '#3073F2', 'rgb(224, 224, 224)'],
cellBorderLineWidth: [0, 0, 2, 0],
cellBgColor: 'rgba(0, 100, 250, 0.16)'
},
frameStyle: {
borderColor: [null, null, 'rgb(224, 224, 224)', null],
borderLineWidth: [0, 0, 2, 0]
},
fontSize: 12,
fontWeight: 'bold',
fontFamily:
'-apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
font: 'normal normal bold 12px -apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
lineHeight: 18
},
bodyStyle: {
borderColor: ['rgb(224, 224, 224)', 'rgb(224, 224, 224)'],
borderLineWidth: 1,
padding: [8.6, 19, 8.6, 19],
textAlign: 'right',
hover: {
cellBgColor: 'rgba(186, 215, 255, 0.2)',
inlineRowBgColor: 'rgba(186, 215, 255, 0.2)',
inlineColumnBgColor: 'rgba(186, 215, 255, 0.2)'
},
click: {
cellBorderColor: '#3073F2',
cellBorderLineWidth: [2],
cellBgColor: 'rgba(186, 215, 255, 0.2)'
},
fontSize: 12,
fontWeight: 'normal',
fontFamily:
'-apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
font: 'normal normal normal 12px -apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
lineHeight: 18
},
rowHeaderStyle: {
borderColor: ['rgb(224, 224, 224)', 'rgb(224, 224, 224)'],
borderLineWidth: 1,
padding: [8.6, 19, 8.6, 19],
textAlign: 'left',
hover: {
cellBgColor: 'rgba(0, 100, 250, 0.16)',
inlineRowBgColor: 'rgba(255, 255, 255, 0)',
inlineColumnBgColor: 'rgba(255, 255, 255, 0)'
},
click: {
cellBorderColor: ['rgb(224, 224, 224)', '#3073F2', 'rgb(224, 224, 224)', 'rgb(224, 224, 224)'],
cellBorderLineWidth: [0, 2, 0, 0],
cellBgColor: 'rgba(0, 100, 250, 0.16)'
},
frameStyle: {
borderColor: [null, 'rgb(224, 224, 224)', null, null],
borderLineWidth: [0, 2, 0, 0]
},
fontSize: 12,
fontWeight: 'bold',
fontFamily:
'-apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
font: 'normal normal bold 12px -apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
lineHeight: 18
},
cornerHeaderStyle: {
borderColor: ['rgb(224, 224, 224)', 'rgb(224, 224, 224)'],
borderLineWidth: 1,
padding: [8.6, 19, 8.6, 19],
textAlign: 'left',

frameStyle: {
borderColor: [null, 'rgb(224, 224, 224)', 'rgb(224, 224, 224)', null],
borderLineWidth: [0, 2, 2, 0]
},
fontSize: 12,
fontWeight: 'bold',
fontFamily:
'-apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
//"font": "normal normal bold -apple-system,\"Helvetica Neue\",\"PingFang SC\",\"Microsoft YaHei\",\"Hiragino Sans GB\",Helvetica,Arial,sans-serif,\"apple color emoji\",\"segoe ui emoji\",\"segoe ui\",\"segoe ui symbol\"",
lineHeight: 18
},
menuStyle: {
color: '#1B1F23',
highlightColor: '#1E54C9',
font: 'normal normal normal 12px -apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"',
highlightFont:
'normal normal bold 12px -apple-system,"Helvetica Neue","PingFang SC","Microsoft YaHei","Hiragino Sans GB",Helvetica,Arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui","segoe ui symbol"'
},
underlayBackgroundColor: 'rgba(255,255,255,0)',
frameStyle: {
borderColor: 'rgb(224, 224, 224)',
borderLineWidth: 1
},
scrollStyle: {
visible: 'focus',
width: 7,
hoverOn: true
}
},
records,
enableDataAnalysis: false,
autoRowHeight: true,
widthMode: 'standard',
disableColumnResize: false,
autoWrapText: false,
enableColumnResizeOnAllRows: true,
resizeColumnEventAllInfo: true,
maxCharactersNumber: 256,
keyboardOptions: {
copySelected: false
},
columnResizerType: 'all',
menuType: 'dom',
pivotSortState: [],
hover: {
isShowTooltip: true,
enableColumnHighlight: false,
enableRowHighlight: true,
enableSingalCellHighlight: true
},
click: {
enableColumnHighlight: false,
enableRowHighlight: false,
enableSingalCellHighlight: true
},
parentElement: document.getElementById(Table_CONTAINER_DOM_ID)
};
const t0 = window.performance.now();
const instance = new PivotTable(option);
window.tableInstance = instance;
console.log('new table', window.performance.now() - t0);
// bindDebugTool(instance.scenegraph.stage as any, {
// customGrapicKeys: ['role', '_updateTag']
// });

// 只为了方便控制太调试用,不要拷贝
(window as any).tableInstance = instance;
});
}
2 changes: 1 addition & 1 deletion packages/vtable/examples/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const createSidebar = (node: HTMLDivElement) => {

node.innerHTML = `
<div>
<p class="sidebar-title">图表列表</p>
<p class="sidebar-title"></p>
<div class="menu-list">
${specsHtml.join('')}
</div>
Expand Down
8 changes: 8 additions & 0 deletions packages/vtable/examples/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ export const menus = [
{
path: 'business',
name: 'roadmap'
},
{
path: 'business',
name: 'aeolusTestPerformance'
},
{
path: 'business',
name: 'testPerformanceMoreColumn'
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions packages/vtable/examples/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body p {
.container .sidebar {
width: 200px;
/* height: 100%; */
border-right: 1px solid rgba(0, 0, 0, 0.06);
/* border-right: 1px solid rgba(0, 0, 0, 0.06); */
}

.container .sidebar > div {
Expand Down Expand Up @@ -71,7 +71,7 @@ body p {

.container .content {
flex: 1;
margin: 0 1em;
/* margin: 0 1em; */
/* height: 100%; */
min-width: 500px;
}
Expand All @@ -87,7 +87,7 @@ body p {
/* height: 500px; */
height: calc(100% - 2em);
width: 100%;
margin: 1em 0em;
/* margin: 1em 0em; */
}

pre {
Expand Down
6 changes: 3 additions & 3 deletions packages/vtable/src/PivotChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,10 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
onVChartEvent(type: string, callback: AnyFunction): void;
onVChartEvent(type: string, query: any, callback: AnyFunction): void;
onVChartEvent(type: string, query?: any, callback?: AnyFunction): void {
if (query) {
this._chartEventMap[type] = { callback, query };
if (typeof query === 'function') {
this._chartEventMap[type] = { callback: query };
} else {
this._chartEventMap[type] = { callback };
this._chartEventMap[type] = { callback, query };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function computeAxisComponentWidth(config: ICellAxisOption, table: BaseTa
labelWidth,
table.measureText(text, {
fontSize: attribute.label?.style?.fontSize,
fontWeight: attribute.label?.style?.fontWeight,
fontFamily: attribute.label?.style?.fontFamily
}).width
);
Expand All @@ -46,6 +47,7 @@ export function computeAxisComponentWidth(config: ICellAxisOption, table: BaseTa
labelWidth,
table.measureText(text, {
fontSize: attribute.label?.style?.fontSize,
fontWeight: attribute.label?.style?.fontWeight,
fontFamily: attribute.label?.style?.fontFamily
}).width + 2
);
Expand All @@ -61,12 +63,14 @@ export function computeAxisComponentWidth(config: ICellAxisOption, table: BaseTa
titleWidth =
table.measureText(attribute.title.text as string, {
fontSize: attribute.title?.style?.fontSize,
fontWeight: attribute.title?.style?.fontWeight,
fontFamily: attribute.title?.style?.fontFamily
}).height + 2;
} else {
titleWidth =
table.measureText(attribute.title.text as string, {
fontSize: attribute.title?.style?.fontSize,
fontWeight: attribute.title?.style?.fontWeight,
fontFamily: attribute.title?.style?.fontFamily
}).width + 2;
}
Expand Down
17 changes: 1 addition & 16 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,21 +874,6 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
this._clearRowRangeHeightsMap(row);
}
}
/**
* 批量设置行高 这个值只可设置在computeRowsHeight函数中
* @param rowStart 起始行
* @param rowEnd 结束行号
* @param height 统一高度值
*/
fillRowsHeight(rowStart: number, rowEnd: number, rowHeight: number): void {
for (let row = rowStart; row <= rowEnd; row++) {
this.rowHeightsMap.put(row, Math.round(rowHeight));
this._rowRangeHeightsMap.set(
`$0$${row}`,
Math.round((this._rowRangeHeightsMap.get(`$0$${row - 1}`) ?? 0) + rowHeight)
); //按照逻辑这里去缓存值$0$${row - 1} 一定是有的(除第一行外)
}
}
/**
* 获取指定行范围的总高度
* @param startCol
Expand Down Expand Up @@ -3062,7 +3047,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
return cellInfoArray;
}
/** 计算字体的宽度接口 */
measureText(text: string, font: { fontSize: number; fontFamily: string }): ITextSize {
measureText(text: string, font: { fontSize: number; fontWeight: string | number; fontFamily: string }): ITextSize {
return textMeasure.measureText(text, font);
}
measureTextBounds(attributes: IWrapTextGraphicAttribute): ITextSize {
Expand Down
6 changes: 6 additions & 0 deletions packages/vtable/src/event/listener/scroll-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ export function bindScrollBarListener(eventManeger: EventManeger) {

// 监听滚动条组件scroll事件
scenegraph.component.vScrollBar.addEventListener('scroll', (e: any) => {
if (stateManeger.interactionState !== InteractionState.scrolling) {
stateManeger.updateInteractionState(InteractionState.scrolling);
}
const ratio = e.detail.value[0] / (1 - e.detail.value[1] + e.detail.value[0]);
throttleVerticalWheel(ratio, e);
});

scenegraph.component.hScrollBar.addEventListener('scroll', (e: any) => {
if (stateManeger.interactionState !== InteractionState.scrolling) {
stateManeger.updateInteractionState(InteractionState.scrolling);
}
const ratio = e.detail.value[0] / (1 - e.detail.value[1] + e.detail.value[0]);
throttleHorizontalWheel(ratio);
});
Expand Down
Loading

0 comments on commit 1a23b7d

Please sign in to comment.