Fix property defaults
This commit is contained in:
10
demo/playground/webpack.config.d/02.bundle.js
vendored
10
demo/playground/webpack.config.d/02.bundle.js
vendored
@ -1,10 +0,0 @@
|
||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
reportFilename: "bundle-report.html"
|
||||
})
|
||||
]
|
||||
}
|
@ -130,16 +130,12 @@ public interface MutableVision : Vision {
|
||||
name: Name,
|
||||
inherited: Boolean = isInheritedProperty(name),
|
||||
useStyles: Boolean = isStyledProperty(name),
|
||||
): MutableMeta {
|
||||
): MutableMeta = properties.getOrCreate(name).withDefault { suffix->
|
||||
val propertyName = name + suffix
|
||||
if (useStyles) getStyleProperty(propertyName)?.let { return@withDefault it }
|
||||
if (inherited) parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }
|
||||
|
||||
val styleMeta = if (useStyles) getStyleProperty(name) else null
|
||||
val inheritMeta = if (inherited) parent?.readProperty(name, inherited, useStyles) else null
|
||||
val defaultMeta = descriptor?.defaultNode?.get(name)
|
||||
val listOfMeta = listOf(styleMeta, inheritMeta, defaultMeta)
|
||||
|
||||
return properties.getOrCreate(name).withDefault{
|
||||
listOfMeta.firstNotNullOfOrNull { it[name] }
|
||||
}
|
||||
descriptor?.defaultNode?.get(propertyName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +200,7 @@ public fun MutableVision.useStyle(styleName: String) {
|
||||
*/
|
||||
public fun Vision.getStyle(name: String): Meta? =
|
||||
readProperty(STYLESHEET_KEY + name, inherited = true, useStyles = false)
|
||||
//properties[STYLESHEET_KEY + name] ?: parent?.getStyle(name)
|
||||
//properties[STYLESHEET_KEY + name] ?: parent?.getStyle(name)
|
||||
|
||||
/**
|
||||
* Resolve a property from all styles
|
||||
|
@ -25,7 +25,7 @@ class TestCubes {
|
||||
val smallBoxPrototype = vision.getPrototype("solids.smallBox") as? Box
|
||||
assertNotNull(smallBoxPrototype)
|
||||
assertEquals(30.0, smallBoxPrototype.xSize.toDouble())
|
||||
val smallBoxVision = vision["composite-111.smallBox"]?.prototype as? Box
|
||||
val smallBoxVision = vision["composite-111.smallBox"]?.prototype?.prototype as? Box
|
||||
assertNotNull(smallBoxVision)
|
||||
assertEquals(30.0, smallBoxVision.xSize.toDouble())
|
||||
}
|
||||
|
@ -3,32 +3,33 @@ package space.kscience.visionforge.solid
|
||||
import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.Colors
|
||||
import space.kscience.visionforge.MutableVision
|
||||
import space.kscience.visionforge.Vision
|
||||
import space.kscience.visionforge.VisionBuilder
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
|
||||
@VisionBuilder
|
||||
public class ColorAccessor(
|
||||
private val provider: MutableMeta,
|
||||
private val colorKey: Name,
|
||||
) : MutableValueProvider {
|
||||
public var value: Value?
|
||||
get() = provider[colorKey]?.value
|
||||
get() = provider.value
|
||||
set(value) {
|
||||
provider.setValue(colorKey, value)
|
||||
provider.value = value
|
||||
}
|
||||
|
||||
override fun getValue(name: Name): Value? = provider.getValue(colorKey + name)
|
||||
override fun getValue(name: Name): Value? = provider.getValue(name)
|
||||
|
||||
override fun setValue(name: Name, value: Value?) {
|
||||
provider.setValue(colorKey + name, value)
|
||||
provider.setValue(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun MutableVision.colorProperty(
|
||||
propertyName: Name? = null,
|
||||
): ReadOnlyProperty<Vision, ColorAccessor> = ReadOnlyProperty { _, property ->
|
||||
ColorAccessor(writeProperties(inherited = true), propertyName ?: property.name.asName())
|
||||
ColorAccessor(mutableProperty(propertyName ?: property.name.asName(), inherited = true))
|
||||
}
|
||||
|
||||
public var ColorAccessor.string: String?
|
||||
|
@ -7,10 +7,13 @@ import space.kscience.dataforge.meta.descriptors.value
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.VisionBuilder
|
||||
import space.kscience.visionforge.hide
|
||||
import space.kscience.visionforge.inherited
|
||||
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY
|
||||
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_KEY
|
||||
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_OPACITY_KEY
|
||||
import space.kscience.visionforge.widgetType
|
||||
|
||||
/**
|
||||
* A scheme for vision material
|
||||
@ -23,14 +26,14 @@ public class SolidMaterial : Scheme() {
|
||||
/**
|
||||
* Primary web-color for the material
|
||||
*/
|
||||
public val color: ColorAccessor = ColorAccessor(meta, COLOR_KEY)
|
||||
public val color: ColorAccessor = ColorAccessor(meta.view(COLOR_KEY))
|
||||
|
||||
/**
|
||||
* Specular color for phong material
|
||||
*/
|
||||
public val specularColor: ColorAccessor = ColorAccessor(meta, SPECULAR_COLOR_KEY)
|
||||
public val specularColor: ColorAccessor = ColorAccessor(meta.view(SPECULAR_COLOR_KEY))
|
||||
|
||||
public val emissiveColor: ColorAccessor = ColorAccessor(meta, EMISSIVE_COLOR_KEY)
|
||||
public val emissiveColor: ColorAccessor = ColorAccessor(meta.view(EMISSIVE_COLOR_KEY))
|
||||
|
||||
/**
|
||||
* Opacity
|
||||
@ -110,7 +113,7 @@ public class SolidMaterial : Scheme() {
|
||||
}
|
||||
|
||||
public val Solid.color: ColorAccessor
|
||||
get() = ColorAccessor(writeProperties(inherited = true), MATERIAL_COLOR_KEY)
|
||||
get() = ColorAccessor(mutableProperty(MATERIAL_COLOR_KEY, inherited = true))
|
||||
|
||||
public var Solid.material: SolidMaterial?
|
||||
get() = readProperty(MATERIAL_KEY)?.let { SolidMaterial.read(it)}
|
||||
|
@ -118,28 +118,27 @@ public class SolidReference(
|
||||
): MutableMeta {
|
||||
val mutable = properties.getOrCreate(name)
|
||||
|
||||
val default = buildList {
|
||||
return mutable.withDefault { suffix ->
|
||||
val propertyName = name + suffix
|
||||
|
||||
//2. Resolve prototype own properties
|
||||
add(prototype.properties[name])
|
||||
prototype.properties[propertyName]?.let { return@withDefault it }
|
||||
|
||||
if (useStyles) {
|
||||
//3. own styles
|
||||
add(getStyleProperty(name))
|
||||
getStyleProperty(propertyName)?.let { return@withDefault it }
|
||||
//4. prototype styles
|
||||
add(prototype.getStyleProperty(name))
|
||||
prototype.getStyleProperty(propertyName)?.let { return@withDefault it }
|
||||
}
|
||||
|
||||
if (inherited) {
|
||||
//5. own inheritance
|
||||
add(parent?.readProperty(name, inherited, useStyles))
|
||||
parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }
|
||||
//6. prototype inheritance
|
||||
add(prototype.parent?.readProperty(name, inherited, useStyles))
|
||||
prototype.parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }
|
||||
}
|
||||
|
||||
add(descriptor.defaultNode[name])
|
||||
}
|
||||
return mutable.withDefault { name ->
|
||||
default.firstNotNullOfOrNull { it[name] }
|
||||
descriptor.defaultNode[name]
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,28 +179,27 @@ private class SolidReferenceChild(
|
||||
useStyles: Boolean
|
||||
): MutableMeta {
|
||||
val mutable = properties.getOrCreate(name)
|
||||
val default = buildList {
|
||||
return mutable.withDefault { suffix ->
|
||||
val propertyName = name + suffix
|
||||
|
||||
//2. Resolve prototype own properties
|
||||
add(prototype.properties[name])
|
||||
prototype.properties[propertyName]?.let { return@withDefault it }
|
||||
|
||||
if (useStyles) {
|
||||
//3. own styles
|
||||
add(getStyleProperty(name))
|
||||
getStyleProperty(propertyName)?.let { return@withDefault it }
|
||||
//4. prototype styles
|
||||
add(prototype.getStyleProperty(name))
|
||||
prototype.getStyleProperty(propertyName)?.let { return@withDefault it }
|
||||
}
|
||||
|
||||
if (inherited) {
|
||||
//5. own inheritance
|
||||
add(parent?.readProperty(name, inherited, useStyles))
|
||||
parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }
|
||||
//6. prototype inheritance
|
||||
add(prototype.parent?.readProperty(name, inherited, useStyles))
|
||||
prototype.parent?.readProperty(propertyName, inherited, useStyles)?.let { return@withDefault it }
|
||||
}
|
||||
|
||||
add(descriptor.defaultNode[name])
|
||||
}
|
||||
return mutable.withDefault { name ->
|
||||
default.firstNotNullOfOrNull { it[name] }
|
||||
descriptor.defaultNode[name]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.kmath.geometry.euclidean3d.Float32Space3D
|
||||
import space.kscience.kmath.geometry.euclidean3d.Float32Vector3D
|
||||
import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.html.VisionOutput
|
||||
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
||||
@ -65,6 +67,11 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Sol
|
||||
defaultDeserializer { SolidBase.serializer(serializer<Solid>()) }
|
||||
solids()
|
||||
}
|
||||
|
||||
|
||||
polymorphic(Float32Vector3D::class, Float32Space3D.VectorSerializer)
|
||||
|
||||
// polymorphic(Float64Vector3D::class, Float64Space3D.VectorSerializer)
|
||||
}
|
||||
|
||||
internal val jsonForSolids: Json = Json(VisionManager.defaultJson) {
|
||||
|
@ -80,6 +80,7 @@ class SolidPropertyTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("#555555", box?.readProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.string)
|
||||
assertEquals("#555555", box?.color?.string)
|
||||
assertEquals(0.3, box?.opacity)
|
||||
}
|
||||
@ -101,6 +102,7 @@ class SolidPropertyTest {
|
||||
box = ref("box".asName())
|
||||
}
|
||||
}
|
||||
assertEquals("#555555", box?.readProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.string)
|
||||
assertEquals("#555555", box!!.color.string)
|
||||
assertEquals(0.3, box.opacity)
|
||||
}
|
||||
|
Reference in New Issue
Block a user