Skip to content

Commit 3e5a287

Browse files
authored
Merge pull request #73 from mipt-npm/dev
0.4.0
2 parents 1c69346 + 27fec65 commit 3e5a287

File tree

181 files changed

+3429
-2900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3429
-2900
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ build/
44
out/
55

66
#gradle.properties
7-
/notebooks/.ipynb_checkpoints/
7+
/examples/notebooks/.ipynb_checkpoints/

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Fixed
1818

19+
### Security
20+
## [0.4.0]
21+
### Added
22+
- Jupyter integration plugin for server
23+
- Separate static plot integration module in `plotlykt-jupyter`
24+
- Expanded JS demo
25+
- Jupyter support goes beta
26+
27+
### Changed
28+
- Package change (again) to `space.kscience`
29+
- Build tools `0.9.5`
30+
- Kotlin `1.5.0`
31+
- HtmlFragment renamed to PlotlyHtmlFragment
32+
33+
### Deprecated
34+
35+
### Removed
36+
- Local bootstrap
37+
38+
### Fixed
39+
- Incomplete coverage in JS (#70)
40+
1941
### Security
2042

2143
## [0.3.1]

README.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
[![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
22
[![DOI](https://zenodo.org/badge/186020000.svg)](https://zenodo.org/badge/latestdoi/186020000)
33
![Gradle build](https://github.com/mipt-npm/plotly.kt/workflows/Gradle%20build/badge.svg)
4-
54
[![Kotlin JS IR supported](https://img.shields.io/badge/Kotlin%2FJS-IR%20supported-yellow)](https://kotl.in/jsirsupported)
65

76
![Plotlykt logo](./docs/logo_text.svg)
87

9-
## Release version
10-
11-
Plotly.kt core on Bintray: [ ![Bintray](https://api.bintray.com/packages/mipt-npm/kscience/plotlykt-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/plotlykt-core/_latestVersion)
12-
13-
Plotly.kt ktor server on Bintray: [ ![Bintray](https://api.bintray.com/packages/mipt-npm/kscience/plotlykt-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/plotlykt-server/_latestVersion)
14-
15-
## Development version
8+
## Artifact details
169

17-
Plotly.kt core on Bintray: [ ![Bintray](https://api.bintray.com/packages/mipt-npm/dev/plotlykt-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/plotlykt-core/_latestVersion)
18-
19-
Plotly.kt ktor server on Bintray: [ ![Bintray](https://api.bintray.com/packages/mipt-npm/dev/plotlykt-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/plotlykt-server/_latestVersion)
10+
**TBD**
2011

2112
## Compatibility note
22-
The current `0.3.0` version of the library is compatible with kotlin 1.4 with JS-IR and kotlinx-serialization 1.0.0. It is not guaranteed to work with kotlin 1.3.
23-
24-
Plotly.kt currently targets JVM 11 and newer, so appropriate target should be used for compillation. If you need to support older JVMs, please open an [issue](https://github.com/mipt-npm/plotly.kt/issues) with your use-case.
13+
The current `0.4.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.
2514

2615
# TL;DR
2716
See [examples](./examples/src/main/kotlin).
@@ -58,11 +47,17 @@ Plotly is a JavaScript library, yet it is convenient to have a type-safe API whe
5847
Plotly.kt could be run in a JavaFX browser. An example project is presented in [fx-demo](./fx-demo).
5948

6049
## Kotlin jupyter kernel (experimental)
61-
Plotly.kt comes with (for now experimental) support for integration with [Kotlin Jupyter kernel](https://github.com/Kotlin/kotlin-jupyter).
50+
Plotly.kt comes with (beta-version) support for integration with [Kotlin Jupyter kernel](https://github.com/Kotlin/kotlin-jupyter). See details [here](./docs/tutorials/jupyter.md).
6251

63-
The examples of the notebooks are shown in [notebooks](./notebooks) directory. There are two module descriptor `plotly.json` and `plotly-server.json` in the same directory. They should be loaded according to Kotlin kernel documentation (either copied to `~/jypyter_kotlin/libraries` or loaded directly).
52+
The examples of the notebooks are shown in [notebooks](./examples/notebooks) directory. Plotly.kt uses Kotlin jupyter notebook API for integration (available in kernel version `0.8.3.236` and later). In order to load the library together with automatic imports one need to simply load a library in a following way:
6453

65-
The module `plotly` allows to render 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)).
54+
```kotlin
55+
@file:Repository("https://repo.kotlin.link")
56+
@file:DependsOn("space.kscience:plotlykt-jupyter:0.4.0")
57+
//@file:DependsOn("space.kscience:plotlykt-server:0.4.0") // Use this one for sever integration.
58+
```
59+
60+
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)).
6661

6762
The module `plotly-server` adds server capabilities and allows to render dynamic plots in notebooks (see [demo notebook](./notebooks/plotlykt-server-demo.ipynb)). One must note that for dynamic pages, one must pass `renderer` parameter explicitly to plot like it is done in examples.
6863

@@ -91,25 +86,16 @@ plugins {
9186
}
9287

9388
repositories {
94-
jcenter()
95-
maven("https://dl.bintray.com/mipt-npm/dataforge")
96-
maven("https://dl.bintray.com/mipt-npm/kscience")
89+
maven("https://repo.kotlin.link")
9790
}
9891

9992
dependencies {
100-
implementation("kscience.plotlykt:plotlykt-server:0.3.0")
93+
implementation("kscience.plotlykt:plotlykt-server:0.4.0")
10194
}
10295
```
10396

104-
When using development versions (if version contains `dev`), one should also add
105-
```
106-
maven("https://dl.bintray.com/mipt-npm/dev")
107-
```
108-
into the repository list.
109-
110-
If you do not need the server, then use plotlykt-core instead and remove `ktor` repository.
11197

112-
**NOTICE** due to problems with kolin-logging publishing, DataForge currently uses a separate fork of the library. So `maven("https://dl.bintray.com/mipt-npm/dev")` is mandatory right now. Follow #66 for solution.
98+
If you do not need the server, then use plotlykt-core instead.
11399

114100
# Naming
115101
The library keeps original Plotly API naming wherever it is possible. There are some usability shortcuts, usually provided via kotlin extensions, included in order to simplify user interaction. For example, `text` and `shape` extensions in the top level API.
@@ -131,3 +117,4 @@ Keeping the original naming sometimes causes clashes with Kotlin code style. For
131117
* [Ekaterina Samorodova](https://github.com/ebsamorodova) (JBR-2020 summer internship) - Model refactoring, tutorials and `0.2` release.
132118

133119
The project was partially founded by JetBrains Research grant.
120+

build.gradle.kts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
plugins {
22
kotlin("js") apply false
3-
id("ru.mipt.npm.project")
3+
kotlin("jupyter.api") apply false
4+
id("ru.mipt.npm.gradle.project")
45
}
56

6-
val ktorVersion by extra("1.5.0")
7-
val dataforgeVersion by extra("0.3.0")
8-
val htmlVersion by extra("0.7.2")
9-
10-
val bintrayRepo by extra("kscience")
11-
val githubProject by extra("plotly.kt")
7+
val dataforgeVersion by extra("0.4.0")
128

139
allprojects {
14-
group = "kscience.plotlykt"
15-
version = "0.3.1"
10+
group = "space.kscience"
11+
version = "0.4.0"
1612

1713
repositories {
18-
mavenLocal()
19-
maven("https://dl.bintray.com/kotlin/kotlin-eap")
14+
maven("https://repo.kotlin.link")
2015
maven("https://kotlin.bintray.com/kotlinx")
2116
}
17+
18+
if(name.startsWith("plotlykt")){
19+
apply<MavenPublishPlugin>()
20+
}
2221
}
2322

2423
apiValidation {
2524
ignoredProjects.addAll(listOf("examples", "fx-demo", "js-demo"))
2625
}
2726

2827
ksciencePublish{
29-
spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven"
28+
github("plotly.kt")
29+
space()
30+
sonatype()
31+
}
32+
33+
readme {
34+
readmeTemplate = file("docs/templates/README-TEMPLATE.md")
35+
}
36+
37+
changelog{
38+
version = project.version.toString()
3039
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
> #### Artifact:
2+
>
3+
> This module artifact: `${group}:${name}:${version}`.
4+
>
5+
>
6+
> [![Maven Central](https://img.shields.io/maven-central/v/space.kscience/${name}.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22%20AND%20a:%22${name}%22)
7+
>
8+
> **Gradle:**
9+
>
10+
> ```gradle
11+
> repositories {
12+
> maven { url 'https://repo.kotlin.link' }
13+
> }
14+
>
15+
> dependencies {
16+
> implementation '${group}:${name}:${version}'
17+
> }
18+
> ```
19+
> **Gradle Kotlin DSL:**
20+
>
21+
> ```kotlin
22+
> repositories {
23+
> maven("https://https://repo.kotlin.link")
24+
> }
25+
>
26+
> dependencies {
27+
> implementation("${group}:${name}:${version}")
28+
> }
29+
> ```

docs/templates/README-TEMPLATE.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
[![JetBrains Research](https://jb.gg/badges/research.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
2+
[![DOI](https://zenodo.org/badge/186020000.svg)](https://zenodo.org/badge/latestdoi/186020000)
3+
![Gradle build](https://github.com/mipt-npm/plotly.kt/workflows/Gradle%20build/badge.svg)
4+
[![Kotlin JS IR supported](https://img.shields.io/badge/Kotlin%2FJS-IR%20supported-yellow)](https://kotl.in/jsirsupported)
5+
6+
![Plotlykt logo](./docs/logo_text.svg)
7+
8+
## Artifact details
9+
10+
**TBD**
11+
12+
## Compatibility note
13+
The current `$version` 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.
14+
15+
# TL;DR
16+
See [examples](./examples/src/main/kotlin).
17+
See [original library samples](https://plotly.com/javascript/) to understand capabilities.
18+
19+
# Description
20+
21+
This project is developed to allow simple access to plotly functionality from kotlin-multiplatform. The API allows to create plotly configuration and render it as a plotly chart.
22+
23+
The library supports three drawable plot objects:
24+
* `Plot` itself stands for a stand-alone plot frame. It requires external infrastructure to load appropriate JavaScript libraries.
25+
* `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.
26+
* `PlotlyPage` (JVM only) is a complete page, including body fragment and page headers (needed to load JavaScript part of Plotly).
27+
28+
The work with plotly graphs could be rendered in following modes:
29+
30+
## HTML page export
31+
(JVM only) Export plot or a plot grid in a standalone html file, which
32+
uses CDN based plotly distribution. This mode does not support updates.
33+
34+
See [staticPlot](./examples/src/main/kotlin/staticPlot.kt) and
35+
[customPage](./examples/src/main/kotlin/customPage.kt) for examples.
36+
37+
## Ktor-based server with dynamic updates
38+
(JVM only) A Ktor CIO server with full multi-page and update capabilities.
39+
40+
See [simpleServer](./examples/src/main/kotlin/simpleServer.kt) and
41+
[dynamicServer](./examples/src/main/kotlin/dynamicServer.kt) for examples.
42+
43+
## Kotlin-JS
44+
Plotly is a JavaScript library, yet it is convenient to have a type-safe API when using in with Kotlin-JS. The sample application is available in [js-demo](./js-demo) module. One should node that Plotly.kt for JS is not a zero-cost wrapper like TypeScript definitions, it maintains its own object structure, could generate stand-alone models and some internal optimizations.
45+
46+
## JavaFX browser
47+
Plotly.kt could be run in a JavaFX browser. An example project is presented in [fx-demo](./fx-demo).
48+
49+
## Kotlin jupyter kernel (experimental)
50+
Plotly.kt comes with (beta-version) support for integration with [Kotlin Jupyter kernel](https://github.com/Kotlin/kotlin-jupyter). See details [here](./docs/tutorials/jupyter.md).
51+
52+
The examples of the notebooks are shown in [notebooks](./examples/notebooks) directory. Plotly.kt uses Kotlin jupyter notebook API for integration (available in kernel version `0.8.3.236` and later). In order to load the library together with automatic imports one need to simply load a library in a following way:
53+
54+
```kotlin
55+
@file:Repository("https://repo.kotlin.link")
56+
@file:DependsOn("space.kscience:plotlykt-jupyter:$version")
57+
//@file:DependsOn("space.kscience:plotlykt-server:$version") // Use this one for sever integration.
58+
```
59+
60+
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)).
61+
62+
The module `plotly-server` adds server capabilities and allows to render dynamic plots in notebooks (see [demo notebook](./notebooks/plotlykt-server-demo.ipynb)). One must note that for dynamic pages, one must pass `renderer` parameter explicitly to plot like it is done in examples.
63+
64+
## Direct image render via Orca (experimental)
65+
[Plotly Orca](https://github.com/plotly/orca) application allows direct rendering of plots (not fragments or pages) to raster of vector images.
66+
`Plot.export` extension could be used to call it. It requires for orca to be installed in the system and available on the system path.
67+
68+
## Kotlin-scripting (experimental)
69+
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.
70+
71+
# The feature I need is not implemented!
72+
73+
There are three ways to solve it:
74+
1. Contribute! It is easy! Just add a model you need.
75+
2. Create a model you need in your project or add an extension. Since the inner model is dynamic, you can add features on flight.
76+
3. You can dynamically add missing features directly into configuration
77+
like it done in [unsupportedFeature](./examples/src/main/kotlin/unsupportedFeature.kt) example.
78+
79+
# Build and usage
80+
81+
In order to use the library, one needs to use following `gradle.kts` configuration:
82+
83+
```kotlin
84+
plugins {
85+
kotlin("jvm")
86+
}
87+
88+
repositories {
89+
maven("https://repo.kotlin.link")
90+
}
91+
92+
dependencies {
93+
implementation("kscience.plotlykt:plotlykt-server:$version")
94+
}
95+
```
96+
97+
98+
If you do not need the server, then use plotlykt-core instead.
99+
100+
# Naming
101+
The library keeps original Plotly API naming wherever it is possible. There are some usability shortcuts, usually provided via kotlin extensions, included in order to simplify user interaction. For example, `text` and `shape` extensions in the top level API.
102+
103+
Keeping the original naming sometimes causes clashes with Kotlin code style. For example enum names are unorthodox.
104+
105+
# Planned features
106+
107+
* Table widgets
108+
* Serverside plot events
109+
* Online plot editor
110+
* Dynamic data
111+
* Mathjax and latex support
112+
113+
# Contributions and thanks
114+
* [Vasily Chernov](https://research.jetbrains.org/researchers/vchernov) - initial project foundation
115+
* [Alexander Nozik](https://research.jetbrains.org/researchers/altavir) - dynamic core and server
116+
* [Mikhail Zeleniy](https://research.jetbrains.org/researchers/gama_sennin) - basic models
117+
* [Ekaterina Samorodova](https://github.com/ebsamorodova) (JBR-2020 summer internship) - Model refactoring, tutorials and `0.2` release.
118+
119+
The project was partially founded by JetBrains Research grant.
120+

docs/tutorials/jupyter.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Plotly.kt Jupyter kernel integration
2+
Being a JavaScript library with a Kotlin-JVM backend, Plotly.kt is ideally suited for [Jupyter kotlin kernel](https://github.com/Kotlin/kotlin-jupyter) integration. The integration is supported in two modes:
3+
4+
* Static rendering in [plotlykt-jupyter](../../plotlykt-jupyter) module.
5+
* Dynamic updates processing via [plotlykt-server](../../plotlykt-server) module.
6+
7+
## Loading the library
8+
9+
* Install or update [Jupyter kotlin kernel](https://github.com/Kotlin/kotlin-jupyter) to version `0.9` or later.
10+
* Launch kotlin kernel in `jupyter lab` (classic jupyter notebook is not supported).
11+
* Use `@file:DependsOn("space.kscience:plotlykt-jupyter:$plotlyVersion")` annotation directive to load library, where `$plotlyVersion` is the required version of the library. This approach uses [Kotlin jupyter notebook API](https://github.com/Kotlin/kotlin-jupyter/blob/master/docs/libraries.md#Integration-using-Kotlin-API). For dynamic version one should replace `plotlykt-server` instead of `plotlykr-jupyter`.
12+
* Alternatively one could use `%use plotly` [directive](https://github.com/Kotlin/kotlin-jupyter#supported-libraries). For dynamic version one should replace `plotly-server` instead of `plotly`.
13+
14+
## Automatic rendering
15+
16+
The integration automatically imports `space.kscience.plotlykt.*` and `space.kscience.plotlykt.models.*` and provides automatic rendering for three basic plotly objects: `Plot`, `PlotlyFragment` and `PlotlyPage`. One needs to return those object as result of last expressions in a cell in order to automatically render them.
17+
18+
## Dynamic update server
19+
20+
**TODO**
21+
22+
## What about classic notebook?
23+
24+
**TODO**

examples/build.gradle.kts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,21 @@ plugins {
33
}
44

55
repositories {
6-
mavenLocal()
6+
maven("https://repo.kotlin.link")
7+
mavenCentral()
78
jcenter()
8-
maven("https://dl.bintray.com/mipt-npm/dataforge")
9-
maven("https://dl.bintray.com/mipt-npm/kscience")
10-
maven("https://dl.bintray.com/mipt-npm/dev")
119
}
1210

1311
dependencies {
1412
implementation(project(":plotlykt-server"))
1513
implementation(kotlin("script-runtime"))
1614
implementation(project(":plotlykt-script"))
17-
implementation("de.mpicbg.scicomp:krangl:0.13")
15+
implementation("com.github.holgerbrandl:krangl:0.16.2")
1816
implementation("org.apache.commons:commons-csv:1.8")
1917
}
2018

21-
val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
22-
compileKotlin.kotlinOptions {
23-
jvmTarget = "11"
24-
}
25-
26-
27-
val compileTestKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
28-
compileTestKotlin.kotlinOptions {
29-
jvmTarget = "11"
19+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
20+
kotlinOptions.jvmTarget = "11"
3021
}
3122

3223
// A workaround for https://youtrack.jetbrains.com/issue/KT-44101

0 commit comments

Comments
 (0)