-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathTestingGeomLayersBuilder.kt
61 lines (54 loc) · 2.33 KB
/
TestingGeomLayersBuilder.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2023. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package demoAndTestShared
import org.jetbrains.letsPlot.core.plot.builder.GeomLayer
import org.jetbrains.letsPlot.core.spec.Option
import org.jetbrains.letsPlot.core.spec.config.PlotConfig
import org.jetbrains.letsPlot.core.spec.front.PlotConfigFrontend
import org.jetbrains.letsPlot.core.spec.front.PlotConfigFrontendUtil
import org.jetbrains.letsPlot.core.util.MonolithicCommon
object TestingGeomLayersBuilder {
fun createMultiTileGeomLayers(plotSpec: MutableMap<String, Any>): List<List<GeomLayer>> {
val transformed = MonolithicCommon.processRawSpecs(plotSpec)
require(!PlotConfig.isFailure(transformed)) { PlotConfig.getErrorMessage(transformed) }
val config = PlotConfigFrontend.create(transformed) {}
return PlotConfigFrontendUtil.createPlotGeomTiles(config).coreLayersByTile()
}
fun createSingleTileGeomLayers(plotSpec: MutableMap<String, Any>): List<GeomLayer> {
val coreLayersByTile = createMultiTileGeomLayers(plotSpec)
return coreLayersByTile.single()
}
fun getSingleGeomLayer(plotSpec: MutableMap<String, Any>): GeomLayer {
val geomLayers = createSingleTileGeomLayers(plotSpec)
require(geomLayers.isNotEmpty())
return geomLayers.single()
}
fun getSingleGeomLayer(spec: String): GeomLayer = getSingleGeomLayer(parsePlotSpec(spec))
fun buildGeomLayer(
geom: String,
data: Map<String, Any?>,
mapping: Map<String, Any>,
tooltips: Any? = null,
scales: List<Map<String, Any?>> = emptyList(),
orientationY: Boolean = false
): GeomLayer {
val plotOpts = mutableMapOf(
Option.Meta.KIND to Option.Meta.Kind.PLOT,
Option.PlotBase.DATA to data,
Option.PlotBase.MAPPING to mapping,
Option.Plot.LAYERS to listOf(
mutableMapOf<String, Any?>().apply {
put(Option.Layer.GEOM, geom)
put(Option.Layer.TOOLTIPS, tooltips)
if (orientationY) {
put(Option.Layer.ORIENTATION, "Y")
}
}
),
Option.Plot.SCALES to scales,
)
return getSingleGeomLayer(plotOpts)
}
}