Skip to content

Commit

Permalink
Merge pull request #100 from SciProgCentre/dev
Browse files Browse the repository at this point in the history
0.6.0
  • Loading branch information
SPC-code authored Jul 29, 2023
2 parents 9f4e760 + b75bef2 commit 5389b49
Show file tree
Hide file tree
Showing 34 changed files with 505 additions and 539 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## 0.6.0 - 2023-07-29

### Added
- Add experimental support for events on JS

### Changed
- DataForge 0.6.2
- Use a self-made Plotly-js bundle instead of one from CDN

## 0.5.3 - 2023-04-01

### Added
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {
id("space.kscience.gradle.project")
}

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

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.w3c.dom.events.Event
import space.kscience.dataforge.meta.MetaSerializer
import space.kscience.dataforge.meta.toMutableMeta
import space.kscience.plotly.*
import space.kscience.plotly.events.PlotlyEventListenerType
import space.kscience.plotly.models.ScatterMode
import space.kscience.plotly.models.TraceType
import kotlin.random.Random
Expand Down Expand Up @@ -133,7 +134,9 @@ fun main(): Unit = withCanvas {
val serialized = plot.toJsonString()
console.log(serialized)
val deserialized = Plot(Json.decodeFromString(MetaSerializer, serialized).toMutableMeta())
plotDiv(plot = deserialized)
plotDiv(plot = deserialized).on(PlotlyEventListenerType.CLICK){
console.info(it.toString())
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions examples/notebooks/plotlykt-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"metadata": {},
"outputs": [],
"source": [
"%use plotly"
"import space.kscience.plotly.PlotlyIntegration\n",
"\n",
"val integration = PlotlyIntegration()\n",
"\n",
"USE(integration.getDefinitions(notebook).first())\n",
"//%use plotly"
]
},
{
Expand All @@ -31,9 +36,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 +92,7 @@
"toc_window_display": false
},
"ktnbPluginMetadata": {
"isAddProjectLibrariesToClasspath": false
"projectDependencies": 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
}
}
41 changes: 19 additions & 22 deletions examples/src/main/kotlin/tutorials/SinusPicture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import kotlin.math.sin
* - Change margins on the plot edges
* - Add shapes (vertical lines)
*/
@OptIn(UnstablePlotlyAPI::class)
fun main() {
val div = 200 / PI
val sub = PI / 6
val xValues = (-410..410).map { it / div }
val xValues: List<Double> = (-410..410).map { it / div }
val yValues = mutableListOf<Double>()
val yText = mutableListOf<String>()

Expand All @@ -31,17 +30,15 @@ fun main() {
yText.add("sin = $x")
}

val shapesList = mutableListOf<Shape>()
val xElems = listOf(-2 * PI + sub, -PI - sub, sub, PI - sub)
for (elem in xElems) {
val newShape = Shape {
x0 = Value.of(elem)
x1 = Value.of(elem)
y0 = Value.of(0)
y1 = Value.of(0.5)
val shapesList = xElems.map { elem ->
Shape {
xref = "x"
yref = "y"
startXY(elem, 0)
endXY(elem, 0.5)
line { color("red") }
}
shapesList.add(newShape)
}

Plotly.page(mathJaxHeader, cdnPlotlyHeader) {
Expand Down Expand Up @@ -104,27 +101,27 @@ fun main() {
}

shape { // y = 1
x0 = Value.of(-2 * PI)
x1 = Value.of(2 * PI)
y0 = Value.of(1)
y1 = Value.of(1)
xref = "x"
yref = "y"
startXY(-2 * PI, 1)
endXY(2 * PI, 1)
line { dash = Dash.dash }
}
shape { // y = 1/2
x0 = Value.of(-2 * PI)
x1 = Value.of(2 * PI)
y0 = Value.of(0.5)
y1 = Value.of(0.5)
xref = "x"
yref = "y"
startXY(-2 * PI, 0.5)
endXY(2 * PI, 0.5)
line {
color("red")
dash = Dash.dash
}
}
shape { // y = -1
x0 = Value.of(-2 * PI)
x1 = Value.of(2 * PI)
y0 = Value.of(-1)
y1 = Value.of(-1)
xref = "x"
yref = "y"
startXY(-2 * PI, -1)
endXY(2 * PI, -1)
line { dash = Dash.dash }
}

Expand Down
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
Loading

0 comments on commit 5389b49

Please sign in to comment.