Commit 0d7affa1 authored by Sergey Konovalov's avatar Sergey Konovalov

buildDependencies relative references in def names; error with arguments;...

buildDependencies relative references in def names; error with arguments; ConditionalFormatting _updateConditionalFormatting for expression;
parent 9ebf7a90
......@@ -74,6 +74,32 @@
//todo more checks
return this.ranges && this.ranges.length > 0;
}
CConditionalFormatting.prototype.getBBox = function() {
var bbox = null;
if (this.ranges && this.ranges.length > 0) {
bbox = this.ranges[0].clone();
for(var i = 1 ; i < this.ranges.length; ++i){
bbox.union2(this.ranges[i]);
}
}
return bbox;
};
//todo need another approach
function CConditionalFormattingFormulaWrapper (ws, cf) {
this.ws = ws;
this.cf = cf;
}
CConditionalFormattingFormulaWrapper.prototype.onFormulaEvent = function(type, eventData) {
if (AscCommon.c_oNotifyParentType.CanDo === type) {
return true;
} else if (AscCommon.c_oNotifyParentType.IsDefName === type) {
return true;
} else if (AscCommon.c_oNotifyParentType.Change === type) {
//todo collect
this.ws._updateConditionalFormatting(new AscCommonExcel.MultiplyRange(this.cf.ranges));
}
};
function CConditionalFormattingRule () {
this.aboveAverage = true;
......@@ -327,17 +353,24 @@
res.Text = this.Text;
return res;
};
CFormulaCF.prototype.init = function(ws) {
CFormulaCF.prototype.init = function(ws, opt_parent) {
if (!this._f) {
this._f = new AscCommonExcel.parserFormula(this.Text, null, ws);
this._f = new AscCommonExcel.parserFormula(this.Text, opt_parent, ws);
this._f.parse();
if (opt_parent) {
//todo realize removeDependencies
this._f.buildDependencies();
}
}
};
CFormulaCF.prototype.getValue = function(ws) {
this.init(ws);
//todo bbox
return this._f.calculate(null, null).getValue();
};
CFormulaCF.prototype.getValueRaw = function(ws, opt_parent, opt_offset) {
this.init(ws, opt_parent);
return this._f.calculate(null, null, opt_offset);
};
function CIconSet () {
this.IconSet = Asc.EIconSetType.Traffic3Lights1;
......@@ -425,6 +458,7 @@
*/
window['AscCommonExcel'] = window['AscCommonExcel'] || {};
window['AscCommonExcel'].CConditionalFormatting = CConditionalFormatting;
window['AscCommonExcel'].CConditionalFormattingFormulaWrapper = CConditionalFormattingFormulaWrapper;
window['AscCommonExcel'].CConditionalFormattingRule = CConditionalFormattingRule;
window['AscCommonExcel'].CColorScale = CColorScale;
window['AscCommonExcel'].CDataBar = CDataBar;
......
......@@ -281,12 +281,10 @@
cCOLUMN.prototype.constructor = cCOLUMN;
cCOLUMN.prototype.argumentsMax = 1;
cCOLUMN.prototype.Calculate = function (arg) {
var arg0;
if (this.argumentsCurrent == 0) {
arg0 = arguments[1];
return this.value = new cNumber(arg0.bbox.c1 + 1);
return this.value = new cNumber(arguments[1].c1 + 1);
}
arg0 = arg[0];
var arg0 = arg[0];
var range;
if (cElementType.cell === arg0.type || cElementType.cell3D === arg0.type ||
cElementType.cellsRange === arg0.type || cElementType.cellsRange3D === arg0.type) {
......@@ -570,7 +568,7 @@
cINDIRECT.prototype.ca = true;
cINDIRECT.prototype.Calculate = function (arg) {
var t = this, arg0 = arg[0].tocString(), arg1 = arg[1] ? arg[1] :
new cBool(true), r1 = arguments[1], wb = r1.worksheet.workbook, o = {
new cBool(true), ws = arguments[3], wb = ws.workbook, o = {
Formula: "", pCurrPos: 0
}, ref, found_operand, ret;
......@@ -591,11 +589,11 @@
}
}
} else if (parserHelp.isArea.call(o, o.Formula, o.pCurrPos)) {
found_operand = new cArea(o.operand_str.toUpperCase(), r1.worksheet);
found_operand = new cArea(o.operand_str.toUpperCase(), ws);
} else if (parserHelp.isRef.call(o, o.Formula, o.pCurrPos, true)) {
found_operand = new cRef(o.operand_str.toUpperCase(), r1.worksheet);
found_operand = new cRef(o.operand_str.toUpperCase(), ws);
} else if (parserHelp.isName.call(o, o.Formula, o.pCurrPos, wb)[0]) {
found_operand = new AscCommonExcel.cName(o.operand_str, r1.worksheet);
found_operand = new AscCommonExcel.cName(o.operand_str, ws);
}
}
......@@ -1012,12 +1010,10 @@
cROW.prototype.constructor = cROW;
cROW.prototype.argumentsMax = 1;
cROW.prototype.Calculate = function (arg) {
var arg0;
if (this.argumentsCurrent == 0) {
arg0 = arguments[1];
return this.value = new cNumber(arg0.bbox.r1 + 1);
return this.value = new cNumber(arguments[1].r1 + 1);
}
arg0 = arg[0];
var arg0 = arg[0];
var range;
if (cElementType.cell === arg0.type || cElementType.cell3D === arg0.type ||
cElementType.cellsRange === arg0.type || cElementType.cellsRange3D === arg0.type) {
......
......@@ -1252,11 +1252,11 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cArea3D.prototype.getWS = function () {
return this.wsFrom;
};
cArea3D.prototype.cross = function (arg, wsID) {
cArea3D.prototype.cross = function (arg, ws) {
if (!this.isSingleSheet()) {
return new cError(cErrorType.wrong_value_type);
}
/*if ( this.wsFrom !== wsID ) {
/*if ( this.wsFrom !== ws ) {
return new cError( cErrorType.wrong_value_type );
}*/
var r = this.getRange();
......@@ -4906,7 +4906,7 @@ parserFormula.prototype.parse = function(local, digitDelim) {
for (var ind = 0; ind < currentElement.getArguments(); ind++) {
arg.unshift(elemArr.pop());
}
_tmp = currentElement.Calculate(arg, bbox, opt_defName, this.ws.getId());
_tmp = currentElement.Calculate(arg, bbox, opt_defName, this.ws);
if (null != _tmp.numFormat) {
numFormat = _tmp.numFormat;
} else if (0 > numFormat || cNumFormatNone === currentElement.numFormat) {
......@@ -5334,6 +5334,11 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.startListeningVolatile(this);
}
var isDefName;
if (this.parent && this.parent.onFormulaEvent) {
isDefName = this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.IsDefName);
}
for (var i = 0; i < this.outStack.length; i++) {
ref = this.outStack[i];
......@@ -5353,6 +5358,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
bbox = this.extentBBoxDefName(isDefName, bbox);
this.wb.dependencyFormulas.startListeningRange(ref.getWsId(), bbox, this);
} else if (cElementType.cellsRange3D === ref.type && ref.isValid()) {
wsR = ref.range(ref.wsRange());
......@@ -5369,6 +5375,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
bbox = this.extentBBoxDefName(isDefName, bbox);
this.wb.dependencyFormulas.startListeningRange(wsId, bbox, this);
}
}
......@@ -5388,6 +5395,11 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.endListeningVolatile(this);
}
var isDefName;
if (this.parent && this.parent.onFormulaEvent) {
isDefName = this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.IsDefName);
}
for (var i = 0; i < this.outStack.length; i++) {
ref = this.outStack[i];
......@@ -5405,6 +5417,7 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
bbox = this.extentBBoxDefName(isDefName, bbox);
this.wb.dependencyFormulas.endListeningRange(ref.getWsId(), bbox, this);
} else if (cElementType.cellsRange3D === ref.type && ref.dependenceRange) {
wsR = ref.dependenceRange;
......@@ -5418,13 +5431,27 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
bbox = this.extentBBoxDefName(isDefName, bbox);
this.wb.dependencyFormulas.endListeningRange(wsId, bbox, this);
}
}
}
}
};
parserFormula.prototype.extentBBoxDefName = function(isDefName, bbox) {
if (isDefName && !bbox.isAbsAll()) {
bbox = bbox.clone();
if (!bbox.isAbsR1() || !bbox.isAbsR2()) {
bbox.r1 = 0;
bbox.r2 = AscCommon.gc_nMaxRow0;
}
if (!bbox.isAbsC1() || !bbox.isAbsC2()) {
bbox.c1 = 0;
bbox.c2 = AscCommon.gc_nMaxCol0;
}
}
return bbox;
};
parserFormula.prototype.getElementByPos = function(pos) {
var curPos = 0;
for (var i = 0; i < this.f.length; ++i) {
......
......@@ -238,6 +238,8 @@
return !(this.isTable &&
(AscCommon.c_oNotifyType.Shift === type || AscCommon.c_oNotifyType.Move === type ||
AscCommon.c_oNotifyType.Delete === type));
} else if (AscCommon.c_oNotifyParentType.IsDefName === type) {
return true;
} else if (AscCommon.c_oNotifyParentType.Change === type) {
this.wb.dependencyFormulas.addToChangedDefName(this);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
......@@ -2688,6 +2690,7 @@
return false;
};
Woorksheet.prototype._updateConditionalFormatting = function(range) {
var t = this;
var oGradient1, oGradient2;
var aCFs = this.aConditionalFormatting;
var aRules, oRule;
......@@ -2908,6 +2911,27 @@
};
})(oRule, oRule.aRuleElements[0] && oRule.aRuleElements[0].getValue(this), oRule.aRuleElements[1] && oRule.aRuleElements[1].getValue(this));
break;
case AscCommonExcel.ECfType.expression:
var offset = {offsetRow: 0, offsetCol: 0};
var bboxCf = cf.getBBox();
var rowLT = bboxCf ? bboxCf.r1 : 0;
var colLT = bboxCf ? bboxCf.c1 : 0;
var formulaParent = new AscCommonExcel.CConditionalFormattingFormulaWrapper(this, cf);
compareFunction = (function(rule, formulaCF) {
return function(val, c) {
offset.offsetRow = c.nRow - rowLT;
offset.offsetCol = c.nCol - colLT;
var res = formulaCF && formulaCF.getValueRaw(t, formulaParent, offset);
if(res && res.tocBool){
res = res.tocBool();
if(res && res.toBool) {
return res.toBool();
}
}
return false;
};
})(oRule, oRule.aRuleElements[0]);
break;
default:
continue;
break;
......
......@@ -841,7 +841,8 @@
Change: 1,
ChangeFormula: 2,
EndCalculate: 3,
GetRangeCell: 4
GetRangeCell: 4,
IsDefName: 5
};
var c_oDashType = {
......
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