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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

if ($Env:DebugCharts -eq $true) {
    $AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset("http://localhost:10000/udcharts.bundle.js")
    [UniversalDashboard.Enterprise.NewNivoChartCommand]::AssetId = $AssetId
} else {
    $JsFile = Get-ChildItem "$PSScriptRoot\udcharts.*.bundle.js"
    $AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset($JsFile.FullName)
    [UniversalDashboard.Enterprise.NewNivoChartCommand]::AssetId = $AssetId
}

function New-UDNivoTheme {
    param(
        [Parameter()]
        [UniversalDashboard.Models.DashboardColor]$TickLineColor,
        [Parameter()]
        [UniversalDashboard.Models.DashboardColor]$TickTextColor,
        [Parameter()]
        [UniversalDashboard.Models.DashboardColor]$GridLineStrokeColor,
        [Parameter()]
        [int]$GridStrokeWidth
    )

    @{
        axis = @{
            ticks = @{
                line = @{
                    stoke = $TickLineColor.HtmlColor
                }
                text = @{
                    fill = $TickTextColor.HtmlColor
                }
            }
        }
        grid = @{
            line = @{
                stroke = $GridLineStrokeColor.HtmlColor
                strokeWidth = $GridStrokeWidth
            }
        }
    }
}

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 = 500,
        [Parameter()]
        [int]$Height = 100,
        [Parameter()]
        [int]$Margin = 10,
        [Parameter()]
        [float]$Minimum,
        [Parameter()]
        [float]$Maximum,
        [Parameter()]
        [UniversalDashboard.Models.DashboardColor]$Color,
        [Parameter()]
        [Hashtable]$Style
    )

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