commonMain.jetbrains.datalore.vis.svg.SvgTSpanElement.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vis-svg-portable-jvm Show documentation
Show all versions of vis-svg-portable-jvm Show documentation
The Let-Plot Kotlin API depends on this artifact.
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.vis.svg
import jetbrains.datalore.base.observable.property.Property
import jetbrains.datalore.base.observable.property.WritableProperty
import jetbrains.datalore.base.values.Color
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.FILL
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.FILL_OPACITY
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.STROKE
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.STROKE_OPACITY
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.STROKE_WIDTH
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.TEXT_ANCHOR
import jetbrains.datalore.vis.svg.SvgTextContent.Companion.TEXT_DY
class SvgTSpanElement() : SvgElement(), SvgTextContent {
companion object {
private val X: SvgAttributeSpec =
SvgAttributeSpec.createSpec("x")
private val Y: SvgAttributeSpec =
SvgAttributeSpec.createSpec("y")
}
override val elementName = "tspan"
override val computedTextLength: Double
get() = container().getPeer()!!.getComputedTextLength(this)
constructor(text: String) : this() {
setText(text)
}
constructor(x: Double, y: Double, text: String) : this(text) {
setAttribute(X, x)
setAttribute(Y, y)
}
fun x(): Property {
return getAttribute(X)
}
fun y(): Property {
return getAttribute(Y)
}
fun setText(text: String) {
children().clear()
addText(text)
}
fun addText(text: String) {
val node = SvgTextNode(text)
children().add(node)
}
override fun fill(): Property {
return getAttribute(FILL)
}
override fun fillColor(): WritableProperty {
return SvgUtils.colorAttributeTransform(fill(), fillOpacity())
}
override fun fillOpacity(): Property {
return getAttribute(FILL_OPACITY)
}
override fun stroke(): Property {
return getAttribute(STROKE)
}
override fun strokeColor(): WritableProperty {
return SvgUtils.colorAttributeTransform(stroke(), strokeOpacity())
}
override fun strokeOpacity(): Property {
return getAttribute(STROKE_OPACITY)
}
override fun strokeWidth(): Property {
return getAttribute(STROKE_WIDTH)
}
override fun textAnchor(): Property {
return getAttribute(TEXT_ANCHOR)
}
override fun textDy(): Property {
return getAttribute(TEXT_DY)
}
}