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