[WIP] new DF experiment

This commit is contained in:
Alexander Nozik 2021-07-21 16:31:17 +03:00
parent e50e266f94
commit 787c841a51
13 changed files with 163 additions and 18 deletions

View File

@ -8,7 +8,7 @@ plugins {
// kotlin("js") version(kotlinVersion) apply false
}
val dataforgeVersion by extra("0.4.3")
val dataforgeVersion by extra("0.5.0-dev-2")
val fxVersion by extra("11")
allprojects {
@ -20,7 +20,7 @@ allprojects {
}
group = "space.kscience"
version = "0.2.0-dev-22"
version = "0.2.0-dev-23"
}
subprojects {

View File

@ -33,6 +33,7 @@ include(
":visionforge-gdml",
":visionforge-server",
":visionforge-plotly",
":visionforge-markdown",
":demo:solid-showcase",
":demo:gdml",
":demo:muon-monitor",

View File

@ -30,13 +30,13 @@ internal data class PropertyListener(
@SerialName("vision")
public open class VisionBase(
override @Transient var parent: VisionGroup? = null,
protected var properties: Config? = null
protected var properties: MutableItemProvider? = null
) : Vision {
@Synchronized
protected fun getOrCreateProperties(): Config {
protected fun getOrCreateProperties(): MutableItemProvider {
if (properties == null) {
val newProperties = Config()
val newProperties = MetaBuilder()
properties = newProperties
}
return properties!!
@ -46,7 +46,7 @@ public open class VisionBase(
* A fast accessor method to get own property (no inheritance or styles
*/
override fun getOwnProperty(name: Name): MetaItem? = if (name == Name.EMPTY) {
properties?.asMetaItem()
properties?.rootItem
} else {
properties?.getItem(name)
}

View File

@ -21,7 +21,7 @@ public class VisionChangeBuilder : VisionContainerBuilder<Vision> {
private var reset: Boolean = false
private var vision: Vision? = null
private val propertyChange = Config()
private val propertyChange = MetaBuilder()
private val children: HashMap<Name, VisionChangeBuilder> = HashMap()
public fun isEmpty(): Boolean = propertyChange.isEmpty() && propertyChange.isEmpty() && children.isEmpty()

View File

@ -1,9 +1,6 @@
package space.kscience.visionforge
import space.kscience.dataforge.meta.Config
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.set
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
/**
@ -20,7 +17,7 @@ public interface VisionPropertyContainer<out V: Vision> {
public fun setProperty(name: Name, item: MetaItem?, notify: Boolean = true)
}
public open class SimpleVisionPropertyContainer<out V: Vision>(protected val config: Config): VisionPropertyContainer<V>{
public open class SimpleVisionPropertyContainer<out V: Vision>(protected val config: ObservableMeta): VisionPropertyContainer<V>{
override fun getProperty(
name: Name,
inherit: Boolean,

View File

@ -2,10 +2,11 @@ package space.kscience.visionforge
import space.kscience.dataforge.meta.Scheme
import space.kscience.dataforge.meta.SchemeSpec
import space.kscience.dataforge.meta.asObservable
import space.kscience.dataforge.meta.descriptors.NodeDescriptor
import space.kscience.dataforge.meta.descriptors.NodeDescriptorBuilder
import space.kscience.dataforge.meta.descriptors.ValueDescriptorBuilder
import space.kscience.dataforge.meta.toConfig
import space.kscience.dataforge.meta.toMutableMeta
import space.kscience.dataforge.values.ValueType
import kotlin.reflect.KProperty1
import kotlin.reflect.typeOf
@ -53,7 +54,7 @@ public inline fun <S : Scheme, reified T> NodeDescriptorBuilder.value(
}
public fun NodeDescriptor.copy(block: NodeDescriptorBuilder.() -> Unit = {}): NodeDescriptor {
return NodeDescriptorBuilder(toMeta().toConfig()).apply(block)
return NodeDescriptorBuilder(toMeta().toMutableMeta().asObservable()).apply(block)
}
public inline fun <S : Scheme, reified T : Scheme> NodeDescriptorBuilder.scheme(

View File

@ -0,0 +1,44 @@
plugins {
id("ru.mipt.npm.gradle.mpp")
}
val markdownVersion = "0.2.4"
kscience {
useSerialization()
}
kotlin {
js {
//binaries.library()
binaries.executable()
browser {
webpackTask {
outputFileName = "js/visionforge-markdown.js"
}
}
}
jvm {
val processResourcesTaskName =
compilations[org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.MAIN_COMPILATION_NAME]
.processResourcesTaskName
}
val jsBrowserDistribution by tasks.getting
tasks.getByName<ProcessResources>("jvmProcessResources") {
dependsOn(jsBrowserDistribution)
from(jsBrowserDistribution)
}
sourceSets {
commonMain {
dependencies {
api(project(":visionforge-core"))
api("org.jetbrains:markdown:$markdownVersion")
}
}
}
}

View File

@ -0,0 +1,40 @@
package space.kscience.visionforge.markup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.modules.subclass
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.toName
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionBase
import space.kscience.visionforge.setProperty
@Serializable
@SerialName("vision.markup")
public class VisionOfMarkup(
public val format: String = COMMONMARK_FORMAT
) : VisionBase() {
//TODO add templates
public var content: String?
get() = getOwnProperty(CONTENT_PROPERTY_KEY).string
set(value) {
setProperty(CONTENT_PROPERTY_KEY, value)
}
public companion object {
public val CONTENT_PROPERTY_KEY: Name = "content".toName()
public const val COMMONMARK_FORMAT: String = "markdown.commonmark"
public const val GFM_FORMAT: String = "markdown.gfm"
}
}
internal val markupSerializersModule = SerializersModule {
polymorphic(Vision::class) {
subclass(VisionOfMarkup.serializer())
}
}

View File

@ -0,0 +1,25 @@
package space.kscience.visionforge.markup
import kotlinx.html.TagConsumer
import kotlinx.html.div
import kotlinx.html.unsafe
import org.intellij.markdown.flavours.MarkdownFlavourDescriptor
import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.html.HtmlGenerator
import org.intellij.markdown.parser.MarkdownParser
/**
* Render markdown inside kotlinx-html tag
*/
public fun <T> TagConsumer<T>.markdown(
flavour: MarkdownFlavourDescriptor = CommonMarkFlavourDescriptor(),
block: () -> String
): T {
val src = block()
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(src)
return div("visionforge-markdown") {
unsafe {
+HtmlGenerator(src, parsedTree, flavour).generateHtml()
}
}
}

View File

@ -0,0 +1,38 @@
package space.kscience.visionforge.markup
import kotlinx.browser.document
import kotlinx.serialization.modules.SerializersModule
import org.w3c.dom.Element
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.PluginFactory
import space.kscience.dataforge.context.PluginTag
import space.kscience.dataforge.meta.Meta
import space.kscience.visionforge.ElementVisionRenderer
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionClient
import space.kscience.visionforge.VisionPlugin
import kotlin.reflect.KClass
public class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
public val visionClient: VisionClient by require(VisionClient)
override val tag: PluginTag get() = Companion.tag
override val visionSerializersModule: SerializersModule get() = markupSerializersModule
override fun rateVision(vision: Vision): Int = when (vision) {
is VisionOfMarkup -> ElementVisionRenderer.DEFAULT_RATING
else -> ElementVisionRenderer.ZERO_RATING
}
override fun render(element: Element, vision: Vision, meta: Meta) {
require(vision is VisionOfMarkup) { "The vision is not a markup vision" }
val div = document.createElement("div")
element.append(div)
TODO()
}
public companion object : PluginFactory<MarkupPlugin> {
override val tag: PluginTag = PluginTag("vision.markup", PluginTag.DATAFORGE_GROUP)
override val type: KClass<MarkupPlugin> = MarkupPlugin::class
override fun invoke(meta: Meta, context: Context): MarkupPlugin = MarkupPlugin()
}
}

View File

@ -2,7 +2,6 @@ package space.kscience.visionforge.plotly
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import space.kscience.dataforge.meta.Config
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.plotly.Plot
import space.kscience.plotly.Plotly

View File

@ -54,7 +54,7 @@ public class VisionServer internal constructor(
private val application: Application,
private val rootRoute: String,
) : Configurable, CoroutineScope by application {
override val config: Config = Config()
override val config: ObservableMeta = ObservableMeta()
public var updateInterval: Long by config.long(300, key = UPDATE_INTERVAL_KEY)
public var cacheFragments: Boolean by config.boolean(true)
public var dataEmbed: Boolean by config.boolean(true, "data.embed".toName())

View File

@ -2,7 +2,7 @@ package space.kscience.visionforge.solid
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import space.kscience.dataforge.meta.Config
import space.kscience.dataforge.meta.ObservableMeta
import space.kscience.visionforge.*
import kotlin.math.PI
import kotlin.math.cos
@ -95,7 +95,7 @@ public class Extruded(
public class ExtrudeBuilder(
public var shape: List<Point2D> = emptyList(),
public var layers: ArrayList<Layer> = ArrayList(),
config: Config = Config()
config: ObservableMeta = ObservableMeta()
) : SimpleVisionPropertyContainer<Extruded>(config) {
public fun shape(block: Shape2DBuilder.() -> Unit) {
this.shape = Shape2DBuilder().apply(block).build()