Aspose.Diagram Shape 覆蓋問題


#1

您好,
我在建立一堆的 Shape 後,有設定 AutoFitPageToDrawingContent = true; ,但輸出的 Shape 間會有覆蓋的狀況,請問還需要調整什麼嗎?
感謝您!

// Use saving options
DiagramSaveOptions options = new DiagramSaveOptions(SaveFileFormat.VSDX);
// Set Auto fit page property
options.AutoFitPageToDrawingContent = true;

// Save Visio diagram
diagram.Save(dataDir + "AutoFitShapesInVisio_out.vsdx", options);

因為我們想產生組織圖,所以有相關的範例可以參考嗎? 謝謝您。


#2

@rainmaker_ho

感谢您与我们联系。

您可以通过访问以下链接找到有关在API文档中使用形状的信息:

Working with Shapes

如果您的问题仍然存在,请与我们分享完整的代码段以及生成的VISIO图表。我们将在我们的环境中测试场景并相应地解决它。


#3

您好,
測試程式如下,

public class OrgInfo
{
	public string OrgName { get; set; }

	public long OrgPartyID { get; set; }

	public long? ParentOrgPartyID { get; set; }
}

static void Main(string[] args)
{
	var outputFilder = Path.Combine(Environment.CurrentDirectory, "outputvsdx");
	var orgDiagramList = new List<OrgInfo>();
	orgDiagramList.Add(new OrgInfo() { OrgName = "GSS", OrgPartyID = 1, ParentOrgPartyID = null });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD1", OrgPartyID = 2, ParentOrgPartyID = 1 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD2", OrgPartyID = 3, ParentOrgPartyID = 1 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD1-1", OrgPartyID = 4, ParentOrgPartyID = 2 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD1-2", OrgPartyID = 5, ParentOrgPartyID = 2 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD1-3", OrgPartyID = 6, ParentOrgPartyID = 2 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD1-4", OrgPartyID = 7, ParentOrgPartyID = 2 });
	orgDiagramList.Add(new OrgInfo() { OrgName = "HRSPD2-1", OrgPartyID = 8, ParentOrgPartyID = 3 });

	Diagram diagram = new Diagram();

	Page page = diagram.Pages[0];
	page.Name = "組織圖";
	// initialize auto space options
	AutoSpaceOptions atopt = new AutoSpaceOptions();
	// set horizontal and vertical distances
	atopt.DistanceInHorizontal = 2;
	atopt.DistanceInVertical = 2;
	// set auto space 
	page.AutoSpaceShapes(page.Shapes, atopt);
	// Page orientation
	page.PageSheet.PrintProps.PrintPageOrientation.Value = PrintPageOrientationValue.Landscape;
	string connectorMaster = "Dynamic connector";
	string rectangle = "Rectangle";

	int pageNumber = 0;
	var tempFile = Path.Combine(Environment.CurrentDirectory, "outputvsdx", "BasicShapes.vss");

	var m1 = diagram.AddMaster(tempFile, rectangle);
	var m2 = diagram.AddMaster(tempFile, connectorMaster);

	// 產生所有單位圖形
	orgDiagramList.ForEach((item) =>
	{
		Shape orgRectangle = new Shape();
		long shapeID = diagram.AddShape(orgRectangle, rectangle, pageNumber);
		Shape shape = page.Shapes.GetShape(shapeID);
		shape.Text.Value.Add(new Txt(item.OrgName));
		shape.Data1 = JsonConvert.SerializeObject(item);
	});

	var shapeCollection = diagram.Pages[pageNumber].Shapes;

	// 產生連結線圖形,進行階層連結
	foreach (var item in orgDiagramList)
	{
		var linkList = orgDiagramList.Where(m => m.ParentOrgPartyID == item.OrgPartyID);
		var from = GetShapeByOrgInfoData(shapeCollection, item);
		foreach (var link in linkList)
		{
			Shape connector = new Shape();
			long connectorID = diagram.AddShape(connector, connectorMaster, pageNumber);
			var to = GetShapeByOrgInfoData(shapeCollection, link);
			page.ConnectShapesViaConnector(from.ID, ConnectionPointPlace.Bottom, to.ID, ConnectionPointPlace.Top, connectorID);
		}
	}

	LayoutOptions flowChartOptions = new LayoutOptions();
	flowChartOptions.LayoutStyle = LayoutStyle.FlowChart;
	flowChartOptions.SpaceShapes = 1f;
	flowChartOptions.EnlargePage = true;
	flowChartOptions.Direction = LayoutDirection.TopToBottom;
	diagram.Layout(flowChartOptions);
	var format = SaveFileFormat.VDX;
	DiagramSaveOptions options = new DiagramSaveOptions(format);
	options.AutoFitPageToDrawingContent = true;
	
	diagram.Refresh();
	diagram.Save("ogfile.vdx", options);
}

產生的圖會有線跟圖折到的狀況,麻煩您了,謝謝。


#4

@rainmaker_ho

感谢您分享代码段。

我们尝试在我们的环境中执行您的代码段,但我们发现了一些问题。代码中有一些未定义的方法,例如GetShapeByOrgInfoData(),Txt()。请与我们分享这些方法的定义,以便我们可以在我们的环境中测试场景并相应地解决它。


#5

您好,
請參考,

public static Shape GetShapeByOrgInfoData(ShapeCollection shapeCollection, OrgInfo orgInfoData)
{
	var targetStringify = JsonConvert.SerializeObject(orgInfoData);
	foreach (Shape shape in shapeCollection)
	{
		if (shape.Data1 == targetStringify)
		{
			return shape;
		}
	}
	return null;
}

感謝您。


#6

@rainmaker_ho

感谢您分享代码段。

我们正在调查这个场景。与此同时,请您分享您所拥有的样本模板(.vss)和生成的输出(.vsdx)文件。


#7

您好,
vss及VDX如附件,
example.zip (60.6 KB)
謝謝您。


#8

@rainmaker_ho

感謝您分享所需的信息和詳細信息。

我們在我們的環境中測試了場景,並觀察到一些形狀越過頁面邊界。請查看附帶的截圖。為了糾正起見,我們在問題跟踪系統中記錄了DIAGRAMNET-51583問題。我們將查看問題的詳細信息,並讓您發布其解決方案狀態。請多花點時間。

我們對造成的不便很抱歉。