Functions/SVG/New-Svg.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function New-Svg {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute(
        "PSUseShouldProcessForStateChangingFunctions", 
        "", 
        Justification = "Creates in-memory object only."
    )]
    
    [CmdletBinding(DefaultParameterSetName='Individual')]
    param(
        [Parameter(ParameterSetName='Individual')]
        [ValidateNotNullOrEmpty()]
        [float]
        $StartX = -400
        ,
        [Parameter(ParameterSetName='Individual')]
        [ValidateNotNullOrEmpty()]
        [float]
        $StartY = -400
        ,
        [Parameter(ParameterSetName='Individual')]
        [ValidateNotNullOrEmpty()]
        [float]
        $Width = 800
        ,
        [Parameter(ParameterSetName='Individual')]
        [ValidateNotNullOrEmpty()]
        [float]
        $Height = 800
        ,
        [Parameter(ParameterSetName='Array')]
        [ValidateNotNullOrEmpty()]
        [hashtable]
        $Dimension
    )

    if ($PSCmdlet.ParameterSetName -ieq 'Array') {
        $StartX = $Dimension.x
        $StartY = $Dimension.y
        $Width  = $Dimension.width
        $Height = $Dimension.height
    }

    $Svg = New-Object System.XML.XMLDocument

    $root = $Svg.CreateElement('svg')
    $root.SetAttribute('version', '1.2')
    $root.SetAttribute('xmlns', 'http://www.w3.org/2000/svg')
    $root.SetAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink')
    $root.SetAttribute('width', "$Width")
    $root.SetAttribute('height', "$Height")
    $root.SetAttribute('viewBox', "$StartX $StartY $Width $Height")
    $Svg.AppendChild($root) | Out-Null
    
    $Svg
}