visionforge/visionforge-jupyter/visionforge-jupyter-common/src/jvmMain/kotlin/JupyterCommonIntegration.kt

91 lines
2.8 KiB
Kotlin
Raw Normal View History

2023-07-19 22:25:32 +03:00
package space.kscience.visionforge.jupyter
2021-03-07 16:19:43 +03:00
2023-07-19 22:25:32 +03:00
import kotlinx.html.*
2021-12-31 13:59:27 +03:00
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
2021-05-05 15:28:06 +03:00
import space.kscience.dataforge.context.Context
2021-03-07 16:19:43 +03:00
import space.kscience.dataforge.misc.DFExperimental
2021-02-23 21:47:18 +03:00
import space.kscience.gdml.Gdml
2021-03-07 16:19:43 +03:00
import space.kscience.plotly.Plot
import space.kscience.plotly.PlotlyPage
import space.kscience.plotly.StaticPlotlyRenderer
2023-07-19 22:25:32 +03:00
import space.kscience.tables.*
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.gdml.toVision
import space.kscience.visionforge.html.HtmlFragment
import space.kscience.visionforge.html.VisionPage
2023-07-19 22:25:32 +03:00
import space.kscience.visionforge.markup.MarkupPlugin
2021-05-05 15:28:06 +03:00
import space.kscience.visionforge.plotly.PlotlyPlugin
2021-06-05 22:31:16 +03:00
import space.kscience.visionforge.plotly.asVision
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.solid.Solids
2023-07-19 22:25:32 +03:00
import space.kscience.visionforge.tables.TableVisionPlugin
import space.kscience.visionforge.tables.toVision
2022-12-06 15:54:34 +03:00
import space.kscience.visionforge.visionManager
2021-02-23 21:47:18 +03:00
2023-07-19 22:25:32 +03:00
2021-02-24 18:26:15 +03:00
@DFExperimental
2023-07-19 22:25:32 +03:00
public class JupyterCommonIntegration : VisionForgeIntegration(CONTEXT.visionManager) {
2021-05-05 15:28:06 +03:00
2023-07-22 18:25:11 +03:00
override fun Builder.afterLoaded(vf: VisionForge) {
2023-07-19 22:25:32 +03:00
2021-12-31 13:59:27 +03:00
resources {
js("visionforge-common") {
2023-07-19 22:25:32 +03:00
classPath("js/visionforge-jupyter-common.js")
2021-12-31 13:59:27 +03:00
}
}
2021-02-23 21:47:18 +03:00
2021-02-24 22:48:17 +03:00
import(
"space.kscience.gdml.*",
2021-03-07 16:19:43 +03:00
"space.kscience.visionforge.solid.*",
2023-07-19 22:25:32 +03:00
"space.kscience.tables.*",
"space.kscience.dataforge.meta.*",
2023-07-20 09:13:24 +03:00
"space.kscience.plotly.*",
"space.kscience.plotly.models.*",
"space.kscience.visionforge.plotly.plotly"
2021-02-24 22:48:17 +03:00
)
2021-02-23 21:47:18 +03:00
render<Gdml> { gdmlModel ->
2023-07-22 18:25:11 +03:00
vf.produceHtml {
vision { gdmlModel.toVision() }
2021-02-24 18:26:15 +03:00
}
2021-02-23 21:47:18 +03:00
}
2023-07-19 22:25:32 +03:00
render<Table<*>> { table ->
2023-07-22 18:25:11 +03:00
vf.produceHtml {
2023-07-19 22:25:32 +03:00
vision { table.toVision() }
}
}
2021-02-23 21:47:18 +03:00
render<Plot> { plot ->
2023-07-22 18:25:11 +03:00
vf.produceHtml {
vision { plot.asVision() }
2021-02-23 21:47:18 +03:00
}
}
render<PlotlyPage> { plotlyPage ->
val headers = plotlyPage.headers.associate { plotlyFragment ->
plotlyFragment.hashCode().toString(16) to HtmlFragment {
plotlyFragment.visit(this)
}
}
VisionPage(visionManager, headers) {
div{
p { +"Plotly page renderer is not recommended in VisionForge, use `vf.page{}`" }
}
div {
plotlyPage.fragment.render.invoke(this, StaticPlotlyRenderer)
}
}
}
2021-02-23 21:47:18 +03:00
}
2023-07-19 22:25:32 +03:00
public companion object {
private val CONTEXT: Context = Context("Jupyter-common") {
plugin(Solids)
plugin(PlotlyPlugin)
plugin(TableVisionPlugin)
plugin(MarkupPlugin)
}
}
2021-02-23 21:47:18 +03:00
}