display results as color and opacity gradient

party colors were not really useful, when there are only two winning parties
main
lub 4 months ago
parent 3d4e9ced0e
commit 1eb674e532

@ -50,7 +50,12 @@ $data = Import-Csv $DataSource
$greenParty = ($data[0].PSObject.Properties.Name -like '*Grüne*')[0]
$partyMapping = $data | Where-Object Description -eq 'Color'
$dataMeasure = $data.$greenParty
| Where-Object {$_ -match '%$'}
| ForEach-Object {$_ -replace '%$'}
| Measure-Object -Minimum -Maximum
$minimumResultValue = $dataMeasure.Minimum
$maximumResultValue = $dataMeasure.Maximum
# nested array instead of hashtable, because hashtable keys are case-insensitive
$replacementList = @(
@ -88,27 +93,21 @@ $featureList = Import-Csv ./polling_stations.csv
$_.Formatted + "`t" + $_.Party
}) -join "`n"
$greenResult = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue
$greenResultValue = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue
$opacity = ($greenResult - 20) / 5 * 0.6 + 0.4
$opacity = $opacity -gt 1.0 ? 1.0 : $opacity
$opacity = $opacity -lt 0.4 ? 0.4 : $opacity
$colorGreen = (($greenResultValue - $minimumResultValue) * (100 - 220)) / ($maximumResultValue - $minimumResultValue) + 220
$color = "rgb(0, $colorGreen, 0)"
$weight = ($greenResult - 20) / 5 * 10 + 5
$weight = $weight -gt 15 ? 15 : $weight
$weight = $weight -lt 5 ? 5 : $weight
$party = $electionResultArray[0].Party
$opacity = (($greenResultValue - $minimumResultValue) * (1.0 - 0.4)) / ($maximumResultValue - $minimumResultValue) + 0.4
} else {
$electionResultString = 'no data available'
$opacity = 0.5
$party = $null
$color = '#ff00ff'
}
$umapOptiones = [PSCustomObject]@{
#color = ($using:partyMapping).$party
color = $partyMapping.$party ?? '#ff00ff'
weight = $weight
color = $color
weight = 10
opacity = $opacity
}

Loading…
Cancel
Save