From ba3d65f122ae715eb84657c9df4dd1e49c83e209 Mon Sep 17 00:00:00 2001 From: horker Date: Thu, 22 Mar 2018 03:03:04 +0900 Subject: [PATCH] Fix BoxPlotSeries problems --- scripts/DataPoints.ps1 | 11 +++++++++- scripts/Misc.ps1 | 3 ++- scripts/Parameter.ps1 | 1 + scripts/Style.ps1 | 37 +++++++++++++++++++++++++++------ styles/ggplot.Style.ps1 | 19 ++++++++++++----- templates/XYSeries.template.ps1 | 10 +++++---- templates/template.build.ps1 | 4 +++- tests/Series.Tests.ps1 | 5 ++++- tests/Style.Tests.ps1 | 9 ++++++++ 9 files changed, 80 insertions(+), 19 deletions(-) diff --git a/scripts/DataPoints.ps1 b/scripts/DataPoints.ps1 index 0be2aa1..534308c 100644 --- a/scripts/DataPoints.ps1 +++ b/scripts/DataPoints.ps1 @@ -314,7 +314,8 @@ function Add-OxyBoxPlotSeriesPoint { [object]$BoxBottom, [object]$Median, [object]$BoxTop, - [object]$UpperWhistker + [object]$UpperWhistker, + [object[]]$Outlier ) $X = Convert-ParameterValue double $X @@ -325,5 +326,13 @@ function Add-OxyBoxPlotSeriesPoint { $UpperWhistker = Convert-ParameterValue double $UpperWhistker $p = New-Object OxyPlot.Series.BoxPlotItem $X, $LowerWhisker, $BoxBottom, $Median, $BoxTop, $UpperWhistker + + if ($null -ne $Outlier -and $Outlier.Count -gt 0) { + $Outlier = $Outlier | foreach { + Convert-ParameterValue double $_ + } + $p.Outliers.AddRange([double[]]$Outlier) + } + $series.Items.Add($p) } diff --git a/scripts/Misc.ps1 b/scripts/Misc.ps1 index 8ed1436..7eb9201 100644 --- a/scripts/Misc.ps1 +++ b/scripts/Misc.ps1 @@ -68,7 +68,8 @@ function Get-RequiredCategoryAxis { ) if ($Series -is [OxyPlot.Series.ColumnSeries] -or - $Series -is [OxyPlot.Series.ErrorColumnSeries]) { + $Series -is [OxyPlot.Series.ErrorColumnSeries] -or + $Series -is [OxyPlot.Series.BoxPlotSeries]) { return "x" } diff --git a/scripts/Parameter.ps1 b/scripts/Parameter.ps1 index 58015e8..25f9eaa 100644 --- a/scripts/Parameter.ps1 +++ b/scripts/Parameter.ps1 @@ -3,6 +3,7 @@ Set-StrictMode -Version 3 $TypeMapping = @{ "System.Double" = "object" "double" = "object" + "double[]" = "object[]" "OxyPlot.OxyColor" = "string" "OxyPlot.OxyPalette" = "object[]" "OxyPlot.OxyThickness" = "double[]" diff --git a/scripts/Style.ps1 b/scripts/Style.ps1 index b7f72d1..9d8ad52 100644 --- a/scripts/Style.ps1 +++ b/scripts/Style.ps1 @@ -11,12 +11,13 @@ function Add-OxyStyle { $filteredTypes = New-Object Collections.Generic.List[object] - $result = @{} + $general = @{} + $specific = @{} foreach ($filter in $Config.Keys) { if ($filter -match "^\[") { - $result[$filter] = $Config[$filter] + $general[$filter] = $Config[$filter] continue } @@ -66,11 +67,22 @@ function Add-OxyStyle { $value = Convert-ParameterValue $prop.PropertyType.FullName $originalValue } - if ($result.Contains($t.FullName)) { - $result[$t.Fullname][$filterProp] = $value + $isGeneral = $filterType -match "[*?]" + if ($isGeneral) { + if ($general.Contains($t.FullName)) { + $general[$t.Fullname][$filterProp] = $value + } + else { + $general[$t.FullName] = @{ $filterProp = $value } + } } else { - $result[$t.FullName] = @{ $filterProp = $value } + if ($specific.Contains($t.FullName)) { + $specific[$t.Fullname][$filterProp] = $value + } + else { + $specific[$t.FullName] = @{ $filterProp = $value } + } } } @@ -82,7 +94,20 @@ function Add-OxyStyle { } - $Styles[$StyleName] = $result + foreach ($type in $specific.Keys) { + if ($specific[$type] -is [Collections.IDictionary]) { + foreach ($prop in $specific[$type].Keys) { + if ($general.Contains($type)) { + $general[$type][$prop] = $specific[$type][$prop] + } + else { + $general[$type] = @{ $prop = $specific[$type][$prop] } + } + } + } + } + + $Styles[$StyleName] = $general } function Remove-OxyStyle { diff --git a/styles/ggplot.Style.ps1 b/styles/ggplot.Style.ps1 index de89e09..8fc5ba9 100644 --- a/styles/ggplot.Style.ps1 +++ b/styles/ggplot.Style.ps1 @@ -31,30 +31,33 @@ $config = @{ "PlotModel.LegendFontSize" = $baseSize, "pt" "PlotModel.LegendLineSpacing" = $baseLineSize, "pt" - # Axis: Tick + # *Axis: Tick "*Axis.TickStyle" = "Outside" "*Axis.TicklineColor" = "#4D4D4D" "*Axis.TextColor" = "#4D4D4D" "*Axis.FontSize" = ($baseSize * 0.8), "pt" - # Axis: MinorTick + # *Axis: MinorTick "*Axis.MinorTickSize" = 0 - # Axis: MajorGridline + # *Axis: MajorGridline "*Axis.MajorGridlineStyle" = "Solid" "*Axis.MajorGridlineColor" = "White" "*Axis.MajorGridlineThickness" = "1px" - # Axis: MinorGridline + # *Axis: MinorGridline "*Axis.MinorGridlineStyle" = "Solid" "*Axis.MinorGridlineColor" = "#F0F0F0" "*Axis.MinorGridlineThickness" = "1px" - # Axis: Title + # *Axis: Title "*Axis.TitleFontSize" = ($baseSize * 1.2), "pt" "*Axis.TitleColor" = "#4D4D4D" "*Axis.AxisTitleDistance" = ($baseSize * 2), "pt" + # CategoryAxis: FontSize + "CategoryAxis.FontSize" = $baseSize, "pt" + # *Series "*Series.StrokeThickness" = "1px" "*Series.StrokeColor" = "Automatic" @@ -65,6 +68,12 @@ $config = @{ "Scatter*Series.MarkerType" = "Diamond" "Scatter*Series.MarkerSize" = "3px" + # BoxPlotSeries + "BoxPlotSeries.Fill" = "White" + "BoxPlotSeries.StrokeThickNess" = "2pt" + "BoxPlotSeries.WhiskerWidth" = 0 + "BoxPlotSeries.OutlierSize" = "3pt" + # PieSeries "PieSeries.StartAngle" = -90 "PieSeries.Diameter" = 0.9 diff --git a/templates/XYSeries.template.ps1 b/templates/XYSeries.template.ps1 index 56eaaad..e7183d7 100644 --- a/templates/XYSeries.template.ps1 +++ b/templates/XYSeries.template.ps1 @@ -167,7 +167,7 @@ end { $grouping = $false } - $dataCount = $<% $SeriesElement.Element[0].Name %>Data.Count + $dataCount = (<% ($SeriesElement.Element.Name -replace "(.+)", '$$$1Data.Count') -join ", " %> | Measure -Maximum).Maximum foreach ($group in $GroupingKeys) { <% } # if ($SeriesElement -ne $null) -%> @@ -186,10 +186,12 @@ end { continue } <% foreach ($e in $SeriesElement.Element) { -%> -<% if ($e.Name -ne "CategoryIndex") { -%> - if ($i -lt $<% $e.Name %>Data.Count) { $<% $e.Name %>Element = $<% $e.Name %>Data[$i] } else { $<% $e.Name %>Element = $null } -<% } else { -%> +<% if ($e.Name -eq "CategoryIndex") { -%> if ($i -lt $CategoryIndexData.Count) { $CategoryIndexElement = $CategoryIndexData[$i] } else { $CategoryIndexElement = $catCount } +<% } elseif ($e.Name -eq "X" -and $ClassName -match "BoxPlotSeries") { -%> + if ($i -lt $XData.Count) { $XElement = $XData[$i] } else { $XElement = $catCount } +<% } else { -%> + if ($i -lt $<% $e.Name %>Data.Count) { $<% $e.Name %>Element = $<% $e.Name %>Data[$i] } else { $<% $e.Name %>Element = $null } <% } -%> <% } -%> <% $SeriesElement.Cmdlet %> $series<% $SeriesElement.Element | where { $_.Name -ne "Category" } | foreach { %> $<% $_.Name %>Element<% } %> diff --git a/templates/template.build.ps1 b/templates/template.build.ps1 index 7fa7f93..8ee8039 100644 --- a/templates/template.build.ps1 +++ b/templates/template.build.ps1 @@ -156,7 +156,9 @@ $DATAPOINTS.BoxPlot = @{ @{ Name = "BoxBottom"; Class = "double" }, @{ Name = "Median"; Class = "double"; Axis = "Y" }, @{ Name = "BoxTop"; Class = "double" }, - @{ Name = "UpperWhisker"; Class = "double" } + @{ Name = "UpperWhisker"; Class = "double" }, + @{ Name = "Outlier"; Class = "double[]" }, + @{ Name = "Category"; Class = "string" } ) } diff --git a/tests/Series.Tests.ps1 b/tests/Series.Tests.ps1 index 6b23a28..9a2c6bf 100644 --- a/tests/Series.Tests.ps1 +++ b/tests/Series.Tests.ps1 @@ -68,7 +68,8 @@ Describe "series creation cmdlets" { -BoxBottom 21,22,23,24,25,36 ` -Median 31,32,33,34,35,36 ` -BoxTop 41,42,43,44,45,46 ` - -UpperWhisker 51,52,53,54,55,56 + -UpperWhisker 51,52,53,54,55,56 ` + -Outlier @(@(1,2,3), @(4,5,6,7), @(8,9,10,11,12)) $s | Should -BeOfType [OxyPlot.Series.BoxPlotSeries] $s.Items[0].X | Should -Be 1 $s.Items[1].LowerWhisker | Should -Be 12 @@ -76,6 +77,8 @@ Describe "series creation cmdlets" { $s.Items[3].Median | Should -Be 34 $s.Items[4].BoxTop | Should -Be 45 $s.Items[5].UpperWhisker | Should -Be 56 + $s.Items[0].Outliers.Count | Should -Be 3 + $s.Items[0].Outliers[2] | Should -Be 3 } It "can create a CandleStickAndVolumeSeries object" { diff --git a/tests/Style.Tests.ps1 b/tests/Style.Tests.ps1 index 9323b5f..30c8707 100644 --- a/tests/Style.Tests.ps1 +++ b/tests/Style.Tests.ps1 @@ -37,6 +37,15 @@ Describe "Add-OxyStyle" { $style["OxyPlot.Series.ColumnSeries"]["FontSize"] | Should -Be (10 * 96) } + It "can override a specific definition over a general definition" { + Add-OxyStyle TestStyle @{ + "*Series.FontSize" = 10 + "ColumnSeries.FontSize" = 20 + } + + $style = Get-OxyStyle TestStyle + $style["OxyPlot.Series.ColumnSeries"]["FontSize"] | Should -Be 20 + } } Describe "Apply-OxyStyle" {