Commit d9860e44 authored by alexey.musinov's avatar alexey.musinov

Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into develop

parents 0acb1bf1 e5aa82ac
......@@ -438,12 +438,12 @@ DependencyGraph.prototype = {
if(cwf)
{
if(!toAdd)
delete cwf.cells[sOldCellId];
delete cwf[sOldCellId];
if(!toDelete)
{
var cell = node.returnCell();
if ( cell && cell.formulaParsed )
cwf.cells[node.cellId] = node.cellId;
cwf[node.cellId] = node.cellId;
}
}
}
......@@ -2098,16 +2098,16 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom
//для формул. создаем копию this.cwf[this.Id] для нового листа.
if ( this.cwf[wsFrom.getId()] ){
var cwf = { cells:{} };
var cwf = {};
var newSheetId = newSheet.getId();
var cwfFrom = this.cwf[wsFrom.getId()];
this.cwf[newSheetId] = cwf;
for( var id in cwfFrom.cells ){
cwf.cells[id] = cwfFrom.cells[id];
for( var id in cwfFrom ){
cwf[id] = cwfFrom[id];
this.needRecalc.nodes[getVertexId(newSheetId, id)] = [newSheetId, id];
this.needRecalc.length++;
}
newSheet._BuildDependencies(cwf.cells);
newSheet._BuildDependencies(cwf);
}
if(!tableNames && newSheet.TableParts && newSheet.TableParts.length)
......@@ -2145,7 +2145,7 @@ Workbook.prototype.insertWorksheet = function (index, sheet, cwf) {
this._insertTablePartsName(sheet);
//восстанавливаем список ячеек с формулами для sheet
this.cwf[sheet.getId()] = cwf;
sheet._BuildDependencies(cwf.cells);
sheet._BuildDependencies(cwf);
this.sortDependency();
};
Workbook.prototype._insertTablePartsName = function (sheet) {
......@@ -2737,7 +2737,7 @@ Workbook.prototype.buildDependency = function(){
// this.dependencyFormulas = null;
// this.dependencyFormulas = new DependencyGraph(this);
for(var i in this.cwf){
this.getWorksheetById(i)._BuildDependencies(this.cwf[i].cells);
this.getWorksheetById(i)._BuildDependencies(this.cwf[i]);
}
};
Workbook.prototype.recalcDependency = function(f,bad,notRecalc){
......@@ -3057,144 +3057,148 @@ Workbook.prototype.getTableNameColumnByIndex = function(tableName, columnIndex){
}
return res;
};
Workbook.prototype.updateSparklineCache = function(sheet, ranges) {
for (var i = 0; i < this.aWorksheets.length; ++i) {
this.aWorksheets[i].updateSparklineCache(sheet, ranges);
}
};
Workbook.prototype.lockDraw = function() {
++this.lockCounter;
};
Workbook.prototype.unLockDraw = function() {
if (0 < this.lockCounter) {
--this.lockCounter;
}
};
Workbook.prototype.buildRecalc = function(notrec, bForce) {
var ws;
if (this.lockCounter > 0 && !bForce) {
return;
}
if (!bForce) {
for (var id in arrDefNameRecalc) {
arrDefNameRecalc[id].rebuild();
}
arrDefNameRecalc = {};
}
for (var id in arrRecalc) {
ws = this.getWorksheetById(id);
if (ws) {
var temp = arrRecalc[id];
var _rec = {};
for (var i = 0, length = temp.length; i < length; ++i) {
var cell = temp[i];
var cellId = g_oCellAddressUtils.getCellId(cell.nRow, cell.nCol);
_rec[cellId] = cellId;
this.needRecalc.nodes[getVertexId(id, cellId)] = [id, cellId];
this.needRecalc.length++;
}
ws._BuildDependencies(_rec);
}
}
arrRecalc = {};
if (!notrec) {
this.sortDependency();
}
};
Workbook.prototype.sortDependency = function(setCellFormat) {
this.buildRecalc(true);
var i;
var nR = this.needRecalc;
if (nR && (nR.length > 0)) {
var oCleanCellCacheArea = {};
var oNodeDependence = this.dependencyFormulas.getNodeDependence(nR.nodes);
for (i in oNodeDependence.oMasterNodes)
this._sortDependency(oNodeDependence.oMasterNodes[i], oNodeDependence, oNodeDependence.oMasterAreaNodes, false,
oCleanCellCacheArea, setCellFormat);
//те AreaNodes
var oCurMasterAreaNodes = oNodeDependence.oMasterAreaNodes;
while (true) {
var bEmpty = true;
var oNewMasterAreaNodes = {};
for (i in oCurMasterAreaNodes) {
bEmpty = false;
this._sortDependency(oCurMasterAreaNodes[i], oNodeDependence, oNewMasterAreaNodes, false, oCleanCellCacheArea,
setCellFormat);
}
oCurMasterAreaNodes = oNewMasterAreaNodes;
if (bEmpty) {
//все оставшиеся считаем как bad
//todo сделать как в Excel, которой определяет циклические ссылки на момент подсчета(пример A1=VLOOKUP(1,B1:D2,2),B2 = 1, D1=A1 - это не циклическая ссылка)
for (i in oNodeDependence.oMasterAreaNodesRestricted) {
this._sortDependency(oNodeDependence.oMasterAreaNodesRestricted[i].node, oNodeDependence, null, true,
oCleanCellCacheArea, setCellFormat);
}
break;
}
}
for (i in oCleanCellCacheArea)
this.handlers.trigger("cleanCellCache", i, oCleanCellCacheArea[i], AscCommonExcel.c_oAscCanChangeColWidth.none);
Workbook.prototype.updateSparklineCache = function (sheet, ranges) {
for (var i = 0; i < this.aWorksheets.length; ++i) {
this.aWorksheets[i].updateSparklineCache(sheet, ranges);
}
};
Workbook.prototype.lockDraw = function () {
++this.lockCounter;
};
Workbook.prototype.unLockDraw = function () {
if (0 < this.lockCounter) {
--this.lockCounter;
}
};
Workbook.prototype.buildRecalc = function (notrec, bForce) {
var ws;
if (this.lockCounter > 0 && !bForce) {
return;
}
if (!bForce) {
for (var id in arrDefNameRecalc) {
arrDefNameRecalc[id].rebuild();
}
arrDefNameRecalc = {};
}
for (var id in arrRecalc) {
ws = this.getWorksheetById(id);
if (ws) {
var temp = arrRecalc[id];
var _rec = {};
for (var i = 0, length = temp.length; i < length; ++i) {
var cell = temp[i];
var cellId = g_oCellAddressUtils.getCellId(cell.nRow, cell.nCol);
_rec[cellId] = cellId;
this.needRecalc.nodes[getVertexId(id, cellId)] = [id, cellId];
this.needRecalc.length++;
}
ws._BuildDependencies(_rec);
}
}
arrRecalc = {};
if (!notrec) {
this.sortDependency();
}
};
Workbook.prototype.sortDependency = function (setCellFormat) {
this.buildRecalc(true);
var i;
var nR = this.needRecalc;
if (nR && (nR.length > 0)) {
var oCleanCellCacheArea = {};
var oNodeDependence = this.dependencyFormulas.getNodeDependence(nR.nodes);
for (i in oNodeDependence.oMasterNodes) {
this._sortDependency(oNodeDependence.oMasterNodes[i], oNodeDependence, oNodeDependence.oMasterAreaNodes, false,
oCleanCellCacheArea, setCellFormat);
}
//те AreaNodes
var oCurMasterAreaNodes = oNodeDependence.oMasterAreaNodes;
while (true) {
var bEmpty = true;
var oNewMasterAreaNodes = {};
for (i in oCurMasterAreaNodes) {
bEmpty = false;
this._sortDependency(oCurMasterAreaNodes[i], oNodeDependence, oNewMasterAreaNodes, false, oCleanCellCacheArea,
setCellFormat);
}
oCurMasterAreaNodes = oNewMasterAreaNodes;
if (bEmpty) {
//все оставшиеся считаем как bad
//todo сделать как в Excel, которой определяет циклические ссылки на момент подсчета(пример A1=VLOOKUP(1,B1:D2,2),B2 = 1, D1=A1 - это не циклическая ссылка)
for (i in oNodeDependence.oMasterAreaNodesRestricted) {
this._sortDependency(oNodeDependence.oMasterAreaNodesRestricted[i].node, oNodeDependence, null, true,
oCleanCellCacheArea, setCellFormat);
}
break;
}
}
for (i in oCleanCellCacheArea) {
this.handlers.trigger("cleanCellCache", i, oCleanCellCacheArea[i], AscCommonExcel.c_oAscCanChangeColWidth.none);
}
AscCommonExcel.g_oVLOOKUPCache.clean();
AscCommonExcel.g_oHLOOKUPCache.clean();
}
this.needRecalc = {nodes: {}, length: 0};
};
Workbook.prototype._sortDependency = function(node, oNodeDependence, oNewMasterAreaNodes, bBad, oCleanCellCacheArea, setCellFormat) {
if (node) {
var oWeightMapElem = oNodeDependence.oWeightMap[node.nodeId];
if (oWeightMapElem) {
oWeightMapElem.cur++;
if (oWeightMapElem.cur == oWeightMapElem.max && !oWeightMapElem.gray) {
if (null != oNewMasterAreaNodes) {
var oNodeToAreaElement = oNodeDependence.oNodeToArea[node.nodeId];
if (oNodeToAreaElement) {
for (var i = 0, length = oNodeToAreaElement.length; i < length; ++i) {
var elem = oNodeToAreaElement[i];
elem.cur++;
if (elem.cur == elem.max) {
oNewMasterAreaNodes[elem.node.nodeId] = elem.node;
delete oNodeDependence.oMasterAreaNodesRestricted[elem.node.nodeId];
}
}
}
}
var bCurBad = oWeightMapElem.bad || bBad;
if (node.isDefinedName) {
//todo
//Обрабатываем тут все, что было сделано с именованной ссылкой: переименована;
//перемещен диапазон; сдвиг/удаление ячеек, приведшие к сдвигу ячеек; удаление именованного диапазона.
//
// var ws = this.getWorksheetById( node.sheetId );
// ws._ReBuildFormulas
// ws._RecalculatedFunctions(node.cellId, bCurBad, setCellFormat);
} else {
//пересчитываем функцию
var ws = this.getWorksheetById(node.sheetId);
ws._RecalculatedFunctions(node.cellId, bCurBad, setCellFormat);
//запоминаем области для удаления cache
var sheetArea = oCleanCellCacheArea[node.sheetId];
if (null == sheetArea) {
sheetArea = {};
oCleanCellCacheArea[node.sheetId] = sheetArea;
}
if (!node.isArea) {
sheetArea[node.cellId] = node.getBBox();
}
}
//обрабатываем child
oWeightMapElem.gray = true;
var oSlaveNodes = node.getSlaveEdges();
if (oSlaveNodes) {
for (var i in oSlaveNodes)
this._sortDependency(oSlaveNodes[i], oNodeDependence, oNewMasterAreaNodes, bBad, oCleanCellCacheArea);
}
oWeightMapElem.gray = false;
}
}
}
};
AscCommonExcel.g_oVLOOKUPCache.clean();
AscCommonExcel.g_oHLOOKUPCache.clean();
}
this.needRecalc = {nodes: {}, length: 0};
};
Workbook.prototype._sortDependency =
function (node, oNodeDependence, oNewMasterAreaNodes, bBad, oCleanCellCacheArea, setCellFormat) {
if (node) {
var oWeightMapElem = oNodeDependence.oWeightMap[node.nodeId];
if (oWeightMapElem) {
oWeightMapElem.cur++;
if (oWeightMapElem.cur == oWeightMapElem.max && !oWeightMapElem.gray) {
if (null != oNewMasterAreaNodes) {
var oNodeToAreaElement = oNodeDependence.oNodeToArea[node.nodeId];
if (oNodeToAreaElement) {
for (var i = 0, length = oNodeToAreaElement.length; i < length; ++i) {
var elem = oNodeToAreaElement[i];
elem.cur++;
if (elem.cur == elem.max) {
oNewMasterAreaNodes[elem.node.nodeId] = elem.node;
delete oNodeDependence.oMasterAreaNodesRestricted[elem.node.nodeId];
}
}
}
}
var bCurBad = oWeightMapElem.bad || bBad;
if (node.isDefinedName) {
//todo
//Обрабатываем тут все, что было сделано с именованной ссылкой: переименована;
//перемещен диапазон; сдвиг/удаление ячеек, приведшие к сдвигу ячеек; удаление именованного диапазона.
//
// var ws = this.getWorksheetById( node.sheetId );
// ws._ReBuildFormulas
// ws._RecalculatedFunctions(node.cellId, bCurBad, setCellFormat);
} else {
//пересчитываем функцию
var ws = this.getWorksheetById(node.sheetId);
ws._RecalculatedFunctions(node.cellId, bCurBad, setCellFormat);
//запоминаем области для удаления cache
var sheetArea = oCleanCellCacheArea[node.sheetId];
if (null == sheetArea) {
sheetArea = {};
oCleanCellCacheArea[node.sheetId] = sheetArea;
}
if (!node.isArea) {
sheetArea[node.cellId] = node.getBBox();
}
}
//обрабатываем child
oWeightMapElem.gray = true;
var oSlaveNodes = node.getSlaveEdges();
if (oSlaveNodes) {
for (var i in oSlaveNodes) {
this._sortDependency(oSlaveNodes[i], oNodeDependence, oNewMasterAreaNodes, bBad, oCleanCellCacheArea);
}
}
oWeightMapElem.gray = false;
}
}
}
};
//-------------------------------------------------------------------------------------------------
/**
* @constructor
......@@ -3439,7 +3443,7 @@ Woorksheet.prototype.copyDrawingObjects=function(oNewWs, wsFrom)
}
};
Woorksheet.prototype.initPostOpen = function(handlers){
this.workbook.cwf[this.Id]={ cells:{} };
var cwf = this.workbook.cwf[this.Id]={};
if(this.aFormulaExt){
var formulaShared = {};
for(var i = 0; i < this.aFormulaExt.length; ++i){
......@@ -3474,7 +3478,7 @@ Woorksheet.prototype.initPostOpen = function(handlers){
off.offsetRow *=-1;
formulaShared[oFormulaExt.si].fVal.changeOffset(off);
}
this.workbook.cwf[this.Id].cells[sCellId] = sCellId;
cwf[sCellId] = sCellId;
}
}
}
......@@ -3495,7 +3499,7 @@ Woorksheet.prototype.initPostOpen = function(handlers){
Если ячейка содержит в себе формулу, то добавляем ее в список ячеек с формулами.
*/
if(oCell.sFormula){
this.workbook.cwf[this.Id].cells[sCellId] = sCellId;
cwf[sCellId] = sCellId;
}
/*
Строится список ячеек, которые необходимо пересчитать при открытии. Это ячейки имеющие атрибут f.ca или значение в которых неопределено.
......@@ -3800,7 +3804,7 @@ Woorksheet.prototype.setName=function(name, bFromUndoRedo){
//перестраиваем формулы, если у них были ссылки на лист со старым именем.
for(var id in this.workbook.cwf) {
this.workbook.getWorksheetById(id)._ReBuildFormulas(this.workbook.cwf[id].cells,lastName,this.sName);
this.workbook.getWorksheetById(id)._ReBuildFormulas(this.workbook.cwf[id],lastName,this.sName);
}
this.workbook.dependencyFormulas.relinkDefNameByWorksheet(lastName, name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment