Skip to content

Commit 969e324

Browse files
committed
feat(workflow-operator): title the Volcano Plot color bar with the x label
Drop the Color Bar Label property; the points are colored by the effect column that is on the x axis, so the color bar now carries the X Label text in both the engine template and the exported script.
1 parent ba9e78d commit 969e324

2 files changed

Lines changed: 27 additions & 28 deletions

File tree

‎common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDesc.scala‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,16 @@ class VolcanoPlotOpDesc extends PythonOperatorDescriptor with PlotlyStandaloneCo
7676

7777
@JsonProperty(required = false)
7878
@JsonSchemaTitle("X Label")
79-
@JsonPropertyDescription("The label for the x axis; leave empty for the effect size column name")
79+
@JsonPropertyDescription(
80+
"The label for the x axis and the color bar; leave empty for the effect size column name"
81+
)
8082
var xLabel: EncodableString = ""
8183

8284
@JsonProperty(required = false)
8385
@JsonSchemaTitle("Y Label")
8486
@JsonPropertyDescription("The label for the y axis; leave empty for -log10(<p-value column>)")
8587
var yLabel: EncodableString = ""
8688

87-
@JsonProperty(required = false)
88-
@JsonSchemaTitle("Color Bar Label")
89-
@JsonPropertyDescription(
90-
"The label for the color bar; leave empty for the effect size column name"
91-
)
92-
var colorLabel: EncodableString = ""
93-
9489
override def operatorInfo: OperatorInfo =
9590
OperatorInfo.forVisualization(
9691
userFriendlyName = "Volcano Plot",
@@ -115,8 +110,6 @@ class VolcanoPlotOpDesc extends PythonOperatorDescriptor with PlotlyStandaloneCo
115110
private def titleText: EncodableString = if (title.trim.nonEmpty) title else "Volcano Plot"
116111
private def xAxisTitle: EncodableString = if (xLabel.trim.nonEmpty) xLabel else effectColumn
117112
private def yAxisTitle: EncodableString = if (yLabel.trim.nonEmpty) yLabel else yColumn
118-
private def colorBarTitle: EncodableString =
119-
if (colorLabel.trim.nonEmpty) colorLabel else effectColumn
120113

121114
override def generatePythonCode(): String = {
122115
pyb"""
@@ -160,7 +153,7 @@ class VolcanoPlotOpDesc extends PythonOperatorDescriptor with PlotlyStandaloneCo
160153
| fig.update_layout(
161154
| xaxis_title=$xAxisTitle,
162155
| yaxis_title=$yAxisTitle,
163-
| coloraxis_colorbar_title_text=$colorBarTitle
156+
| coloraxis_colorbar_title_text=$xAxisTitle
164157
| )
165158
|
166159
| html = plotly.io.to_html(fig, include_plotlyjs='cdn', auto_play=False)
@@ -206,7 +199,7 @@ class VolcanoPlotOpDesc extends PythonOperatorDescriptor with PlotlyStandaloneCo
206199
| fig.update_layout(
207200
| xaxis_title=${pyStringLiteral(xAxisTitle)},
208201
| yaxis_title=${pyStringLiteral(yAxisTitle)},
209-
| coloraxis_colorbar_title_text=${pyStringLiteral(colorBarTitle)}
202+
| coloraxis_colorbar_title_text=${pyStringLiteral(xAxisTitle)}
210203
| )
211204
| fig.write_json(outputJson)
212205
| fig.write_html(outputHtml)

‎common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,38 +108,44 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers {
108108
val op = configured
109109
op.title = "TITLE_SENT \"quoted\" 火山"
110110
op.xLabel = "X_LBL_SENT log₂ fold change"
111-
op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p)"
112-
op.colorLabel = "COLOR_LBL_SENT \\ back\\slash"
111+
op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p) \\ back\\slash"
113112
val code = op.generatePythonCode()
114113
code should include(s"title=${decoded(op.title)}")
115114
code should include(s"xaxis_title=${decoded(op.xLabel)}")
116115
code should include(s"yaxis_title=${decoded(op.yLabel)}")
117-
code should include(s"coloraxis_colorbar_title_text=${decoded(op.colorLabel)}")
118-
Seq(op.title, op.xLabel, op.yLabel, op.colorLabel).foreach { sentinel =>
116+
Seq(op.title, op.xLabel, op.yLabel).foreach { sentinel =>
119117
code should not include sentinel
120118
}
121119
// A set label replaces the default rather than being emitted next to it.
122120
code should not include b64("Volcano Plot")
123121
code should not include s"xaxis_title=${decoded("log2fc")}"
124122
code should not include s"yaxis_title=${decoded("-log10(pvalue)")}"
125-
code should not include s"coloraxis_colorbar_title_text=${decoded("log2fc")}"
126123
// The y column itself keeps the derived name: a label is text on the axis,
127124
// not a column rename.
128125
code should include(s"y=${decoded("-log10(pvalue)")}")
129126
}
130127

128+
it should "title the color bar with the x axis text because both show the effect column" in {
129+
// The points are colored by the column on the x axis, so the color bar
130+
// carries the x axis text rather than a label of its own.
131+
val op = configured
132+
op.xLabel = "X_LBL_SENT log₂ fold change"
133+
val code = op.generatePythonCode()
134+
code should include(s"coloraxis_colorbar_title_text=${decoded(op.xLabel)}")
135+
code should not include s"coloraxis_colorbar_title_text=${decoded("log2fc")}"
136+
}
137+
131138
it should "treat a whitespace-only label as empty and keep the default" in {
132139
val op = configured
133140
op.title = " "
134141
op.xLabel = "\t"
135-
op.yLabel = " "
136-
op.colorLabel = " \n "
142+
op.yLabel = " \n "
137143
val code = op.generatePythonCode()
138144
code should include(s"title=${decoded("Volcano Plot")}")
139145
code should include(s"xaxis_title=${decoded("log2fc")}")
140146
code should include(s"yaxis_title=${decoded("-log10(pvalue)")}")
141147
code should include(s"coloraxis_colorbar_title_text=${decoded("log2fc")}")
142-
Seq(op.title, op.xLabel, op.yLabel, op.colorLabel).foreach { blank =>
148+
Seq(op.title, op.xLabel, op.yLabel).foreach { blank =>
143149
code should not include decoded(blank)
144150
}
145151
}
@@ -199,13 +205,13 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers {
199205
val op = configured
200206
op.title = "TITLE_SENT \"quoted\" 火山"
201207
op.xLabel = "X_LBL_SENT log₂ fold change"
202-
op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p)"
203-
op.colorLabel = "COLOR_LBL_SENT \\ back\\slash"
208+
op.yLabel = "Y_LBL_SENT -log₁₀(BH-adjusted p) \\ back\\slash"
204209
val code = op.generateStandaloneCode()
205210
code should include("title=\"TITLE_SENT \\\"quoted\\\" 火山\"")
206211
code should include("xaxis_title=\"X_LBL_SENT log₂ fold change\",")
207-
code should include("yaxis_title=\"Y_LBL_SENT -log₁₀(BH-adjusted p)\",")
208-
code should include("coloraxis_colorbar_title_text=\"COLOR_LBL_SENT \\\\ back\\\\slash\"")
212+
code should include("yaxis_title=\"Y_LBL_SENT -log₁₀(BH-adjusted p) \\\\ back\\\\slash\",")
213+
// The color bar follows the x label, since both show the effect column.
214+
code should include("coloraxis_colorbar_title_text=\"X_LBL_SENT log₂ fold change\"")
209215
// A set label replaces the default rather than being emitted next to it.
210216
code should not include """title="Volcano Plot""""
211217
code should not include """xaxis_title="log2fc""""
@@ -220,8 +226,7 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers {
220226
val op = configured
221227
op.title = " "
222228
op.xLabel = "\t"
223-
op.yLabel = " "
224-
op.colorLabel = " \n "
229+
op.yLabel = " \n "
225230
op.generateStandaloneCode() shouldBe configured.generateStandaloneCode()
226231
}
227232

@@ -242,13 +247,14 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with Matchers {
242247
val op = configured
243248
op.pvalueColumn = "padj"
244249
op.title = "Treated vs control"
250+
op.xLabel = "Shrunken log2 fold change"
245251
val engine = op.generatePythonCode()
246252
val export = op.generateStandaloneCode()
247253
Seq(
248254
"title" -> "Treated vs control",
249-
"xaxis_title" -> "log2fc",
255+
"xaxis_title" -> "Shrunken log2 fold change",
250256
"yaxis_title" -> "-log10(padj)",
251-
"coloraxis_colorbar_title_text" -> "log2fc"
257+
"coloraxis_colorbar_title_text" -> "Shrunken log2 fold change"
252258
).foreach {
253259
case (key, text) =>
254260
engine should include(s"$key=${decoded(text)}")

0 commit comments

Comments
 (0)