Skip to content

Commit 062bec9

Browse files
committed
limited series ktor3 release for kap
1 parent 6dd0ec4 commit 062bec9

File tree

5 files changed

+81
-39
lines changed

5 files changed

+81
-39
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ val plotlyVersion by extra("2.29.0")
1010

1111
allprojects {
1212
group = "space.kscience"
13-
version = "0.7.1.1"
13+
version = "0.7.1.1-ktor3"
1414
}
1515

1616
apiValidation {

examples/fx-demo/src/main/kotlin/space/kscience/plotly/fx/PlotlyFXController.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package space.kscience.plotly.fx
33
import io.ktor.server.engine.ApplicationEngine
44
import javafx.beans.property.SimpleIntegerProperty
55
import javafx.beans.property.SimpleStringProperty
6-
import kotlinx.coroutines.DelicateCoroutinesApi
7-
import kotlinx.coroutines.Dispatchers
8-
import kotlinx.coroutines.GlobalScope
9-
import kotlinx.coroutines.launch
6+
import kotlinx.coroutines.*
107
import tornadofx.*
118
import java.net.URI
129

@@ -35,9 +32,9 @@ class PlotlyFXController : Controller() {
3532

3633
val address = SimpleStringProperty()
3734

38-
fun displayPage(page: String) {
35+
fun displayPage(page: String) = runBlocking {
3936
server?.let {
40-
val connector = it.environment.connectors.first()
37+
val connector = it.resolvedConnectors().first()
4138
val uri = URI("http", null, connector.host, connector.port, null, null, null)
4239
address.set("$uri/$page")
4340
}

examples/notebooks/plotlykt-demo.ipynb

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,22 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
65
"metadata": {},
7-
"outputs": [],
86
"source": [
97
"import space.kscience.plotly.PlotlyIntegration\n",
10-
"\n",
11-
"val integration = PlotlyIntegration()\n",
12-
"\n",
13-
"USE(integration.getDefinitions(notebook).first())\n",
14-
"//%use plotly"
15-
]
16-
},
17-
{
18-
"cell_type": "code",
19-
"outputs": [],
20-
"source": [
21-
"Plotly.jupyter.notebook()"
8+
"USE(PlotlyIntegration())\n",
9+
"//@file:CompilerArgs(\"-jvm-target=11\")\n",
10+
"//@file:Repository(\"https://repo.kotlin.link\")\n",
11+
"//@file:DependsOn(\"space.kscience:plotlykt-jupyter-jvm:0.7.1\")"
2212
],
23-
"metadata": {
24-
"collapsed": false
25-
},
13+
"outputs": [],
2614
"execution_count": null
2715
},
2816
{
2917
"cell_type": "code",
30-
"execution_count": null,
3118
"metadata": {
3219
"tags": []
3320
},
34-
"outputs": [],
3521
"source": [
3622
"import kotlin.math.*\n",
3723
"\n",
@@ -59,14 +45,74 @@
5945
" }\n",
6046
"\n",
6147
"}"
62-
]
48+
],
49+
"outputs": [],
50+
"execution_count": null
6351
},
6452
{
6553
"cell_type": "code",
66-
"execution_count": null,
67-
"metadata": {},
54+
"source": [
55+
"HTML(\n",
56+
" \"\"\"\n",
57+
" <div id=\"debug\">\n",
58+
" debug\n",
59+
" </div>\n",
60+
" \"\"\".trimIndent()\n",
61+
")"
62+
],
63+
"metadata": {
64+
"collapsed": false
65+
},
6866
"outputs": [],
69-
"source": []
67+
"execution_count": null
68+
},
69+
{
70+
"cell_type": "code",
71+
"source": [
72+
"HTML(\"\"\"\n",
73+
"<script type = \"text/javascript\">\n",
74+
" element = document.getElementById(\"debug\")\n",
75+
" element.append(window.Plotly)\n",
76+
" element.append(window.plotlyConnect)\n",
77+
"</script>\n",
78+
" \"\"\".trimIndent())"
79+
],
80+
"metadata": {
81+
"collapsed": false
82+
},
83+
"outputs": [],
84+
"execution_count": null
85+
},
86+
{
87+
"cell_type": "code",
88+
"source": [],
89+
"metadata": {
90+
"collapsed": false
91+
},
92+
"outputs": [],
93+
"execution_count": null
94+
},
95+
{
96+
"cell_type": "code",
97+
"source": [
98+
"HTML(\"\"\"\n",
99+
"<script src=\"https://cdn.plot.ly/plotly-2.29.1.min.js\" charset=\"utf-8\"></script>\n",
100+
"\"\"\")"
101+
],
102+
"metadata": {
103+
"collapsed": false
104+
},
105+
"outputs": [],
106+
"execution_count": null
107+
},
108+
{
109+
"cell_type": "code",
110+
"source": [],
111+
"metadata": {
112+
"collapsed": false
113+
},
114+
"outputs": [],
115+
"execution_count": null
70116
}
71117
],
72118
"metadata": {

plotlykt-server/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import space.kscience.gradle.KScienceVersions
2-
31
plugins {
42
id("space.kscience.gradle.mpp")
53
kotlin("jupyter.api")
64
`maven-publish`
75
}
86

97
val dataforgeVersion: String by rootProject.extra
10-
val ktorVersion = KScienceVersions.ktorVersion
8+
val ktorVersion = "3.0.2"
119

1210
kscience{
1311
jvm()

plotlykt-server/src/jvmMain/kotlin/space/kscience/plotly/server/PlotlyServer.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package space.kscience.plotly.server
22

33
import io.ktor.http.*
44
import io.ktor.server.application.*
5+
import io.ktor.server.cio.CIO
56
import io.ktor.server.engine.ApplicationEngine
67
import io.ktor.server.engine.embeddedServer
78
import io.ktor.server.html.respondHtml
@@ -17,6 +18,7 @@ import io.ktor.websocket.Frame
1718
import kotlinx.coroutines.CoroutineScope
1819
import kotlinx.coroutines.DelicateCoroutinesApi
1920
import kotlinx.coroutines.GlobalScope
21+
import kotlinx.coroutines.runBlocking
2022
import kotlinx.html.*
2123
import kotlinx.serialization.json.JsonObject
2224
import space.kscience.dataforge.meta.*
@@ -25,7 +27,6 @@ import space.kscience.plotly.*
2527
import space.kscience.plotly.server.PlotlyServer.Companion.DEFAULT_PAGE
2628
import java.awt.Desktop
2729
import java.net.URI
28-
import kotlin.collections.set
2930
import kotlin.coroutines.CoroutineContext
3031

3132
public enum class PlotlyUpdateMode {
@@ -273,7 +274,7 @@ public fun Application.plotlyModule(route: String = DEFAULT_PAGE, block: PlotlyS
273274
}
274275

275276
// val root: Route = feature(Routing).createRouteFromPath(route)
276-
return PlotlyServer(plugin(Routing), route).apply(block)
277+
return PlotlyServer(plugin(RoutingRoot), route).apply(block)
277278
}
278279

279280

@@ -304,14 +305,14 @@ public fun Plotly.serve(
304305
host: String = "localhost",
305306
port: Int = 7777,
306307
block: PlotlyServer.() -> Unit,
307-
): ApplicationEngine = scope.embeddedServer(io.ktor.server.cio.CIO, port, host) {
308+
): ApplicationEngine = scope.embeddedServer(CIO, port, host) {
308309
// install(CallLogging)
309310
install(CORS) {
310311
anyHost()
311312
}
312313

313314
plotlyModule(block = block)
314-
}.start()
315+
}.start().engine
315316

316317
/**
317318
* A shortcut to make a single plot at the default page
@@ -328,8 +329,8 @@ public fun PlotlyServer.plot(
328329
}
329330
}
330331

331-
public fun ApplicationEngine.show() {
332-
val connector = environment.connectors.first()
332+
public fun ApplicationEngine.show(): Unit = runBlocking {
333+
val connector = resolvedConnectors().first()
333334
val uri = URI("http", null, connector.host, connector.port, null, null, null)
334335
Desktop.getDesktop().browse(uri)
335336
}

0 commit comments

Comments
 (0)