Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions packages/grid/src/DataBarGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface DataBarOptions {
columnMax: number;
axis: AxisOption;
color: GridColor | GridColor[];
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