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 2022/03/24 11:10:07 UTC

[isis] 01/03: ISIS-2957 upgrade to gradle 7.4, js functions in companion object

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

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

commit b393710c1a2e257ace582eb4aaf096752c549a4f
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Wed Mar 23 09:14:30 2022 +0100

    ISIS-2957 upgrade to gradle 7.4, js functions in companion object
---
 .../gradle/wrapper/gradle-wrapper.properties       |   2 +-
 .../client/kroviz/ui/panel/EventBubbleChart.kt     | 109 ++++++++++++---------
 2 files changed, 64 insertions(+), 47 deletions(-)

diff --git a/incubator/clients/kroviz/gradle/wrapper/gradle-wrapper.properties b/incubator/clients/kroviz/gradle/wrapper/gradle-wrapper.properties
index 69a9715..41dfb87 100644
--- a/incubator/clients/kroviz/gradle/wrapper/gradle-wrapper.properties
+++ b/incubator/clients/kroviz/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventBubbleChart.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventBubbleChart.kt
index a400cbe..441df86 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventBubbleChart.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventBubbleChart.kt
@@ -26,8 +26,8 @@ import io.kvision.core.UNIT
 import io.kvision.panel.SimplePanel
 import io.kvision.utils.obj
 import org.apache.isis.client.kroviz.core.event.LogEntry
-import org.apache.isis.client.kroviz.ui.dialog.EventLogDetail
 import org.apache.isis.client.kroviz.ui.core.SessionManager
+import org.apache.isis.client.kroviz.ui.dialog.EventLogDetail
 import kotlin.math.pow
 
 @OptIn(kotlin.js.ExperimentalJsExport::class)
@@ -63,26 +63,34 @@ class EventBubbleChart() : SimplePanel() {
         )
     }
 
+    private fun buildLabelsNew(): List<String> {
+        val legendLabels = mutableListOf<String>()
+        legendLabels.add("0 .. 4")
+        legendLabels.add("5 .. 8")
+        legendLabels.add("9 .. 16")
+        legendLabels.add("17 .. 32")
+        legendLabels.add("33 .. 64")
+        legendLabels.add("65 .. 128")
+        legendLabels.add(">= 129")
+        return legendLabels
+    }
+
     // https://stackoverflow.com/questions/45249779/chart-js-bubble-chart-changing-dataset-labels
     private fun buildChartOptions(dataSetsList: List<DataSets>): ChartOptions {
-        val chartOptions = ChartOptions(
+        return ChartOptions(
             plugins = PluginsOptions(
                 title = TitleOptions(
                     text = listOf<String>("Request Duration over Time by Request Density and Response Size"),
                     display = true
                 ),
-                tooltip = TooltipOptions(callbacks = toolTipCallback()),
+                tooltip = TooltipOptions(
+                    callbacks = TooltipCallback(
+                        footer = tooltipCallbackFooterJsFunction()
+                    )
+                ),
                 legend = buildLegend()
             ),
-            onClick = js(
-                "function(e) {"
-                        + "var element = e.chart.getElementsAtEventForMode(e, 'nearest', {intersect: true}, true);"
-                        + "if (element.length > 0) {"
-                        + "var i = element[0].index;"
-                        + "kroviz.org.apache.isis.client.kroviz.ui.panel.openLogEntry(i);"
-                        + "}"
-                        + "}"
-            ),
+            onClick = onClickJsFunction(),
             showLine = true,
             scales = mapOf(
                 "x" to ChartScales(
@@ -96,25 +104,6 @@ class EventBubbleChart() : SimplePanel() {
                 )
             )
         )
-        return chartOptions
-    }
-
-    // https://www.youtube.com/watch?v=UxJ5d-HGhJA
-    // https://en.wikipedia.org/wiki/Clarke%27s_three_laws -> #2
-    // I would have appreciated a real API.
-    private fun toolTipCallback(): TooltipCallback {
-        return TooltipCallback(
-            footer = js(
-                "function(context) {"
-                        + "var ctx = context[0];"
-                        + "var chart = ctx.chart;"
-                        + "var ccc = chart.config._config;"
-                        + "var data = ccc.data;"
-                        + "var i = ctx.dataIndex;"
-                        + "return data.labels[i];"
-                        + "}"
-            )
-        )
     }
 
     private fun LogEntry.toLabel(index: Int): String {
@@ -167,13 +156,13 @@ class EventBubbleChart() : SimplePanel() {
     private fun LogEntry.calculateBubbleColor(): Color {
         val i = runningAtStart
         return when {
-            (i >= 0) && (i <= 4) -> EventBubbleChart.LIGHT_BLUE
-            (i > 4) && (i <= 8) -> EventBubbleChart.DARK_BLUE
-            (i > 8) && (i <= 16) -> EventBubbleChart.GREEN
-            (i > 16) && (i <= 32) -> EventBubbleChart.YELLOW
-            (i > 32) && (i <= 64) -> EventBubbleChart.RED
-            (i > 64) && (i <= 128) -> EventBubbleChart.RED_VIOLET
-            else -> EventBubbleChart.VIOLET
+            (i >= 0) && (i <= 4) -> LIGHT_BLUE
+            (i > 4) && (i <= 8) -> DARK_BLUE
+            (i > 8) && (i <= 16) -> GREEN
+            (i > 16) && (i <= 32) -> YELLOW
+            (i > 32) && (i <= 64) -> RED
+            (i > 64) && (i <= 128) -> RED_VIOLET
+            else -> VIOLET
         }
     }
 
@@ -192,26 +181,29 @@ class EventBubbleChart() : SimplePanel() {
     }
 
     private fun buildLegend(): LegendOptions {
-        val legend = LegendOptions(
+        return LegendOptions(
             display = true,
             position = Position.RIGHT,
             labels = buildLegendLabelOptions(),
-            title = LegendTitleOptions(text = "title here")
+            title = LegendTitleOptions(text = "Parallel Requests", display = true),
         )
-        return legend
     }
 
     private fun buildLegendLabelOptions(): LegendLabelOptions {
         val legendLabelOptions = LegendLabelOptions(
-            color = EventBubbleChart.YELLOW //mutableListOf(DARK_BLUE, LIGHT_BLUE, GREEN, YELLOW, RED, RED_VIOLET, VIOLET)
+ /*           generateLabels = {
+                val legendItemList = mutableListOf<LegendItem>()
+                val li = obj {
+                    text = "0 ..4"
+                }
+                legendItemList.add(li as LegendItem)
+                legendItemList as Array<LegendItem>
+            },*/
+            color = YELLOW
         )
         return legendLabelOptions
     }
 
-    private fun generateLabels(): List<LegendItem> {
-        return mutableListOf<LegendItem>()
-    }
-
     companion object {
         val VIOLET = Color.rgba(0x80, 0x64, 0xA2, 0x80)
         val RED_VIOLET = Color.rgba(0xA0, 0x5A, 0x78, 0x80)
@@ -220,6 +212,31 @@ class EventBubbleChart() : SimplePanel() {
         val GREEN = Color.rgba(0x9B, 0xBB, 0x59, 0x80)
         val LIGHT_BLUE = Color.rgba(0x4B, 0xAC, 0xC6, 0x80)
         val DARK_BLUE = Color.rgba(0x4F, 0x81, 0xBD, 0x80)
+
+        fun onClickJsFunction(): dynamic {
+            return js(
+                """function(e) {
+                        var element = e.chart.getElementsAtEventForMode(e, 'nearest', {intersect: true}, true);
+                        if (element.length > 0) {
+                            var i = element[0].index;
+                            kroviz.org.apache.isis.client.kroviz.ui.panel.openLogEntry(i);
+                            }
+                        }"""
+            )
+        }
+
+        fun tooltipCallbackFooterJsFunction(): dynamic {
+            return js(
+                """function(context) {
+                            var ctx = context[0];
+                            var chart = ctx.chart;
+                            var ccc = chart.config._config;
+                            var data = ccc.data;
+                            var i = ctx.dataIndex;
+                            return data.labels[i];
+                }"""
+            )
+        }
     }
 
 }