org.jetbrains.kotlinx.ggdsl.dsl.kProp.kt Maven / Gradle / Ivy
/*
* Copyright 2020-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package org.jetbrains.kotlinx.ggdsl.dsl
import org.jetbrains.kotlinx.ggdsl.ir.bindings.*
import org.jetbrains.kotlinx.ggdsl.ir.data.ColumnPointer
import org.jetbrains.kotlinx.ggdsl.ir.scale.NonPositionalScale
import org.jetbrains.kotlinx.ggdsl.ir.scale.NonPositionalUnspecifiedScale
import org.jetbrains.kotlinx.ggdsl.ir.scale.PositionalScale
import org.jetbrains.kotlinx.ggdsl.ir.scale.PositionalUnspecifiedScale
import kotlin.reflect.KProperty
import kotlin.reflect.typeOf
//TODO
@PublishedApi
internal inline fun KProperty.toColumnPointer(): ColumnPointer =
ColumnPointer(this.name)
/**
* Maps the given [KProperty] (i.e. a column with the same name and type as the given property)
* to this non-scalable positional ("sub-positional") aesthetic attribute.
*
* @param property the mapped [KProperty].
*/
public inline operator fun NonScalablePositionalAes.invoke(
property: KProperty
) {
context.bindingCollector.mappings[this.name] =
NonScalablePositionalMapping(this.name, property.toColumnPointer(), typeOf())
}
/**
* Maps the given [KProperty] (i.e. a column with the same name and type as the given property)
* to this positional aesthetic attribute with a default (i.e. without specifying the type and parameters;
* they will be defined automatically) scale.
*
* @param property the mapped [KProperty].
*/
public inline operator fun ScalablePositionalAes.invoke(
property: KProperty
): ScaledUnspecifiedDefaultPositionalMapping {
val mapping = ScaledUnspecifiedDefaultPositionalMapping(
this.name,
property.toColumnPointer().scaled(),
typeOf()
)
context.bindingCollector.mappings[this.name] = mapping
return mapping
}
/**
* Maps the given [KProperty] (i.e. a column with the same name and type as the given property)
* to this non-positional aesthetic attribute with a default (i.e. without specifying the type and parameters;
* they will be defined automatically) scale.
*
* @param property the mapped [KProperty].
*/
public inline operator fun ScalableNonPositionalAes.invoke(
property: KProperty
): ScaledUnspecifiedDefaultNonPositionalMapping {
val mapping = ScaledUnspecifiedDefaultNonPositionalMapping(
this.name,
property.toColumnPointer().scaled(),
typeOf()
)
context.bindingCollector.mappings[this.name] = mapping
return mapping
}
/**
* Applies default (i.e. without specifying the type and parameters;
* they will be defined automatically; can be both used for positional and non-positional mappings) scale
* to this [KProperty] (i.e. a column with the same name and type as the given property).
*/
public inline fun KProperty.scaled()
: ColumnScaledUnspecifiedDefault =
ColumnScaledUnspecifiedDefault(this.toColumnPointer())
/**
* Applies unspecified (i.e. without specifying the type and parameters;
* they will be defined automatically) positional scale to this [KProperty] (i.e. a column with the same
* name and type as the given property).
*
* @param DomainType type of domain.
* @param scale positional default scale.
* @return scaled source.
*/
public inline fun KProperty.scaled(scale: PositionalUnspecifiedScale):
ColumnScaledPositionalUnspecified =
ColumnScaledPositionalUnspecified(this.toColumnPointer(), scale)
/**
* Applies unspecified (i.e. without specifying the type and parameters;
* they will be defined automatically) non-positional scale to this [KProperty] (i.e. a column with the same
* name and type as the given property).
*
* @param DomainType type of domain.
* @param scale non-positional default scale.
* @return scaled source.
*/
public inline fun KProperty.scaled(scale: NonPositionalUnspecifiedScale):
ColumnScaledNonPositionalUnspecified =
ColumnScaledNonPositionalUnspecified(this.toColumnPointer(), scale)
/**
* Applies positional scale to this [KProperty] (i.e. a column with the same name
* and type as the given property).
*
* @param DomainType type of domain.
* @param scale positional scale.
* @return scaled source.
*/
public inline fun KProperty.scaled(
scale: PositionalScale
): ColumnScaledPositional = ColumnScaledPositional(this.toColumnPointer(), scale)
/**
* Applies non-positional scale to this [KProperty] (i.e. a column with the same name
* and type as the given property).
*
* @param DomainType type of domain.
* @param scale non-positional scale.
* @return scaled source.
*/
public inline fun KProperty.scaled(
scale: NonPositionalScale
): ColumnScaledNonPositional = ColumnScaledNonPositional(this.toColumnPointer(), scale)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy