Commit 5ca5094c authored by Sergey Luzyanin's avatar Sergey Luzyanin

Merge branch 'release/4.0.1' into develop

parents b7549732 a7f33a1f
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
* @param {number} nFromRow * @param {number} nFromRow
* @param {number} nToCol * @param {number} nToCol
* @param {number} nToRow * @param {number} nToRow
* @returns {ApiCahrt}
*/ */
ApiWorksheet.prototype.AddChart = ApiWorksheet.prototype.AddChart =
function (sDataRange, bInRows, sType, nStyleIndex, nFromCol, nFromRow, nToCol, nToRow) { function (sDataRange, bInRows, sType, nStyleIndex, nFromCol, nFromRow, nToCol, nToRow) {
...@@ -293,6 +294,7 @@ ...@@ -293,6 +294,7 @@
if (AscFormat.isRealNumber(nStyleIndex)) { if (AscFormat.isRealNumber(nStyleIndex)) {
oChart.setStyle(nStyleIndex); oChart.setStyle(nStyleIndex);
} }
return new ApiChart(oChart);
}; };
/** /**
...@@ -364,6 +366,185 @@ ...@@ -364,6 +366,185 @@
}; };
ApiChart.prototype.CreateTitle = function(sTitle, nFontSize){
if(!this.Chart)
{
return null;
}
if(typeof sTitle === "string" && sTitle.length > 0){
var oTitle = new AscFormat.CTitle();
oTitle.setTx(new AscFormat.CChartText());
oTitle.setOverlay(false);
var oTextBody = AscFormat.CreateTextBodyFromString(sTitle, this.Chart.getDrawingDocument(), oTitle.tx);
if(AscFormat.isRealNumber(nFontSize)){
oTextBody.content.Set_ApplyToAll(true);
oTextBody.content.Paragraph_Add(new ParaTextPr({ FontSize : nFontSize}));
oTextBody.content.Set_ApplyToAll(false);
}
oTitle.tx.setRich(oTextBody);
return oTitle;
}
return null;
};
/**
* Specifies a chart title
* @param {string} sTitle
* @param {number} nFontSize
*/
ApiChart.prototype.SetTitle = function (sTitle, nFontSize)
{
if(this.Chart)
{
this.Chart.chart.setTitle(this.CreateTitle(sTitle, nFontSize));
}
};
/**
* Specifies a horizontal axis title
* @param {string} sTitle
* @param {number} nFontSize
* */
ApiChart.prototype.SetHorAxisTitle = function (sTitle, nFontSize)
{
if(this.Chart)
{
var horAxis = this.Chart.chart.plotArea.getHorizontalAxis();
if(horAxis)
{
horAxis.setTitle(this.CreateTitle(sTitle, nFontSize));
}
}
};
/**
* Specifies a vertical axis title
* @param {string} sTitle
* @param {number} nFontSize
* */
ApiChart.prototype.SetVerAxisTitle = function (sTitle, nFontSize)
{
if(this.Chart)
{
var verAxis = this.Chart.chart.plotArea.getVerticalAxis();
if(verAxis)
{
if(typeof sTitle === "string" && sTitle.length > 0)
{
verAxis.setTitle(this.CreateTitle(sTitle, nFontSize));
if(verAxis.title){
var _body_pr = new AscFormat.CBodyPr();
_body_pr.reset();
if(!verAxis.title.txPr)
{
verAxis.title.setTxPr(AscFormat.CreateTextBodyFromString("", this.Chart.getDrawingDocument(), verAxis.title));
}
var _text_body = verAxis.title.txPr;
_text_body.setBodyPr(_body_pr);
verAxis.title.setOverlay(false);
}
}
else
{
verAxis.setTitle(null);
}
}
}
};
/**
* Specifies a legend position
* @param {"left" | "top" | "right" | "bottom" | "none"} sLegendPos
* */
ApiChart.prototype.SetLegendPos = function(sLegendPos)
{
if(this.Chart && this.Chart.chart)
{
if(sLegendPos === "none")
{
if(this.Chart.chart.legend)
{
this.Chart.chart.setLegend(null);
}
}
else
{
var nLegendPos = null;
switch(sLegendPos)
{
case "left":
{
nLegendPos = Asc.c_oAscChartLegendShowSettings.left;
break;
}
case "top":
{
nLegendPos = Asc.c_oAscChartLegendShowSettings.top;
break;
}
case "right":
{
nLegendPos = Asc.c_oAscChartLegendShowSettings.right;
break;
}
case "bottom":
{
nLegendPos = Asc.c_oAscChartLegendShowSettings.bottom;
break;
}
}
if(null !== nLegendPos)
{
if(!this.Chart.chart.legend)
{
this.Chart.chart.setLegend(new AscFormat.CLegend());
}
if(this.Chart.chart.legend.legendPos !== nLegendPos)
this.Chart.chart.legend.setLegendPos(nLegendPos);
if(this.Chart.chart.legend.overlay !== false)
{
this.Chart.chart.legend.setOverlay(false);
}
}
}
}
};
/**
* Spicifies a show options for data labels
* @param {boolean} bShowSerName
* @param {boolean} bShowCatName
* @param {boolean} bShowVal
* */
ApiChart.prototype.SetShowDataLabels = function(bShowSerName, bShowCatName, bShowVal)
{
if(this.Chart && this.Chart.chart && this.Chart.chart.plotArea && this.Chart.chart.plotArea.charts[0])
{
var oChart = this.Chart.chart.plotArea.charts[0];
if(false == bShowSerName && false == bShowCatName && false == bShowVal)
{
if(oChart.dLbls)
{
oChart.setDLbls(null);
}
}
if(!oChart.dLbls)
{
oChart.setDLbls(new AscFormat.CDLbls());
}
oChart.dLbls.setSeparator(",");
oChart.dLbls.setShowSerName(true == bShowSerName);
oChart.dLbls.setShowCatName(true == bShowCatName);
oChart.dLbls.setShowVal(true == bShowVal);
oChart.dLbls.setShowLegendKey(false);
//oChart.dLbls.setShowPercent(false);
oChart.dLbls.setShowBubbleSize(false);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Export // Export
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -385,4 +566,10 @@ ...@@ -385,4 +566,10 @@
ApiRange.prototype["SetFontName"] = ApiRange.prototype.SetFontName; ApiRange.prototype["SetFontName"] = ApiRange.prototype.SetFontName;
ApiRange.prototype["SetAlignVertical"] = ApiRange.prototype.SetAlignVertical; ApiRange.prototype["SetAlignVertical"] = ApiRange.prototype.SetAlignVertical;
ApiRange.prototype["SetAlignHorizontal"] = ApiRange.prototype.SetAlignHorizontal; ApiRange.prototype["SetAlignHorizontal"] = ApiRange.prototype.SetAlignHorizontal;
ApiChart.prototype["SetTitle"] = ApiChart.prototype.SetTitle;
ApiChart.prototype["SetHorAxisTitle"] = ApiChart.prototype.SetHorAxisTitle;
ApiChart.prototype["SetVerAxisTitle"] = ApiChart.prototype.SetVerAxisTitle;
ApiChart.prototype["SetLegendPos"] = ApiChart.prototype.SetLegendPos;
ApiChart.prototype["SetShowDataLabels"] = ApiChart.prototype.SetShowDataLabels;
}(window, null)); }(window, null));
...@@ -613,9 +613,11 @@ ...@@ -613,9 +613,11 @@
* @param {Array} aCatNames * @param {Array} aCatNames
* @param {EMU} nWidth * @param {EMU} nWidth
* @param {EMU} nHeight * @param {EMU} nHeight
* @param {EMU} nHeight
* @param {number} nStyleIndex
* @returns {ApiChart} * @returns {ApiChart}
* */ * */
Api.prototype.CreateChart = function(sType, aSeries, aSeriesNames, aCatNames, nWidth, nHeight) Api.prototype.CreateChart = function(sType, aSeries, aSeriesNames, aCatNames, nWidth, nHeight, nStyleIndex)
{ {
var oDrawingDocument = private_GetDrawingDocument(); var oDrawingDocument = private_GetDrawingDocument();
var oLogicDocument = private_GetLogicDocument(); var oLogicDocument = private_GetLogicDocument();
...@@ -782,6 +784,9 @@ ...@@ -782,6 +784,9 @@
oChartSpace.setBDeleted(false); oChartSpace.setBDeleted(false);
oChartSpace.extX = nW; oChartSpace.extX = nW;
oChartSpace.extY = nH; oChartSpace.extY = nH;
if(AscFormat.isRealNumber(nStyleIndex)){
oChartSpace.setStyle(nStyleIndex);
}
AscFormat.CheckSpPrXfrm(oChartSpace); AscFormat.CheckSpPrXfrm(oChartSpace);
oDrawing.setExtent( oChartSpace.spPr.xfrm.extX, oChartSpace.spPr.xfrm.extY ); oDrawing.setExtent( oChartSpace.spPr.xfrm.extX, oChartSpace.spPr.xfrm.extY );
return new ApiChart(oChartSpace); return new ApiChart(oChartSpace);
...@@ -3719,49 +3724,54 @@ ...@@ -3719,49 +3724,54 @@
}; };
ApiChart.prototype.CreateTitle = function(sTitle, nFontSize){
if(!this.Chart)
{
return null;
}
if(typeof sTitle === "string" && sTitle.length > 0){
var oTitle = new AscFormat.CTitle();
oTitle.setOverlay(false);
oTitle.setTx(new AscFormat.CChartText());
var oTextBody = AscFormat.CreateTextBodyFromString(sTitle, this.Chart.getDrawingDocument(), oTitle.tx);
if(AscFormat.isRealNumber(nFontSize)){
oTextBody.content.Set_ApplyToAll(true);
oTextBody.content.Paragraph_Add(new ParaTextPr({ FontSize : nFontSize}));
oTextBody.content.Set_ApplyToAll(false);
}
oTitle.tx.setRich(oTextBody);
return oTitle;
}
return null;
};
/** /**
* Specifies a chart title * Specifies a chart title
* @param {string} sTitle * @param {string} sTitle
* */ * @param {hps} nFontSize
ApiChart.prototype.SetTitle = function (sTitle) */
ApiChart.prototype.SetTitle = function (sTitle, nFontSize)
{ {
if(this.Chart) if(this.Chart)
{ {
if(typeof sTitle === "string" && sTitle.length > 0) this.Chart.chart.setTitle(this.CreateTitle(sTitle, nFontSize));
{
this.Chart.chart.setTitle(new AscFormat.CTitle());
this.Chart.chart.title.setTx(new AscFormat.CChartText());
this.Chart.chart.title.tx.setRich(AscFormat.CreateTextBodyFromString(sTitle, this.Chart.getDrawingDocument(), this.Chart.chart.title.tx))
}
else
{
this.Chart.chart.setTitle(null);
}
} }
}; };
/** /**
* Specifies a horizontal axis title * Specifies a horizontal axis title
* @param {string} sTitle * @param {string} sTitle
* @param {hps} nFontSize
* */ * */
ApiChart.prototype.SetHorAxisTitle = function (sTitle) ApiChart.prototype.SetHorAxisTitle = function (sTitle, nFontSize)
{ {
if(this.Chart) if(this.Chart)
{ {
var horAxis = this.Chart.chart.plotArea.getHorizontalAxis(); var horAxis = this.Chart.chart.plotArea.getHorizontalAxis();
if(horAxis) if(horAxis)
{ {
if(typeof sTitle === "string" && sTitle.length > 0) horAxis.setTitle(this.CreateTitle(sTitle, nFontSize));
{
horAxis.setTitle(new AscFormat.CTitle());
horAxis.title.setTx(new AscFormat.CChartText());
horAxis.title.tx.setRich(AscFormat.CreateTextBodyFromString(sTitle, this.Chart.getDrawingDocument(), horAxis.title.tx));
horAxis.title.setOverlay(false);
}
else
{
horAxis.setTitle(null);
}
} }
} }
}; };
...@@ -3769,8 +3779,9 @@ ...@@ -3769,8 +3779,9 @@
/** /**
* Specifies a vertical axis title * Specifies a vertical axis title
* @param {string} sTitle * @param {string} sTitle
* @param {hps} nFontSize
* */ * */
ApiChart.prototype.SetVerAxisTitle = function (sTitle) ApiChart.prototype.SetVerAxisTitle = function (sTitle, nFontSize)
{ {
if(this.Chart) if(this.Chart)
{ {
...@@ -3779,10 +3790,8 @@ ...@@ -3779,10 +3790,8 @@
{ {
if(typeof sTitle === "string" && sTitle.length > 0) if(typeof sTitle === "string" && sTitle.length > 0)
{ {
verAxis.setTitle(new AscFormat.CTitle()); verAxis.setTitle(this.CreateTitle(sTitle, nFontSize));
verAxis.title.setTx(new AscFormat.CChartText()); if(verAxis.title){
verAxis.title.tx.setRich(AscFormat.CreateTextBodyFromString(sTitle, this.Chart.getDrawingDocument(), verAxis.title.tx));
var _body_pr = new AscFormat.CBodyPr(); var _body_pr = new AscFormat.CBodyPr();
_body_pr.reset(); _body_pr.reset();
if(!verAxis.title.txPr) if(!verAxis.title.txPr)
...@@ -3793,6 +3802,7 @@ ...@@ -3793,6 +3802,7 @@
_text_body.setBodyPr(_body_pr); _text_body.setBodyPr(_body_pr);
verAxis.title.setOverlay(false); verAxis.title.setOverlay(false);
} }
}
else else
{ {
verAxis.setTitle(null); verAxis.setTitle(null);
...@@ -3885,6 +3895,9 @@ ...@@ -3885,6 +3895,9 @@
oChart.dLbls.setShowSerName(true == bShowSerName); oChart.dLbls.setShowSerName(true == bShowSerName);
oChart.dLbls.setShowCatName(true == bShowCatName); oChart.dLbls.setShowCatName(true == bShowCatName);
oChart.dLbls.setShowVal(true == bShowVal); oChart.dLbls.setShowVal(true == bShowVal);
oChart.dLbls.setShowLegendKey(false);
//oChart.dLbls.setShowPercent(false);
oChart.dLbls.setShowBubbleSize(false);
} }
}; };
......
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