Skip to content

Commit

Permalink
[all] Trendlines forward/backward fixes (#4751)
Browse files Browse the repository at this point in the history
* [all] Trendlines forward/backward fixed and labels are now displayed correctly
* [all] Fixed iteration in generateArrValues function
  • Loading branch information
ansaraidarbek authored Jul 30, 2024
1 parent 0536f87 commit 4234a96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 21 additions & 6 deletions common/Charts/ChartsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,11 +1992,20 @@ CChartsDrawer.prototype =
}
} else {
if(series.length > 0) {
//возможно стоит пройтись по всем сериям
seria = series[0];
numCache = t.getNumCache(seria.val);
// every chart except scatter should start from 1
min = 1;
max = numCache ? numCache.ptCount : 1;
max = 1;
// find max value across each seria
for (let i = 0; i < series.length; i++) {
const seria = series[i];
if (seria) {
numCache = t.getNumCache(seria.val);
const ptCount = numCache && AscFormat.isRealNumber(numCache.ptCount) ? numCache.ptCount : 0;
// trendline can affect max value
const newMax = seria.trendline && seria.trendline.forward && ptCount > 1 ? ptCount + seria.trendline.forward : ptCount;
max = Math.max(max, newMax);
}
}
}
}
};
Expand All @@ -2019,6 +2028,12 @@ CChartsDrawer.prototype =
newArr[l][j] = [val.x, val.y];
}
}

// check the impact of trendline on scatter chart
if (series[l].trendline) {
min = series[l].trendline.backward ? min - series[l].trendline.backward : min;
max = series[l].trendline.forward ? max + series[l].trendline.forward : max;
}
}
};

Expand Down Expand Up @@ -17588,8 +17603,8 @@ CColorObj.prototype =
const coefficients = this._getEquationCoefficients(coords.catVals, coords.valVals, type, order, attributes.intercept);
const equationStorage = this._obtainEquationStorage(type);
if (coefficients && equationStorage) {
let catMax = catAxis.max + attributes.forward;
let catMin = catAxis.min + attributes.backward;
let catMax = catAxis.max;
let catMin = catAxis.min;
const midPointsNum = 100;
const lineBuilder = new CLineBuilder(coefficients, catMin, catMax, valAxis.scaling.min, valAxis.scaling.max, valAxis.scaling.logBase);
lineBuilder.setCalcYVal(equationStorage.calcYVal);
Expand Down
4 changes: 3 additions & 1 deletion common/Drawings/Format/ChartSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -4785,7 +4785,9 @@ function(window, undefined) {
oCurPts = oSeries.val.numLit;
}
if (oCurPts) {
nPtsLength = Math.max(nPtsLength, oCurPts.ptCount);
const forward = oSeries.trendline && oSeries.trendline.forward ? oSeries.trendline.forward : 0;
const newNPtsLength = oCurPts.ptCount + forward;
nPtsLength = Math.max(nPtsLength, newNPtsLength);
}
}
}
Expand Down

0 comments on commit 4234a96

Please sign in to comment.