OxyPlot.Series.PieSeries.ps1

Set-StrictMode -Version 3

<#
.SYNOPSIS
 
Represents a series for pie/circle/doughnut charts.
 
The arc length/central angle/area of each slice is proportional to the quantity it represents.
See Pie charts (http://en.wikipedia.org/wiki/Pie_chart).
 
.PARAMETER Parent
 
Gets the parent model of the element.
 
.PARAMETER ItemsSource
Sets the items source. The default is null.
 
.PARAMETER Background
Sets the background color of the series. The default is OxyColors.Undefined.
 
This property defines the background color in the area defined by the x and y axes used by this series.
 
.PARAMETER IsVisible
Sets a value indicating whether this series is visible. The default is true.
 
.PARAMETER Title
Sets the title of the series. The default is null.
 
.PARAMETER RenderInLegend
Sets a value indicating whether the series should be rendered in the legend. The default is true.
 
.PARAMETER TrackerFormatString
Sets a format string used for the tracker. The default depends on the series.
 
The arguments for the format string may be different for each type of series. See the documentation.
 
.PARAMETER TrackerKey
Sets the key for the tracker to use on this series. The default is null.
 
This key may be used by the plot view to show a custom tracker for the series.
 
.PARAMETER AngleIncrement
Sets the angle increment.
 
.PARAMETER AngleSpan
Sets the angle span.
 
.PARAMETER AreInsideLabelsAngled
Sets a value indicating whether inside labels are angled.
 
.PARAMETER ColorField
Sets the name of the property containing the color.
 
.PARAMETER Diameter
Sets the diameter.
 
.PARAMETER ExplodedDistance
Sets the exploded distance.
 
.PARAMETER InnerDiameter
Sets the inner diameter.
 
.PARAMETER InsideLabelColor
Sets the color of the inside labels.
 
If the value is OxyColors.Automatic, the OxyPlot.PlotElement.TextColor will be used.
 
.PARAMETER InsideLabelFormat
Sets the inside label format.
 
The formatting arguments are: value {0}, label {1} and percentage {2}.
 
.PARAMETER InsideLabelPosition
Sets the inside label position.
 
.PARAMETER IsExplodedField
Sets the is exploded field.
 
.PARAMETER LabelField
Sets the label field.
 
.PARAMETER LegendFormat
Sets the legend format.
 
.PARAMETER OutsideLabelFormat
Sets the outside label format.
 
.PARAMETER Slices
Sets the slices.
 
.PARAMETER StartAngle
Sets the start angle.
 
.PARAMETER Stroke
Sets the stroke color.
 
.PARAMETER StrokeThickness
Sets the stroke thickness.
 
.PARAMETER TickDistance
Sets the distance from the edge of the pie slice to the tick line.
 
.PARAMETER TickHorizontalLength
Sets the length of the horizontal part of the tick.
 
.PARAMETER TickLabelDistance
Sets the distance from the tick line to the outside label.
 
.PARAMETER TickRadialLength
Sets the length of the radial part of the tick line.
 
.PARAMETER ValueField
Sets the name of the property containing the value.
 
.PARAMETER Font
Sets the font. The default is null (use OxyPlot.PlotModel.DefaultFont.
 
If the value is null, the DefaultFont of the parent PlotModel will be used.
 
.PARAMETER FontSize
Sets the size of the font. The default is double.NaN (use OxyPlot.PlotModel.DefaultFontSize).
 
If the value is NaN, the DefaultFontSize of the parent PlotModel will be used.
 
.PARAMETER FontWeight
Sets the font weight. The default is FontWeights.Normal.
 
.PARAMETER PlotModel
 
Gets the parent OxyPlot.PlotElement.PlotModel.
 
.PARAMETER Tag
Sets an arbitrary object value that can be used to store custom information about this plot element. The default is null.
 
This property is analogous to Tag properties in other Microsoft programming models. Tag is intended to provide a pre-existing property location where you can store some basic custom information about any PlotElement without requiring you to subclass an element.
 
.PARAMETER TextColor
Sets the color of the text. The default is OxyColors.Automatic (use OxyPlot.PlotModel.TextColor).
 
If the value is OxyColors.Automatic, the TextColor of the parent PlotModel will be used.
 
.PARAMETER ToolTip
Sets the tool tip. The default is null.
 
.PARAMETER ActualFont
 
Gets the actual font.
 
.PARAMETER ActualFontSize
 
Gets the actual size of the font.
 
.PARAMETER ActualFontWeight
 
Gets the actual font weight.
 
.PARAMETER ActualTextColor
 
Gets the actual color of the text.
 
.PARAMETER ActualCulture
 
Gets the actual culture.
 
The culture is defined in the parent PlotModel.
 
.PARAMETER Selectable
Sets a value indicating whether this element can be selected. The default is true.
 
.PARAMETER SelectionMode
Sets the selection mode of items in this element. The default is SelectionMode.All.
 
This is only used by the select/unselect functionality, not by the rendering.
 
.PARAMETER ActualSelectedColor
 
Gets the actual selection color.
 
.LINK
http://en.wikipedia.org/wiki/Pie_chart
 
 
.DESCRIPTION
This cmdlet creates an OxyPlot.Series.PieSeries object.
 
.PARAMETER InputObject
Sets the source of the data set.
 
.PARAMETER Label
Sets the column Label of the data set.
 
.PARAMETER Value
Sets the column Value of the data set.
 
.PARAMETER Fill
Sets the column Fill of the data set.
 
.PARAMETER IsExploded
Sets the column IsExploded of the data set.
 
.PARAMETER Group
Specifies groups to which each element of the data set belongs.
 
If this parameter is set, the data set will be grouped by these values, and multiple series will be produced for each group.
 
.PARAMETER LabelName
Specifies a property name of the input objects to be assigned to the column Label of the data set.
 
.PARAMETER ValueName
Specifies a property name of the input objects to be assigned to the column Value of the data set.
 
.PARAMETER FillName
Specifies a property name of the input objects to be assigned to the column Fill of the data set.
 
.PARAMETER IsExplodedName
Specifies a property name of the input objects to be assigned to the column IsExploded of the data set.
 
.PARAMETER GroupName
Specifies a property name of the input objects to be treated as groups.
 
If this parameter is set, the data set will be grouped by the values of this property, and multiple series will be produced for each group.
 
.PARAMETER GroupingKeys
Specifies effective groups and these order.
 
This option is useful when you will select groups, or specify the order of the groups shown in the legend.
 
.PARAMETER Options
Sets properties of the object.
 
.PARAMETER Style
Sets a style of the object.
 
.PARAMETER AddTo
Specifies a plot model to which the object will be added.
 
.INPUTS
You can send any object to the cmdlet as the source of the data set.
#>

function New-OxyPieSeries {
  [cmdletbinding()]
  [OutputType([OxyPlot.Series.PieSeries[]], [void])]
  param(
    [Parameter(ValueFromPipeline=$true)]
    [object]$InputObject,

    [string[]]$Label = @(),
    [object[]]$Value = @(),
    [string[]]$Fill = @(),
    [object[]]$IsExploded = @(),
    [string[]]$Group = @(),

    [string]$LabelName,
    [string]$ValueName,
    [string]$FillName,
    [string]$IsExplodedName,
    [string]$GroupName,
    [string[]]$GroupingKeys = @(),

    [object]$AngleIncrement,
    [object]$AngleSpan,
    [System.Boolean]$AreInsideLabelsAngled,
    [System.String]$ColorField,
    [object]$Diameter,
    [object]$ExplodedDistance,
    [object]$InnerDiameter,
    [ValidatePattern('AliceBlue|AntiqueWhite|Aqua|Aquamarine|Automatic|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenrod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|Firebrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|Goldenrod|Gray|Green|GreenYellow|Honeydew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenrodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquamarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenrod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Undefined|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen|(#?[0-9a-f]{1,8})')][string]$InsideLabelColor,
    [System.String]$InsideLabelFormat,
    [object]$InsideLabelPosition,
    [System.String]$IsExplodedField,
    [System.String]$LabelField,
    [System.String]$LegendFormat,
    [System.String]$OutsideLabelFormat,
    [OxyPlot.Series.PieSlice[]]$Slices,
    [object]$StartAngle,
    [ValidatePattern('AliceBlue|AntiqueWhite|Aqua|Aquamarine|Automatic|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenrod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|Firebrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|Goldenrod|Gray|Green|GreenYellow|Honeydew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenrodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquamarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenrod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Undefined|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen|(#?[0-9a-f]{1,8})')][string]$Stroke,
    [object]$StrokeThickness,
    [object]$TickDistance,
    [object]$TickHorizontalLength,
    [object]$TickLabelDistance,
    [object]$TickRadialLength,
    [System.String]$ValueField,
    [System.Collections.IEnumerable]$ItemsSource,
    [ValidatePattern('AliceBlue|AntiqueWhite|Aqua|Aquamarine|Automatic|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenrod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|Firebrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|Goldenrod|Gray|Green|GreenYellow|Honeydew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenrodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquamarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenrod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Undefined|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen|(#?[0-9a-f]{1,8})')][string]$Background,
    [System.Boolean]$IsVisible,
    [System.String]$Title,
    [System.Boolean]$RenderInLegend,
    [System.String]$TrackerFormatString,
    [System.String]$TrackerKey,
    [System.String]$Font,
    [object]$FontSize,
    [object]$FontWeight,
    [System.Object]$Tag,
    [ValidatePattern('AliceBlue|AntiqueWhite|Aqua|Aquamarine|Automatic|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenrod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|Firebrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|Goldenrod|Gray|Green|GreenYellow|Honeydew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenrodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquamarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenrod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Undefined|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen|(#?[0-9a-f]{1,8})')][string]$TextColor,
    [System.String]$ToolTip,
    [System.Boolean]$Selectable,
    [OxyPlot.SelectionMode]$SelectionMode,
    [OxyPlot.Model]$Parent,

    [hashtable]$Options = @{},

    [string]$Style = "default",
    [OxyPlot.PlotModel]$AddTo
  )

begin {

  if (!(Test-OxyStyleName $Style)) {
    Write-Error "Unknown style: '$Style'"
    return
  }

  $info = [PSCustomObject]@{
    XAxisTitle = $null
    YAxisTitle = $null
    XDataType = $null
    YDataType = $null
    GroupName = $GroupName
    CategoryNames = @()
    CategoryTitle = $null
  }



  $LabelData = New-Object Collections.Generic.List[string]
  $ValueData = New-Object Collections.Generic.List[object]
  $FillData = New-Object Collections.Generic.List[string]
  $IsExplodedData = New-Object Collections.Generic.List[object]
  $GroupData = New-Object Collections.Generic.List[string]

}

process {
  if ($InputObject -ne $null) {
    if ($PSBoundParameters.ContainsKey("LabelName")) { $LabelData.Add($InputObject.$LabelName) }
    if ($PSBoundParameters.ContainsKey("ValueName")) { $ValueData.Add($InputObject.$ValueName) }
    if ($PSBoundParameters.ContainsKey("FillName")) { $FillData.Add($InputObject.$FillName) }
    if ($PSBoundParameters.ContainsKey("IsExplodedName")) { $IsExplodedData.Add($InputObject.$IsExplodedName) }
    if ($PSBoundParameters.ContainsKey("GroupName")) { $GroupData.Add($InputObject.$GroupName) }
  }
}

end {
  if ($LabelData.Count -gt 0 -and $Label.Count -gt 0) { Write-Error "Data set of 'Label' is given in two ways"; return }
  if ($ValueData.Count -gt 0 -and $Value.Count -gt 0) { Write-Error "Data set of 'Value' is given in two ways"; return }
  if ($FillData.Count -gt 0 -and $Fill.Count -gt 0) { Write-Error "Data set of 'Fill' is given in two ways"; return }
  if ($IsExplodedData.Count -gt 0 -and $IsExploded.Count -gt 0) { Write-Error "Data set of 'IsExploded' is given in two ways"; return }
  if ($GroupData.Count -gt 0 -and $Group.Count -gt 0) { Write-Error "Data set of 'Group' is given in two ways"; return }

  $LabelData.AddRange($Label)
  $ValueData.AddRange($Value)
  $FillData.AddRange($Fill)
  $IsExplodedData.AddRange($IsExploded)
  $GroupData.AddRange($Group)

  if ($GroupData.Count -gt 0) {
    $groups = @{}
    foreach ($e in $GroupData) {
      $groups[$e] = 1
    }
    if ($GroupingKeys.Count -eq 0) {
      $GroupingKeys = $groups.Keys | Sort
    }
    $grouping = $true
  }
  else {
    $GroupingKeys = @("dummy")
    $grouping = $false
  }

  $dataCount = $LabelData.Count
  foreach ($group in $GroupingKeys) {

    $series = New-Object OxyPlot.Series.PieSeries

    if ($grouping) {
      $series.Title = $group
    }

    $catCount = 0;
    for ($i = 0; $i -lt $dataCount; ++$i) {
      if ($grouping -and $GroupData[$i] -ne $group) {
        continue
      }
      if ($i -lt $LabelData.Count) { $LabelElement = $LabelData[$i] } else { $LabelElement = $null }
      if ($i -lt $ValueData.Count) { $ValueElement = $ValueData[$i] } else { $ValueElement = $null }
      if ($i -lt $FillData.Count) { $FillElement = $FillData[$i] } else { $FillElement = $null }
      if ($i -lt $IsExplodedData.Count) { $IsExplodedElement = $IsExplodedData[$i] } else { $IsExplodedElement = $null }
      Add-OxyPieSeriesPoint $series $LabelElement $ValueElement $FillElement $IsExplodedElement
      ++$catCount
    }


    $series = $series | Add-Member -PassThru NoteProperty _Info $info

    Apply-OxyStyle $series $Style $MyInvocation

    $props = $PROPERTY_HASH["OxyPlot.Series.PieSeries"]
    Assign-ParametersToProperties $props $PSBoundParameters $Options $series

    if ($AddTo -ne $null) {
      Add-OxyObjectToPlotModel $series $AddTo -NoRefresh
    }
    else {
      $series
    }
  }

  if ($AddTo -ne $null) {
    $AddTo.InvalidatePlot($true)
  }
}
}