fun labs()

in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/label/labs.kt [55:112]


fun labs(
    title: String? = null,
    subtitle: String? = null,
    caption: String? = null,
    // aesthetics
    x: String? = null,
    y: String? = null,
    alpha: String? = null,
    color: String? = null,
    fill: String? = null,
    shape: String? = null,
    size: String? = null,
    width: String? = null,
    height: String? = null,
    linetype: String? = null,
    manual: String? = null
): FeatureList {
    val list = ArrayList<Feature>()
    title?.let { list.add(ggtitle(it, subtitle)) }

    caption?.let {
        list.add(
            OptionsMap(
                Option.Plot.CAPTION,
                mapOf(Option.Plot.CAPTION_TEXT to it)
            )
        )
    }

    // set titles via guides

    val aesTitles = listOf(
        Aes.X to x,
        Aes.Y to y,
        Aes.ALPHA to alpha,
        Aes.COLOR to color,
        Aes.FILL to fill,
        Aes.SHAPE to shape,
        Aes.SIZE to size,
        Aes.WIDTH to width,
        Aes.HEIGHT to height,
        Aes.LINETYPE to linetype,
    ).map { (aes, title) -> toOption(aes) to title }

    val titleGuides = (aesTitles + listOf(Option.Layer.DEFAULT_LEGEND_GROUP_NAME to manual))
        .associate { (key, title) -> key to title?.let(::guideTitleOption) }
        .filterNonNullValues()

    if (titleGuides.isNotEmpty()) {
        list.add(
            OptionsMap(
                Option.Plot.GUIDES, titleGuides
            )
        )
    }

    return FeatureList(list)
}