Skip to content

Commit af9b1e1

Browse files
authored
fix: DH-21616: Databar overrides text color when using format prop (#1323)
For DH-21616. Databar cells were using the databar bar color for both the bar and the text, ignoring any explicit text color set via formatting. Companion PR: deephaven/web-client-ui#2640
1 parent 7f56903 commit af9b1e1

18 files changed

Lines changed: 50 additions & 1 deletion

plugins/ui/src/js/src/elements/UITable/UITableModel.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,30 @@ class UITableModel extends IrisGridModel {
402402
negativeColor = this.colorMap.get(negativeColor) ?? negativeColor;
403403
}
404404

405+
const barColor = value >= 0 ? positiveColor : negativeColor;
406+
const hasGradient = Array.isArray(barColor) && barColor.length > 1;
407+
const formatTextColor = this.getFormatOptionForCell(
408+
columnIndex,
409+
rowIndex,
410+
'color'
411+
);
412+
413+
let textColor: string;
414+
if (formatTextColor != null) {
415+
textColor = this.colorMap.get(formatTextColor) ?? formatTextColor;
416+
} else if (hasGradient) {
417+
textColor = value >= 0 ? barColor[barColor.length - 1] : barColor[0];
418+
} else {
419+
textColor = Array.isArray(barColor) ? barColor[0] : barColor;
420+
}
421+
405422
return {
406423
columnMin: minRowValue,
407424
columnMax: maxRowValue,
408425
axis,
409-
color: value >= 0 ? positiveColor : negativeColor,
426+
color: barColor,
427+
// @ts-expect-error TODO: bump web version
428+
textColor,
410429
valuePlacement,
411430
opacity,
412431
markers,

tests/app.d/ui_table.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,30 @@ def t_selection_component():
298298
),
299299
],
300300
)
301+
302+
t_databar_text_color = ui.table(
303+
_stocks,
304+
format_=[
305+
ui.TableFormat(
306+
cols="Size", color="red", mode=ui.TableDatabar(color="purple-800")
307+
),
308+
],
309+
)
310+
311+
t_databar_gradient_text_color = ui.table(
312+
_stocks,
313+
format_=[
314+
ui.TableFormat(
315+
cols="Size",
316+
color="orange",
317+
mode=ui.TableDatabar(color=["negative", "positive"]),
318+
),
319+
],
320+
)
321+
322+
t_databar_pos_neg_text_color = ui.table(
323+
_stocks,
324+
format_=[
325+
ui.TableFormat(cols="Random", color="info", mode=ui.TableDatabar()),
326+
],
327+
)

tests/ui_table.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ test.describe('UI table', () => {
2222
't_databar_priority',
2323
't_databar_mixed',
2424
't_databar_gradient',
25+
't_databar_text_color',
26+
't_databar_gradient_text_color',
27+
't_databar_pos_neg_text_color',
2528
].forEach(name => {
2629
test(name, async ({ page }) => {
2730
await gotoPage(page, '');
-3.27 KB
Loading
-3.94 KB
Loading
-3.4 KB
Loading
76 KB
Loading
127 KB
Loading
81 KB
Loading
-64 Bytes
Loading

0 commit comments

Comments
 (0)