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

update draw sparklines styles

parent bb7eb4c4
...@@ -4986,12 +4986,12 @@ CellArea.prototype = { ...@@ -4986,12 +4986,12 @@ CellArea.prototype = {
return oExcellColor; return oExcellColor;
}; };
sparklineGroup.prototype.generateCache = function () { sparklineGroup.prototype._generateThumbCache = function () {
function createItem(value) { function createItem(value) {
return {numFormatStr: "General", isDateTimeFormat: false, val: value, isHidden: false}; return {numFormatStr: "General", isDateTimeFormat: false, val: value, isHidden: false};
} }
switch (this.type) { switch (this.asc_getType()) {
case Asc.c_oAscSparklineType.Line: { case Asc.c_oAscSparklineType.Line: {
return [createItem(128), createItem(56), createItem(175), createItem(0), createItem(248), createItem(184)]; return [createItem(128), createItem(56), createItem(175), createItem(0), createItem(248), createItem(184)];
} }
...@@ -5009,35 +5009,22 @@ CellArea.prototype = { ...@@ -5009,35 +5009,22 @@ CellArea.prototype = {
return []; return [];
}; };
sparklineGroup.prototype.getThumbBySparklineGroup = function (oSparklineGroup) { sparklineGroup.prototype._drawThumbBySparklineGroup = function (oSparkline, oSparklineGroup, oSparklineView, oGraphics) {
if (!this.canvas) { oSparklineView.initFromSparkline(oSparkline, oSparklineGroup, null, true);
this.canvas = document.createElement('canvas');
if (AscCommon.AscBrowser.isRetina) {
this.canvas.width = 100;
this.canvas.height = 100;
} else {
this.canvas.width = 50;
this.canvas.height = 50;
}
}
// if(!this.sparklineView){
this.sparklineView = new AscFormat.CSparklineView();
var oSparkline = new sparkline();
oSparkline.oCache = this.generateCache();
this.sparklineView.initFromSparkline(oSparkline, oSparklineGroup, null, true);
var api_sheet = Asc['editor']; var api_sheet = Asc['editor'];
AscFormat.ExecuteNoHistory(function () { AscFormat.ExecuteNoHistory(function () {
this.sparklineView.chartSpace.setWorksheet(api_sheet.wb.getWorksheet().model); oSparklineView.chartSpace.setWorksheet(api_sheet.wb.getWorksheet().model);
}, this, []); }, this, []);
this.sparklineView.chartSpace.extX = 100; oSparklineView.chartSpace.extX = 100;
this.sparklineView.chartSpace.extY = 100; oSparklineView.chartSpace.extY = 100;
this.sparklineView.chartSpace.x = 0; oSparklineView.chartSpace.x = 0;
this.sparklineView.chartSpace.y = 0; oSparklineView.chartSpace.y = 0;
if (oSparklineGroup.type === Asc.c_oAscSparklineType.Stacked) { var type = oSparklineGroup.asc_getType();
if (type === Asc.c_oAscSparklineType.Stacked) {
AscFormat.ExecuteNoHistory(function () { AscFormat.ExecuteNoHistory(function () {
var oPlotArea = this.sparklineView.chartSpace.chart.plotArea; var oPlotArea = oSparklineView.chartSpace.chart.plotArea;
if (!oPlotArea.layout) { if (!oPlotArea.layout) {
oPlotArea.setLayout(new AscFormat.CLayout()); oPlotArea.setLayout(new AscFormat.CLayout());
} }
...@@ -5050,9 +5037,9 @@ CellArea.prototype = { ...@@ -5050,9 +5037,9 @@ CellArea.prototype = {
oPlotArea.layout.setY(fPos); oPlotArea.layout.setY(fPos);
}, this, []); }, this, []);
} }
if (oSparklineGroup.type === Asc.c_oAscSparklineType.Line) { if (type === Asc.c_oAscSparklineType.Line) {
AscFormat.ExecuteNoHistory(function () { AscFormat.ExecuteNoHistory(function () {
var oPlotArea = this.sparklineView.chartSpace.chart.plotArea; var oPlotArea = oSparklineView.chartSpace.chart.plotArea;
if (!oPlotArea.layout) { if (!oPlotArea.layout) {
oPlotArea.setLayout(new AscFormat.CLayout()); oPlotArea.setLayout(new AscFormat.CLayout());
} }
...@@ -5064,66 +5051,54 @@ CellArea.prototype = { ...@@ -5064,66 +5051,54 @@ CellArea.prototype = {
}, this, []); }, this, []);
} }
AscFormat.ExecuteNoHistory(function () { AscFormat.ExecuteNoHistory(function () {
AscFormat.CheckSpPrXfrm(this.sparklineView.chartSpace); AscFormat.CheckSpPrXfrm(oSparklineView.chartSpace);
}, this, []); }, this, []);
this.sparklineView.chartSpace.recalculate(); oSparklineView.chartSpace.recalculate();
this.sparklineView.chartSpace.brush = AscFormat.CreateSolidFillRGBA(0xFF, 0xFF, 0xFF, 0xFF); oSparklineView.chartSpace.brush = AscFormat.CreateSolidFillRGBA(0xFF, 0xFF, 0xFF, 0xFF);
// }
var oGraphics = new AscCommon.CGraphics(); oSparklineView.chartSpace.draw(oGraphics);
oGraphics.init(this.canvas.getContext('2d'), this.canvas.width, this.canvas.height,
this.sparklineView.chartSpace.extX, this.sparklineView.chartSpace.extY);
oGraphics.m_oFontManager = AscCommon.g_fontManager;
oGraphics.transform(1, 0, 0, 1, 0, 0);
this.sparklineView.chartSpace.draw(oGraphics);
return this.canvas.toDataURL("image/png");
}; };
sparklineGroup.prototype.isEqualColors = function (oSparklineGroup) { sparklineGroup.prototype._isEqualStyle = function (oSparklineGroup) {
if (this.colorSeries && !this.colorSeries.isEqual(oSparklineGroup.colorSeries) || var equalColors = function (color1, color2) {
!this.colorSeries && oSparklineGroup.colorSeries) { return color1 ? color1.isEqual(color2) : color1 === color2;
return false; };
} return equalColors(this.colorSeries, oSparklineGroup.colorSeries) &&
if (this.colorNegative && !this.colorNegative.isEqual(oSparklineGroup.colorNegative) || equalColors(this.colorNegative, oSparklineGroup.colorNegative) &&
!this.colorNegative && oSparklineGroup.colorNegative) { equalColors(this.colorMarkers, oSparklineGroup.colorMarkers) &&
return false; equalColors(this.colorFirst, oSparklineGroup.colorFirst) &&
} equalColors(this.colorLast, oSparklineGroup.colorLast) &&
/*if(this.colorAxis && !this.colorAxis.isEqual(oSparklineGroup.colorAxis) || !this.colorAxis && oSparklineGroup.colorAxis){ equalColors(this.colorHigh, oSparklineGroup.colorHigh) && equalColors(this.colorLow, oSparklineGroup.colorLow);
return false;
}*/
if (this.colorMarkers && !this.colorMarkers.isEqual(oSparklineGroup.colorMarkers) ||
!this.colorMarkers && oSparklineGroup.colorMarkers) {
return false;
}
if (this.colorFirst && !this.colorFirst.isEqual(oSparklineGroup.colorFirst) ||
!this.colorFirst && oSparklineGroup.colorFirst) {
return false;
}
if (this.colorLast && !this.colorLast.isEqual(oSparklineGroup.colorLast) ||
!this.colorLast && oSparklineGroup.colorLast) {
return false;
}
if (this.colorHigh && !this.colorHigh.isEqual(oSparklineGroup.colorHigh) ||
!this.colorHigh && oSparklineGroup.colorHigh) {
return false;
}
if (this.colorLow && !this.colorLow.isEqual(oSparklineGroup.colorLow) ||
!this.colorLow && oSparklineGroup.colorLow) {
return false;
}
return true;
}; };
sparklineGroup.prototype.asc_getStyles = function () { sparklineGroup.prototype.asc_getStyles = function () {
var aRet = []; var aRet = [];
var nStyleIndex = -1; var nStyleIndex = -1;
var oSparklineGroup = this.clone(true); var oSparklineGroup = this.clone(true);
var canvas = document.createElement('canvas');
canvas.width = 50;
canvas.height = 50;
if (AscCommon.AscBrowser.isRetina) {
canvas.width >>= 1;
canvas.height >>= 1;
}
var oSparklineView = new AscFormat.CSparklineView();
var oSparkline = new sparkline();
oSparkline.oCache = this._generateThumbCache();
var oGraphics = new AscCommon.CGraphics();
oGraphics.init(canvas.getContext('2d'), canvas.width, canvas.height, 100, 100);
oGraphics.m_oFontManager = AscCommon.g_fontManager;
oGraphics.transform(1, 0, 0, 1, 0, 0);
for (var i = 0; i < 36; ++i) { for (var i = 0; i < 36; ++i) {
oSparklineGroup.asc_setStyle(i); oSparklineGroup.asc_setStyle(i);
if (nStyleIndex === -1 && this.isEqualColors(oSparklineGroup)) { if (nStyleIndex === -1 && this._isEqualStyle(oSparklineGroup)) {
nStyleIndex = i; nStyleIndex = i;
} }
aRet.push(this.getThumbBySparklineGroup(oSparklineGroup));
this._drawThumbBySparklineGroup(oSparkline, oSparklineGroup, oSparklineView, oGraphics);
aRet.push(canvas.toDataURL("image/png"));
} }
aRet.push(nStyleIndex); aRet.push(nStyleIndex);
return aRet; return aRet;
......
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