Ma77Ball commented on code in PR #4221: URL: https://github.com/apache/texera/pull/4221#discussion_r2825202029
########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/webglPolarChart/WebglPolarChartOpDesc.scala: ########## @@ -0,0 +1,113 @@ +/* + * 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. + */ + +package org.apache.texera.amber.operator.visualization.webglPolarChart + +import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription} +import com.kjetland.jackson.jsonSchema.annotations.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 +import org.apache.texera.amber.operator.metadata.{OperatorGroupConstants, OperatorInfo} + +class WebglPolarChartOpDesc extends PythonOperatorDescriptor { + + @JsonProperty(value = "r", required = true) + @JsonSchemaTitle("r") + @JsonPropertyDescription("The column name for radial values") + @AutofillAttributeName + var r: String = "" + + @JsonProperty(value = "theta", required = true) + @JsonSchemaTitle("theta") + @JsonPropertyDescription("The column name for angular values (degrees)") + @AutofillAttributeName + var theta: String = "" + + override def getOutputSchemas( + inputSchemas: Map[PortIdentity, Schema] + ): Map[PortIdentity, Schema] = { + val outputSchema = Schema() + .add("html-content", AttributeType.STRING) + + Map(operatorInfo.outputPorts.head.id -> outputSchema) + } + + override def operatorInfo: OperatorInfo = + OperatorInfo( + "WebGL Polar Chart", + "Displays data points in a WebGL-accelerated polar scatter plot", + OperatorGroupConstants.VISUALIZATION_SCIENTIFIC_GROUP, + inputPorts = List(InputPort()), + outputPorts = List(OutputPort(mode = OutputMode.SINGLE_SNAPSHOT)) + ) + + override def generatePythonCode(): String = { + s"""from pytexera import * + |import plotly.graph_objects as go + |import plotly.io as pio + | + |class ProcessTableOperator(UDFTableOperator): + | + | @overrides + | def process_table(self, table: Table, port: int) -> Iterator[Optional[TableLike]]: + | + | if table is None or table.empty: + | yield {'html-content': '<h3>No data available for WebGL Polar Chart</h3>'} + | return + | + | r_vals = table['$r'].values + | theta_vals = table['$theta'].values Review Comment: Breaks when the column name has an apostrophe in it. Also, it might be good to accept only numeric columns to avoid confusion. ########## frontend/src/assets/operator_images/WebglPolarChart.png: ########## Review Comment: The polar chart icon is not showing on the frontend. <img width="662" height="274" alt="Image" src="https://github.com/user-attachments/assets/15725a81-e156-4669-a5a0-6a4c060c589c" /> ########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/webglPolarChart/WebglPolarChartOpDesc.scala: ########## @@ -0,0 +1,113 @@ +/* + * 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. + */ + +package org.apache.texera.amber.operator.visualization.webglPolarChart + +import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription} +import com.kjetland.jackson.jsonSchema.annotations.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 +import org.apache.texera.amber.operator.metadata.{OperatorGroupConstants, OperatorInfo} + +class WebglPolarChartOpDesc extends PythonOperatorDescriptor { + + @JsonProperty(value = "r", required = true) + @JsonSchemaTitle("r") + @JsonPropertyDescription("The column name for radial values") + @AutofillAttributeName + var r: String = "" + + @JsonProperty(value = "theta", required = true) + @JsonSchemaTitle("theta") + @JsonPropertyDescription("The column name for angular values (degrees)") + @AutofillAttributeName + var theta: String = "" + + override def getOutputSchemas( + inputSchemas: Map[PortIdentity, Schema] + ): Map[PortIdentity, Schema] = { + val outputSchema = Schema() + .add("html-content", AttributeType.STRING) + + Map(operatorInfo.outputPorts.head.id -> outputSchema) + } + + override def operatorInfo: OperatorInfo = + OperatorInfo( + "WebGL Polar Chart", + "Displays data points in a WebGL-accelerated polar scatter plot", + OperatorGroupConstants.VISUALIZATION_SCIENTIFIC_GROUP, + inputPorts = List(InputPort()), + outputPorts = List(OutputPort(mode = OutputMode.SINGLE_SNAPSHOT)) + ) + + override def generatePythonCode(): String = { + s"""from pytexera import * + |import plotly.graph_objects as go + |import plotly.io as pio + | + |class ProcessTableOperator(UDFTableOperator): + | + | @overrides + | def process_table(self, table: Table, port: int) -> Iterator[Optional[TableLike]]: + | + | if table is None or table.empty: + | yield {'html-content': '<h3>No data available for WebGL Polar Chart</h3>'} + | return + | + | r_vals = table['$r'].values + | theta_vals = table['$theta'].values + | + | fig = go.Figure(data=go.Scatterpolargl( + | r=r_vals, + | theta=theta_vals, + | mode='markers', + | marker=dict( + | size=10, + | opacity=0.7, + | line=dict(color='white') + | ) + | )) + | + | fig.update_layout( + | title='WebGL Polar Chart', Review Comment: WebGL does not need to be included. You can add it to the information button (if you want to keep it). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
