TestFromString() { // Empty string, which is allowed. CollapsedGroupAttributes oCollapsedGroupAttributes2 = CollapsedGroupAttributes.FromString(String.Empty); Assert.AreEqual(0, oCollapsedGroupAttributes2.Count); }
TestCollapsedAttributes() { // With vertex names. IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); oAnchorVertex1.Name = "Name1"; oAnchorVertex2.Name = "Name2"; DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List <IVertex>() { oAnchorVertex1, oAnchorVertex2 }); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); String sCollapsedAttributes = oDConnectorMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual(CollapsedGroupAttributeValues.DConnectorMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type]); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.AnchorVertices]); Assert.IsTrue(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0))); Assert.IsTrue(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1))); Assert.AreEqual("Name1", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0)]); Assert.AreEqual("Name2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1)]); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.SpanVertices]); Assert.IsTrue(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.SpanScale)); Assert.AreEqual("1", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.SpanScale]); }
TestCollapsedAttributes2() { // Without vertex names and with SpanScale set to a non-default value. IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List <IVertex>() { oAnchorVertex1, oAnchorVertex2 }); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); oDConnectorMotif.SpanScale = 0.5; String sCollapsedAttributes = oDConnectorMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual(CollapsedGroupAttributeValues.DConnectorMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type]); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.AnchorVertices]); Assert.IsFalse(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0))); Assert.IsFalse(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1))); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.SpanVertices]); Assert.IsTrue(oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.SpanScale)); Assert.AreEqual("0.5", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.SpanScale]); }
TestToAndFromString() { // Typical case. m_oCollapsedGroupAttributes.Add("Key1", "Value1"); m_oCollapsedGroupAttributes.Add("Key2", "Value2"); m_oCollapsedGroupAttributes.Add("Key3", "Value3"); String sSavedString = m_oCollapsedGroupAttributes.ToString(); CollapsedGroupAttributes oCollapsedGroupAttributes2 = CollapsedGroupAttributes.FromString(sSavedString); Assert.AreEqual("Value1", oCollapsedGroupAttributes2["Key1"]); Assert.AreEqual("Value2", oCollapsedGroupAttributes2["Key2"]); Assert.AreEqual("Value3", oCollapsedGroupAttributes2["Key3"]); }
GetReadColorAndShapeFlags ( IVertex oVertex, GroupInfo oGroup, ReadWorkbookContext oReadWorkbookContext, out Boolean bReadColorFromGroup, out Boolean bReadShapeFromGroup ) { Debug.Assert(oVertex != null); Debug.Assert(oReadWorkbookContext != null); AssertValid(); // Assume that the settings specified in the context object will be // used. bReadColorFromGroup = oReadWorkbookContext.ReadVertexColorFromGroups; bReadShapeFromGroup = oReadWorkbookContext.ReadVertexShapeFromGroups; if (oGroup.CollapsedAttributes != null) { CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString( oGroup.CollapsedAttributes); String sHeadVertexName; if ( oCollapsedGroupAttributes.GetGroupType() == CollapsedGroupAttributeValues.FanMotifType && oCollapsedGroupAttributes.TryGetValue( CollapsedGroupAttributeKeys.HeadVertexName, out sHeadVertexName) && oVertex.Name == sHeadVertexName ) { // The shape of a fan motif's head vertex should never be // changed. Do not get it from the group. bReadShapeFromGroup = false; } } }
TestCollapsedAttributes() { // With head vertex name. IVertex oHeadVertex = new Vertex(); oHeadVertex.Name = "Head"; IVertex oLeafVertex1 = new Vertex(); IVertex oLeafVertex2 = new Vertex(); FanMotif oFanMotif = new FanMotif(oHeadVertex, new IVertex[] { oLeafVertex1, oLeafVertex2 }); String sCollapsedAttributes = oFanMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual(CollapsedGroupAttributeValues.FanMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type]); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.HeadVertexName)); Assert.AreEqual("Head", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.HeadVertexName]); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.LeafVertices]); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.ArcScale)); Assert.AreEqual("1", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.ArcScale]); }
TestToAndFromString2() { // Empty and null keys, which aren't persisted. m_oCollapsedGroupAttributes.Add("Key1", "Value1"); m_oCollapsedGroupAttributes.Add("KeyX", ""); m_oCollapsedGroupAttributes.Add("Key2", "Value2"); m_oCollapsedGroupAttributes.Add("Key3", "Value3"); m_oCollapsedGroupAttributes.Add("KeyY", null); String sSavedString = m_oCollapsedGroupAttributes.ToString(); CollapsedGroupAttributes oCollapsedGroupAttributes2 = CollapsedGroupAttributes.FromString(sSavedString); Assert.AreEqual("Value1", oCollapsedGroupAttributes2["Key1"]); Assert.AreEqual("Value2", oCollapsedGroupAttributes2["Key2"]); Assert.AreEqual("Value3", oCollapsedGroupAttributes2["Key3"]); Assert.IsFalse(oCollapsedGroupAttributes2.ContainsKey("KeyX")); Assert.IsFalse(oCollapsedGroupAttributes2.ContainsKey("KeyY")); }
TestCollapsedAttributes2() { // Without head vertex name, and with ArcScale set to a non-default // value. IVertex oHeadVertex = new Vertex(); IVertex oLeafVertex1 = new Vertex(); IVertex oLeafVertex2 = new Vertex(); FanMotif oFanMotif = new FanMotif(oHeadVertex, new IVertex[] { oLeafVertex1, oLeafVertex2 }); oFanMotif.ArcScale = 0.5; String sCollapsedAttributes = oFanMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual(CollapsedGroupAttributeValues.FanMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type]); Assert.IsFalse( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.HeadVertexName)); Assert.AreEqual("2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.LeafVertices]); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.ArcScale)); Assert.AreEqual("0.5", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.ArcScale]); }
AddCollapsedGroupAttributesInternal ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, ReadWorkbookContext oReadWorkbookContext, ListObject oEdgeTable, ListObject oVertexTable, GroupInfo[] aoGroups ) { Debug.Assert(oWorkbook != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oEdgeTable != null); Debug.Assert(oVertexTable != null); Debug.Assert(aoGroups != null); Debug.Assert(aoGroups.Length > 0); // Check whether relevant columns have been autofilled using numerical // source columns. PerWorkbookSettings oPerWorkbookSettings = new PerWorkbookSettings(oWorkbook); AutoFillColorColumnResults oVertexColorResults = oPerWorkbookSettings.AutoFillWorkbookResults.VertexColorResults; Boolean bVertexColorColumnAutoFilled = oVertexColorResults.ColumnAutoFilled && !oVertexColorResults.ColumnAutoFilledWithCategories; AutoFillColorColumnResults oEdgeColorResults = oPerWorkbookSettings.AutoFillWorkbookResults.EdgeColorResults; Boolean bEdgeColorColumnAutoFilled = oEdgeColorResults.ColumnAutoFilled && !oEdgeColorResults.ColumnAutoFilledWithCategories; AutoFillNumericRangeColumnResults oEdgeWidthResults = oPerWorkbookSettings.AutoFillWorkbookResults.EdgeWidthResults; Boolean bEdgeWidthColumnAutoFilled = oEdgeWidthResults.ColumnAutoFilled; // Some user settings for autofill may be needed. // // Note: This is a design bug. The user's current settings should not // be required; everything needed here should come from the autofill // results. The long-term fix is to add a UseLogs property to the // AutoFillColorColumnResults class. AutoFillUserSettings oAutoFillUserSettings = new AutoFillUserSettings(); ColorColumnAutoFillUserSettings oVertexColorDetails = oAutoFillUserSettings.VertexColorDetails; ColorColumnAutoFillUserSettings oEdgeColorDetails = oAutoFillUserSettings.EdgeColorDetails; NumericRangeColumnAutoFillUserSettings oEdgeWidthDetails = oAutoFillUserSettings.EdgeWidthDetails; // The key is the row ID for each visible row in the vertex table and // the value is value of the source column cell in that row that was // used to autofill the vertex color column, if it was autofilled. Dictionary <Int32, Object> oVertexColorSourceDictionary = bVertexColorColumnAutoFilled ? GetRowIDDictionary(oVertexTable, oVertexColorResults.SourceColumnName) : null; // Ditto for edge colors and edge widths. Dictionary <Int32, Object> oEdgeColorSourceDictionary = bEdgeColorColumnAutoFilled ? GetRowIDDictionary(oEdgeTable, oEdgeColorResults.SourceColumnName) : null; Dictionary <Int32, Object> oEdgeWidthSourceDictionary = bEdgeWidthColumnAutoFilled ? GetRowIDDictionary(oEdgeTable, oEdgeWidthResults.SourceColumnName) : null; // Only motifs need to have attributes added to them. foreach (ExcelTemplateGroupInfo oGroup in aoGroups.Where( oGroup => oGroup.CollapsedAttributes != null)) { CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString( oGroup.CollapsedAttributes); String sType = oCollapsedGroupAttributes.GetGroupType(); if ( sType == CollapsedGroupAttributeValues.FanMotifType || sType == CollapsedGroupAttributeValues.DConnectorMotifType || sType == CollapsedGroupAttributeValues.CliqueMotifType ) { AddVertexColorAttributeToMotif(oGroup, sType, bVertexColorColumnAutoFilled, oVertexColorResults, oVertexColorDetails, oVertexColorSourceDictionary, oReadWorkbookContext, oCollapsedGroupAttributes); } if (sType == CollapsedGroupAttributeValues.DConnectorMotifType) { Int32 iAnchorVertices; if (oCollapsedGroupAttributes.TryGetValue( CollapsedGroupAttributeKeys.AnchorVertices, out iAnchorVertices)) { AddEdgeColorAttributesToDConnectorMotif(oGroup, bEdgeColorColumnAutoFilled, oEdgeColorResults, oEdgeColorDetails, oEdgeColorSourceDictionary, oReadWorkbookContext, oCollapsedGroupAttributes, iAnchorVertices); AddEdgeWidthAttributesToDConnectorMotif(oGroup, bEdgeWidthColumnAutoFilled, oEdgeWidthResults, oEdgeWidthDetails, oEdgeWidthSourceDictionary, oReadWorkbookContext, oCollapsedGroupAttributes, iAnchorVertices); } } oGroup.CollapsedAttributes = oCollapsedGroupAttributes.ToString(); } }