JetBrains / lets-plot-kotlin

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

Shouldn't `scaleDateTime()` work by default with Instant? #174

Closed AndreiKingsley closed 1 year ago

AndreiKingsley commented 1 year ago

We can use Instant as the data type, but we need to add scaleDatetime() to format the axis correctly. Why don't we do this automatically when we have Instant as a data type? Including in the case of yMin, middle etc. It's also a bit strange that the public api lacks something like scaleColorDatetime, but we can implement it with

Scale(Aes.COLOR, otherOptions = Options(
        mapOf(
            Option.Scale.DATE_TIME to true
        ))
)
IKupriyanov-HORIS commented 1 year ago

Hi! Sorry, the issue description is kinda unclear. May I clarify it? Are you talking about the plot legend that uses numbers as labels instead of formatted date/time?

Like in this example:

%use lets-plot
import java.time.Instant.parse

val instants = listOf(
    "2021-01-01T00:00:00Z",
    "2021-02-23T00:00:00Z",
    "2021-04-03T00:00:00Z",
    "2021-05-04T00:00:00Z",
    "2021-10-05T00:00:00Z"
).map(::parse)

val daysData = mapOf<String, Any>(
    "days" to instants,
    "val" to (1..instants.size)
)

val p = letsPlot(daysData) + geomBar() { x = "days"; color = "days" }
p

Actual result: image

And you expected this? image

Am I correct?

AndreiKingsley commented 1 year ago

Yes!

AndreiKingsley commented 1 year ago

Also i want axis formatting when i use, for example, error bar: `val instants = listOf( "2021-01-01T00:00:00Z", "2021-01-01T00:04:00Z", "2021-01-01T00:00:00Z", "2021-01-01T00:00:00Z", "2021-01-01T00:00:00Z", ).map(::parse) val instants2 = listOf( "2021-01-01T00:05:00Z", "2021-01-01T00:05:00Z", "2021-01-01T00:05:00Z", "2021-01-01T00:05:00Z", "2021-01-01T00:05:00Z", ).map(::parse) val daysData = mapOf<String, Any>( "t1" to instants, "t2" to instants2, "val" to (1..instants.size) )

val p = letsPlot(daysData) + geomErrorBar(stat = Stat.identity) { x = "val"; ymin = "t1" ymax = "t2" } p` gives

image

but I expect y date-time formatting

alshan commented 1 year ago

Fixed in LPK v4.4.0