Skip to content

Commit

Permalink
Feature/val ax (#4731)
Browse files Browse the repository at this point in the history
* [all] First changes into val ax

* [all] Fix for _getArrayDataValues

* [all] CLabelsParameters refactored

* [all] Labels fixed for serAx and labelWidth

* [al] New label width calculations for layoutHorNormal

* [all] Small changes into formulas after testing on standart tester

* [se] By left/right plotArea margin

* [all] TickLblPos based left/right margins implemented

* [all] Fixes for tickLblPos value, when axis is hidden

* [all] recalculateAxesSet iteration count fixed

* [all] TickLblPos logic changed for cases when axis is reversed

* [all] GetTrueMinMax constants back to 0.05

* [all] User defined rotation fixed for catAx

* [all] TickLabelsPos switched to isLeftAxis/isRightAxis, comments added for constants, unnecessary comments removed

---------

Co-authored-by: Igor Zotov <[email protected]>
  • Loading branch information
ansaraidarbek and GoshaZotov authored Jul 18, 2024
1 parent 4ed5617 commit 623c0db
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 92 deletions.
138 changes: 91 additions & 47 deletions common/Charts/ChartsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,26 +957,44 @@ CChartsDrawer.prototype =
//добавляем размеры подписей осей + размеры названия
//TODO генерировать extX для всех осей
var axId = chartSpace.chart.plotArea.axId;
let isLeftAxis = false;
let isRightAxis = false;
if(axId) {
for(var i = 0; i < axId.length; i++) {
if(null !== axId[i].title) {
switch (axId[i].axPos) {
case window['AscFormat'].AX_POS_B: {
switch (axId[i].axPos) {
case window['AscFormat'].AX_POS_B: {
if (null !== axId[i].title) {
bottomTextLabels += axId[i].title.extY;
break;
}
case window['AscFormat'].AX_POS_T: {
break;
}
case window['AscFormat'].AX_POS_T: {
if (null !== axId[i].title) {
topTextLabels += axId[i].title.extY;
break;
}
case window['AscFormat'].AX_POS_L: {
break;
}
case window['AscFormat'].AX_POS_L: {
if (null !== axId[i].title) {
leftTextLabels += axId[i].title.extX;
break;
}
case window['AscFormat'].AX_POS_R: {
break;
}
case window['AscFormat'].AX_POS_R: {
if (null !== axId[i].title) {
rightTextLabels += axId[i].title.extX;
break;
}
break;
}
}
if (!axId[i].bDelete) {
if (axId[i].axPos === AscFormat.AX_POS_L) {
isLeftAxis = axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_NEXT_TO || axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_LOW;
isRightAxis = axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_HIGH;
}
if (axId[i].axPos === AscFormat.AX_POS_R ) {
isLeftAxis = axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_HIGH;
isRightAxis = axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_NEXT_TO || axId[i].tickLblPos === AscFormat.TICK_LABEL_POSITION_LOW;
}
}
}
Expand Down Expand Up @@ -1075,10 +1093,10 @@ CChartsDrawer.prototype =
}

if((null === pieChart) || is3dChart) {
left += this._getStandartMargin(left, leftKey, leftTextLabels, 0) + leftKey + leftTextLabels;
left += this._getStandartMargin(isLeftAxis ? 1 : left, leftKey, leftTextLabels, 0) + leftKey + leftTextLabels;
bottom += this._getStandartMargin(bottom, bottomKey, bottomTextLabels, 0) + bottomKey + bottomTextLabels;
top += this._getStandartMargin(top, topKey, topTextLabels, topMainTitle) + topKey + topTextLabels + topMainTitle;
right += this._getStandartMargin(right, rightKey, rightTextLabels, 0) + rightKey + rightTextLabels;
right += this._getStandartMargin(isRightAxis ? 1 : right, rightKey, rightTextLabels, 0) + rightKey + rightTextLabels;
}

var pxLeft = calculateLeft ? calculateLeft * pxToMM : left * pxToMM;
Expand Down Expand Up @@ -1249,31 +1267,31 @@ CChartsDrawer.prototype =
var defMargin = standartMarginForCharts / this.calcProp.pxToMM;
var result;

if (labelsMargin == 0 && keyMargin == 0 && textMargin == 0 && topMainTitleMargin == 0) {
if (labelsMargin === 0 && keyMargin === 0 && textMargin === 0 && topMainTitleMargin === 0) {
result = defMargin;
} else if (labelsMargin != 0 && keyMargin == 0 && textMargin == 0 && topMainTitleMargin == 0) {
} else if (labelsMargin !== 0 && keyMargin === 0 && textMargin === 0 && topMainTitleMargin === 0) {
result = defMargin / 2;
} else if (labelsMargin != 0 && keyMargin == 0 && textMargin != 0 && topMainTitleMargin == 0) {
} else if (labelsMargin !== 0 && keyMargin === 0 && textMargin !== 0 && topMainTitleMargin === 0) {
result = defMargin;
} else if (labelsMargin != 0 && keyMargin != 0 && textMargin != 0 && topMainTitleMargin == 0) {
} else if (labelsMargin !== 0 && keyMargin !== 0 && textMargin !== 0 && topMainTitleMargin === 0) {
result = defMargin + defMargin / 2;
} else if (labelsMargin == 0 && keyMargin != 0 && textMargin == 0 && topMainTitleMargin == 0) {
} else if (labelsMargin === 0 && keyMargin !== 0 && textMargin === 0 && topMainTitleMargin === 0) {
result = defMargin;
} else if (labelsMargin == 0 && keyMargin == 0 && textMargin != 0 && topMainTitleMargin == 0) {
} else if (labelsMargin === 0 && keyMargin === 0 && textMargin !== 0 && topMainTitleMargin === 0) {
result = defMargin;
} else if (labelsMargin == 0 && keyMargin != 0 && textMargin != 0 && topMainTitleMargin == 0) {
} else if (labelsMargin === 0 && keyMargin !== 0 && textMargin !== 0 && topMainTitleMargin === 0) {
result = defMargin + defMargin / 2;
} else if (labelsMargin != 0 && keyMargin != 0 && textMargin == 0 && topMainTitleMargin == 0) {
} else if (labelsMargin !== 0 && keyMargin !== 0 && textMargin === 0 && topMainTitleMargin === 0) {
result = defMargin;
} else if (labelsMargin == 0 && keyMargin != 0 && textMargin != 0 && topMainTitleMargin == 0) {
} else if (labelsMargin === 0 && keyMargin !== 0 && textMargin !== 0 && topMainTitleMargin === 0) {
result = defMargin + defMargin / 2;
} else if (labelsMargin == 0 && keyMargin == 0 && topMainTitleMargin != 0) {
} else if (labelsMargin === 0 && keyMargin === 0 && topMainTitleMargin !== 0) {
result = defMargin + defMargin / 2;
} else if (labelsMargin == 0 && keyMargin != 0 && topMainTitleMargin != 0) {
} else if (labelsMargin === 0 && keyMargin !== 0 && topMainTitleMargin !== 0) {
result = 2 * defMargin;
} else if (labelsMargin != 0 && keyMargin == 0 && topMainTitleMargin != 0) {
} else if (labelsMargin !== 0 && keyMargin === 0 && topMainTitleMargin !== 0) {
result = defMargin;
} else if (labelsMargin != 0 && keyMargin != 0 && topMainTitleMargin != 0) {
} else if (labelsMargin !== 0 && keyMargin !== 0 && topMainTitleMargin !== 0) {
result = 2 * defMargin;
}

Expand All @@ -1291,12 +1309,22 @@ CChartsDrawer.prototype =
let horizontalAxis = horizontalAxes ? horizontalAxes[0] : null;
let verticalAxis = verticalAxes ? verticalAxes[0] : null;

let getInterval = function (_axis) {
if (_axis.interval) {
return Math.abs((horizontalAxis.interval) / 2);
}
if (_axis.scale && _axis.scale.length > 1) {
return Math.abs(_axis.scale[1] - _axis.scale[0]);
}
return 1;
};

let diffPoints;
if(horizontalAxis && horizontalAxis.xPoints && horizontalAxis.xPoints.length) {
let orientationHorAxis = !horizontalAxis.isReversed();
diffPoints = 0;
if((horizontalAxis instanceof AscFormat.CDateAx || horizontalAxis instanceof AscFormat.CCatAx) && crossBetween === AscFormat.CROSS_BETWEEN_BETWEEN) {
diffPoints = Math.abs((horizontalAxis.interval) / 2);
diffPoints = getInterval(horizontalAxis);
}
if(orientationHorAxis) {
leftDownPointX = horizontalAxis.xPoints[0].pos - diffPoints;
Expand All @@ -1322,7 +1350,7 @@ CChartsDrawer.prototype =
diffPoints = 0;
const isChartEx = chartSpace.isChartEx();
if((verticalAxis instanceof AscFormat.CDateAx || verticalAxis instanceof AscFormat.CCatAx)&& crossBetween === AscFormat.CROSS_BETWEEN_BETWEEN) {
diffPoints = Math.abs((verticalAxis.interval) / 2);
diffPoints = getInterval(verticalAxis);
}
if(orientationVerAxis || isChartEx) {
leftDownPointY = verticalAxis.yPoints[0].pos + diffPoints;
Expand Down Expand Up @@ -2067,8 +2095,8 @@ CChartsDrawer.prototype =
let isOx = axis.axPos === window['AscFormat'].AX_POS_B || axis.axPos === window['AscFormat'].AX_POS_T;
//для оси категорий берем интервал 1
let arrayValues;

if(AscDFH.historyitem_type_CatAx === axis.getObjectType() || AscDFH.historyitem_type_DateAx === axis.getObjectType()) {
const axisType = axis.getObjectType();
if(AscDFH.historyitem_type_CatAx === axisType || AscDFH.historyitem_type_DateAx === axisType) {
arrayValues = [];
let max = axis.max;
for(let i = axis.min; i <= max; i++) {
Expand All @@ -2094,7 +2122,7 @@ CChartsDrawer.prototype =
var bIsManualStep = false;
let t = this;
let calcAxisMinMax = function (isDefaultMinMax) {
let trueMinMax = t._getTrueMinMax((manualMin !== null && manualMin > yMin) ? manualMin : yMin, (manualMax !== null && manualMax < yMax) ? manualMax : yMax, isDefaultMinMax, isScatter);
let trueMinMax = t._getTrueMinMax((manualMin !== null && manualMin > yMin) ? manualMin : yMin, (manualMax !== null && manualMax < yMax) ? manualMax : yMax, isDefaultMinMax, isScatter, manualMax);
let _axisMin, _axisMax, _step, firstDegree;
//TODO временная проверка для некорректных минимальных и максимальных значений
if (manualMax && manualMin && manualMax < manualMin) {
Expand Down Expand Up @@ -2127,7 +2155,8 @@ CChartsDrawer.prototype =
} else {
//было следующее условие - isOx || c_oChartTypes.HBar === this.calcProp.type
if (isOx /*&& !isScatter && axisMin !== 0 && axisMax !== 0*/) {
_step = t._getStep(firstDegree.val + (firstDegree.val / 10) * 3);
_step = t._getStep(firstDegree.val + (firstDegree.val / 10) * 1.1111);
// _step = t._getStep(firstDegree.val);
} else {
_step = t._getStep(firstDegree.val);
}
Expand Down Expand Up @@ -2155,7 +2184,11 @@ CChartsDrawer.prototype =
}

if (isNaN(step) || step === 0) {
arrayValues = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1];
if (manualMax <= 0) {
arrayValues = [-1, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0];
} else {
arrayValues = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1];
}
} else {
if (false && isRadarChart) {
arrayValues = this._getRadarAxisValues(axisMin, axisMax, step);
Expand Down Expand Up @@ -2238,7 +2271,8 @@ CChartsDrawer.prototype =
} else {
var limitArr = [0, 0, 32, 26, 24, 22, 21, 19, 18, 17, 16];
var limit = limitArr[res.length - 1];
var heightGrid = Math.round((trueHeight / (res.length - 1)));
const num = (trueHeight / (res.length - 1));
var heightGrid = Math.round(num);
while (heightGrid <= limit) {
var firstDegreeStep = this._getFirstDegree(newStep);
var tempStep = this._getNextStep(firstDegreeStep.val);
Expand Down Expand Up @@ -2272,25 +2306,35 @@ CChartsDrawer.prototype =
},

_getArrayDataValues: function (step, axisMin, axisMax, manualMin, manualMax, isRadarChart) {
if (!AscFormat.isRealNumber(axisMin) || !AscFormat.isRealNumber(axisMax) || !AscFormat.isRealNumber(step)) {
return [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1];
}

var arrayValues;
//минимальное значение оси
//TODO use axisMin
var minUnit = 0;
let minUnit = 0;

if (manualMin != null) {
if (AscFormat.isRealNumber(manualMin)) {
minUnit = manualMin;
} else if (manualMin == null && axisMin != null && axisMin != 0 && axisMin > 0 && axisMax > 0)//TODO пересмотреть все значения, где-то могут быть расхождения с EXCEL
{
minUnit = parseInt(axisMin / step) * step;
} else {
if (axisMin < 0) {
while ((!isRadarChart && minUnit >= axisMin) || (isRadarChart && minUnit > axisMin)) {
minUnit -= step;
}
} else if (axisMin > 0) {
while (minUnit < axisMin && minUnit > (axisMin - step)) {
minUnit += step;
if (AscFormat.isRealNumber(manualMax) && manualMax > axisMin && manualMax >= 0) {
const stepCount = Math.ceil((manualMax - axisMin) / step);
minUnit = manualMax - (stepCount * step);
// minUnit = Math.min(minUnit, manualMax - upperLimit);
} else if (AscFormat.isRealNumber(manualMax)) {
if (manualMax > 0) {
minUnit = 0;
} else if (manualMax === 0) {
minUnit = -1;
} else {
minUnit = manualMax * 2;
}
} else {
// possible problems if axisMin < 0 should be checked
// const statement1 = !isRadarChart && minUnit >= axisMin;
// const statement2 = isRadarChart && minUnit > axisMin;
minUnit = Math.floor(axisMin / step) * step;
}
}

Expand Down Expand Up @@ -2500,7 +2544,7 @@ CChartsDrawer.prototype =
return step;
},

_getTrueMinMax: function (yMin, yMax, isStackedType, isScatter) {
_getTrueMinMax: function (yMin, yMax, isStackedType, isScatter, isMaxSet) {

var axisMax, axisMin, diffMaxMin;
var cDiff = 1/6;
Expand All @@ -2509,7 +2553,7 @@ CChartsDrawer.prototype =
// TODO пересмотреть все остальные ситуации!
if (yMin >= 0 && yMax >= 0) {
diffMaxMin = (yMax - yMin) / yMax;
if (cDiff > diffMaxMin) {
if (isMaxSet === null && cDiff > diffMaxMin) {
if (isScatter) {
axisMin = isStackedType ? yMin : yMin - 0.05 * (yMax - yMin);
axisMax = isStackedType ? yMax : yMax + 0.05 * (yMax - yMin);
Expand Down
Loading

0 comments on commit 623c0db

Please sign in to comment.