Replace plot properties by a wrapper
This commit is contained in:
parent
f0a6e12358
commit
81aa5d2fcc
@ -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
|
||||
|
@ -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
|
||||
|
@ -298,4 +298,3 @@ public operator fun MutableVisionProperties.set(name: Name, value: String): Unit
|
||||
|
||||
public operator fun MutableVisionProperties.set(name: String, value: String): Unit =
|
||||
set(name.parseAsName(), value)
|
||||
|
||||
|
@ -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 constructor(plot: Plot) : this() {
|
||||
properties.setProperty(Name.EMPTY, 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)
|
||||
}
|
||||
|
||||
public val plot: Plot get() = Plot(properties.root().asObservable())
|
||||
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<Name> = if (meta is ObservableMeta) {
|
||||
callbackFlow {
|
||||
meta.onChange(this) {
|
||||
launch {
|
||||
send(it)
|
||||
}
|
||||
}
|
||||
awaitClose {
|
||||
meta.removeListener(this)
|
||||
}
|
||||
}
|
||||
} else emptyFlow()
|
||||
|
||||
|
||||
override fun invalidate(propertyName: Name) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override val descriptor: MetaDescriptor? = null // TODO add descriptor for Plot
|
||||
}
|
||||
|
||||
public fun Plot.asVision(): VisionOfPlotly = VisionOfPlotly(this)
|
||||
|
@ -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}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user