Commit b4c8bc7f authored by Sergey Luzyanin's avatar Sergey Luzyanin

drawing previews for sparklines

parent e7bce0cf
......@@ -4585,9 +4585,13 @@ CellArea.prototype = {
this.f = null;
this.arrSparklines = [];
this.arrCachedSparklines = [];
//for drawing preview
this.canvas = null;
this.sparklineView = null;
}
sparklineGroup.prototype.clone = function () {
sparklineGroup.prototype.clone = function (bNoCloneSparklines) {
var res = new sparklineGroup();
res.manualMax = this.manualMax;
res.manualMin = this.manualMin;
......@@ -4617,6 +4621,9 @@ CellArea.prototype = {
res.colorLow = this.colorLow ? this.colorLow : null;
res.f = this.f;
if(bNoCloneSparklines) {
return res;
}
for (var i = 0; i < this.arrSparklines.length; ++i) {
res.arrSparklines.push(this.arrSparklines[i].clone());
}
......@@ -4724,11 +4731,98 @@ CellArea.prototype = {
sparklineGroup.prototype.asc_getColorLow = function () {
return this.colorLow ? Asc.colorObjToAscColor(this.colorLow) : this.colorLow;
};
sparklineGroup.prototype.createExcellColor = function(aColor) {
var oExcellColor = null;
if(Array.isArray(aColor)) {
if(2 === aColor.length){
oExcellColor = AscCommonExcel.g_oColorManager.getThemeColor(aColor[0], aColor[1]);
}
else if(1 === aColor.length){
oExcellColor = new AscCommonExcel.RgbColor(0x00ffffff & aColor[0]);
}
}
return oExcellColor;
};
sparklineGroup.prototype.asc_createSparklineGroupByStyle = function(nStyleIndex){
var oSparklineGroup = this.clone(true);
var oStyle = AscFormat.aSparklinesStyles[nStyleIndex];
if(oStyle) {
oSparklineGroup.colorSeries = this.createExcellColor(oStyle[0]);
oSparklineGroup.colorNegative = this.createExcellColor(oStyle[1]);
oSparklineGroup.colorAxis = this.createExcellColor(0xff000000);
oSparklineGroup.colorMarkers = this.createExcellColor(oStyle[2]);
oSparklineGroup.colorFirst = this.createExcellColor(oStyle[3]);
oSparklineGroup.colorLast = this.createExcellColor(oStyle[4]);
oSparklineGroup.colorHigh = this.createExcellColor(oStyle[5]);
oSparklineGroup.colorLow = this.createExcellColor(oStyle[6]);
}
return oSparklineGroup;
};
sparklineGroup.prototype.generateCache = function(){
function createItem(value) {
return { numFormatStr: "General", isDateTimeFormat: false, val: value, isHidden: false };
}
switch(this.type){
case Asc.c_oAscSparklineType.Line: {
return [createItem(128), createItem(56), createItem(175), createItem(0), createItem(248), createItem(184)];
}
case Asc.c_oAscSparklineType.Column: {
return [createItem(88), createItem(56), createItem(144), createItem(64), createItem(-56), createItem(-104), createItem(-40), createItem(-24), createItem(-56), createItem(104), createItem(56), createItem(80), createItem(-56), createItem(88)];
}
case Asc.c_oAscSparklineType.Stacked: {
return [createItem(1), createItem(-1), createItem(-1), createItem(-2), createItem(1), createItem(1), createItem(-1), createItem(1), createItem(1), createItem(1), createItem(1), createItem(2), createItem(-1), createItem(1)];
}
}
return [];
};
sparklineGroup.prototype.asc_getThumbBySparklineGroup = function(oSparklineGroup){
// if(!this.sparklineView){
this.sparklineView = new AscFormat.CSparklineView();
var oSparkline = new sparkline();
oSparkline.oCache = this.generateCache();
this.sparklineView.initFromSparkline(oSparkline, oSparklineGroup, null);
var api_sheet = Asc['editor'];
this.sparklineView.chartSpace.setWorksheet(api_sheet.wb.getWorksheet().model);
this.sparklineView.chartSpace.extX = 100;
this.sparklineView.chartSpace.extY = 100;
this.sparklineView.chartSpace.x = 0;
this.sparklineView.chartSpace.x = 0;
AscFormat.ExecuteNoHistory(function () {
AscFormat.CheckSpPrXfrm(this.sparklineView.chartSpace);
}, this, []);
this.sparklineView.chartSpace.recalculate();
// }
if(!this.canvas) {
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;
}
}
var oGraphics = new AscCommon.CGraphics();
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");
};
/** @constructor */
function sparkline() {
this.sqref = null;
this.f = null;
this._f = null;
//for preview
this.oCache = null;
}
sparkline.prototype.clone = function () {
......@@ -6944,6 +7038,8 @@ function getCurrencyFormat(opt_cultureInfo, opt_fraction, opt_currency, opt_curr
prot["asc_getColorLast"] = prot.asc_getColorLast;
prot["asc_getColorHigh"] = prot.asc_getColorHigh;
prot["asc_getColorLow"] = prot.asc_getColorLow;
prot["asc_createSparklineGroupByStyle"] = prot.asc_createSparklineGroupByStyle;
prot["asc_getThumbBySparklineGroup"] = prot.asc_getThumbBySparklineGroup;
window['AscCommonExcel'].sparkline = sparkline;
window['AscCommonExcel'].TablePart = TablePart;
window['AscCommonExcel'].AutoFilter = AutoFilter;
......
......@@ -59,6 +59,344 @@ var c_oAscInsertOptions = Asc.c_oAscInsertOptions;
var c_oAscDeleteOptions = Asc.c_oAscDeleteOptions;
var c_oAscSelectionType = Asc.c_oAscSelectionType;
var aSparklinesStyles =
[
[
[4, -0.499984740745262],
[5, 0],
[4, -0.499984740745262],
[4, 0.39997558519241921],
[4, 0.39997558519241921],
[4, 0],
[4, 0]
],
[
[5, -0.499984740745262],
[6, 0],
[5, -0.499984740745262],
[5, 0.39997558519241921],
[5, 0.39997558519241921],
[5, 0],
[5, 0]
],
[
[6, -0.499984740745262],
[7, 0],
[6, -0.499984740745262],
[6, 0.39997558519241921],
[6, 0.39997558519241921],
[6, 0],
[6, 0]
],
[
[7, -0.499984740745262],
[8, 0],
[7, -0.499984740745262],
[7, 0.39997558519241921],
[7, 0.39997558519241921],
[7, 0],
[7, 0]
],
[
[8, -0.499984740745262],
[9, 0],
[8, -0.499984740745262],
[8, 0.39997558519241921],
[8, 0.39997558519241921],
[8, 0],
[8, 0]
],
[
[9, -0.499984740745262],
[4, 0],
[9, -0.499984740745262],
[9, 0.39997558519241921],
[9, 0.39997558519241921],
[9, 0],
[9, 0]
],
[
[4, -0.249977111117893],
[5, 0],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893]
],
[
[5, -0.249977111117893],
[6, 0],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893]
],
[
[6, -0.249977111117893],
[7, 0],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893]
],
[
[7, -0.249977111117893],
[8, 0],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893]
],
[
[8, -0.249977111117893],
[9, 0],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893]
],
[
[9, -0.249977111117893],
[4, 0],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893]
],
[
[4, 0],
[5, 0],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.249977111117893]
],
[
[5, 0],
[6, 0],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.249977111117893]
],
[
[6, 0],
[7, 0],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.249977111117893]
],
[
[7, 0],
[8, 0],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.249977111117893]
],
[
[8, 0],
[9, 0],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.249977111117893]
],
[
[9, 0],
[4, 0],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.249977111117893]
],
[
[4, 0.39997558519241921],
[0, -0.499984740745262],
[4, 0.79998168889431442],
[4, -0.249977111117893],
[4, -0.249977111117893],
[4, -0.499984740745262],
[4, -0.499984740745262]
],
[
[5, 0.39997558519241921],
[0, -0.499984740745262],
[5, 0.79998168889431442],
[5, -0.249977111117893],
[5, -0.249977111117893],
[5, -0.499984740745262],
[5, -0.499984740745262]
],
[
[6, 0.39997558519241921],
[0, -0.499984740745262],
[6, 0.79998168889431442],
[6, -0.249977111117893],
[6, -0.249977111117893],
[6, -0.499984740745262],
[6, -0.499984740745262]
],
[
[7, 0.39997558519241921],
[0, -0.499984740745262],
[7, 0.79998168889431442],
[7, -0.249977111117893],
[7, -0.249977111117893],
[7, -0.499984740745262],
[7, -0.499984740745262]
],
[
[8, 0.39997558519241921],
[0, -0.499984740745262],
[8, 0.79998168889431442],
[8, -0.249977111117893],
[8, -0.249977111117893],
[8, -0.499984740745262],
[8, -0.499984740745262]
],
[
[9, 0.39997558519241921],
[0, -0.499984740745262],
[9, 0.79998168889431442],
[9, -0.249977111117893],
[9, -0.249977111117893],
[9, -0.499984740745262],
[9, -0.499984740745262]
],
[
[1, 0.499984740745262],
[1, 0.249977111117893],
[1, 0.249977111117893],
[1, 0.249977111117893],
[1, 0.249977111117893],
[1, 0.249977111117893],
[1, 0.249977111117893]
],
[
[1, 0.34998626667073579],
[0, -0.249977111117893],
[0, -0.249977111117893],
[0, -0.249977111117893],
[0, -0.249977111117893],
[0, -0.249977111117893],
[0, -0.249977111117893]
],
[
[0xFF323232],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000]
],
[
[0xFF000000],
[0xFF0070C0],
[0xFF000000],
[0xFF0070C0],
[0xFF0070C0],
[0xFF0070C0],
[0xFF0070C0],
[0xFF0070C0]
],
[
[0xFF376092],
[0xFFD00000],
[0xFF000000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000],
[0xFFD00000]
],
[
[0xFF0070C0],
[0xFF000000],
[0xFF000000],
[0xFF000000],
[0xFF000000],
[0xFF000000],
[0xFF000000],
[0xFF000000]
],
[
[0xFF5F5F5F],
[0xFFFFB620],
[0xFF000000],
[0xFFD70077],
[0xFF5687C2],
[0xFF359CEB],
[0xFF56BE79],
[0xFFFF5055]
],
[
[0xFF5687C2],
[0xFFFFB620],
[0xFF000000],
[0xFFD70077],
[0xFF777777],
[0xFF359CEB],
[0xFF56BE79],
[0xFFFF5055]
],
[
[0xFFC6EFCE],
[0xFFFFC7CE],
[0xFF000000],
[0xFF8CADD6],
[0xFFFFDC47],
[0xFFFFEB9C],
[0xFF60D276],
[0xFFFF5367]
],
[
[0xFF00B050],
[0xFFFF0000],
[0xFF000000],
[0xFF0070C0],
[0xFFFFC000],
[0xFFFFC000],
[0xFF00B050],
[0xFFFF0000]
],
[
[3, 0],
[9, 0],
[0xFF000000],
[8, 0],
[4, 0],
[5, 0],
[6, 0],
[7, 0]
],
[
[1, 0],
[9, 0],
[0xFF000000],
[8, 0],
[4, 0],
[5, 0],
[6, 0],
[7, 0]
]
];
function isObject(what) {
return ( (what != null) && (typeof(what) == "object") );
}
......@@ -315,10 +653,16 @@ CSparklineView.prototype.initFromSparkline = function(oSparkline, oSparklineGrou
}
var ser = new asc_CChartSeria();
ser.Val.Formula = oSparkline.f;
if(oSparkline.oCache){
ser.Val.NumCache = oSparkline.oCache;
}
var chartSeries = {series: [ser], parsedHeaders: {bLeft: false, bTop: false}};
var chart_space = AscFormat.DrawingObjectsController.prototype._getChartSpace(chartSeries, settings, true);
chart_space.setBDeleted(false);
if(worksheetView){
chart_space.setWorksheet(worksheetView.model);
}
chart_space.displayHidden = oSparklineGroup.displayHidden;
chart_space.displayEmptyCellsAs = oSparklineGroup.displayEmptyCellsAs;
......@@ -626,6 +970,8 @@ CSparklineView.prototype.initFromSparkline = function(oSparkline, oSparklineGrou
}
this.chartSpace = chart_space;
if(worksheetView){
var oBBox = oSparkline.sqref;
this.col = oBBox.c1;
this.row = oBBox.r1;
......@@ -639,6 +985,7 @@ CSparklineView.prototype.initFromSparkline = function(oSparkline, oSparklineGrou
this.chartSpace.spPr.xfrm.setExtX(this.extX*nSparklineMultiplier);
this.chartSpace.spPr.xfrm.setExtY(this.extY*nSparklineMultiplier);
this.chartSpace.recalculate();
}
}, this, []);
};
......@@ -4088,7 +4435,9 @@ function CoordsManager(ws) {
}
}
//--------------------------------------------------------export----------------------------------------------------
//--------------------------------------------------------export----------------------------------------------------
var prot;
window['AscFormat'] = window['AscFormat'] || {};
window['Asc'] = window['Asc'] || {};
......@@ -4134,4 +4483,6 @@ function CoordsManager(ws) {
window["AscFormat"].GraphicOption = GraphicOption;
window["AscFormat"].DrawingObjects = DrawingObjects;
window["AscFormat"].ClickCounter = ClickCounter;
window["AscFormat"].aSparklinesStyles = aSparklinesStyles;
window["AscFormat"].CSparklineView = CSparklineView;
})(window);
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