in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/scale/Manual.kt [46:103]
fun scaleManual(
aesthetic: Any,
values: Any,
name: String? = null,
breaks: Any? = null,
labels: Any? = null,
lablim: Int? = null,
limits: List<Any>? = null,
naValue: Any? = null,
format: String? = null,
guide: Any? = null
): Scale {
var newBreaks = breaks
val newValues: List<Any>? = when (values) {
is Map<*, *> -> {
if (breaks == null && limits == null) {
newBreaks = values.keys.toList()
values.values
} else {
val baseOrderList = when (val base = limits ?: breaks) {
is Map<*, *> -> base.values
is List<*> -> base
else -> null
}
val newValues = baseOrderList?.mapNotNull { values[it] }
if (!newValues.isNullOrEmpty()) {
val noMatchValues = values.values.filter { it !in newValues }
newValues + noMatchValues
} else {
null
}
}
}
is List<*> -> values
else -> error("The scale 'values' parameter should be specified with a list or dictionary.")
}?.let { list ->
require(list.all { it != null }) { "'values' is non-nullable list, but was: $list" }
list.map { v -> v as Any }
}
return Scale(
aesthetic = aesthetic,
name = name,
breaks = newBreaks,
labels = labels,
lablim = lablim,
limits = limits,
naValue = naValue,
format = format,
guide = guide,
otherOptions = Options(
mapOf(
Option.Scale.OUTPUT_VALUES to newValues
)
)
)
}