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

Commit

Permalink
feat(zoom gui): zoom plus and minus, restore origin, slider
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Aug 17, 2020
1 parent 249aa02 commit d70dab4
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 233 deletions.
334 changes: 174 additions & 160 deletions src/controllers/constant.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ export default function luckysheetHandler() {
let scrollNum = event.deltaFactor<40?1:(event.deltaFactor<80?2:3);
//一次滚动三行或三列
if(event.deltaY != 0){
let row_ed;

let row_ed,step=Math.round(scrollNum/Store.zoomRatio);
step = step<1?1:step;
if(event.deltaY < 0){
row_ed = row_st + scrollNum;
row_ed = row_st + step;

if(row_ed >= visibledatarow_c.length){
row_ed = visibledatarow_c.length - 1;
}
}
else{
row_ed = row_st - scrollNum;
row_ed = row_st - step;

if(row_ed < 0){
row_ed = 0;
Expand All @@ -161,23 +161,23 @@ export default function luckysheetHandler() {

// if((isMac && event.deltaX >0 ) || (!isMac && event.deltaX < 0)){
if(event.deltaX >0){
col_ed = col_st + scrollNum;
scrollLeft = scrollLeft + 20*Store.zoomRatio;

if(col_ed >= visibledatacolumn_c.length){
col_ed = visibledatacolumn_c.length - 1;
}
// if(col_ed >= visibledatacolumn_c.length){
// col_ed = visibledatacolumn_c.length - 1;
// }
}
else{
col_ed = col_st - scrollNum;
scrollLeft = scrollLeft - 20*Store.zoomRatio;

if(col_ed < 0){
col_ed = 0;
}
// if(col_ed < 0){
// col_ed = 0;
// }
}

colscroll = col_ed == 0 ? 0 : visibledatacolumn_c[col_ed - 1];
// colscroll = col_ed == 0 ? 0 : visibledatacolumn_c[col_ed - 1];

$("#luckysheet-scrollbar-x").scrollLeft(colscroll);
$("#luckysheet-scrollbar-x").scrollLeft(scrollLeft);
}
});

Expand Down
95 changes: 55 additions & 40 deletions src/controllers/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,8 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {

$("#" + Store.container).find(".luckysheet").height(gridH - 2).width(gridW - 2);

Store.cellmainHeight = gridH - (Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight + Store.sheetBarHeight + Store.statisticBarHeight);
Store.cellmainWidth = gridW - Store.rowHeaderWidth;

$("#luckysheet-cols-h-c, #luckysheet-cell-main, #luckysheet-scrollbar-x").width(Store.cellmainWidth);
$("#luckysheet-cell-main").height(Store.cellmainHeight);
$("#luckysheet-rows-h").height(Store.cellmainHeight - Store.cellMainSrollBarSize);

$("#luckysheet-scrollbar-y").height(Store.cellmainHeight + 6);
$("#luckysheet-scrollbar-x").height(Store.cellMainSrollBarSize);
$("#luckysheet-scrollbar-y").width(Store.cellMainSrollBarSize);

Store.luckysheetTableContentHW = [
Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
Store.cellmainHeight + Store.columeHeaderHeight - Store.cellMainSrollBarSize
];

$("#luckysheetTableContent, #luckysheetTableContentF").attr({
width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
})
.css({ width: Store.luckysheetTableContentHW[0], height: Store.luckysheetTableContentHW[1] });

$("#" + Store.container).find("#luckysheet-grid-window-1").css("bottom", Store.sheetBarHeight);
$("#" + Store.container).find(".luckysheet-grid-window").css("bottom", Store.statisticBarHeight);

let gridwidth = $("#luckysheet-grid-window-1").width();
$("#luckysheet-freezebar-horizontal").find(".luckysheet-freezebar-horizontal-handle")
.css({ "width": gridwidth - 10 })
.end()
.find(".luckysheet-freezebar-horizontal-drop")
.css({ "width": gridwidth - 10 });

let gridheight = $("#luckysheet-grid-window-1").height();
$("#luckysheet-freezebar-vertical")
.find(".luckysheet-freezebar-vertical-handle")
.css({ "height": gridheight - 10 })
.end()
.find(".luckysheet-freezebar-vertical-drop")
.css({ "height": gridheight - 10 });
changeSheetContainerSize(gridW,gridH)

luckysheetFreezen.createAssistCanvas();
if(isRefreshCanvas){
luckysheetrefreshgrid($("#luckysheet-cell-main").scrollLeft(), $("#luckysheet-cell-main").scrollTop());
}
Expand Down Expand Up @@ -173,4 +134,58 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {

sheetmanage.sheetArrowShowAndHide();
sheetmanage.sheetBarShowAndHide();
}


export function changeSheetContainerSize(gridW, gridH){
if(gridW==null){
gridW = $("#" + Store.container).width();
}

if(gridH==null){
gridH = $("#" + Store.container).height();
}
Store.cellmainHeight = gridH - (Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columeHeaderHeight + Store.sheetBarHeight + Store.statisticBarHeight);
Store.cellmainWidth = gridW - Store.rowHeaderWidth;

$("#luckysheet-cols-h-c, #luckysheet-cell-main").width(Store.cellmainWidth);
$("#luckysheet-cell-main").height(Store.cellmainHeight);
$("#luckysheet-rows-h").height(Store.cellmainHeight - Store.cellMainSrollBarSize);

$("#luckysheet-scrollbar-y").height(Store.cellmainHeight + Store.columeHeaderHeight-Store.cellMainSrollBarSize-3);
$("#luckysheet-scrollbar-x").height(Store.cellMainSrollBarSize);
$("#luckysheet-scrollbar-y").width(Store.cellMainSrollBarSize);

$("#luckysheet-scrollbar-x").width(Store.cellmainWidth).css("left",Store.rowHeaderWidth-1);

Store.luckysheetTableContentHW = [
Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
Store.cellmainHeight + Store.columeHeaderHeight - Store.cellMainSrollBarSize
];

$("#luckysheetTableContent, #luckysheetTableContentF").attr({
width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
})
.css({ width: Store.luckysheetTableContentHW[0], height: Store.luckysheetTableContentHW[1] });

$("#" + Store.container).find("#luckysheet-grid-window-1").css("bottom", Store.sheetBarHeight);
$("#" + Store.container).find(".luckysheet-grid-window").css("bottom", Store.statisticBarHeight);

let gridwidth = $("#luckysheet-grid-window-1").width();
$("#luckysheet-freezebar-horizontal").find(".luckysheet-freezebar-horizontal-handle")
.css({ "width": gridwidth - 10 })
.end()
.find(".luckysheet-freezebar-horizontal-drop")
.css({ "width": gridwidth - 10 });

let gridheight = $("#luckysheet-grid-window-1").height();
$("#luckysheet-freezebar-vertical")
.find(".luckysheet-freezebar-vertical-handle")
.css({ "height": gridheight - 10 })
.end()
.find(".luckysheet-freezebar-vertical-drop")
.css({ "height": gridheight - 10 });

luckysheetFreezen.createAssistCanvas();
}
2 changes: 1 addition & 1 deletion src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ const sheetmanage = {
$("#luckysheet-cols-h-cells_0").css("width", Store.ch_width); //width更新

$("#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 );
},
setCurSheet: function(index) {
for (let i = 0; i < Store.luckysheetfile.length; i++) {
Expand Down
152 changes: 142 additions & 10 deletions src/controllers/zoom.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,151 @@
import Store from '../store';
import locale from '../locale/locale';
import { replaceHtml } from '../utils/util';
import rhchInit from '../global/rhchInit';
import luckysheetConfigsetting from './luckysheetConfigsetting';
import {changeSheetContainerSize} from './resize';
import { jfrefreshgrid_rhcw } from '../global/refresh';


export function zoomChange(ratio){
if(Store.flowdata==null || Store.flowdata.length==0){
return;
}

Store.zoomRatio = ratio;

jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);

changeSheetContainerSize();
}


export function zoomInitial(){
//zoom
Store.rowHeaderWidth = luckysheetConfigsetting.rowHeaderWidth * Store.zoomRatio;
Store.columeHeaderHeight = luckysheetConfigsetting.columeHeaderHeight *Store.zoomRatio;
$("#luckysheet-rows-h").width((Store.rowHeaderWidth-1.5));
$("#luckysheet-cols-h-c").height((Store.columeHeaderHeight-1.5));
$("#luckysheet-left-top").css({width:Store.rowHeaderWidth-1.5, height:Store.columeHeaderHeight-1.5});

$("#luckysheet-zoom-minus").click(function(){
let currentRatio;
if(Store.zoomRatio==null){
currentRatio = Store.zoomRatio = 1;
}
else{
currentRatio = Math.ceil(Store.zoomRatio*10)/10;
}

currentRatio = currentRatio-0.1;

if(currentRatio<=0.1){
currentRatio = 0.1;
}

Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});

$("#luckysheet-zoom-plus").click(function(){
let currentRatio;
if(Store.zoomRatio==null){
currentRatio = Store.zoomRatio = 1;
}
else{
currentRatio = Math.floor(Store.zoomRatio*10)/10;
}

currentRatio = currentRatio+0.1;

if(currentRatio>=4){
currentRatio = 4;
}

Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});

$("#luckysheet-zoom-slider").click(function(e){
let xoffset = $(this).offset().left, pageX = e.pageX;

let currentRatio = positionToRatio(pageX-xoffset);
Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});

$("#luckysheet-zoom-cursor").mousedown(function(e){
let curentX = e.pageX,cursorLeft = parseFloat($("#luckysheet-zoom-cursor").css("left"));
$(document).off("mousemove.zoomCursor").on("mousemove.zoomCursor",function(event){
let moveX = event.pageX;
let offsetX = moveX - curentX;
// console.log(moveX, curentX, offsetX);
// curentX = moveX;
// let left = parseFloat($("#luckysheet-zoom-cursor").css("left"));
let pos = cursorLeft + offsetX;
let currentRatio = positionToRatio(pos);

if(currentRatio>4){
currentRatio =4;
pos = 100;
}

if(currentRatio<0.1){
currentRatio =0.1;
pos = 0;
}

Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
let r = Math.round(currentRatio*100) + "%";
$("#luckysheet-zoom-ratioText").html(r);
$("#luckysheet-zoom-cursor").css("left", pos-4);
});

$(document).off("mouseup.zoomCursor").on("mouseup.zoomCursor",function(event){
$(document).off(".zoomCursor");
});

e.stopPropagation();
}).click(function(e){
e.stopPropagation();
});

$("#luckysheet-zoom-ratioText").click(function(){
Store.zoomRatio = 1;
zoomChange(1);
zoomNumberDomBind(1);
});

zoomNumberDomBind(Store.zoomRatio);
}

export function zoomChange(){

}
function zoomSlierDown(){

}

function positionToRatio(pos){
let ratio = 1;
if(pos<50){
ratio = Math.round((pos*1.8/100 + 0.1)*100)/100;
}
else if(pos>50){
ratio = Math.round(((pos-50)*6/100 + 1)*100)/100;
}

return ratio;
}

function zoomSlierDomBind(ratio){
let domPos = 50;
if(ratio<1){
domPos = Math.round((ratio - 0.1)*100 / 0.18)/10;
}
else if(ratio>1){
domPos = Math.round((ratio - 1)*100 / 0.6)/10+50;
}
$("#luckysheet-zoom-cursor").css("left", domPos-4);
}

function zoomNumberDomBind(ratio){
let r = Math.round(ratio*100) + "%";
$("#luckysheet-zoom-ratioText").html(r);
zoomSlierDomBind(ratio);
}

2 changes: 2 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { luckysheetlodingHTML } from './controllers/constant';
import { getcellvalue, getdatabyselection } from './global/getdata';
import { setcellvalue } from './global/setdata';
import { selectHightlightShow } from './controllers/select';
import {zoomInitial} from './controllers/zoom';
import method from './global/method';

let luckysheet = {};
Expand Down Expand Up @@ -138,6 +139,7 @@ function initialWorkBook(){
rowColumnOperationInitial();//row and coloumn operate initialization
keyboardInitial();//Keyboard operate initialization
orderByInitial();//menu bar orderby function initialization
zoomInitial();//zoom method initialization
}

//获取所有表格数据
Expand Down
7 changes: 4 additions & 3 deletions src/css/luckysheet-core.css
Original file line number Diff line number Diff line change
Expand Up @@ -940,11 +940,12 @@
}

.luckysheet-sta-c .luckysheet-sta-content {
position: relative;
position: absolute;
left: 0px;
right: 220px;
height: 22px;
line-height: 22px;
text-align: right;
padding-right: 10px;
white-space: nowrap;
overflow: hidden;
}
Expand Down Expand Up @@ -1686,7 +1687,7 @@ body:not(.ewa-ipad) .luckysheet-cols-h-cell-nosel:hover, body:not(.ewa-ipad) .lu
height: 30px;
/*width: 400px;*/
/* background: #000; */
bottom: 68px;
bottom: 38px;
left: 0px;
z-index: 1000;
}
Expand Down
Loading

0 comments on commit d70dab4

Please sign in to comment.