From 82c003ca229b5c98dfbf946c79bf6b4983777716 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 1 Mar 2020 17:07:31 +0300 Subject: [PATCH] Slight design improvement --- dataforge-vis-common/build.gradle.kts | 2 +- .../hep/dataforge/vis/js/editor/bootstrap.kt | 50 ++++++++++++++- .../vis/spatial/three/ThreeLabelFactory.kt | 2 +- .../vis/spatial/three/ThreePlugin.kt | 4 +- .../vis/spatial/three/outputConfig.kt | 63 ++++++++++++++++++- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 8 +-- demo/gdml/src/jsMain/web/index.html | 41 ++++++------ 7 files changed, 135 insertions(+), 35 deletions(-) diff --git a/dataforge-vis-common/build.gradle.kts b/dataforge-vis-common/build.gradle.kts index 548c1be5..6459c337 100644 --- a/dataforge-vis-common/build.gradle.kts +++ b/dataforge-vis-common/build.gradle.kts @@ -37,7 +37,7 @@ kotlin { jsMain{ dependencies { api("hep.dataforge:dataforge-output-html:$dataforgeVersion") - api(npm("bootstrap","4.4.1")) + //api(npm("bootstrap","4.4.1")) implementation(npm("jsoneditor")) implementation(npm("file-saver")) } diff --git a/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/bootstrap.kt b/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/bootstrap.kt index 2f1e4595..171aa86d 100644 --- a/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/bootstrap.kt +++ b/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/bootstrap.kt @@ -1,8 +1,7 @@ package hep.dataforge.vis.js.editor -import kotlinx.html.TagConsumer +import kotlinx.html.* import kotlinx.html.js.div -import kotlinx.html.js.h3 import org.w3c.dom.HTMLElement inline fun TagConsumer.card(title: String, crossinline block: TagConsumer.() -> Unit) { @@ -12,4 +11,51 @@ inline fun TagConsumer.card(title: String, crossinline block: TagCo block() } } +} + +fun TagConsumer.accordion(id: String, elements: Map Unit>) { + div("container-fluid") { + div("accordion") { + this.id = id + elements.entries.forEachIndexed { index, (title, builder) -> + val headerID = "${id}-${index}-heading" + val collapseID = "${id}-${index}-collapse" + div("card") { + div("card-header") { + this.id = headerID + h5("mb-0") { + button(classes = "btn btn-link collapsed", type = ButtonType.button) { + attributes["data-toggle"] = "collapse" + attributes["data-target"] = "#$collapseID" + attributes["aria-expanded"] = "false" + attributes["aria-controls"] = collapseID + +title + } + } + } + div("collapse") { + this.id = collapseID + attributes["aria-labelledby"] = headerID + attributes["data-parent"] = "#$id" + div("card-body", block = builder) + } + } + } + } + } +} + +class AccordionBuilder { + private val map = HashMap Unit>() + fun entry(title: String, block: DIV.() -> Unit) { + map[title] = block + } + + fun build(consumer: TagConsumer, id: String) { + consumer.accordion(id, map) + } +} + +fun TagConsumer.accordion(id: String, block: AccordionBuilder.() -> Unit) { + AccordionBuilder().apply(block).build(this, id) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLabelFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLabelFactory.kt index c3e1024a..54e0ae03 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLabelFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLabelFactory.kt @@ -25,7 +25,7 @@ object ThreeLabelFactory : ThreeFactory { } ) return Mesh(textGeo, getMaterial(obj)).apply { updatePosition(obj) - obj.onPropertyChange(this@ThreeLabelFactory){name: Name, before: MetaItem<*>?, after: MetaItem<*>? -> + obj.onPropertyChange(this@ThreeLabelFactory){ _: Name, _: MetaItem<*>?, _: MetaItem<*>? -> //TODO } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt index 11117b27..e5c99efe 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt @@ -74,8 +74,8 @@ class ThreePlugin : AbstractPlugin() { return@onChildrenChange } - val parentName = name.cutLast() - val childName = name.last()!! +// val parentName = name.cutLast() +// val childName = name.last()!! //removing old object findChild(name)?.let { oldChild -> diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/outputConfig.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/outputConfig.kt index f27a6754..70afb07d 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/outputConfig.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/outputConfig.kt @@ -1,7 +1,7 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.js.requireJS -import hep.dataforge.vis.js.editor.card +import hep.dataforge.vis.js.editor.accordion import hep.dataforge.vis.spatial.Visual3D import hep.dataforge.vis.spatial.VisualGroup3D import kotlinx.html.InputType @@ -28,7 +28,64 @@ private fun saveData(event: Event, fileName: String, mimeType: String = "text/pl fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer.() -> Unit = {}) { clear() append { - card("Settings") { + accordion("controls") { + entry("Settings") { + div("row") { + div("col-2") { + label("checkbox-inline") { + input(type = InputType.checkBox).apply { + checked = canvas.axes.visible + onChangeFunction = { + canvas.axes.visible = checked + } + } + +"Axes" + } + } + div("col-1") { + button { + +"Export" + onClickFunction = { + val json = (canvas.content as? VisualGroup3D)?.let { group -> + Visual3D.json.stringify( + VisualGroup3D.serializer(), + group + ) + } + if (json != null) { + saveData(it, "object.json", "text/json") { + json + } + } + } + } + } + } + } + entry("Layers") { + div("row") { + (0..11).forEach { layer -> + div("col-1") { + label { +layer.toString() } + input(type = InputType.checkBox).apply { + if (layer == 0) { + checked = true + } + onChangeFunction = { + if (checked) { + canvas.camera.layers.enable(layer) + } else { + canvas.camera.layers.disable(layer) + } + } + } + } + } + } + } + } + +/* card("Settings") { div("row") { div("col-2") { label("checkbox-inline") { @@ -81,7 +138,7 @@ fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer - selectElement(name) - canvas.highlight(name) + treeElement.displayObjectTree(visual) { treeName -> + selectElement(treeName) + canvas.highlight(treeName) } canvas.render(visual) diff --git a/demo/gdml/src/jsMain/web/index.html b/demo/gdml/src/jsMain/web/index.html index 5b9bb025..6a8a8ebe 100644 --- a/demo/gdml/src/jsMain/web/index.html +++ b/demo/gdml/src/jsMain/web/index.html @@ -4,24 +4,26 @@ Three js demo for particle physics - - - + + + +
-
-
+

GDML demo

+
+ +
+
+ -
Load data @@ -29,23 +31,18 @@ (drag file here)
+
-
-
-
-

GDML demo

-
- -
-
-
-
-
+
+
+
+
+
-
- - + + + \ No newline at end of file