AddEdgeColorAttributesToDConnectorMotif ( ExcelTemplateGroupInfo oGroup, Boolean bEdgeColorColumnAutoFilled, AutoFillColorColumnResults oEdgeColorResults, ColorColumnAutoFillUserSettings oEdgeColorDetails, Dictionary <Int32, Object> oEdgeColorSourceDictionary, ReadWorkbookContext oReadWorkbookContext, CollapsedGroupAttributes oCollapsedGroupAttributes, Int32 iAnchorVertices ) { Debug.Assert(oGroup != null); Debug.Assert(oEdgeColorResults != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oCollapsedGroupAttributes != null); Debug.Assert(iAnchorVertices >= 0); // If the edge color column was autofilled, get the average color for // the edges incident to the D-connector motif's first anchor, then its // second anchor, and so on. Otherwise, don't do anything. if (!bEdgeColorColumnAutoFilled) { return; } for (Int32 iAnchorVertexIndex = 0; iAnchorVertexIndex < iAnchorVertices; iAnchorVertexIndex++) { Color oAverageColor; if (TableColumnMapper.TryMapAverageColor( GetRowIDsToAverageForEdges(oGroup, oCollapsedGroupAttributes, iAnchorVertexIndex), oEdgeColorSourceDictionary, oEdgeColorResults.SourceCalculationNumber1, oEdgeColorResults.SourceCalculationNumber2, oEdgeColorResults.DestinationColor1, oEdgeColorResults.DestinationColor2, oEdgeColorDetails.UseLogs, out oAverageColor) ) { oCollapsedGroupAttributes.Add( CollapsedGroupAttributeKeys.GetAnchorVertexEdgeColorKey( iAnchorVertexIndex), oReadWorkbookContext.ColorConverter2.GraphToWorkbook( oAverageColor) ); } } }
AddEdgeWidthAttributesToDConnectorMotif ( ExcelTemplateGroupInfo oGroup, Boolean bEdgeWidthColumnAutoFilled, AutoFillNumericRangeColumnResults oEdgeWidthResults, NumericRangeColumnAutoFillUserSettings oEdgeWidthDetails, Dictionary <Int32, Object> oEdgeWidthSourceDictionary, ReadWorkbookContext oReadWorkbookContext, CollapsedGroupAttributes oCollapsedGroupAttributes, Int32 iAnchorVertices ) { Debug.Assert(oGroup != null); Debug.Assert(oEdgeWidthResults != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oCollapsedGroupAttributes != null); Debug.Assert(iAnchorVertices >= 0); // If the edge width column was autofilled, get the average width for // the edges incident to the two-connector motif's first anchor, then // its second anchor. Otherwise, don't do anything. if (!bEdgeWidthColumnAutoFilled) { return; } for (Int32 iAnchorVertexIndex = 0; iAnchorVertexIndex < iAnchorVertices; iAnchorVertexIndex++) { Double dAverageEdgeWidth; if (TableColumnMapper.TryMapAverageNumber( GetRowIDsToAverageForEdges(oGroup, oCollapsedGroupAttributes, iAnchorVertexIndex), oEdgeWidthSourceDictionary, oEdgeWidthResults.SourceCalculationNumber1, oEdgeWidthResults.SourceCalculationNumber2, oEdgeWidthResults.DestinationNumber1, oEdgeWidthResults.DestinationNumber2, oEdgeWidthDetails.UseLogs, out dAverageEdgeWidth ) ) { oCollapsedGroupAttributes.Add( CollapsedGroupAttributeKeys.GetAnchorVertexEdgeWidthKey( iAnchorVertexIndex), dAverageEdgeWidth ); } } }
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]); }
GetRowIDsToAverageForEdges ( GroupInfo oGroup, CollapsedGroupAttributes oCollapsedGroupAttributes, Int32 iAnchorVertexIndex ) { Debug.Assert(oGroup != null); Debug.Assert(oCollapsedGroupAttributes != null); Debug.Assert(iAnchorVertexIndex >= 0); List <Int32> oRowIDsOfRowsToAverage = new List <Int32>(); String sAnchorVertexName; if (oCollapsedGroupAttributes.TryGetValue( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey( iAnchorVertexIndex), out sAnchorVertexName)) { // The group's vertices are the span vertices. Loop through them. foreach (IVertex oVertex in oGroup.Vertices) { // We need to find the edge that is incident to the specified // anchor vertex. foreach (IEdge oIncidentEdge in oVertex.IncidentEdges) { IVertex oAdjacentVertex = oIncidentEdge.GetAdjacentVertex(oVertex); if (oAdjacentVertex.Name == sAnchorVertexName) { // The row ID is stored in the edge's Tag, as long as // the edge row isn't hidden. if (oIncidentEdge.Tag is Int32) { oRowIDsOfRowsToAverage.Add( (Int32)oIncidentEdge.Tag); } break; } } } } return(oRowIDsOfRowsToAverage); }
AddVertexColorAttributeToMotif ( ExcelTemplateGroupInfo oGroup, String sType, Boolean bVertexColorColumnAutoFilled, AutoFillColorColumnResults oVertexColorResults, ColorColumnAutoFillUserSettings oVertexColorDetails, Dictionary <Int32, Object> oVertexColorSourceDictionary, ReadWorkbookContext oReadWorkbookContext, CollapsedGroupAttributes oCollapsedGroupAttributes ) { Debug.Assert(oGroup != null); Debug.Assert(!String.IsNullOrEmpty(sType)); Debug.Assert(oVertexColorResults != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oCollapsedGroupAttributes != null); Color oColor; // If the vertex color column was autofilled, get the average color // for the vertices in the motif. if ( !bVertexColorColumnAutoFilled || !TableColumnMapper.TryMapAverageColor( GetRowIDsToAverageForVertexColor(oGroup, oCollapsedGroupAttributes, sType), oVertexColorSourceDictionary, oVertexColorResults.SourceCalculationNumber1, oVertexColorResults.SourceCalculationNumber2, oVertexColorResults.DestinationColor1, oVertexColorResults.DestinationColor2, oVertexColorDetails.UseLogs, out oColor) ) { // Default to the color that was assigned to the group. oColor = oGroup.VertexColor; } oCollapsedGroupAttributes.Add( CollapsedGroupAttributeKeys.VertexColor, oReadWorkbookContext.ColorConverter2.GraphToWorkbook(oColor) ); }
GetRowIDsToAverageForVertexColor ( GroupInfo oGroup, CollapsedGroupAttributes oCollapsedGroupAttributes, String sType ) { Debug.Assert(oGroup != null); Debug.Assert(oCollapsedGroupAttributes != null); Debug.Assert(!String.IsNullOrEmpty(sType)); List <Int32> oRowIDsOfRowsToAverage = new List <Int32>(); IEnumerable <IVertex> oVerticesToAverage = null; switch (sType) { // Fan, Connector, and Clique fall through as each includes the proper vertices case CollapsedGroupAttributeValues.FanMotifType: case CollapsedGroupAttributeValues.DConnectorMotifType: case CollapsedGroupAttributeValues.CliqueMotifType: // All of the motif's vertices should be included. oVerticesToAverage = oGroup.Vertices; break; default: break; } if (oVerticesToAverage != null) { foreach (IVertex oVertex in oVerticesToAverage) { // The row ID is stored in the vertex's Tag, as long as the // vertex row isn't hidden. if (oVertex.Tag is Int32) { oRowIDsOfRowsToAverage.Add((Int32)oVertex.Tag); } } } return(oRowIDsOfRowsToAverage); }
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(); } }
SetUp() { m_oCollapsedGroupAttributes = new CollapsedGroupAttributes(); }