JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
435 stars 36 forks source link

It fails to auto-convert number #98

Closed holgerbrandl closed 2 years ago

holgerbrandl commented 2 years ago

Consider the following type (simplified version of https://github.com/holgerbrandl/kalasim/blob/master/src/main/kotlin/org/kalasim/TickTransform.kt#L10)

data class TickTime(val value: Double) {
    override fun toString(): String {
        return value.toString()
    }
}

When trying to visualize a data-frame Map<*, *> including a column with values of type TickTime it fails with

The problem is found in one of the loaded libraries: check library renderers
org.jetbrains.kotlinx.jupyter.ReplEvalRuntimeException: Can't standardize the value "2.54" of type org.kalasim.TickTime as a string, number or date-time.
org.jetbrains.kotlinx.jupyter.exceptions.ReplLibraryException: The problem is found in one of the loaded libraries: check library renderers
    at org.jetbrains.kotlinx.jupyter.exceptions.ReplLibraryExceptionKt.rethrowAsLibraryException(ReplLibraryException.kt:28)
    at org.jetbrains.kotlinx.jupyter.codegen.RenderersProcessorImpl.renderResult(RenderersProcessorImpl.kt:23)
    at org.jetbrains.kotlinx.jupyter.ReplForJupyterImpl$evalEx$1$rendered$1$1.invoke(repl.kt:432)
    at org.jetbrains.kotlinx.jupyter.config.LoggingKt.catchAll(logging.kt:41)
    at org.jetbrains.kotlinx.jupyter.config.LoggingKt.catchAll$default(logging.kt:40)

It's not clear to the user why it did not succeed to parse the stringified value into a number.

alshan commented 2 years ago

Does ggplot2 convert strings to numbers?

holgerbrandl commented 2 years ago

Very good point. No it does not for sure.