Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(big data slowly): speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Sep 24, 2020
1 parent ddc5c5d commit 5109873
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 50 deletions.
60 changes: 47 additions & 13 deletions src/controllers/handler.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(){
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/sheetmanage.js
Expand Up @@ -688,6 +688,8 @@ const sheetmanage = {
colwidth = c2 + 1;
}

Store.flowdata = data;

luckysheetcreatedom(colwidth, rowheight, data, menu, title);

setTimeout(function () {
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/zoom.js
Expand Up @@ -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);
}


Expand Down
48 changes: 24 additions & 24 deletions src/global/createdom.js
Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/global/draw.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/global/formula.js
Expand Up @@ -4862,6 +4862,7 @@ const luckysheetformula = {
}

editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
_this.groupValuesRefreshData = [];
}
},
delFunctionGroup: function(r, c, index) {
Expand Down Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion src/global/getRowlen.js
Expand Up @@ -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,
Expand Down

0 comments on commit 5109873

Please sign in to comment.