Commit f21228bd authored by Alexander.Trofimov's avatar Alexander.Trofimov

support top10 in conditional formatting

parent 0e04bf2a
...@@ -1901,7 +1901,7 @@ function angleInterfaceToFormat(val) ...@@ -1901,7 +1901,7 @@ function angleInterfaceToFormat(val)
function getUniqueKeys(array) { function getUniqueKeys(array) {
var i, o = {}; var i, o = {};
for (i = 0; i < array.length; ++i) { for (i = 0; i < array.length; ++i) {
o[array[i]] = o.hasOwnProperty(array[i]); o[array[i].v] = o.hasOwnProperty(array[i].v);
} }
return o; return o;
} }
...@@ -3480,15 +3480,14 @@ Woorksheet.prototype.initPostOpen = function(handlers){ ...@@ -3480,15 +3480,14 @@ Woorksheet.prototype.initPostOpen = function(handlers){
this._setHandlersTablePart(); this._setHandlersTablePart();
}; };
Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref) { Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref) {
var res = [];
var aValues = [], aCells = []; var aValues = [], aCells = [];
var tmp;
this.getRange3(sqref.r1, sqref.c1, sqref.r2, sqref.c2)._setPropertyNoEmpty(null, null, function(c) { this.getRange3(sqref.r1, sqref.c1, sqref.r2, sqref.c2)._setPropertyNoEmpty(null, null, function(c) {
if (!c.isEmptyTextString()) { if (!c.isEmptyTextString()) {
aCells.push(c); res.push({c: c, v: c.getValueWithoutFormat()});
aValues.push(c.getValueWithoutFormat());
} }
}); });
return {c: aCells, v: aValues}; return res;
}; };
Woorksheet.prototype._updateConditionalFormatting = function(range) { Woorksheet.prototype._updateConditionalFormatting = function(range) {
var oGradient = null; var oGradient = null;
...@@ -3496,7 +3495,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3496,7 +3495,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
var aRules, oRule; var aRules, oRule;
var oRuleElement = null; var oRuleElement = null;
var o; var o;
var i, j, cell, sqref, values, tmp, min, max, dxf, compareFunction; var i, j, cell, sqref, values, value, tmp, min, max, dxf, compareFunction;
for (i = 0; i < aCFs.length; ++i) { for (i = 0; i < aCFs.length; ++i) {
sqref = aCFs[i].sqref; sqref = aCFs[i].sqref;
// ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx) // ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx)
...@@ -3508,9 +3507,9 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3508,9 +3507,9 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
for (j = 0; j < aRules.length; ++j) { for (j = 0; j < aRules.length; ++j) {
oRule = aRules[j]; oRule = aRules[j];
// ToDo aboveAverage, beginsWith, cellIs, containsBlanks, containsErrors, // ToDo aboveAverage, cellIs, containsBlanks, containsErrors,
// ToDo dataBar, endsWith, expression, iconSet, notContainsBlanks, // ToDo dataBar, expression, iconSet, notContainsBlanks,
// ToDo notContainsErrors, timePeriod, top10 (page 2679) // ToDo notContainsErrors, timePeriod (page 2679)
if (Asc.ECfType.colorScale === oRule.type) { if (Asc.ECfType.colorScale === oRule.type) {
if (1 !== oRule.aRuleElements.length) { if (1 !== oRule.aRuleElements.length) {
break; break;
...@@ -3523,28 +3522,54 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3523,28 +3522,54 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
max = -Number.MAX_VALUE; max = -Number.MAX_VALUE;
values = this._getValuesForConditionalFormatting(sqref); values = this._getValuesForConditionalFormatting(sqref);
for (cell = 0; cell < values.v.length; ++cell) { for (cell = 0; cell < values.v.length; ++cell) {
if (CellValueType.Number === values.c[cell].getType() && !isNaN(tmp = parseFloat(values.v[cell]))) { value = values[cell];
values.v[cell] = tmp; if (CellValueType.Number === value.c.getType() && !isNaN(tmp = parseFloat(value.v))) {
value.v = tmp;
min = Math.min(min, tmp); min = Math.min(min, tmp);
max = Math.max(max, tmp); max = Math.max(max, tmp);
} else { } else {
values.v[cell] = null; value.v = null;
} }
} }
// ToDo CFVO Type (formula, max, min, num, percent, percentile) (page 2681) // ToDo CFVO Type (formula, max, min, num, percent, percentile) (page 2681)
// ToDo support 3 colors in rule // ToDo support 3 colors in rule
if (0 < values.c.length && 2 === oRuleElement.aColors.length) { if (0 < values.length && 2 === oRuleElement.aColors.length) {
oGradient = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]); oGradient = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]);
oGradient.init(min, max); oGradient.init(min, max);
for (cell = 0; cell < values.c.length; ++cell) { for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
dxf = null; dxf = null;
if (null !== values.v[cell]) { if (null !== value.v) {
dxf = new AscCommonExcel.CellXfs(); dxf = new AscCommonExcel.CellXfs();
dxf.fill = new AscCommonExcel.Fill({bg: oGradient.calculateColor(values.v[cell])}); dxf.fill = new AscCommonExcel.Fill({bg: oGradient.calculateColor(value.v)});
}
value.c.setConditionalFormattingStyle(dxf);
}
} }
values.c[cell].setConditionalFormattingStyle(dxf); } else if (Asc.ECfType.top10 === oRule.type) {
if (oRule.rank > 0 && oRule.dxf) {
values = this._getValuesForConditionalFormatting(sqref);
o = oRule.bottom ? -Number.MAX_VALUE : Number.MAX_VALUE;
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
if (CellValueType.Number === value.c.getType() && !isNaN(tmp = parseFloat(value.v))) {
value.v = tmp;
} else {
value.v = o;
}
}
values.sort((function(condition) {
return function(v1, v2) {
return condition* (v2.v - v1.v);
}
})(oRule.bottom ? -1 : 1));
tmp = 0;
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
value.c.setConditionalFormattingStyle((o !== value.v && tmp < oRule.rank) ? (++tmp && oRule.dxf) : null);
} }
} }
} else { } else {
...@@ -3556,7 +3581,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3556,7 +3581,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
switch (oRule.type) { switch (oRule.type) {
case Asc.ECfType.duplicateValues: case Asc.ECfType.duplicateValues:
case Asc.ECfType.uniqueValues: case Asc.ECfType.uniqueValues:
o = getUniqueKeys(values.v); o = getUniqueKeys(values);
compareFunction = (function(obj, condition){ compareFunction = (function(obj, condition){
return function(val) { return function(val) {
return condition === obj[val]; return condition === obj[val];
...@@ -3597,8 +3622,8 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3597,8 +3622,8 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
break; break;
} }
for (cell = 0; cell < values.c.length; ++cell) { for (cell = 0; cell < values.length; ++cell) {
values.c[cell].setConditionalFormattingStyle(compareFunction(values.v[cell]) ? oRule.dxf : null); values[cell].c.setConditionalFormattingStyle(compareFunction(values[cell].v) ? oRule.dxf : null);
} }
} }
} }
......
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