Skip to content

Commit

Permalink
Merge pull request #83 from mipt-npm/dev
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
altavir authored Aug 13, 2021
2 parents 35e549f + afecd3a commit 77c3882
Show file tree
Hide file tree
Showing 31 changed files with 234 additions and 194 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- Switch to DataForge 0.5

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Dev builds and intermediate artifacts are available via `https://repo.kotlin.link` maven repository.

## Compatibility note
The current `0.4.4` version of the library is compatible with kotlin 1.4 with JS-IR and kotlinx-serialization 1.1.0. The JVM part requires JVM 11 to run.
The current `0.5.0` version of the library is compatible with kotlin 1.4 with JS-IR and kotlinx-serialization 1.1.0. The JVM part requires JVM 11 to run.

# TL;DR
See [examples](./examples/src/main/kotlin).
Expand Down Expand Up @@ -55,8 +55,8 @@ The examples of the notebooks are shown in [notebooks](./examples/notebooks) dir

```kotlin
@file:Repository("https://repo.kotlin.link")
@file:DependsOn("space.kscience:plotlykt-jupyter:0.4.4")
//@file:DependsOn("space.kscience:plotlykt-server:0.4.4") // Use this one for sever integration.
@file:DependsOn("space.kscience:plotlykt-jupyter:0.5.0")
//@file:DependsOn("space.kscience:plotlykt-server:0.5.0") // Use this one for sever integration.
```

The module `plotly` allows rendering static plots in Jupyter. Jupyter lab is currently supported. Jupyter notebook (classic) is able to render only `PlotlyPage` objects, so one must convert plots to pages to be able to use notebook (see [demo notebook](./notebooks/plotlykt-demo-classic.ipynb)).
Expand Down Expand Up @@ -92,7 +92,7 @@ repositories {
}

dependencies {
implementation("space.kscience:plotlykt-server:0.4.4")
implementation("space.kscience:plotlykt-server:0.5.0")
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ plugins {
id("ru.mipt.npm.gradle.project")
}

val dataforgeVersion by extra("0.4.3")
val dataforgeVersion by extra("0.5.0")

allprojects {
group = "space.kscience"
version = "0.4.4"
version = "0.5.0"
}

apiValidation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package space.kscience.plotly.fx
import io.ktor.server.engine.ApplicationEngine
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleStringProperty
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -15,6 +16,7 @@ class PlotlyFXController : Controller() {

private var server: ApplicationEngine? = null

@OptIn(DelicateCoroutinesApi::class)
fun startServer() {
GlobalScope.launch(Dispatchers.Default) {
log.info("Starting server")
Expand Down
2 changes: 1 addition & 1 deletion examples/js-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ kotlin {

dependencies {
implementation(project(":plotlykt-core"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package space.kscience.plotly.jsdemo


import kotlinx.browser.document
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.html.TagConsumer
import kotlinx.html.dom.append
import kotlinx.html.h1
Expand Down Expand Up @@ -33,6 +30,7 @@ private fun withCanvas(block: TagConsumer<HTMLElement>.() -> Unit) = onDomLoaded
}


@OptIn(DelicateCoroutinesApi::class)
fun main(): Unit = withCanvas {
div {
style = "height:50%; width=100%;"
Expand All @@ -43,7 +41,7 @@ fun main(): Unit = withCanvas {
name = "Random data"
GlobalScope.launch {
while (isActive) {
x.numbers = List(500){rnd.nextDouble()}
x.numbers = List(500) { rnd.nextDouble() }
delay(300)
}
}
Expand Down Expand Up @@ -93,10 +91,11 @@ fun main(): Unit = withCanvas {
y(10, 15, 13, 17)
mode = ScatterMode.lines
type = TraceType.scatter
marker.apply {
GlobalScope.launch {
while (isActive) {
delay(500)

GlobalScope.launch {
while (isActive) {
delay(500)
marker {
if (Random.nextBoolean()) {
color("magenta")
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/kotlin/candlestick/basicCandleStick.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package candlestick

import space.kscience.dataforge.meta.invoke
import space.kscience.dataforge.meta.set
import space.kscience.plotly.Plotly
import space.kscience.plotly.layout
import space.kscience.plotly.makeFile
import space.kscience.plotly.models.AxisType
import space.kscience.plotly.models.CandleStick
import space.kscience.plotly.models.DragMode

internal val candleStickTrace = CandleStick {
x.strings = listOf(
Expand Down Expand Up @@ -190,7 +190,7 @@ fun main() {
Plotly.plot {
traces(candleStickTrace)
layout {
set("dragmode", "zoom")
dragmode = DragMode.zoom
margin {
r = 10
t = 25
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/kotlin/candlestick/dynamicCandleStick.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package candlestick

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -41,7 +40,7 @@ fun main() {
}
}

GlobalScope.launch {
launch {
while (isActive) {
delay(400)
candleStickTrace.open.numbers = candleStickTrace.open.doubles.map { it + Random.nextDouble() - 0.5 }
Expand Down
7 changes: 3 additions & 4 deletions examples/src/main/kotlin/complexDynamicServer.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -86,7 +85,7 @@ fun main() {
}
trace {
val flow: Flow<Iterable<Double>> = sinFlow.windowed(100)
GlobalScope.launch {
launch {
updateFrom(Trace.Y_AXIS, flow)
}
}
Expand All @@ -101,7 +100,7 @@ fun main() {
}
trace {
val flow: Flow<Iterable<Double>> = cosFlow.windowed(100)
GlobalScope.launch {
launch {
updateFrom(Trace.Y_AXIS, flow)
}
}
Expand All @@ -119,7 +118,7 @@ fun main() {
trace {
name = "non-synchronized"
val flow: Flow<Iterable<Pair<Double, Double>>> = sinCosFlow.windowed(30)
GlobalScope.launch {
launch {
updateXYFrom(flow)
}
}
Expand Down
6 changes: 2 additions & 4 deletions examples/src/main/kotlin/dynamicServer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.html.a
import kotlinx.html.h1
import space.kscience.dataforge.meta.invoke
Expand All @@ -18,6 +15,7 @@ import kotlin.math.cos
import kotlin.math.sin


@OptIn(DelicateCoroutinesApi::class)
fun main() {

val freq = 1.0 / 1000
Expand Down
6 changes: 4 additions & 2 deletions examples/src/main/kotlin/plots3d/scatter3d.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package plots3d

import space.kscience.dataforge.meta.set
import space.kscience.dataforge.meta.configure
import space.kscience.plotly.Plotly
import space.kscience.plotly.makeFile
import space.kscience.plotly.trace

fun main() {
val plot = Plotly.plot {
trace {
set("type","scatter3d")
configure {
"type" put "scatter3d"
}
x(1,2,3)
y(1,2,3)
z(1,2,3)
Expand Down
6 changes: 4 additions & 2 deletions examples/src/main/kotlin/plots3d/surface3d.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package plots3d

import space.kscience.dataforge.meta.set
import space.kscience.dataforge.meta.configure
import space.kscience.dataforge.values.asValue
import space.kscience.plotly.Plotly
import space.kscience.plotly.makeFile
Expand Down Expand Up @@ -28,7 +28,9 @@ 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()
set("type", "surface")
configure {
"type" put "surface"
}
}
}
plot.makeFile()
Expand Down
20 changes: 9 additions & 11 deletions examples/src/main/kotlin/simpleServer.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io.ktor.util.KtorExperimentalAPI
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.html.a
import kotlinx.html.div
Expand All @@ -17,7 +16,6 @@ import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin

@KtorExperimentalAPI
@ExperimentalCoroutinesApi
fun main() {
val server = Plotly.serve {
Expand All @@ -28,7 +26,14 @@ fun main() {
val trace1 = Trace(x, y1) { name = "sin" }
val trace2 = Trace(x, y2) { name = "cos" }

lateinit var plot1: Plot
val plot1: Plot = Plotly.plot{
traces(trace1, trace2)
layout {
title = "First graph, row: 1, size: 8/12"
xaxis { title = "x axis name" }
yaxis { title = "y axis name" }
}
}

//root level plots go to default page
page {
Expand All @@ -38,14 +43,7 @@ fun main() {
style = "display: flex; align-items: stretch; "
div {
style = "width: 64%;"
plot1 = plot {
traces(trace1, trace2)
layout {
title = "First graph, row: 1, size: 8/12"
xaxis { title = "x axis name" }
yaxis { title = "y axis name" }
}
}
plot(plot1)
}
div {
style = "width: 32%;"
Expand Down
15 changes: 8 additions & 7 deletions examples/src/main/kotlin/unsupportedFeature.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.configure
import space.kscience.dataforge.meta.invoke
import space.kscience.dataforge.meta.set
import space.kscience.dataforge.values.ListValue
import space.kscience.plotly.Plotly
import space.kscience.plotly.makeFile
import space.kscience.plotly.models.Trace
import space.kscience.plotly.models.invoke
import space.kscience.plotly.set

fun main() {

Expand All @@ -17,7 +19,7 @@ fun main() {
* We are applying it directly to configuration.
* It is still observable in the same way as other properties but is not type safe.
*/
set("text", x.map { "label for $it" })
meta["text"] = x.map { "label for $it"}
}

val plot = Plotly.plot {
Expand All @@ -26,14 +28,13 @@ fun main() {
title = "Plot with labels"
xaxis {
title = "x axis name"
set(
"rangebreaks",
listOf(
configure {
"rangebreaks" putIndexed listOf(
Meta {
"values" put listOf(2.0, 3.0)
"values" put ListValue(2.0, 3.0)
}
)
)
}
}
yaxis { title = "y axis name" }
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 11 additions & 5 deletions plotlykt-core/api/plotlykt-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ public final class space/kscience/plotly/BootstrapHeadersKt {
public static final fun getCdnBootstrap ()Lspace/kscience/plotly/PlotlyHtmlFragment;
}

public final class space/kscience/plotly/DfExtKt {
public static final fun set (Lspace/kscience/dataforge/meta/MutableMeta;Ljava/lang/String;Ljava/lang/Object;)V
public static final fun set (Lspace/kscience/dataforge/meta/Scheme;Ljava/lang/String;Ljava/lang/Object;)V
}

public final class space/kscience/plotly/FileExportKt {
public static final fun display (Lspace/kscience/plotly/Plotly;Lkotlin/jvm/functions/Function2;)V
public static final fun export (Lspace/kscience/plotly/Plot;Ljava/nio/file/Path;Lspace/kscience/plotly/OrcaFormat;)V
Expand Down Expand Up @@ -37,12 +42,13 @@ public final class space/kscience/plotly/OrcaFormat : java/lang/Enum {

public final class space/kscience/plotly/Plot : space/kscience/dataforge/meta/Configurable, space/kscience/dataforge/meta/MetaRepr {
public fun <init> ()V
public fun <init> (Lspace/kscience/dataforge/meta/Config;)V
public synthetic fun <init> (Lspace/kscience/dataforge/meta/Config;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lspace/kscience/dataforge/meta/ObservableMutableMeta;)V
public synthetic fun <init> (Lspace/kscience/dataforge/meta/ObservableMutableMeta;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addTrace (Lspace/kscience/plotly/models/Trace;)V
public fun getConfig ()Lspace/kscience/dataforge/meta/Config;
public final fun getData ()Ljava/util/List;
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;
public fun toMeta ()Lspace/kscience/dataforge/meta/Meta;
public final fun traces (Ljava/util/Collection;)V
public final fun traces ([Lspace/kscience/plotly/models/Trace;)V
Expand Down Expand Up @@ -496,6 +502,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 <init> ()V
public final fun getCandleStickMeta ()Lspace/kscience/dataforge/values/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;
Expand All @@ -504,19 +511,18 @@ public final class space/kscience/plotly/models/CandleStick : space/kscience/plo
public final fun getIncreasing ()Lspace/kscience/plotly/models/CandleStickLine;
public final fun getLineWidth ()D
public final fun getLow ()Lspace/kscience/plotly/models/TraceValues;
public final fun getMeta ()Lspace/kscience/dataforge/values/Value;
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 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 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 setMeta (Lspace/kscience/dataforge/values/Value;)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
Expand Down
Loading

0 comments on commit 77c3882

Please sign in to comment.