All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.vis.svg.SvgImageElement.kt Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
/*
 * 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.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.base.observable.property.Property
import jetbrains.datalore.vis.svg.SvgTransformable.Companion.TRANSFORM
import jetbrains.datalore.vis.svg.XmlNamespace.XLINK_NAMESPACE_URI
import jetbrains.datalore.vis.svg.XmlNamespace.XLINK_PREFIX

open class SvgImageElement() : SvgGraphicsElement(),
    SvgTransformable {

    companion object {
        val X: SvgAttributeSpec =
            SvgAttributeSpec.createSpec("x")
        val Y: SvgAttributeSpec =
            SvgAttributeSpec.createSpec("y")
        val WIDTH: SvgAttributeSpec =
            SvgAttributeSpec.createSpec(SvgConstants.WIDTH)
        val HEIGHT: SvgAttributeSpec =
            SvgAttributeSpec.createSpec(SvgConstants.HEIGHT)
        val HREF: SvgAttributeSpec =
            SvgAttributeSpec.createSpecNS(
                "href",
                XLINK_PREFIX,
                XLINK_NAMESPACE_URI
            )
        val PRESERVE_ASPECT_RATIO: SvgAttributeSpec =
            SvgAttributeSpec.createSpec("preserveAspectRatio")
    }

    override val elementName = "image"

    override val bBox: DoubleRectangle
        get() = container().getPeer()!!.getBBox(this)

    init {
        setAttribute(PRESERVE_ASPECT_RATIO, "none")
    }

    constructor(x: Double, y: Double, width: Double, height: Double) : this() {

        setAttribute(X, x)
        setAttribute(Y, y)
        setAttribute(WIDTH, width)
        setAttribute(HEIGHT, height)
    }

    fun x(): Property {
        return getAttribute(X)
    }

    fun y(): Property {
        return getAttribute(Y)
    }

    fun width(): Property {
        return getAttribute(WIDTH)
    }

    fun height(): Property {
        return getAttribute(HEIGHT)
    }

    open fun href(): Property {
        return getAttribute(HREF)
    }

    fun preserveAspectRatio(): Property {
        return getAttribute(PRESERVE_ASPECT_RATIO)
    }

    override fun transform(): Property {
        return getAttribute(TRANSFORM)
    }

    override fun pointToTransformedCoordinates(point: DoubleVector): DoubleVector {
        return container().getPeer()!!.invertTransform(this, point)
    }

    override fun pointToAbsoluteCoordinates(point: DoubleVector): DoubleVector {
        return container().getPeer()!!.applyTransform(this, point)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy