Skip to content

Commit f4d2777

Browse files
authored
Merge pull request #64 from mipt-npm/dev
0.3.1
2 parents c911883 + 7b10437 commit f4d2777

File tree

19 files changed

+330
-54
lines changed

19 files changed

+330
-54
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10+
11+
### Changed
12+
13+
### Deprecated
14+
15+
### Removed
16+
17+
### Fixed
18+
19+
### Security
20+
21+
## [0.3.1]
22+
### Added
1023
- Table widget implementation by @ArtificialPB
24+
- Mathjax header promoted to stable
25+
- Tabbed plots layout (experimental)
26+
- Trace value builders for functions and ranges (experimental)
1127

1228
### Changed
1329
- **Breaking API change!** Trace `text` replaced by `TraceValues`
1430
- Moved to DataForge 0.3 API
15-
- Kotlin 1.4.21
31+
- Kotlin 1.4.30
32+
- **JVM-IR**
1633
- Plot `Config` moved to constructor
1734
- Replaced direct color accessor by a delegate
1835

@@ -22,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2239

2340
### Fixed
2441
- https://github.com/mipt-npm/plotly.kt/issues/53
42+
- Add JQuery to Bootstrap headers
2543

2644
### Security
2745

build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ plugins {
44
}
55

66
val ktorVersion by extra("1.5.0")
7-
val dataforgeVersion by extra("0.3.0-dev-1")
7+
val dataforgeVersion by extra("0.3.0")
88
val htmlVersion by extra("0.7.2")
99

1010
val bintrayRepo by extra("kscience")
1111
val githubProject by extra("plotly.kt")
1212

1313
allprojects {
1414
group = "kscience.plotlykt"
15-
version = "0.3.1-dev-4"
15+
version = "0.3.1"
1616

1717
repositories {
1818
mavenLocal()
@@ -23,4 +23,8 @@ allprojects {
2323

2424
apiValidation {
2525
ignoredProjects.addAll(listOf("examples", "fx-demo", "js-demo"))
26+
}
27+
28+
ksciencePublish{
29+
spaceRepo = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven"
2630
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import hep.dataforge.meta.invoke
2+
import kscience.plotly.Plotly
3+
import kscience.plotly.UnstablePlotlyAPI
4+
import kscience.plotly.makeFile
5+
import kscience.plotly.models.functionXY
6+
import kscience.plotly.trace
7+
import kotlin.math.PI
8+
import kotlin.math.sin
9+
10+
@OptIn(UnstablePlotlyAPI::class)
11+
fun main() {
12+
val plot = Plotly.plot {
13+
repeat(50) { phase ->
14+
trace {
15+
functionXY(0.0..2 * PI, step = 0.05) {
16+
sin(it + phase * 2 * PI / 60)
17+
}
18+
name = "Sin with phase offset ${phase * 2 * PI / 60}"
19+
}
20+
}
21+
22+
layout {
23+
title = "Graph name"
24+
xaxis {
25+
title = "x axis"
26+
}
27+
yaxis {
28+
title = "y axis"
29+
}
30+
height = 700
31+
}
32+
}
33+
34+
plot.makeFile()
35+
}

examples/src/main/kotlin/io/ioUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import krangl.DataFrame
44
import krangl.readCSV
55
import kscience.plotly.Plotly
66

7-
@OptIn(ExperimentalStdlibApi::class)
87
fun readResourceAsString(resource: String): String =
9-
Plotly.javaClass.getResourceAsStream(resource).readAllBytes().decodeToString()
8+
Plotly.javaClass.getResourceAsStream(resource)?.readAllBytes()?.decodeToString()
9+
?: error("Resource $resource not found")
1010

1111
fun readResourceAsCsv(resource: String): DataFrame =
12-
DataFrame.readCSV(Plotly.javaClass.getResource(resource).file.toString())
12+
DataFrame.readCSV(Plotly.javaClass.getResource(resource)?.file?.toString() ?: error("Resource $resource not found"))

examples/src/main/kotlin/latexLabels.kt

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
import kotlinx.html.script
2-
import kotlinx.html.unsafe
31
import kscience.plotly.*
42

5-
val customMathJaxHeader = HtmlFragment {
6-
script {
7-
type = "text/x-mathjax-config"
8-
unsafe {
9-
//language=JavaScript
10-
+"""
11-
MathJax.Hub.Config({
12-
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
13-
});
14-
"""
15-
}
16-
}
17-
script {
18-
type = "text/javascript"
19-
async = true
20-
src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_SVG"
21-
}
22-
}
23-
24-
253
fun main() {
26-
Plotly.page(customMathJaxHeader, cdnPlotlyHeader) {
4+
Plotly.page(mathJaxHeader, cdnPlotlyHeader) {
275
plot {
286
scatter {
297
x(2, 3, 4, 5)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import kscience.plotly.*
2+
import kscience.plotly.models.Trace
3+
import kscience.plotly.models.invoke
4+
import kscience.plotly.palettes.T10
5+
import kotlin.math.PI
6+
import kotlin.math.cos
7+
import kotlin.math.sin
8+
9+
@UnstablePlotlyAPI
10+
fun main() {
11+
12+
val x = (0..100).map { it.toDouble() / 100.0 }
13+
val y1 = x.map { sin(2.0 * PI * it) }
14+
val y2 = x.map { cos(2.0 * PI * it) }
15+
16+
val trace1 = Trace(x, y1) {
17+
name = "sin"
18+
marker.color(T10.BLUE)
19+
20+
}
21+
22+
val trace2 = Trace(x, y2) {
23+
name = "cos"
24+
marker.color(T10.ORANGE)
25+
26+
}
27+
28+
val responsive = PlotlyConfig{
29+
responsive = true
30+
}
31+
32+
val plot = Plotly.tabs {
33+
34+
tab("First"){
35+
plot (config = responsive){
36+
traces(trace1)
37+
layout {
38+
title = "First graph"
39+
xaxis.title = "x axis name"
40+
xaxis.title = "y axis name"
41+
}
42+
}
43+
}
44+
tab("Second"){
45+
plot(config = responsive) {
46+
traces(trace2)
47+
layout {
48+
title = "Second graph"
49+
xaxis.title = "x axis name"
50+
xaxis.title = "y axis name"
51+
}
52+
}
53+
}
54+
}
55+
56+
plot.makeFile()
57+
}

examples/src/main/kotlin/tutorials/SinusPicture.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import kotlin.math.sin
1717
* - Change margins on the plot edges
1818
* - Add shapes (vertical lines)
1919
*/
20+
@OptIn(UnstablePlotlyAPI::class)
2021
fun main() {
2122
val div = 200 / PI
2223
val sub = PI / 6

plotlykt-core/api/plotlykt-core.api

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public final class kscience/plotly/Plot : hep/dataforge/meta/Configurable, hep/d
5555
public fun <init> ()V
5656
public fun <init> (Lhep/dataforge/meta/Config;)V
5757
public synthetic fun <init> (Lhep/dataforge/meta/Config;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
58+
public final fun addTrace (Lkscience/plotly/models/Trace;)V
5859
public fun getConfig ()Lhep/dataforge/meta/Config;
5960
public final fun getData ()Ljava/util/List;
6061
public final fun getLayout ()Lkscience/plotly/models/Layout;
@@ -74,6 +75,7 @@ public final class kscience/plotly/PlotExtensionsKt {
7475
public static final fun pie (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/models/Pie;
7576
public static final fun scatter (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/models/Scatter;
7677
public static final fun shape (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)V
78+
public static final fun table (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/models/Table;
7779
public static final fun text (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)V
7880
public static final fun violin (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/models/Violin;
7981
}
@@ -118,6 +120,33 @@ public final class kscience/plotly/PlotKt {
118120
public static final fun trace (Lkscience/plotly/Plot;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/models/Trace;
119121
}
120122

123+
public final class kscience/plotly/PlotTabs {
124+
public fun <init> ()V
125+
public final fun getTabs ()Ljava/util/List;
126+
public final fun tab (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V
127+
public static synthetic fun tab$default (Lkscience/plotly/PlotTabs;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
128+
}
129+
130+
public final class kscience/plotly/PlotTabs$Tab {
131+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lkscience/plotly/PlotlyFragment;)V
132+
public final fun component1 ()Ljava/lang/String;
133+
public final fun component2 ()Ljava/lang/String;
134+
public final fun component3 ()Lkscience/plotly/PlotlyFragment;
135+
public final fun copy (Ljava/lang/String;Ljava/lang/String;Lkscience/plotly/PlotlyFragment;)Lkscience/plotly/PlotTabs$Tab;
136+
public static synthetic fun copy$default (Lkscience/plotly/PlotTabs$Tab;Ljava/lang/String;Ljava/lang/String;Lkscience/plotly/PlotlyFragment;ILjava/lang/Object;)Lkscience/plotly/PlotTabs$Tab;
137+
public fun equals (Ljava/lang/Object;)Z
138+
public final fun getContent ()Lkscience/plotly/PlotlyFragment;
139+
public final fun getId ()Ljava/lang/String;
140+
public final fun getTitle ()Ljava/lang/String;
141+
public fun hashCode ()I
142+
public fun toString ()Ljava/lang/String;
143+
}
144+
145+
public final class kscience/plotly/PlotTabsKt {
146+
public static final fun tabs (Lkscience/plotly/Plotly;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lkscience/plotly/PlotlyPage;
147+
public static synthetic fun tabs$default (Lkscience/plotly/Plotly;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkscience/plotly/PlotlyPage;
148+
}
149+
121150
public final class kscience/plotly/Plotly {
122151
public static final field INSTANCE Lkscience/plotly/Plotly;
123152
public static final field VERSION Ljava/lang/String;
@@ -740,6 +769,16 @@ public final class kscience/plotly/models/Fill : hep/dataforge/meta/Scheme {
740769
public final class kscience/plotly/models/Fill$Companion : hep/dataforge/meta/SchemeSpec {
741770
}
742771

772+
public final class kscience/plotly/models/FillTraceKt {
773+
public static final fun appendXY (Lkscience/plotly/models/Trace;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;)V
774+
public static final fun appendXY (Lkscience/plotly/models/Trace;[Lkotlin/Pair;)V
775+
public static synthetic fun appendXY$default (Lkscience/plotly/models/Trace;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/Number;ILjava/lang/Object;)V
776+
public static final fun functionXY (Lkscience/plotly/models/Trace;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)V
777+
public static final fun functionXY (Lkscience/plotly/models/Trace;Lkotlin/ranges/ClosedFloatingPointRange;DLkotlin/jvm/functions/Function1;)V
778+
public static final fun functionXY (Lkscience/plotly/models/Trace;Lkotlin/ranges/IntRange;Lkotlin/jvm/functions/Function1;)V
779+
public static synthetic fun functionXY$default (Lkscience/plotly/models/Trace;Lkotlin/ranges/ClosedFloatingPointRange;DLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
780+
}
781+
743782
public final class kscience/plotly/models/FillType : java/lang/Enum {
744783
public static final field none Lkscience/plotly/models/FillType;
745784
public static final field tonext Lkscience/plotly/models/FillType;

plotlykt-core/src/commonMain/kotlin/kscience/plotly/Plot.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kscience.plotly
22

33
import hep.dataforge.meta.*
4+
import hep.dataforge.misc.DFBuilder
45
import kotlinx.serialization.json.JsonObject
56
import kotlinx.serialization.json.buildJsonArray
67
import kotlinx.serialization.json.buildJsonObject
@@ -25,7 +26,7 @@ public class Plot(
2526
*/
2627
public val layout: Layout by config.spec(Layout)
2728

28-
private fun appendTrace(trace: Trace) {
29+
public fun addTrace(trace: Trace) {
2930
val traceRoot = trace.rootNode
3031
if (traceRoot is Config) {
3132
config.append("data", traceRoot)
@@ -41,14 +42,14 @@ public class Plot(
4142
* Append all traces from [traces] to the plot
4243
*/
4344
public fun traces(traces: Collection<Trace>) {
44-
traces.forEach { appendTrace(it) }
45+
traces.forEach { addTrace(it) }
4546
}
4647

4748
/**
4849
* Append all [traces]
4950
*/
5051
public fun traces(vararg traces: Trace) {
51-
traces.forEach { appendTrace(it) }
52+
traces.forEach { addTrace(it) }
5253
}
5354

5455
/**

plotlykt-core/src/commonMain/kotlin/kscience/plotly/dfExt.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kscience.plotly
22

33
import hep.dataforge.meta.*
4+
import hep.dataforge.misc.DFExperimental
45
import hep.dataforge.names.*
56
import hep.dataforge.values.Value
67
import hep.dataforge.values.asValue

0 commit comments

Comments
 (0)