Browse Source

perf(render performace): improve

master
liuyang 5 years ago
parent
commit
9ed242307b
  1. 45
      src/global/border.js
  2. 87
      src/global/draw.js
  3. 3
      src/global/method.js
  4. 4
      src/index.html
  5. 3
      src/store/index.js

45
src/global/border.js

@ -3,13 +3,9 @@ import { getObjType } from '../utils/util';
import Store from '../store'; import Store from '../store';
//获取表格边框数据计算值 //获取表格边框数据计算值
function getBorderInfoCompute(sheetIndex) { function getBorderInfoComputeRange(dataset_row_st,dataset_row_ed,dataset_col_st,dataset_col_ed,sheetIndex) {
let borderInfoCompute = {}; let borderInfoCompute = {};
if(Store.borderInfoCache!=null){
return Store.borderInfoCache;
}
let cfg, data; let cfg, data;
if(sheetIndex == null){ if(sheetIndex == null){
cfg = Store.config; cfg = Store.config;
@ -37,6 +33,22 @@ function getBorderInfoCompute(sheetIndex) {
let bd_r1 = borderRange[j].row[0], bd_r2 = borderRange[j].row[1]; let bd_r1 = borderRange[j].row[0], bd_r2 = borderRange[j].row[1];
let bd_c1 = borderRange[j].column[0], bd_c2 = borderRange[j].column[1]; let bd_c1 = borderRange[j].column[0], bd_c2 = borderRange[j].column[1];
if(bd_r1<dataset_row_st){
bd_r1 = dataset_row_st;
}
if(bd_r2>dataset_row_ed){
bd_r2 = dataset_row_ed;
}
if(bd_c1<dataset_col_st){
bd_c1 = dataset_col_st;
}
if(bd_c2>dataset_col_ed){
bd_c2 = dataset_col_ed;
}
if(borderType == "border-left"){ if(borderType == "border-left"){
for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){ for(let bd_r = bd_r1; bd_r <= bd_r2; bd_r++){
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
@ -816,6 +828,10 @@ function getBorderInfoCompute(sheetIndex) {
let bd_r = value.row_index, bd_c = value.col_index; let bd_r = value.row_index, bd_c = value.col_index;
if(bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed){
continue;
}
if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) { if (cfg["rowhidden"] != null && cfg["rowhidden"][bd_r] != null) {
continue; continue;
} }
@ -1030,11 +1046,28 @@ function getBorderInfoCompute(sheetIndex) {
} }
} }
Store.borderInfoCache = borderInfoCompute; return borderInfoCompute;
}
function getBorderInfoCompute(sheetIndex) {
let borderInfoCompute = {};
let cfg, data;
if(sheetIndex == null){
cfg = Store.config;
data = Store.flowdata;
}
else{
cfg = Store.luckysheetfile[getSheetIndex(sheetIndex)].config;
data = Store.luckysheetfile[getSheetIndex(sheetIndex)].data;
}
getBorderInfoComputeRange(0, data.length,0, data[0].length, sheetIndex);
return borderInfoCompute; return borderInfoCompute;
} }
export { export {
getBorderInfoCompute, getBorderInfoCompute,
getBorderInfoComputeRange
} }

87
src/global/draw.js

@ -11,7 +11,7 @@ import browser from './browser';
import { isRealNull, isRealNum } from './validate'; import { isRealNull, isRealNum } from './validate';
import { getCellTextSplitArr,getMeasureText,getCellTextInfo } from './getRowlen'; import { getCellTextSplitArr,getMeasureText,getCellTextInfo } from './getRowlen';
import { getcellvalue,getRealCellValue } from './getdata'; import { getcellvalue,getRealCellValue } from './getdata';
import { getBorderInfoCompute } from './border'; import { getBorderInfoComputeRange } from './border';
import { getSheetIndex } from '../methods/get'; import { getSheetIndex } from '../methods/get';
import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util'; import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util';
import { isInlineStringCell } from '../controllers/inlineString'; import { isInlineStringCell } from '../controllers/inlineString';
@ -1010,7 +1010,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
canvas.restore(); canvas.restore();
} }
let borderInfoCompute = getBorderInfoCompute(); let borderInfoCompute = getBorderInfoComputeRange(dataset_row_st,dataset_row_ed,dataset_col_st,dataset_col_ed);
for(let x in borderInfoCompute){ for(let x in borderInfoCompute){
//let bd_r = x.split("_")[0], bd_c = x.split("_")[1]; //let bd_r = x.split("_")[0], bd_c = x.split("_")[1];
@ -1018,9 +1018,9 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
let bd_r = x.substr(0, x.indexOf('_')); let bd_r = x.substr(0, x.indexOf('_'));
let bd_c = x.substr(x.indexOf('_') + 1); let bd_c = x.substr(x.indexOf('_') + 1);
if(bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed){ // if(bd_r < dataset_row_st || bd_r > dataset_row_ed || bd_c < dataset_col_st || bd_c > dataset_col_ed){
continue; // continue;
} // }
if(borderOffset[bd_r + "_" + bd_c]){ if(borderOffset[bd_r + "_" + bd_c]){
let start_r = borderOffset[bd_r + "_" + bd_c].start_r; let start_r = borderOffset[bd_r + "_" + bd_c].start_r;
@ -1068,8 +1068,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
Store.measureTextCacheTimeOut = setTimeout(() => { Store.measureTextCacheTimeOut = setTimeout(() => {
Store.measureTextCache = {}; Store.measureTextCache = {};
Store.measureTextCellInfoCache = {}; Store.measureTextCellInfoCache = {};
Store.borderInfoCache = null; Store.cellOverflowMapCache = {};
Store.cellOverflowMapCache = null;
}, 2000); }, 2000);
} }
@ -1960,19 +1959,28 @@ let cellOverflowRender = function(r, c, stc, edc,luckysheetTableContent,scrollHe
function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){
let map = {}; let map = {};
if(Store.cellOverflowMapCache!=null){
return Store.cellOverflowMapCache;
}
let data = Store.flowdata; let data = Store.flowdata;
for(let r = row_st; r <= row_end; r++){ for(let r = row_st; r <= row_end; r++){
if(data[r]==null){ if(data[r]==null){
continue; continue;
} }
if(Store.cellOverflowMapCache[r]!=null){
map[r] = Store.cellOverflowMapCache[r];
continue;
}
let hasCellOver = false;
for(let c = 0; c < data[r].length; c++){ for(let c = 0; c < data[r].length; c++){
let cell = data[r][c]; let cell = data[r][c];
// if(Store.cellOverflowMapCache[r + '_' + c]!=null){
// map[r + '_' + c] = Store.cellOverflowMapCache[r + '_' + c];
// continue;
// }
if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) { if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) {
continue continue
} }
@ -2055,17 +2063,30 @@ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){
// if(((stc >= col_st && stc <= col_ed) || (edc >= col_st && edc <= col_ed)) && stc < edc){ // if(((stc >= col_st && stc <= col_ed) || (edc >= col_st && edc <= col_ed)) && stc < edc){
if(((stc <= col_ed) || (edc >= col_st)) && stc < edc){ if(((stc <= col_ed) || (edc >= col_st)) && stc < edc){
map[r + '_' + c] = { let item = {
r: r, r: r,
stc: stc, stc: stc,
edc: edc edc: edc
} }
if(map[r]==null){
map[r] = {};
}
map[r][c] = item;
// Store.cellOverflowMapCache[r + '_' + c] = item;
hasCellOver = true;
} }
} }
} }
}
Store.cellOverflowMapCache = map; if(hasCellOver){
Store.cellOverflowMapCache[r] = map[r];
}
}
return map; return map;
} }
@ -2168,25 +2189,31 @@ function cellOverflow_colIn(map, r, c, col_st, col_ed){
stc, stc,
edc; edc;
for(let key in map){ for(let rkey in map){
// rowIndex = key.split('_')[0]; for(let ckey in map[rkey]){
// colIndex = key.split('_')[1]; rowIndex = rkey;
rowIndex = key.substr(0, key.indexOf('_')); colIndex = ckey;
colIndex = key.substr(key.indexOf('_') + 1); // rowIndex = key.substr(0, key.indexOf('_'));
// colIndex = key.substr(key.indexOf('_') + 1);
stc = map[key].stc; let mapItem = map[rkey][ckey];
edc = map[key].edc; stc = mapItem.stc;
edc = mapItem.edc;
if(rowIndex == r){
if(c >= stc && c <= edc){ if(rowIndex == r){
colIn = true; if(c >= stc && c <= edc){
colIn = true;
if(c == edc || c == col_ed){
colLast = true; if(c == edc || c == col_ed){
break; colLast = true;
break;
}
} }
} }
} }
if(colLast){
break;
}
} }
return { return {

3
src/global/method.js

@ -135,8 +135,7 @@ const defaultConfig = {
measureTextCache:{}, measureTextCache:{},
measureTextCellInfoCache:{}, measureTextCellInfoCache:{},
measureTextCacheTimeOut:null, measureTextCacheTimeOut:null,
borderInfoCache:null, cellOverflowMapCache:{},
cellOverflowMapCache:null,
zoomRatio:1, zoomRatio:1,

4
src/index.html

File diff suppressed because one or more lines are too long

3
src/store/index.js

@ -119,8 +119,7 @@ const Store = {
measureTextCache:{}, measureTextCache:{},
measureTextCellInfoCache:{}, measureTextCellInfoCache:{},
measureTextCacheTimeOut:null, measureTextCacheTimeOut:null,
borderInfoCache:null, cellOverflowMapCache:{},
cellOverflowMapCache:null,
zoomRatio:1, zoomRatio:1,

Loading…
Cancel
Save