From bc15d9241b4853201407dd1bd7e2827d7bf57cba Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 26 Feb 2021 13:03:40 +0300 Subject: [PATCH] Refactor VisionForge global --- build.gradle.kts | 1 - .../VisionForgePlayGroundForJupyter.kt | 16 ++++---- .../src/jsMain/kotlin/playgroundMain.kt | 5 +-- .../src/jvmMain/kotlin/gdmlCubes.kt | 12 +++--- .../src/jvmMain/kotlin/plotlyVision.kt | 16 ++++---- .../src/jvmMain/kotlin/randomSpheres.kt | 10 ++--- .../src/jvmMain/kotlin/serverExtensions.kt | 6 +-- .../src/jvmMain/kotlin/simpleCube.kt | 12 +++--- settings.gradle.kts | 2 - .../hep/dataforge/vision/VisionForge.kt | 12 ++++-- .../hep/dataforge/vision/VisionGroupBase.kt | 7 ++-- .../vision/html/HtmlVisionFragment.kt | 4 +- .../kotlin/hep/dataforge/vision/html/Page.kt | 7 ++-- .../vision/{client => }/VisionClient.kt | 5 +-- .../hep/dataforge/vision/VisionForge.kt | 38 ------------------- .../vision/{client => }/elementOutput.kt | 3 +- .../hep/dataforge/vision/visionForgeJs.kt | 37 ++++++++++++++++++ .../hep/dataforge/vision/VisionForge.kt | 8 ---- .../hep/dataforge/vision/visionForgeJvm.kt | 13 +++++++ .../{plotlyCommon.kt => PlotlyPlugin.kt} | 14 ++++++- .../hep/dataforge/vision/plotly/plotlyJs.kt | 15 ++------ .../hep/dataforge/vision/plotly/plotlyJvm.kt | 6 +-- .../dataforge/vision/solid/SolidManager.kt | 5 ++- .../vision/solid/three/ThreePlugin.kt | 12 ++---- .../dataforge/vision/three/server/jsMain.kt | 4 +- .../vision/three/server/serverExtensions.kt | 4 +- 26 files changed, 136 insertions(+), 138 deletions(-) rename visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/{client => }/VisionClient.kt (98%) delete mode 100644 visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionForge.kt rename visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/{client => }/elementOutput.kt (92%) create mode 100644 visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/visionForgeJs.kt delete mode 100644 visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/VisionForge.kt create mode 100644 visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/visionForgeJvm.kt rename visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/{plotlyCommon.kt => PlotlyPlugin.kt} (51%) diff --git a/build.gradle.kts b/build.gradle.kts index 5a0f3400..949d00a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,6 @@ val fxVersion by extra("14") allprojects { repositories { - mavenLocal() mavenCentral() jcenter() maven("https://kotlin.bintray.com/kotlin-js-wrappers") diff --git a/demo/jupyter-playground/src/main/kotlin/hep/dataforge/playground/VisionForgePlayGroundForJupyter.kt b/demo/jupyter-playground/src/main/kotlin/hep/dataforge/playground/VisionForgePlayGroundForJupyter.kt index c1228ce1..4ae7cf4b 100644 --- a/demo/jupyter-playground/src/main/kotlin/hep/dataforge/playground/VisionForgePlayGroundForJupyter.kt +++ b/demo/jupyter-playground/src/main/kotlin/hep/dataforge/playground/VisionForgePlayGroundForJupyter.kt @@ -3,15 +3,14 @@ package hep.dataforge.playground import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.Vision import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.html.HtmlVisionFragment import hep.dataforge.vision.html.Page import hep.dataforge.vision.html.embedVisionFragment import hep.dataforge.vision.html.fragment import hep.dataforge.vision.plotly.toVision -import hep.dataforge.vision.plotly.withPlotly -import hep.dataforge.vision.solid.withSolids +import hep.dataforge.vision.plotly.usePlotly +import hep.dataforge.vision.solid.useSolids import hep.dataforge.vision.visionManager import kotlinx.html.div import kotlinx.html.id @@ -44,7 +43,7 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() { } script { type = "text/javascript" - unsafe { +"renderVisionsAt(\"$id\");" } + unsafe { +"VisionForge.renderVisionsAt(\"$id\");" } } } @@ -52,7 +51,8 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() { resource(jsResource) onLoaded { - VisionForge.withPlotly().withSolids() + VisionForge.useSolids() + VisionForge.usePlotly() } import( @@ -66,14 +66,14 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() { import("hep.dataforge.vision.VisionForge") render { gdmlModel -> - val fragment = VisionManager.fragment { + val fragment = VisionForge.fragment { vision(gdmlModel.toVision()) } HTML(produceHtmlVisionString(fragment)) } render { vision -> - val fragment = VisionManager.fragment { + val fragment = VisionForge.fragment { vision(vision) } @@ -81,7 +81,7 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() { } render { plot -> - val fragment = VisionManager.fragment { + val fragment = VisionForge.fragment { vision(plot.toVision()) } diff --git a/demo/playground/src/jsMain/kotlin/playgroundMain.kt b/demo/playground/src/jsMain/kotlin/playgroundMain.kt index de1b2fb4..6c3bb939 100644 --- a/demo/playground/src/jsMain/kotlin/playgroundMain.kt +++ b/demo/playground/src/jsMain/kotlin/playgroundMain.kt @@ -1,9 +1,8 @@ -//import hep.dataforge.vision.plotly.withPlotly +import hep.dataforge.vision.VisionForge import hep.dataforge.vision.plotly.usePlotly -import hep.dataforge.vision.renderVisionsInWindow import hep.dataforge.vision.solid.three.useThreeJs -fun main() { +fun main(): Unit = VisionForge.run{ usePlotly() useThreeJs() renderVisionsInWindow() diff --git a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt index 29dff01a..2caefaaa 100644 --- a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt +++ b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt @@ -2,11 +2,11 @@ package hep.dataforge.vision.examples import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.fragment -import hep.dataforge.vision.solid.withSolids +import hep.dataforge.vision.invoke +import hep.dataforge.vision.solid.useSolids import space.kscience.gdml.* internal val cubes = Gdml { @@ -60,12 +60,12 @@ internal val cubes = Gdml { } @DFExperimental -fun main() { - val content = VisionManager.fragment { +fun main() = VisionForge { + val content = VisionForge.fragment { vision("canvas") { cubes.toVision() } } - - VisionForge.withSolids().makeVisionFile(content, resourceLocation = ResourceLocation.SYSTEM) + useSolids() + makeVisionFile(content, resourceLocation = ResourceLocation.SYSTEM) } \ No newline at end of file diff --git a/demo/playground/src/jvmMain/kotlin/plotlyVision.kt b/demo/playground/src/jvmMain/kotlin/plotlyVision.kt index 93f79ace..0058232d 100644 --- a/demo/playground/src/jvmMain/kotlin/plotlyVision.kt +++ b/demo/playground/src/jvmMain/kotlin/plotlyVision.kt @@ -2,25 +2,25 @@ package hep.dataforge.vision.examples import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.fragment +import hep.dataforge.vision.invoke import hep.dataforge.vision.plotly.plotly -import hep.dataforge.vision.plotly.withPlotly +import hep.dataforge.vision.plotly.usePlotly import kscience.plotly.scatter @DFExperimental -fun main() { - val fragment = VisionManager.fragment { +fun main() = VisionForge { + val fragment = fragment { vision { plotly { scatter { - x(1,2,3) - y(5,8,7) + x(1, 2, 3) + y(5, 8, 7) } } } } - - VisionForge.withPlotly().makeVisionFile(fragment, resourceLocation = ResourceLocation.SYSTEM) + usePlotly() + makeVisionFile(fragment, resourceLocation = ResourceLocation.SYSTEM) } \ No newline at end of file diff --git a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt index 3e971e24..bed0ebbf 100644 --- a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt +++ b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt @@ -2,19 +2,19 @@ package hep.dataforge.vision.examples import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.fragment +import hep.dataforge.vision.invoke import hep.dataforge.vision.solid.* import kotlinx.html.h1 import java.nio.file.Paths import kotlin.random.Random @OptIn(DFExperimental::class) -fun main() { +fun main() = VisionForge.invoke { val random = Random(112233) - val fragment = VisionManager.fragment { + val fragment = fragment { h1 { +"Happy new year!" } vision { solid { @@ -33,8 +33,8 @@ fun main() { } } } - - VisionForge.withSolids().makeVisionFile( + useSolids() + makeVisionFile( fragment, Paths.get("randomSpheres.html"), resourceLocation = ResourceLocation.EMBED diff --git a/demo/playground/src/jvmMain/kotlin/serverExtensions.kt b/demo/playground/src/jvmMain/kotlin/serverExtensions.kt index eb26d5e4..fe77564d 100644 --- a/demo/playground/src/jvmMain/kotlin/serverExtensions.kt +++ b/demo/playground/src/jvmMain/kotlin/serverExtensions.kt @@ -1,8 +1,8 @@ package hep.dataforge.vision.examples -import hep.dataforge.context.Context import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionForge import hep.dataforge.vision.html.HtmlVisionFragment import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.page @@ -19,7 +19,7 @@ public fun VisionServer.usePlayground(): Unit { } @DFExperimental -public fun Context.makeVisionFile( +public fun VisionForge.makeVisionFile( content: HtmlVisionFragment, path: Path? = null, title: String = "VisionForge page", @@ -33,7 +33,7 @@ public fun Context.makeVisionFile( } @DFExperimental -public fun Context.makeVisionFile( +public fun VisionForge.makeVisionFile( vision: Vision, path: Path? = null, title: String = "VisionForge page", diff --git a/demo/playground/src/jvmMain/kotlin/simpleCube.kt b/demo/playground/src/jvmMain/kotlin/simpleCube.kt index 159e908b..e8dc6cf5 100644 --- a/demo/playground/src/jvmMain/kotlin/simpleCube.kt +++ b/demo/playground/src/jvmMain/kotlin/simpleCube.kt @@ -2,22 +2,22 @@ package hep.dataforge.vision.examples import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.fragment +import hep.dataforge.vision.invoke import hep.dataforge.vision.solid.box import hep.dataforge.vision.solid.solid -import hep.dataforge.vision.solid.withSolids +import hep.dataforge.vision.solid.useSolids @DFExperimental -fun main() { - val content = VisionManager.fragment { +fun main() = VisionForge.invoke { + val content = fragment { vision("canvas") { solid { box(100, 100, 100) } } } - - VisionForge.withSolids().makeVisionFile(content, resourceLocation = ResourceLocation.SYSTEM) + useSolids() + makeVisionFile(content, resourceLocation = ResourceLocation.SYSTEM) } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 68836190..0df27ede 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,10 +3,8 @@ pluginManagement { val toolsVersion = "0.8.3" repositories { - mavenLocal() maven("https://repo.kotlin.link") mavenCentral() - jcenter() gradlePluginPortal() } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionForge.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionForge.kt index b9c98d93..ae42bf02 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionForge.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionForge.kt @@ -1,8 +1,12 @@ package hep.dataforge.vision import hep.dataforge.context.Context +import hep.dataforge.context.PluginManager -/** - * A drop-in replacement for [Global] for VisionForge activities - */ -public expect val VisionForge: Context \ No newline at end of file +public expect object VisionForge + +public expect val VisionForge.context: Context + +public val VisionForge.plugins: PluginManager get() = context.plugins + +public val VisionForge.visionManager: VisionManager get() = plugins.fetch(VisionManager) \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt index 48ff4982..e26cc212 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt @@ -26,8 +26,9 @@ public open class VisionGroupBase( override val children: Map get() = childrenInternal init { - childrenInternal.values.forEach { - it.parent = this + childrenInternal.forEach { (token, child) -> + if (child.parent != null && child.parent != this) error("Can't reassign existing parent for child $token") + child.parent = this } } @@ -78,7 +79,7 @@ public open class VisionGroupBase( childrenInternal[token] = child } child.parent !== this -> { - error("Can't reassign existing parent for $child") + error("Can't reassign existing parent for child $token") } } if (before != child) { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlVisionFragment.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlVisionFragment.kt index debfe28e..31239c71 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlVisionFragment.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlVisionFragment.kt @@ -1,7 +1,7 @@ package hep.dataforge.vision.html import hep.dataforge.misc.DFExperimental -import hep.dataforge.vision.VisionManager +import hep.dataforge.vision.VisionForge import kotlinx.html.FlowContent import kotlinx.html.TagConsumer @@ -18,4 +18,4 @@ public fun FlowContent.fragment(fragment: HtmlFragment) { public typealias HtmlVisionFragment = VisionTagConsumer<*>.() -> Unit @DFExperimental -public fun VisionManager.Companion.fragment(content: HtmlVisionFragment): VisionTagConsumer<*>.() -> Unit = content \ No newline at end of file +public fun VisionForge.fragment(content: HtmlVisionFragment): VisionTagConsumer<*>.() -> Unit = content \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/Page.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/Page.kt index c9feb965..86ce5140 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/Page.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/Page.kt @@ -2,9 +2,10 @@ package hep.dataforge.vision.html import hep.dataforge.context.Context import hep.dataforge.misc.DFExperimental +import hep.dataforge.vision.VisionForge +import hep.dataforge.vision.context import hep.dataforge.vision.visionManager import kotlinx.html.* -import kotlinx.html.stream.createHTML public data class Page( public val context: Context, @@ -30,8 +31,8 @@ public data class Page( @DFExperimental -public fun Context.page( +public fun VisionForge.page( title: String, content: HtmlVisionFragment, vararg headers: Pair, -): Page = Page(this, title, mapOf(*headers), content) \ No newline at end of file +): Page = Page(context, title, mapOf(*headers), content) \ No newline at end of file diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionClient.kt similarity index 98% rename from visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt rename to visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionClient.kt index f6799fc0..2933f01d 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionClient.kt @@ -1,11 +1,8 @@ -package hep.dataforge.vision.client +package hep.dataforge.vision import hep.dataforge.context.* import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaSerializer -import hep.dataforge.vision.Vision -import hep.dataforge.vision.VisionChange -import hep.dataforge.vision.VisionManager import hep.dataforge.vision.html.VisionTagConsumer import hep.dataforge.vision.html.VisionTagConsumer.Companion.OUTPUT_CONNECT_ATTRIBUTE import hep.dataforge.vision.html.VisionTagConsumer.Companion.OUTPUT_ENDPOINT_ATTRIBUTE diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionForge.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionForge.kt deleted file mode 100644 index 9f478b34..00000000 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/VisionForge.kt +++ /dev/null @@ -1,38 +0,0 @@ -package hep.dataforge.vision - -import hep.dataforge.context.Context -import hep.dataforge.context.Global -import hep.dataforge.vision.client.VisionClient -import hep.dataforge.vision.client.renderAllVisions -import hep.dataforge.vision.client.renderAllVisionsAt -import kotlinx.browser.document -import kotlinx.browser.window - -public actual val VisionForge: Context = Global.context("VisionForge").apply { - plugins.fetch(VisionManager) - plugins.fetch(VisionClient) -} - - -/** - * Render all visions in this [window] using current global state of [VisionForge] - */ -@JsExport -public fun renderVisionsInWindow() { - window.onload = { - VisionForge.plugins[VisionClient]?.renderAllVisions() - } -} - -/** - * Render all visions in an element with a given [id] - */ -@JsExport -public fun renderVisionsAt(id: String) { - val element = document.getElementById(id) - if (element != null) { - VisionForge.plugins[VisionClient]?.renderAllVisionsAt(element) - } else { - console.warn("Element with id $id not found") - } -} \ No newline at end of file diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/elementOutput.kt similarity index 92% rename from visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt rename to visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/elementOutput.kt index bd2e2554..809f60ef 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/elementOutput.kt @@ -1,8 +1,7 @@ -package hep.dataforge.vision.client +package hep.dataforge.vision import hep.dataforge.meta.Meta import hep.dataforge.misc.Type -import hep.dataforge.vision.Vision import org.w3c.dom.Element @Type(ElementVisionRenderer.TYPE) diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/visionForgeJs.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/visionForgeJs.kt new file mode 100644 index 00000000..119bfe50 --- /dev/null +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/visionForgeJs.kt @@ -0,0 +1,37 @@ +package hep.dataforge.vision + +import hep.dataforge.context.Context +import kotlinx.browser.document +import kotlinx.browser.window + +@JsExport +public actual object VisionForge{ + /** + * Render all visions in this [window] using current global state of [VisionForge] + */ + public fun renderVisionsInWindow() { + window.onload = { + visionClient.renderAllVisions() + } + } + + /** + * Render all visions in an element with a given [id] + */ + public fun renderVisionsAt(id: String) { + val element = document.getElementById(id) + if (element != null) { + visionClient.renderAllVisionsAt(element) + } else { + console.warn("Element with id $id not found") + } + } +} + +private val visionForgeContext = Context("VisionForge"){ + plugin(VisionClient) +} + +public actual val VisionForge.context: Context get() = visionForgeContext + +public val VisionForge.visionClient: VisionClient get() = plugins.fetch(VisionClient) \ No newline at end of file diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/VisionForge.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/VisionForge.kt deleted file mode 100644 index 67b656b8..00000000 --- a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/VisionForge.kt +++ /dev/null @@ -1,8 +0,0 @@ -package hep.dataforge.vision - -import hep.dataforge.context.Context -import hep.dataforge.context.Global - -public actual val VisionForge: Context = Global.context("VisionForge").apply{ - plugins.fetch(VisionManager) -} \ No newline at end of file diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/visionForgeJvm.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/visionForgeJvm.kt new file mode 100644 index 00000000..42c1d67b --- /dev/null +++ b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/visionForgeJvm.kt @@ -0,0 +1,13 @@ +package hep.dataforge.vision + +import hep.dataforge.context.Context +import hep.dataforge.misc.DFExperimental + +public actual object VisionForge + +private val visionForgeContext = Context("VisionForge") + +public actual val VisionForge.context: Context get() = visionForgeContext + +@DFExperimental +public operator fun VisionForge.invoke(block: VisionForge.() -> Unit): Unit = run(block) \ No newline at end of file diff --git a/visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/plotlyCommon.kt b/visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/PlotlyPlugin.kt similarity index 51% rename from visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/plotlyCommon.kt rename to visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/PlotlyPlugin.kt index f7a95f1f..cba38c85 100644 --- a/visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/plotlyCommon.kt +++ b/visionforge-plotly/src/commonMain/kotlin/hep/dataforge/vision/plotly/PlotlyPlugin.kt @@ -1,15 +1,27 @@ package hep.dataforge.vision.plotly +import hep.dataforge.context.PluginFactory import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionForge import hep.dataforge.vision.VisionPlugin +import hep.dataforge.vision.plugins import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.polymorphic import kotlinx.serialization.modules.subclass -public expect class PlotlyPlugin : VisionPlugin +public expect class PlotlyPlugin : VisionPlugin{ + public companion object: PluginFactory +} internal val plotlySerializersModule = SerializersModule { polymorphic(Vision::class) { subclass(VisionOfPlotly.serializer()) } +} + +/** + * Ensure that [PlotlyPlugin] is loaded in the global [VisionForge] context + */ +public fun VisionForge.usePlotly() { + plugins.fetch(PlotlyPlugin) } \ No newline at end of file diff --git a/visionforge-plotly/src/jsMain/kotlin/hep/dataforge/vision/plotly/plotlyJs.kt b/visionforge-plotly/src/jsMain/kotlin/hep/dataforge/vision/plotly/plotlyJs.kt index 27f13860..790844b6 100644 --- a/visionforge-plotly/src/jsMain/kotlin/hep/dataforge/vision/plotly/plotlyJs.kt +++ b/visionforge-plotly/src/jsMain/kotlin/hep/dataforge/vision/plotly/plotlyJs.kt @@ -6,11 +6,10 @@ import hep.dataforge.context.PluginTag import hep.dataforge.meta.Meta import hep.dataforge.names.Name import hep.dataforge.names.asName +import hep.dataforge.vision.ElementVisionRenderer import hep.dataforge.vision.Vision -import hep.dataforge.vision.VisionForge +import hep.dataforge.vision.VisionClient import hep.dataforge.vision.VisionPlugin -import hep.dataforge.vision.client.ElementVisionRenderer -import hep.dataforge.vision.client.VisionClient import kotlinx.serialization.modules.SerializersModule import kscience.plotly.PlotlyConfig import kscience.plotly.plot @@ -42,17 +41,9 @@ public actual class PlotlyPlugin : VisionPlugin(), ElementVisionRenderer { } } - public companion object : PluginFactory { + public actual companion object : PluginFactory { override val tag: PluginTag = PluginTag("vision.plotly", PluginTag.DATAFORGE_GROUP) override val type: KClass = PlotlyPlugin::class override fun invoke(meta: Meta, context: Context): PlotlyPlugin = PlotlyPlugin() } -} - -/** - * Ensure that [PlotlyPlugin] is loaded in the global [VisionForge] context - */ -@JsExport -public fun usePlotly() { - VisionForge.plugins.fetch(PlotlyPlugin) } \ No newline at end of file diff --git a/visionforge-plotly/src/jvmMain/kotlin/hep/dataforge/vision/plotly/plotlyJvm.kt b/visionforge-plotly/src/jvmMain/kotlin/hep/dataforge/vision/plotly/plotlyJvm.kt index e0a2ec5b..29687288 100644 --- a/visionforge-plotly/src/jvmMain/kotlin/hep/dataforge/vision/plotly/plotlyJvm.kt +++ b/visionforge-plotly/src/jvmMain/kotlin/hep/dataforge/vision/plotly/plotlyJvm.kt @@ -15,13 +15,9 @@ public actual class PlotlyPlugin : VisionPlugin(), Plugin { override val visionSerializersModule: SerializersModule get() = plotlySerializersModule - public companion object : PluginFactory { + public actual companion object : PluginFactory { override val tag: PluginTag = PluginTag("vision.plotly", PluginTag.DATAFORGE_GROUP) override val type: KClass = PlotlyPlugin::class override fun invoke(meta: Meta, context: Context): PlotlyPlugin = PlotlyPlugin() } -} - -public fun Context.withPlotly(): Context = apply { - plugins.fetch(PlotlyPlugin) } \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt index 442af1a5..d716442b 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt @@ -70,6 +70,7 @@ public class SolidManager(meta: Meta) : VisionPlugin(meta) { @DFExperimental public inline fun VisionOutput.solid(block: SolidGroup.() -> Unit): SolidGroup = SolidGroup().apply(block) -public fun Context.withSolids(): Context = apply { +@DFExperimental +public fun VisionForge.useSolids(): Unit{ plugins.fetch(SolidManager) -} \ No newline at end of file +} diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt index b00a6cac..6baab0ba 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt @@ -3,13 +3,10 @@ package hep.dataforge.vision.solid.three import hep.dataforge.context.* import hep.dataforge.meta.Meta import hep.dataforge.names.* -import hep.dataforge.vision.Vision -import hep.dataforge.vision.VisionForge -import hep.dataforge.vision.client.ElementVisionRenderer -import hep.dataforge.vision.onPropertyChange +import hep.dataforge.vision.* import hep.dataforge.vision.solid.* import hep.dataforge.vision.solid.specifications.Canvas3DOptions -import hep.dataforge.vision.visible +import hep.dataforge.vision.solid.three.set import info.laht.threekt.core.Object3D import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.launchIn @@ -155,9 +152,8 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer { /** * Ensure that [ThreePlugin] is loaded in the global [VisionForge] context */ -@JsExport -public fun useThreeJs() { - VisionForge.plugins.fetch(ThreePlugin) +public fun VisionForge.useThreeJs() { + plugins.fetch(ThreePlugin) } public fun ThreePlugin.render( diff --git a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt index 069eb073..07bdcb4a 100644 --- a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt +++ b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt @@ -1,9 +1,9 @@ package hep.dataforge.vision.three.server -import hep.dataforge.vision.renderVisionsInWindow +import hep.dataforge.vision.VisionForge import hep.dataforge.vision.solid.three.useThreeJs -public fun main() { +public fun main(): Unit = VisionForge.run { useThreeJs() renderVisionsInWindow() } \ No newline at end of file diff --git a/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt b/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt index 80948c67..7d78e2ea 100644 --- a/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt +++ b/visionforge-threejs/visionforge-threejs-server/src/jvmMain/kotlin/hep/dataforge/vision/three/server/serverExtensions.kt @@ -1,7 +1,7 @@ package hep.dataforge.vision.three.server -import hep.dataforge.context.Context import hep.dataforge.misc.DFExperimental +import hep.dataforge.vision.VisionForge import hep.dataforge.vision.html.HtmlVisionFragment import hep.dataforge.vision.html.ResourceLocation import hep.dataforge.vision.html.page @@ -16,7 +16,7 @@ public fun VisionServer.useThreeJs(): Unit { } @DFExperimental -public fun Context.makeThreeJsFile( +public fun VisionForge.makeThreeJsFile( content: HtmlVisionFragment, path: Path? = null, title: String = "VisionForge page",