You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2020/05/26 15:12:23 UTC

[isis] branch master updated (4340168 -> 9e53cfa)

This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git.


    from 4340168  Merge branch 'master' of https://github.com/apache/isis
     new 9eb48fc  ISIS-2342 scale image / fix test
     new 9e53cfa  ISIS-2342 scale image with buttons 3/3

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../kroviz/core/aggregator/BaseAggregator.kt       |  5 --
 .../isis/client/kroviz/core/model/ObjectDM.kt      | 10 +++-
 .../apache/isis/client/kroviz/ui/kv/RoDialog.kt    |  6 +--
 .../client/kroviz/utils/ScalableVectorGraphic.kt   | 58 ++++++++--------------
 .../ScalableVectorGraphicTest.kt                   | 37 +++++++++-----
 5 files changed, 57 insertions(+), 59 deletions(-)


[isis] 01/02: ISIS-2342 scale image / fix test

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 9eb48fc35ad696fb9ff8a298242ae09b39a354df
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Tue May 26 11:04:04 2020 +0200

    ISIS-2342 scale image / fix test
---
 .../org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt | 8 ++++----
 .../ScalableVectorGraphicTest.kt                                 | 9 +++------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
index d14a968..61f1edc 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
@@ -32,21 +32,21 @@ class ScalableVectorGraphic(val data: String) {
         return document.rootElement!!
     }
 
-    private fun setHeight(height: Int) {
+    fun setHeight(height: Int) {
         root().setAttribute("height", height.toString() + "px")
     }
 
-    private fun getHeight(): Int {
+    fun getHeight(): Int {
         val raw = root().getAttribute("height") as String
         val value = raw.replace("px", "")
         return value.toInt()
     }
 
-    private fun setWidth(width: Int) {
+    fun setWidth(width: Int) {
         root().setAttribute("width", width.toString() + "px")
     }
 
-    private fun getWidth(): Int {
+    fun getWidth(): Int {
         val raw = root().getAttribute("width") as String
         val value = raw.replace("px", "")
         return value.toInt()
diff --git a/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt b/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
index af4c455..fb1533c 100644
--- a/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
+++ b/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
@@ -15,8 +15,7 @@ class ScalableVectorGraphicTest {
         val type = "image/svg+xml"
         val p = DOMParser()
         //when
-        val doc = p.parseFromString(response, type)
-        val svg = ScalableVectorGraphic(doc)
+        val svg = ScalableVectorGraphic(response)
         svg.scaleDown()
 
         // then
@@ -31,8 +30,7 @@ class ScalableVectorGraphicTest {
         val type = "image/svg+xml"
         val p = DOMParser()
         //when
-        val doc = p.parseFromString(response, type)
-        val svg = ScalableVectorGraphic(doc)
+        val svg = ScalableVectorGraphic(response)
         svg.scaleUp()
 
         // then
@@ -47,8 +45,7 @@ class ScalableVectorGraphicTest {
         val type = "image/svg+xml"
         val p = DOMParser()
         //when
-        val doc = p.parseFromString(response, type)
-        val svg = ScalableVectorGraphic(doc)
+        val svg = ScalableVectorGraphic(response)
         svg.scaleUp(2.0)
 
         //then


[isis] 02/02: ISIS-2342 scale image with buttons 3/3

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 9e53cfade07a8b3d70bbb5cae03ca9921ff8eba4
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Tue May 26 17:11:56 2020 +0200

    ISIS-2342 scale image with buttons 3/3
---
 .../kroviz/core/aggregator/BaseAggregator.kt       |  5 --
 .../isis/client/kroviz/core/model/ObjectDM.kt      | 10 +++-
 .../apache/isis/client/kroviz/ui/kv/RoDialog.kt    |  6 +--
 .../client/kroviz/utils/ScalableVectorGraphic.kt   | 58 ++++++++--------------
 .../ScalableVectorGraphicTest.kt                   | 28 ++++++++---
 5 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/BaseAggregator.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/BaseAggregator.kt
index 6d6a4d7..9be799b 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/BaseAggregator.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/BaseAggregator.kt
@@ -38,11 +38,6 @@ abstract class BaseAggregator {
         throw Throwable("[BaseAggregator.log] no handler found: ${this::class.simpleName}")
     }
 
-    @Deprecated("use extension function")
-    fun invokeWith(link: Link) {
-        RoXmlHttpRequest().invoke(link, this)
-    }
-
     fun TObject.getLayoutLink(): Link? {
         return links.firstOrNull { l ->
             l.isLayout()
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/ObjectDM.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/ObjectDM.kt
index 88fbef3..29da7fe 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/ObjectDM.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/ObjectDM.kt
@@ -1,7 +1,9 @@
 package org.apache.isis.client.kroviz.core.model
 
+import org.apache.isis.client.kroviz.core.aggregator.BaseAggregator
 import org.apache.isis.client.kroviz.core.event.EventStore
 import org.apache.isis.client.kroviz.core.event.ResourceSpecification
+import org.apache.isis.client.kroviz.core.event.RoXmlHttpRequest
 import org.apache.isis.client.kroviz.to.Link
 import org.apache.isis.client.kroviz.to.Method
 import org.apache.isis.client.kroviz.to.TObject
@@ -48,10 +50,10 @@ class ObjectDM(override val title: String) : DisplayModelWithLayout() {
             val putLink = Link(method = Method.PUT.operation, href = href)
             val logEntry = EventStore.find(reSpec)
             val aggregator = logEntry?.getAggregator()!!
-            aggregator.invokeWith(putLink)
+            putLink.invokeWith(aggregator)
 
             // now data should be reloaded - wait for invoking PUT?
-            aggregator.invokeWith(getLink)
+            getLink.invokeWith(aggregator)
             //refresh of display to be triggered?
         }
     }
@@ -62,4 +64,8 @@ class ObjectDM(override val title: String) : DisplayModelWithLayout() {
         }
     }
 
+    fun Link.invokeWith(aggregator: BaseAggregator) {
+        RoXmlHttpRequest().invoke(this, aggregator)
+    }
+
 }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
index d410d3b..42206fc 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
@@ -42,7 +42,7 @@ class RoDialog(
 
     private val scaleUpButton = Button(
             "",
-            "fas fa-plus",
+            "fas fa-minus",    // TODO fix brain twister
             ButtonStyle.OUTLINEINFO)
             .onClick {
                 (command as ImageDialog).scale(Direction.UP)
@@ -50,7 +50,7 @@ class RoDialog(
 
     private val scaleDownButton = Button(
             "",
-            "fas fa-minus",
+            "fas fa-plus",     // TODO fix brain twister
             ButtonStyle.OUTLINEINFO)
             .onClick {
                 (command as ImageDialog).scale(Direction.DOWN)
@@ -110,7 +110,7 @@ class RoDialog(
     }
 
     private fun hasScalableContent(): Boolean {
-        val scalable = items.firstOrNull() { it.type == ValueType.IMAGE.type }
+        val scalable = items.firstOrNull { it.type == ValueType.IMAGE.type }
         return scalable != null
     }
 
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
index 61f1edc..af1b059 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/ScalableVectorGraphic.kt
@@ -1,10 +1,7 @@
 package org.apache.isis.client.kroviz.utils
 
 import org.w3c.dom.Document
-import org.w3c.dom.Element
 import org.w3c.dom.parsing.DOMParser
-import org.w3c.dom.parsing.XMLSerializer
-import org.w3c.dom.svg.SVGSVGElement
 
 enum class Direction(val id: String) {
     UP("UP"),
@@ -13,56 +10,43 @@ enum class Direction(val id: String) {
 
 class ScalableVectorGraphic(val data: String) {
 
-    val parser = DOMParser()
-    val mimeType = "image/svg+xml"
+    private val parser = DOMParser()
+    private val mimeType = "image/svg+xml"
+    private val tag = "viewBox"
     var document: Document
+    var viewBox: ViewBox
 
     init {
         document = parser.parseFromString(data, mimeType)
-    }
-
-    fun asDocumentElement(): Element? {
-        val xs = XMLSerializer()
-        val str = xs.serializeToString(document)
-        val svg = parser.parseFromString(str, mimeType)
-        return svg.documentElement
-    }
 
-    private fun root(): SVGSVGElement {
-        return document.rootElement!!
+        val root = document.rootElement!!
+        val raw = root.getAttribute(tag) as String
+        val arr = raw.split(" ")
+        viewBox = ViewBox(arr[0].toInt(), arr[1].toInt(), arr[2].toInt(), arr[3].toInt())
     }
 
-    fun setHeight(height: Int) {
-        root().setAttribute("height", height.toString() + "px")
-    }
-
-    fun getHeight(): Int {
-        val raw = root().getAttribute("height") as String
-        val value = raw.replace("px", "")
-        return value.toInt()
-    }
-
-    fun setWidth(width: Int) {
-        root().setAttribute("width", width.toString() + "px")
-    }
-
-    fun getWidth(): Int {
-        val raw = root().getAttribute("width") as String
-        val value = raw.replace("px", "")
-        return value.toInt()
+    private fun setCorner(width: Int, height: Int) {
+        viewBox.width = width
+        viewBox.height = height
+        document.rootElement?.setAttribute(tag, viewBox.asArgs())
     }
 
     fun scaleUp(factor: Double = 0.1) {
         var f = factor
         if (factor < 1) f = 1 + factor
-        val oldHeight = getHeight()
-        val oldWidth = getWidth()
-        setHeight((oldHeight * f).toInt())
-        setWidth((oldWidth * f).toInt())
+        val newWidth = (viewBox.width * f).toInt()
+        val newHeight = (viewBox.height * f).toInt()
+        setCorner(newWidth, newHeight)
     }
 
     fun scaleDown(factor: Double = 0.1) {
         scaleUp(factor * -1)
     }
 
+    class ViewBox(val x: Int, val y: Int, var width: Int, var height: Int) {
+        fun asArgs(): String {
+            return "$x $y $width $height"
+        }
+    }
+
 }
diff --git a/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt b/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
index fb1533c..b460ff9 100644
--- a/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
+++ b/incubator/clients/kroviz/src/test/kotlin/org.apache.isis.client.kroviz.util/ScalableVectorGraphicTest.kt
@@ -9,6 +9,22 @@ import kotlin.test.assertEquals
 class ScalableVectorGraphicTest {
 
     @Test
+    fun testViewBox() {
+        //given
+        val response = PUML_SVG.str
+        val type = "image/svg+xml"
+        val p = DOMParser()
+        //when
+        val svg = ScalableVectorGraphic(response)
+        val viewBox = svg.viewBox
+        // then
+        assertEquals(0, viewBox.x)
+        assertEquals(0, viewBox.y)
+        assertEquals(309, viewBox.width)
+        assertEquals(203, viewBox.height)
+    }
+
+    @Test
     fun testScaleDown() {
         //given
         val response = PUML_SVG.str
@@ -19,8 +35,8 @@ class ScalableVectorGraphicTest {
         svg.scaleDown()
 
         // then
-        assertEquals((203 * 0.9).toInt(), svg.getHeight())
-        assertEquals((309 * 0.9).toInt(), svg.getWidth())
+        assertEquals((203 * 0.9).toInt(), svg.viewBox.height)
+        assertEquals((309 * 0.9).toInt(), svg.viewBox.width)
     }
 
     @Test
@@ -34,8 +50,8 @@ class ScalableVectorGraphicTest {
         svg.scaleUp()
 
         // then
-        assertEquals((203 * 1.1).toInt(), svg.getHeight())
-        assertEquals((309 * 1.1).toInt(), svg.getWidth())
+        assertEquals((203 * 1.1).toInt(), svg.viewBox.height)
+        assertEquals((309 * 1.1).toInt(), svg.viewBox.width)
     }
 
     @Test
@@ -49,8 +65,8 @@ class ScalableVectorGraphicTest {
         svg.scaleUp(2.0)
 
         //then
-        assertEquals(406, svg.getHeight())
-        assertEquals(618, svg.getWidth())
+        assertEquals(406, svg.viewBox.height)
+        assertEquals(618, svg.viewBox.width)
     }
 
 }