From c093ddd2b023b0c1fd7769d720f383702227dc11 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 31 Mar 2023 12:16:27 +0300 Subject: [PATCH 01/10] Versions upgrade --- build.gradle.kts | 5 +- examples/build.gradle.kts | 7 +- examples/fx-demo/build.gradle.kts | 7 +- examples/js-demo/build.gradle.kts | 5 +- .../src/main/kotlin/misc/secondaryYAxis.kt | 46 ++++++++++ examples/src/main/kotlin/plots3d/scatter3d.kt | 3 +- examples/src/main/kotlin/plots3d/surface3d.kt | 6 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- plotlykt-core/api/plotlykt-core.api | 90 ++++++++++--------- plotlykt-core/build.gradle.kts | 33 +++---- plotlykt-geo/build.gradle.kts | 12 ++- plotlykt-script/build.gradle.kts | 10 +-- plotlykt-server/api/plotlykt-server.api | 6 +- settings.gradle.kts | 3 +- 15 files changed, 139 insertions(+), 98 deletions(-) create mode 100644 examples/src/main/kotlin/misc/secondaryYAxis.kt diff --git a/build.gradle.kts b/build.gradle.kts index 689888e7..290c7b15 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,11 +6,12 @@ plugins { id("space.kscience.gradle.project") } -val dataforgeVersion by extra("0.6.0-dev-15") +val dataforgeVersion by extra("0.6.1") +val plotlyVersion by extra("2.20.0") allprojects { group = "space.kscience" - version = "0.5.3-dev-2" + version = "0.5.3" } apiValidation { diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 31c65056..9931f981 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -12,11 +12,14 @@ dependencies { implementation(project(":plotlykt-geo")) implementation(kotlin("script-runtime")) implementation(project(":plotlykt-script")) - implementation("org.jetbrains.kotlinx:dataframe:0.8.0-dev-968-0.11.0.83") + implementation("org.jetbrains.kotlinx:dataframe:0.9.1") +} + +kotlin{ + jvmToolchain(11) } tasks.withType { - kotlinOptions.jvmTarget = "11" kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" } diff --git a/examples/fx-demo/build.gradle.kts b/examples/fx-demo/build.gradle.kts index cfa26d59..28436df4 100644 --- a/examples/fx-demo/build.gradle.kts +++ b/examples/fx-demo/build.gradle.kts @@ -14,7 +14,7 @@ repositories { dependencies { implementation(project(":plotlykt-server")) implementation("no.tornado:tornadofx:1.7.20") - implementation("ch.qos.logback:logback-classic:1.2.11") + implementation(spclibs.logback.classic) } javafx{ @@ -26,7 +26,10 @@ application { mainClass.set("space.kscience.plotly.fx.PlotlyFXAppKt") } +kotlin{ + jvmToolchain(11) +} + tasks.withType { - kotlinOptions.jvmTarget = "11" kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" } diff --git a/examples/js-demo/build.gradle.kts b/examples/js-demo/build.gradle.kts index 76f46289..dbef5c0e 100644 --- a/examples/js-demo/build.gradle.kts +++ b/examples/js-demo/build.gradle.kts @@ -15,11 +15,10 @@ kotlin { } dependencies { - implementation(project(":plotlykt-core")) - implementation(npmlibs.kotlinx.coroutines.core) + implementation(projects.plotlyktCore) + implementation(spclibs.kotlinx.coroutines.core) } tasks.withType { - kotlinOptions.jvmTarget = "11" kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" } \ No newline at end of file diff --git a/examples/src/main/kotlin/misc/secondaryYAxis.kt b/examples/src/main/kotlin/misc/secondaryYAxis.kt new file mode 100644 index 00000000..01e30a9c --- /dev/null +++ b/examples/src/main/kotlin/misc/secondaryYAxis.kt @@ -0,0 +1,46 @@ +package misc + +import space.kscience.plotly.Plotly +import space.kscience.plotly.layout +import space.kscience.plotly.makeFile +import space.kscience.plotly.models.AxisSide +import space.kscience.plotly.scatter + + +fun main() { + Plotly.plot { + + scatter { + x(1, 2, 3) + y(40, 50, 60) + name = "yaxis data" + } + + scatter { + x(2, 3, 4) + y(4, 5, 6) + name = "yaxis2 data" + yaxis = "y2" + } + + layout { + title = "Double Y Axis Example" + yaxis { + title = "yaxis title" + } + yaxis(2) { + title { + text = "yaxis2 title" + font { + color("rgb(148, 103, 189)") + } + } + tickfont { + color("rgb(148, 103, 189)") + } + overlaying = "y" + side = AxisSide.right + } + } + }.makeFile() +} \ No newline at end of file diff --git a/examples/src/main/kotlin/plots3d/scatter3d.kt b/examples/src/main/kotlin/plots3d/scatter3d.kt index 498db0eb..39143a79 100644 --- a/examples/src/main/kotlin/plots3d/scatter3d.kt +++ b/examples/src/main/kotlin/plots3d/scatter3d.kt @@ -1,12 +1,11 @@ package plots3d import space.kscience.plotly.Plotly -import space.kscience.plotly.UnsupportedPlotlyAPI import space.kscience.plotly.makeFile import space.kscience.plotly.models.TraceType import space.kscience.plotly.trace -@OptIn(UnsupportedPlotlyAPI::class) + fun main() { val plot = Plotly.plot { trace { diff --git a/examples/src/main/kotlin/plots3d/surface3d.kt b/examples/src/main/kotlin/plots3d/surface3d.kt index 845ff296..9871449f 100644 --- a/examples/src/main/kotlin/plots3d/surface3d.kt +++ b/examples/src/main/kotlin/plots3d/surface3d.kt @@ -1,9 +1,9 @@ package plots3d import space.kscience.dataforge.meta.asValue -import space.kscience.dataforge.meta.configure import space.kscience.plotly.Plotly import space.kscience.plotly.makeFile +import space.kscience.plotly.models.TraceType import space.kscience.plotly.trace private fun l(vararg numbers: Number) = numbers.map { it.asValue() }.asValue() @@ -28,9 +28,7 @@ fun main() { l(8.99, 8.99, 8.98, 9.18, 9.2, 9.19), l(8.93, 8.97, 8.97, 9.18, 9.2, 9.18) ).asValue() - configure { - "type" put "surface" - } + type = TraceType.surface } } plot.makeFile() diff --git a/gradle.properties b/gradle.properties index 75ec15c2..9903e9a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false kotlin.incremental.js.ir=true -toolsVersion=0.13.3-kotlin-1.7.20 \ No newline at end of file +toolsVersion=0.14.5-kotlin-1.8.20-RC \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb702..e1bef7e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plotlykt-core/api/plotlykt-core.api b/plotlykt-core/api/plotlykt-core.api index 4d076c90..34b7d4cf 100644 --- a/plotlykt-core/api/plotlykt-core.api +++ b/plotlykt-core/api/plotlykt-core.api @@ -42,12 +42,14 @@ public final class space/kscience/plotly/OrcaFormat : java/lang/Enum { public static fun values ()[Lspace/kscience/plotly/OrcaFormat; } -public final class space/kscience/plotly/Plot : space/kscience/dataforge/meta/Configurable, space/kscience/dataforge/meta/MetaRepr { +public final class space/kscience/plotly/Plot : space/kscience/dataforge/meta/Configurable, space/kscience/dataforge/meta/MetaRepr, space/kscience/dataforge/meta/descriptors/Described { + public static final field Companion Lspace/kscience/plotly/Plot$Companion; public fun ()V public fun (Lspace/kscience/dataforge/meta/ObservableMutableMeta;)V public synthetic fun (Lspace/kscience/dataforge/meta/ObservableMutableMeta;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun addTrace (Lspace/kscience/plotly/models/Trace;)V public final fun getData ()Ljava/util/List; + public fun getDescriptor ()Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor; public final fun getLayout ()Lspace/kscience/plotly/models/Layout; public synthetic fun getMeta ()Lspace/kscience/dataforge/meta/MutableMeta; public fun getMeta ()Lspace/kscience/dataforge/meta/ObservableMutableMeta; @@ -56,6 +58,10 @@ public final class space/kscience/plotly/Plot : space/kscience/dataforge/meta/Co public final fun traces ([Lspace/kscience/plotly/models/Trace;)V } +public final class space/kscience/plotly/Plot$Companion { + public final fun getDescriptor ()Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor; +} + public final class space/kscience/plotly/PlotExtensionsKt { public static final fun bar (Lspace/kscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lspace/kscience/plotly/models/Bar; public static final fun box (Lspace/kscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lspace/kscience/plotly/models/Box; @@ -257,7 +263,7 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/ public final fun getAutorange ()Z public final fun getAutotick ()Ljava/lang/Boolean; public final fun getColor ()Lspace/kscience/plotly/models/Color; - public final fun getDtick ()Lspace/kscience/dataforge/values/Value; + public final fun getDtick ()Lspace/kscience/dataforge/meta/Value; public final fun getGridcolor ()Lspace/kscience/plotly/models/Color; public final fun getGridwidth ()Ljava/lang/Number; public final fun getLinecolor ()Lspace/kscience/plotly/models/Color; @@ -284,12 +290,12 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/ public final fun getZerolinewidth ()Ljava/lang/Number; public final fun range (Lkotlin/ranges/ClosedFloatingPointRange;)V public final fun range (Lkotlin/ranges/ClosedRange;)V - public final fun range (Lspace/kscience/dataforge/values/Value;Lspace/kscience/dataforge/values/Value;)V + public final fun range (Lspace/kscience/dataforge/meta/Value;Lspace/kscience/dataforge/meta/Value;)V public final fun setAnchor (Ljava/lang/String;)V public final fun setAutomargin (Ljava/lang/Boolean;)V public final fun setAutorange (Z)V public final fun setAutotick (Ljava/lang/Boolean;)V - public final fun setDtick (Lspace/kscience/dataforge/values/Value;)V + public final fun setDtick (Lspace/kscience/dataforge/meta/Value;)V public final fun setGridwidth (Ljava/lang/Number;)V public final fun setLinewidth (Ljava/lang/Number;)V public final fun setPosition (Ljava/lang/Number;)V @@ -505,7 +511,7 @@ public final class space/kscience/plotly/models/Calendar : java/lang/Enum { public final class space/kscience/plotly/models/CandleStick : space/kscience/plotly/models/Trace { public static final field Companion Lspace/kscience/plotly/models/CandleStick$Companion; public fun ()V - public final fun getCandleStickMeta ()Lspace/kscience/dataforge/values/Value; + public final fun getCandleStickMeta ()Lspace/kscience/dataforge/meta/Value; public final fun getClose ()Lspace/kscience/plotly/models/TraceValues; public final fun getDecreasing ()Lspace/kscience/plotly/models/CandleStickLine; public final fun getHigh ()Lspace/kscience/plotly/models/TraceValues; @@ -516,19 +522,19 @@ public final class space/kscience/plotly/models/CandleStick : space/kscience/plo public final fun getOpen ()Lspace/kscience/plotly/models/TraceValues; public final fun getWhiskerwidth ()D public final fun getXaxis ()Ljava/lang/String; - public final fun getXperiod ()Lspace/kscience/dataforge/values/Value; - public final fun getXperiod0 ()Lspace/kscience/dataforge/values/Value; + public final fun getXperiod ()Lspace/kscience/dataforge/meta/Value; + public final fun getXperiod0 ()Lspace/kscience/dataforge/meta/Value; public final fun getXperiodalignment ()Lspace/kscience/plotly/models/XPeriodAlignment; public final fun getYaxis ()Ljava/lang/String; - public final fun setCandleStickMeta (Lspace/kscience/dataforge/values/Value;)V + public final fun setCandleStickMeta (Lspace/kscience/dataforge/meta/Value;)V public final fun setDecreasing (Lspace/kscience/plotly/models/CandleStickLine;)V public final fun setIds (Ljava/util/List;)V public final fun setIncreasing (Lspace/kscience/plotly/models/CandleStickLine;)V public final fun setLineWidth (D)V public final fun setWhiskerwidth (D)V public final fun setXaxis (Ljava/lang/String;)V - public final fun setXperiod (Lspace/kscience/dataforge/values/Value;)V - public final fun setXperiod0 (Lspace/kscience/dataforge/values/Value;)V + public final fun setXperiod (Lspace/kscience/dataforge/meta/Value;)V + public final fun setXperiod0 (Lspace/kscience/dataforge/meta/Value;)V public final fun setXperiodalignment (Lspace/kscience/plotly/models/XPeriodAlignment;)V public final fun setYaxis (Ljava/lang/String;)V } @@ -577,13 +583,13 @@ public final class space/kscience/plotly/models/Cells$Companion : space/kscience public final class space/kscience/plotly/models/Color { public final fun getString ()Ljava/lang/String; - public final fun getValue ()Lspace/kscience/dataforge/values/Value; + public final fun getValue ()Lspace/kscience/dataforge/meta/Value; public final fun invoke (Ljava/lang/Number;)V public final fun invoke (Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public final fun invoke (Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V public final fun invoke (Ljava/lang/String;)V public final fun setString (Ljava/lang/String;)V - public final fun setValue (Lspace/kscience/dataforge/values/Value;)V + public final fun setValue (Lspace/kscience/dataforge/meta/Value;)V } public final class space/kscience/plotly/models/ColorBar : space/kscience/dataforge/meta/Scheme { @@ -1314,7 +1320,7 @@ public final class space/kscience/plotly/models/MarkerLine : space/kscience/data public final fun getCmid ()Ljava/lang/Number; public final fun getCmin ()Ljava/lang/Number; public fun getColor ()Lspace/kscience/plotly/models/Color; - public final fun getColorscale ()Lspace/kscience/dataforge/values/Value; + public final fun getColorscale ()Lspace/kscience/dataforge/meta/Value; public final fun getOutliercolor ()Lspace/kscience/plotly/models/Color; public final fun getOutlierwidth ()Ljava/lang/Number; public final fun getReversescale ()Ljava/lang/Boolean; @@ -1325,7 +1331,7 @@ public final class space/kscience/plotly/models/MarkerLine : space/kscience/data public final fun setCmax (Ljava/lang/Number;)V public final fun setCmid (Ljava/lang/Number;)V public final fun setCmin (Ljava/lang/Number;)V - public final fun setColorscale (Lspace/kscience/dataforge/values/Value;)V + public final fun setColorscale (Lspace/kscience/dataforge/meta/Value;)V public final fun setOutlierwidth (Ljava/lang/Number;)V public final fun setReversescale (Ljava/lang/Boolean;)V public fun setWidth (Ljava/lang/Number;)V @@ -1517,14 +1523,14 @@ public final class space/kscience/plotly/models/Shape : space/kscience/dataforge public final fun getTemplateitemname ()Ljava/lang/String; public final fun getType ()Lspace/kscience/plotly/models/ShapeType; public final fun getVisible ()Ljava/lang/Boolean; - public final fun getX0 ()Lspace/kscience/dataforge/values/Value; - public final fun getX1 ()Lspace/kscience/dataforge/values/Value; - public final fun getXanchor ()Lspace/kscience/dataforge/values/Value; + public final fun getX0 ()Lspace/kscience/dataforge/meta/Value; + public final fun getX1 ()Lspace/kscience/dataforge/meta/Value; + public final fun getXanchor ()Lspace/kscience/dataforge/meta/Value; public final fun getXref ()Ljava/lang/String; public final fun getXsizemode ()Lspace/kscience/plotly/models/ShapeSizeMode; - public final fun getY0 ()Lspace/kscience/dataforge/values/Value; - public final fun getY1 ()Lspace/kscience/dataforge/values/Value; - public final fun getYanchor ()Lspace/kscience/dataforge/values/Value; + public final fun getY0 ()Lspace/kscience/dataforge/meta/Value; + public final fun getY1 ()Lspace/kscience/dataforge/meta/Value; + public final fun getYanchor ()Lspace/kscience/dataforge/meta/Value; public final fun getYref ()Ljava/lang/String; public final fun getYsizemode ()Lspace/kscience/plotly/models/ShapeSizeMode; public final fun line (Lkotlin/jvm/functions/Function1;)V @@ -1538,14 +1544,14 @@ public final class space/kscience/plotly/models/Shape : space/kscience/dataforge public final fun setTemplateitemname (Ljava/lang/String;)V public final fun setType (Lspace/kscience/plotly/models/ShapeType;)V public final fun setVisible (Ljava/lang/Boolean;)V - public final fun setX0 (Lspace/kscience/dataforge/values/Value;)V - public final fun setX1 (Lspace/kscience/dataforge/values/Value;)V - public final fun setXanchor (Lspace/kscience/dataforge/values/Value;)V + public final fun setX0 (Lspace/kscience/dataforge/meta/Value;)V + public final fun setX1 (Lspace/kscience/dataforge/meta/Value;)V + public final fun setXanchor (Lspace/kscience/dataforge/meta/Value;)V public final fun setXref (Ljava/lang/String;)V public final fun setXsizemode (Lspace/kscience/plotly/models/ShapeSizeMode;)V - public final fun setY0 (Lspace/kscience/dataforge/values/Value;)V - public final fun setY1 (Lspace/kscience/dataforge/values/Value;)V - public final fun setYanchor (Lspace/kscience/dataforge/values/Value;)V + public final fun setY0 (Lspace/kscience/dataforge/meta/Value;)V + public final fun setY1 (Lspace/kscience/dataforge/meta/Value;)V + public final fun setYanchor (Lspace/kscience/dataforge/meta/Value;)V public final fun setYref (Ljava/lang/String;)V public final fun setYsizemode (Lspace/kscience/plotly/models/ShapeSizeMode;)V } @@ -1652,8 +1658,8 @@ public final class space/kscience/plotly/models/Text : space/kscience/dataforge/ public final fun font (Lkotlin/jvm/functions/Function1;)V public final fun getAlign ()Lspace/kscience/plotly/models/HorizontalAlign; public final fun getArrowcolor ()Lspace/kscience/plotly/models/Color; - public final fun getAx ()Lspace/kscience/dataforge/values/Value; - public final fun getAy ()Lspace/kscience/dataforge/values/Value; + public final fun getAx ()Lspace/kscience/dataforge/meta/Value; + public final fun getAy ()Lspace/kscience/dataforge/meta/Value; public final fun getBgcolor ()Lspace/kscience/plotly/models/Color; public final fun getBordercolor ()Lspace/kscience/plotly/models/Color; public final fun getFont ()Lspace/kscience/plotly/models/Font; @@ -1666,16 +1672,16 @@ public final class space/kscience/plotly/models/Text : space/kscience/dataforge/ public final fun getValign ()Lspace/kscience/plotly/models/VerticalAlign; public final fun getVisible ()Ljava/lang/Boolean; public final fun getWidth ()Ljava/lang/Number; - public final fun getX ()Lspace/kscience/dataforge/values/Value; + public final fun getX ()Lspace/kscience/dataforge/meta/Value; public final fun getXanchor ()Lspace/kscience/plotly/models/XAnchor; public final fun getXref ()Ljava/lang/String; - public final fun getY ()Lspace/kscience/dataforge/values/Value; + public final fun getY ()Lspace/kscience/dataforge/meta/Value; public final fun getYanchor ()Lspace/kscience/plotly/models/YAnchor; public final fun getYref ()Ljava/lang/String; public final fun position (Ljava/lang/Number;Ljava/lang/Number;)V public final fun setAlign (Lspace/kscience/plotly/models/HorizontalAlign;)V - public final fun setAx (Lspace/kscience/dataforge/values/Value;)V - public final fun setAy (Lspace/kscience/dataforge/values/Value;)V + public final fun setAx (Lspace/kscience/dataforge/meta/Value;)V + public final fun setAy (Lspace/kscience/dataforge/meta/Value;)V public final fun setFont (Lspace/kscience/plotly/models/Font;)V public final fun setHeight (Ljava/lang/Number;)V public final fun setOpacity (Ljava/lang/Number;)V @@ -1686,10 +1692,10 @@ public final class space/kscience/plotly/models/Text : space/kscience/dataforge/ public final fun setValign (Lspace/kscience/plotly/models/VerticalAlign;)V public final fun setVisible (Ljava/lang/Boolean;)V public final fun setWidth (Ljava/lang/Number;)V - public final fun setX (Lspace/kscience/dataforge/values/Value;)V + public final fun setX (Lspace/kscience/dataforge/meta/Value;)V public final fun setXanchor (Lspace/kscience/plotly/models/XAnchor;)V public final fun setXref (Ljava/lang/String;)V - public final fun setY (Lspace/kscience/dataforge/values/Value;)V + public final fun setY (Lspace/kscience/dataforge/meta/Value;)V public final fun setYanchor (Lspace/kscience/plotly/models/YAnchor;)V public final fun setYref (Ljava/lang/String;)V } @@ -1795,7 +1801,7 @@ public class space/kscience/plotly/models/Trace : space/kscience/dataforge/meta/ public final fun getAxis ()Lkotlin/properties/ReadOnlyProperty; public final fun getCliponaxis ()Ljava/lang/Boolean; public final fun getColorbar ()Lspace/kscience/plotly/models/ColorBar; - public final fun getColorscale ()Lspace/kscience/dataforge/values/Value; + public final fun getColorscale ()Lspace/kscience/dataforge/meta/Value; public final fun getConnectgaps ()Ljava/lang/Boolean; public final fun getDomain ()Lspace/kscience/plotly/models/Domain; public final fun getDx ()Ljava/lang/Number; @@ -1826,10 +1832,10 @@ public class space/kscience/plotly/models/Trace : space/kscience/dataforge/meta/ public final fun getValues ()Ljava/util/List; public final fun getVisible ()Lspace/kscience/plotly/models/Visible; public final fun getX ()Lspace/kscience/plotly/models/TraceValues; - public final fun getX0 ()Lspace/kscience/dataforge/values/Value; + public final fun getX0 ()Lspace/kscience/dataforge/meta/Value; public final fun getXcalendar ()Lspace/kscience/plotly/models/Calendar; public final fun getY ()Lspace/kscience/plotly/models/TraceValues; - public final fun getY0 ()Lspace/kscience/dataforge/values/Value; + public final fun getY0 ()Lspace/kscience/dataforge/meta/Value; public final fun getYcalendar ()Lspace/kscience/plotly/models/Calendar; public final fun getZ ()Lspace/kscience/plotly/models/TraceValues; public final fun getZauto ()Ljava/lang/Boolean; @@ -1842,7 +1848,7 @@ public class space/kscience/plotly/models/Trace : space/kscience/dataforge/meta/ public final fun marker (Lkotlin/jvm/functions/Function1;)V public final fun setCliponaxis (Ljava/lang/Boolean;)V public final fun setColorbar (Lspace/kscience/plotly/models/ColorBar;)V - public final fun setColorscale (Lspace/kscience/dataforge/values/Value;)V + public final fun setColorscale (Lspace/kscience/dataforge/meta/Value;)V public final fun setConnectgaps (Ljava/lang/Boolean;)V public final fun setDomain (Lspace/kscience/plotly/models/Domain;)V public final fun setDx (Ljava/lang/Number;)V @@ -1869,9 +1875,9 @@ public class space/kscience/plotly/models/Trace : space/kscience/dataforge/meta/ public final fun setType (Lspace/kscience/plotly/models/TraceType;)V public final fun setValues (Ljava/util/List;)V public final fun setVisible (Lspace/kscience/plotly/models/Visible;)V - public final fun setX0 (Lspace/kscience/dataforge/values/Value;)V + public final fun setX0 (Lspace/kscience/dataforge/meta/Value;)V public final fun setXcalendar (Lspace/kscience/plotly/models/Calendar;)V - public final fun setY0 (Lspace/kscience/dataforge/values/Value;)V + public final fun setY0 (Lspace/kscience/dataforge/meta/Value;)V public final fun setYcalendar (Lspace/kscience/plotly/models/Calendar;)V public final fun setZauto (Ljava/lang/Boolean;)V public final fun setZmax (Ljava/lang/Number;)V @@ -1934,7 +1940,7 @@ public final class space/kscience/plotly/models/TraceValues { public final fun getNumbers ()Ljava/lang/Iterable; public final fun getOwner ()Lspace/kscience/dataforge/meta/Scheme; public final fun getStrings ()Ljava/lang/Iterable; - public final fun getValue ()Lspace/kscience/dataforge/values/Value; + public final fun getValue ()Lspace/kscience/dataforge/meta/Value; public final fun invoke (Ljava/util/List;)V public final fun invoke ([Ljava/lang/Number;)V public final fun invoke ([Ljava/lang/String;)V @@ -1942,7 +1948,7 @@ public final class space/kscience/plotly/models/TraceValues { public final fun setDoubles ([D)V public final fun setNumbers (Ljava/lang/Iterable;)V public final fun setStrings (Ljava/lang/Iterable;)V - public final fun setValue (Lspace/kscience/dataforge/values/Value;)V + public final fun setValue (Lspace/kscience/dataforge/meta/Value;)V } public final class space/kscience/plotly/models/VerticalAlign : java/lang/Enum { diff --git a/plotlykt-core/build.gradle.kts b/plotlykt-core/build.gradle.kts index 99b02f45..8d71b322 100644 --- a/plotlykt-core/build.gradle.kts +++ b/plotlykt-core/build.gradle.kts @@ -3,32 +3,21 @@ plugins { `maven-publish` } -kscience { - useHtml() -} - val dataforgeVersion: String by rootProject.extra +val plotlyVersion: String by rootProject.extra -kotlin { - sourceSets { - commonMain { - dependencies { - api("space.kscience:dataforge-meta:$dataforgeVersion") - } - } - - jsMain { - dependencies { - api(npm("plotly.js", "1.54.6")) - } - } +kscience { + jvm() + js() + dependencies { + api("space.kscience:dataforge-meta:$dataforgeVersion") + api(spclibs.kotlinx.html) + } + dependencies(jsMain) { + api(npm("plotly.js", plotlyVersion)) } } -readme{ +readme { maturity = space.kscience.gradle.Maturity.DEVELOPMENT -} - -rootProject.extensions.configure { - versions.webpackCli.version = "4.10.0" } \ No newline at end of file diff --git a/plotlykt-geo/build.gradle.kts b/plotlykt-geo/build.gradle.kts index 1a0aed42..654ad926 100644 --- a/plotlykt-geo/build.gradle.kts +++ b/plotlykt-geo/build.gradle.kts @@ -3,13 +3,11 @@ plugins { `maven-publish` } -kotlin { - sourceSets { - commonMain { - dependencies { - api(project(":plotlykt-core")) - } - } +kscience{ + jvm() + js() + dependencies { + api(project(":plotlykt-core")) } } diff --git a/plotlykt-script/build.gradle.kts b/plotlykt-script/build.gradle.kts index de10b212..3e747251 100644 --- a/plotlykt-script/build.gradle.kts +++ b/plotlykt-script/build.gradle.kts @@ -5,7 +5,6 @@ plugins { } kscience{ - useHtml() application() } @@ -17,12 +16,13 @@ val ktorVersion: String by rootProject.extra val dataforgeVersion: String by rootProject.extra dependencies { - api(project(":plotlykt-core")) + api(projects.plotlyktCore) + api(spclibs.kotlinx.html) api(kotlin("scripting-jvm-host")) api(kotlin("scripting-jvm")) - api("io.github.microutils:kotlin-logging:1.8.3") - implementation("ch.qos.logback:logback-classic:1.2.3") - implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3") + api("io.github.microutils:kotlin-logging:3.0.5") + implementation(spclibs.logback.classic) + implementation(spclibs.kotlinx.cli) } application{ diff --git a/plotlykt-server/api/plotlykt-server.api b/plotlykt-server/api/plotlykt-server.api index 848ef5bf..0838e5d4 100644 --- a/plotlykt-server/api/plotlykt-server.api +++ b/plotlykt-server/api/plotlykt-server.api @@ -11,7 +11,7 @@ public final class space/kscience/plotly/server/MetaChangeCollectorKt { public final class space/kscience/plotly/server/PlotlyServer : kotlinx/coroutines/CoroutineScope, space/kscience/dataforge/meta/Configurable { public static final field Companion Lspace/kscience/plotly/server/PlotlyServer$Companion; public static final field DEFAULT_PAGE Ljava/lang/String; - public final fun getApplication ()Lio/ktor/application/Application; + public final fun getApplication ()Lio/ktor/server/application/Application; public fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext; public final fun getDataSourceHost ()Ljava/lang/String; public final fun getDataSourcePort ()Ljava/lang/Integer; @@ -56,8 +56,8 @@ public final class space/kscience/plotly/server/PlotlyServerKt { public static final fun close (Lio/ktor/server/engine/ApplicationEngine;)V public static final fun plot (Lspace/kscience/plotly/server/PlotlyServer;Ljava/lang/String;Lspace/kscience/plotly/PlotlyConfig;Lkotlin/jvm/functions/Function1;)V public static synthetic fun plot$default (Lspace/kscience/plotly/server/PlotlyServer;Ljava/lang/String;Lspace/kscience/plotly/PlotlyConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V - public static final fun plotlyModule (Lio/ktor/application/Application;Ljava/lang/String;)Lspace/kscience/plotly/server/PlotlyServer; - public static synthetic fun plotlyModule$default (Lio/ktor/application/Application;Ljava/lang/String;ILjava/lang/Object;)Lspace/kscience/plotly/server/PlotlyServer; + public static final fun plotlyModule (Lio/ktor/server/application/Application;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lspace/kscience/plotly/server/PlotlyServer; + public static synthetic fun plotlyModule$default (Lio/ktor/server/application/Application;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/plotly/server/PlotlyServer; public static final fun pullUpdates (Lspace/kscience/plotly/server/PlotlyServer;I)Lspace/kscience/plotly/server/PlotlyServer; public static synthetic fun pullUpdates$default (Lspace/kscience/plotly/server/PlotlyServer;IILjava/lang/Object;)Lspace/kscience/plotly/server/PlotlyServer; public static final fun pushUpdates (Lspace/kscience/plotly/server/PlotlyServer;I)Lspace/kscience/plotly/server/PlotlyServer; diff --git a/settings.gradle.kts b/settings.gradle.kts index bc3cfb37..aa8d2d52 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,6 @@ rootProject.name = "plotly-kt" enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -enableFeaturePreview("VERSION_CATALOGS") pluginManagement { @@ -33,7 +32,7 @@ dependencyResolutionManagement { } versionCatalogs { - create("npmlibs") { + create("spclibs") { from("space.kscience:version-catalog:$toolsVersion") } } From 01d26f4ccf89e275725b6ee43bbe9c7c53d3dc38 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 31 Mar 2023 12:16:48 +0300 Subject: [PATCH 02/10] Add secondary y axis API --- .../space/kscience/plotly/models/Axis.kt | 19 +++++++++++++++++++ .../space/kscience/plotly/models/Layout.kt | 10 ++++++++++ .../space/kscience/plotly/models/Scatter.kt | 6 ++++++ .../space/kscience/plotly/models/Trace.kt | 2 -- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt index 9868c5a4..1f552dbb 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt @@ -31,6 +31,10 @@ public enum class Ticks { outside } +public enum class AxisSide { + top, bottom, left, right +} + /** * Axis scheme */ @@ -259,6 +263,21 @@ public class Axis : Scheme() { */ public var position: Number by numberInRange(0.0..1.0) + /** + * Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area. + */ + public var side: AxisSide? by value( + writer = { it?.name?.asValue() }, + reader = { value -> value?.string?.let { enumValueOf(it) } } + ) + + /** + * If set a same-letter axis id, this axis is overlaid on top of the corresponding same-letter axis, + * with traces and axes visible for both axes. If "false", this axis does not overlay any same-letter axes. + * In this case, for axes with overlapping domains only the highest-numbered axis will be visible. + */ + public var overlaying: String? by string() + public fun title(block: Title.() -> Unit) { val spec = Title.write(meta.getOrCreate("title")) spec.apply(block) diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt index dca9ff71..68289cd6 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt @@ -4,6 +4,7 @@ package space.kscience.plotly.models import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.set +import space.kscience.dataforge.names.asName import space.kscience.plotly.appendAndAttach import space.kscience.plotly.list import space.kscience.plotly.numberGreaterThan @@ -286,6 +287,15 @@ public class Layout : Scheme() { yaxis.apply(block) } + /** + * Secondary y-axis. [index] must be 2 or more + */ + public fun yaxis(index: Int, block: Axis.() -> Unit) { + require(index >= 2) { "Secondary axis index must be 2 or more" } + val axisSpec by spec(Axis, "yaxis$index".asName()) + axisSpec.apply(block) + } + public fun annotation(an: Text) { meta.appendAndAttach("annotations", an.meta) } diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Scatter.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Scatter.kt index 39801820..4fe1b550 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Scatter.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Scatter.kt @@ -132,6 +132,12 @@ public open class Scatter : Trace(), SelectedPoints { */ public var stackgaps: StackGaps by enum(StackGaps.`infer zero`) + /** + * Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If "y" (the default value), + * the y coordinates refer to `layout.yaxis`. If "y2", the y coordinates refer to `layout.yaxis2`, and so on. + */ + public var yaxis: String by string("y") + public fun selected(block: SelectPoints.() -> Unit) { selected = SelectPoints(block) } diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Trace.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Trace.kt index ff93a25d..f4a4d316 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Trace.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Trace.kt @@ -41,10 +41,8 @@ public enum class TraceType { waterfall, // 3D - @UnsupportedPlotlyAPI scatter3d, - @UnsupportedPlotlyAPI surface, @UnsupportedPlotlyAPI From 736fb6cb24fc68de6c75c49f3e909da21cdb8b97 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 31 Mar 2023 14:12:31 +0300 Subject: [PATCH 03/10] Add images API --- examples/src/main/kotlin/misc/layoutImages.kt | 39 ++++++ plotlykt-core/api/plotlykt-core.api | 87 ++++++++++++ .../kotlin/space/kscience/plotly/dfExt.kt | 3 +- .../space/kscience/plotly/models/Images.kt | 130 ++++++++++++++++++ .../space/kscience/plotly/models/Layout.kt | 26 ++++ 5 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 examples/src/main/kotlin/misc/layoutImages.kt create mode 100644 plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Images.kt diff --git a/examples/src/main/kotlin/misc/layoutImages.kt b/examples/src/main/kotlin/misc/layoutImages.kt new file mode 100644 index 00000000..55684d29 --- /dev/null +++ b/examples/src/main/kotlin/misc/layoutImages.kt @@ -0,0 +1,39 @@ +package misc + +import space.kscience.plotly.Plotly +import space.kscience.plotly.layout +import space.kscience.plotly.makeFile +import space.kscience.plotly.models.ImageXAnchor +import space.kscience.plotly.models.ImageYAnchor +import space.kscience.plotly.scatter + +fun main() { + Plotly.plot { + scatter { + x(1, 2, 3) + y(1, 2, 3) + } + layout { + image { + source = "https://images.plot.ly/language-icons/api-home/python-logo.png" + x = 0.0 + y = 1.0 + sizex = 0.2 + sizey = 0.2 + xanchor = ImageXAnchor.right + yanchor = ImageYAnchor.bottom + } + image { + source = "https://images.plot.ly/language-icons/api-home/js-logo.png" + xref = "x" + yref = "y" + x = 1.5 + y = 2.0 + sizex = 1.0 + sizey = 1.0 + xanchor = ImageXAnchor.right + yanchor = ImageYAnchor.bottom + } + } + }.makeFile() +} \ No newline at end of file diff --git a/plotlykt-core/api/plotlykt-core.api b/plotlykt-core/api/plotlykt-core.api index 34b7d4cf..fb7a59d0 100644 --- a/plotlykt-core/api/plotlykt-core.api +++ b/plotlykt-core/api/plotlykt-core.api @@ -268,11 +268,13 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/ public final fun getGridwidth ()Ljava/lang/Number; public final fun getLinecolor ()Lspace/kscience/plotly/models/Color; public final fun getLinewidth ()Ljava/lang/Number; + public final fun getOverlaying ()Ljava/lang/String; public final fun getPosition ()Ljava/lang/Number; public final fun getRange ()Lkotlin/ranges/ClosedFloatingPointRange; public final fun getShowgrid ()Ljava/lang/Boolean; public final fun getShowline ()Ljava/lang/Boolean; public final fun getShowticklabels ()Ljava/lang/Boolean; + public final fun getSide ()Lspace/kscience/plotly/models/AxisSide; public final fun getTickangle ()Ljava/lang/Number; public final fun getTickcolor ()Lspace/kscience/plotly/models/Color; public final fun getTickfont ()Lspace/kscience/plotly/models/Font; @@ -298,11 +300,13 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/ public final fun setDtick (Lspace/kscience/dataforge/meta/Value;)V public final fun setGridwidth (Ljava/lang/Number;)V public final fun setLinewidth (Ljava/lang/Number;)V + public final fun setOverlaying (Ljava/lang/String;)V public final fun setPosition (Ljava/lang/Number;)V public final fun setRange (Lkotlin/ranges/ClosedFloatingPointRange;)V public final fun setShowgrid (Ljava/lang/Boolean;)V public final fun setShowline (Ljava/lang/Boolean;)V public final fun setShowticklabels (Ljava/lang/Boolean;)V + public final fun setSide (Lspace/kscience/plotly/models/AxisSide;)V public final fun setTickangle (Ljava/lang/Number;)V public final fun setTickfont (Lspace/kscience/plotly/models/Font;)V public final fun setTicklen (Ljava/lang/Number;)V @@ -325,6 +329,15 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/ public final class space/kscience/plotly/models/Axis$Companion : space/kscience/dataforge/meta/SchemeSpec { } +public final class space/kscience/plotly/models/AxisSide : java/lang/Enum { + public static final field bottom Lspace/kscience/plotly/models/AxisSide; + public static final field left Lspace/kscience/plotly/models/AxisSide; + public static final field right Lspace/kscience/plotly/models/AxisSide; + public static final field top Lspace/kscience/plotly/models/AxisSide; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/plotly/models/AxisSide; + public static fun values ()[Lspace/kscience/plotly/models/AxisSide; +} + public final class space/kscience/plotly/models/AxisType : java/lang/Enum { public static final field - Lspace/kscience/plotly/models/AxisType; public static final field category Lspace/kscience/plotly/models/AxisType; @@ -1105,6 +1118,75 @@ public final class space/kscience/plotly/models/Hoverlabel : space/kscience/data public final class space/kscience/plotly/models/Hoverlabel$Companion : space/kscience/dataforge/meta/SchemeSpec { } +public final class space/kscience/plotly/models/Image : space/kscience/dataforge/meta/Scheme { + public static final field Companion Lspace/kscience/plotly/models/Image$Companion; + public fun ()V + public final fun getLayer ()Lspace/kscience/plotly/models/ImageLayer; + public final fun getName ()Ljava/lang/String; + public final fun getOpacity ()D + public final fun getSizex ()D + public final fun getSizey ()D + public final fun getSizing ()Lspace/kscience/plotly/models/ImageSizing; + public final fun getSource ()Ljava/lang/String; + public final fun getTemplateitemname ()Ljava/lang/String; + public final fun getVisible ()Z + public final fun getX ()D + public final fun getXanchor ()Lspace/kscience/plotly/models/ImageXAnchor; + public final fun getXref ()Ljava/lang/String; + public final fun getY ()D + public final fun getYanchor ()Lspace/kscience/plotly/models/ImageYAnchor; + public final fun getYref ()Ljava/lang/String; + public final fun setLayer (Lspace/kscience/plotly/models/ImageLayer;)V + public final fun setName (Ljava/lang/String;)V + public final fun setOpacity (D)V + public final fun setSizex (D)V + public final fun setSizey (D)V + public final fun setSizing (Lspace/kscience/plotly/models/ImageSizing;)V + public final fun setSource (Ljava/lang/String;)V + public final fun setTemplateitemname (Ljava/lang/String;)V + public final fun setVisible (Z)V + public final fun setX (D)V + public final fun setXanchor (Lspace/kscience/plotly/models/ImageXAnchor;)V + public final fun setXref (Ljava/lang/String;)V + public final fun setY (D)V + public final fun setYanchor (Lspace/kscience/plotly/models/ImageYAnchor;)V + public final fun setYref (Ljava/lang/String;)V +} + +public final class space/kscience/plotly/models/Image$Companion : space/kscience/dataforge/meta/SchemeSpec { +} + +public final class space/kscience/plotly/models/ImageLayer : java/lang/Enum { + public static final field above Lspace/kscience/plotly/models/ImageLayer; + public static final field below Lspace/kscience/plotly/models/ImageLayer; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/plotly/models/ImageLayer; + public static fun values ()[Lspace/kscience/plotly/models/ImageLayer; +} + +public final class space/kscience/plotly/models/ImageSizing : java/lang/Enum { + public static final field contain Lspace/kscience/plotly/models/ImageSizing; + public static final field fill Lspace/kscience/plotly/models/ImageSizing; + public static final field stretch Lspace/kscience/plotly/models/ImageSizing; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/plotly/models/ImageSizing; + public static fun values ()[Lspace/kscience/plotly/models/ImageSizing; +} + +public final class space/kscience/plotly/models/ImageXAnchor : java/lang/Enum { + public static final field center Lspace/kscience/plotly/models/ImageXAnchor; + public static final field left Lspace/kscience/plotly/models/ImageXAnchor; + public static final field right Lspace/kscience/plotly/models/ImageXAnchor; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/plotly/models/ImageXAnchor; + public static fun values ()[Lspace/kscience/plotly/models/ImageXAnchor; +} + +public final class space/kscience/plotly/models/ImageYAnchor : java/lang/Enum { + public static final field bottom Lspace/kscience/plotly/models/ImageYAnchor; + public static final field middle Lspace/kscience/plotly/models/ImageYAnchor; + public static final field top Lspace/kscience/plotly/models/ImageYAnchor; + public static fun valueOf (Ljava/lang/String;)Lspace/kscience/plotly/models/ImageYAnchor; + public static fun values ()[Lspace/kscience/plotly/models/ImageYAnchor; +} + public final class space/kscience/plotly/models/Layout : space/kscience/dataforge/meta/Scheme { public static final field Companion Lspace/kscience/plotly/models/Layout$Companion; public fun ()V @@ -1140,6 +1222,8 @@ public final class space/kscience/plotly/models/Layout : space/kscience/dataforg public final fun getWidth ()Ljava/lang/Number; public final fun getXaxis ()Lspace/kscience/plotly/models/Axis; public final fun getYaxis ()Lspace/kscience/plotly/models/Axis; + public final fun image (Lkotlin/jvm/functions/Function1;)V + public final fun image (Lspace/kscience/plotly/models/Image;)V public final fun legend (Lkotlin/jvm/functions/Function1;)V public final fun margin (Lkotlin/jvm/functions/Function1;)V public final fun setAnnotations (Ljava/util/List;)V @@ -1170,6 +1254,7 @@ public final class space/kscience/plotly/models/Layout : space/kscience/dataforg public final fun setYaxis (Lspace/kscience/plotly/models/Axis;)V public final fun title (Lkotlin/jvm/functions/Function1;)V public final fun xaxis (Lkotlin/jvm/functions/Function1;)V + public final fun yaxis (ILkotlin/jvm/functions/Function1;)V public final fun yaxis (Lkotlin/jvm/functions/Function1;)V } @@ -1428,6 +1513,7 @@ public class space/kscience/plotly/models/Scatter : space/kscience/plotly/models public final fun getStackgaps ()Lspace/kscience/plotly/models/StackGaps; public final fun getStackgroup ()Ljava/lang/String; public fun getUnselected ()Lspace/kscience/plotly/models/SelectPoints; + public final fun getYaxis ()Ljava/lang/String; public final fun selected (Lkotlin/jvm/functions/Function1;)V public final fun setFill (Lspace/kscience/plotly/models/FillType;)V public final fun setGroupnorm (Lspace/kscience/plotly/models/GroupNorm;)V @@ -1438,6 +1524,7 @@ public class space/kscience/plotly/models/Scatter : space/kscience/plotly/models public final fun setStackgaps (Lspace/kscience/plotly/models/StackGaps;)V public final fun setStackgroup (Ljava/lang/String;)V public fun setUnselected (Lspace/kscience/plotly/models/SelectPoints;)V + public final fun setYaxis (Ljava/lang/String;)V public final fun unselected (Lkotlin/jvm/functions/Function1;)V } diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/dfExt.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/dfExt.kt index 4ab34d3a..a9b4f2bc 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/dfExt.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/dfExt.kt @@ -70,11 +70,12 @@ internal fun Scheme.listOfValues( */ internal fun Scheme.doubleInRange( range: ClosedFloatingPointRange, + defaultValue: Double = Double.NaN, key: Name? = null, ): ReadWriteProperty = object : ReadWriteProperty { override fun getValue(thisRef: Any?, property: KProperty<*>): Double { val name = key ?: property.name.asName() - return meta[name].double ?: Double.NaN + return meta[name].double ?: defaultValue } override fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) { diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Images.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Images.kt new file mode 100644 index 00000000..26a8343b --- /dev/null +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Images.kt @@ -0,0 +1,130 @@ +package space.kscience.plotly.models + +import space.kscience.dataforge.meta.* +import space.kscience.plotly.doubleInRange + + +public enum class ImageLayer { + below, above +} + +public enum class ImageSizing { + fill, contain, stretch +} + +public enum class ImageXAnchor { + left, center, right +} + +public enum class ImageYAnchor { + top, middle, bottom +} + +public class Image : Scheme() { + /** + * Specifies whether images are drawn below or above traces. When `xref` and `yref` are both set to `paper`, + * image is drawn below the entire plot area. + */ + public var layer: ImageLayer by enum(ImageLayer.above) + + /** + * When used in a template, named items are created in the output figure in addition to any items the figure + * already has in this array. You can modify these items in the output figure by making your own item with + * `templateitemname` matching this `name` alongside your modifications (including `visible: false` or + * `enabled: false` to hide it). Has no effect outside of a template. + */ + public var name: String? by string() + + + /** + * Sets the opacity of the image. + */ + public var opacity: Double by doubleInRange(0.0..1.0, 0.0) + + /** + * Sets the image container size horizontally. The image will be sized based on the `position` value . + * When `xref` is set to `paper`, units are sized relative to the plot width. When `xref` ends with ` domain`, + * units are sized relative to the axis width. + */ + public var sizex: Double by double(0.0) + + + /** + * Sets the image container size vertically. The image will be sized based on the `position` value . + * When `yref` is set to `paper`, units are sized relative to the plot height. When `yref` ends with ` domain`, + * units are sized relative to the axis height. + */ + public var sizey: Double by double(0.0) + + + /** + * Specifies which dimension of the image to constrain. + */ + public var sizing: ImageSizing by enum(ImageSizing.contain) + + /** + * Specifies the URL of the image to be used. The URL must be accessible from the domain where the plot code is run, + * and can be either relative or absolute. + */ + public var source: String? by string() + + /** + * Used to refer to a named item in this array in the template. Named items from the template will be created even + * without a matching item in the input figure, but you can modify one by making an item with `templateitemname` + * matching its `name`, alongside your modifications (including `visible: false` or `enabled: false` to hide it). + * If there is no template or no matching item, this item will be hidden unless you explicitly show it with `visible: true`. + */ + public var templateitemname: String? by string() + + /** + * Determines whether this image is visible. + */ + public var visible: Boolean by boolean(true) + + + /** + * Sets the image's x position. When `xref` is set to `paper`, units are sized relative to the plot height. See `xref` for more info + */ + public var x: Double by double(0.0) + + + /** + * Sets the anchor for the x position + */ + public var xanchor: ImageXAnchor by enum(ImageXAnchor.left) + + + /** + * Sets the images's x coordinate axis. If set to a x axis id (e.g. "x" or "x2"), the `x` position refers to + * a x coordinate. If set to "paper", the `x` position refers to the distance from the left of the plotting + * area in normalized coordinates where "0" ("1") corresponds to the left (right). If set to a x axis ID followed + * by "domain" (separated by a space), the position behaves like for "paper", but refers to the distance in fractions + * of the domain length from the left of the domain of that axis: e.g., "x2 domain" refers to the domain of the + * second x axis and a x position of 0.5 refers to the point between the left and the right of the domain of the second x axis. + */ + public var xref: String by string("paper") + + /** + * Sets the image's y position. When `yref` is set to `paper`, units are sized relative to the plot height. See `yref` for more info + */ + public var y: Double by double(0.0) + + /** + * Sets the anchor for the y position. + */ + public var yanchor: ImageYAnchor by enum(ImageYAnchor.top) + + /** + * Sets the images's y coordinate axis. If set to a y axis id (e.g. "y" or "y2"), the `y` position refers to a y + * coordinate. If set to "paper", the `y` position refers to the distance from the bottom of the plotting area in + * normalized coordinates where "0" ("1") corresponds to the bottom (top). If set to a y axis ID followed by "domain" + * (separated by a space), the position behaves like for "paper", but refers to the distance in fractions of the + * domain length from the bottom of the domain of that axis: e.g., "y2 domain" refers to the domain of the second + * y axis and a y position of 0.5 refers to the point between the bottom and the top of the domain of the second y axis. + */ + public var yref: String by string("paper") + + public companion object : SchemeSpec(::Image) { + + } +} \ No newline at end of file diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt index 68289cd6..f502f88e 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Layout.kt @@ -296,22 +296,48 @@ public class Layout : Scheme() { axisSpec.apply(block) } + /** + * Add a [Text] annotation to layout + */ public fun annotation(an: Text) { meta.appendAndAttach("annotations", an.meta) } + /** + * Add a [Text] annotation to layout + */ public fun annotation(anBuilder: Text.() -> Unit) { annotation(Text(anBuilder)) } + /** + * Add a [Shape] to layout + */ public fun figure(sh: Shape) { meta.appendAndAttach("shapes", sh.meta) } + /** + * Add a [Shape] to layout + */ public fun figure(shBuilder: Shape.() -> Unit) { figure(Shape(shBuilder)) } + /** + * Add an image to the layout + */ + public fun image(image: Image) { + meta.appendAndAttach("images", image.meta) + } + + /** + * Add an image to the layout + */ + public fun image(block: Image.() -> Unit) { + image(Image(block)) + } + public fun margin(block: Margin.() -> Unit) { margin = Margin(block) } From 0ad2068d6a18541d726d0264dab8892707c5d570 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 31 Mar 2023 15:16:59 +0300 Subject: [PATCH 04/10] Add native support (???) --- CHANGELOG.md | 3 + examples/native-demo/build.gradle.kts | 27 +++++ .../src/mingwX64Main/kotlin/plotlyMain.kt | 13 ++ plotlykt-core/api/plotlykt-core.api | 6 +- plotlykt-core/build.gradle.kts | 5 + .../space/kscience/plotly/PlotlyRenderer.kt | 0 .../kotlin/space/kscience/plotly/html.kt | 64 ++++++++++ .../space/kscience/plotly/models/Axis.kt | 2 +- .../kotlin/space/kscience/plotly/html.kt | 111 ------------------ .../space/kscience/plotly/plotlyHeaders.kt | 52 +++++++- .../kotlin/space/kscience/plotly/makeFile.kt | 20 ++++ plotlykt-geo/build.gradle.kts | 1 + .../plotly/server/PlotlyServerIntegration.kt | 4 +- settings.gradle.kts | 3 +- 14 files changed, 190 insertions(+), 121 deletions(-) create mode 100644 examples/native-demo/build.gradle.kts create mode 100644 examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt rename plotlykt-core/src/{jvmMain => commonMain}/kotlin/space/kscience/plotly/PlotlyRenderer.kt (100%) create mode 100644 plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt delete mode 100644 plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/html.kt create mode 100644 plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f139b95..a4040b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- API for background images (https://github.com/SciProgCentre/plotly.kt/issues/49) +- API for multiple Y axis (https://github.com/SciProgCentre/plotly.kt/issues/92) +- Native support - `plotlykt module` with basic Geo API - DataSourceHost/DataSourcePost to configure custom networks diff --git a/examples/native-demo/build.gradle.kts b/examples/native-demo/build.gradle.kts new file mode 100644 index 00000000..1f6116d5 --- /dev/null +++ b/examples/native-demo/build.gradle.kts @@ -0,0 +1,27 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("multiplatform") +} + +repositories { + mavenCentral() + maven("https://repo.kotlin.link") +} + +kotlin { + mingwX64{ + binaries.executable() + } + sourceSets{ + commonMain { + dependencies { + implementation(project(":plotlykt-core")) + } + } + } +} + +tasks.withType { + kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs +"-Xopt-in=kotlin.RequiresOptIn" +} diff --git a/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt b/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt new file mode 100644 index 00000000..0cda3050 --- /dev/null +++ b/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt @@ -0,0 +1,13 @@ +import okio.Path.Companion.toPath +import space.kscience.plotly.Plotly +import space.kscience.plotly.makeFile +import space.kscience.plotly.scatter + +fun main() { + Plotly.plot { + scatter { + x(1,2,3) + y(5,8,10) + } + }.makeFile("plotly.html".toPath()) +} \ No newline at end of file diff --git a/plotlykt-core/api/plotlykt-core.api b/plotlykt-core/api/plotlykt-core.api index fb7a59d0..3db8e9b4 100644 --- a/plotlykt-core/api/plotlykt-core.api +++ b/plotlykt-core/api/plotlykt-core.api @@ -24,9 +24,8 @@ public final class space/kscience/plotly/FileExportKt { } public final class space/kscience/plotly/HtmlKt { + public static final fun getCdnPlotlyHeader ()Lspace/kscience/plotly/PlotlyHtmlFragment; public static final fun getMathJaxHeader ()Lspace/kscience/plotly/PlotlyHtmlFragment; - public static final fun localCssHeader (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/lang/String;)Lspace/kscience/plotly/PlotlyHtmlFragment; - public static final fun localScriptHeader (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/lang/String;)Lspace/kscience/plotly/PlotlyHtmlFragment; public static final fun plus (Lspace/kscience/plotly/PlotlyHtmlFragment;Lspace/kscience/plotly/PlotlyHtmlFragment;)Lspace/kscience/plotly/PlotlyHtmlFragment; public static final fun toHTML (Lspace/kscience/plotly/Plot;[Lspace/kscience/plotly/PlotlyHtmlFragment;Lspace/kscience/plotly/PlotlyConfig;)Ljava/lang/String; public static synthetic fun toHTML$default (Lspace/kscience/plotly/Plot;[Lspace/kscience/plotly/PlotlyHtmlFragment;Lspace/kscience/plotly/PlotlyConfig;ILjava/lang/Object;)Ljava/lang/String; @@ -180,7 +179,8 @@ public final class space/kscience/plotly/PlotlyFragment { } public final class space/kscience/plotly/PlotlyHeadersKt { - public static final fun getCdnPlotlyHeader ()Lspace/kscience/plotly/PlotlyHtmlFragment; + public static final fun localCssHeader (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/lang/String;)Lspace/kscience/plotly/PlotlyHtmlFragment; + public static final fun localScriptHeader (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/lang/String;)Lspace/kscience/plotly/PlotlyHtmlFragment; } public final class space/kscience/plotly/PlotlyHtmlFragment { diff --git a/plotlykt-core/build.gradle.kts b/plotlykt-core/build.gradle.kts index 8d71b322..918623e7 100644 --- a/plotlykt-core/build.gradle.kts +++ b/plotlykt-core/build.gradle.kts @@ -9,6 +9,7 @@ val plotlyVersion: String by rootProject.extra kscience { jvm() js() + native() dependencies { api("space.kscience:dataforge-meta:$dataforgeVersion") api(spclibs.kotlinx.html) @@ -16,6 +17,10 @@ kscience { dependencies(jsMain) { api(npm("plotly.js", plotlyVersion)) } + + dependencies(nativeMain) { + implementation("com.squareup.okio:okio:3.3.0") + } } readme { diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotlyRenderer.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyRenderer.kt similarity index 100% rename from plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotlyRenderer.kt rename to plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyRenderer.kt diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt new file mode 100644 index 00000000..82b9cbd9 --- /dev/null +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/html.kt @@ -0,0 +1,64 @@ +package space.kscience.plotly + +import kotlinx.html.* +import kotlinx.html.stream.createHTML + + +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 { + script { + type = "text/javascript" + src = Plotly.PLOTLY_CDN + } +} + +/** + * Create a html (including headers) string from plot + */ +public fun Plot.toHTML( + vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), + config: PlotlyConfig = PlotlyConfig(), +): String = createHTML().html { + head { + meta { + charset = "utf-8" + } + title(layout.title ?: "Plotly.kt") + headers.forEach { + it.visit(consumer) + } + } + body { + StaticPlotlyRenderer.run { + renderPlot(this@toHTML, this@toHTML.toString(), config) + } + } +} + +public val mathJaxHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { + script { + type = "text/x-mathjax-config" + unsafe { + +""" + MathJax.Hub.Config({ + tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} + }); + """ + } + } + script { + type = "text/javascript" + async = true + src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_SVG" + } +} \ No newline at end of file diff --git a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt index 1f552dbb..4145522e 100644 --- a/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt +++ b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/models/Axis.kt @@ -24,7 +24,7 @@ public enum class TickMode { } public enum class Ticks { - @Suppress("EnumEntryName") + @Suppress("EnumEntryName", "DANGEROUS_CHARACTERS") @JsName("empty") `""`, inside, diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/html.kt b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/html.kt deleted file mode 100644 index 4f3cdbd2..00000000 --- a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/html.kt +++ /dev/null @@ -1,111 +0,0 @@ -package space.kscience.plotly - -import kotlinx.html.* -import kotlinx.html.stream.createHTML -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.StandardOpenOption - -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() } -} - -/** - * Create a html (including headers) string from plot - */ -public fun Plot.toHTML( - vararg headers: PlotlyHtmlFragment = arrayOf(cdnPlotlyHeader), - config: PlotlyConfig = PlotlyConfig(), -): String = createHTML().html { - head { - meta { - charset = "utf-8" - } - title(layout.title ?: "Plotly.kt") - headers.forEach { - it.visit(consumer) - } - } - body { - StaticPlotlyRenderer.run { - renderPlot(this@toHTML, this@toHTML.toString(), config) - } - } -} - -/** - * Check if the asset exists in given local location and put it there if it does not - */ -internal fun checkOrStoreFile(basePath: Path, filePath: Path, resource: String): Path { - val fullPath = basePath.resolveSibling(filePath).toAbsolutePath() - - if (Files.exists(fullPath)) { - //TODO checksum - } else { - //TODO add logging - - val bytes = PlotlyHtmlFragment::class.java.getResourceAsStream(resource)!!.readAllBytes() - Files.createDirectories(fullPath.parent) - Files.write(fullPath, bytes, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) - } - - return if (basePath.isAbsolute && fullPath.startsWith(basePath)) { - basePath.relativize(fullPath) - } else { - filePath - } -} - -/** - * A header that automatically copies relevant scripts to given path - */ -public fun localScriptHeader( - basePath: Path, - scriptPath: Path, - resource: String, -): PlotlyHtmlFragment = PlotlyHtmlFragment { - val relativePath = checkOrStoreFile(basePath, scriptPath, resource) - script { - type = "text/javascript" - src = relativePath.toString() - attributes["onload"] = "console.log('Script successfully loaded from $relativePath')" - attributes["onerror"] = "console.log('Failed to load script from $relativePath')" - } -} - -public fun localCssHeader( - basePath: Path, - cssPath: Path, - resource: String, -): PlotlyHtmlFragment = PlotlyHtmlFragment { - val relativePath = checkOrStoreFile(basePath, cssPath, resource) - link { - rel = "stylesheet" - href = relativePath.toString() - } -} - -public val mathJaxHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { - script { - type = "text/x-mathjax-config" - unsafe { - +""" - MathJax.Hub.Config({ - tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} - }); - """ - } - } - script { - type = "text/javascript" - async = true - src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_SVG" - } -} \ No newline at end of file diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt index 31c3d002..73abd52f 100644 --- a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt +++ b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/plotlyHeaders.kt @@ -1,18 +1,64 @@ package space.kscience.plotly +import kotlinx.html.link import kotlinx.html.script import kotlinx.html.unsafe -import space.kscience.plotly.Plotly.PLOTLY_CDN +import java.nio.file.Files import java.nio.file.Path +import java.nio.file.StandardOpenOption internal const val PLOTLY_SCRIPT_PATH = "/js/plotly.min.js" //const val PLOTLY_PROMISE_NAME = "promiseOfPlotly" +/** + * Check if the asset exists in given local location and put it there if it does not + */ +internal fun checkOrStoreFile(basePath: Path, filePath: Path, resource: String): Path { + val fullPath = basePath.resolveSibling(filePath).toAbsolutePath() + + if (Files.exists(fullPath)) { + //TODO checksum + } else { + //TODO add logging + + val bytes = PlotlyHtmlFragment::class.java.getResourceAsStream(resource)!!.readAllBytes() + Files.createDirectories(fullPath.parent) + Files.write(fullPath, bytes, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE) + } + + return if (basePath.isAbsolute && fullPath.startsWith(basePath)) { + basePath.relativize(fullPath) + } else { + filePath + } +} -public val cdnPlotlyHeader: PlotlyHtmlFragment = PlotlyHtmlFragment { +/** + * A header that automatically copies relevant scripts to given path + */ +public fun localScriptHeader( + basePath: Path, + scriptPath: Path, + resource: String, +): PlotlyHtmlFragment = PlotlyHtmlFragment { + val relativePath = checkOrStoreFile(basePath, scriptPath, resource) script { type = "text/javascript" - src = PLOTLY_CDN + src = relativePath.toString() + attributes["onload"] = "console.log('Script successfully loaded from $relativePath')" + attributes["onerror"] = "console.log('Failed to load script from $relativePath')" + } +} + +public fun localCssHeader( + basePath: Path, + cssPath: Path, + resource: String, +): PlotlyHtmlFragment = PlotlyHtmlFragment { + val relativePath = checkOrStoreFile(basePath, cssPath, resource) + link { + rel = "stylesheet" + href = relativePath.toString() } } diff --git a/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt b/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt new file mode 100644 index 00000000..57670452 --- /dev/null +++ b/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt @@ -0,0 +1,20 @@ +package space.kscience.plotly + +import okio.FileSystem +import okio.Path + +/** + * Create a standalone html with the plot + * @param path the reference to html file. If null, create a temporary file + * @param show if true, start the browser after file is created + * @param config represents plotly frame configuration + */ +@UnstablePlotlyAPI +public fun Plot.makeFile( + path: Path, + config: PlotlyConfig = PlotlyConfig(), +) { + FileSystem.SYSTEM.write(path, true) { + writeUtf8( toHTML(cdnPlotlyHeader, config = config)) + } +} \ No newline at end of file diff --git a/plotlykt-geo/build.gradle.kts b/plotlykt-geo/build.gradle.kts index 654ad926..d6ff96fc 100644 --- a/plotlykt-geo/build.gradle.kts +++ b/plotlykt-geo/build.gradle.kts @@ -6,6 +6,7 @@ plugins { kscience{ jvm() js() + native() dependencies { api(project(":plotlykt-core")) } diff --git a/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt b/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt index f665fa94..8db03cc7 100644 --- a/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt +++ b/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServerIntegration.kt @@ -176,12 +176,12 @@ internal class PlotlyServerIntegration : JupyterIntegration() { logger.info("Starting JupyterPlotlyServer with $config") val serverStart = start(config) logger.info("JupyterPlotlyServer started with $config") - display(HTML(serverStart.toString())) + display(HTML(serverStart.toString()), null) } onShutdown { logger.info("Stopping JupyterPlotlyServer") - display(HTML(stop().toString())) + display(HTML(stop().toString()), null) } } diff --git a/settings.gradle.kts b/settings.gradle.kts index aa8d2d52..0091c83d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,5 +46,6 @@ include( ":plotlykt-script", ":examples", ":examples:fx-demo", - ":examples:js-demo" + ":examples:js-demo", + ":examples:native-demo" ) \ No newline at end of file From 7fccacac54c6a9a0714a3196bf1b3a9393e0ffbb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 1 Apr 2023 11:47:30 +0300 Subject: [PATCH 05/10] Ready for 0.5.3 release. --- CHANGELOG.md | 66 +++++++++---------- README.md | 10 +-- docs/templates/README-TEMPLATE.md | 10 +-- .../src/mingwX64Main/kotlin/plotlyMain.kt | 52 ++++++++++++--- examples/src/main/kotlin/customPage.kt | 2 +- examples/src/main/kotlin/gridPageLayout.kt | 1 + examples/src/main/kotlin/tabPageLayout.kt | 1 + plotlykt-core/README.md | 6 +- .../space/kscience/plotly/PlotlyPage.kt | 0 .../kotlin/space/kscience/plotly/PlotGrid.kt | 2 + .../kotlin/space/kscience/plotly/PlotTabs.kt | 3 + .../kotlin/space/kscience/plotly/makeFile.kt | 28 +++++++- plotlykt-geo/README.md | 6 +- plotlykt-jupyter/README.md | 6 +- plotlykt-script/README.md | 6 +- plotlykt-server/README.md | 6 +- 16 files changed, 138 insertions(+), 67 deletions(-) rename plotlykt-core/src/{jvmMain => commonMain}/kotlin/space/kscience/plotly/PlotlyPage.kt (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4040b83..5d6187f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,25 @@ # Changelog - All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## Unreleased + +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## 0.5.3 - 2023-04-01 + ### Added - API for background images (https://github.com/SciProgCentre/plotly.kt/issues/49) - API for multiple Y axis (https://github.com/SciProgCentre/plotly.kt/issues/92) @@ -14,14 +28,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - DataSourceHost/DataSourcePost to configure custom networks ### Changed +- Kotlin 1.8.20 - Moved renderers to JVM to avoid confusion with JS direct element rendering. - DataForge 0.6 -- Replaced krangl by Kotlin-DataFrame +- Replaced krangl by Kotlin-DataFrame in examples - Plotly server uses push strategy by default - Renderers moved to common - Moved to Ktor 2.0 ### Deprecated +- Page layout. Use VisionForge for that. ### Removed - Moved CORS to `Plotly.serve` @@ -31,13 +47,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #85 - Rendering in JS that used backend HTML generation -### Security -## [0.5.0] +## 0.5.0 ### Changed - Switch to DataForge 0.5 -- -## [0.4.4] +- + +## 0.4.4 + ### Added - Candlestick support - Range builders for axis @@ -49,22 +66,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated - Direct usage of `range` in axis -### Removed - ### Fixed - #80 - Plotly coordinate array wrap is moved to the server side -### Security -## [0.4.3] +## 0.4.3 ### Fixed - Proper deserialization of single plot. - A bug in jupyter lab visualization -### Security - -## [0.4.2] +## 0.4.2 ### Added - `automargin` property to `Axis` according to https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-automargin @@ -73,8 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove unnecessary `kotlinx-css` dependency. - Added compatibility mode for legacy notebooks. Use `Plotly.jupyter.notebook()` call to enable legacy mode. -### Security -## [0.4.0] +## 0.4.0 + ### Added - Jupyter integration plugin for server - Separate static plot integration module in `plotlykt-jupyter` @@ -87,17 +99,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Kotlin `1.5.0` - HtmlFragment renamed to PlotlyHtmlFragment -### Deprecated - ### Removed - Local bootstrap ### Fixed - Incomplete coverage in JS (#70) -### Security +## 0.3.1 -## [0.3.1] ### Added - Table widget implementation by @ArtificialPB - Mathjax header promoted to stable @@ -108,23 +117,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking API change!** Trace `text` replaced by `TraceValues` - Moved to DataForge 0.3 API - Kotlin 1.4.30 -- **JVM-IR** +- **JVM-IR** - Plot `Config` moved to constructor - Replaced direct color accessor by a delegate -### Deprecated - -### Removed - ### Fixed - https://github.com/mipt-npm/plotly.kt/issues/53 - Add JQuery to Bootstrap headers -### Security - -## [0.3.0] -### Added --Support for `plotly.kts` in IDEA +## 0.3.0 ### Changed - Serialization API is encapsulated (not longer exposed) in order to provide compatibility with new serialization. @@ -135,7 +136,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - https://github.com/mipt-npm/plotly.kt/issues/51 -## [0.2.0] +## 0.2.0 ### Added - Experimental scripting support @@ -144,7 +145,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Color palettes (T10 and XKCD) - New parameters and classes in Trace, Legend, Layout - Parameters description -- naming.md with decisions about parameters and methods names +- naming.md with decisions about parameters and methods names - Error bars - New scatter, contour, error plots examples - Interfaces with common parameters for some plots (Histogram, Contour, Heatmap) @@ -155,7 +156,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - TraceValues extension for krangl columns ### Changed - - Migrated from `scientifik` to `kscience` - Refactored packages to better suit star import style - Removed bootstrap dependency diff --git a/README.md b/README.md index c63370da..9467f7c3 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,13 @@ This project is developed to allow simple access to plotly functionality from ko The library supports three drawable plot objects: * `Plot` itself stands for a stand-alone plot frame. It requires external infrastructure to load appropriate JavaScript libraries. -* `PlotFragment` (JVM only) is an HTML fragment possibly including several plots. The API for html is provided by [kotlinx-html](https://github.com/Kotlin/kotlinx.html) library. -* `PlotlyPage` (JVM only) is a complete page, including body fragment and page headers (needed to load JavaScript part of Plotly). +* `PlotFragment` is an HTML fragment possibly including several plots. The API for html is provided by [kotlinx-html](https://github.com/Kotlin/kotlinx.html) library. +* `PlotlyPage` is a complete page, including body fragment and page headers (needed to load JavaScript part of Plotly). The work with plotly graphs could be rendered in following modes: ## HTML page export -(JVM only) Export plot or a plot grid in a standalone html file, which -uses CDN based plotly distribution. This mode does not support updates. +(JVM and native) Export plot or page in a standalone html file, using CDN distribution or local JS file (JVM only). This mode does not support updates. See [staticPlot](./examples/src/main/kotlin/staticPlot.kt) and [customPage](./examples/src/main/kotlin/customPage.kt) for examples. @@ -72,6 +71,9 @@ The module `plotly-server` adds server capabilities and allows to render dynamic ## Kotlin-scripting (experimental) It is possible to separate script logic into stand-alone `plotly.kts` script file and generate an html from the command line. See [plotlykt-script](./plotlykt-script) module for details. +## Kotlin/Native (experimental) +Plotly model now fully supports Kotlin/Native. It means that you can use it to create a proper Plotly-based HTML file. You will still need browser to view it. You can use [native-demo](./examples/native-demo) example. + # The feature I need is not implemented! There are three ways to solve it: diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md index c63370da..9467f7c3 100644 --- a/docs/templates/README-TEMPLATE.md +++ b/docs/templates/README-TEMPLATE.md @@ -24,14 +24,13 @@ This project is developed to allow simple access to plotly functionality from ko The library supports three drawable plot objects: * `Plot` itself stands for a stand-alone plot frame. It requires external infrastructure to load appropriate JavaScript libraries. -* `PlotFragment` (JVM only) is an HTML fragment possibly including several plots. The API for html is provided by [kotlinx-html](https://github.com/Kotlin/kotlinx.html) library. -* `PlotlyPage` (JVM only) is a complete page, including body fragment and page headers (needed to load JavaScript part of Plotly). +* `PlotFragment` is an HTML fragment possibly including several plots. The API for html is provided by [kotlinx-html](https://github.com/Kotlin/kotlinx.html) library. +* `PlotlyPage` is a complete page, including body fragment and page headers (needed to load JavaScript part of Plotly). The work with plotly graphs could be rendered in following modes: ## HTML page export -(JVM only) Export plot or a plot grid in a standalone html file, which -uses CDN based plotly distribution. This mode does not support updates. +(JVM and native) Export plot or page in a standalone html file, using CDN distribution or local JS file (JVM only). This mode does not support updates. See [staticPlot](./examples/src/main/kotlin/staticPlot.kt) and [customPage](./examples/src/main/kotlin/customPage.kt) for examples. @@ -72,6 +71,9 @@ The module `plotly-server` adds server capabilities and allows to render dynamic ## Kotlin-scripting (experimental) It is possible to separate script logic into stand-alone `plotly.kts` script file and generate an html from the command line. See [plotlykt-script](./plotlykt-script) module for details. +## Kotlin/Native (experimental) +Plotly model now fully supports Kotlin/Native. It means that you can use it to create a proper Plotly-based HTML file. You will still need browser to view it. You can use [native-demo](./examples/native-demo) example. + # The feature I need is not implemented! There are three ways to solve it: diff --git a/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt b/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt index 0cda3050..968d4966 100644 --- a/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt +++ b/examples/native-demo/src/mingwX64Main/kotlin/plotlyMain.kt @@ -1,13 +1,47 @@ -import okio.Path.Companion.toPath -import space.kscience.plotly.Plotly -import space.kscience.plotly.makeFile -import space.kscience.plotly.scatter +import kotlinx.html.div +import kotlinx.html.h1 +import kotlinx.html.hr +import space.kscience.plotly.* +import space.kscience.plotly.models.Trace +import space.kscience.plotly.models.invoke +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.sin +/** + * Creates a renderable plotly html + */ +@OptIn(UnstablePlotlyAPI::class) fun main() { - Plotly.plot { - scatter { - x(1,2,3) - y(5,8,10) + val x1 = (0..100).map { it.toDouble() / 100.0 } + val y1 = x1.map { sin(2.0 * PI * it) } + val y2 = x1.map { cos(2.0 * PI * it) } + + val trace1 = Trace(x1, y1) { name = "sin" } + val trace2 = Trace(x1, y2) { name = "cos" } + + Plotly.page { container -> + h1 { +"This is a plotly page" } + plot(renderer = container) { + traces(trace1, trace2) + layout { + title = "The plot above" + xaxis.title = "x axis name" + yaxis.title = "y axis name" + } + } + hr() + h1 { +"A custom separator" } + hr() + div { + plot { + traces(trace1, trace2) + layout { + title = "The plot below" + xaxis.title = "x axis name" + yaxis.title = "y axis name" + } + } } - }.makeFile("plotly.html".toPath()) + }.makeFile("plotly.html") } \ No newline at end of file diff --git a/examples/src/main/kotlin/customPage.kt b/examples/src/main/kotlin/customPage.kt index 7e205275..26ff5a50 100644 --- a/examples/src/main/kotlin/customPage.kt +++ b/examples/src/main/kotlin/customPage.kt @@ -17,7 +17,7 @@ fun main() { val trace1 = Trace(x1, y1) { name = "sin" } val trace2 = Trace(x1, y2) { name = "cos" } - Plotly.fragment { container -> + Plotly.page { container -> plot(renderer = container) { traces(trace1, trace2) layout { diff --git a/examples/src/main/kotlin/gridPageLayout.kt b/examples/src/main/kotlin/gridPageLayout.kt index a48ee90a..7e5c4c4a 100644 --- a/examples/src/main/kotlin/gridPageLayout.kt +++ b/examples/src/main/kotlin/gridPageLayout.kt @@ -6,6 +6,7 @@ import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin +@Suppress("DEPRECATION") @UnstablePlotlyAPI fun main() { diff --git a/examples/src/main/kotlin/tabPageLayout.kt b/examples/src/main/kotlin/tabPageLayout.kt index a240ad72..47d51782 100644 --- a/examples/src/main/kotlin/tabPageLayout.kt +++ b/examples/src/main/kotlin/tabPageLayout.kt @@ -6,6 +6,7 @@ import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin +@Suppress("DEPRECATION") @UnstablePlotlyAPI fun main() { diff --git a/plotlykt-core/README.md b/plotlykt-core/README.md index a89ef9fc..e8af1e6d 100644 --- a/plotlykt-core/README.md +++ b/plotlykt-core/README.md @@ -6,7 +6,7 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:plotlykt-core:0.5.3-dev-2`. +The Maven coordinates of this project are `space.kscience:plotlykt-core:0.5.3`. **Gradle Groovy:** ```groovy @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation 'space.kscience:plotlykt-core:0.5.3-dev-2' + implementation 'space.kscience:plotlykt-core:0.5.3' } ``` **Gradle Kotlin DSL:** @@ -27,6 +27,6 @@ repositories { } dependencies { - implementation("space.kscience:plotlykt-core:0.5.3-dev-2") + implementation("space.kscience:plotlykt-core:0.5.3") } ``` diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotlyPage.kt b/plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt similarity index 100% rename from plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotlyPage.kt rename to plotlykt-core/src/commonMain/kotlin/space/kscience/plotly/PlotlyPage.kt diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotGrid.kt b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotGrid.kt index 293f99ba..c6b5080c 100644 --- a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotGrid.kt +++ b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotGrid.kt @@ -3,6 +3,7 @@ package space.kscience.plotly import kotlinx.html.div @UnstablePlotlyAPI +@Deprecated("Discontinued in favor of VisionForge layouts") public class PlotGrid { public data class PlotCell(val id: String, val plot: Plot, val row: Int, val col: Int, val width: Int = 1) @@ -55,6 +56,7 @@ public class PlotGrid { } @UnstablePlotlyAPI +@Deprecated("Discontinued in favor of VisionForge layouts") public fun Plotly.grid(block: PlotGrid.() -> Unit): PlotlyPage { val grid = PlotGrid().apply(block) return page(cdnBootstrap, cdnPlotlyHeader) { container -> diff --git a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotTabs.kt b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotTabs.kt index f1d9a8c4..25ec8173 100644 --- a/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotTabs.kt +++ b/plotlykt-core/src/jvmMain/kotlin/space/kscience/plotly/PlotTabs.kt @@ -2,6 +2,8 @@ package space.kscience.plotly import kotlinx.html.* +@UnstablePlotlyAPI +@Deprecated("Discontinued in favor of VisionForge layouts") public class PlotTabs { public data class Tab(val title: String, val id: String, val content: PlotlyFragment) @@ -14,6 +16,7 @@ public class PlotTabs { } @UnstablePlotlyAPI +@Deprecated("Discontinued in favor of VisionForge layouts") public fun Plotly.tabs(tabsID: String = "tabs", block: PlotTabs.() -> Unit): PlotlyPage { val grid = PlotTabs().apply(block) diff --git a/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt b/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt index 57670452..37363b7a 100644 --- a/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt +++ b/plotlykt-core/src/nativeMain/kotlin/space/kscience/plotly/makeFile.kt @@ -2,6 +2,7 @@ package space.kscience.plotly import okio.FileSystem import okio.Path +import okio.Path.Companion.toPath /** * Create a standalone html with the plot @@ -15,6 +16,31 @@ public fun Plot.makeFile( config: PlotlyConfig = PlotlyConfig(), ) { FileSystem.SYSTEM.write(path, true) { - writeUtf8( toHTML(cdnPlotlyHeader, config = config)) + writeUtf8(toHTML(cdnPlotlyHeader, config = config)) } +} + +@UnstablePlotlyAPI +public fun Plot.makeFile( + path: String, + config: PlotlyConfig = PlotlyConfig(), +) { + makeFile(path.toPath(), config) +} + +/** + * Export a page html to a file. + */ +@UnstablePlotlyAPI +public fun PlotlyPage.makeFile(path: Path) { + FileSystem.SYSTEM.write(path, true) { + writeUtf8(render()) + } +} + +@UnstablePlotlyAPI +public fun PlotlyPage.makeFile( + path: String, +) { + makeFile(path.toPath()) } \ No newline at end of file diff --git a/plotlykt-geo/README.md b/plotlykt-geo/README.md index a6e7916d..2d14613e 100644 --- a/plotlykt-geo/README.md +++ b/plotlykt-geo/README.md @@ -6,7 +6,7 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:plotlykt-geo:0.5.3-dev-2`. +The Maven coordinates of this project are `space.kscience:plotlykt-geo:0.5.3`. **Gradle Groovy:** ```groovy @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation 'space.kscience:plotlykt-geo:0.5.3-dev-2' + implementation 'space.kscience:plotlykt-geo:0.5.3' } ``` **Gradle Kotlin DSL:** @@ -27,6 +27,6 @@ repositories { } dependencies { - implementation("space.kscience:plotlykt-geo:0.5.3-dev-2") + implementation("space.kscience:plotlykt-geo:0.5.3") } ``` diff --git a/plotlykt-jupyter/README.md b/plotlykt-jupyter/README.md index 211c3675..b604c3d9 100644 --- a/plotlykt-jupyter/README.md +++ b/plotlykt-jupyter/README.md @@ -6,7 +6,7 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:plotlykt-jupyter:0.5.3-dev-2`. +The Maven coordinates of this project are `space.kscience:plotlykt-jupyter:0.5.3`. **Gradle Groovy:** ```groovy @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation 'space.kscience:plotlykt-jupyter:0.5.3-dev-2' + implementation 'space.kscience:plotlykt-jupyter:0.5.3' } ``` **Gradle Kotlin DSL:** @@ -27,6 +27,6 @@ repositories { } dependencies { - implementation("space.kscience:plotlykt-jupyter:0.5.3-dev-2") + implementation("space.kscience:plotlykt-jupyter:0.5.3") } ``` diff --git a/plotlykt-script/README.md b/plotlykt-script/README.md index df7682f8..a69e554f 100644 --- a/plotlykt-script/README.md +++ b/plotlykt-script/README.md @@ -6,7 +6,7 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:plotlykt-script:0.5.3-dev-2`. +The Maven coordinates of this project are `space.kscience:plotlykt-script:0.5.3`. **Gradle Groovy:** ```groovy @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation 'space.kscience:plotlykt-script:0.5.3-dev-2' + implementation 'space.kscience:plotlykt-script:0.5.3' } ``` **Gradle Kotlin DSL:** @@ -27,6 +27,6 @@ repositories { } dependencies { - implementation("space.kscience:plotlykt-script:0.5.3-dev-2") + implementation("space.kscience:plotlykt-script:0.5.3") } ``` diff --git a/plotlykt-server/README.md b/plotlykt-server/README.md index 7e0bb822..67c490e9 100644 --- a/plotlykt-server/README.md +++ b/plotlykt-server/README.md @@ -6,7 +6,7 @@ ## Artifact: -The Maven coordinates of this project are `space.kscience:plotlykt-server:0.5.3-dev-2`. +The Maven coordinates of this project are `space.kscience:plotlykt-server:0.5.3`. **Gradle Groovy:** ```groovy @@ -16,7 +16,7 @@ repositories { } dependencies { - implementation 'space.kscience:plotlykt-server:0.5.3-dev-2' + implementation 'space.kscience:plotlykt-server:0.5.3' } ``` **Gradle Kotlin DSL:** @@ -27,6 +27,6 @@ repositories { } dependencies { - implementation("space.kscience:plotlykt-server:0.5.3-dev-2") + implementation("space.kscience:plotlykt-server:0.5.3") } ``` From 01bc0435cecfb987749cd7c1049f8f02df085deb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Apr 2023 17:58:22 +0300 Subject: [PATCH 06/10] Fix ktor server address --- gradle.properties | 2 +- .../main/kotlin/space/kscience/plotly/server/PlotlyServer.kt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9903e9a6..c2ab572f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false kotlin.incremental.js.ir=true -toolsVersion=0.14.5-kotlin-1.8.20-RC \ No newline at end of file +toolsVersion=0.14.6-kotlin-1.8.20 \ No newline at end of file diff --git a/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServer.kt b/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServer.kt index 0d366fd4..ccc6088b 100644 --- a/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServer.kt +++ b/plotlykt-server/src/main/kotlin/space/kscience/plotly/server/PlotlyServer.kt @@ -185,8 +185,8 @@ public class PlotlyServer internal constructor( val url = URLBuilder().apply { protocol = URLProtocol.createOrDefault(origin.scheme) //workaround for https://github.com/ktorio/ktor/issues/1663 - host = dataSourceHost ?: if (origin.host.startsWith("0:")) "[${origin.host}]" else origin.host - port = dataSourcePort ?: origin.port + host = dataSourceHost ?: if (origin.serverHost.startsWith("0:")) "[${origin.serverHost}]" else origin.serverHost + port = dataSourcePort ?: origin.serverPort encodedPath = origin.uri }.build() call.respondHtml { @@ -294,6 +294,7 @@ public fun PlotlyServer.pullUpdates(interval: Int = 500): PlotlyServer = apply { /** * Start static server (updates via reload) */ +@Suppress("ExtractKtorModule") @OptIn(DelicateCoroutinesApi::class) public fun Plotly.serve( scope: CoroutineScope = GlobalScope, From 0c01f5c59153600ee4083797486f855f6519ef76 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Apr 2023 18:16:58 +0300 Subject: [PATCH 07/10] Fix name clash in JS --- .../src/main/kotlin/space/kscience/plotly/jsdemo/main.kt | 6 +++--- .../jsMain/kotlin/space/kscience/plotly/plotlyElement.kt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/js-demo/src/main/kotlin/space/kscience/plotly/jsdemo/main.kt b/examples/js-demo/src/main/kotlin/space/kscience/plotly/jsdemo/main.kt index e82fba64..6bf7b488 100644 --- a/examples/js-demo/src/main/kotlin/space/kscience/plotly/jsdemo/main.kt +++ b/examples/js-demo/src/main/kotlin/space/kscience/plotly/jsdemo/main.kt @@ -35,7 +35,7 @@ fun main(): Unit = withCanvas { div { style = "height:50%; width=100%;" h1 { +"Histogram demo" } - plot { + plotDiv { val rnd = Random(222) histogram { name = "Random data" @@ -79,7 +79,7 @@ fun main(): Unit = withCanvas { div { style = "height:50%; width=100%;" h1 { +"Dynamic trace demo" } - plot { + plotDiv { scatter { x(1, 2, 3, 4) y(10, 15, 13, 17) @@ -133,7 +133,7 @@ fun main(): Unit = withCanvas { val serialized = plot.toJsonString() console.log(serialized) val deserialized = Plot(Json.decodeFromString(MetaSerializer, serialized).toMutableMeta()) - plot(plot = deserialized) + plotDiv(plot = deserialized) } } diff --git a/plotlykt-core/src/jsMain/kotlin/space/kscience/plotly/plotlyElement.kt b/plotlykt-core/src/jsMain/kotlin/space/kscience/plotly/plotlyElement.kt index 00a3b82b..93002302 100644 --- a/plotlykt-core/src/jsMain/kotlin/space/kscience/plotly/plotlyElement.kt +++ b/plotlykt-core/src/jsMain/kotlin/space/kscience/plotly/plotlyElement.kt @@ -62,7 +62,7 @@ public inline fun Element.plot(plotlyConfig: PlotlyConfig = PlotlyConfig(), plot plot(plotlyConfig, Plot().apply(plotBuilder)) } -public fun TagConsumer.plot( +public fun TagConsumer.plotDiv( plotlyConfig: PlotlyConfig = PlotlyConfig(), plot: Plot, ): HTMLElement = div("plotly-kt-plot").apply { plot(plotlyConfig, plot) } @@ -70,7 +70,7 @@ public fun TagConsumer.plot( /** * Render plot in HTML element using direct plotly API. */ -public inline fun TagConsumer.plot( +public inline fun TagConsumer.plotDiv( plotlyConfig: PlotlyConfig = PlotlyConfig(), plotBuilder: Plot.() -> Unit, ): HTMLElement = div("plotly-kt-plot").apply { plot(plotlyConfig, plotBuilder) } From f72ba0a2472a2cc934703320dbfae2c12fe0beb7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Apr 2023 18:51:23 +0300 Subject: [PATCH 08/10] Add jupyter artefact to demos --- examples/build.gradle.kts | 1 + examples/notebooks/plotlykt-demo.ipynb | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 9931f981..997ee723 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -9,6 +9,7 @@ repositories { dependencies { implementation(project(":plotlykt-server")) + implementation(projects.plotlyktJupyter) implementation(project(":plotlykt-geo")) implementation(kotlin("script-runtime")) implementation(project(":plotlykt-script")) diff --git a/examples/notebooks/plotlykt-demo.ipynb b/examples/notebooks/plotlykt-demo.ipynb index 6183fe94..598df9ef 100644 --- a/examples/notebooks/plotlykt-demo.ipynb +++ b/examples/notebooks/plotlykt-demo.ipynb @@ -3,11 +3,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "ExecuteTime": { - "start_time": "2021-04-29T19:06:33.505Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "%use plotly" @@ -17,9 +13,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "ExecuteTime": { - "start_time": "2021-04-29T19:05:34.298Z" - }, "tags": [] }, "outputs": [], @@ -92,6 +85,9 @@ "toc_position": {}, "toc_section_display": false, "toc_window_display": false + }, + "ktnbPluginMetadata": { + "isAddProjectLibrariesToClasspath": false } }, "nbformat": 4, From aded8431b40a0d1900c076f6eed8e4f9c51578f3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Apr 2023 19:06:05 +0300 Subject: [PATCH 09/10] Add flexible native target for native demo --- examples/native-demo/build.gradle.kts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/native-demo/build.gradle.kts b/examples/native-demo/build.gradle.kts index 1f6116d5..da6b56ae 100644 --- a/examples/native-demo/build.gradle.kts +++ b/examples/native-demo/build.gradle.kts @@ -10,8 +10,19 @@ repositories { } kotlin { - mingwX64{ - binaries.executable() + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + val nativeTarget = when { + hostOs == "Mac OS X" -> macosX64("native") + hostOs == "Linux" -> linuxX64("native") + isMingwX64 -> mingwX64("native") + else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + } + + nativeTarget.apply { + binaries { + executable() + } } sourceSets{ commonMain { From 9cb0d117149f9067bbb00ee0d7f06126760c2e37 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Apr 2023 19:23:34 +0300 Subject: [PATCH 10/10] Add gh-pages and gh-publishing --- .github/workflows/pages.yml | 31 ++++++++++++++++++++++ .github/workflows/publish.yml | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/pages.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 00000000..5c1c3bac --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,31 @@ +name: Dokka publication + +on: + workflow_dispatch: + release: + types: [ created ] + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 40 + steps: + - uses: actions/checkout@v3.0.0 + - uses: actions/setup-java@v3.0.0 + with: + java-version: 11 + distribution: liberica + - name: Cache konan + uses: actions/cache@v3.0.1 + with: + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - uses: gradle/gradle-build-action@v2.1.5 + with: + arguments: dokkaHtmlMultiModule --no-parallel + - uses: JamesIves/github-pages-deploy-action@v4.3.0 + with: + branch: gh-pages + folder: build/dokka/htmlMultiModule diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..ab9243f1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,50 @@ +name: Gradle publish + +on: + workflow_dispatch: + release: + types: [ created ] + +jobs: + publish: + environment: + name: publish + strategy: + matrix: + os: [ macOS-latest, windows-latest ] + runs-on: ${{matrix.os}} + steps: + - uses: actions/checkout@v3.0.0 + - uses: actions/setup-java@v3.10.0 + with: + java-version: 11 + distribution: liberica + - name: Cache konan + uses: actions/cache@v3.0.1 + with: + path: ~/.konan + key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Publish Windows Artifacts + if: matrix.os == 'windows-latest' + uses: gradle/gradle-build-action@v2.4.0 + with: + arguments: | + publishAllPublicationsToSpaceRepository + -Ppublishing.targets=all + -Ppublishing.space.user=${{ secrets.SPACE_APP_ID }} + -Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }} + - name: Publish Mac Artifacts + if: matrix.os == 'macOS-latest' + uses: gradle/gradle-build-action@v2.4.0 + with: + arguments: | + publishMacosX64PublicationToSpaceRepository + publishMacosArm64PublicationToSpaceRepository + publishIosX64PublicationToSpaceRepository + publishIosArm64PublicationToSpaceRepository + publishIosSimulatorArm64PublicationToSpaceRepository + -Ppublishing.targets=all + -Ppublishing.space.user=${{ secrets.SPACE_APP_ID }} + -Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}