Skip to content

Commit

Permalink
Merge pull request #78 from mipt-npm/dev
Browse files Browse the repository at this point in the history
0.4.2
  • Loading branch information
altavir authored May 30, 2021
2 parents c19525d + 0f14699 commit 9498f75
Show file tree
Hide file tree
Showing 24 changed files with 204 additions and 80 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

### Security

## [0.4.2]

### Added
- `automargin` property to `Axis` according to https://plotly.com/python/reference/layout/xaxis/#layout-xaxis-automargin

### Fixed
- Remove unnecessary `kotlinx-css` dependency.
- Added compatibility mode for legacy notebooks. Use `Plotly.jupyter.notebook()` call to enable legacy mode.

### Security
## [0.4.0]
### Added
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

## Artifact details

**TBD**
[![Maven Central](https://img.shields.io/maven-central/v/space.kscience/plotlykt-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22%20AND%20a:%22plotlykt-core%22)

Dev builds and intermediate artifacts are available via `https://repo.kotlin.link` maven repository.

## Compatibility note
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.
The current `0.4.2` 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 @@ -53,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.0")
//@file:DependsOn("space.kscience:plotlykt-server:0.4.0") // Use this one for sever integration.
@file:DependsOn("space.kscience:plotlykt-jupyter:0.4.2")
//@file:DependsOn("space.kscience:plotlykt-server:0.4.2") // 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 @@ -90,7 +92,7 @@ repositories {
}

dependencies {
implementation("space.kscience:plotlykt-server:0.4.0")
implementation("space.kscience:plotlykt-server:0.4.2")
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val dataforgeVersion by extra("0.4.0")

allprojects {
group = "space.kscience"
version = "0.4.0"
version = "0.4.2"

repositories {
maven("https://repo.kotlin.link")
Expand Down
4 changes: 3 additions & 1 deletion docs/templates/README-TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

## Artifact details

**TBD**
[![Maven Central](https://img.shields.io/maven-central/v/space.kscience/plotlykt-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22space.kscience%22%20AND%20a:%22plotlykt-core%22)

Dev builds and intermediate artifacts are available via `https://repo.kotlin.link` maven repository.

## Compatibility note
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.
Expand Down
1 change: 1 addition & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}

// A workaround for https://youtrack.jetbrains.com/issue/KT-44101
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/customPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun main() {
val trace2 = Trace(x1, y2) { name = "cos" }

Plotly.fragment { container ->
val plot = plot(renderer = container) {
plot(renderer = container) {
traces(trace1, trace2)
layout {
title = "The plot above"
Expand Down
3 changes: 1 addition & 2 deletions fx-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("no.tornado:tornadofx:1.7.19")
implementation(project(":plotlykt-server"))
implementation("no.tornado:tornadofx:1.7.19")
implementation("ch.qos.logback:logback-classic:1.2.3")
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
4 changes: 2 additions & 2 deletions js-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

Expand All @@ -16,5 +16,5 @@ kotlin {

dependencies {
implementation(project(":plotlykt-core"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.4.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.5.0")
}
2 changes: 2 additions & 0 deletions plotlykt-core/api/plotlykt-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/
public static final field Companion Lspace/kscience/plotly/models/Axis$Companion;
public fun <init> ()V
public final fun getAnchor ()Ljava/lang/String;
public final fun getAutomargin ()Ljava/lang/Boolean;
public final fun getAutorange ()Z
public final fun getAutotick ()Ljava/lang/Boolean;
public final fun getColor ()Lspace/kscience/plotly/models/Color;
Expand Down Expand Up @@ -273,6 +274,7 @@ public final class space/kscience/plotly/models/Axis : space/kscience/dataforge/
public final fun getZerolinecolor ()Lspace/kscience/plotly/models/Color;
public final fun getZerolinewidth ()Ljava/lang/Number;
public final fun setAnchor (Ljava/lang/String;)V
public final fun setAutomargin (Ljava/lang/Boolean;)V
public final fun setAutorange (Z)V
public final fun setAutotick (Ljava/lang/Boolean;)V
public final fun setDtick (Lspace/kscience/dataforge/values/Value;)V
Expand Down
5 changes: 2 additions & 3 deletions plotlykt-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id("ru.mipt.npm.gradle.mpp")
`maven-publish`
}

kscience {
publish()
useHtml()
}

val dataforgeVersion: String by rootProject.extra
Expand All @@ -13,8 +14,6 @@ kotlin {
commonMain {
dependencies {
api("space.kscience:dataforge-meta:$dataforgeVersion")
api("org.jetbrains.kotlinx:kotlinx-html:${ru.mipt.npm.gradle.KScienceVersions.htmlVersion}")
api("org.jetbrains:kotlin-css:1.0.0-pre.122-kotlin-1.4.10")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public class Axis : Scheme() {

public var autotick: Boolean? by boolean()

/**
* Determines whether long tick labels automatically grow the figure margins.
*/
public var automargin: Boolean? by boolean()

/**
* Enumerated, one of ( "free" | "/^x([2-9]|[1-9][0-9]+)?$/" | "/^y([2-9]|[1-9][0-9]+)?$/" )
* If set to an opposite-letter axis id (e.g. `x2`, `y`), this axis is bound to the corresponding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public fun Plot.toHTML(
}
body {
StaticPlotlyRenderer.run {
renderPlot(this@toHTML, "plot", config)
renderPlot(this@toHTML, this@toHTML.toString(), config)
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions plotlykt-jupyter/api/plotlykt-jupyter.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public final class space/kscience/plotly/PlotlyIntegration : org/jetbrains/kotlinx/jupyter/api/libraries/JupyterIntegration, space/kscience/plotly/PlotlyRenderer {
public fun <init> ()V
public fun onLoaded (Lorg/jetbrains/kotlinx/jupyter/api/libraries/JupyterIntegration$Builder;)V
public fun renderPlot (Lkotlinx/html/FlowContent;Lspace/kscience/plotly/Plot;Ljava/lang/String;Lspace/kscience/plotly/PlotlyConfig;)Lspace/kscience/plotly/Plot;
}

public final class space/kscience/plotly/PlotlyIntegrationKt {
public static final fun getJupyter (Lspace/kscience/plotly/Plotly;)Lspace/kscience/plotly/PlotlyJupyterConfiguration;
}

public final class space/kscience/plotly/PlotlyJupyterConfiguration {
public static final field INSTANCE Lspace/kscience/plotly/PlotlyJupyterConfiguration;
public final fun getLegacyMode ()Z
public final fun notebook ()Lspace/kscience/plotly/PlotlyHtmlFragment;
public final fun setLegacyMode (Z)V
}

5 changes: 1 addition & 4 deletions plotlykt-jupyter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
plugins {
id("ru.mipt.npm.gradle.jvm")
kotlin("jupyter.api")
}

kscience{
publish()
`maven-publish`
}

val dataforgeVersion: String by rootProject.extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,33 @@ import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
import space.kscience.plotly.Plotly.PLOTLY_CDN

public object PlotlyJupyterConfiguration {
public var legacyMode: Boolean = false

/**
* Switch plotly renderer to the legacy notebook mode (Jupyter classic)
*/
public fun notebook(): PlotlyHtmlFragment {
legacyMode = true
return PlotlyHtmlFragment {
div {
style = "color: blue;"
+"Plotly notebook integration switch into the legacy mode."
}
}
}
}

/**
* Global plotly jupyter configuration
*/
@UnstablePlotlyAPI
@JupyterLibrary
internal class PlotlyIntegration : JupyterIntegration(), PlotlyRenderer {
public val Plotly.jupyter: PlotlyJupyterConfiguration
get() = PlotlyJupyterConfiguration

@UnstablePlotlyAPI
@JupyterLibrary
public class PlotlyIntegration : JupyterIntegration(), PlotlyRenderer {
override fun FlowContent.renderPlot(plot: Plot, plotId: String, config: PlotlyConfig): Plot {
div {
id = plotId
Expand Down Expand Up @@ -53,11 +76,11 @@ internal class PlotlyIntegration : JupyterIntegration(), PlotlyRenderer {
override fun Builder.onLoaded() {

resources {
js("plotly"){
js("plotly") {
url(PLOTLY_CDN)
classPath("js/plotly.min.js")
}
js("plotlyConnect"){
js("plotlyConnect") {
classPath("js/plotlyConnect.js")
}
}
Expand All @@ -71,16 +94,45 @@ internal class PlotlyIntegration : JupyterIntegration(), PlotlyRenderer {
"kotlinx.html.*"
)

import("space.kscience.plotly.jupyter")

render<PlotlyHtmlFragment> {
HTML(it.toString())
}

render<Plot> {
HTML(renderPlot(it))
val renderer = this@PlotlyIntegration

render<Plot> { plot ->
if (PlotlyJupyterConfiguration.legacyMode) {
HTML(
Plotly.page(renderer = renderer) {
plot(renderer = renderer, plot = plot)
}.render(),
true
)
} else {
HTML(
createHTML().div {
renderer.run { renderPlot(plot) }
}
)
}
}

render<PlotlyFragment> {
HTML(renderFragment(it))
render<PlotlyFragment> { fragment ->
if (PlotlyJupyterConfiguration.legacyMode) {
HTML(
Plotly.page(renderer = renderer) { renderer ->
fragment.render(this, renderer)
}.render(), true
)
} else {
HTML(
createHTML().div {
fragment.render(this, renderer)
}
)
}
}

render<PlotlyPage> {
Expand Down
5 changes: 3 additions & 2 deletions plotlykt-script/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
id("ru.mipt.npm.gradle.jvm")
application
`maven-publish`
}

kscience{
useHtml()
application()
publish()
}

repositories {
Expand All @@ -25,5 +26,5 @@ dependencies {
}

application{
mainClassName = "space.kscience.plotly.script.CliKt"
mainClass.set("space.kscience.plotly.script.CliKt")
}
Loading

0 comments on commit 9498f75

Please sign in to comment.