Commit fd4db83b authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

код для инициализации серий в chart вынесен в common

parserHelp перенесен в editorscommon.js.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@49429 954022d7-b5bf-4e40-9824-e11837661b57
parent 9c6399c6
......@@ -1320,12 +1320,69 @@ function Binary_ChartReader(stream, chart, chartAsGroup)
this.PostRead();
return res;
};
this.ParseFormula = function(formula)
{
var oRes = {bbox: null, sheet: null};
if (formula) {
var ref3D = parserHelp.is3DRef(formula, 0);
var sRef = null;
if (!ref3D[0])
sRef = formula;
else {
var resultRef = parserHelp.parse3DRef(formula);
if (null !== resultRef) {
oRes.sheet = resultRef.sheet;
sRef = resultRef.range;
}
}
if(null != sRef)
{
sRef = sRef.replace(/\$/g,"");
var parts = sRef.split(":");
if (2 == parts.length)
{
var first = new CellAddress(parts[0]);
var last = new CellAddress(parts[1]);
oRes.bbox = {r1: first.getRow0(), c1: first.getCol0(), r2: last.getRow0(), c2: last.getCol0()};
}
else
{
var cell = new CellAddress(sRef);
oRes.bbox = {r1: cell.getRow0(), c1: cell.getCol0(), r2: cell.getRow0(), c2: cell.getCol0()};
}
}
}
return oRes;
}
this.parseDataFormula = function(data, bbox)
{
if ( data && data.Formula ) {
var oParsed = this.ParseFormula(data.Formula);
if ( oParsed.bbox ) {
if(null == bbox)
bbox = oParsed.bbox;
else
{
if(oParsed.bbox.r1 < bbox.r1)
bbox.r1 = oParsed.bbox.r1;
if(oParsed.bbox.r2 > bbox.r2)
bbox.r2 = oParsed.bbox.r2;
if(oParsed.bbox.c1 < bbox.c1)
bbox.c1 = oParsed.bbox.c1;
if(oParsed.bbox.c2 > bbox.c2)
bbox.c2 = oParsed.bbox.c2;
}
}
}
return bbox;
}
this.PostRead = function()
{
if("" != this.chartType && null != this.chart.series && this.chart.series.length > 0)
var chart = this.chart;
if("" != this.chartType && null != chart.series && chart.series.length > 0)
{
//инициализируем interval в Woorksheet.init
this.chart.type = this.chartType;
chart.type = this.chartType;
for(var i in this.oLegendEntries)
{
var index = i - 0;
......@@ -1338,6 +1395,43 @@ function Binary_ChartReader(stream, chart, chartAsGroup)
}
}
}
if(chart.series.length > 0)
{
var oFirstSeria = chart.series[0];
var sheetName = "Sheet1";
if(null != oFirstSeria && null != oFirstSeria.Val && null != oFirstSeria.Val.Formula)
{
var oParsed = this.ParseFormula(oFirstSeria.Val.Formula);
if(null != oParsed.bbox)
{
var bbox = oParsed.bbox;
chart.range.rows = false;
chart.range.columns = false;
if ( bbox.c2 - bbox.c1 > bbox.r2 - bbox.r1 )
chart.range.rows = true;
else
chart.range.columns = true;
}
if(null != oParsed.sheet)
sheetName = oParsed.sheet;
}
// Общий диапазон
var bbox = null;
bbox = this.parseDataFormula(oFirstSeria.Val, bbox);
bbox = this.parseDataFormula(chart.series[chart.series.length - 1].Val, bbox);
bbox = this.parseDataFormula(oFirstSeria.TxCache, bbox);
bbox = this.parseDataFormula(oFirstSeria.xVal, bbox);
bbox = this.parseDataFormula(oFirstSeria.Cat, bbox);
var oCellStart = new CellAddress(bbox.r1, bbox.c1, 0);
var oCellEnd = new CellAddress(bbox.r2, bbox.c2, 0);
if(false == rx_test_ws_name.test(sheetName))
sheetName = "'" + sheetName + "'";
chart.range.interval = sheetName + "!" + oCellStart.getID() + ":" + oCellEnd.getID();
}
}
this.GraphicFrame = function(type, length)
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -5526,13 +5526,16 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadDrawing(t, l, oNewDrawing, oFlags);
});
if(false != oFlags.from && false != oFlags.to)
oNewDrawing.Type = ECellAnchorType.cellanchorTwoCell;
else if(false != oFlags.from && false != oFlags.ext)
oNewDrawing.Type = ECellAnchorType.cellanchorOneCell;
else if(false != oFlags.pos && false != oFlags.ext)
oNewDrawing.Type = ECellAnchorType.cellanchorAbsolute;
aDrawings.push(oNewDrawing);
if(null != oNewDrawing.graphicObject)
{
if(false != oFlags.from && false != oFlags.to)
oNewDrawing.Type = ECellAnchorType.cellanchorTwoCell;
else if(false != oFlags.from && false != oFlags.ext)
oNewDrawing.Type = ECellAnchorType.cellanchorOneCell;
else if(false != oFlags.pos && false != oFlags.ext)
oNewDrawing.Type = ECellAnchorType.cellanchorAbsolute;
aDrawings.push(oNewDrawing);
}
}
else
res = c_oSerConstants.ReadUnknown;
......@@ -5584,9 +5587,11 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
}
else if ( c_oSer_DrawingType.GraphicFrame == type )
{
oDrawing.graphicObject = new CChartAsGroup();
var oBinary_ChartReader = new Binary_ChartReader(this.stream, oDrawing.graphicObject.chart, oDrawing.graphicObject);
var oNewGraphicObject = new CChartAsGroup();
var oBinary_ChartReader = new Binary_ChartReader(this.stream, oNewGraphicObject.chart, oNewGraphicObject);
res = oBinary_ChartReader.Read(length);
if(null != oNewGraphicObject.chart.range.interval)
oDrawing.graphicObject = oNewGraphicObject;
}
else if ( c_oSer_DrawingType.pptxDrawing == type )
{
......
......@@ -2318,122 +2318,22 @@ Woorksheet.prototype.initPostOpen = function(){
if(null != this.Drawings)
{
var oThis = this;
var fParseRef = function(sRef)
{
var result = null;
var oRefParsed = parserHelp.parse3DRef(sRef);
if (null !== oRefParsed) {
// Получаем sheet по имени
ws = oThis.workbook.getWorksheetByName (oRefParsed.sheet);
if (ws)
{
var range = ws.getRange2(oRefParsed.range);
if (null !== range)
{
var oBBox = range.getBBox0();
result = {sheet: ws, range: new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), bbox: oBBox};
}
}
}
return result;
}
var fAddBounds = function(oBounds, oNewBounds ,chart)
{
if(null == oBounds)
{
/*chart.range.rows = false;
chart.range.columns = false;
if(oNewBounds.bbox.c2 - oNewBounds.bbox.c1 > oNewBounds.bbox.r2 - oNewBounds.bbox.r1)
chart.range.rows = true;
else
chart.range.columns = true;*/
oBounds = oNewBounds.range;
}
else
oBounds = oBounds.union(oNewBounds.range);
return oBounds;
}
for(var i = this.Drawings.length - 1; i >= 0; --i)
{
var obj = this.Drawings[i];
if(obj.graphicObject && obj.graphicObject.chart)
{
var chart = obj.graphicObject.chart;
//анализируем series
var oBounds = null;
var ws = null;
for(var j = 0; j < chart.series.length; ++j)
{
var seria = chart.series[j];
if(0 == j && null != seria && null != seria.TxCache && null != seria.TxCache.Formula)
{
var sRef = seria.TxCache.Formula.replace(/\$/g,"");
var oNewBounds = fParseRef(sRef);
if(null != oNewBounds)
{
if(null == oBounds)
ws = oNewBounds.sheet;
oBounds = fAddBounds(oBounds, oNewBounds, chart);
}
}
if(0 == j && null != seria && null != seria.xVal && null != seria.xVal.Formula)
{
var sRef = seria.xVal.Formula.replace(/\$/g,"");
var oNewBounds = fParseRef(sRef);
if(null != oNewBounds)
{
if(null == oBounds)
ws = oNewBounds.sheet;
oBounds = fAddBounds(oBounds, oNewBounds, chart);
}
}
if(0 == j && null != seria && null != seria.Cat && null != seria.Cat.Formula)
{
var sRef = seria.Cat.Formula.replace(/\$/g,"");
var oNewBounds = fParseRef(sRef);
if(null != oNewBounds)
{
if(null == oBounds)
ws = oNewBounds.sheet;
oBounds = fAddBounds(oBounds, oNewBounds, chart);
}
}
if(null != seria && null != seria.Val && null != seria.Val.Formula)
{
var sRef = seria.Val.Formula.replace(/\$/g,"");
var oNewBounds = fParseRef(sRef);
if(null != oNewBounds)
{
if(null == oBounds)
ws = oNewBounds.sheet;
oBounds = fAddBounds(oBounds, oNewBounds, chart);
}
}
}
if (null != oBounds)
if(chart.range.interval)
{
chart.range.intervalObject = ws.getRange(new CellAddress(oBounds.r1, oBounds.c1, 0), new CellAddress(oBounds.r2, oBounds.c2, 0));
if(null != chart.range.intervalObject)
chart.range.interval = chart.range.intervalObject.getName();
if ( chart.series.length && chart.series[0].Val.Formula ) // Rows/Columns по диапазону первой серии
{
chart.range.rows = false;
chart.range.columns = false;
var sRef = chart.series[0].Val.Formula.replace(/\$/g, "");
var bounds = fParseRef(sRef);
if ( null != bounds )
{
if (bounds.bbox.c2 - bounds.bbox.c1 > bounds.bbox.r2 - bounds.bbox.r1)
chart.range.rows = true;
else
chart.range.columns = true;
}
var oRefParsed = parserHelp.parse3DRef(chart.range.interval);
if (null !== oRefParsed) {
// Получаем sheet по имени
var ws = oThis.workbook.getWorksheetByName (oRefParsed.sheet);
if (ws)
chart.range.intervalObject = ws.getRange2(oRefParsed.range);
}
}
else
this.Drawings.splice(i, 1);
}
}
}
......
......@@ -23,6 +23,7 @@
<script src="../Common/docscoapicommon.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Underscore/underscore-min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/XRegExp/xregexp-all.js"></script>
<script type="text/javascript" src="../Common/docscoapi.js"></script>
<script type="text/javascript" src="../Common/wordcopypaste.js"></script>
<script type="text/javascript" src="../Common/editorscommon.js"></script>
......
......@@ -87,6 +87,7 @@
<script type="text/javascript" src="../../../3rdparty/jquery/mousewheel/jquery.mousewheel.js"></script>
<script type="text/javascript" src="../../../3rdparty/jquery/jscrollpane/jquery.jscrollpane.js"></script>
<script type="text/javascript" src="../../../3rdparty/sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../../../3rdparty/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../3rdparty/underscore/underscore-min.js"></script>
<!-- Application -->
......
......@@ -3129,7 +3129,7 @@ function BinaryFileReader(doc, openParams)
if(e.message == g_sErrorCharCountMessage)
return false;
else
throw "open error";
throw e;
}
return true;
};
......@@ -5657,29 +5657,6 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, bAllow
res = c_oSerConstants.ReadUnknown;
return res;
};
this.ParseFormula = function(formula)
{
var bbox = null;
//todo надо бы подключить parserHelp.parse3DRef. сейчас здесь упрошенный парсер.
var index = formula.indexOf("!");
if(-1 != index)
formula = formula.substring(index + 1);
formula = formula.replace(/\$/g,"");
var parts = formula.split(":");
if (2 == parts.length)
{
var first = new CellAddress(parts[0]);
var last = new CellAddress(parts[1]);
bbox = {r1: first.getRow0(), c1: first.getCol0(), r2: last.getRow0(), c2: last.getCol0()};
}
else
{
var cell = new CellAddress(formula);
if ( cell )
bbox = {r1: cell.getRow0(), c1: cell.getCol0(), r2: cell.getRow0(), c2: cell.getCol0()};
}
return bbox;
}
this.ReadPptxDrawing = function(type, length, oParaDrawing, oChartObject)
{
var res = c_oSerConstants.ReadOk;
......@@ -5703,89 +5680,8 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, bAllow
var chart = oParaDrawing.GraphicObj.chart;
var oBinary_ChartReader = new Binary_ChartReader(this.stream, chart, oParaDrawing.GraphicObj);
oBinary_ChartReader.ReadExternal(length);
if(chart.series.length > 0)
{
var oFirstSeria = chart.series[0];
if(null != oFirstSeria && null != oFirstSeria.Val && null != oFirstSeria.Val.Formula)
{
var bbox = this.ParseFormula(oFirstSeria.Val.Formula);
if(null != bbox)
{
chart.range.rows = false;
chart.range.columns = false;
if ( bbox.c2 - bbox.c1 > bbox.r2 - bbox.r1 )
chart.range.rows = true;
else
chart.range.columns = true;
}
}
// Общий диапазон
var _this = this;
var colArray = [], rowArray = [];
var seriesCount = chart.series.length;
function parseDataFormula(data, bMinimum) {
if ( data && data.Formula ) {
var range = _this.ParseFormula(data.Formula);
if ( range ) {
if ( bMinimum ) {
colArray.push(range.c1);
rowArray.push(range.r1);
}
else {
colArray.push(range.c2);
rowArray.push(range.r2);
}
}
}
}
parseDataFormula(chart.series[0].Val, true);
parseDataFormula(chart.series[seriesCount - 1].Val, false);
parseDataFormula(chart.series[0].TxCache, true);
parseDataFormula(chart.series[0].xVal, true);
parseDataFormula(chart.series[0].Cat, true);
var c1 = Math.min.apply(null, colArray);
var r1 = Math.min.apply(null, rowArray);
var c2 = Math.max.apply(null, colArray);
var r2 = Math.max.apply(null, rowArray);
var oCellStart = new CellAddress(r1, c1, 0);
var oCellEnd = new CellAddress(r2, c2, 0);
var sheetName = "Sheet1";
if ( oFirstSeria.Val.Formula ) {
var index = oFirstSeria.Val.Formula.indexOf("!");
if ( -1 != index )
sheetName = oFirstSeria.Val.Formula.substring(0, index);
}
chart.range.interval = sheetName + "!" + oCellStart.getID() + ":" + oCellEnd.getID();
}
oChartObject.chart = chart;
/*
var nRowCount = 0;
var nColCount = 0;
if ( chart.range.rows ) {
nRowCount = chart.series.length;
nColCount = chart.series[0].Val.NumCache.length;
}
else {
nRowCount = chart.series[0].Val.NumCache.length;
nColCount = chart.series.length;
}
if(0 != nRowCount && 0 != nColCount)
{
var oCellAddress = new CellAddress(nRowCount, nColCount);
chart.range.interval = "Sheet1!A1:" + oCellAddress.getID();
if(null != chart.range.interval)
oChartObject.chart = chart;
}*/
}
else if( c_oSerImageType2.AllowOverlap === type )
var AllowOverlap = this.stream.GetBool();
......
......@@ -16,6 +16,7 @@
<script type="text/javascript" src="../Common/spellCheckLanguagesAll.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Underscore/underscore-min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/XRegExp/xregexp-all.js"></script>
<script type="text/javascript" src="../Common/docscoapi.js"></script>
<script type="text/javascript" src="../Common/spellcheckapisettings.js"></script>
<script type="text/javascript" src="../Common/spellcheckapi.js"></script>
......
......@@ -26,6 +26,7 @@
<script type="text/javascript" src="../Common/spellCheckLanguagesAll.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Underscore/underscore-min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/XRegExp/xregexp-all.js"></script>
<script type="text/javascript" src="../Common/docscoapi.js"></script>
<script type="text/javascript" src="../Common/spellcheckapisettings.js"></script>
<script type="text/javascript" src="../Common/spellcheckapi.js"></script>
......
......@@ -87,6 +87,7 @@
<script type="text/javascript" src="../../../3rdparty/jquery/mousewheel/jquery.mousewheel.js"></script>
<script type="text/javascript" src="../../../3rdparty/jquery/jscrollpane/jquery.jscrollpane.js"></script>
<script type="text/javascript" src="../../../3rdparty/sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../../../3rdparty/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../3rdparty/underscore/underscore-min.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/editorscommon.js"></script>
......
......@@ -55,6 +55,7 @@
<script type="text/javascript" src="../../../3rdparty/touch/sencha-touch-debug.js"></script>
<script type="text/javascript" src="../../../3rdparty/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../../3rdparty/sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../../../3rdparty/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../3rdparty/underscore/underscore-min.js"></script>
<script type="text/javascript" src="../../../3rdparty/megapixel/src/megapix-image.js"></script>
......
......@@ -13,6 +13,7 @@
<script type="text/javascript" src="../../OfficeWeb/Common/spellCheckLanguagesAll.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/3rdparty/Underscore/underscore-min.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/3rdparty/Sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/3rdparty/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/docscoapi.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/spellcheckapisettings.js"></script>
<script type="text/javascript" src="../../OfficeWeb/Common/spellcheckapi.js"></script>
......
......@@ -26,6 +26,7 @@
<script type="text/javascript" src="../Common/spellCheckLanguagesAll.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Underscore/underscore-min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/Sockjs/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="../Common/3rdparty/XRegExp/xregexp-all.js"></script>
<script type="text/javascript" src="../Common/docscoapi.js"></script>
<script type="text/javascript" src="../Common/spellcheckapisettings.js"></script>
<script type="text/javascript" src="../Common/spellcheckapi.js"></script>
......
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