From 5109873500996ac4e17abb95899f1fe5950f33b9 Mon Sep 17 00:00:00 2001 From: wbfsa Date: Fri, 25 Sep 2020 00:26:12 +0800 Subject: [PATCH] fix(big data slowly): speed up --- src/controllers/handler.js | 60 ++++++++++++++++++++++++++-------- src/controllers/sheetmanage.js | 2 ++ src/controllers/zoom.js | 12 +++---- src/global/createdom.js | 48 +++++++++++++-------------- src/global/draw.js | 10 +++--- src/global/formula.js | 3 +- src/global/getRowlen.js | 2 +- 7 files changed, 87 insertions(+), 50 deletions(-) diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 7812cebf3..c8b55e2af 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -99,6 +99,36 @@ export default function luckysheetHandler() { window.cancelAnimationFrame = clearTimeout; } }()); + + + + $("#luckysheet-sheet-container-c").mousewheel(function (event, delta) { + let scrollNum = event.deltaFactor<40?1:(event.deltaFactor<80?2:3); + let scrollLeft = $(this).scrollLeft(); + if(event.deltaY != 0){ + if(event.deltaY <0){ + scrollLeft = scrollLeft + 10*scrollNum; + + } + else{ + scrollLeft = scrollLeft - 10*scrollNum; + + } + } + else if(event.deltaX != 0){ + + if(event.deltaX >0){ + scrollLeft = scrollLeft + 10*scrollNum; + + } + else{ + scrollLeft = scrollLeft - 10*scrollNum; + + } + } + $(this).scrollLeft(scrollLeft); + event.preventDefault(); + }); //滚动监听 $("#luckysheet-cell-main").scroll(function () { @@ -128,20 +158,24 @@ export default function luckysheetHandler() { clearTimeout(mousewheelArrayUniqueTimeout); - if(Store.visibledatacolumn_unique!=null){ - visibledatacolumn_c = Store.visibledatacolumn_unique; - } - else{ - visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); - Store.visibledatacolumn_unique = visibledatacolumn_c; + if(Store.visibledatacolumn.length!=visibledatacolumn_c.length){ + if(Store.visibledatacolumn_unique!=null){ + visibledatacolumn_c = Store.visibledatacolumn_unique; + } + else{ + visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); + Store.visibledatacolumn_unique = visibledatacolumn_c; + } } - if(Store.visibledatarow_unique!=null){ - visibledatarow_c = Store.visibledatarow_unique; - } - else{ - visibledatarow_c = ArrayUnique(visibledatarow_c); - Store.visibledatarow_unique = visibledatarow_c; + if(Store.visibledatarow.length!=visibledatarow_c.length){ + if(Store.visibledatarow_unique!=null){ + visibledatarow_c = Store.visibledatarow_unique; + } + else{ + visibledatarow_c = ArrayUnique(visibledatarow_c); + Store.visibledatarow_unique = visibledatarow_c; + } } // visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); @@ -204,7 +238,7 @@ export default function luckysheetHandler() { mousewheelArrayUniqueTimeout = setTimeout(() => { Store.visibledatacolumn_unique = null; Store.visibledatarow_unique = null; - }, 200); + }, 500); }); $("#luckysheet-scrollbar-x").scroll(function(){ diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index e680a3213..2b0c8f4dd 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -688,6 +688,8 @@ const sheetmanage = { colwidth = c2 + 1; } + Store.flowdata = data; + luckysheetcreatedom(colwidth, rowheight, data, menu, title); setTimeout(function () { diff --git a/src/controllers/zoom.js b/src/controllers/zoom.js index 6e38d0cf2..a06df15e6 100644 --- a/src/controllers/zoom.js +++ b/src/controllers/zoom.js @@ -35,18 +35,18 @@ export function zoomChange(ratio){ } export function zoomRefreshView(){ - let $scrollLeft = $("#luckysheet-scrollbar-x"), $scrollTop = $("#luckysheet-scrollbar-y"); - let sl = $scrollLeft.scrollLeft(), st = $scrollTop.scrollTop(); + // let $scrollLeft = $("#luckysheet-scrollbar-x"), $scrollTop = $("#luckysheet-scrollbar-y"); + // let sl = $scrollLeft.scrollLeft(), st = $scrollTop.scrollTop(); - let wp = $scrollLeft.find("div").width(), hp = $scrollTop.find("div").height(); + // let wp = $scrollLeft.find("div").width(), hp = $scrollTop.find("div").height(); jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); changeSheetContainerSize(); - let wc = $scrollLeft.find("div").width(), hc = $scrollTop.find("div").height(); + // let wc = $scrollLeft.find("div").width(), hc = $scrollTop.find("div").height(); - $scrollLeft.scrollLeft(sl+wc-wp); - $scrollTop.scrollTop(st+hc-hp); + // $scrollLeft.scrollLeft(sl+wc-wp); + // $scrollTop.scrollTop(st+hc-hp); } diff --git a/src/global/createdom.js b/src/global/createdom.js index 68ed91e02..8c1709662 100644 --- a/src/global/createdom.js +++ b/src/global/createdom.js @@ -22,35 +22,35 @@ import locale from '../locale/locale'; import {menuToolBarWidth} from '../controllers/resize' export default function luckysheetcreatedom(colwidth, rowheight, data, menu, title) { - //最少30行 - if(rowheight < 30){ - rowheight = 30; - } + // //最少30行 + // if(rowheight < 30){ + // rowheight = 30; + // } - //最少22列 - if(colwidth < 22){ - colwidth = 22; - } + // //最少22列 + // if(colwidth < 22){ + // colwidth = 22; + // } let gh = gridHTML(); gh = replaceHtml(gh, { "logotitle": title });//设置title gh = replaceHtml(gh, { "menu": menuToolBar() });//设置需要显示的菜单 - if (data.length == 0) { - Store.flowdata = datagridgrowth(data, rowheight, colwidth); - } - else if (data.length < rowheight && data[0].length < colwidth) { - Store.flowdata = datagridgrowth(data, rowheight - data.length, colwidth - data[0].length); - } - else if (data.length < rowheight) { - Store.flowdata = datagridgrowth(data, rowheight - data.length, 0); - } - else if (data[0].length < colwidth) { - Store.flowdata = datagridgrowth(data, 0, colwidth - data[0].length); - } - else { - Store.flowdata = data; - } + // if (data.length == 0) { + // Store.flowdata = datagridgrowth(data, rowheight, colwidth); + // } + // else if (data.length < rowheight && data[0].length < colwidth) { + // Store.flowdata = datagridgrowth(data, rowheight - data.length, colwidth - data[0].length); + // } + // else if (data.length < rowheight) { + // Store.flowdata = datagridgrowth(data, rowheight - data.length, 0); + // } + // else if (data[0].length < colwidth) { + // Store.flowdata = datagridgrowth(data, 0, colwidth - data[0].length); + // } + // else { + // Store.flowdata = data; + // } let flowHTML = flow; if(Store.config == null){ @@ -103,7 +103,7 @@ export default function luckysheetcreatedom(colwidth, rowheight, data, menu, tit menuToolBarWidth(); $("#luckysheet-scrollbar-x div").width(Store.ch_width); - $("#luckysheet-scrollbar-y div").height(Store.rh_height - 30); + $("#luckysheet-scrollbar-y div").height(Store.rh_height + Store.columeHeaderHeight - Store.cellMainSrollBarSize - 3); //新建行菜单 $("body").append(maskHTML); diff --git a/src/global/draw.js b/src/global/draw.js index ed1f0a1a1..293812022 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -1222,10 +1222,10 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee ]; luckysheetTableContent.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]); - //数据验证(单元格左上角红色小三角标示) let dataVerification = dataVerificationCtrl.dataVerification; - let cellValue = getcellvalue(r, c, null); - if(dataVerification != null && dataVerification[r + '_' + c] != null && !dataVerificationCtrl.validateCellData(cellValue, dataVerification[r + '_' + c])){ + + if(dataVerification != null && dataVerification[r + '_' + c] != null && !dataVerificationCtrl.validateCellData(value, dataVerification[r + '_' + c])){ + //单元格左上角红色小三角标示 let dv_w = 5 * Store.zoomRatio, dv_h = 5 * Store.zoomRatio; //红色小三角宽高 luckysheetTableContent.beginPath(); @@ -2169,7 +2169,7 @@ function cellTextRender(textInfo, ctx, option){ Math.floor((pos_x +c.endX)/Store.zoomRatio)+0.5 , Math.floor((pos_y+c.endY)/Store.zoomRatio)+0.5 , ); - ctx.lineWidth = Math.floor(c.fs/9); + ctx.lineWidth = 1; ctx.strokeStyle = ctx.fillStyle; ctx.stroke(); ctx.closePath(); @@ -2188,7 +2188,7 @@ function cellTextRender(textInfo, ctx, option){ Math.floor((pos_x +item.endX)/Store.zoomRatio)+0.5, Math.floor((pos_y+ item.endY)/Store.zoomRatio)+0.5 ); - ctx.lineWidth = Math.floor(item.fs/9); + ctx.lineWidth = 1; ctx.strokeStyle = ctx.fillStyle; ctx.stroke(); ctx.closePath(); diff --git a/src/global/formula.js b/src/global/formula.js index cf206648f..b329411c8 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -4862,6 +4862,7 @@ const luckysheetformula = { } editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据 + _this.groupValuesRefreshData = []; } }, delFunctionGroup: function(r, c, index) { @@ -4996,7 +4997,7 @@ const luckysheetformula = { let _locale = locale(); let locale_formulaMore = _locale.formulaMore; - console.log(txt,r,c) + // console.log(txt,r,c) if(txt.indexOf(_this.error.r) > -1){ return [false, _this.error.r, txt]; } diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index da0113c5f..e2e1bfc09 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -1104,7 +1104,7 @@ function getCellTextInfo(cell , ctx, option){ wordGroup.left = left; wordGroup.top = top; - console.log(left, top, cumWordHeight, size.height); + // console.log(left, top, cumWordHeight, size.height); drawLineInfo(wordGroup, cancelLine, underLine,{ width:wordGroup.width,