Commit 76277a57 authored by Alexander.Trofimov's avatar Alexander.Trofimov

support min, max, num, percent, percentile, 3 color conditional formatting

parent 70505698
......@@ -91,6 +91,42 @@
res.aColors.push(this.aColors[i].clone());
return res;
};
CColorScale.prototype.getMin = function(min, max, count) {
var oCFVO = (0 < this.aCFVOs.length) ? this.aCFVOs[0] : null;
return this.getValue(min, max, count, oCFVO);
};
CColorScale.prototype.getMid = function(min, max, count) {
var oCFVO = (2 < this.aCFVOs.length ? this.aCFVOs[1] : null);
return this.getValue(min, max, count, oCFVO);
};
CColorScale.prototype.getMax = function(min, max, count) {
var oCFVO = (2 === this.aCFVOs.length) ? this.aCFVOs[1] : (2 < this.aCFVOs.length ? this.aCFVOs[2] : null);
return this.getValue(min, max, count, oCFVO);
};
CColorScale.prototype.getValue = function(min, max, count, oCFVO) {
var res = min;
if (oCFVO) {
// ToDo Formula
switch (oCFVO.Type) {
case AscCommonExcel.ECfvoType.Minimum:
res = min;
break;
case AscCommonExcel.ECfvoType.Maximum:
res = max;
break;
case AscCommonExcel.ECfvoType.Number:
res = parseFloat(oCFVO.Val);
break;
case AscCommonExcel.ECfvoType.Percent:
res = min + Math.floor((max - min) * parseFloat(oCFVO.Val) / 100);
break;
case AscCommonExcel.ECfvoType.Percentile:
res = min + Math.floor(count * parseFloat(oCFVO.Val) / 100);
break;
}
}
return res;
};
function CDataBar () {
this.MaxLength = 90;
......@@ -191,6 +227,11 @@
this.b2 = this.c2.getB();
};
CGradient.prototype.calculateColor = function (indexColor) {
if (indexColor < this.min) {
indexColor = this.min;
} else if (indexColor > this.max) {
indexColor = this.max;
}
indexColor = ((indexColor - this.min) * this.koef) >> 0;
var r = (this.r1 + ((FT_Common.IntToUInt(this.r2 - this.r1) * indexColor) >> this.base_shift)) & 0xFF;
......
......@@ -8088,6 +8088,7 @@
window["Asc"].EFontScheme = EFontScheme;
window["Asc"].EIconSetType = EIconSetType;
window["Asc"].ECfType = ECfType;
window["AscCommonExcel"].ECfvoType = ECfvoType;
window["Asc"].ESparklineType = ESparklineType;
window["Asc"].EDispBlanksAs = EDispBlanksAs;
window["Asc"].SparklineAxisMinMax = SparklineAxisMinMax;
......
......@@ -3493,12 +3493,12 @@ Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref, withEm
return res;
};
Woorksheet.prototype._updateConditionalFormatting = function(range) {
var oGradient = null;
var oGradient1, oGradient2;
var aCFs = this.aConditionalFormatting;
var aRules, oRule;
var oRuleElement = null;
var o;
var i, j, cell, sqref, values, value, tmp, min, max, dxf, compareFunction, nc;
var i, j, l, cell, sqref, values, value, v, tmp, min, mid, max, dxf, compareFunction, nc;
for (i = 0; i < aCFs.length; ++i) {
sqref = aCFs[i].sqref;
// ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx)
......@@ -3521,32 +3521,47 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
if (!(oRuleElement instanceof AscCommonExcel.CColorScale)) {
break;
}
nc = 0;
min = Number.MAX_VALUE;
max = -Number.MAX_VALUE;
values = this._getValuesForConditionalFormatting(sqref, false);
for (cell = 0; cell < values.v.length; ++cell) {
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
if (CellValueType.Number === value.c.getType() && !isNaN(tmp = parseFloat(value.v))) {
value.v = tmp;
min = Math.min(min, tmp);
max = Math.max(max, tmp);
++nc;
} else {
value.v = null;
}
}
// ToDo CFVO Type (formula, max, min, num, percent, percentile) (page 2681)
// ToDo support 3 colors in rule
if (0 < values.length && 2 === oRuleElement.aColors.length) {
oGradient = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]);
oGradient.init(min, max);
// ToDo CFVO Type formula (page 2681)
l = oRuleElement.aColors.length;
if (0 < values.length && 2 <= l) {
oGradient1 = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]);
min = oRuleElement.getMin(min, max, nc);
max = oRuleElement.getMax(min, max, nc);
oGradient2 = null;
if (2 < l) {
oGradient2 = new AscCommonExcel.CGradient(oRuleElement.aColors[1], oRuleElement.aColors[2]);
mid = oRuleElement.getMid(min, max, nc);
oGradient1.init(min, mid);
oGradient2.init(mid, max);
} else {
oGradient1.init(min, max);
}
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
v = value.v;
dxf = null;
if (null !== value.v) {
if (null !== v) {
dxf = new AscCommonExcel.CellXfs();
dxf.fill = new AscCommonExcel.Fill({bg: oGradient.calculateColor(value.v)});
tmp = (oGradient2 && v > oGradient1.max) ? oGradient2 : oGradient1;
dxf.fill = new AscCommonExcel.Fill({bg: tmp.calculateColor(v)});
}
value.c.setConditionalFormattingStyle(dxf);
}
......@@ -3567,7 +3582,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
}
values.sort((function(condition) {
return function(v1, v2) {
return condition* (v2.v - v1.v);
return condition * (v2.v - v1.v);
}
})(oRule.bottom ? -1 : 1));
......
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