diff --git a/build.gradle.kts b/build.gradle.kts index 3d1779e7..0888408f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,11 +6,11 @@ plugins { // id("org.jetbrains.kotlinx.kover") version "0.5.0" } -val dataforgeVersion by extra("0.7.1") +val dataforgeVersion by extra("0.8.0") allprojects { group = "space.kscience" - version = "0.4.0-dev-1" + version = "0.4.0-dev-2" } subprojects { diff --git a/demo/gdml/build.gradle.kts b/demo/gdml/build.gradle.kts index 03093d23..48a3298e 100644 --- a/demo/gdml/build.gradle.kts +++ b/demo/gdml/build.gradle.kts @@ -38,30 +38,6 @@ kotlin { explicitApi = null } -//kotlin { -// -// sourceSets { -// commonMain { -// dependencies { -// implementation(project(":visionforge-solid")) -// implementation(project(":visionforge-gdml")) -// } -// } -// jvmMain { -// dependencies { -//// implementation(project(":visionforge-fx")) -// implementation("ch.qos.logback:logback-classic:1.2.11") -// } -// } -// jsMain { -// dependencies { -// implementation(project(":ui:ring")) -// implementation(project(":visionforge-threejs")) -// implementation(npm("react-file-drop", "3.0.6")) -// } -// } -// } -//} //val convertGdmlToJson by tasks.creating(JavaExec::class) { // group = "application" diff --git a/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GDMLAppComponent.kt b/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GDMLAppComponent.kt index c3016145..56c408e6 100644 --- a/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GDMLAppComponent.kt +++ b/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GDMLAppComponent.kt @@ -9,6 +9,7 @@ import org.jetbrains.compose.web.dom.Text import org.w3c.files.File import org.w3c.files.FileReader import org.w3c.files.get +import space.kscience.dataforge.context.Context import space.kscience.dataforge.names.Name import space.kscience.gdml.Gdml import space.kscience.gdml.decodeFromString @@ -17,17 +18,18 @@ import space.kscience.visionforge.gdml.markLayers import space.kscience.visionforge.gdml.toVision import space.kscience.visionforge.setAsRoot import space.kscience.visionforge.solid.Solid -import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.ambientLight import space.kscience.visionforge.solid.invoke import space.kscience.visionforge.solid.three.compose.ThreeView +import space.kscience.visionforge.visionManager @Composable -fun GDMLApp(solids: Solids, initialVision: Solid?, selected: Name? = null) { +fun GDMLApp(context: Context, initialVision: Solid?, selected: Name? = null) { var vision: Solid? by remember { mutableStateOf(initialVision) } fun readFileAsync(file: File) { + val visionManager = context.visionManager FileReader().apply { onload = { val data = result as String @@ -36,7 +38,7 @@ fun GDMLApp(solids: Solids, initialVision: Solid?, selected: Name? = null) { name.endsWith(".gdml") || name.endsWith(".xml") -> { val gdml = Gdml.decodeFromString(data) gdml.toVision().apply { - setAsRoot(solids.visionManager) + setAsRoot(visionManager) console.info("Marking layers for file $name") markLayers() ambientLight { @@ -45,7 +47,7 @@ fun GDMLApp(solids: Solids, initialVision: Solid?, selected: Name? = null) { } } - name.endsWith(".json") -> solids.visionManager.decodeFromString(data) + name.endsWith(".json") -> visionManager.decodeFromString(data) else -> { window.alert("File extension is not recognized: $name") error("File extension is not recognized: $name") @@ -64,7 +66,7 @@ fun GDMLApp(solids: Solids, initialVision: Solid?, selected: Name? = null) { width(100.vw) } }) { - ThreeView(solids, vision, selected) { + ThreeView(context, vision, selected) { Tab("Load") { P { Text("Drag and drop .gdml or .json VisionForge files here") diff --git a/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GdmlJsDemoApp.kt b/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GdmlJsDemoApp.kt index 350c9de9..e60f1dec 100644 --- a/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GdmlJsDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/space/kscience/visionforge/gdml/demo/GdmlJsDemoApp.kt @@ -5,13 +5,11 @@ import org.jetbrains.compose.web.dom.Style import org.jetbrains.compose.web.renderComposable import org.w3c.dom.Document import space.kscience.dataforge.context.Context -import space.kscience.dataforge.context.request import space.kscience.gdml.GdmlShowCase import space.kscience.visionforge.Application import space.kscience.visionforge.Colors import space.kscience.visionforge.compose.TreeStyles import space.kscience.visionforge.gdml.toVision -import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.ambientLight import space.kscience.visionforge.solid.invoke import space.kscience.visionforge.solid.three.ThreePlugin @@ -20,10 +18,11 @@ import space.kscience.visionforge.startApplication private class GDMLDemoApp : Application { + val context = Context("gdml-demo") { + plugin(ThreePlugin) + } + override fun start(document: Document, state: Map) { - val context = Context("gdml-demo") { - plugin(ThreePlugin) - } val element = document.getElementById("application") ?: error("Element with id 'application' not found on page") @@ -52,7 +51,7 @@ private class GDMLDemoApp : Application { alignItems(AlignItems.Stretch) } } - GDMLApp(context.request(Solids), vision) + GDMLApp(context, vision) } } } diff --git a/demo/js-playground/build.gradle.kts b/demo/js-playground/build.gradle.kts index e1b39c62..86067e7a 100644 --- a/demo/js-playground/build.gradle.kts +++ b/demo/js-playground/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("space.kscience.gradle.mpp") + alias(spclibs.plugins.compose) } kscience { @@ -11,12 +12,20 @@ kotlin { js { browser { binaries.executable() + commonWebpackConfig{ + cssSupport{ + enabled = true + } + scssSupport{ + enabled = true + } + sourceMaps = true + } } } } kscience { - dependencies { implementation(projects.visionforge.visionforgeGdml) implementation(projects.visionforge.visionforgePlotly) diff --git a/demo/js-playground/src/jsMain/kotlin/JsPlaygroundApp.kt b/demo/js-playground/src/jsMain/kotlin/JsPlaygroundApp.kt index 3e53e866..8516736c 100644 --- a/demo/js-playground/src/jsMain/kotlin/JsPlaygroundApp.kt +++ b/demo/js-playground/src/jsMain/kotlin/JsPlaygroundApp.kt @@ -3,13 +3,13 @@ import org.jetbrains.compose.web.dom.Div import org.jetbrains.compose.web.renderComposable import org.w3c.dom.Document import space.kscience.dataforge.context.Context -import space.kscience.dataforge.context.request import space.kscience.plotly.models.Trace import space.kscience.plotly.scatter import space.kscience.visionforge.Application import space.kscience.visionforge.Colors -import space.kscience.visionforge.JsVisionClient import space.kscience.visionforge.compose.Tabs +import space.kscience.visionforge.compose.TreeStyles +import space.kscience.visionforge.markup.MarkupPlugin import space.kscience.visionforge.plotly.PlotlyPlugin import space.kscience.visionforge.solid.* import space.kscience.visionforge.solid.three.ThreePlugin @@ -26,19 +26,21 @@ fun Trace.appendXYLatest(x: Number, y: Number, history: Int = 400, xErr: Number? private class JsPlaygroundApp : Application { + val playgroundContext = Context { + plugin(ThreePlugin) + plugin(PlotlyPlugin) + plugin(MarkupPlugin) + } + override fun start(document: Document, state: Map) { - val playgroundContext = Context { - plugin(ThreePlugin) - plugin(PlotlyPlugin) - } - - val solids = playgroundContext.request(Solids) - val client = playgroundContext.request(JsVisionClient) +// val solids = playgroundContext.request(Solids) +// val client = playgroundContext.request(JsVisionClient) val element = document.getElementById("playground") ?: error("Element with id 'playground' not found on page") renderComposable(element) { + Style(TreeStyles) Div({ style { padding(0.pt) @@ -49,7 +51,7 @@ private class JsPlaygroundApp : Application { }) { Tabs("gravity") { Tab("gravity") { - GravityDemo(solids, client) + GravityDemo(playgroundContext) } // Tab("D0") { @@ -66,7 +68,7 @@ private class JsPlaygroundApp : Application { height(100.vh - 50.pt) } }) { - ThreeView(solids, SolidGroup { + ThreeView(playgroundContext, SolidGroup { ambientLight { color(Colors.white) } @@ -85,7 +87,7 @@ private class JsPlaygroundApp : Application { } } Tab("plotly") { - Plot(client) { + Plot(playgroundContext) { scatter { x(1, 2, 3) y(5, 8, 7) diff --git a/demo/js-playground/src/jsMain/kotlin/gravityDemo.kt b/demo/js-playground/src/jsMain/kotlin/gravityDemo.kt index 8e041513..5cff2864 100644 --- a/demo/js-playground/src/jsMain/kotlin/gravityDemo.kt +++ b/demo/js-playground/src/jsMain/kotlin/gravityDemo.kt @@ -1,19 +1,20 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember +import app.softwork.bootstrapcompose.Column +import app.softwork.bootstrapcompose.Row import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import org.jetbrains.compose.web.css.* import org.jetbrains.compose.web.dom.AttrBuilderContext import org.jetbrains.compose.web.dom.Div import org.w3c.dom.HTMLDivElement +import space.kscience.dataforge.context.Context import space.kscience.dataforge.meta.Meta import space.kscience.plotly.Plot import space.kscience.plotly.layout import space.kscience.plotly.models.Trace import space.kscience.visionforge.Colors -import space.kscience.visionforge.VisionClient -import space.kscience.visionforge.compose.FlexRow import space.kscience.visionforge.compose.Vision import space.kscience.visionforge.compose.zIndex import space.kscience.visionforge.markup.VisionOfMarkup @@ -24,12 +25,12 @@ import kotlin.math.sqrt @Composable fun Plot( - client: VisionClient, + context: Context, meta: Meta = Meta.EMPTY, attrs: AttrBuilderContext? = null, block: Plot.() -> Unit, ) = Vision( - client = client, + context = context, attrs = attrs, meta = meta, vision = Plot().apply(block).asVision() @@ -37,12 +38,12 @@ fun Plot( @Composable fun Markup( - client: VisionClient, + context: Context, markup: VisionOfMarkup, meta: Meta = Meta.EMPTY, attrs: AttrBuilderContext? = null, ) = Vision( - client = client, + context = context, attrs = attrs, meta = meta, vision = markup @@ -52,7 +53,7 @@ fun Markup( private val h = 100.0 @Composable -fun GravityDemo(solids: Solids, client: VisionClient) { +fun GravityDemo(context: Context) { val velocityTrace = remember { Trace { name = "velocity" @@ -128,32 +129,36 @@ fun GravityDemo(solids: Solids, client: VisionClient) { height(50.vh) } }) { - ThreeView(solids, solid) + ThreeView(context, solid) } - FlexRow({ + Row(attrs = { style { alignContent(AlignContent.Stretch) alignItems(AlignItems.Stretch) height(50.vh - 50.pt) } }) { - Plot(client) { - traces(velocityTrace, energyTrace) - layout { - xaxis.title = "time" + Column { + Plot(context) { + traces(velocityTrace, energyTrace) + layout { + xaxis.title = "time" + } } } - Markup(client, markup, attrs = { - style { - width(100.percent) - height(100.percent) - border(2.pt, LineStyle.Solid, Color.blue) - paddingLeft(8.pt) - backgroundColor(Color.white) - flex(1) - zIndex(10000) - } - }) + Column { + Markup(context, markup, attrs = { + style { + width(100.percent) + height(100.percent) + border(2.pt, LineStyle.Solid, Color.blue) + paddingLeft(8.pt) + backgroundColor(Color.white) + flex(1) + zIndex(10000) + } + }) + } } } } \ No newline at end of file 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 09f3a46d..63924c42 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 @@ -17,10 +17,10 @@ import org.jetbrains.compose.web.dom.P import org.jetbrains.compose.web.dom.Span import org.jetbrains.compose.web.dom.Text import org.w3c.fetch.RequestInit +import space.kscience.dataforge.context.Context import space.kscience.dataforge.meta.invoke import space.kscience.dataforge.names.Name import space.kscience.visionforge.Colors -import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.ambientLight import space.kscience.visionforge.solid.edges import space.kscience.visionforge.solid.invoke @@ -29,7 +29,7 @@ import space.kscience.visionforge.solid.three.compose.ThreeView import kotlin.math.PI @Composable -fun MMApp(solids: Solids, model: Model, selected: Name? = null) { +fun MMApp(context: Context, model: Model, selected: Name? = null) { val mmOptions = remember { Canvas3DOptions { @@ -60,7 +60,7 @@ fun MMApp(solids: Solids, model: Model, selected: Name? = null) { } ) { ThreeView( - solids = solids, + context, solid = root, initialSelected = selected, options = mmOptions, @@ -68,7 +68,7 @@ fun MMApp(solids: Solids, model: Model, selected: Name? = null) { Tab("Events") { ButtonGroup({ Layout.width = Width.Full }) { Button("Next") { - solids.context.launch { + context.launch { val event = window.fetch( "http://localhost:8080/event", RequestInit("GET") diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index fa08b0ff..d26bc052 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -8,7 +8,6 @@ import space.kscience.dataforge.context.request import space.kscience.visionforge.Application import space.kscience.visionforge.VisionManager import space.kscience.visionforge.compose.VisionForgeStyles -import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.three.ThreePlugin import space.kscience.visionforge.startApplication @@ -26,7 +25,7 @@ private class MMDemoApp : Application { renderComposable("app") { Style(VisionForgeStyles) - MMApp(context.request(Solids), model) + MMApp(context, model) } } } diff --git a/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt b/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt index 5b272b72..9227f014 100644 --- a/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt +++ b/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt @@ -2,7 +2,6 @@ package space.kscience.visionforge.examples import kotlinx.html.h2 import space.kscience.dataforge.meta.ValueType -import space.kscience.dataforge.meta.invoke import space.kscience.plotly.layout import space.kscience.plotly.models.ScatterMode import space.kscience.plotly.models.TextPosition @@ -11,9 +10,9 @@ import space.kscience.tables.ColumnHeader import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.markup.markdown import space.kscience.visionforge.plotly.plotly +import space.kscience.visionforge.solid.axes import space.kscience.visionforge.solid.box import space.kscience.visionforge.solid.solid -import space.kscience.visionforge.solid.specifications.Canvas3DOptions import space.kscience.visionforge.solid.z import space.kscience.visionforge.tables.columnTable import kotlin.io.path.Path @@ -34,14 +33,8 @@ fun main() = makeVisionFile( h2 { +"3D visualization with Three-js" } vision("3D") { - solid( - Canvas3DOptions { - axes { - size = 200.0 - visible = true - } - } - ) { + solid { + axes(200) box(100, 100, 100, name = "aBox") { z = 50.0 } diff --git a/demo/playground/src/jvmMain/kotlin/markdownVision.kt b/demo/playground/src/jvmMain/kotlin/markdownVision.kt new file mode 100644 index 00000000..63edbcb6 --- /dev/null +++ b/demo/playground/src/jvmMain/kotlin/markdownVision.kt @@ -0,0 +1,19 @@ +package space.kscience.visionforge.examples + +import space.kscience.visionforge.html.ResourceLocation +import space.kscience.visionforge.markup.markdown + +fun main() = makeVisionFile(resourceLocation = ResourceLocation.SYSTEM) { + vision { + markdown{ + content = """ + # h1 Heading 8-) + ## h2 Heading + ### h3 Heading + #### h4 Heading + ##### h5 Heading + ###### h6 Heading + """.trimIndent() + } + } +} \ No newline at end of file diff --git a/demo/solid-showcase/src/commonMain/kotlin/space/kscience/visionforge/solid/demo/demo.kt b/demo/solid-showcase/src/commonMain/kotlin/space/kscience/visionforge/solid/demo/demo.kt index 698cc846..52a524e1 100644 --- a/demo/solid-showcase/src/commonMain/kotlin/space/kscience/visionforge/solid/demo/demo.kt +++ b/demo/solid-showcase/src/commonMain/kotlin/space/kscience/visionforge/solid/demo/demo.kt @@ -38,10 +38,6 @@ val canvasOptions = Canvas3DOptions { size { minSize = 400 } - axes { - size = 500.0 - visible = true - } camera { distance = 600.0 latitude = PI / 6 @@ -52,6 +48,8 @@ val canvasOptions = Canvas3DOptions { fun VisionLayout.showcase() { demo("shapes", "Basic shapes") { ambientLight() + axes(size = 500.0) + box(100.0, 100.0, 100.0) { z = -110.0 color("teal") diff --git a/gradle.properties b/gradle.properties index 4e33feb5..23061828 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ org.gradle.jvmargs=-Xmx4G org.jetbrains.compose.experimental.jscanvas.enabled=true -toolsVersion=0.15.2-kotlin-1.9.21 +toolsVersion=0.15.2-kotlin-1.9.22 #kotlin.experimental.tryK2=true #kscience.wasm.disabled=true diff --git a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/MetaViewer.kt b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/MetaViewer.kt index f83d4da6..5c93cd15 100644 --- a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/MetaViewer.kt +++ b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/MetaViewer.kt @@ -63,7 +63,7 @@ private fun MetaViewerItem(root: Meta, name: Name, rootDescriptor: MetaDescripto classes(TreeStyles.tree) }) { val keys = buildSet { - descriptorItem?.children?.keys?.forEach { + descriptorItem?.nodes?.keys?.forEach { add(NameToken(it)) } actualMeta!!.items.keys.let { addAll(it) } diff --git a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/PropertyEditor.kt b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/PropertyEditor.kt index 89bae724..452750df 100644 --- a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/PropertyEditor.kt +++ b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/PropertyEditor.kt @@ -55,7 +55,7 @@ public fun PropertyEditor( val keys by derivedStateOf { buildSet { - descriptor?.children?.filterNot { + descriptor?.nodes?.filterNot { it.key.startsWith("@") || it.value.hidden }?.forEach { add(NameToken(it.key)) diff --git a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/composeVision.kt b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/composeVision.kt index e9b22261..ffb3da5f 100644 --- a/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/composeVision.kt +++ b/visionforge-compose-html/src/jsMain/kotlin/space/kscience/visionforge/compose/composeVision.kt @@ -8,13 +8,13 @@ import kotlinx.dom.clear import org.jetbrains.compose.web.dom.AttrBuilderContext import org.jetbrains.compose.web.dom.Div import org.w3c.dom.HTMLDivElement +import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.gather +import space.kscience.dataforge.context.request import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName -import space.kscience.visionforge.ElementVisionRenderer -import space.kscience.visionforge.Vision -import space.kscience.visionforge.VisionClient +import space.kscience.visionforge.* /** @@ -22,13 +22,20 @@ import space.kscience.visionforge.VisionClient */ @Composable public fun Vision( - client: VisionClient, + context: Context, vision: Vision, name: Name = "@vision[${vision.hashCode().toString(16)}]".asName(), meta: Meta = Meta.EMPTY, attrs: AttrBuilderContext? = null, ): Unit = Div(attrs) { + val client: VisionClient = context.request(JsVisionClient) + + // set vision root if necessary + if (vision.manager == null) { + vision.setAsRoot(client.visionManager) + } + val renderer by derivedStateOf { client.context.gather(ElementVisionRenderer.TYPE).values.mapNotNull { val rating = it.rateVision(vision) diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleReference.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleReference.kt index 62d898b8..b26e3a36 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleReference.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/StyleReference.kt @@ -3,7 +3,7 @@ package space.kscience.visionforge import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.MutableMeta import space.kscience.dataforge.meta.Scheme -import space.kscience.dataforge.meta.Specification +import space.kscience.dataforge.meta.SchemeSpec import kotlin.properties.ReadOnlyProperty /** @@ -36,7 +36,7 @@ public fun Vision.style( @VisionBuilder public fun Vision.style( - spec: Specification, + spec: SchemeSpec, styleKey: String? = null, builder: T.() -> Unit, ): ReadOnlyProperty = ReadOnlyProperty { _, property -> 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 d607f706..74bbb504 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt @@ -113,7 +113,7 @@ private class VisionPropertiesItem( override val items: Map get() { val metaKeys = properties.own?.get(nodeName)?.items?.keys ?: emptySet() - val descriptorKeys = descriptor?.children?.map { NameToken(it.key) } ?: emptySet() + val descriptorKeys = descriptor?.nodes?.map { NameToken(it.key) } ?: emptySet() val defaultKeys = default?.get(nodeName)?.items?.keys ?: emptySet() val inheritFlag = descriptor?.inherited ?: inherit val stylesFlag = descriptor?.usesStyles ?: useStyles diff --git a/visionforge-jupyter/src/jvmMain/kotlin/VisionForge.kt b/visionforge-jupyter/src/jvmMain/kotlin/VisionForge.kt index 8cb2dcd5..5ac2c37b 100644 --- a/visionforge-jupyter/src/jvmMain/kotlin/VisionForge.kt +++ b/visionforge-jupyter/src/jvmMain/kotlin/VisionForge.kt @@ -55,7 +55,7 @@ public class VisionForge( override val context: Context get() = visionManager.context - public val configuration: ObservableMutableMeta = meta.toMutableMeta() + public val configuration: ObservableMutableMeta = meta.toMutableMeta().asObservable() private var counter = 0 diff --git a/visionforge-markdown/src/jsMain/kotlin/space/kscience/visionforge/markup/MarkupPlugin.kt b/visionforge-markdown/src/jsMain/kotlin/space/kscience/visionforge/markup/MarkupPlugin.kt index 0d5e0431..4f3122c3 100644 --- a/visionforge-markdown/src/jsMain/kotlin/space/kscience/visionforge/markup/MarkupPlugin.kt +++ b/visionforge-markdown/src/jsMain/kotlin/space/kscience/visionforge/markup/MarkupPlugin.kt @@ -34,7 +34,7 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer { COMMONMARK_FORMAT -> CommonMarkFlavourDescriptor() GFM_FORMAT -> GFMFlavourDescriptor() //TODO add new formats via plugins - else-> error("Format ${vision.format} not recognized") + else -> error("Format ${vision.format} not recognized") } vision.useProperty(VisionOfMarkup::content) { div.clear() @@ -53,7 +53,7 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer { public actual companion object : PluginFactory { override val tag: PluginTag = PluginTag("vision.markup.js", PluginTag.DATAFORGE_GROUP) - override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin() + override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin() } } \ No newline at end of file diff --git a/visionforge-plotly/build.gradle.kts b/visionforge-plotly/build.gradle.kts index c4df8593..81e5f60a 100644 --- a/visionforge-plotly/build.gradle.kts +++ b/visionforge-plotly/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("space.kscience.gradle.mpp") } -val plotlyVersion = "0.6.1" +val plotlyVersion = "0.7.0" kscience { jvm() 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 index 7634e73d..2b2d4328 100644 --- a/visionforge-plotly/src/commonTest/kotlin/space/kscience/visionforge/plotly/VisionOfPlotlyTest.kt +++ b/visionforge-plotly/src/commonTest/kotlin/space/kscience/visionforge/plotly/VisionOfPlotlyTest.kt @@ -1,22 +1,110 @@ package space.kscience.visionforge.plotly +import space.kscience.dataforge.context.Context +import space.kscience.dataforge.meta.Value import space.kscience.plotly.Plotly -import space.kscience.plotly.scatter +import space.kscience.plotly.layout +import space.kscience.plotly.models.* +import space.kscience.visionforge.visionManager import kotlin.test.Test -import kotlin.test.assertTrue +import kotlin.test.assertEquals class VisionOfPlotlyTest { @Test - fun conversion(){ + fun conversion() { + val trace1 = Violin { + text("sample length: 32") + marker { + line { + width = 2 + color("#bebada") + } + symbol = Symbol.valueOf("line-ns") + } + orientation = Orientation.h + hoveron = ViolinHoveron.`points+kde` + meanline { + visible = true + } + legendgroup = "F" + scalegroup = "F" + points = ViolinPoints.all + pointpos = 1.2 + jitter = 0 + box { + visible = true + } + scalemode = ViolinScaleMode.count + showlegend = false + side = ViolinSide.positive + y0 = Value.of(0) + line { + color("#bebada") + } + name = "F" + + x(10.07, 34.83, 10.65, 12.43, 24.08, 13.42, 12.48, 29.8, 14.52, 11.38, + 20.27, 11.17, 12.26, 18.26, 8.51, 10.33, 14.15, 13.16, 17.47, 27.05, 16.43, + 8.35, 18.64, 11.87, 19.81, 43.11, 13.0, 12.74, 13.0, 16.4, 16.47, 18.78) + } + + val trace2 = Violin { + text("sample length: 30") + marker { + line { + width = 2 + color("#8dd3c7") + } + symbol = Symbol.valueOf("line-ns") + } + orientation = Orientation.h + hoveron = ViolinHoveron.`points+kde` + meanline { + visible = true + } + legendgroup = "M" + scalegroup = "M" + points = ViolinPoints.all + pointpos = -1.2 + jitter = 0 + box { + visible = true + } + scalemode = ViolinScaleMode.count + showlegend = false + side = ViolinSide.negative + y0 = Value.of(0) + + line { + color("#8dd3c7") + } + name = "M" + + x(27.2, 22.76, 17.29, 19.44, 16.66, 32.68, 15.98, 13.03, 18.28, 24.71, + 21.16, 11.69, 14.26, 15.95, 8.52, 22.82, 19.08, 16.0, 34.3, 41.19, 9.78, + 7.51, 28.44, 15.48, 16.58, 7.56, 10.34, 13.51, 18.71, 20.53) + } + val plot = Plotly.plot { - scatter { - x(1,2,3) - y(1,2,3) + traces(trace1, trace2) + layout { + width = 800 + height = 800 + title = "Advanced Violin Plot" } } val vision = VisionOfPlotly(plot) -// println(vision.plot.toJsonString()) -// println(vision.plot.data.toJsonString()) - assertTrue { vision.plot.data.first().x.doubles.size == 3} + val context = Context { + plugin(PlotlyPlugin) + } + val serialized = context.visionManager.encodeToString(vision) + + val deserialized: VisionOfPlotly = context.visionManager.decodeFromString(serialized) as VisionOfPlotly + + println(deserialized.plot.meta) + + assertEquals(62, deserialized.plot.data.sumOf { it.x.doubles.size}) + + assertEquals("Advanced Violin Plot", deserialized.plot.layout.title) } } \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/AxesScheme.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/AxesScheme.kt deleted file mode 100644 index 0ed9126e..00000000 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/AxesScheme.kt +++ /dev/null @@ -1,35 +0,0 @@ -package space.kscience.visionforge.solid.specifications - -import space.kscience.dataforge.meta.Scheme -import space.kscience.dataforge.meta.SchemeSpec -import space.kscience.dataforge.meta.boolean -import space.kscience.dataforge.meta.descriptors.MetaDescriptor -import space.kscience.dataforge.meta.descriptors.value -import space.kscience.dataforge.meta.double - -@Deprecated("Use separate axes object instead") -public class AxesScheme : Scheme() { - public var visible: Boolean by boolean(false) - public var size: Double by double(AXIS_SIZE) - public var width: Double by double(AXIS_WIDTH) - - @Suppress("DEPRECATION") - public companion object : SchemeSpec(::AxesScheme) { - public const val AXIS_SIZE: Double = 1000.0 - public const val AXIS_WIDTH: Double = 3.0 - - override val descriptor: MetaDescriptor by lazy { - MetaDescriptor { - value(AxesScheme::visible){ - default(false) - } - value(AxesScheme::size){ - default(AXIS_SIZE) - } - value(AxesScheme::width){ - default(AXIS_WIDTH) - } - } - } - } -} \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt index 8a081d63..19e93b0f 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt @@ -1,3 +1,5 @@ +@file:OptIn(DFExperimental::class) + package space.kscience.visionforge.solid.specifications import space.kscience.dataforge.meta.* @@ -5,6 +7,7 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.dataforge.meta.descriptors.scheme import space.kscience.dataforge.meta.descriptors.value import space.kscience.dataforge.meta.set +import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.names.Name import space.kscience.visionforge.hide import space.kscience.visionforge.widgetType @@ -61,16 +64,14 @@ public class CanvasSize : Scheme() { public class Canvas3DOptions : Scheme() { public var canvasName: String by string("vision") - @Suppress("DEPRECATION") - public var axes: AxesScheme by spec(AxesScheme) - public var camera: CameraScheme by spec(CameraScheme) - public var controls: Canvas3DUIScheme by spec(Canvas3DUIScheme) + public var camera: CameraScheme by scheme(CameraScheme) + public var controls: Canvas3DUIScheme by scheme(Canvas3DUIScheme) - public var size: CanvasSize by spec(CanvasSize) + public var size: CanvasSize by scheme(CanvasSize) public var layers: List by numberList(0) - public var clipping: PointScheme by spec(Clipping) + public var clipping: PointScheme by scheme(Clipping) public var onSelect: ((Name?) -> Unit)? = null @@ -78,9 +79,6 @@ public class Canvas3DOptions : Scheme() { public companion object : SchemeSpec(::Canvas3DOptions) { override val descriptor: MetaDescriptor by lazy { MetaDescriptor { - @Suppress("DEPRECATION") - scheme(Canvas3DOptions::axes, AxesScheme) - value(Canvas3DOptions::layers) { multiple = true default(listOf(0)) diff --git a/visionforge-solid/src/commonTest/kotlin/space/kscience/visionforge/solid/DescriptorTest.kt b/visionforge-solid/src/commonTest/kotlin/space/kscience/visionforge/solid/DescriptorTest.kt deleted file mode 100644 index 87527802..00000000 --- a/visionforge-solid/src/commonTest/kotlin/space/kscience/visionforge/solid/DescriptorTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package space.kscience.visionforge.solid - -import space.kscience.dataforge.meta.ValueType -import space.kscience.dataforge.meta.descriptors.get -import space.kscience.visionforge.solid.specifications.Canvas3DOptions -import kotlin.test.Test -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -class DescriptorTest { - @Test - fun canvasDescriptor() { - val descriptor = Canvas3DOptions.descriptor - //println(descriptor.config) - val axesSize = descriptor["axes.size"] - assertNotNull(axesSize) - assertTrue { - ValueType.NUMBER in axesSize.valueTypes!! - } - } -} \ No newline at end of file diff --git a/visionforge-tables/build.gradle.kts b/visionforge-tables/build.gradle.kts index 23912afe..ccc0341a 100644 --- a/visionforge-tables/build.gradle.kts +++ b/visionforge-tables/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("space.kscience.gradle.mpp") } -val tablesVersion = "0.3.0" +val tablesVersion = "0.4.0" kscience { jvm() diff --git a/visionforge-tables/src/commonMain/kotlin/space/kscience/visionforge/tables/VisionOfTable.kt b/visionforge-tables/src/commonMain/kotlin/space/kscience/visionforge/tables/VisionOfTable.kt index 3e4f9da8..a691bd85 100644 --- a/visionforge-tables/src/commonMain/kotlin/space/kscience/visionforge/tables/VisionOfTable.kt +++ b/visionforge-tables/src/commonMain/kotlin/space/kscience/visionforge/tables/VisionOfTable.kt @@ -70,7 +70,7 @@ public fun Table.toVision( } else { Meta { headers.forEach { - it.name put converter(row[it.name]) + it.name put converter(row.getOrNull(it.name)) } } } diff --git a/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt b/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt index 18170686..f9ef25c3 100644 --- a/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt +++ b/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt @@ -1,6 +1,6 @@ package space.kscience.visionforge.tables -import js.core.jso +import js.objects.jso import org.w3c.dom.Element import org.w3c.dom.HTMLElement import space.kscience.dataforge.context.AbstractPlugin diff --git a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt index dac32e08..786a0cc1 100644 --- a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt +++ b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt @@ -20,7 +20,6 @@ import three.core.Raycaster import three.external.controls.OrbitControls import three.external.controls.TrackballControls import three.geometries.EdgesGeometry -import three.helpers.AxesHelper import three.materials.Material import three.math.* import three.meshline.MeshLine @@ -50,14 +49,7 @@ public class ThreeCanvas( private val raycaster = Raycaster() private val mousePosition: Vector2 = Vector2() - private val scene: Scene = Scene().apply { - options.useProperty(Canvas3DOptions::axes, this) { - getObjectByName(AXES_NAME)?.let { remove(it) } - val axesObject = AxesHelper(axes.size.toInt()).apply { visible = axes.visible } - axesObject.name = AXES_NAME - add(axesObject) - } - } + private val scene: Scene = Scene() private fun buildCamera(spec: CameraScheme) = PerspectiveCamera( diff --git a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt index 45068a3a..3ca87d48 100644 --- a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt +++ b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt @@ -1,7 +1,7 @@ package space.kscience.visionforge.solid.three -import js.core.jso +import js.objects.jso import space.kscience.dataforge.context.logger import space.kscience.dataforge.context.warn import space.kscience.visionforge.onPropertyChange @@ -27,7 +27,7 @@ public object ThreeLabelFactory : ThreeFactory { return Mesh(textGeo, ThreeMaterials.DEFAULT).apply { setMaterial(vision) updatePosition(vision) - if(observe) { + if (observe) { vision.onPropertyChange(three.context) { //TODO three.logger.warn { "Label parameter change not implemented" } diff --git a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreePlugin.kt b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreePlugin.kt index b00f3c31..7f7cc29b 100644 --- a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreePlugin.kt +++ b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/ThreePlugin.kt @@ -189,7 +189,7 @@ public class ThreePlugin : AbstractPlugin(), ComposeVisionRenderer { @Composable override fun DOMScope.render(client: VisionClient, name: Name, vision: Vision, meta: Meta) { require(vision is Solid) { "Expected Solid but found ${vision::class}" } - ThreeView(solids, vision, null, Canvas3DOptions.read(meta)) + ThreeView(context, vision, null, Canvas3DOptions.read(meta)) } public companion object : PluginFactory { diff --git a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/compose/ThreeView.kt b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/compose/ThreeView.kt index 21a61ebd..2ea1d930 100644 --- a/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/compose/ThreeView.kt +++ b/visionforge-threejs/src/jsMain/kotlin/space/kscience/visionforge/solid/three/compose/ThreeView.kt @@ -17,7 +17,6 @@ import space.kscience.visionforge.compose.* import space.kscience.visionforge.root import space.kscience.visionforge.solid.Solid import space.kscience.visionforge.solid.SolidGroup -import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.specifications.Canvas3DOptions import space.kscience.visionforge.solid.three.ThreeCanvas import space.kscience.visionforge.solid.three.ThreePlugin @@ -63,7 +62,7 @@ private fun SimpleThreeView( @Composable public fun ThreeView( - solids: Solids, + context: Context, solid: Solid?, initialSelected: Name? = null, options: Canvas3DOptions? = null, @@ -114,7 +113,7 @@ public fun ThreeView( } } } else { - SimpleThreeView(solids.context, optionsSnapshot, solid, selected) + SimpleThreeView(context, optionsSnapshot, solid, selected) } key(selected) { @@ -136,7 +135,7 @@ public fun ThreeView( NameCrumbs(selected) { selected = it } Hr() PropertyEditor( - scope = solids.context, + scope = context, rootMeta = vision.properties.root(), getPropertyState = { name -> if (vision.properties.own?.get(name) != null) { @@ -189,6 +188,6 @@ public fun ThreeView( } } } else { - SimpleThreeView(solids.context, optionsSnapshot, solid, selected) + SimpleThreeView(context, optionsSnapshot, solid, selected) } } \ No newline at end of file