Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend override_aes #1115

Merged
merged 20 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactoring legend
  • Loading branch information
MKoroteev-HORIS committed Jun 18, 2024
commit 44287db6892116e9f2f869303c88c2d00af4eb4c
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,14 @@ class LegendAssembler(
}
}

val legendBreaks = ArrayList<LegendBreak>()
for (legendBreak in legendBreaksByLabel.values) {
if (legendBreak.isEmpty) {
continue
}
legendBreaks.add(legendBreak)
}


val legendBreaks = legendBreaksByLabel.values.filterNot { it.isEmpty }
if (legendBreaks.isEmpty()) {
return LegendBoxInfo.EMPTY
}

// legend options
val legendOptionsList = ArrayList<LegendOptions>()
for (legendLayer in legendLayers) {
val aesList = legendLayer.aesList
for (aes in aesList) {
if (guideOptionsMap[aes] is LegendOptions) {
legendOptionsList.add(guideOptionsMap[aes] as LegendOptions)
}
val legendOptionsList = legendLayers.flatMap { legendLayer ->
legendLayer.aesList.mapNotNull { aes ->
guideOptionsMap[aes] as? LegendOptions
}
}

Expand Down Expand Up @@ -157,7 +144,7 @@ class LegendAssembler(

overrideAesValues.forEach { (aesToOverride, v) ->
val newAesValue = if (v is List<*>) {
v.getOrElse(index) { v.last() }
v.getOrElse(index) { v.lastOrNull() }
} else {
v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,18 @@ internal object PlotAssemblerUtil {
val legendKeyFactory = layerInfo.legendKeyElementFactory
val aestheticsDefaults = layerInfo.aestheticsDefaults

val overrideAesValues = mutableMapOf<Aes<*>, Any>()
aesListForScaleName.forEach { aes ->
val overrideOptionsForAes = (guideOptionsMap[aes] as? LegendOptions)?.overrideAesValues
if (!overrideOptionsForAes.isNullOrEmpty()) {
// ToDo Need to check for conflicting settings?
overrideAesValues += overrideOptionsForAes
}
}
val allOverrideAesValues =
guideOptionsMap
.filter { (aes, _) -> aes in aesListForScaleName }
.values
.filterIsInstance<LegendOptions>()
.map{it.overrideAesValues.orEmpty()}
.fold(mapOf<Aes<*>, Any>(), { acc, overrideAesValues -> acc + overrideAesValues })

legendAssembler.addLayer(
legendKeyFactory,
aesListForScaleName,
overrideAesValues,
allOverrideAesValues,
layerConstantByAes,
aestheticsDefaults,
layerInfo.colorByAes,
Expand Down