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 @@ ...@@ -31,6 +31,8 @@
this.SqRef = null; this.SqRef = null;
this.aRules = []; this.aRules = [];
this.SqRefRange = null;
return this; return this;
} }
...@@ -121,16 +123,22 @@ ...@@ -121,16 +123,22 @@
return this; return this;
} }
function CGradient () { function CGradient (c1, c2) {
if ( !(this instanceof CGradient) ) { if ( !(this instanceof CGradient) ) {
return new CGradient (); return new CGradient (c1, c2);
} }
this.MaxColorIndex = 512; this.MaxColorIndex = 512;
this.base_shift = 8; this.base_shift = 8;
this.c1 = null; this.c1 = c1;
this.c2 = null; 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; return this;
} }
...@@ -139,33 +147,27 @@ ...@@ -139,33 +147,27 @@
/** @type CGradient */ /** @type CGradient */
constructor: CGradient, constructor: CGradient,
generate: function (count) { init: function (min, max) {
if (null === this.c1 || null === this.c2) var distance = max - min;
return null;
this.min = min;
var result = []; this.max = max;
var i, indexColor; this.koef = this.MaxColorIndex / (2.0 * distance);
var tmp = this.MaxColorIndex / (2.0 * (count - 1)); this.r1 = this.c1.getR();
for (i = 0; i < count; ++i) { this.g1 = this.c1.getG();
indexColor = parseInt(i * tmp); this.b1 = this.c1.getB();
result[i] = this.calculateColor(indexColor); this.r2 = this.c2.getR();
} this.g2 = this.c2.getG();
this.b2 = this.c2.getB();
return result;
}, },
calculateColor: function (indexColor) { calculateColor: function (indexColor) {
var ret = new CAscColor(); indexColor = parseInt((indexColor - this.min) * this.koef);
var r1 = this.c1.getR();
var g1 = this.c1.getG(); var r = (this.r1 + ((FT_Common.IntToUInt(this.r2 - this.r1) * indexColor) >> this.base_shift)) & 0xFF;
var b1 = this.c1.getB(); var g = (this.g1 + ((FT_Common.IntToUInt(this.g2 - this.g1) * indexColor) >> this.base_shift)) & 0xFF;
var r2 = this.c2.getR(); var b = (this.b1 + ((FT_Common.IntToUInt(this.b2 - this.b1) * indexColor) >> this.base_shift)) & 0xFF;
var g2 = this.c2.getG(); //console.log("index=" + indexColor + ": r=" + r + " g=" + g + " b=" + b);
var b2 = this.c2.getB(); return new RgbColor((r << 16) + (g << 8) + b);
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;
} }
}; };
......
...@@ -4843,7 +4843,8 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs, ...@@ -4843,7 +4843,8 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
else if (c_oSerWorksheetsTypes.ConditionalFormatting === type) { else if (c_oSerWorksheetsTypes.ConditionalFormatting === type) {
oConditionalFormatting = new Asc.CConditionalFormatting(); oConditionalFormatting = new Asc.CConditionalFormatting();
res = this.bcr.Read1(length, function (t, l) { 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); oWorksheet.aConditionalFormatting.push(oConditionalFormatting);
} }
...@@ -5471,14 +5472,16 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs, ...@@ -5471,14 +5472,16 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
res = c_oSerConstants.ReadUnknown; res = c_oSerConstants.ReadUnknown;
return res; return res;
}; };
this.ReadConditionalFormatting = function (type, length, oConditionalFormatting) { this.ReadConditionalFormatting = function (type, length, oConditionalFormatting, functionGetRange2) {
var res = c_oSerConstants.ReadOk; var res = c_oSerConstants.ReadOk;
var oThis = this; var oThis = this;
var oConditionalFormattingRule = null; var oConditionalFormattingRule = null;
if (c_oSer_ConditionalFormatting.Pivot === type) if (c_oSer_ConditionalFormatting.Pivot === type)
oConditionalFormatting.Pivot = this.stream.GetBool(); 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.SqRef = this.stream.GetString2LE(length);
oConditionalFormatting.SqRefRange = functionGetRange2(oConditionalFormatting.SqRef);
}
else if (c_oSer_ConditionalFormatting.ConditionalFormattingRule === type) { else if (c_oSer_ConditionalFormatting.ConditionalFormattingRule === type) {
oConditionalFormattingRule = new Asc.CConditionalFormattingRule(); oConditionalFormattingRule = new Asc.CConditionalFormattingRule();
res = this.bcr.Read1(length, function (t, l) { res = this.bcr.Read1(length, function (t, l) {
......
...@@ -1037,9 +1037,70 @@ ...@@ -1037,9 +1037,70 @@
this._cleanCellsTextMetricsCache(); this._cleanCellsTextMetricsCache();
this._prepareCellTextMetricsCache(this.visibleRange); this._prepareCellTextMetricsCache(this.visibleRange);
this.autoFilters.addFiltersAfterOpen(this); this.autoFilters.addFiltersAfterOpen(this);
this._initConditionalFormatting();
// initializing is completed // initializing is completed
this._trigger("initialized"); 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 () { _calcEmSize: function () {
// set default worksheet header font for calculations // set default worksheet header font for calculations
var c = this.settings.cells; 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