Commit 979e0dec authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

ConditionalFormatting для colorScale

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47261 954022d7-b5bf-4e40-9824-e11837661b57
parent 8a6e20d5
......@@ -31,6 +31,8 @@
this.SqRef = null;
this.aRules = [];
this.SqRefRange = null;
return this;
}
......@@ -121,16 +123,22 @@
return this;
}
function CGradient () {
function CGradient (c1, c2) {
if ( !(this instanceof CGradient) ) {
return new CGradient ();
return new CGradient (c1, c2);
}
this.MaxColorIndex = 512;
this.base_shift = 8;
this.c1 = null;
this.c2 = null;
this.c1 = c1;
this.c2 = c2;
this.min = this.max = 0;
this.koef = null;
this.r1 = this.r2 = 0;
this.g1 = this.g2 = 0;
this.b1 = this.b2 = 0;
return this;
}
......@@ -139,33 +147,27 @@
/** @type CGradient */
constructor: CGradient,
generate: function (count) {
if (null === this.c1 || null === this.c2)
return null;
var result = [];
var i, indexColor;
var tmp = this.MaxColorIndex / (2.0 * (count - 1));
for (i = 0; i < count; ++i) {
indexColor = parseInt(i * tmp);
result[i] = this.calculateColor(indexColor);
}
return result;
init: function (min, max) {
var distance = max - min;
this.min = min;
this.max = max;
this.koef = this.MaxColorIndex / (2.0 * distance);
this.r1 = this.c1.getR();
this.g1 = this.c1.getG();
this.b1 = this.c1.getB();
this.r2 = this.c2.getR();
this.g2 = this.c2.getG();
this.b2 = this.c2.getB();
},
calculateColor: function (indexColor) {
var ret = new CAscColor();
var r1 = this.c1.getR();
var g1 = this.c1.getG();
var b1 = this.c1.getB();
var r2 = this.c2.getR();
var g2 = this.c2.getG();
var b2 = this.c2.getB();
ret.r = (r1 + ((FT_Common.IntToUInt(r2 - r1) * indexColor) >> this.base_shift)) & 0xFFFF;
ret.g = (g1 + ((FT_Common.IntToUInt(g2 - g1) * indexColor) >> this.base_shift)) & 0xFFFF;
ret.b = (b1 + ((FT_Common.IntToUInt(b2 - b1) * indexColor) >> this.base_shift)) & 0xFFFF;
return ret;
indexColor = parseInt((indexColor - this.min) * this.koef);
var r = (this.r1 + ((FT_Common.IntToUInt(this.r2 - this.r1) * indexColor) >> this.base_shift)) & 0xFF;
var g = (this.g1 + ((FT_Common.IntToUInt(this.g2 - this.g1) * indexColor) >> this.base_shift)) & 0xFF;
var b = (this.b1 + ((FT_Common.IntToUInt(this.b2 - this.b1) * indexColor) >> this.base_shift)) & 0xFF;
//console.log("index=" + indexColor + ": r=" + r + " g=" + g + " b=" + b);
return new RgbColor((r << 16) + (g << 8) + b);
}
};
......
......@@ -4843,7 +4843,8 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
else if (c_oSerWorksheetsTypes.ConditionalFormatting === type) {
oConditionalFormatting = new Asc.CConditionalFormatting();
res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadConditionalFormatting(t, l, oConditionalFormatting);
return oThis.ReadConditionalFormatting(t, l, oConditionalFormatting,
function (sRange) {return oWorksheet.getRange2(sRange);});
});
oWorksheet.aConditionalFormatting.push(oConditionalFormatting);
}
......@@ -5471,14 +5472,16 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
res = c_oSerConstants.ReadUnknown;
return res;
};
this.ReadConditionalFormatting = function (type, length, oConditionalFormatting) {
this.ReadConditionalFormatting = function (type, length, oConditionalFormatting, functionGetRange2) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
var oConditionalFormattingRule = null;
if (c_oSer_ConditionalFormatting.Pivot === type)
oConditionalFormatting.Pivot = this.stream.GetBool();
else if (c_oSer_ConditionalFormatting.SqRef === type)
else if (c_oSer_ConditionalFormatting.SqRef === type) {
oConditionalFormatting.SqRef = this.stream.GetString2LE(length);
oConditionalFormatting.SqRefRange = functionGetRange2(oConditionalFormatting.SqRef);
}
else if (c_oSer_ConditionalFormatting.ConditionalFormattingRule === type) {
oConditionalFormattingRule = new Asc.CConditionalFormattingRule();
res = this.bcr.Read1(length, function (t, l) {
......
......@@ -1037,9 +1037,70 @@
this._cleanCellsTextMetricsCache();
this._prepareCellTextMetricsCache(this.visibleRange);
this.autoFilters.addFiltersAfterOpen(this);
this._initConditionalFormatting();
// initializing is completed
this._trigger("initialized");
},
_initConditionalFormatting: function () {
var oGradient = null;
var aCFs = this.model.aConditionalFormatting;
var aRules = null;
var oRule = null;
var oRuleElement = null;
var min = Number.MAX_VALUE;
var max = Number.MIN_VALUE, tmp;
var arrayCells = [];
for (var i in aCFs) {
if (!aCFs.hasOwnProperty(i) )
continue;
aRules = aCFs[i].aRules;
if (0 >= aRules.length)
continue;
for (var j in aRules) {
if (!aRules.hasOwnProperty(j))
continue;
oRule = aRules[j];
// ToDo aboveAverage, beginsWith, cellIs, containsBlanks, containsErrors,
// ToDo containsText, dataBar, duplicateValues, endsWith, expression, iconSet, notContainsBlanks,
// ToDo notContainsErrors, notContainsText, timePeriod, top10, uniqueValues (page 2679)
switch (oRule.Type) {
case "colorScale":
if (1 !== oRule.aRuleElements.length)
break;
oRuleElement = oRule.aRuleElements[0];
if (!(oRuleElement instanceof asc.CColorScale))
break;
aCFs[i].SqRefRange._setPropertyNoEmpty(null, null, function (c) {
if (CellValueType.Number === c.getType()) {
tmp = parseInt(c.getValueWithoutFormat());
if (isNaN(tmp))
return;
arrayCells.push({cell: c, val: tmp});
min = Math.min(min, tmp);
max = Math.max(max, tmp);
}
});
if (0 < arrayCells.length) {
oGradient = new asc.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]);
oGradient.init(min, max);
for (var cell in arrayCells) {
if (arrayCells.hasOwnProperty(cell)) {
arrayCells[cell].cell.setFill(oGradient.calculateColor(arrayCells[cell].val));
}
}
}
break;
}
arrayCells.splice(0, arrayCells.length);
min = Number.MAX_VALUE;
max = Number.MIN_VALUE;
}
}
},
_calcEmSize: function () {
// set default worksheet header font for calculations
var c = this.settings.cells;
......
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