Skip to content

Commit

Permalink
Migrate to self-made JS
Browse files Browse the repository at this point in the history
  • Loading branch information
altavir committed Jun 25, 2023
1 parent 9cb0d11 commit 1e2199f
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 495 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ plugins {
}

val dataforgeVersion by extra("0.6.1")
val plotlyVersion by extra("2.20.0")
val plotlyVersion by extra("2.24.1")

allprojects {
group = "space.kscience"
version = "0.5.3"
version = "0.6.0-dev-1"
}

apiValidation {
Expand All @@ -29,10 +29,10 @@ ksciencePublish{
if (isInDevelopment) {
"https://maven.pkg.jetbrains.space/spc/p/sci/dev"
} else {
"https://maven.pkg.jetbrains.space/spc/p/sci/release"
"https://maven.pkg.jetbrains.space/spc/p/sci/maven"
}
)
sonatype()
sonatype("https://oss.sonatype.org")
}

readme {
Expand Down
9 changes: 5 additions & 4 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ repositories {
}

dependencies {
implementation(project(":plotlykt-server"))
implementation(projects.plotlyktServer)
implementation(projects.plotlyktJupyter)
implementation(project(":plotlykt-geo"))
implementation(projects.plotlyktGeo)
implementation(kotlin("script-runtime"))
implementation(project(":plotlykt-script"))
implementation("org.jetbrains.kotlinx:dataframe:0.9.1")
implementation(projects.plotlyktScript)
implementation("org.jetbrains.kotlinx:dataframe:0.10.1")
}

kotlin{
Expand All @@ -28,6 +28,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {

val copyPlotlyResources by tasks.creating(Copy::class){
dependsOn(":plotlykt-core:jvmProcessResources")
mustRunAfter(":plotlykt-core:jvmTestProcessResources")
from(project(":plotlykt-core").buildDir.resolve("processedResources/jvm"))
into(buildDir.resolve("resources"))
}
Expand Down
14 changes: 10 additions & 4 deletions examples/notebooks/plotlykt-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
"metadata": {},
"outputs": [],
"source": [
"%use plotly"
"import space.kscience.plotly.PlotlyIntegration\n",
"\n",
"val integration = PlotlyIntegration()\n",
"\n",
"USE(integration.getDefinitions(notebook).first())\n",
"\n",
"//%use plotly"
]
},
{
Expand All @@ -31,9 +37,9 @@
" responsive = true\n",
" imageFormat = \"svg\"\n",
" } \n",
" h1 { +\"A custom separator\" }\n",
" h1 { +\"A custom header\" }\n",
" hr()\n",
" plot(\"below\", renderer = renderer) {\n",
" plot(\"below\", config = plotConfig, renderer = renderer) {\n",
" traces(trace1, trace2)\n",
" layout {\n",
" title = \"The plot below\"\n",
Expand Down Expand Up @@ -87,7 +93,7 @@
"toc_window_display": false
},
"ktnbPluginMetadata": {
"isAddProjectLibrariesToClasspath": false
"isBuildProject": true
}
},
"nbformat": 4,
Expand Down
100 changes: 45 additions & 55 deletions examples/notebooks/plotlykt-server-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import space.kscience.plotly.server.PlotlyServerIntegration\n",
"import space.kscience.plotly.server.jupyter\n",
"\n",
"val integration = PlotlyServerIntegration()\n",
"integration.getDefinitions(notebook).forEach {\n",
" USE(it)\n",
"}"
],
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%use plotly-server\n",
"import kotlin.math.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"val x1 = (0..100).map { it.toDouble() / 100.0 }\n",
Expand All @@ -34,10 +40,10 @@
"val trace2 = Trace(x1, y2) { name = \"cos\" }\n",
"\n",
"val fragment = Plotly.fragment { renderer ->\n",
" val plotConfig = PlotlyConfig{\n",
" val plotConfig = PlotlyConfig {\n",
" responsive = true\n",
" } \n",
" \n",
" }\n",
"\n",
" plot(\"above\", config = plotConfig, renderer = renderer) {\n",
" traces(trace1, trace2)\n",
" layout {\n",
Expand All @@ -50,7 +56,7 @@
" h1 { +\"A custom separator\" }\n",
" hr()\n",
" div {\n",
" plot(renderer = renderer) {\n",
" plot(\"below\", renderer = renderer) {\n",
" traces(trace1, trace2)\n",
" layout {\n",
" title = \"The plot below\"\n",
Expand All @@ -66,12 +72,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"Plotly.plot {\n",
Expand All @@ -87,12 +88,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"val x = (0..100).map { it.toDouble() / 100.0 }\n",
Expand All @@ -116,12 +112,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"import kotlinx.coroutines.*\n",
Expand All @@ -140,12 +131,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"job.cancel()"
Expand All @@ -154,12 +140,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"dynamicPlot.layout.xaxis.title = \"крокозябра\""
Expand All @@ -168,23 +149,29 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-08T21:37+0300",
"start_time": "2020-08-08T21:37+0300"
}
},
"metadata": {},
"outputs": [],
"source": [
"plotly.port = 8884"
"Plotly.jupyter.port = 8884"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"Plotly.jupyter.port"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
Expand Down Expand Up @@ -219,8 +206,11 @@
"toc_position": {},
"toc_section_display": false,
"toc_window_display": false
},
"ktnbPluginMetadata": {
"isBuildProject": true
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ kotlin.mpp.stability.nowarn=true
kotlin.jupyter.add.scanner=false
kotlin.incremental.js.ir=true

toolsVersion=0.14.6-kotlin-1.8.20
toolsVersion=0.14.9-kotlin-1.8.20
5 changes: 3 additions & 2 deletions plotlykt-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ val dataforgeVersion: String by rootProject.extra
val plotlyVersion: String by rootProject.extra

kscience {
jvm()
js()
fullStack(bundleName = "js/plotly-kt.js")
native()

dependencies {
api("space.kscience:dataforge-meta:$dataforgeVersion")
api(spclibs.kotlinx.html)
}

dependencies(jsMain) {
api(npm("plotly.js", plotlyVersion))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package space.kscience.plotly.events

import space.kscience.dataforge.meta.*
import space.kscience.plotly.list
import space.kscience.plotly.models.Trace

public enum class PlotlyEventListenerType(public val typeName: String){
CLICK("plotly_click"),
HOVER("plotly_hover"),
UNHOVER("plotly_unhover"),
SELECTING("plotly_selecting"),
SELECTED("plotly_selected")
}

public class PlotlyEventPoint : Scheme() {
public val curveNumber: Int by int(1)
public val pointNumber: Int? by int()
public val x: Value? by value()
public val y: Value? by value()

public val data: Trace by spec(Trace)
public val fullData: Trace by spec(Trace)

public companion object : SchemeSpec<PlotlyEventPoint>(::PlotlyEventPoint)
}


public class PlotlyEvent : Scheme() {
public val points: List<PlotlyEventPoint> by list(PlotlyEventPoint)

public companion object : SchemeSpec<PlotlyEvent>(::PlotlyEvent)
}


Loading

0 comments on commit 1e2199f

Please sign in to comment.