From 4f49901351ab0780f60c9479fd7d94bd09976333 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 5 Jun 2024 09:49:29 +0300 Subject: [PATCH] [WIP] gradual merge of Plotly --- build.gradle.kts | 1 - plotly/CHANGELOG.md | 3 +++ plotly/build.gradle.kts | 7 ++++++- plotly/examples/build.gradle.kts | 1 - plotly/examples/compose-demo/build.gradle.kts | 6 ------ plotly/examples/fx-demo/build.gradle.kts | 5 ----- plotly/examples/js-demo/build.gradle.kts | 4 ---- plotly/examples/native-demo/build.gradle.kts | 8 +------ plotly/plotlykt-core/build.gradle.kts | 11 +++++----- .../space/kscience/plotly/PlotlyPage.kt | 12 ++++++----- .../kotlin/space/kscience/plotly/html.kt | 21 ++++++------------- .../kscience/plotly/models/geo/Choropleth.kt | 0 .../plotly/models/geo/ChoroplethMapBox.kt | 0 .../space/kscience/plotly/models/geo/Geo.kt | 0 .../kscience/plotly/models/geo/GeoMapBox.kt | 0 .../plotly/models/geo/GeoProjection.kt | 0 .../kscience/plotly/models/geo/GeoTrace.kt | 0 .../kscience/plotly/models/geo/MapAxis.kt | 0 .../plotly/models/geo/MapCoordinates.kt | 0 .../kscience/plotly/models/geo/ScatterGeo.kt | 0 .../plotly/models/geo/ScatterMapBox.kt | 0 .../plotly/models/geo/json/GeoJson.kt | 0 .../space/kscience/plotly/bootstrapHeaders.kt | 3 ++- .../space/kscience/plotly/fileExport.kt | 3 ++- .../space/kscience/plotly/plotlyHeaders.kt | 17 ++++++++------- plotly/plotlykt-geo/README.md | 21 ------------------- plotly/plotlykt-geo/build.gradle.kts | 18 ---------------- .../kscience/plotly/PlotlyIntegration.kt | 11 +++++----- .../space/kscience/plotly/script/builder.kt | 7 ++++--- .../kscience/plotly/server/PlotlyServer.kt | 14 +++++++------ .../plotly/server/PlotlyServerIntegration.kt | 17 ++++++++------- settings.gradle.kts | 1 - .../visionforge-jupyter-common/README.md | 21 +++++++++++++++++++ .../kotlin/JupyterCommonIntegration.kt | 3 ++- 34 files changed, 92 insertions(+), 123 deletions(-) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/Choropleth.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/ChoroplethMapBox.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/Geo.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoMapBox.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoProjection.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoTrace.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapAxis.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapCoordinates.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterGeo.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterMapBox.kt (100%) rename plotly/{plotlykt-geo => plotlykt-core}/src/commonMain/kotlin/space/kscience/plotly/models/geo/json/GeoJson.kt (100%) delete mode 100644 plotly/plotlykt-geo/README.md delete mode 100644 plotly/plotlykt-geo/build.gradle.kts create mode 100644 visionforge-jupyter/visionforge-jupyter-common/README.md diff --git a/build.gradle.kts b/build.gradle.kts index 4f519d6a..9479292d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,6 @@ plugins { } val dataforgeVersion by extra("0.9.0") -val plotlyVersion by extra("2.29.0") allprojects { group = "space.kscience" diff --git a/plotly/CHANGELOG.md b/plotly/CHANGELOG.md index 4b24f56b..c7fb8999 100644 --- a/plotly/CHANGELOG.md +++ b/plotly/CHANGELOG.md @@ -9,10 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- Plotly moved on top of VisionForge (in the VisionForge repository) +- Geo module merged into core ### Deprecated ### Removed +- Own HtmlFragment replaced by VisionForge Html handling ### Fixed diff --git a/plotly/build.gradle.kts b/plotly/build.gradle.kts index 0825ced9..e3003cd6 100644 --- a/plotly/build.gradle.kts +++ b/plotly/build.gradle.kts @@ -1,6 +1,11 @@ +plugins{ + id("org.jetbrains.changelog") +} + + allprojects { group = "space.kscience" - version = "0.7.2" + version = "0.8.0-dev-1" } readme { diff --git a/plotly/examples/build.gradle.kts b/plotly/examples/build.gradle.kts index 2fa4f1b7..da8b0a37 100644 --- a/plotly/examples/build.gradle.kts +++ b/plotly/examples/build.gradle.kts @@ -10,7 +10,6 @@ repositories { dependencies { implementation(projects.plotly.plotlyktServer) implementation(projects.plotly.plotlyktJupyter) - implementation(projects.plotly.plotlyktGeo) implementation(projects.plotly.plotlyktScript) implementation(kotlin("script-runtime")) implementation("org.jetbrains.kotlinx:dataframe:0.13.1") diff --git a/plotly/examples/compose-demo/build.gradle.kts b/plotly/examples/compose-demo/build.gradle.kts index fe3133a9..71a38eb9 100644 --- a/plotly/examples/compose-demo/build.gradle.kts +++ b/plotly/examples/compose-demo/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { kotlin("multiplatform") alias(spclibs.plugins.compose.compiler) @@ -30,10 +28,6 @@ kotlin { } } -tasks.withType { - kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" -} - compose { desktop { application { diff --git a/plotly/examples/fx-demo/build.gradle.kts b/plotly/examples/fx-demo/build.gradle.kts index f316d883..c279a9d0 100644 --- a/plotly/examples/fx-demo/build.gradle.kts +++ b/plotly/examples/fx-demo/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { kotlin("jvm") application @@ -30,6 +28,3 @@ kotlin{ jvmToolchain(11) } -tasks.withType { - kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" -} diff --git a/plotly/examples/js-demo/build.gradle.kts b/plotly/examples/js-demo/build.gradle.kts index 11bf896c..4b21016e 100644 --- a/plotly/examples/js-demo/build.gradle.kts +++ b/plotly/examples/js-demo/build.gradle.kts @@ -20,8 +20,4 @@ kotlin { } } } -} - -tasks.withType { - kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" } \ No newline at end of file diff --git a/plotly/examples/native-demo/build.gradle.kts b/plotly/examples/native-demo/build.gradle.kts index bb03b243..c52fb55c 100644 --- a/plotly/examples/native-demo/build.gradle.kts +++ b/plotly/examples/native-demo/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { kotlin("multiplatform") } @@ -23,8 +21,4 @@ kotlin { } } } -} - -tasks.withType { - kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" -} +} \ No newline at end of file diff --git a/plotly/plotlykt-core/build.gradle.kts b/plotly/plotlykt-core/build.gradle.kts index fb953ab5..f98466d5 100644 --- a/plotly/plotlykt-core/build.gradle.kts +++ b/plotly/plotlykt-core/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } val dataforgeVersion: String by rootProject.extra -val plotlyVersion: String by rootProject.extra +val plotlyVersion by extra("2.29.0") kotlin{ @@ -16,10 +16,11 @@ kscience { native() wasm() - dependencies { - api("space.kscience:dataforge-meta:$dataforgeVersion") - api(spclibs.kotlinx.html) -// api("org.jetbrains.kotlinx:kotlinx-html:0.11.0") + commonMain { + api(projects.visionforgeCore) +// api("space.kscience:dataforge-meta:$dataforgeVersion") +// api(spclibs.kotlinx.html) + } jsMain{ diff --git a/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt index d21ca62d..01562f7d 100644 --- a/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt +++ b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt @@ -2,6 +2,8 @@ package space.kscience.plotly import kotlinx.html.* import kotlinx.html.stream.createHTML +import space.kscience.visionforge.html.HtmlFragment +import space.kscience.visionforge.html.appendTo /** * A custom HTML fragment including plotly container reference @@ -12,7 +14,7 @@ public class PlotlyFragment(public val render: FlowContent.(renderer: PlotlyRend * A complete page including headers and title */ public data class PlotlyPage( - val headers: Collection, + val headers: Collection, val fragment: PlotlyFragment, val title: String = "Plotly.kt", val renderer: PlotlyRenderer = StaticPlotlyRenderer @@ -23,7 +25,7 @@ public data class PlotlyPage( charset = "utf-8" } title(this@PlotlyPage.title) - headers.distinct().forEach { it.visit(consumer) } + headers.distinct().forEach { it.appendTo(consumer) } } body { fragment.render(this, renderer) @@ -37,7 +39,7 @@ public fun Plotly.fragment(content: FlowContent.(renderer: PlotlyRenderer) -> Un * Create a complete page including plots */ public fun Plotly.page( - vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), + vararg headers: HtmlFragment = arrayOf(cdnPlotlyHeader), title: String = "Plotly.kt", renderer: PlotlyRenderer = StaticPlotlyRenderer, content: FlowContent.(renderer: PlotlyRenderer) -> Unit @@ -47,7 +49,7 @@ public fun Plotly.page( * Convert an html plot fragment to page */ public fun PlotlyFragment.toPage( - vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), + vararg headers: HtmlFragment = arrayOf(cdnPlotlyHeader), title: String = "Plotly.kt", renderer: PlotlyRenderer = StaticPlotlyRenderer ): PlotlyPage = PlotlyPage(headers.toList(), this, title, renderer) @@ -56,7 +58,7 @@ public fun PlotlyFragment.toPage( * Convert a plot to the sigle-plot page */ public fun Plot.toPage( - vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), + vararg headers: HtmlFragment = arrayOf(cdnPlotlyHeader), config: PlotlyConfig = PlotlyConfig.empty(), title: String = "Plotly.kt", renderer: PlotlyRenderer = StaticPlotlyRenderer diff --git a/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt index 82b9cbd9..fb6608be 100644 --- a/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt +++ b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt @@ -2,20 +2,11 @@ package space.kscience.plotly import kotlinx.html.* import kotlinx.html.stream.createHTML +import space.kscience.visionforge.html.HtmlFragment +import space.kscience.visionforge.html.appendTo -public class PlotlyHtmlFragment(public val visit: TagConsumer<*>.() -> Unit) { - override fun toString(): String { - return createHTML().also(visit).finalize() - } -} - -public operator fun PlotlyHtmlFragment.plus(other: PlotlyHtmlFragment): PlotlyHtmlFragment = PlotlyHtmlFragment { - this@plus.run { visit() } - other.run { visit() } -} - -public val cdnPlotlyHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { +public val cdnPlotlyHeader: HtmlFragment = HtmlFragment{ script { type = "text/javascript" src = Plotly.PLOTLY_CDN @@ -26,7 +17,7 @@ public val cdnPlotlyHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { * Create a html (including headers) string from plot */ public fun Plot.toHTML( - vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), + vararg headers: HtmlFragment = arrayOf(cdnPlotlyHeader), config: PlotlyConfig = PlotlyConfig(), ): String = createHTML().html { head { @@ -35,7 +26,7 @@ public fun Plot.toHTML( } title(layout.title ?: "Plotly.kt") headers.forEach { - it.visit(consumer) + it.appendTo(consumer) } } body { @@ -45,7 +36,7 @@ public fun Plot.toHTML( } } -public val mathJaxHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { +public val mathJaxHeader: HtmlFragment = HtmlFragment { script { type = "text/x-mathjax-config" unsafe { diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/Choropleth.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/Choropleth.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/Choropleth.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/Choropleth.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ChoroplethMapBox.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ChoroplethMapBox.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ChoroplethMapBox.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ChoroplethMapBox.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/Geo.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/Geo.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/Geo.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/Geo.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoMapBox.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoMapBox.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoMapBox.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoMapBox.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoProjection.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoProjection.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoProjection.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoProjection.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoTrace.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoTrace.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoTrace.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/GeoTrace.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapAxis.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapAxis.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapAxis.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapAxis.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapCoordinates.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapCoordinates.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapCoordinates.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/MapCoordinates.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterGeo.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterGeo.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterGeo.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterGeo.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterMapBox.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterMapBox.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterMapBox.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/ScatterMapBox.kt diff --git a/plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/json/GeoJson.kt b/plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/json/GeoJson.kt similarity index 100% rename from plotly/plotlykt-geo/src/commonMain/kotlin/space/kscience/plotly/models/geo/json/GeoJson.kt rename to plotly/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/geo/json/GeoJson.kt diff --git a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/bootstrapHeaders.kt b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/bootstrapHeaders.kt index db098a5b..186e857b 100644 --- a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/bootstrapHeaders.kt +++ b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/bootstrapHeaders.kt @@ -2,6 +2,7 @@ package space.kscience.plotly import kotlinx.html.link import kotlinx.html.script +import space.kscience.visionforge.html.HtmlFragment //public fun localBootstrap(basePath: Path) = HtmlFragment { @@ -31,7 +32,7 @@ import kotlinx.html.script // } //} -public val cdnBootstrap: PlotlyHtmlFragment = PlotlyHtmlFragment { +public val cdnBootstrap: HtmlFragment = HtmlFragment { script { src = "https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity = "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" diff --git a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/fileExport.kt b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/fileExport.kt index 0b0741b7..91e2c969 100644 --- a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/fileExport.kt +++ b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/fileExport.kt @@ -1,6 +1,7 @@ package space.kscience.plotly import kotlinx.html.FlowContent +import space.kscience.visionforge.html.HtmlFragment import java.awt.Desktop import java.nio.file.Files import java.nio.file.Path @@ -64,7 +65,7 @@ public fun PlotlyFragment.makeFile( show: Boolean = true, title: String = "Plotly.kt", resourceLocation: ResourceLocation = ResourceLocation.LOCAL, - additionalHeaders: List = emptyList(), + additionalHeaders: List = emptyList(), ) { toPage( title = title, diff --git a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt index 73abd52f..265bb2d9 100644 --- a/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt +++ b/plotly/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt @@ -3,6 +3,7 @@ package space.kscience.plotly import kotlinx.html.link import kotlinx.html.script import kotlinx.html.unsafe +import space.kscience.visionforge.html.HtmlFragment import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardOpenOption @@ -21,7 +22,7 @@ internal fun checkOrStoreFile(basePath: Path, filePath: Path, resource: String): } else { //TODO add logging - val bytes = PlotlyHtmlFragment::class.java.getResourceAsStream(resource)!!.readAllBytes() + val bytes = HtmlFragment::class.java.getResourceAsStream(resource)!!.readAllBytes() Files.createDirectories(fullPath.parent) Files.write(fullPath, bytes, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) } @@ -40,7 +41,7 @@ public fun localScriptHeader( basePath: Path, scriptPath: Path, resource: String, -): PlotlyHtmlFragment = PlotlyHtmlFragment { +): HtmlFragment = HtmlFragment { val relativePath = checkOrStoreFile(basePath, scriptPath, resource) script { type = "text/javascript" @@ -54,7 +55,7 @@ public fun localCssHeader( basePath: Path, cssPath: Path, resource: String, -): PlotlyHtmlFragment = PlotlyHtmlFragment { +): HtmlFragment = HtmlFragment { val relativePath = checkOrStoreFile(basePath, cssPath, resource) link { rel = "stylesheet" @@ -66,7 +67,7 @@ public fun localCssHeader( internal fun localPlotlyHeader( path: Path, relativeScriptPath: String = "$assetsDirectory$PLOTLY_SCRIPT_PATH" -) = PlotlyHtmlFragment { +) = HtmlFragment { val relativePath = checkOrStoreFile(path, Path.of(relativeScriptPath), PLOTLY_SCRIPT_PATH) script { type = "text/javascript" @@ -78,7 +79,7 @@ internal fun localPlotlyHeader( /** * A system-wide plotly store location */ -internal val systemPlotlyHeader = PlotlyHtmlFragment { +internal val systemPlotlyHeader = HtmlFragment { val relativePath = checkOrStoreFile( Path.of("."), Path.of(System.getProperty("user.home")).resolve(".plotly/$assetsDirectory$PLOTLY_SCRIPT_PATH"), @@ -94,10 +95,10 @@ internal val systemPlotlyHeader = PlotlyHtmlFragment { /** * embedded plotly script */ -internal val embededPlotlyHeader = PlotlyHtmlFragment { +internal val embededPlotlyHeader = HtmlFragment { script { unsafe { - val bytes = PlotlyHtmlFragment::class.java.getResourceAsStream(PLOTLY_SCRIPT_PATH)!!.readAllBytes() + val bytes = HtmlFragment::class.java.getResourceAsStream(PLOTLY_SCRIPT_PATH)!!.readAllBytes() +bytes.toString(Charsets.UTF_8) } } @@ -107,7 +108,7 @@ internal val embededPlotlyHeader = PlotlyHtmlFragment { internal fun inferPlotlyHeader( target: Path?, resourceLocation: ResourceLocation -): PlotlyHtmlFragment = when (resourceLocation) { +): HtmlFragment = when (resourceLocation) { ResourceLocation.REMOTE -> cdnPlotlyHeader ResourceLocation.LOCAL -> if (target != null) { localPlotlyHeader(target) diff --git a/plotly/plotlykt-geo/README.md b/plotly/plotlykt-geo/README.md deleted file mode 100644 index f15f5f2a..00000000 --- a/plotly/plotlykt-geo/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Module plotlykt-geo - - - -## Usage - -## Artifact: - -The Maven coordinates of this project are `space.kscience:plotlykt-geo:0.7.1`. - -**Gradle Kotlin DSL:** -```kotlin -repositories { - maven("https://repo.kotlin.link") - mavenCentral() -} - -dependencies { - implementation("space.kscience:plotlykt-geo:0.7.1") -} -``` diff --git a/plotly/plotlykt-geo/build.gradle.kts b/plotly/plotlykt-geo/build.gradle.kts deleted file mode 100644 index 5cad496a..00000000 --- a/plotly/plotlykt-geo/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("space.kscience.gradle.mpp") - `maven-publish` -} - -kscience{ - jvm() - js() - native() - wasm() - dependencies { - api(projects.plotly.plotlyktCore) - } -} - -readme{ - maturity = space.kscience.gradle.Maturity.EXPERIMENTAL -} \ No newline at end of file diff --git a/plotly/plotlykt-jupyter/src/jvmMain/kotlin/space/kscience/plotly/PlotlyIntegration.kt b/plotly/plotlykt-jupyter/src/jvmMain/kotlin/space/kscience/plotly/PlotlyIntegration.kt index dc0d197b..3c199f55 100644 --- a/plotly/plotlykt-jupyter/src/jvmMain/kotlin/space/kscience/plotly/PlotlyIntegration.kt +++ b/plotly/plotlykt-jupyter/src/jvmMain/kotlin/space/kscience/plotly/PlotlyIntegration.kt @@ -5,6 +5,7 @@ import kotlinx.html.stream.createHTML import org.jetbrains.kotlinx.jupyter.api.HTML import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration import org.jetbrains.kotlinx.jupyter.api.libraries.resources +import space.kscience.visionforge.html.HtmlFragment public object PlotlyJupyterConfiguration { public var legacyMode: Boolean = false @@ -12,9 +13,9 @@ public object PlotlyJupyterConfiguration { /** * Switch plotly renderer to the legacy notebook mode (Jupyter classic) */ - public fun notebook(): PlotlyHtmlFragment { + public fun notebook(): HtmlFragment { legacyMode = true - return PlotlyHtmlFragment { + return HtmlFragment { div { style = "color: blue;" +"Plotly notebook integration switched into the notebook mode." @@ -22,9 +23,9 @@ public object PlotlyJupyterConfiguration { } } - public fun lab(): PlotlyHtmlFragment { + public fun lab(): HtmlFragment { legacyMode = false - return PlotlyHtmlFragment { + return HtmlFragment { div { style = "color: blue;" +"Plotly notebook integration switched into the lab mode." @@ -98,7 +99,7 @@ public class PlotlyIntegration : JupyterIntegration(), PlotlyRenderer { import("space.kscience.plotly.jupyter") - render { + render { HTML(it.toString()) } diff --git a/plotly/plotlykt-script/src/jvmMain/kotlin/space/kscience/plotly/script/builder.kt b/plotly/plotlykt-script/src/jvmMain/kotlin/space/kscience/plotly/script/builder.kt index 82981317..d5a6755d 100644 --- a/plotly/plotlykt-script/src/jvmMain/kotlin/space/kscience/plotly/script/builder.kt +++ b/plotly/plotlykt-script/src/jvmMain/kotlin/space/kscience/plotly/script/builder.kt @@ -4,6 +4,7 @@ import kotlinx.html.FlowContent import mu.KLogger import mu.KotlinLogging import space.kscience.plotly.* +import space.kscience.visionforge.html.HtmlFragment import java.io.File import kotlin.script.experimental.api.* import kotlin.script.experimental.host.toScriptSource @@ -16,7 +17,7 @@ import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost public fun Plotly.page( source: SourceCode, title: String = "Plotly.kt", - headers: Array = arrayOf(cdnPlotlyHeader), + headers: Array = arrayOf(cdnPlotlyHeader), logger: KLogger = KotlinLogging.logger("scripting") ): PlotlyPage { @@ -62,7 +63,7 @@ public fun Plotly.page( public fun Plotly.page( file: File, title: String = "Plotly.kt", - headers: Array = arrayOf(cdnPlotlyHeader), + headers: Array = arrayOf(cdnPlotlyHeader), logger: KLogger = KotlinLogging.logger("scripting") ): PlotlyPage = page(file.toScriptSource(), title, headers, logger) @@ -71,6 +72,6 @@ public fun Plotly.page( public fun Plotly.page( string: String, title: String = "Plotly.kt", - headers: Array = arrayOf(cdnPlotlyHeader), + headers: Array = arrayOf(cdnPlotlyHeader), logger: KLogger = KotlinLogging.logger("scripting") ): PlotlyPage = page(string.toScriptSource(), title, headers, logger) \ No newline at end of file diff --git a/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt b/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt index d08a057c..08371b58 100644 --- a/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt +++ b/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt @@ -23,6 +23,8 @@ import space.kscience.dataforge.meta.* import space.kscience.dataforge.names.Name import space.kscience.plotly.* import space.kscience.plotly.server.PlotlyServer.Companion.DEFAULT_PAGE +import space.kscience.visionforge.html.HtmlFragment +import space.kscience.visionforge.html.appendTo import java.awt.Desktop import java.net.URI import kotlin.collections.set @@ -141,10 +143,10 @@ public class PlotlyServer internal constructor( /** * a list of headers that should be applied to all pages */ - private val globalHeaders: ArrayList = ArrayList() + private val globalHeaders: ArrayList = ArrayList() public fun header(block: TagConsumer<*>.() -> Unit) { - globalHeaders.add(PlotlyHtmlFragment(block)) + globalHeaders.add(HtmlFragment(block)) } internal fun Route.servePlotData(plots: Map) { @@ -186,7 +188,7 @@ public class PlotlyServer internal constructor( plotlyFragment: PlotlyFragment, route: String = DEFAULT_PAGE, title: String = "Plotly server page '$route'", - headers: List = emptyList(), + headers: List = emptyList(), ) { root.apply { val plots = HashMap() @@ -214,9 +216,9 @@ public class PlotlyServer internal constructor( meta { charset = "utf-8" (globalHeaders + headers).forEach { - it.visit(consumer) + it.appendTo(consumer) } - plotlyKtHeader.visit(consumer) + plotlyKtHeader.appendTo(consumer) } title(title) } @@ -239,7 +241,7 @@ public class PlotlyServer internal constructor( public fun page( route: String = DEFAULT_PAGE, title: String = "Plotly server page '$route'", - headers: List = emptyList(), + headers: List = emptyList(), content: FlowContent.(renderer: PlotlyRenderer) -> Unit, ) { page(PlotlyFragment(content), route, title, headers) diff --git a/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt b/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt index 2ea82a3a..20d1cf2f 100644 --- a/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt +++ b/plotly/plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt @@ -14,6 +14,7 @@ import space.kscience.dataforge.meta.Scheme import space.kscience.dataforge.meta.boolean import space.kscience.dataforge.meta.int import space.kscience.plotly.* +import space.kscience.visionforge.html.HtmlFragment public object PlotlyServerConfiguration : Scheme() { public var port: Int by int(System.getProperty("space.kscience.plotly.port")?.toInt() ?: 8882) @@ -24,9 +25,9 @@ public object PlotlyServerConfiguration : Scheme() { /** * Switch plotly renderer to the legacy notebook mode (Jupyter classic) */ - public fun notebook(): PlotlyHtmlFragment { + public fun notebook(): HtmlFragment { legacyMode = true - return PlotlyHtmlFragment { + return HtmlFragment { div { style = "color: blue;" +"Plotly notebook integration switch into the legacy mode." @@ -35,7 +36,7 @@ public object PlotlyServerConfiguration : Scheme() { } } -internal val plotlyKtHeader = PlotlyHtmlFragment { +internal val plotlyKtHeader = HtmlFragment { script { src = "js/plotly-kt.js" } @@ -59,15 +60,15 @@ public class PlotlyServerIntegration : JupyterIntegration() { public val isServerStarted: Boolean get() = server != null - private fun start(): PlotlyHtmlFragment = if (server != null) { - PlotlyHtmlFragment { + private fun start(): HtmlFragment = if (server != null) { + HtmlFragment { div { style = "color: blue;" +"The server is already running on ${Plotly.jupyter.port}. It must be shut down first to be restarted." } } } else { - fun doStart(): PlotlyHtmlFragment { + fun doStart(): HtmlFragment { server?.stop(1000, 1000) server = Plotly.serve(host = "0.0.0.0", port = Plotly.jupyter.port) { root.servePlotData(plots) @@ -80,7 +81,7 @@ public class PlotlyServerIntegration : JupyterIntegration() { ) { plotId, plot -> plots[plotId] = plot } - return PlotlyHtmlFragment { + return HtmlFragment { div { style = "color: blue;" +"Started plotly server on ${Plotly.jupyter.port}" @@ -135,7 +136,7 @@ public class PlotlyServerIntegration : JupyterIntegration() { import("space.kscience.plotly.server.jupyter") - render { + render { HTML(it.toString()) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 4994aa83..def6cc70 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -62,7 +62,6 @@ include( ":visionforge-jupyter:visionforge-jupyter-common", ":plotly", ":plotly:plotlykt-core", - ":plotly:plotlykt-geo", ":plotly:plotlykt-jupyter", ":plotly:plotlykt-server", ":plotly:plotlykt-script", diff --git a/visionforge-jupyter/visionforge-jupyter-common/README.md b/visionforge-jupyter/visionforge-jupyter-common/README.md new file mode 100644 index 00000000..928b7167 --- /dev/null +++ b/visionforge-jupyter/visionforge-jupyter-common/README.md @@ -0,0 +1,21 @@ +# Module visionforge-jupyter-common + +Jupyter api artifact including all common modules + +## Usage + +## Artifact: + +The Maven coordinates of this project are `space.kscience:visionforge-jupyter-common:0.4.1`. + +**Gradle Kotlin DSL:** +```kotlin +repositories { + maven("https://repo.kotlin.link") + mavenCentral() +} + +dependencies { + implementation("space.kscience:visionforge-jupyter-common:0.4.1") +} +``` diff --git a/visionforge-jupyter/visionforge-jupyter-common/src/jvmMain/kotlin/JupyterCommonIntegration.kt b/visionforge-jupyter/visionforge-jupyter-common/src/jvmMain/kotlin/JupyterCommonIntegration.kt index 2f7988f8..8b8f3cfa 100644 --- a/visionforge-jupyter/visionforge-jupyter-common/src/jvmMain/kotlin/JupyterCommonIntegration.kt +++ b/visionforge-jupyter/visionforge-jupyter-common/src/jvmMain/kotlin/JupyterCommonIntegration.kt @@ -12,6 +12,7 @@ import space.kscience.tables.Table import space.kscience.visionforge.gdml.toVision import space.kscience.visionforge.html.HtmlFragment import space.kscience.visionforge.html.VisionPage +import space.kscience.visionforge.html.appendTo import space.kscience.visionforge.markup.MarkupPlugin import space.kscience.visionforge.plotly.PlotlyPlugin import space.kscience.visionforge.plotly.asVision @@ -63,7 +64,7 @@ public class JupyterCommonIntegration : VisionForgeIntegration(CONTEXT.visionMan render { plotlyPage -> val headers = plotlyPage.headers.associate { plotlyFragment -> plotlyFragment.hashCode().toString(16) to HtmlFragment { - plotlyFragment.visit(this) + plotlyFragment.appendTo(this) } }