fun asDiscreteRegression()

in plot-api/src/jvmTest/kotlin/org/jetbrains/letsPlot/SeriesAnnotationTest.kt [161:286]


    fun asDiscreteRegression() {

        val data = mapOf(
            "v" to listOf("a", "b"),
            "bar" to listOf("b", "a")
        )

        (ggplot(data) { x = asDiscrete("v") } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).containsExactly(
                mappingAsDiscreteAnnotation(aes = Aes.X, label = "v")
            )
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING),
                seriesAnnotation(column = "bar", type = Types.STRING),
            )
        }

        (ggplot(data) { x = asDiscrete("v", order = 1) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).containsExactly(
                mappingAsDiscreteAnnotation(aes = Aes.X, label = "v", order = 1)
            )
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
        }

        (ggplot(data) { x = asDiscrete("v", orderBy = "bar") } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).containsExactly(
                mappingAsDiscreteAnnotation(aes = Aes.X, label = "v", orderBy = "bar")
            )
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
        }

        (ggplot(data) { x = asDiscrete("v", levels = listOf("b", "a")) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING, factorLevels = listOf("b", "a")),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(data) { x = asDiscrete("v", order = 1, levels = listOf("b", "a")) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING, factorLevels = listOf("b", "a"), order = 1),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(data) { x = asDiscrete("v", orderBy = "bar", levels = listOf("b", "a")) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING, factorLevels = listOf("b", "a")),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(data) {
            x = asDiscrete("v", order = 1, orderBy = "bar", levels = listOf("b", "a"))
        } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.STRING, factorLevels = listOf("b", "a"), order = 1),
                seriesAnnotation(column = "bar", type = Types.STRING)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        val a = Instant.parse("2020-01-01T00:00:00Z")
        val b = Instant.parse("2020-01-02T00:00:00Z")

        (ggplot(mapOf("v" to listOf(a, b))) { x = asDiscrete("v") } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).containsExactly(
                mappingAsDiscreteAnnotation(aes = Aes.X, label = "v")
            )
        }

        (ggplot(mapOf("v" to listOf(a, b))) { x = asDiscrete("v", levels = listOf(b, a)) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME, factorLevels = listOf(b, a))
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(mapOf("v" to listOf(a, b))) {
            x = asDiscrete("v", levels = listOf(b, a), order = 1)
        } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME, factorLevels = listOf(b, a), order = 1)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(mapOf("v" to listOf(a, b))) {
            x = asDiscrete("v", levels = listOf(b, a), orderBy = "v")
        } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME, factorLevels = listOf(b, a))
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(mapOf("v" to listOf(a, b))) {
            x = asDiscrete("v", levels = listOf(b, a), order = 1, orderBy = "v")
        } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME, factorLevels = listOf(b, a), order = 1)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).isNull()
        }

        (ggplot(mapOf("v" to listOf(a, b))) { x = asDiscrete("v", order = 1) } + geomPoint()).toSpec().let {
            assertThat(it.getList(DATA_META, SeriesAnnotation.TAG)).containsExactly(
                seriesAnnotation(column = "v", type = Types.DATE_TIME)
            )
            assertThat(it.getList(DATA_META, MappingAnnotation.TAG)).containsExactly(
                mappingAsDiscreteAnnotation(aes = Aes.X, label = "v", order = 1)
            )
        }
    }