Modules/UniversalDashboard.Charts/UniversalDashboard.Charts.psm1

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
56
57
58
59

$JsFiles = Get-ChildItem "$PSScriptRoot\*.bundle.js"

$Items = @("nivo-bar", "nivo-calendar", "nivo-heatmap", "nivo-line", "nivo-pie", "nivo-stream", "nivo-treemap")
foreach($item in $items) {
    $JsFiles | Where-Object { $_.FullName.Contains($item)} | ForEach-Object {

        if (-not ([UniversalDashboard.Enterprise.NewNivoChartCommand]::AssetIds.ContainsKey($item))) {
            [UniversalDashboard.Enterprise.NewNivoChartCommand]::AssetIds.Add($item, [UniversalDashboard.Services.AssetService]::Instance.RegisterScript($_))
        }
    }
}

$SparklinesFile = $JsFiles | Where-Object { $_.FullName.Contains("sparklines")}

$SparklinesAssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterScript($SparklinesFile.FullName)

function New-UDSparklines {
    param(
        [Parameter()]
        [string]$Id = (New-Guid).ToString(),
        [Parameter(Mandatory)]
        [float[]]$Data,
        [Parameter()]
        [ValidateSet('lines', 'bars', 'both')]
        [string]$Type = 'lines',
        [Parameter()]
        [int]$Width,
        [Parameter()]
        [int]$Height,
        [Parameter()]
        [int]$Margin,
        [Parameter()]
        [float]$Minimum,
        [Parameter()]
        [float]$Maximum,
        [Parameter()]
        [UniversalDashboard.Models.DashboardColor]$Color,
        [Parameter()]
        [Hashtable]$Style
    )

    Process {
        @{
            isPlugin = $true
            assetId = $SparklinesAssetId
            data = $Data
            type = $Type
            id = $Id
            width = $Width
            height = $Height
            margin = $Margin
            min = $Minimum
            max = $Maximum
            color = $Color
            style = $Style
        }
    }
}