diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 3ecb7f9f..4c9649c6 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -25,9 +25,9 @@ import space.kscience.visionforge.ring.ThreeCanvasWithControls import space.kscience.visionforge.ring.tab import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.ambientLight +import space.kscience.visionforge.solid.edges import space.kscience.visionforge.solid.set import space.kscience.visionforge.solid.specifications.Canvas3DOptions -import space.kscience.visionforge.solid.three.edges import styled.css import styled.styledDiv import styled.styledSpan diff --git a/gradle.properties b/gradle.properties index aeb2ca21..668f0f5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ kotlin.code.style=official kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false -#kotlin.incremental.js.ir=true +kotlin.incremental.js.ir=true org.gradle.parallel=true org.gradle.jvmargs=-Xmx4G diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt index cddb6585..eb001b64 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt @@ -297,5 +297,4 @@ public operator fun MutableVisionProperties.set(name: Name, value: String): Unit setValue(name, value.asValue()) public operator fun MutableVisionProperties.set(name: String, value: String): Unit = - set(name.parseAsName(), value) - + set(name.parseAsName(), value) \ No newline at end of file diff --git a/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt b/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt index 2e89dbf5..54ba4551 100644 --- a/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt +++ b/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt @@ -1,25 +1,83 @@ package space.kscience.visionforge.plotly +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.launch import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import space.kscience.dataforge.meta.asObservable +import kotlinx.serialization.Transient +import space.kscience.dataforge.meta.* +import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.names.Name import space.kscience.plotly.Plot import space.kscience.plotly.Plotly -import space.kscience.visionforge.AbstractVision +import space.kscience.visionforge.MutableVisionProperties +import space.kscience.visionforge.Vision import space.kscience.visionforge.html.VisionOutput -import space.kscience.visionforge.root @Serializable @SerialName("vision.plotly") -public class VisionOfPlotly private constructor() : AbstractVision() { +public class VisionOfPlotly private constructor( + @Serializable(MutableMetaSerializer::class) public val meta: MutableMeta, +) : Vision { + public constructor(plot: Plot) : this(plot.meta) + + public val plot: Plot get() = Plot(meta.asObservable()) + + @Transient + override var parent: Vision? = null + + @Transient + override val properties: MutableVisionProperties = object : MutableVisionProperties { + override fun setProperty(name: Name, node: Meta?, notify: Boolean) { + meta.setMeta(name, node) + } + + override fun setValue(name: Name, value: Value?, notify: Boolean) { + meta.setValue(name, value) + } + + override val own: Meta get() = meta + + override val descriptor: MetaDescriptor? get() = this@VisionOfPlotly.descriptor + + override fun getProperty( + name: Name, + inherit: Boolean?, + includeStyles: Boolean?, + ): MutableMeta = meta.getMeta(name) ?: MutableMeta() + + override fun getValue( + name: Name, + inherit: Boolean?, + includeStyles: Boolean?, + ): Value? = meta.getValue(name) + + override val changes: Flow = if (meta is ObservableMeta) { + callbackFlow { + meta.onChange(this) { + launch { + send(it) + } + } + awaitClose { + meta.removeListener(this) + } + } + } else emptyFlow() + + + override fun invalidate(propertyName: Name) { + // Do nothing + } - public constructor(plot: Plot) : this() { - properties.setProperty(Name.EMPTY, plot.meta) } - public val plot: Plot get() = Plot(properties.root().asObservable()) + + override val descriptor: MetaDescriptor? = null // TODO add descriptor for Plot } public fun Plot.asVision(): VisionOfPlotly = VisionOfPlotly(this) diff --git a/visionforge-plotly/src/commonTest/kotlin/space/kscience/visionforge/plotly/VisionOfPlotlyTest.kt b/visionforge-plotly/src/commonTest/kotlin/space/kscience/visionforge/plotly/VisionOfPlotlyTest.kt new file mode 100644 index 00000000..7634e73d --- /dev/null +++ b/visionforge-plotly/src/commonTest/kotlin/space/kscience/visionforge/plotly/VisionOfPlotlyTest.kt @@ -0,0 +1,22 @@ +package space.kscience.visionforge.plotly + +import space.kscience.plotly.Plotly +import space.kscience.plotly.scatter +import kotlin.test.Test +import kotlin.test.assertTrue + +class VisionOfPlotlyTest { + @Test + fun conversion(){ + val plot = Plotly.plot { + scatter { + x(1,2,3) + y(1,2,3) + } + } + val vision = VisionOfPlotly(plot) +// println(vision.plot.toJsonString()) +// println(vision.plot.data.toJsonString()) + assertTrue { vision.plot.data.first().x.doubles.size == 3} + } +} \ No newline at end of file