Skip to content

Commit

Permalink
Merge pull request #60 from KevinMarquette/feature/record !deploy
Browse files Browse the repository at this point in the history
Feature/record
  • Loading branch information
KevinMarquette committed Feb 17, 2018
2 parents b2ed12b + 1793725 commit 37ee908
Show file tree
Hide file tree
Showing 14 changed files with 912 additions and 165 deletions.
15 changes: 12 additions & 3 deletions PSGraph/PSGraph.psd1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# Module manifest for module 'PSGraphViz'
#
# Generated by: Kevin Marquette
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSGraph.psm1'

# Version number of this module.
ModuleVersion = '1.2.6'
ModuleVersion = '2.1.16'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -69,7 +69,7 @@
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @('Edge', 'Export-PSGraph', 'Graph', 'Inline', 'Install-GraphViz', 'Node', 'Rank', 'Set-NodeFormatScript', 'SubGraph')
FunctionsToExport = @('Edge', 'Entity', 'Export-PSGraph', 'Graph', 'Inline', 'Install-GraphViz', 'Node', 'Rank', 'Record', 'Row', 'Set-NodeFormatScript', 'Show-PSGraph', 'SubGraph')

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand Down Expand Up @@ -108,10 +108,19 @@

# ReleaseNotes of this module
ReleaseNotes = @'
2.1.16 20180217
* add Record command
* add Row command
* add Entity command
* add Show-PSGraph command
* add key name case correction
* throws error when there are graphviz parse errors
1.2.0 20171022
* #53 add support for edges to and from a subgraph
* #55 subgraph name is now optional
* 56 remove extra blank lines in graph output
1.1.4 20171021
* #51 Updated build script
Expand Down
2 changes: 1 addition & 1 deletion PSGraph/Private/ConvertTo-GraphVizAttribute.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function ConvertTo-GraphVizAttribute
{
$value = $key.value
}
'{0}={1};' -f $key.name, ( Format-Value $value )
'{0}={1};' -f ( Format-KeyName $key.name ), ( Format-Value $value )
}

if ( $UseGraphStyle )
Expand Down
27 changes: 27 additions & 0 deletions PSGraph/Private/Format-KeyName.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Format-KeyName
{
[OutputType('System.String')]
[cmdletbinding()]
param(
[Parameter(Position = 0)]
[string]
$InputObject
)
begin
{
$translate = @{
Damping = 'Damping'
K = 'K'
URL = 'URL'
}
}
process
{
$InputObject = $InputObject.ToLower()
if ( $translate.ContainsKey( $InputObject ) )
{
return $translate[ $InputObject ]
}
return $InputObject
}
}
129 changes: 129 additions & 0 deletions PSGraph/Public/Entity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

Enum EntityType
{
Name
Value
TypeName
}

Function Entity
{
<#
.SYNOPSIS
Convert an object into a PSGraph Record
.DESCRIPTION
Convert an object into a PSGraph Record
.PARAMETER InputObject
The object to convert into a record
.PARAMETER Name
The name of the node
.PARAMETER Show
The different details to show in the record.
Name : The property name
Value : The property name and value
TypeName : The property name and the value type
.PARAMETER Property
The list of properties to display. Default is to list them all.
Supports wildcards.
.EXAMPLE
$sample = [pscustomobject]@{
first = 1
second = 'two'
}
graph {
$sample | Entity -Show TypeName
} | export-PSGraph -ShowGraph
.NOTES
General notes
#>
[CmdletBinding()]
param (
[parameter(
ValueFromPipeline,
position = 0
)]
$InputObject,

[string]
$Name,

[string[]]
$Property,

[EntityType]
$Show = [EntityType]::TypeName
)

end
{
if([string]::isnullorempty($Name) )
{
$Name = $InputObject.GetType().Name
}

if($InputObject -is [System.Collections.IDictionary])
{
$members = $InputObject.keys
}
else
{
$Members = $InputObject.PSObject.Properties.Name
}

$rows = foreach ($propertyName in $members)
{
if($null -ne $Property)
{
$matches = $property | Where-Object {$propertyName -like $_}
if($null -eq $matches)
{
continue
}
}

$value = $inputobject.($propertyName)
switch ($Show)
{
Name
{
Row "<B>$propertyName</B>" -Name $propertyName
}
TypeName
{
if($null -ne $value)
{
$type = $value.GetType().Name
}
else
{
$type = 'null'
}
Row ('<B>{0}</B> <I>[{1}]</I>' -f $propertyName, $type) -Name $propertyName
}
Value
{
if([string]::IsNullOrEmpty($value))
{
$value = ' '
}
elseif ($value.count -gt 1)
{
$value = '[object[]]'
}
Row ('<B>{0}</B> : <I>{1}</I>' -f $propertyName, ([System.Net.WebUtility]::HtmlEncode($value))) -Name $propertyName
}
}
}

Record -Name $Name -Row $rows
}
}
10 changes: 9 additions & 1 deletion PSGraph/Public/Export-PSGraph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ function Export-PSGraph
# Resolve-path spits out an error with empty string paths, even with SilentlyContinue
if ( @( $Source | Where-Object { [String]::IsNullOrEmpty($_) } ).Count -eq 0 )
{
$fileList = Resolve-Path -Path $Source -ErrorAction SilentlyContinue
try
{
$fileList = Resolve-Path -Path $Source -ErrorAction Stop
}
catch
{
# I don't care that it isn't a file, I'll do something else with the data
$fileList = $null
}
}

if ( $null -ne $fileList -and $Source.Count -gt 0 )
Expand Down
129 changes: 129 additions & 0 deletions PSGraph/Public/Record.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

function Record
{
<#
.SYNOPSIS
Creates a record object
.DESCRIPTION
Creates a record object that contains rows of data.
.PARAMETER Name
The node name for this record
.PARAMETER Label
The label to use for the headder of the record.
.PARAMETER Row
An array of strings/objects to place in this record
.PARAMETER RowScript
A script to run on each row
.PARAMETER ScriptBlock
A sub expression that contains Row commands
.EXAMPLE
graph {
Record Components1 @(
'Name'
'Environment'
'Test <I>[string]</I>'
)
Record Components2 {
Row Name
Row 'Environment <B>test</B>'
'Test'
}
Edge Components1:Name -to Components2:Name
Echo one two three | Record Fish
Record Cow red,blue,green
} | Export-PSGraph -ShowGraph
.NOTES
Early release version of this command.
A lot of stuff is hard coded that should be exposed as attributes
#>
[OutputType('System.String')]
[cmdletbinding(DefaultParameterSetName = 'Script')]
param(
[Parameter(
Mandatory,
Position = 0
)]
[alias('ID', 'Node')]
[string]
$Name,

[Parameter(
Position = 1,
ValueFromPipeline,
ParameterSetName = 'Strings'
)]
[alias('Rows')]
[Object[]]
$Row,

[Parameter(
Position = 1,
ParameterSetName = 'Script'
)]
[ScriptBlock]
$ScriptBlock,

[Parameter(
Position = 2
)]
[ScriptBlock]
$RowScript,

[string]
$Label
)
begin
{
$tableData = [System.Collections.ArrayList]::new()
if ( [string]::IsNullOrEmpty($Label) )
{
$Label = $Name
}
}
process
{
if ( $null -ne $ScriptBlock )
{
$Row = $ScriptBlock.Invoke()
}

if ( $null -ne $RowScript )
{
$Row = foreach ( $node in $Row )
{
@($node).ForEach($RowScript)
}
}

$results = foreach ( $node in $Row )
{
Row -Label $node
}

foreach ( $node in $results )
{
[void]$tableData.Add($node)
}
}
end
{
$html = '<TABLE CELLBORDER="1" BORDER="0" CELLSPACING="0"><TR><TD bgcolor="black" align="center"><font color="white"><B>{0}</B></font></TD></TR>{1}</TABLE>' -f $Label, ($tableData -join '')
Node $Name @{label = $html; shape = 'none'; fontname = "Courier New"; style = "filled"; penwidth = 1; fillcolor = "white"}
}
}

Loading

0 comments on commit 37ee908

Please sign in to comment.