PoshCode Logo PowerShell Code Repository

Show-NodeXLMap (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/733"></script>download | new post

Update version of Doug Finke’s Show-NetMap script (http://www.dougfinke.com/blog/?p=465). The NetMap research project has been renamed to NodeXL and is available on Codeplex (http://www.codeplex.com/nodexl). This script is updated to use the new code and adds support for adding color to the map points.

  1. # Author: Doug Finke http://www.dougfinke.com/blog/
  2. # Originally Posted: 08/13/08 (Microsoft Research .NetMap and PowerShell)
  3. # http://www.dougfinke.com/blog/?p=465
  4. # Modified by Steven Murawski http://www.mindofroot.com
  5. # Updated to use the new project name "NodeXL"
  6. # Added support for coloring the labels
  7. # By adding a color property to the input objects, the source and target vertices
  8. # will show with that color.  If the source vertex already exists, its color will
  9. # not be changed.
  10. # Date:  12/15/2008
  11.  
  12. [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")   | Out-Null
  13. [Reflection.Assembly]::LoadWithPartialName("System.Drawing")   | Out-Null
  14. [Reflection.Assembly]::Loadfrom("$pwd\Microsoft.NodeXL.Control.dll") | Out-Null
  15.  
  16. function Add-Edge($source, $target, $color)
  17. {
  18.     [Microsoft.NodeXL.Core.IVertex]$sourceVertex=$null
  19.     $res=$netMapControl.Graph.Vertices.Find($source, [ref] $sourceVertex)
  20.     if ($sourceVertex -eq $null)
  21.     {
  22.                 $sourceVertex = $netMapControl.Graph.Vertices.Add()
  23.                 $sourceVertex.Name = $source
  24.                 $sourceVertex.SetValue("~PVLDPrimaryLabel", $source)
  25.                 if ($color -ne $null)
  26.                 {
  27.                         $sourceVertex.SetValue("~PVLDPrimaryLabelFillColor", [System.Drawing.Color]::$color )
  28.                 }
  29.         }
  30.  
  31.     [Microsoft.NodeXL.Core.IVertex]$targetVertex=$null
  32.     $res=$netMapControl.Graph.Vertices.Find($target, [ref] $targetVertex)
  33.     if ($targetVertex -eq $null)
  34.     {
  35.                 $targetVertex = $netMapControl.Graph.Vertices.Add()
  36.                 $targetVertex.Name = $target
  37.                 $targetVertex.SetValue("~PVLDPrimaryLabel", $target)
  38.                 if ($color -ne $null)
  39.                 {
  40.                         $targetVertex.SetValue("~PVLDPrimaryLabelFillColor", [System.Drawing.Color]::$color )
  41.                 }
  42.     }
  43.  
  44.     $edge=$netMapControl.Graph.Edges.Add($sourceVertex, $targetVertex, $true)
  45. }
  46.  
  47. function Show-NodeXLMap($layoutType="circular") {
  48.   Begin {
  49.     $form = New-Object Windows.Forms.Form
  50.     $netMapControl = New-Object Microsoft.NodeXL.Visualization.NodeXLControl
  51.     $netMapControl.Dock = "Fill"
  52.         $netMapControl.VertexDrawer = new-object Microsoft.NodeXL.Visualization.PerVertexWithLabelDrawer
  53.     $netMapControl.EdgeDrawer   = new-object Microsoft.NodeXL.Visualization.PerEdgeWithLabelDrawer
  54.     $netMapControl.BeginUpdate()
  55.   }
  56.  
  57.   Process {
  58.     if($_) {
  59.       Add-Edge $_.Source $_.Target $_.Color
  60.     }
  61.   }
  62.  
  63.   End {
  64.     switch -regex ($layoutType) {
  65.        "C" { $Layout = New-Object Microsoft.NodeXL.Visualization.CircleLayout }
  66.        "S" { $Layout = New-Object Microsoft.NodeXL.Visualization.SpiralLayout }
  67.        "H" { $Layout = New-Object Microsoft.NodeXL.Visualization.SinusoidHorizontalLayout }
  68.        "V" { $Layout = New-Object Microsoft.NodeXL.Visualization.SinusoidVerticalLayout }
  69.        "G" { $Layout = New-Object Microsoft.NodeXL.Visualization.GridLayout }
  70.        "F" { $Layout = New-Object Microsoft.NodeXL.Visualization.FruchtermanReingoldLayout }
  71.        "R" { $Layout = New-Object Microsoft.NodeXL.Visualization.RandomLayout }
  72.        "Y" { $Layout = New-Object Microsoft.NodeXL.Visualization.SugiyamaLayout }
  73.     }
  74.  
  75.     $netMapControl.Layout=$layout
  76.     $netMapControl.EndUpdate()
  77.     $form.Controls.Add($NetMapControl)
  78.     $form.WindowState="Maximized"
  79.     #$form.Size = New-Object Drawing.Size @(1000, 600)
  80.     $form.ShowDialog() | out-null
  81.        
  82.   }
  83. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me