Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[all] Trendlines forward/backward fixes #4751

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4783,7 +4783,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
Loading