Skip to content

Commit

Permalink
Fix BoxPlotSeries problems
Browse files Browse the repository at this point in the history
  • Loading branch information
horker committed Mar 21, 2018
1 parent 937d637 commit ba3d65f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 19 deletions.
11 changes: 10 additions & 1 deletion scripts/DataPoints.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ function Add-OxyBoxPlotSeriesPoint {
[object]$BoxBottom,
[object]$Median,
[object]$BoxTop,
[object]$UpperWhistker
[object]$UpperWhistker,
[object[]]$Outlier
)

$X = Convert-ParameterValue double $X
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion scripts/Misc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
1 change: 1 addition & 0 deletions scripts/Parameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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[]"
Expand Down
37 changes: 31 additions & 6 deletions scripts/Style.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 }
}
}

}
Expand All @@ -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 {
Expand Down
19 changes: 14 additions & 5 deletions styles/ggplot.Style.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions templates/XYSeries.template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%>
Expand All @@ -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<% } %>
Expand Down
4 changes: 3 additions & 1 deletion templates/template.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
)
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Series.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ 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
$s.Items[2].BoxBottom | Should -Be 23
$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" {
Expand Down
9 changes: 9 additions & 0 deletions tests/Style.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit ba3d65f

Please sign in to comment.