Commit 879cdc55 authored by Igor.Zotov's avatar Igor.Zotov Committed by Alexander.Trofimov

рефакторинг

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@54989 954022d7-b5bf-4e40-9824-e11837661b57
parent 4df4bc3c
...@@ -16,7 +16,8 @@ function CChartsDrawer() ...@@ -16,7 +16,8 @@ function CChartsDrawer()
CChartsDrawer.prototype = CChartsDrawer.prototype =
{ {
reCalculate : function(chartSpace) //****draw and recalculate functions****
reCalculate : function(chartSpace)
{ {
this.cChartSpace = chartSpace; this.cChartSpace = chartSpace;
...@@ -135,6 +136,9 @@ CChartsDrawer.prototype = ...@@ -135,6 +136,9 @@ CChartsDrawer.prototype =
this.chart.draw(this, cShapeDrawer, chartSpace); this.chart.draw(this, cShapeDrawer, chartSpace);
}, },
//****positions text labels****
reCalculatePositionText : function(type, chartSpace, ser, val) reCalculatePositionText : function(type, chartSpace, ser, val)
{ {
var pos; var pos;
...@@ -288,180 +292,372 @@ CChartsDrawer.prototype = ...@@ -288,180 +292,372 @@ CChartsDrawer.prototype =
return {x: x, y: y} return {x: x, y: y}
}, },
_calculateProperties: function(chartProp)
{
if(!this.calcProp.scale) //****calculate margins****
this.preCalculateData(chartProp); _calculateMarginsChart: function(chartSpace) {
this.calcProp.chartGutter = {};
//считаем маргины if(!this.calcProp.pxToMM)
this._calculateMarginsChart(chartProp); this.calcProp.pxToMM = 1 / chartSpace.convertPixToMM(1);
this.calcProp.trueWidth = this.calcProp.widthCanvas - this.calcProp.chartGutter._left - this.calcProp.chartGutter._right; var pxToMM = this.calcProp.pxToMM;
this.calcProp.trueHeight = this.calcProp.heightCanvas - this.calcProp.chartGutter._top - this.calcProp.chartGutter._bottom; var standartMargin = 13 / pxToMM;
var isHBar = (chartSpace.chart.plotArea.chart.getObjectType() == historyitem_type_BarChart && chartSpace.chart.plotArea.chart.barDir != 1) ? true : false;
this._calculateWidthChart(); //высчитываем выходящие за пределы подписи осей
var labelsMargin = this._calculateMarginLabels(chartSpace);
var left = labelsMargin.left, right = labelsMargin.right, top = labelsMargin.top, bottom = labelsMargin.bottom;
//count line of chart grid //****left*****
if((chartProp.chart.plotArea.valAx && chartProp.chart.plotArea.catAx && chartProp.chart.plotArea.valAx.yPoints && chartProp.chart.plotArea.catAx.xPoints) || (chartProp.chart.plotArea.catAx && chartProp.chart.plotArea.valAx && chartProp.chart.plotArea.catAx.yPoints && chartProp.chart.plotArea.valAx.xPoints)) if(left || !right)
{ {
if(chartProp.chart.plotArea.valAx.yPoints) if(chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null && !isHBar)
this.calcProp.numhlines = chartProp.chart.plotArea.valAx.yPoints.length - 1; left += chartSpace.chart.plotArea.valAx.title.extX + standartMargin;
if(this.calcProp.type == "Bar") else if(isHBar && chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null)
{ left += chartSpace.chart.plotArea.catAx.title.extX + standartMargin;
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length; else
left += standartMargin / 2;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "HBar")
{
this.calcProp.numhlines = chartProp.chart.plotArea.catAx.yPoints.length;
this.calcProp.numvlines = chartProp.chart.plotArea.valAx.xPoints.length - 1;
this.calcProp.numhMinorlines = 2;
this.calcProp.numvMinorlines = 5;
}
else if(this.calcProp.type == "Line" || this.calcProp.type == "Stock")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "Scatter" || this.calcProp.type == "BubbleChart")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 5;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "Area")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
} }
else
left += standartMargin;
if(this.calcProp.type != "Scatter") //****right*****
this.calcProp.nullPositionOX = this._getNullPosition(); if(right)
{
right += standartMargin / 2;
if(chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null && !isHBar)
left += chartSpace.chart.plotArea.valAx.title.extX;
else if(isHBar && chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null)
left += chartSpace.chart.plotArea.catAx.title.extX;
}
else else
right += standartMargin;
//****bottom*****
if(bottom || !top)
{ {
var scatterNullPos = this._getScatterNullPosition(); if(chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null && !isHBar)
this.calcProp.nullPositionOX = scatterNullPos.x; bottom += chartSpace.chart.plotArea.catAx.title.extY + standartMargin;
this.calcProp.nullPositionOY = scatterNullPos.y; else if(isHBar && chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null)
bottom += chartSpace.chart.plotArea.valAx.title.extY + standartMargin;
else
bottom += standartMargin / 2;
} }
else
if(this.calcProp.type == "Bar") bottom += standartMargin;
//****top*****
if(top)
{ {
this.calcProp.max = this.calcProp.scale[this.calcProp.scale.length -1]; top += standartMargin + standartMargin / 2;
this.calcProp.min = this.calcProp.scale[0]; if(chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null && !isHBar)
bottom += chartSpace.chart.plotArea.catAx.title.extY;
else if(isHBar && chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null)
bottom += chartSpace.chart.plotArea.valAx.title.extY;
if(chartSpace.chart.title !== null && !chartSpace.chart.title.overlay)
top += chartSpace.chart.title.extY;
}
else
{
top += standartMargin;
if(chartSpace.chart.title !== null && !chartSpace.chart.title.overlay)
top += chartSpace.chart.title.extY + standartMargin / 2;
}
//KEY
if(chartSpace.chart.legend && !chartSpace.chart.legend.overlay)
{
switch ( chartSpace.chart.legend.legendPos )
{
case LEGEND_POS_L:
{
left += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
case LEGEND_POS_T:
{
top += chartSpace.chart.legend.extY + standartMargin / 2;
break;
}
case LEGEND_POS_R:
{
right += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
case LEGEND_POS_B:
{
bottom += chartSpace.chart.legend.extY + standartMargin / 2;
break;
}
case LEGEND_POS_TR:
{
right += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
}
} }
this.calcProp.chartGutter._left = left * pxToMM;
this.calcProp.chartGutter._right = right * pxToMM;
this.calcProp.chartGutter._top = top * pxToMM;
this.calcProp.chartGutter._bottom = bottom * pxToMM;
}, },
preCalculateData: function(chartProp) _calculateMarginLabels: function(chartSpace)
{ {
this.calcProp.pxToMM = 1 / chartProp.convertPixToMM(1); var isHBar = this.calcProp.type;
var left = 0, right = 0, bottom = 0, top = 0;
this.calcProp.pathH = 1000000000; var leftDownPointX, leftDownPointY, rightUpPointX, rightUpPointY;
this.calcProp.pathW = 1000000000;
var typeChart = chartProp.chart.plotArea.chart.getObjectType(); var valAx = chartSpace.chart.plotArea.valAx;
var catAx = chartSpace.chart.plotArea.catAx;
switch ( typeChart )
if(isHBar === 'HBar' && catAx && valAx && catAx.yPoints && valAx.xPoints)
{ {
case historyitem_type_LineChart: if(catAx.yPoints.length > 1)
{
this.calcProp.type = "Line";
break;
}
case historyitem_type_BarChart:
{ {
if(chartProp.chart.plotArea.chart.barDir == 1) if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
this.calcProp.type = "Bar"; leftDownPointY = catAx.yPoints[0].pos - (catAx.yPoints[1].pos - catAx.yPoints[0].pos) / 2;
else else
this.calcProp.type = "HBar"; leftDownPointY = catAx.yPoints[0].pos;
break;
} }
case historyitem_type_PieChart: else
leftDownPointY = valAx.labels.y;
leftDownPointX = valAx.xPoints[0].pos;
if(catAx.yPoints.length > 1)
{ {
this.calcProp.type = "Pie"; if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
break; rightUpPointY = catAx.yPoints[0].pos - Math.abs((catAx.yPoints[1].pos - catAx.yPoints[0].pos) / 2);
else
rightUpPointY = catAx.yPoints[catAx.yPoints.length - 1].pos;
} }
case historyitem_type_AreaChart: else
rightUpPointY = catAx.labels.x;
rightUpPointX = valAx.xPoints[valAx.xPoints.length - 1].pos;
if(catAx.labels && !catAx.bDelete)
{ {
this.calcProp.type = "Area"; //подпись оси OY находится левее крайней левой точки
break; if(leftDownPointX >= catAx.labels.x)
{
left = leftDownPointX - catAx.labels.x;
}
else if((catAx.labels.x + catAx.labels.extX) >= rightUpPointX)//правее крайней правой точки
{
right = catAx.labels.x + catAx.labels.extX - rightUpPointX;
}
} }
case historyitem_type_ScatterChart:
if(valAx.labels && !valAx.bDelete)
{ {
this.calcProp.type = "Scatter"; //подпись оси OX находится ниже крайней нижней точки
break; if((valAx.labels.y + valAx.labels.extY) >= leftDownPointY)
{
bottom = (valAx.labels.y + valAx.labels.extY) - leftDownPointY;
}
else if(valAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - valAx.labels.y;
}
} }
case historyitem_type_StockChart: }
else if(isHBar === 'Scatter' && catAx && valAx && catAx.xPoints && valAx.yPoints)
{
leftDownPointX = catAx.xPoints[0].pos;
leftDownPointY = valAx.yPoints[0].pos;
rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos;
rightUpPointY = valAx.yPoints[valAx.yPoints.length - 1].pos;
if(valAx.labels && !valAx.bDelete)
{ {
this.calcProp.type = "Stock"; //подпись оси OY находится левее крайней левой точки
break; if(leftDownPointX >= valAx.labels.x)
{
left = leftDownPointX - valAx.labels.x;
}
else if((valAx.labels.x + valAx.labels.extX) >= rightUpPointY)//правее крайней правой точки
{
right = valAx.labels.x + valAx.labels.extX - rightUpPointY;
}
} }
case historyitem_type_DoughnutChart:
if(catAx.labels && !catAx.bDelete)
{ {
this.calcProp.type = "DoughnutChart"; //подпись оси OX находится ниже крайней нижней точки
break; if((catAx.labels.y + catAx.labels.extY) >= leftDownPointY)
{
bottom = (catAx.labels.y + catAx.labels.extY) - leftDownPointY;
}
else if(catAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - catAx.labels.y;
}
} }
case historyitem_type_RadarChart: }
else if(isHBar !== undefined && valAx && catAx && catAx.xPoints && valAx.yPoints)
{
if(catAx.xPoints.length > 1)
{ {
this.calcProp.type = "Radar"; if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
break; leftDownPointX = catAx.xPoints[0].pos - (catAx.xPoints[1].pos - catAx.xPoints[0].pos) / 2;
else
leftDownPointX = catAx.xPoints[0].pos;
} }
case historyitem_type_BubbleChart: else
leftDownPointX = catAx.labels.x;
leftDownPointY = valAx.yPoints[0].pos;
if(catAx.xPoints.length > 1)
{ {
this.calcProp.type = "BubbleChart"; if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
break; rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos + (catAx.xPoints[1].pos - catAx.xPoints[0].pos) / 2;
else
rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos;
} }
}; else
rightUpPointX = catAx.labels.x;
var grouping = chartProp.chart.plotArea.chart.grouping;
if(this.calcProp.type == "Line" || this.calcProp.type == "Area")
this.calcProp.subType = (grouping === GROUPING_PERCENT_STACKED) ? "stackedPer" : (grouping === GROUPING_STACKED) ? "stacked" : "normal" if(valAx.scaling.orientation == ORIENTATION_MIN_MAX)
else rightUpPointY = valAx.yPoints[valAx.yPoints.length - 1].pos;
this.calcProp.subType = (grouping === BAR_GROUPING_PERCENT_STACKED) ? "stackedPer" : (grouping === BAR_GROUPING_STACKED) ? "stacked" : "normal" else
rightUpPointY = valAx.yPoints[0].pos;
if(valAx.labels && !valAx.bDelete)
{
//подпись оси OY находится левее крайней левой точки
if(leftDownPointX >= valAx.labels.x)
{
left = leftDownPointX - valAx.labels.x;
}
else if((valAx.labels.x + valAx.labels.extX) >= rightUpPointY)//правее крайней правой точки
{
right = valAx.labels.extX;
}
}
if(catAx.labels && !catAx.bDelete)
{
//подпись оси OX находится ниже крайней нижней точки
if((catAx.labels.y + catAx.labels.extY) >= leftDownPointY)
{
bottom = (catAx.labels.y + catAx.labels.extY) - leftDownPointY;
}
else if(catAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - catAx.labels.y;
}
}
}
this.calcProp.xaxispos = null; return {left: left, right: right, top: top, bottom: bottom};
this.calcProp.yaxispos = null; },
//****calculate properties****
_calculateProperties: function(chartProp)
{
if(!this.calcProp.scale)
this.preCalculateData(chartProp);
//рассчёт данных и ещё некоторых параметров(this.calcProp./min/max/ymax/ymin/data) //считаем маргины
this._calculateData2(chartProp); this._calculateMarginsChart(chartProp);
//пересчёт данных для накопительных диаграмм this.calcProp.trueWidth = this.calcProp.widthCanvas - this.calcProp.chartGutter._left - this.calcProp.chartGutter._right;
if(this.calcProp.subType == 'stackedPer' || this.calcProp.subType == 'stacked') this.calcProp.trueHeight = this.calcProp.heightCanvas - this.calcProp.chartGutter._top - this.calcProp.chartGutter._bottom;
this._calculateStackedData2();
//***series*** //count line of chart grid
this.calcProp.series = chartProp.chart.plotArea.chart.series; if((chartProp.chart.plotArea.valAx && chartProp.chart.plotArea.catAx && chartProp.chart.plotArea.valAx.yPoints && chartProp.chart.plotArea.catAx.xPoints) || (chartProp.chart.plotArea.catAx && chartProp.chart.plotArea.valAx && chartProp.chart.plotArea.catAx.yPoints && chartProp.chart.plotArea.valAx.xPoints))
{
if(chartProp.chart.plotArea.valAx.yPoints)
this.calcProp.numhlines = chartProp.chart.plotArea.valAx.yPoints.length - 1;
if(this.calcProp.type == "Bar")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "HBar")
{
this.calcProp.numhlines = chartProp.chart.plotArea.catAx.yPoints.length;
this.calcProp.numvlines = chartProp.chart.plotArea.valAx.xPoints.length - 1;
this.calcProp.numhMinorlines = 2;
this.calcProp.numvMinorlines = 5;
}
else if(this.calcProp.type == "Line" || this.calcProp.type == "Stock")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "Scatter" || this.calcProp.type == "BubbleChart")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 5;
this.calcProp.numhMinorlines = 5;
}
else if(this.calcProp.type == "Area")
{
this.calcProp.numvlines = chartProp.chart.plotArea.catAx.xPoints.length;
this.calcProp.numvMinorlines = 2;
this.calcProp.numhMinorlines = 5;
}
}
//находим значния для осей
/*this.calcProp.scale = this._getAxisData(false, this.calcProp, this.calcProp.min, this.calcProp.max, this.calcProp.ymin, this.calcProp.ymax, chartProp);
if(this.calcProp.type == "Scatter")
this.calcProp.xScale = this._getAxisData(true, this.calcProp, this.calcProp.min, this.calcProp.max, this.calcProp.ymin, this.calcProp.ymax, chartProp);*/
if(this.calcProp.type == "Scatter") if(this.calcProp.type != "Scatter")
this.calcProp.nullPositionOX = this._getNullPosition();
else
{ {
this.calcProp.scale = this._getAxisData2(false, this.calcProp.ymin, this.calcProp.ymax, chartProp); var scatterNullPos = this._getScatterNullPosition();
this.calcProp.xScale = this._getAxisData2(true, this.calcProp.min, this.calcProp.max, chartProp); this.calcProp.nullPositionOX = scatterNullPos.x;
this.calcProp.nullPositionOY = scatterNullPos.y;
}
if(this.calcProp.type == "Bar")
{
this.calcProp.max = this.calcProp.scale[this.calcProp.scale.length -1];
this.calcProp.min = this.calcProp.scale[0];
} }
else
this.calcProp.scale = this._getAxisData2(false, this.calcProp.min, this.calcProp.max, chartProp);
this.calcProp.widthCanvas = chartProp.extX*this.calcProp.pxToMM;
this.calcProp.heightCanvas = chartProp.extY*this.calcProp.pxToMM;
}, },
//****calculate data****
_calculateStackedData: function() _calculateStackedData: function()
{ {
if(this.calcProp.type == "Bar") if(this.calcProp.type == "Bar")
...@@ -571,164 +767,52 @@ CChartsDrawer.prototype = ...@@ -571,164 +767,52 @@ CChartsDrawer.prototype =
}; };
}, },
_calculateStackedData2: function() _calculateData: function(chart) {
{ var isSeries = false;
if(this.calcProp.type == "Bar" || this.calcProp.type == "HBar") var formatCell = 'General';
{ var formatCellScOy = 'General';
if (this.calcProp.subType == 'stacked') { var defaultFormat = 'General';
var originalData = $.extend(true, [], this.calcProp.data); var isDateTimeFormat;
for (var j = 0; j < this.calcProp.data.length; j++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j][i] = this._findPrevValue(originalData, j, i)
}
}
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
}
else if(this.calcProp.subType == 'stackedPer') {
var summ;
var originalData = $.extend(true, [], this.calcProp.data);
for (var j = 0; j < (this.calcProp.data.length); j++) {
summ = 0;
for (var i = 0; i < this.calcProp.data[j].length; i++) {
summ += Math.abs(this.calcProp.data[j][i]);
}
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j][i] = (this._findPrevValue(originalData, j, i) * 100) / summ;
}
}
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
}
};
var api_doc = window["editor"];
var api_sheet = window["Asc"]["editor"];
var styleManager = api_doc ? api_doc.chartStyleManager : api_sheet.chartStyleManager;
var arrFormatAdobeLabels = [];
var catNameLabels = [];
if(this.calcProp.type == "Line" || this.calcProp.type == "Area") //просматриваем bShowValue для каждой из серий
{ //TODO позже отрисовывать значения для каждой серии индивидуально
if (this.calcProp.subType == 'stacked') { /*if ( !chart.bShowValue ) {
for (var j = 0; j < (this.calcProp.data.length - 1); j++) { for (var n = 0; n < chart.series.length; n++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) { if ( chart.series[n].bShowValue ) {
if(!this.calcProp.data[j + 1]) chart.bShowValue = true;
this.calcProp.data[j + 1] = []; break;
this.calcProp.data[j + 1][i] = this.calcProp.data[j + 1][i] + this.calcProp.data[j][i];
}
} }
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
} }
else if (this.calcProp.subType == 'stackedPer') { }
var firstData = this.calcProp.data;
var summValue = []; if(chart.bShowCatName)
for (var j = 0; j < (firstData[0].length); j++) { chart.bShowValue = true;*/
summValue[j] = 0;
for (var i = 0; i < firstData.length; i++) {
summValue[j] += Math.abs(firstData[i][j])
}
}
for (var j = 0; j < (this.calcProp.data.length - 1); j++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j + 1][i] = this.calcProp.data[j + 1][i] + this.calcProp.data[j][i]
}
}
var tempData = this.calcProp.data;
for (var j = 0; j < (tempData[0].length); j++) {
for (var i = 0; i < tempData.length; i++) {
if(summValue[j] == 0)
tempData[i][j] = 0;
else
tempData[i][j] = (100 * tempData[i][j]) / (summValue[j]);
}
}
this.calcProp.max = this._getMaxValueArray(tempData);
this.calcProp.min = this._getMinValueArray(tempData);
this.calcProp.data = tempData;
}
};
},
_getSumArray: function (arr, isAbs)
{
if (typeof(arr) == 'number') {
return arr;
}
else if(typeof(arr) == 'string'){
return parseFloat(arr);
}
var i, sum;
for(i = 0,sum = 0; i < arr.length; i++)
{
if(typeof(arr[i]) == 'object' && arr[i].val)
sum += parseFloat(isAbs ? Math.abs(arr[i].val) : arr[i].val);
else
sum += isAbs ? Math.abs(arr[i]) : arr[i];
}
return sum;
},
_getMaxValueArray: function(array)
{
var max = 0;
for(var i = 0; i < array.length; i++)
{
for(var j = 0; j < array[i].length; j++)
{
if(i == 0 && j == 0)
max = array[i][j];
if(array[i][j] > max)
max = array[i][j];
}
}
return max;
},
_getMinValueArray: function(array)
{
var min = 0;
for(var i = 0; i < array.length; i++)
{
for(var j = 0; j < array[i].length; j++)
{
if(i == 0 && j == 0)
min = array[i][j];
if(array[i][j] < min)
min = array[i][j];
}
}
return min;
},
_findPrevValue: function(originalData, num, max) {
var summ = 0;
for (var i = 0; i <= max; i++) {
if (originalData[num][max] >= 0) {
if (originalData[num][i] >= 0)
summ += originalData[num][i];
}
else {
if (originalData[num][i] < 0)
summ += originalData[num][i];
}
}
return summ;
},
_calculateData2: function(chart) {
var max = 0; var max = 0;
var min = 0; var min = 0;
var minY = 0; var minY = 0;
var maxY = 0; var maxY = 0;
var xNumCache, yNumCache, newArr; var newArr, formatAdobeLabel, xNumCache, yNumCache;
var series = chart.chart.plotArea.chart.series; var series = chart.chart.plotArea.chart.series;
if(this.calcProp.type != 'Scatter')//берём данные из NumCache if(series && series.length != 0 && this.calcProp.type != 'Scatter')//берём данные из NumCache
{ {
isSeries = true;
/*chart.reSeries = chart.series;
if(chart.type == 'Pie')
{
series = chart.getReverseSeries(true);
chart.reSeries = series;
}*/
var arrValues = []; var arrValues = [];
var isSkip = []; var isSkip = [];
var skipSeries = []; var skipSeries = [];
...@@ -738,29 +822,54 @@ CChartsDrawer.prototype = ...@@ -738,29 +822,54 @@ CChartsDrawer.prototype =
var numSeries = 0; var numSeries = 0;
var curSeria; var curSeria;
var isNumberVal = true; var isNumberVal = true;
if(series[0] && series[0].xVal && series[0].xVal.Formula != null && this.calcProp.type == 'Scatter')
{
var cash = series[0].xVal.NumCache;
for(var i = 0; i < cash.length; i++)
{
if(!isNumber(cash.val))
isNumberVal = false;
}
}
for(var l = 0; l < series.length; ++l) for(var l = 0; l < series.length; ++l)
{ {
var firstCol = 0; var firstCol = 0;
var firstRow = 0; var firstRow = 0;
if(series[0].xVal && numSeries == 0 && this.calcProp.type == 'Scatter' && series[numSeries].xVal.numRef.numCache.pts.length)
{
curSeria = series[numSeries].xVal.numRef.numCache.pts;
}
else if(this.calcProp.type == 'Scatter')
curSeria = series[numSeries].yVal.numRef.numCache.pts;
else
curSeria = series[l].val.numRef.numCache.pts;
curSeria = series[l].val.numRef.numCache.pts; var lastCol = curSeria.length;
skipSeries[l] = true; skipSeries[l] = true;
var isRow = false;
if(firstCol == lastCol)
isRow = true;
if(series[l].isHidden == true) if(series[l].isHidden == true)
{
continue; continue;
}
if(!curSeria.length) if(!curSeria.length)
{
continue; continue;
}
if(series[0].xVal && numSeries == 0 && this.calcProp.type == 'Scatter')
l--;
skipSeries[l] = false; skipSeries[l] = false;
arrValues[numSeries] = []; arrValues[numSeries] = [];
arrFormatAdobeLabels[numSeries] = [];
catNameLabels[numSeries] = [];
isSkip[numSeries] = true; isSkip[numSeries] = true;
var row = firstRow; var row = firstRow;
var n = 0; var n = 0;
for(var col = firstCol; col < curSeria.length; ++col) for(var col = firstCol; col < lastCol; ++col)
{ {
if(!curSeria[col]) if(!curSeria[col])
{ {
...@@ -771,10 +880,31 @@ CChartsDrawer.prototype = ...@@ -771,10 +880,31 @@ CChartsDrawer.prototype =
continue; continue;
} }
//var cell = ws.getCell(new CellAddress(row - 1, col - 1, 0));
var cell = curSeria[col]; var cell = curSeria[col];
if(numSeries == 0 && col == firstCol && chart.subType != 'stackedPer' && this.calcProp.type != 'Stock')
{
formatCell = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
isDateTimeFormat = cell.isDateTimeFormat;
}
else if(this.calcProp.type == 'Stock' && numSeries == 0 && col == firstCol)
{
formatCellScOy = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
isDateTimeFormat = cell.isDateTimeFormat;
}
if(this.calcProp.type == 'Scatter')
{
if(numSeries == 1 && col == firstCol)
formatCellScOy = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
}
formatAdobeLabel = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
var orValue = cell.val; var orValue = cell.val;
if(series[0].xVal && series[0].xVal.Formula != null && numSeries == 0 && !isNumberVal && this.calcProp.type == 'Scatter')
orValue = col - firstCol + 1;
if('' != orValue) if('' != orValue)
isSkip[numSeries] = false; isSkip[numSeries] = false;
var value = parseFloat(orValue) var value = parseFloat(orValue)
...@@ -788,20 +918,31 @@ CChartsDrawer.prototype = ...@@ -788,20 +918,31 @@ CChartsDrawer.prototype =
max = value max = value
if(!isNaN(value) && value < min) if(!isNaN(value) && value < min)
min = value min = value
if(isNaN(value) && orValue == '' && (((this.calcProp.type == 'Line' ) && this.calcProp.type == 'normal'))) if(isNaN(value) && orValue == '' && (((this.calcProp.type == 'Line' ) && this.calcProp.type == 'normal') || (this.calcProp.type == 'Scatter' )))
{ {
value = ''; value = '';
} }
else if (isNaN(value)) else if (isNaN(value))
{ {
if(this.calcProp.type == "Bar" || this.calcProp.type == "HBar")
formatAdobeLabel = null;
value = 0; value = 0;
} }
if(this.calcProp.type == 'Pie' || this.calcProp.type == "DoughnutChart") if(this.calcProp.type == 'Pie' || this.calcProp.type == "DoughnutChart")
arrValues[numSeries][n] = Math.abs(value); arrValues[numSeries][n] = Math.abs(value);
else else
arrValues[numSeries][n] = value; arrValues[numSeries][n] = value;
arrFormatAdobeLabels[numSeries][n] = formatAdobeLabel;
if(chart.bShowCatName && this.calcProp.type != 'Scatter')
{
if(series[numSeries] && series[numSeries].Cat && series[numSeries].Cat.NumCache[col] && this.calcProp.type != "Pie" && this.calcProp.type != "DoughnutChart")
catNameLabels[numSeries][n] = series[numSeries].Cat.NumCache[col].val;
else if(this.calcProp.type != "Pie" && this.calcProp.type != "DoughnutChart" && series[numSeries] && series[numSeries].TxCache)
catNameLabels[numSeries][n] = series[numSeries].TxCache.Tx;
else if(series[numSeries] && series[numSeries] && series[numSeries].TxCache)
catNameLabels[numSeries][n] = series[numSeries].TxCache.Tx;
}
n++; n++;
} }
numSeries++; numSeries++;
...@@ -855,266 +996,24 @@ CChartsDrawer.prototype = ...@@ -855,266 +996,24 @@ CChartsDrawer.prototype =
this.calcProp.ymax = maxY; this.calcProp.ymax = maxY;
} }
this.calcProp.min = min;
this.calcProp.max = max;
if(newArr)
arrValues = newArr;
if(this.calcProp.type == 'Bar' || this.calcProp.type == 'HBar')
this.calcProp.data = arrReverse(arrValues);
else
this.calcProp.data = arrValues
},
_calculateData: function(chart) {
var isSeries = false;
var formatCell = 'General';
var formatCellScOy = 'General';
var defaultFormat = 'General';
var isDateTimeFormat;
var api_doc = window["editor"];
var api_sheet = window["Asc"]["editor"];
var styleManager = api_doc ? api_doc.chartStyleManager : api_sheet.chartStyleManager;
var arrFormatAdobeLabels = [];
var catNameLabels = [];
//просматриваем bShowValue для каждой из серий if(isSeries)
//TODO позже отрисовывать значения для каждой серии индивидуально {
/*if ( !chart.bShowValue ) { var arrFormatAdobeLabelsRev = arrFormatAdobeLabels;
for (var n = 0; n < chart.series.length; n++) { var arrValuesRev = arrValues;
if ( chart.series[n].bShowValue ) {
chart.bShowValue = true;
break;
}
}
} }
if(chart.bShowCatName) isEn = false;
chart.bShowValue = true;*/ if(this.calcProp.type == 'Scatter' && !newArr)
var max = 0;
var min = 0;
var minY = 0;
var maxY = 0;
var newArr, formatAdobeLabel, xNumCache, yNumCache;
var series = chart.chart.plotArea.chart.series;
if(series && series.length != 0 && this.calcProp.type != 'Scatter')//берём данные из NumCache
{ {
isSeries = true; /*min = 0;
/*chart.reSeries = chart.series; max = 0;
if(chart.type == 'Pie') minY = 0;
{ maxY = 0;
series = chart.getReverseSeries(true); var isEnY = false
chart.reSeries = series; var scatterArr = arrValuesRev;
}*/ var scatterArrLabels = arrFormatAdobeLabelsRev;
if(!scatterArr)
var arrValues = [];
var isSkip = [];
var skipSeries = [];
var isEn = false;
var isEnY = false;
var numSeries = 0;
var curSeria;
var isNumberVal = true;
if(series[0] && series[0].xVal && series[0].xVal.Formula != null && this.calcProp.type == 'Scatter')
{
var cash = series[0].xVal.NumCache;
for(var i = 0; i < cash.length; i++)
{
if(!isNumber(cash.val))
isNumberVal = false;
}
}
for(var l = 0; l < series.length; ++l)
{
var firstCol = 0;
var firstRow = 0;
if(series[0].xVal && numSeries == 0 && this.calcProp.type == 'Scatter' && series[numSeries].xVal.numRef.numCache.pts.length)
{
curSeria = series[numSeries].xVal.numRef.numCache.pts;
}
else if(this.calcProp.type == 'Scatter')
curSeria = series[numSeries].yVal.numRef.numCache.pts;
else
curSeria = series[l].val.numRef.numCache.pts;
var lastCol = curSeria.length;
skipSeries[l] = true;
var isRow = false;
if(firstCol == lastCol)
isRow = true;
if(series[l].isHidden == true)
{
continue;
}
if(!curSeria.length)
{
continue;
}
if(series[0].xVal && numSeries == 0 && this.calcProp.type == 'Scatter')
l--;
skipSeries[l] = false;
arrValues[numSeries] = [];
arrFormatAdobeLabels[numSeries] = [];
catNameLabels[numSeries] = [];
isSkip[numSeries] = true;
var row = firstRow;
var n = 0;
for(var col = firstCol; col < lastCol; ++col)
{
if(!curSeria[col])
{
curSeria[col] = {val:0};
}
else if(curSeria[col].isHidden == true)
{
continue;
}
//var cell = ws.getCell(new CellAddress(row - 1, col - 1, 0));
var cell = curSeria[col];
if(numSeries == 0 && col == firstCol && chart.subType != 'stackedPer' && this.calcProp.type != 'Stock')
{
formatCell = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
isDateTimeFormat = cell.isDateTimeFormat;
}
else if(this.calcProp.type == 'Stock' && numSeries == 0 && col == firstCol)
{
formatCellScOy = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
isDateTimeFormat = cell.isDateTimeFormat;
}
if(this.calcProp.type == 'Scatter')
{
if(numSeries == 1 && col == firstCol)
formatCellScOy = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
}
formatAdobeLabel = cell.numFormatStr ? cell.numFormatStr : defaultFormat;
var orValue = cell.val;
if(series[0].xVal && series[0].xVal.Formula != null && numSeries == 0 && !isNumberVal && this.calcProp.type == 'Scatter')
orValue = col - firstCol + 1;
if('' != orValue)
isSkip[numSeries] = false;
var value = parseFloat(orValue)
if(!isEn && !isNaN(value))
{
min = value;
max = value;
isEn = true;
}
if(!isNaN(value) && value > max)
max = value
if(!isNaN(value) && value < min)
min = value
if(isNaN(value) && orValue == '' && (((this.calcProp.type == 'Line' ) && this.calcProp.type == 'normal') || (this.calcProp.type == 'Scatter' )))
{
value = '';
}
else if (isNaN(value))
{
if(this.calcProp.type == "Bar" || this.calcProp.type == "HBar")
formatAdobeLabel = null;
value = 0;
}
if(this.calcProp.type == 'Pie' || this.calcProp.type == "DoughnutChart")
arrValues[numSeries][n] = Math.abs(value);
else
arrValues[numSeries][n] = value;
arrFormatAdobeLabels[numSeries][n] = formatAdobeLabel;
if(chart.bShowCatName && this.calcProp.type != 'Scatter')
{
if(series[numSeries] && series[numSeries].Cat && series[numSeries].Cat.NumCache[col] && this.calcProp.type != "Pie" && this.calcProp.type != "DoughnutChart")
catNameLabels[numSeries][n] = series[numSeries].Cat.NumCache[col].val;
else if(this.calcProp.type != "Pie" && this.calcProp.type != "DoughnutChart" && series[numSeries] && series[numSeries].TxCache)
catNameLabels[numSeries][n] = series[numSeries].TxCache.Tx;
else if(series[numSeries] && series[numSeries] && series[numSeries].TxCache)
catNameLabels[numSeries][n] = series[numSeries].TxCache.Tx;
}
n++;
}
numSeries++;
}
}
else
{
var yVal;
var xVal;
newArr = [];
for(var l = 0; l < series.length; ++l)
{
newArr[l] = [];
yNumCache = series[l].yVal.numRef.numCache ? series[l].yVal.numRef.numCache : series[l].yVal.numLit;
for(var j = 0; j < yNumCache.pts.length; ++j)
{
yVal = parseFloat(yNumCache.pts[j].val);
xNumCache = series[l].xVal && series[l].xVal.numRef ? series[l].xVal.numRef.numCache : series[l].xVal && series[l].xVal.numLit ? series[l].xVal.numLit : null;
if(xNumCache && xNumCache.pts[j] && xNumCache.pts[j].val)
{
if(!isNaN(parseFloat(xNumCache.pts[j].val)))
xVal = parseFloat(xNumCache.pts[j].val);
else
xVal = j + 1;
}
else
xVal = j + 1;
newArr[l][j] = [xVal, yVal];
if(l == 0 && j == 0)
{
min = xVal;
max = xVal;
minY = yVal;
maxY = yVal;
};
if(xVal < min)
min = xVal;
if(xVal > max)
max = xVal;
if(yVal < minY)
minY = yVal;
if(yVal > maxY)
maxY = yVal;
}
}
this.calcProp.ymin = minY;
this.calcProp.ymax = maxY;
}
if(isSeries)
{
var arrFormatAdobeLabelsRev = arrFormatAdobeLabels;
var arrValuesRev = arrValues;
}
isEn = false;
if(this.calcProp.type == 'Scatter' && !newArr)
{
/*min = 0;
max = 0;
minY = 0;
maxY = 0;
var isEnY = false
var scatterArr = arrValuesRev;
var scatterArrLabels = arrFormatAdobeLabelsRev;
if(!scatterArr)
{ {
scatterArr = arrReverse(arrValues); scatterArr = arrReverse(arrValues);
scatterArrLabels = arrReverse(arrFormatAdobeLabels); scatterArrLabels = arrReverse(arrFormatAdobeLabels);
...@@ -1205,434 +1104,29 @@ CChartsDrawer.prototype = ...@@ -1205,434 +1104,29 @@ CChartsDrawer.prototype =
{ {
this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabelsRev; this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabelsRev;
this.calcProp.data = arrValuesRev; this.calcProp.data = arrValuesRev;
} }
else else
{ {
this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabels; this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabels;
this.calcProp.data = arrValues; this.calcProp.data = arrValues;
} }
} }
else else
{ {
if(this.calcProp.type == 'HBar' || this.calcProp.type == 'Bar' || this.calcProp.type == 'Stock') if(this.calcProp.type == 'HBar' || this.calcProp.type == 'Bar' || this.calcProp.type == 'Stock')
{ {
this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabels; this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabels;
this.calcProp.data = arrValues; this.calcProp.data = arrValues;
} }
else else
{ {
this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabelsRev; this.calcProp.arrFormatAdobeLabels = arrFormatAdobeLabelsRev;
this.calcProp.data = arrValuesRev; this.calcProp.data = arrValuesRev;
} }
} }
}
}
},
_calculateWidthChart: function() {
var trueWidth = this.calcProp.trueWidth;
var trueHeight = this.calcProp.trueHeight;
if('Line' == this.calcProp.type)
{
var lengthOfData = this.calcProp.data[0].length;
var widthChart = (trueWidth/lengthOfData)*(lengthOfData - 1) + 5;
this.calcProp.hmargin = (trueWidth - widthChart) / 2;
}
else {
var pointKoff = 1 - 1 / (this.calcProp.data[0].length)
this.calcProp.hmargin = (trueWidth - trueWidth * pointKoff) / 2;
}
if('Area' == this.calcProp.type)
this.calcProp.hmargin = 0;
},
calculateSizePlotArea : function(chartSpace)
{
this._calculateMarginsChart(chartSpace);
var widthCanvas = chartSpace.extX;
var heightCanvas = chartSpace.extY;
var w = widthCanvas - (this.calcProp.chartGutter._left + this.calcProp.chartGutter._right) / this.calcProp.pxToMM;
var h = heightCanvas - (this.calcProp.chartGutter._top + this.calcProp.chartGutter._bottom) / this.calcProp.pxToMM;
return {w: w , h: h , startX: this.calcProp.chartGutter._left / this.calcProp.pxToMM, startY: this.calcProp.chartGutter._top / this.calcProp.pxToMM};
},
_calculateMarginsChart: function(chartSpace) {
this.calcProp.chartGutter = {};
if(!this.calcProp.pxToMM)
this.calcProp.pxToMM = 1 / chartSpace.convertPixToMM(1);
var pxToMM = this.calcProp.pxToMM;
var standartMargin = 13 / pxToMM;
var isHBar = (chartSpace.chart.plotArea.chart.getObjectType() == historyitem_type_BarChart && chartSpace.chart.plotArea.chart.barDir != 1) ? true : false;
//высчитываем выходящие за пределы подписи осей
var labelsMargin = this._calculateMarginLabels(chartSpace);
var left = labelsMargin.left, right = labelsMargin.right, top = labelsMargin.top, bottom = labelsMargin.bottom;
//****left*****
if(left || !right)
{
if(chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null && !isHBar)
left += chartSpace.chart.plotArea.valAx.title.extX + standartMargin;
else if(isHBar && chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null)
left += chartSpace.chart.plotArea.catAx.title.extX + standartMargin;
else
left += standartMargin / 2;
}
else
left += standartMargin;
//****right*****
if(right)
{
right += standartMargin / 2;
if(chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null && !isHBar)
left += chartSpace.chart.plotArea.valAx.title.extX;
else if(isHBar && chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null)
left += chartSpace.chart.plotArea.catAx.title.extX;
}
else
right += standartMargin;
//****bottom*****
if(bottom || !top)
{
if(chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null && !isHBar)
bottom += chartSpace.chart.plotArea.catAx.title.extY + standartMargin;
else if(isHBar && chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null)
bottom += chartSpace.chart.plotArea.valAx.title.extY + standartMargin;
else
bottom += standartMargin / 2;
}
else
bottom += standartMargin;
//****top*****
if(top)
{
top += standartMargin + standartMargin / 2;
if(chartSpace.chart.plotArea.catAx && chartSpace.chart.plotArea.catAx.title != null && !isHBar)
bottom += chartSpace.chart.plotArea.catAx.title.extY;
else if(isHBar && chartSpace.chart.plotArea.valAx && chartSpace.chart.plotArea.valAx.title != null)
bottom += chartSpace.chart.plotArea.valAx.title.extY;
if(chartSpace.chart.title !== null && !chartSpace.chart.title.overlay)
top += chartSpace.chart.title.extY;
}
else
{
top += standartMargin;
if(chartSpace.chart.title !== null && !chartSpace.chart.title.overlay)
top += chartSpace.chart.title.extY + standartMargin / 2;
}
//KEY
if(chartSpace.chart.legend && !chartSpace.chart.legend.overlay)
{
switch ( chartSpace.chart.legend.legendPos )
{
case LEGEND_POS_L:
{
left += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
case LEGEND_POS_T:
{
top += chartSpace.chart.legend.extY + standartMargin / 2;
break;
}
case LEGEND_POS_R:
{
right += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
case LEGEND_POS_B:
{
bottom += chartSpace.chart.legend.extY + standartMargin / 2;
break;
}
case LEGEND_POS_TR:
{
right += chartSpace.chart.legend.extX + standartMargin / 2;
break;
}
}
}
this.calcProp.chartGutter._left = left * pxToMM;
this.calcProp.chartGutter._right = right * pxToMM;
this.calcProp.chartGutter._top = top * pxToMM;
this.calcProp.chartGutter._bottom = bottom * pxToMM;
},
_calculateMarginLabels: function(chartSpace)
{
var isHBar = this.calcProp.type;
var left = 0, right = 0, bottom = 0, top = 0;
var leftDownPointX, leftDownPointY, rightUpPointX, rightUpPointY;
var valAx = chartSpace.chart.plotArea.valAx;
var catAx = chartSpace.chart.plotArea.catAx;
if(isHBar === 'HBar' && catAx && valAx && catAx.yPoints && valAx.xPoints)
{
if(catAx.yPoints.length > 1)
{
if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
leftDownPointY = catAx.yPoints[0].pos - (catAx.yPoints[1].pos - catAx.yPoints[0].pos) / 2;
else
leftDownPointY = catAx.yPoints[0].pos;
}
else
leftDownPointY = valAx.labels.y;
leftDownPointX = valAx.xPoints[0].pos;
if(catAx.yPoints.length > 1)
{
if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
rightUpPointY = catAx.yPoints[0].pos - Math.abs((catAx.yPoints[1].pos - catAx.yPoints[0].pos) / 2);
else
rightUpPointY = catAx.yPoints[catAx.yPoints.length - 1].pos;
}
else
rightUpPointY = catAx.labels.x;
rightUpPointX = valAx.xPoints[valAx.xPoints.length - 1].pos;
if(catAx.labels && !catAx.bDelete)
{
//подпись оси OY находится левее крайней левой точки
if(leftDownPointX >= catAx.labels.x)
{
left = leftDownPointX - catAx.labels.x;
}
else if((catAx.labels.x + catAx.labels.extX) >= rightUpPointX)//правее крайней правой точки
{
right = catAx.labels.x + catAx.labels.extX - rightUpPointX;
}
}
if(valAx.labels && !valAx.bDelete)
{
//подпись оси OX находится ниже крайней нижней точки
if((valAx.labels.y + valAx.labels.extY) >= leftDownPointY)
{
bottom = (valAx.labels.y + valAx.labels.extY) - leftDownPointY;
}
else if(valAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - valAx.labels.y;
}
}
}
else if(isHBar === 'Scatter' && catAx && valAx && catAx.xPoints && valAx.yPoints)
{
leftDownPointX = catAx.xPoints[0].pos;
leftDownPointY = valAx.yPoints[0].pos;
rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos;
rightUpPointY = valAx.yPoints[valAx.yPoints.length - 1].pos;
if(valAx.labels && !valAx.bDelete)
{
//подпись оси OY находится левее крайней левой точки
if(leftDownPointX >= valAx.labels.x)
{
left = leftDownPointX - valAx.labels.x;
}
else if((valAx.labels.x + valAx.labels.extX) >= rightUpPointY)//правее крайней правой точки
{
right = valAx.labels.x + valAx.labels.extX - rightUpPointY;
}
}
if(catAx.labels && !catAx.bDelete)
{
//подпись оси OX находится ниже крайней нижней точки
if((catAx.labels.y + catAx.labels.extY) >= leftDownPointY)
{
bottom = (catAx.labels.y + catAx.labels.extY) - leftDownPointY;
}
else if(catAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - catAx.labels.y;
}
}
}
else if(isHBar !== undefined && valAx && catAx && catAx.xPoints && valAx.yPoints)
{
if(catAx.xPoints.length > 1)
{
if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
leftDownPointX = catAx.xPoints[0].pos - (catAx.xPoints[1].pos - catAx.xPoints[0].pos) / 2;
else
leftDownPointX = catAx.xPoints[0].pos;
}
else
leftDownPointX = catAx.labels.x;
leftDownPointY = valAx.yPoints[0].pos;
if(catAx.xPoints.length > 1)
{
if(valAx.crossBetween == CROSS_BETWEEN_BETWEEN)
rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos + (catAx.xPoints[1].pos - catAx.xPoints[0].pos) / 2;
else
rightUpPointX = catAx.xPoints[catAx.xPoints.length - 1].pos;
}
else
rightUpPointX = catAx.labels.x;
if(valAx.scaling.orientation == ORIENTATION_MIN_MAX)
rightUpPointY = valAx.yPoints[valAx.yPoints.length - 1].pos;
else
rightUpPointY = valAx.yPoints[0].pos;
if(valAx.labels && !valAx.bDelete)
{
//подпись оси OY находится левее крайней левой точки
if(leftDownPointX >= valAx.labels.x)
{
left = leftDownPointX - valAx.labels.x;
}
else if((valAx.labels.x + valAx.labels.extX) >= rightUpPointY)//правее крайней правой точки
{
right = valAx.labels.extX;
}
}
if(catAx.labels && !catAx.bDelete)
{
//подпись оси OX находится ниже крайней нижней точки
if((catAx.labels.y + catAx.labels.extY) >= leftDownPointY)
{
bottom = (catAx.labels.y + catAx.labels.extY) - leftDownPointY;
}
else if(catAx.labels.y <= rightUpPointY)//выше верхней
{
top = rightUpPointY - catAx.labels.y;
}
}
}
return {left: left, right: right, top: top, bottom: bottom};
},
_getNullPosition: function()
{
var numNull = this.calcProp.numhlines;
var min = this.calcProp.min;
var max = this.calcProp.max;
var orientation = this.cChartSpace ? this.cChartSpace.chart.plotArea.valAx.scaling.orientation : ORIENTATION_MIN_MAX;
if(min >= 0 && max >= 0)
{
if(orientation == ORIENTATION_MIN_MAX)
numNull = 0;
else
{
numNull = this.calcProp.numhlines;
if(this.calcProp.type == "HBar")
numNull = this.calcProp.numvlines;
}
}
else if(min <= 0 && max <= 0)
{
if(orientation == ORIENTATION_MIN_MAX)
{
numNull = this.calcProp.numhlines;
if(this.calcProp.type == "HBar")
numNull = this.calcProp.numvlines;
}
else
numNull = 0;
}
else
{
for (var i=0; i < this.calcProp.scale.length; i++)
{
if(this.calcProp.scale[i] == 0)
{
if(this.calcProp.type == "HBar")
numNull = i;
else
numNull = i;
break;
}
}
}
var nullPosition;
if(0 == numNull)
nullPosition = 0;
else if(this.calcProp.type == "HBar")
nullPosition = (this.calcProp.widthCanvas - this.calcProp.chartGutter._left - this.calcProp.chartGutter._right)/(this.calcProp.numvlines)*numNull;
else
nullPosition = (this.calcProp.heightCanvas - this.calcProp.chartGutter._bottom - this.calcProp.chartGutter._top)/(this.calcProp.numhlines)*numNull;
var result;
if(this.calcProp.type == "HBar")
result = nullPosition + this.calcProp.chartGutter._left;
else
result = this.calcProp.heightCanvas - this.calcProp.chartGutter._bottom - nullPosition;
return result;
},
_getScatterNullPosition: function()
{
var x, y;
//OY
for(var i = 0; i < this.calcProp.xScale.length; i++)
{
if(this.calcProp.xScale[i] == 0)
{
y = this.calcProp.chartGutter._left + i * (this.calcProp.trueWidth / (this.calcProp.xScale.length - 1));
break;
}
}
//OX
for(var i = 0; i < this.calcProp.scale.length; i++)
{
if(this.calcProp.scale[i] == 0)
{
x = this.calcProp.heightCanvas - (this.calcProp.chartGutter._bottom + i * (this.calcProp.trueHeight / (this.calcProp.scale.length - 1)));
break;
} }
} }
return {x: x, y: y};
}, },
_getAxisData: function (max, mainObj, minVal, maxVal, yminVal, ymaxVal) _getAxisData: function (max, mainObj, minVal, maxVal, yminVal, ymaxVal)
...@@ -1647,11 +1141,6 @@ CChartsDrawer.prototype = ...@@ -1647,11 +1141,6 @@ CChartsDrawer.prototype =
return this._getAnotherChartAxisData(max, mainObj, minVal, maxVal, yminVal, ymaxVal); return this._getAnotherChartAxisData(max, mainObj, minVal, maxVal, yminVal, ymaxVal);
}, },
_getAxisData2: function (isOx, minVal, maxVal, chartProp)
{
return this._getAxisValues(isOx, minVal, maxVal, chartProp);
},
_getLineAreaBarPercentAxisData : function(max, mainObj, minVal, maxVal, yminVal, ymaxVal) _getLineAreaBarPercentAxisData : function(max, mainObj, minVal, maxVal, yminVal, ymaxVal)
{ {
//*** LINE / BAR / AREA + 100% **** //*** LINE / BAR / AREA + 100% ****
...@@ -2695,23 +2184,257 @@ CChartsDrawer.prototype = ...@@ -2695,23 +2184,257 @@ CChartsDrawer.prototype =
break; break;
} }
} }
if(minVal < 0 && maxVal <= 0) if(minVal < 0 && maxVal <= 0)
massRes = this._array_reverse(massRes); massRes = this._array_reverse(massRes);
}
if('line' == mainObj.type && max > 0 && min < 0)
{
mainObj.ymax = massRes[massRes.length - 1];
mainObj.ymin = this._round_val(this._array_exp(massRes[0] - stepOY));
}
else
{
mainObj.ymax = massRes[massRes.length - 1];
mainObj.ymin = this._round_val(this._array_exp(massRes[0] - stepOY));
}
return this._array_exp(massRes);
},
//****new calculate data****
_calculateStackedData2: function()
{
if(this.calcProp.type == "Bar" || this.calcProp.type == "HBar")
{
if (this.calcProp.subType == 'stacked') {
var originalData = $.extend(true, [], this.calcProp.data);
for (var j = 0; j < this.calcProp.data.length; j++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j][i] = this._findPrevValue(originalData, j, i)
}
}
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
}
else if(this.calcProp.subType == 'stackedPer') {
var summ;
var originalData = $.extend(true, [], this.calcProp.data);
for (var j = 0; j < (this.calcProp.data.length); j++) {
summ = 0;
for (var i = 0; i < this.calcProp.data[j].length; i++) {
summ += Math.abs(this.calcProp.data[j][i]);
}
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j][i] = (this._findPrevValue(originalData, j, i) * 100) / summ;
}
}
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
}
};
if(this.calcProp.type == "Line" || this.calcProp.type == "Area")
{
if (this.calcProp.subType == 'stacked') {
for (var j = 0; j < (this.calcProp.data.length - 1); j++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) {
if(!this.calcProp.data[j + 1])
this.calcProp.data[j + 1] = [];
this.calcProp.data[j + 1][i] = this.calcProp.data[j + 1][i] + this.calcProp.data[j][i];
}
}
this.calcProp.max = this._getMaxValueArray(this.calcProp.data);
this.calcProp.min = this._getMinValueArray(this.calcProp.data);
}
else if (this.calcProp.subType == 'stackedPer') {
var firstData = this.calcProp.data;
var summValue = [];
for (var j = 0; j < (firstData[0].length); j++) {
summValue[j] = 0;
for (var i = 0; i < firstData.length; i++) {
summValue[j] += Math.abs(firstData[i][j])
}
}
for (var j = 0; j < (this.calcProp.data.length - 1); j++) {
for (var i = 0; i < this.calcProp.data[j].length; i++) {
this.calcProp.data[j + 1][i] = this.calcProp.data[j + 1][i] + this.calcProp.data[j][i]
}
}
var tempData = this.calcProp.data;
for (var j = 0; j < (tempData[0].length); j++) {
for (var i = 0; i < tempData.length; i++) {
if(summValue[j] == 0)
tempData[i][j] = 0;
else
tempData[i][j] = (100 * tempData[i][j]) / (summValue[j]);
}
}
this.calcProp.max = this._getMaxValueArray(tempData);
this.calcProp.min = this._getMinValueArray(tempData);
this.calcProp.data = tempData;
}
};
},
_calculateData2: function(chart) {
var max = 0;
var min = 0;
var minY = 0;
var maxY = 0;
var xNumCache, yNumCache, newArr;
var series = chart.chart.plotArea.chart.series;
if(this.calcProp.type != 'Scatter')//берём данные из NumCache
{
var arrValues = [];
var isSkip = [];
var skipSeries = [];
var isEn = false;
var isEnY = false;
var numSeries = 0;
var curSeria;
var isNumberVal = true;
for(var l = 0; l < series.length; ++l)
{
var firstCol = 0;
var firstRow = 0;
curSeria = series[l].val.numRef.numCache.pts;
skipSeries[l] = true;
if(series[l].isHidden == true)
continue;
if(!curSeria.length)
continue;
skipSeries[l] = false;
arrValues[numSeries] = [];
isSkip[numSeries] = true;
var row = firstRow;
var n = 0;
for(var col = firstCol; col < curSeria.length; ++col)
{
if(!curSeria[col])
{
curSeria[col] = {val:0};
}
else if(curSeria[col].isHidden == true)
{
continue;
}
var cell = curSeria[col];
var orValue = cell.val;
if('' != orValue)
isSkip[numSeries] = false;
var value = parseFloat(orValue)
if(!isEn && !isNaN(value))
{
min = value;
max = value;
isEn = true;
}
if(!isNaN(value) && value > max)
max = value
if(!isNaN(value) && value < min)
min = value
if(isNaN(value) && orValue == '' && (((this.calcProp.type == 'Line' ) && this.calcProp.type == 'normal')))
{
value = '';
}
else if (isNaN(value))
{
value = 0;
}
if(this.calcProp.type == 'Pie' || this.calcProp.type == "DoughnutChart")
arrValues[numSeries][n] = Math.abs(value);
else
arrValues[numSeries][n] = value;
n++;
}
numSeries++;
}
}
else
{
var yVal;
var xVal;
newArr = [];
for(var l = 0; l < series.length; ++l)
{
newArr[l] = [];
yNumCache = series[l].yVal.numRef.numCache ? series[l].yVal.numRef.numCache : series[l].yVal.numLit;
for(var j = 0; j < yNumCache.pts.length; ++j)
{
yVal = parseFloat(yNumCache.pts[j].val);
xNumCache = series[l].xVal && series[l].xVal.numRef ? series[l].xVal.numRef.numCache : series[l].xVal && series[l].xVal.numLit ? series[l].xVal.numLit : null;
if(xNumCache && xNumCache.pts[j] && xNumCache.pts[j].val)
{
if(!isNaN(parseFloat(xNumCache.pts[j].val)))
xVal = parseFloat(xNumCache.pts[j].val);
else
xVal = j + 1;
}
else
xVal = j + 1;
newArr[l][j] = [xVal, yVal];
if(l == 0 && j == 0)
{
min = xVal;
max = xVal;
minY = yVal;
maxY = yVal;
};
if(xVal < min)
min = xVal;
if(xVal > max)
max = xVal;
if(yVal < minY)
minY = yVal;
if(yVal > maxY)
maxY = yVal;
}
}
this.calcProp.ymin = minY;
this.calcProp.ymax = maxY;
} }
this.calcProp.min = min;
this.calcProp.max = max;
if('line' == mainObj.type && max > 0 && min < 0) if(newArr)
{ arrValues = newArr;
mainObj.ymax = massRes[massRes.length - 1];
mainObj.ymin = this._round_val(this._array_exp(massRes[0] - stepOY)); if(this.calcProp.type == 'Bar' || this.calcProp.type == 'HBar')
} this.calcProp.data = arrReverse(arrValues);
else else
{ this.calcProp.data = arrValues
mainObj.ymax = massRes[massRes.length - 1];
mainObj.ymin = this._round_val(this._array_exp(massRes[0] - stepOY));
}
return this._array_exp(massRes);
}, },
_getAxisData2: function (isOx, minVal, maxVal, chartProp)
{
return this._getAxisValues(isOx, minVal, maxVal, chartProp);
},
_getAxisValues : function(isOx, yMin, yMax, chartProp) _getAxisValues : function(isOx, yMin, yMax, chartProp)
{ {
...@@ -2854,142 +2577,215 @@ CChartsDrawer.prototype = ...@@ -2854,142 +2577,215 @@ CChartsDrawer.prototype =
return {min: axisMin, max: axisMax}; return {min: axisMin, max: axisMax};
}, },
_getFirstDegree: function(val)
//****get null position****
_getNullPosition: function()
{ {
var secPart = val.toString().split('.'); var numNull = this.calcProp.numhlines;
var numPow = 1,tempMax;
var min = this.calcProp.min;
var max = this.calcProp.max;
var orientation = this.cChartSpace ? this.cChartSpace.chart.plotArea.valAx.scaling.orientation : ORIENTATION_MIN_MAX;
if(secPart[1] && secPart[1].toString().search('e+') != -1 && secPart[0] && secPart[0].toString().length == 1) if(min >= 0 && max >= 0)
{ {
var expNum = secPart[1].toString().split('e+'); if(orientation == ORIENTATION_MIN_MAX)
numPow = Math.pow(10, expNum[1]); numNull = 0;
else
{
numNull = this.calcProp.numhlines;
if(this.calcProp.type == "HBar")
numNull = this.calcProp.numvlines;
}
} }
else if(0 != secPart[0]) else if(min <= 0 && max <= 0)
numPow = Math.pow(10, secPart[0].toString().length - 1)
else if(0 == secPart[0])
{ {
var tempMax = val; if(orientation == ORIENTATION_MIN_MAX)
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{ {
tempMax = val; numNull = this.calcProp.numhlines;
numPow = Math.pow(10, num); if(this.calcProp.type == "HBar")
tempMax = tempMax / numPow; numNull = this.calcProp.numvlines;
num--; }
else
numNull = 0;
}
else
{
for (var i=0; i < this.calcProp.scale.length; i++)
{
if(this.calcProp.scale[i] == 0)
{
if(this.calcProp.type == "HBar")
numNull = i;
else
numNull = i;
break;
}
} }
val = tempMax;
} }
if(tempMax == undefined) var nullPosition;
val = val / numPow; if(0 == numNull)
nullPosition = 0;
else if(this.calcProp.type == "HBar")
nullPosition = (this.calcProp.widthCanvas - this.calcProp.chartGutter._left - this.calcProp.chartGutter._right)/(this.calcProp.numvlines)*numNull;
else
nullPosition = (this.calcProp.heightCanvas - this.calcProp.chartGutter._bottom - this.calcProp.chartGutter._top)/(this.calcProp.numhlines)*numNull;
return {val: val, numPow: numPow}; var result;
if(this.calcProp.type == "HBar")
result = nullPosition + this.calcProp.chartGutter._left;
else
result = this.calcProp.heightCanvas - this.calcProp.chartGutter._bottom - nullPosition;
return result;
}, },
_round_val: function (num) _getScatterNullPosition: function()
{ {
if(num.toString() && num.toString().indexOf('e+') == -1 && isNaN(parseFloat(num))) var x, y;
return num; //OY
var floatKoff = 100000000000; for(var i = 0; i < this.calcProp.xScale.length; i++)
if(num.toString() && num.toString().indexOf('e+') > -1)
{
var parseVal = num.toString().split("e+");
var roundVal = Math.round(parseFloat(parseVal[0])*floatKoff)/floatKoff;
var changeSymbol = roundVal.toString() + "e+" + parseVal[1];
num = parseFloat(changeSymbol);
}
num = Math.round(num*floatKoff)/floatKoff ;
return num;
},
_array_exp: function (arr)
{
var maxDig = 1000000000;
var minDig = 0.000000001;
var floatKoff = 100000000000;
if(typeof(arr) == 'number')
{ {
if(arr < 0) if(this.calcProp.xScale[i] == 0)
maxDig = 100000000;
if(Math.abs(arr) > maxDig)
{ {
var tmp = Math.abs(arr); y = this.calcProp.chartGutter._left + i * (this.calcProp.trueWidth / (this.calcProp.xScale.length - 1));
var exp = 0; break;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
if(arr < 0)
tmp *= -1;
arr = tmp + "E+" + exp;
} }
} }
else //OX
for(var i = 0; i < this.calcProp.scale.length; i++)
{ {
for (var i=0; i<arr.length; ++i) { if(this.calcProp.scale[i] == 0)
maxDig = 1000000000 {
if(arr[i] < 0) x = this.calcProp.heightCanvas - (this.calcProp.chartGutter._bottom + i * (this.calcProp.trueHeight / (this.calcProp.scale.length - 1)));
maxDig = 100000000; break;
if(Math.abs(arr[i]) > maxDig)
{
var tmp = Math.abs(arr[i]);
var exp = 0;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
tmp = Math.round(tmp*floatKoff)/floatKoff
if(arr[i] < 0)
tmp *= -1;
arr[i] = tmp + "E+" + exp;
}
} }
} }
return arr; return {x: x, y: y};
}, },
_array_reverse: function (arr)
{
var newarr = [];
for (var i = arr.length - 1; i >= 0; i--) {
newarr.push(arr[i]);
}
return newarr;
},
_convert3DTo2D: function(x, y, z, p, q, r)
//****functions for UP Functions****
preCalculateData: function(chartProp)
{ {
var convertMatrix = [[1, 0, 0, p], [0, 1, 0, q], [0, 0, 0, r], [0, 0, 0, 1]]; this.calcProp.pxToMM = 1 / chartProp.convertPixToMM(1);
this.calcProp.pathH = 1000000000;
this.calcProp.pathW = 1000000000;
var typeChart = chartProp.chart.plotArea.chart.getObjectType();
switch ( typeChart )
{
case historyitem_type_LineChart:
{
this.calcProp.type = "Line";
break;
}
case historyitem_type_BarChart:
{
if(chartProp.chart.plotArea.chart.barDir == 1)
this.calcProp.type = "Bar";
else
this.calcProp.type = "HBar";
break;
}
case historyitem_type_PieChart:
{
this.calcProp.type = "Pie";
break;
}
case historyitem_type_AreaChart:
{
this.calcProp.type = "Area";
break;
}
case historyitem_type_ScatterChart:
{
this.calcProp.type = "Scatter";
break;
}
case historyitem_type_StockChart:
{
this.calcProp.type = "Stock";
break;
}
case historyitem_type_DoughnutChart:
{
this.calcProp.type = "DoughnutChart";
break;
}
case historyitem_type_RadarChart:
{
this.calcProp.type = "Radar";
break;
}
case historyitem_type_BubbleChart:
{
this.calcProp.type = "BubbleChart";
break;
}
};
var grouping = chartProp.chart.plotArea.chart.grouping;
if(this.calcProp.type == "Line" || this.calcProp.type == "Area")
this.calcProp.subType = (grouping === GROUPING_PERCENT_STACKED) ? "stackedPer" : (grouping === GROUPING_STACKED) ? "stacked" : "normal"
else
this.calcProp.subType = (grouping === BAR_GROUPING_PERCENT_STACKED) ? "stackedPer" : (grouping === BAR_GROUPING_STACKED) ? "stacked" : "normal"
this.calcProp.xaxispos = null;
this.calcProp.yaxispos = null;
//рассчёт данных и ещё некоторых параметров(this.calcProp./min/max/ymax/ymin/data)
this._calculateData2(chartProp);
//пересчёт данных для накопительных диаграмм
if(this.calcProp.subType == 'stackedPer' || this.calcProp.subType == 'stacked')
this._calculateStackedData2();
//***series***
this.calcProp.series = chartProp.chart.plotArea.chart.series;
var qC = x * convertMatrix[0][3] + y * convertMatrix[1][3] + z * convertMatrix[2][3] + 1; //находим значния для осей
var newX = (x * convertMatrix[0][0] + y * convertMatrix[1][0] + z * convertMatrix[2][0] - 0)/(qC); /*this.calcProp.scale = this._getAxisData(false, this.calcProp, this.calcProp.min, this.calcProp.max, this.calcProp.ymin, this.calcProp.ymax, chartProp);
var newY = (x * convertMatrix[0][1] + y * convertMatrix[1][1] + z * convertMatrix[2][1] - 0)/(qC); if(this.calcProp.type == "Scatter")
return {x: newX, y: newY}; this.calcProp.xScale = this._getAxisData(true, this.calcProp, this.calcProp.min, this.calcProp.max, this.calcProp.ymin, this.calcProp.ymax, chartProp);*/
if(this.calcProp.type == "Scatter")
{
this.calcProp.scale = this._getAxisData2(false, this.calcProp.ymin, this.calcProp.ymax, chartProp);
this.calcProp.xScale = this._getAxisData2(true, this.calcProp.min, this.calcProp.max, chartProp);
}
else
this.calcProp.scale = this._getAxisData2(false, this.calcProp.min, this.calcProp.max, chartProp);
this.calcProp.widthCanvas = chartProp.extX*this.calcProp.pxToMM;
this.calcProp.heightCanvas = chartProp.extY*this.calcProp.pxToMM;
}, },
_turnCoords: function(x, y, z, angleOX, angleOY, angleOZ) calculateSizePlotArea : function(chartSpace)
{ {
var newX, newY, newZ; this._calculateMarginsChart(chartSpace);
//around OY
newX = x * Math.cos(angleOY) - z * Math.sin(angleOY);
newY = y;
newZ = x * Math.sin(angleOY) + z * Math.cos(angleOY);
//around OX var widthCanvas = chartSpace.extX;
newX = newX; var heightCanvas = chartSpace.extY;
newY = newY * Math.cos(angleOX) + newZ * Math.sin(angleOX);
newZ = newZ * Math.cos(angleOX) - newY * Math.sin(angleOX);
//around OZ var w = widthCanvas - (this.calcProp.chartGutter._left + this.calcProp.chartGutter._right) / this.calcProp.pxToMM;
newX = newX * Math.cos(angleOZ) + newY * Math.sin(angleOZ); var h = heightCanvas - (this.calcProp.chartGutter._top + this.calcProp.chartGutter._bottom) / this.calcProp.pxToMM;
newY = newY * Math.cos(angleOZ) - newX * Math.sin(angleOZ);
newZ = newZ;
return {x: newX,y: newY,z: newZ};
return {w: w , h: h , startX: this.calcProp.chartGutter._left / this.calcProp.pxToMM, startY: this.calcProp.chartGutter._top / this.calcProp.pxToMM};
}, },
//****functions for chart classes****
calculatePoint: function(x, y, size, symbol) calculatePoint: function(x, y, size, symbol)
{ {
size = size / 2.69; size = size / 2.69;
...@@ -3163,6 +2959,216 @@ CChartsDrawer.prototype = ...@@ -3163,6 +2959,216 @@ CChartsDrawer.prototype =
} }
return result; return result;
},
//****for 3D****
_convert3DTo2D: function(x, y, z, p, q, r)
{
var convertMatrix = [[1, 0, 0, p], [0, 1, 0, q], [0, 0, 0, r], [0, 0, 0, 1]];
var qC = x * convertMatrix[0][3] + y * convertMatrix[1][3] + z * convertMatrix[2][3] + 1;
var newX = (x * convertMatrix[0][0] + y * convertMatrix[1][0] + z * convertMatrix[2][0] - 0)/(qC);
var newY = (x * convertMatrix[0][1] + y * convertMatrix[1][1] + z * convertMatrix[2][1] - 0)/(qC);
return {x: newX, y: newY};
},
_turnCoords: function(x, y, z, angleOX, angleOY, angleOZ)
{
var newX, newY, newZ;
//around OY
newX = x * Math.cos(angleOY) - z * Math.sin(angleOY);
newY = y;
newZ = x * Math.sin(angleOY) + z * Math.cos(angleOY);
//around OX
newX = newX;
newY = newY * Math.cos(angleOX) + newZ * Math.sin(angleOX);
newZ = newZ * Math.cos(angleOX) - newY * Math.sin(angleOX);
//around OZ
newX = newX * Math.cos(angleOZ) + newY * Math.sin(angleOZ);
newY = newY * Math.cos(angleOZ) - newX * Math.sin(angleOZ);
newZ = newZ;
return {x: newX,y: newY,z: newZ};
},
//****accessory functions****
_getSumArray: function (arr, isAbs)
{
if (typeof(arr) == 'number') {
return arr;
}
else if(typeof(arr) == 'string'){
return parseFloat(arr);
}
var i, sum;
for(i = 0,sum = 0; i < arr.length; i++)
{
if(typeof(arr[i]) == 'object' && arr[i].val)
sum += parseFloat(isAbs ? Math.abs(arr[i].val) : arr[i].val);
else
sum += isAbs ? Math.abs(arr[i]) : arr[i];
}
return sum;
},
_getMaxValueArray: function(array)
{
var max = 0;
for(var i = 0; i < array.length; i++)
{
for(var j = 0; j < array[i].length; j++)
{
if(i == 0 && j == 0)
max = array[i][j];
if(array[i][j] > max)
max = array[i][j];
}
}
return max;
},
_getMinValueArray: function(array)
{
var min = 0;
for(var i = 0; i < array.length; i++)
{
for(var j = 0; j < array[i].length; j++)
{
if(i == 0 && j == 0)
min = array[i][j];
if(array[i][j] < min)
min = array[i][j];
}
}
return min;
},
_findPrevValue: function(originalData, num, max) {
var summ = 0;
for (var i = 0; i <= max; i++) {
if (originalData[num][max] >= 0) {
if (originalData[num][i] >= 0)
summ += originalData[num][i];
}
else {
if (originalData[num][i] < 0)
summ += originalData[num][i];
}
}
return summ;
},
_round_val: function (num)
{
if(num.toString() && num.toString().indexOf('e+') == -1 && isNaN(parseFloat(num)))
return num;
var floatKoff = 100000000000;
if(num.toString() && num.toString().indexOf('e+') > -1)
{
var parseVal = num.toString().split("e+");
var roundVal = Math.round(parseFloat(parseVal[0])*floatKoff)/floatKoff;
var changeSymbol = roundVal.toString() + "e+" + parseVal[1];
num = parseFloat(changeSymbol);
}
num = Math.round(num*floatKoff)/floatKoff ;
return num;
},
_array_exp: function (arr)
{
var maxDig = 1000000000;
var minDig = 0.000000001;
var floatKoff = 100000000000;
if(typeof(arr) == 'number')
{
if(arr < 0)
maxDig = 100000000;
if(Math.abs(arr) > maxDig)
{
var tmp = Math.abs(arr);
var exp = 0;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
if(arr < 0)
tmp *= -1;
arr = tmp + "E+" + exp;
}
}
else
{
for (var i=0; i<arr.length; ++i) {
maxDig = 1000000000
if(arr[i] < 0)
maxDig = 100000000;
if(Math.abs(arr[i]) > maxDig)
{
var tmp = Math.abs(arr[i]);
var exp = 0;
while (tmp > 9) {
exp += 1;
tmp /= 10;
}
tmp = Math.round(tmp*floatKoff)/floatKoff
if(arr[i] < 0)
tmp *= -1;
arr[i] = tmp + "E+" + exp;
}
}
}
return arr;
},
_array_reverse: function (arr)
{
var newarr = [];
for (var i = arr.length - 1; i >= 0; i--) {
newarr.push(arr[i]);
}
return newarr;
},
_getFirstDegree: function(val)
{
var secPart = val.toString().split('.');
var numPow = 1,tempMax;
if(secPart[1] && secPart[1].toString().search('e+') != -1 && secPart[0] && secPart[0].toString().length == 1)
{
var expNum = secPart[1].toString().split('e+');
numPow = Math.pow(10, expNum[1]);
}
else if(0 != secPart[0])
numPow = Math.pow(10, secPart[0].toString().length - 1)
else if(0 == secPart[0])
{
var tempMax = val;
var num = -1;
while(0 == tempMax.toString().split('.')[0])
{
tempMax = val;
numPow = Math.pow(10, num);
tempMax = tempMax / numPow;
num--;
}
val = tempMax;
}
if(tempMax == undefined)
val = val / numPow;
return {val: val, numPow: numPow};
} }
} }
......
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