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

chenli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new c1bb23094a feat: add a new radar chart operator (#4248)
c1bb23094a is described below

commit c1bb23094ac117bb9db717a4d921428cbf7518a4
Author: Prateek Ganigi <[email protected]>
AuthorDate: Wed Mar 4 20:52:19 2026 -0800

    feat: add a new radar chart operator (#4248)
    
    ### What changes were proposed in this PR?
    <img width="2940" height="1662" alt="image"
    
src="https://github.com/user-attachments/assets/68f1c752-37fc-4b77-9417-c25dd72afa43";
    />
    
    This change introduces a radar chart operator, which visualizes
    multivariate data by plotting multiple quantitative variables on axes
    that radiate from a central point.
    
    In a radar chart:
    
    Each axis represents a distinct variable or feature.
    Data points are plotted along each axis according to their value and
    connected to form a polygon.
    Multiple observations can be overlaid for comparison.
    The resulting shape and area provide intuitive insights into the
    strengths, weaknesses, and patterns across variables.
    This visualization is especially useful for comparing feature profiles,
    identifying outliers, and understanding the distribution of values
    across several dimensions in a single, compact graphic.
    The operator takes as input a set of variables (features) for each
    observation and outputs a radar chart that enables easy visual
    comparison across all provided dimensions.
    
    ### Any related issues, documentation, discussions?
    No related issues, documentation, discussions have been linked to this
    feature at this time.
    
    ### How was this PR tested?
    A dedicated test file (TestRadarChart.scala) was created to thoroughly
    test the radar chart operator, covering both typical and edge cases. The
    tests verify correct rendering and data handling for various input
    scenarios. In addition, all existing test cases were run using sbt test
    to ensure no regressions were introduced. Manual testing was also
    performed in the Texera UI to visually confirm the radar chart output.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    This PR was co-authored by Perplexity AI.
    
    Co-authored-by: Chen Li <[email protected]>
---
 .../apache/texera/amber/operator/LogicalOp.scala   |   2 +
 .../radarChart/RadarChartOpDesc.scala              | 166 +++++++++++++++++++++
 frontend/src/assets/operator_images/RadarChart.png | Bin 0 -> 171348 bytes
 3 files changed, 168 insertions(+)

diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/LogicalOp.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/LogicalOp.scala
index a575d5b018..931596b1bf 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/LogicalOp.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/LogicalOp.scala
@@ -124,6 +124,7 @@ import 
org.apache.texera.amber.operator.visualization.nestedTable.NestedTableOpD
 import 
org.apache.texera.amber.operator.visualization.networkGraph.NetworkGraphOpDesc
 import org.apache.texera.amber.operator.visualization.pieChart.PieChartOpDesc
 import 
org.apache.texera.amber.operator.visualization.quiverPlot.QuiverPlotOpDesc
+import 
org.apache.texera.amber.operator.visualization.radarChart.RadarChartOpDesc
 import 
org.apache.texera.amber.operator.visualization.rangeSlider.RangeSliderOpDesc
 import 
org.apache.texera.amber.operator.visualization.sankeyDiagram.SankeyDiagramOpDesc
 import 
org.apache.texera.amber.operator.visualization.scatter3DChart.Scatter3dChartOpDesc
@@ -190,6 +191,7 @@ trait StateTransferFunc
     new Type(value = classOf[RangeSliderOpDesc], name = "RangeSlider"),
     new Type(value = classOf[PieChartOpDesc], name = "PieChart"),
     new Type(value = classOf[QuiverPlotOpDesc], name = "QuiverPlot"),
+    new Type(value = classOf[RadarChartOpDesc], name = "RadarChart"),
     new Type(value = classOf[WordCloudOpDesc], name = "WordCloud"),
     new Type(value = classOf[HtmlVizOpDesc], name = "HTMLVisualizer"),
     new Type(value = classOf[UrlVizOpDesc], name = "URLVisualizer"),
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/radarChart/RadarChartOpDesc.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/radarChart/RadarChartOpDesc.scala
new file mode 100644
index 0000000000..ae4c383ea1
--- /dev/null
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/radarChart/RadarChartOpDesc.scala
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.operator.visualization.radarChart
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import org.apache.texera.amber.core.workflow.OutputPort.OutputMode
+import org.apache.texera.amber.core.workflow.{InputPort, OutputPort, 
PortIdentity}
+import org.apache.texera.amber.operator.PythonOperatorDescriptor
+import org.apache.texera.amber.operator.metadata.annotations.{
+  AutofillAttributeName,
+  AutofillAttributeNameList
+}
+import org.apache.texera.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import org.apache.texera.amber.pybuilder.PyStringTypes.EncodableString
+import org.apache.texera.amber.pybuilder.PythonTemplateBuilder
+import 
org.apache.texera.amber.pybuilder.PythonTemplateBuilder.PythonTemplateBuilderStringContext
+
+import javax.validation.constraints.NotNull
+
+// type constraint: value can only be numeric
+@JsonSchemaInject(json = """
+{
+  "attributeTypeRules": {
+    "valueColumns": {
+      "enum": ["integer", "long", "double"]
+    }
+  }
+}
+""")
+class RadarChartOpDesc extends PythonOperatorDescriptor {
+
+  @JsonProperty(value = "nameColumn", required = true)
+  @JsonSchemaTitle("Name Column")
+  @JsonPropertyDescription("Column containing entity names for each radar")
+  @AutofillAttributeName
+  @NotNull(message = "Name column cannot be empty")
+  var nameColumn: EncodableString = ""
+
+  @JsonProperty(value = "valueColumns", required = true)
+  @JsonSchemaTitle("Value Columns")
+  @JsonPropertyDescription("Columns containing numeric values for radar chart 
axes")
+  @AutofillAttributeNameList
+  var valueColumns: List[EncodableString] = _
+
+  @JsonProperty(value = "fillOpacity", required = true)
+  @JsonSchemaTitle("Fill Opacity")
+  @JsonPropertyDescription(
+    "Opacity value for radar chart fill from 0.0 (transparent) to 1.0 (opaque)"
+  )
+  @JsonSchemaInject(json = """{ "minimum": 0.0, "maximum": 1.0, "default": 0.5 
}""")
+  var fillOpacity: Double = 0.5
+
+  override def operatorInfo: OperatorInfo =
+    OperatorInfo(
+      "Radar Chart",
+      "Visualize data in a Radar Chart",
+      OperatorGroupConstants.VISUALIZATION_SCIENTIFIC_GROUP,
+      inputPorts = List(InputPort()),
+      outputPorts = List(OutputPort(mode = OutputMode.SINGLE_SNAPSHOT))
+    )
+
+  override def getOutputSchemas(
+      inputSchemas: Map[PortIdentity, Schema]
+  ): Map[PortIdentity, Schema] = {
+    val outputSchema = Schema()
+      .add("html-content", AttributeType.STRING)
+    Map(operatorInfo.outputPorts.head.id -> outputSchema)
+  }
+
+  def manipulateTable(): PythonTemplateBuilder = {
+    assert(nameColumn.nonEmpty)
+    assert(valueColumns != null && valueColumns.nonEmpty)
+    val valueColsList = valueColumns.map(col => pyb"""$col""").mkString(", ")
+    pyb"""
+       |        required_cols = [$nameColumn, $valueColsList]
+       |        table.dropna(subset=required_cols, inplace=True)
+       |        value_cols = [$valueColsList]
+       |        for col in value_cols:
+       |            table[col] = pd.to_numeric(table[col], errors='coerce')
+       |        table.dropna(subset=value_cols, inplace=True)
+       |"""
+  }
+
+  def createPlotlyFigure(): PythonTemplateBuilder = {
+    val valueColsList = valueColumns.map(col => pyb"""$col""").mkString(", ")
+    pyb"""
+       |        fig = go.Figure()
+       |        categories = [$valueColsList]
+       |
+       |        for idx, row in table.iterrows():
+       |            values = [row[col] for col in categories]
+       |            values.append(values[0])
+       |            categories_closed = categories + [categories[0]]
+       |
+       |            fig.add_trace(go.Scatterpolar(
+       |                r=values,
+       |                theta=categories_closed,
+       |                fill='toself',
+       |                name=str(row[$nameColumn]),
+       |                opacity=$fillOpacity
+       |            ))
+       |
+       |        fig.update_layout(
+       |            polar=dict(
+       |                radialaxis=dict(
+       |                    visible=True,
+       |                    range=[0, None]
+       |                )
+       |            ),
+       |            showlegend=True,
+       |            margin=dict(t=40, b=40, l=40, r=40)
+       |        )
+       |"""
+  }
+
+  override def generatePythonCode(): String = {
+    val finalcode =
+      pyb"""
+         |from pytexera import *
+         |
+         |import plotly.graph_objects as go
+         |import plotly.io
+         |import pandas as pd
+         |
+         |class ProcessTableOperator(UDFTableOperator):
+         |    def render_error(self, error_msg):
+         |        return '''<h1>RadarChart is not available.</h1>
+         |                  <p>Reason is: {} </p>
+         |               '''.format(error_msg)
+         |
+         |    @overrides
+         |    def process_table(self, table: Table, port: int) -> 
Iterator[Optional[TableLike]]:
+         |        if table.empty:
+         |           yield {'html-content': self.render_error("input table is 
empty.")}
+         |           return
+         |        ${manipulateTable()}
+         |        if table.empty:
+         |           yield {'html-content': self.render_error("input table is 
empty after removing missing values.")}
+         |           return
+         |        ${createPlotlyFigure()}
+         |        html = plotly.io.to_html(fig, include_plotlyjs='cdn', 
auto_play=False)
+         |        yield {'html-content': html}
+         |
+         |"""
+    finalcode.encode
+  }
+}
diff --git a/frontend/src/assets/operator_images/RadarChart.png 
b/frontend/src/assets/operator_images/RadarChart.png
new file mode 100644
index 0000000000..c5d9569df8
Binary files /dev/null and b/frontend/src/assets/operator_images/RadarChart.png 
differ

Reply via email to