Commit 9be565ae authored by Sergey Luzyanin's avatar Sergey Luzyanin

support layout positioning chart's elements, support bestFit dataLables position

parent 1a2d6213
......@@ -419,73 +419,7 @@ CChartSpace.prototype.recalculate = function()
}
for(var i = 0; i < this.recalcInfo.dataLbls.length; ++i)
{
var series = this.chart.plotArea.chart.series;
if(this.recalcInfo.dataLbls[i].series && this.recalcInfo.dataLbls[i].pt)
{
var ser_idx = this.recalcInfo.dataLbls[i].series.idx; //сделаем проверку лежит ли серия с индексом this.recalcInfo.dataLbls[i].series.idx в сериях первой диаграммы
for(var j = 0; j < series.length; ++j)
{
if(series[j].idx === this.recalcInfo.dataLbls[i].series.idx)
{
var pos = this.chartObj.reCalculatePositionText("dlbl", this, /*this.recalcInfo.dataLbls[i].series.idx todo здесь оставить как есть в chartDrawere выбирать серии по индексу*/j, this.recalcInfo.dataLbls[i].pt.idx);//
this.recalcInfo.dataLbls[i].setPosition(pos.x, pos.y);
break;
}
}
}
}
this.recalcInfo.dataLbls.length = 0;
if(b_recalc_labels)
{
if(this.chart && this.chart.title)
{
var pos = this.chartObj.reCalculatePositionText("title", this, this.chart.title);
this.chart.title.setPosition(pos.x, pos.y);
}
if(this.chart && this.chart.plotArea && this.chart.plotArea)
{
var hor_axis = this.chart.plotArea.getHorizontalAxis();
if(hor_axis && hor_axis.title)
{
var old_cat_ax = this.chart.plotArea.catAx;
this.chart.plotArea.catAx = hor_axis;
var pos = this.chartObj.reCalculatePositionText("catAx", this, hor_axis.title);
hor_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.catAx = old_cat_ax;
}
var vert_axis = this.chart.plotArea.getVerticalAxis();
if(vert_axis && vert_axis.title)
{
var old_val_ax = this.chart.plotArea.valAx;
this.chart.plotArea.valAx = vert_axis;
var pos = this.chartObj.reCalculatePositionText("valAx", this, vert_axis.title);
vert_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.valAx = old_val_ax;
}
}
}
if(b_recalc_legend && this.chart && this.chart.legend)
{
var bResetLegendPos = false;
if(!AscFormat.isRealNumber(this.chart.legend.legendPos))
{
this.chart.legend.legendPos = Asc.c_oAscChartLegendShowSettings.bottom;
bResetLegendPos = true;
}
var pos = this.chartObj.reCalculatePositionText("legend", this, this.chart.legend);
this.chart.legend.setPosition(pos.x, pos.y);
if(bResetLegendPos)
{
this.chart.legend.legendPos = null;
}
}
this.calculateLabelsPositions(b_recalc_labels, b_recalc_legend);
if(this.recalcInfo.recalculateBounds)
{
......
This diff is collapsed.
......@@ -134,6 +134,73 @@ var DISTANCE_TO_TEXT_LEFTRIGHT = 3.2;
}
}
}
function fApproxEqual(a, b, fDelta){
if ( a === b ) {
return true;
}
if(AscFormat.isRealNumber(fDelta)){
return Math.abs( a - b ) < fDelta;
}
return Math.abs( a - b ) < 1e-15;
};
function fSolveQuadraticEquation(a, b, c){
var oResult = {x1: null, x2: null, bError: true}
var D = b*b - 4*a*c;
if(D < 0){
return oResult;
}
oResult.bError = false;
oResult.x1 = (-b + Math.sqrt(D))/(2*a), oResult.x2 = (-b - Math.sqrt(D))/(2*a);
return oResult;
}
function fCheckBoxIntersectionSegment(fX, fY, fWidth, fHeight, x1, y1, x2, y2){
return fCheckSegementIntersection(fX, fY, fX + fWidth, fY, x1, y1, x2, y2) ||
fCheckSegementIntersection(fX + fWidth, fY, fX + fWidth, fY + fHeight, x1, y1, x2, y2) ||
fCheckSegementIntersection(fX + fWidth, fY + fHeight, fX, fY + fHeight, x1, y1, x2, y2) ||
fCheckSegementIntersection(fX, fY + fHeight, fX, fY, x1, y1, x2, y2);
}
function fCheckSegementIntersection(x11, y11, x12, y12, x21, y21, x22, y22){
//check bounding boxes intersection
if(Math.max(x11, x12) < Math.min(x21, x22)){
return false;
}
if(Math.min(x11, x12) > Math.max(x21, x22)){
return false;
}
if(Math.max(y11, y12) < Math.min(y21, y22)){
return false;
}
if(Math.min(y11, y12) > Math.max(y21, y22)){
return false;
}
var oCoeffs = fResolve2LinearSystem(x12-x11, -(x22-x21), y12-y11, -(y22-y21), x21-x11, y21-y11);
if(oCoeffs.bError){
return false;
}
return (oCoeffs.x1 >= 0 && oCoeffs.x1 <= 1
&& oCoeffs.x2 >= 0 && oCoeffs.x2 <= 1);
}
function fResolve2LinearSystem(a11, a12, a21, a22, t1, t2){
var oResult = {bError: true};
var D = a11*a22 - a12*a21;
if(fApproxEqual(D, 0)){
return oResult;
}
oResult.bError = false;
oResult.x1 = (t1*a22 - a12*t2)/D;
oResult.x2 = (a11*t2 - t1*a21)/D;
return oResult;
}
function checkParagraphDefFonts(map, par)
{
par && par.Pr && par.Pr.DefaultRunPr && checkRFonts(map, par.Pr.DefaultRunPr.RFonts);
......@@ -8823,4 +8890,7 @@ function CalcLiterByLength(aAlphaBet, nLength)
window['AscFormat'].GetMinSnapDistanceYObjectByArrays = GetMinSnapDistanceYObjectByArrays;
window['AscFormat'].CalcLiterByLength = CalcLiterByLength;
window['AscFormat'].fillImage = fillImage;
window['AscFormat'].fSolveQuadraticEquation = fSolveQuadraticEquation;
window['AscFormat'].fApproxEqual = fApproxEqual;
window['AscFormat'].fCheckBoxIntersectionSegment = fCheckBoxIntersectionSegment;
})(window);
......@@ -964,7 +964,7 @@ CDLbl.prototype =
}
}
}
max_width += 2;
max_width += 1;
content.Reset(0, 0, max_width, 20000);
content.Recalculate_Page(0, true);
......@@ -1064,6 +1064,11 @@ CDLbl.prototype =
if(dLbl.idx != null)
this.setIdx(dLbl.idx);
if(dLbl.layout != null)
{
this.setLayout(dLbl.layout.createDuplicate());
}
if(dLbl.numFmt != null)
this.setNumFmt(dLbl.numFmt);
......@@ -1148,31 +1153,9 @@ CDLbl.prototype =
this.x = x;
this.y = y;
if(this.layout && this.layout.manualLayout)
{
if(typeof this.layout.manualLayout.x === "number")
{
this.calcX = this.chart.extX*this.layout.x + this.x;
}
else
{
this.calcX = this.x;
}
if(typeof this.layout.manualLayout.y === "number")
{
this.calcY = this.chart.extY*this.layout.y + this.y;
}
else
{
this.calcY = this.y;
}
}
else
{
this.calcX = this.x;
this.calcY = this.y;
}
this.localTransform.Reset();
global_MatrixTransformer.TranslateAppend(this.localTransform, this.calcX, this.calcY);
......@@ -1202,30 +1185,8 @@ CDLbl.prototype =
this.x = x;
this.y = y;
if(this.layout && this.layout.manualLayout)
{
if(typeof this.layout.manualLayout.x === "number")
{
this.calcX = this.chart.extX*this.layout.x + this.x;
}
else
{
this.calcX = this.x;
}
if(typeof this.layout.manualLayout.y === "number")
{
this.calcY = this.chart.extY*this.layout.y + this.y;
}
else
{
this.calcY = this.y;
}
}
else
{
this.calcX = this.x;
this.calcY = this.y;
}
this.calcX = this.x;
this.calcY = this.y;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -11124,4 +11124,11 @@ BinaryChartReader.prototype.ReadAlternateContentFallback = function (type, lengt
window['AscCommon'] = window['AscCommon'] || {};
window['AscCommon'].BinaryChartWriter = BinaryChartWriter;
window['AscCommon'].BinaryChartReader = BinaryChartReader;
window['AscFormat'] = window['AscFormat'] || {};
window['AscFormat'].LAYOUT_MODE_EDGE = LAYOUT_MODE_EDGE;
window['AscFormat'].LAYOUT_MODE_FACTOR = LAYOUT_MODE_FACTOR;
window['AscFormat'].LAYOUT_TARGET_INNER = LAYOUT_TARGET_INNER;
window['AscFormat'].LAYOUT_TARGET_OUTER = LAYOUT_TARGET_OUTER;
})(window);
......@@ -510,73 +510,8 @@ CChartSpace.prototype.recalculate = function()
}
for(var i = 0; i < this.recalcInfo.dataLbls.length; ++i)
{
var series = this.chart.plotArea.chart.series;
if(this.recalcInfo.dataLbls[i].series && this.recalcInfo.dataLbls[i].pt)
{
var ser_idx = this.recalcInfo.dataLbls[i].series.idx; //сделаем проверку лежит ли серия с индексом this.recalcInfo.dataLbls[i].series.idx в сериях первой диаграммы
for(var j = 0; j < series.length; ++j)
{
if(series[j].idx === this.recalcInfo.dataLbls[i].series.idx)
{
var pos = this.chartObj.reCalculatePositionText("dlbl", this, /*this.recalcInfo.dataLbls[i].series.idx todo здесь оставить как есть в chartDrawere выбирать серии по индексу*/j, this.recalcInfo.dataLbls[i].pt.idx);//
this.recalcInfo.dataLbls[i].setPosition(pos.x, pos.y);
break;
}
}
}
}
this.recalcInfo.dataLbls.length = 0;
if(b_recalc_labels)
{
if(this.chart && this.chart.title)
{
var pos = this.chartObj.reCalculatePositionText("title", this, this.chart.title);
this.chart.title.setPosition(pos.x, pos.y);
}
if(this.chart && this.chart.plotArea && this.chart.plotArea)
{
var hor_axis = this.chart.plotArea.getHorizontalAxis();
if(hor_axis && hor_axis.title)
{
var old_cat_ax = this.chart.plotArea.catAx;
this.chart.plotArea.catAx = hor_axis;
var pos = this.chartObj.reCalculatePositionText("catAx", this, hor_axis.title);
hor_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.catAx = old_cat_ax;
}
var vert_axis = this.chart.plotArea.getVerticalAxis();
if(vert_axis && vert_axis.title)
{
var old_val_ax = this.chart.plotArea.valAx;
this.chart.plotArea.valAx = vert_axis;
var pos = this.chartObj.reCalculatePositionText("valAx", this, vert_axis.title);
vert_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.valAx = old_val_ax;
}
}
}
if(b_recalc_legend && this.chart && this.chart.legend)
{
var bResetLegendPos = false;
if(!AscFormat.isRealNumber(this.chart.legend.legendPos))
{
this.chart.legend.legendPos = Asc.c_oAscChartLegendShowSettings.bottom;
bResetLegendPos = true;
}
var pos = this.chartObj.reCalculatePositionText("legend", this, this.chart.legend);
this.chart.legend.setPosition(pos.x, pos.y);
if(bResetLegendPos)
{
this.chart.legend.legendPos = null;
}
}
this.calculateLabelsPositions(b_recalc_labels, b_recalc_legend);
if(this.recalcInfo.recalculateBounds)
{
......
......@@ -415,73 +415,9 @@ CChartSpace.prototype.recalculate = function()
}
}
for(var i = 0; i < this.recalcInfo.dataLbls.length; ++i)
{
var series = this.chart.plotArea.chart.series;
if(this.recalcInfo.dataLbls[i].series && this.recalcInfo.dataLbls[i].pt)
{
var ser_idx = this.recalcInfo.dataLbls[i].series.idx; //сделаем проверку лежит ли серия с индексом this.recalcInfo.dataLbls[i].series.idx в сериях первой диаграммы
for(var j = 0; j < series.length; ++j)
{
if(series[j].idx === this.recalcInfo.dataLbls[i].series.idx)
{
var pos = this.chartObj.reCalculatePositionText("dlbl", this, /*this.recalcInfo.dataLbls[i].series.idx todo здесь оставить как есть в chartDrawere выбирать серии по индексу*/j, this.recalcInfo.dataLbls[i].pt.idx);//
this.recalcInfo.dataLbls[i].setPosition(pos.x, pos.y);
break;
}
}
}
}
this.recalcInfo.dataLbls.length = 0;
if(b_recalc_labels)
{
if(this.chart && this.chart.title)
{
var pos = this.chartObj.reCalculatePositionText("title", this, this.chart.title);
this.chart.title.setPosition(pos.x, pos.y);
}
if(this.chart && this.chart.plotArea && this.chart.plotArea)
{
var hor_axis = this.chart.plotArea.getHorizontalAxis();
if(hor_axis && hor_axis.title)
{
var old_cat_ax = this.chart.plotArea.catAx;
this.chart.plotArea.catAx = hor_axis;
var pos = this.chartObj.reCalculatePositionText("catAx", this, hor_axis.title);
hor_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.catAx = old_cat_ax;
}
var vert_axis = this.chart.plotArea.getVerticalAxis();
if(vert_axis && vert_axis.title)
{
var old_val_ax = this.chart.plotArea.valAx;
this.chart.plotArea.valAx = vert_axis;
var pos = this.chartObj.reCalculatePositionText("valAx", this, vert_axis.title);
vert_axis.title.setPosition(pos.x, pos.y);
this.chart.plotArea.valAx = old_val_ax;
}
}
}
if(b_recalc_legend && this.chart && this.chart.legend)
{
var bResetLegendPos = false;
if(!AscFormat.isRealNumber(this.chart.legend.legendPos))
{
this.chart.legend.legendPos = Asc.c_oAscChartLegendShowSettings.bottom;
bResetLegendPos = true;
}
var pos = this.chartObj.reCalculatePositionText("legend", this, this.chart.legend);
this.chart.legend.setPosition(pos.x, pos.y);
if(bResetLegendPos)
{
this.chart.legend.legendPos = null;
}
}
this.calculateLabelsPositions(b_recalc_labels, b_recalc_legend);
if(this.recalcInfo.recalculateTextPr)
{
this.recalculateTextPr();
......
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