Skip to content

Commit

Permalink
Added to use DependentExternal object to correctly receive data when …
Browse files Browse the repository at this point in the history
…clicked
  • Loading branch information
DimitryOrlov committed Sep 13, 2024
1 parent d7ce9a0 commit c3dd822
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
55 changes: 53 additions & 2 deletions cell/model/FormulaObjects/traceDependents.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function (window, undefined) {
this.ws = ws;
this.precedents = null;
this.precedentsExternal = null;
this.dependentsExternal = null;
this.dependents = null;
this.isDependetsCall = null;
this.inLoop = null;
Expand Down Expand Up @@ -115,6 +116,34 @@ function (window, undefined) {
}
return this.precedentsExternal[cellIndex];
};
// dependentsExternal
TraceDependentsManager.prototype.setDependentsExternal = function (from, to, elemRange, elemWs) {
if (!this.dependentsExternal) {
this.dependentsExternal = {};
}

if (!this.dependentsExternal[from]) {
this.dependentsExternal[from] = {};
}

let externalInfo = {range: elemRange, fullPath: null};

let rangeName = elemRange.getName();
let wsName = elemWs.getName();
let bookName = "";
let fullPath = wsName + "!" + rangeName;

externalInfo.fullPath = fullPath;

this.dependentsExternal[from][to] = externalInfo;
};
TraceDependentsManager.prototype.checkDependentExternal = function (cellIndex) {
if (!this.dependentsExternal) {
return false;
}
return this.dependentsExternal[cellIndex];
};

TraceDependentsManager.prototype.checkCircularReference = function (cellIndex, isDependentCall) {
if (this.dependents && this.dependents[cellIndex] && this.precedents && this.precedents[cellIndex]) {
if (isDependentCall) {
Expand Down Expand Up @@ -591,6 +620,13 @@ function (window, undefined) {
//if (parentCellIndex === null || (typeof(parentCellIndex) === "number" && isNaN(parentCellIndex))) {
continue;
}

if (is3D && typeof parentCellIndex === "string") {
// the object dependentsExternal is only needed to handle a double click on an arrow, and is not used in drawing
let elemRange = cellListeners[i].ref ? cellListeners[i].ref : new Asc.Range(parent.col, parent.row, parent.col, parent.row);
let elemWs = parent.ws;
this.setDependentsExternal(cellIndex, parentCellIndex, elemRange, elemWs);
}
this._setDependents(cellIndex, parentCellIndex);
this._setPrecedents(parentCellIndex, cellIndex, true);
}
Expand Down Expand Up @@ -1198,7 +1234,7 @@ function (window, undefined) {
TraceDependentsManager.prototype.addExternalLineCoordinates = function (from, x1, y1, x2, y2) {
/*
from - cellIndex
we are working with the precedentsExternal object, where
we are working with the precedentsExternal and dependentsExternal object, where
[from] - this is the position of the line with an arrow indicating external dependencies
*/

Expand All @@ -1209,8 +1245,8 @@ function (window, undefined) {
// in external we pass an array of strings like "[BookName.xlsx]SheetName!$A$1:$A$3" which we should pass to the goto window
let traceLineInfo = {from : {x: x1, y: y1}, to: {x: x2, y: y2}, external: null};

// we go through all external dependencies and fill array of external dependencies for chosen line
if (this.precedentsExternal && this.precedentsExternal[from]) {
// go through all externals and fill in the coords info and array of external dependencies
for (let i in this.precedentsExternal[from]) {
let externalInfo = this.precedentsExternal[from][i];

Expand All @@ -1221,6 +1257,17 @@ function (window, undefined) {
traceLineInfo.external.push(externalInfo.fullPath)
}
}
if (this.dependentsExternal && this.dependentsExternal[from]) {
for (let i in this.dependentsExternal[from]) {
let externalInfo = this.dependentsExternal[from][i];

if (!traceLineInfo.external) {
traceLineInfo.external = [];
}

traceLineInfo.external.push(externalInfo.fullPath)
}
}

if (!this.tracesCoords) {
this.tracesCoords = [];
Expand Down Expand Up @@ -1438,6 +1485,9 @@ function (window, undefined) {
TraceDependentsManager.prototype.isHaveExternalPrecedents = function () {
return !!this.precedentsExternal;
};
TraceDependentsManager.prototype.isHaveExternalDependents = function () {
return !!this.dependentsExternal;
};
TraceDependentsManager.prototype.forEachDependents = function (callback) {
for (let i in this.dependents) {
callback(i, this.dependents[i], this.isPrecedentsCall);
Expand Down Expand Up @@ -1466,6 +1516,7 @@ function (window, undefined) {
}
this.precedents = null;
this.precedentsExternal = null;
this.dependentsExternal = null;
this.dependents = null;
this.isDependetsCall = null;
this.inLoop = null;
Expand Down
10 changes: 6 additions & 4 deletions cell/view/WorksheetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5996,6 +5996,9 @@
};

const drawDependentLine = function (from, to, external) {
let fromCellIndex = from ? AscCommonExcel.getCellIndex(from.row, from.col) : null,
toCellIndex = to ? AscCommonExcel.getCellIndex(to.row, to.col) : null;

let x1 = t._getColLeft(from.col) - offsetX + t._getColumnWidth(from.col) / 4;
let y1 = t._getRowTop(from.row) - offsetY + t._getRowHeight(from.row) / 2;
let arrowSize = 7 * zoom * customScale;
Expand Down Expand Up @@ -6060,6 +6063,8 @@
drawArrowHead(x2, y2, arrowSize, angle, externalLineColor);
drawDot(x1, y1, externalLineColor);
drawMiniTable(x2, y2, miniTableCol, miniTableRow, isTableLeft, isTableTop);

traceManager.addExternalLineCoordinates(fromCellIndex, x1, y1, newX2, newY2);
} else {
ctx.beginPath();
ctx.setStrokeStyle(!external ? lineColor : externalLineColor);
Expand All @@ -6069,9 +6074,6 @@
drawArrowHead(newX2, newY2, arrowSize, angle, lineColor);
drawDot(x1, y1, lineColor);

let fromCellIndex = AscCommonExcel.getCellIndex(from.row, from.col),
toCellIndex = AscCommonExcel.getCellIndex(to.row, to.col);

// write the coordinates of line to traceManager
traceManager.addLineCoordinates(fromCellIndex, toCellIndex, /*{x: x1, y: y1}, {x: newX2, y: newY2}*/x1, y1, newX2, newY2);
}
Expand Down Expand Up @@ -6137,7 +6139,7 @@
drawMiniTable(x1, y1, miniTableCol, miniTableRow, isTableLeft, isTableTop);


traceManager.addExternalLineCoordinates(fromCellIndex, x1, y1, newX2, newY2)
traceManager.addExternalLineCoordinates(fromCellIndex, x1, y1, newX2, newY2);
};

const drawDottedLine = function (x1, y1, x2, y2) {
Expand Down

0 comments on commit c3dd822

Please sign in to comment.