提交 e0d5c09b 编写于 作者: K kener

柱形图、折线图堆积下开启数值轴的scale模式计算错误

fix #255
上级 d1638d19
......@@ -248,10 +248,13 @@ define(function(require) {
// 空数据在做完后补充拖拽提示框
continue;
}
y = valueAxis.getCoord(value);
//y = valueAxis.getCoord(value);
if (value > 0) {
// 正向堆叠
barHeight = baseYP - y;
//barHeight = baseYP - y;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (baseYP - valueAxis.getCoord(value));
// 非堆叠数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
......@@ -263,7 +266,10 @@ define(function(require) {
}
else if (value < 0){
// 负向堆叠
barHeight = y - baseYN;
//barHeight = y - baseYN;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseYN);
// 非堆叠数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
......@@ -275,7 +281,7 @@ define(function(require) {
}
else {
// 0值
barHeight = baseYP - y;
barHeight = 0;//baseYP - y;
// 最小高度无效
lastYP -= barHeight;
y = lastYP;
......@@ -442,10 +448,13 @@ define(function(require) {
// 空数据在做完后补充拖拽提示框
continue;
}
x = valueAxis.getCoord(value);
//x = valueAxis.getCoord(value);
if (value > 0) {
// 正向堆叠
barHeight = x - baseXP;
//barHeight = x - baseXP;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseXP);
// 非堆叠数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
......@@ -457,7 +466,10 @@ define(function(require) {
}
else if (value < 0){
// 负向堆叠
barHeight = baseXN - x;
//barHeight = baseXN - x;
barHeight = m > 0
? valueAxis.getCoordSize(value)
: (baseXN - valueAxis.getCoord(value));
// 非堆叠数据最小高度有效
if (n == 1
&& barMinHeightMap[seriesIndex] > barHeight
......@@ -469,7 +481,7 @@ define(function(require) {
}
else {
// 0值
barHeight = x - baseXP;
barHeight = 0;//x - baseXP;
// 最小高度无效
x = lastXP;
lastXP += barHeight;
......
......@@ -268,15 +268,19 @@ define(function(require) {
}
continue;
}
y = valueAxis.getCoord(value);
//y = valueAxis.getCoord(value);
if (value >= 0) {
// 正向堆叠
lastYP -= (baseYP - y);
lastYP -= m > 0
? valueAxis.getCoordSize(value)
: (baseYP - valueAxis.getCoord(value));
y = lastYP;
}
else if (value < 0){
// 负向堆叠
lastYN += y - baseYN;
lastYN += m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseYN);
y = lastYN;
}
curPLMap[seriesIndex].push(
......@@ -434,15 +438,19 @@ define(function(require) {
}
continue;
}
x = valueAxis.getCoord(value);
//x = valueAxis.getCoord(value);
if (value >= 0) {
// 正向堆叠
lastXP += x - baseXP;
lastXP += m > 0
? valueAxis.getCoordSize(value)
: (valueAxis.getCoord(value) - baseXP);
x = lastXP;
}
else if (value < 0){
// 负向堆叠
lastXN -= baseXN - x;
lastXN -= m > 0
? valueAxis.getCoordSize(value)
: (baseXN - valueAxis.getCoord(value));
x = lastXN;
}
curPLMap[seriesIndex].push(
......
......@@ -481,10 +481,10 @@ define(function (require) {
// 不是自己的数据不计算极值
continue;
}
var key = series[i].name || 'kener';
if (!series[i].stack) {
var key = series[i].name || '';
data[key] = [];
data[key] = data[key] || [];
oriData = series[i].data;
for (var j = 0, k = oriData.length; j < k; j++) {
value = typeof oriData[j].value != 'undefined'
......@@ -515,6 +515,7 @@ define(function (require) {
var keyN = '__Magic_Key_Negative__' + series[i].stack;
data[keyP] = data[keyP] || [];
data[keyN] = data[keyN] || [];
data[key] = data[key] || []; // scale下还需要记录每一个量
oriData = series[i].data;
for (var j = 0, k = oriData.length; j < k; j++) {
value = typeof oriData[j].value != 'undefined'
......@@ -540,6 +541,9 @@ define(function (require) {
data[keyN][j] = value;
}
}
if (option.scale) {
data[key].push(value);
}
}
}
}
......@@ -676,7 +680,7 @@ define(function (require) {
var splitGap;
var power;
if (precision === 0) { // 整数
power = option.power;
power = option.power > 1 ? option.power : 1;
}
else { // 小数
// 放大倍数后复用整数逻辑,最后再缩小回去
......@@ -690,52 +694,52 @@ define(function (require) {
if (_min >= 0 && _max >= 0) {
// 双正
if (!scale) {
// power自动降级
while ((_max / power < splitNumber) && power != 1) {
power = power / 10;
}
_min = 0;
}
// power自动降级
while ((_max / power < splitNumber) && power != 1) {
power = power / 10;
}
total = _max - _min;
// 粗算
splitGap = Math.ceil((total / splitNumber) / power) * power;
if (scale) {
if (precision === 0) { // 整数
_min = Math.floor(_min / splitGap) * splitGap;
else {
// power自动降级
while (_min < power && power != 1) {
power = power / 10;
}
// 修正
if (_min + splitGap * splitNumber < _max) {
splitGap =
Math.ceil(((_max - _min) / splitNumber) / power)
* power;
if (precision === 0) { // 整数
// 满足power
_min = Math.floor(_min / power) * power;
_max = Math.ceil(_max / power) * power;
}
}
power = power > 1 ? power / 10 : 1;
total = _max - _min;
splitGap = Math.ceil((total / splitNumber) / power) * power;
_max = _min + splitGap * splitNumber;
}
else if (_min <= 0 && _max <= 0) {
// 双负
power = -power;
if (!scale) {
// power自动降级
while ((_min / power < splitNumber) && power != -1) {
power = power / 10;
}
_max = 0;
}
power = -power;
// power自动降级
while ((_min / power < splitNumber) && power != -1) {
power = power / 10;
}
total = _min - _max;
splitGap = -Math.ceil((total / splitNumber) / power) * power;
if (scale) {
if (precision === 0) { // 整数
_max = Math.ceil(_max / splitGap) * splitGap;
else {
// power自动降级
while (_max > power && power != -1) {
power = power / 10;
}
// 修正
if (_max - splitGap * splitNumber > _min) {
splitGap =
Math.ceil(((_min - _max) / splitNumber) / power)
* power;
if (precision === 0) { // 整数
// 满足power
_min = Math.ceil(_min / power) * power;
_max = Math.floor(_max / power) * power;
}
}
power = power < -1 ? power / 10 : -1;
total = _min - _max;
splitGap = -Math.ceil((total / splitNumber) / power) * power;
_min = -splitGap * splitNumber + _max;
}
else {
......@@ -777,7 +781,6 @@ define(function (require) {
(_valueList[i] / power).toFixed(precision) - 0;
}
}
_reformLabelData();
}
......@@ -886,6 +889,18 @@ define(function (require) {
: Math.floor(result);
*/
}
// 根据值换算绝对大小
function getCoordSize(value) {
if (option.position == 'left' || option.position == 'right') {
// 纵向
return Math.abs(value / (_max - _min) * grid.getHeight());
}
else {
// 横向
return Math.abs(value / (_max - _min) * grid.getWidth());
}
}
function getPosition() {
return option.position;
......@@ -895,6 +910,7 @@ define(function (require) {
self.refresh = refresh;
self.getExtremum = getExtremum;
self.getCoord = getCoord;
self.getCoordSize = getCoordSize;
self.getPosition = getPosition;
init(option, grid, series);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册