VisionForge window binding
This commit is contained in:
parent
8060933859
commit
1a5a207fb7
@ -20,7 +20,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "space.kscience"
|
||||
version = "0.2.0-dev-8"
|
||||
version = "0.2.0-dev-9"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
@ -43,7 +43,7 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() {
|
||||
}
|
||||
script {
|
||||
type = "text/javascript"
|
||||
unsafe { +"window.renderVisionsAt(\"$id\");" }
|
||||
unsafe { +"VisionForge.renderVisionsAt(\"$id\");" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ kotlin {
|
||||
val jvmMain by getting{
|
||||
dependencies {
|
||||
api(project(":visionforge-server"))
|
||||
api("ch.qos.logback:logback-classic:1.2.3")
|
||||
implementation("com.github.Ricky12Awesome:json-schema-serialization:0.6.6")
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import space.kscience.visionforge.solid.three.useThreeJs
|
||||
|
||||
@DFExperimental
|
||||
fun main(): Unit = VisionForge.run{
|
||||
console.info("Starting VisionForge context")
|
||||
usePlotly()
|
||||
useThreeJs()
|
||||
window.asDynamic()["VisionForge"] = VisionForge
|
||||
renderVisionsInWindow()
|
||||
window.asDynamic()["renderVisionsAt"] = ::renderVisionsAt
|
||||
window.asDynamic()["renderVisionsInWindow"] = ::renderVisionsInWindow
|
||||
}
|
@ -40,7 +40,7 @@ internal class GdmlForJupyter : JupyterIntegration() {
|
||||
}
|
||||
script {
|
||||
type = "text/javascript"
|
||||
unsafe { +"window.renderVisionsAt(\"$id\");" }
|
||||
unsafe { +"VisionForge.renderVisionsAt(\"$id\");" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,26 +2,36 @@ package space.kscience.visionforge
|
||||
|
||||
import kotlinx.browser.document
|
||||
import kotlinx.browser.window
|
||||
import org.w3c.dom.COMPLETE
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.DocumentReadyState
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
|
||||
|
||||
private fun whenDocumentLoaded(block: Document.() -> Unit): Unit {
|
||||
if(document.readyState == DocumentReadyState.COMPLETE){
|
||||
block(document)
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", { block(document) })
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
@DFExperimental
|
||||
public actual object VisionForge {
|
||||
/**
|
||||
* Render all visions in this [window] using current global state of [VisionForge]
|
||||
*/
|
||||
public fun renderVisionsInWindow() {
|
||||
window.onload = {
|
||||
visionClient.renderAllVisions()
|
||||
}
|
||||
public fun renderVisionsInWindow(): Unit = whenDocumentLoaded {
|
||||
visionClient.renderAllVisions()
|
||||
}
|
||||
|
||||
/**
|
||||
* Render all visions in an element with a given [id]
|
||||
*/
|
||||
public fun renderVisionsAt(id: String) {
|
||||
val element = document.getElementById(id)
|
||||
public fun renderVisionsAt(id: String): Unit = whenDocumentLoaded {
|
||||
val element = getElementById(id)
|
||||
if (element != null) {
|
||||
visionClient.renderAllVisionsAt(element)
|
||||
} else {
|
||||
|
@ -7,8 +7,8 @@ import space.kscience.visionforge.solid.three.useThreeJs
|
||||
|
||||
@DFExperimental
|
||||
public fun main(): Unit = VisionForge.run {
|
||||
console.info("Starting VisionForge context")
|
||||
useThreeJs()
|
||||
window.asDynamic()["VisionForge"] = VisionForge
|
||||
renderVisionsInWindow()
|
||||
window.asDynamic()["renderVisionsAt"] = ::renderVisionsAt
|
||||
window.asDynamic()["renderVisionsInWindow"] = ::renderVisionsInWindow
|
||||
}
|
Loading…
Reference in New Issue
Block a user