Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/grid/src/DataBarCellRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class DataBarCellRenderer extends CellRenderer {
columnMax,
axis,
color: dataBarColor,
textColor,
valuePlacement,
opacity,
markers,
Expand All @@ -146,15 +147,7 @@ class DataBarCellRenderer extends CellRenderer {

context.save();
context.textAlign = textAlign;
if (hasGradient) {
const color =
value >= 0 ? dataBarColor[dataBarColor.length - 1] : dataBarColor[0];
context.fillStyle = color;
} else {
context.fillStyle = Array.isArray(dataBarColor)
? dataBarColor[0]
: dataBarColor;
}
context.fillStyle = textColor;
context.textBaseline = 'middle';
context.font = theme.font;

Expand Down Expand Up @@ -230,6 +223,10 @@ class DataBarCellRenderer extends CellRenderer {
context.restore(); // Restore gradient translate/scale
} else {
// Draw normal bar
const barColor = Array.isArray(dataBarColor)
? dataBarColor[0]
: dataBarColor;
context.fillStyle = barColor;
context.beginPath();
context.roundRect(dataBarX, dataBarY, dataBarWidth, rowHeight, 1);
context.fill();
Expand Down
6 changes: 6 additions & 0 deletions packages/grid/src/DataBarGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export interface DataBarOptions {
columnMax: number;
axis: AxisOption;
color: GridColor | GridColor[];
/**
* The text color for the cell, resolved from format rules/bar color.
* If the user has explicitly set a text color via formatting, that color is used.
* Otherwise it defaults to the databar's bar color.
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just be "the text color for the cell". How it is derived is not determined from within this context.
If we took an optional textColor here and fell back to the color, we could say that. But this behaviour documented here is not accurate from this context.
And then the color attribute should have a doc string for "Color of the databar", maybe explain how you can pass a gradient.

textColor: GridColor;
valuePlacement: ValuePlacementOption;
opacity: number;
markers: Marker[];
Expand Down
9 changes: 9 additions & 0 deletions packages/grid/src/MockDataBarGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,20 @@ class MockDataBarGridModel extends GridModel implements DataBarGridModel {
const color = value >= 0 ? positiveColor : negativeColor;
const markers = this.markers.get(column) ?? [];

const hasGradient = Array.isArray(color) && color.length > 1;
let textColor: string;
if (hasGradient) {
textColor = value >= 0 ? color[color.length - 1] : color[0];
} else {
textColor = Array.isArray(color) ? color[0] : color;
}

return {
columnMin,
columnMax,
axis,
color,
textColor,
valuePlacement,
opacity,
markers,
Expand Down
Loading