Skip to content

Commit aa19603

Browse files
merge datetime
2 parents 4483697 + 44d0033 commit aa19603

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

ggdsl-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/ggdsl/letsplot/translator/LayerWrapper.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
package org.jetbrains.kotlinx.ggdsl.letsplot.translator
66

77
import org.jetbrains.kotlinx.ggdsl.ir.Layer
8+
import org.jetbrains.kotlinx.ggdsl.letsplot.feature.Reversed
89
import org.jetbrains.kotlinx.ggdsl.letsplot.internal.GROUP
910
import org.jetbrains.kotlinx.ggdsl.letsplot.internal.MERGED_GROUPS
10-
import org.jetbrains.kotlinx.ggdsl.letsplot.feature.Reversed
1111
import org.jetbrains.kotlinx.ggdsl.letsplot.position.Position
1212
import org.jetbrains.kotlinx.ggdsl.letsplot.tooltips.feature.LayerTooltips
1313
import org.jetbrains.letsPlot.Stat
@@ -37,4 +37,3 @@ internal class LayerWrapper internal constructor(private val layer: Layer, addGr
3737
}.toMap()
3838
)
3939
}
40-

ggdsl-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/ggdsl/letsplot/translator/data.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.jetbrains.kotlinx.ggdsl.ir.data.NamedDataInterface
77
import org.jetbrains.kotlinx.ggdsl.ir.data.TableData
88
import org.jetbrains.kotlinx.ggdsl.letsplot.internal.MERGED_GROUPS
99
import kotlin.reflect.typeOf
10-
import kotlin.time.Duration.Companion.nanoseconds
1110

1211
internal fun LazyGroupedDataInterface.mergedKeys(): List<String> = buildList {
1312
val map = this@mergedKeys.origin.nameToValues
@@ -33,13 +32,7 @@ internal object DateTimeMaster {
3332
(dateTime as? LocalDateTime)?.toInstant(TimeZone.currentSystemDefault())
3433
}
3534
typeOf<LocalTime>(), typeOf<LocalTime?>() -> values.map { time ->
36-
(time as? LocalTime)?.let {
37-
Clock.System.now().toLocalDateTime(
38-
TimeZone.currentSystemDefault()
39-
).date.atStartOfDayIn(TimeZone.currentSystemDefault()).plus(
40-
it.toNanosecondOfDay().nanoseconds
41-
)
42-
}
35+
(time as? LocalTime)?.toMillisecondOfDay()
4336
}
4437
else -> values
4538
})

ggdsl-lets-plot/src/main/kotlin/org/jetbrains/kotlinx/ggdsl/letsplot/translator/scaleWrap.kt

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jetbrains.datalore.plot.base.Aes
44
import kotlinx.datetime.Instant
55
import kotlinx.datetime.LocalDate
66
import kotlinx.datetime.LocalDateTime
7+
import kotlinx.datetime.LocalTime
78
import org.jetbrains.kotlinx.ggdsl.ir.aes.AesName
89
import org.jetbrains.kotlinx.ggdsl.ir.scale.*
910
import org.jetbrains.kotlinx.ggdsl.letsplot.internal.*
@@ -24,6 +25,9 @@ internal val dateTimeTypes = setOf(
2425
)
2526

2627
internal fun List<*>?.wrap() = this?.filterNotNull()
28+
internal val timeTypes = setOf(
29+
typeOf<LocalTime>(), typeOf<LocalTime?>(),
30+
)
2731

2832
/**
2933
* TODO datetime
@@ -103,7 +107,23 @@ internal fun Scale.wrap(
103107

104108
is PositionalContinuousScale<*> -> {
105109
when (aesName) {
106-
X -> if (domainType !in dateTimeTypes) {
110+
X -> if (domainType in dateTimeTypes) {
111+
scaleXDateTime(
112+
limits = limits.wrap(),
113+
name = name,
114+
breaks = breaks?.values?.filterNotNull(), // todo
115+
labels = labels,
116+
format = format
117+
)
118+
} else if (domainType in timeTypes) {
119+
scaleXTime(
120+
limits = limits.wrap(),
121+
name = name,
122+
breaks = breaks?.values?.filterNotNull(), // todo
123+
labels = labels,
124+
// format = format
125+
)
126+
} else {
107127
scaleXContinuous(
108128
limits = limits.wrap(),
109129
name = name,
@@ -113,35 +133,34 @@ internal fun Scale.wrap(
113133
format = format,
114134
naValue = naValue as? Number
115135
)
116-
} else {
117-
scaleXDateTime(
136+
}
137+
138+
Y -> if (domainType in dateTimeTypes) {
139+
scaleYDateTime(
118140
limits = limits.wrap(),
119141
name = name,
120142
breaks = breaks?.values.wrap(),
121143
labels = labels,
122144
format = format,
123145
naValue = naValue
124146
)
125-
}
126-
127-
Y -> if (domainType !in dateTimeTypes) {
128-
scaleYContinuous(
147+
} else if (domainType in timeTypes) {
148+
scaleYTime(
129149
limits = limits.wrap(),
130150
name = name,
131-
breaks = breaks?.values?.map { it as Number }, // TODO() }
151+
breaks = breaks?.values?.filterNotNull(), // todo
132152
labels = labels,
133-
trans = (transform as? Transformation)?.name,
134-
format = format,
135-
naValue = naValue as? Number
153+
// format = format
136154
)
137155
} else {
138-
scaleYDateTime(
156+
scaleYContinuous(
139157
limits = limits.wrap(),
140158
name = name,
141-
breaks = breaks?.values.wrap(),
159+
breaks = breaks?.values?.map { it as Number }, // TODO() }
142160
labels = labels,
161+
trans = (transform as? Transformation)?.name,
143162
format = format,
144-
naValue = naValue
163+
naValue = naValue as? Number
145164
)
146165
}
147166

@@ -263,6 +282,7 @@ internal fun Scale.wrap(
263282
}
264283
}
265284
// TODO
285+
266286
ALPHA -> if (rangeValues != null) { scaleAlphaManual(
267287
limits = domainCategories?.values.wrap(),
268288
values = rangeValues!!.values.map { it as Double },
@@ -640,6 +660,27 @@ internal fun Scale.wrap(
640660
format = format,
641661
)
642662

663+
else -> TODO()
664+
}
665+
} else if (domainType in timeTypes) {
666+
return when (aesName) {
667+
X -> scaleXTime(
668+
// limits = limits.toLP(),
669+
name = name,
670+
breaks = breaks?.values?.map { it as Number }, // TODO() }
671+
labels = labels,
672+
// trans = (transform as? Transformation)?.name,
673+
// format = format
674+
)
675+
676+
Y -> scaleYTime(
677+
//limits = categories,
678+
name = name,
679+
breaks = breaks?.values.wrap(),
680+
labels = labels,
681+
// format = format
682+
)
683+
643684
else -> TODO()
644685
}
645686
}

0 commit comments

Comments
 (0)