Skip to content

Commit 2e17ff9

Browse files
committed
move color resolution to dataBar options
1 parent a0205f2 commit 2e17ff9

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/grid/src/DataBarCellRenderer.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,7 @@ class DataBarCellRenderer extends CellRenderer {
147147

148148
context.save();
149149
context.textAlign = textAlign;
150-
151-
// Use explicit text color if set.
152-
// Otherwise, fall back to the databar color for text.
153-
if (textColor != null) {
154-
context.fillStyle = textColor;
155-
} else if (hasGradient) {
156-
const color =
157-
value >= 0 ? dataBarColor[dataBarColor.length - 1] : dataBarColor[0];
158-
context.fillStyle = color;
159-
} else {
160-
context.fillStyle = Array.isArray(dataBarColor)
161-
? dataBarColor[0]
162-
: dataBarColor;
163-
}
150+
context.fillStyle = textColor;
164151
context.textBaseline = 'middle';
165152
context.font = theme.font;
166153

packages/grid/src/DataBarGridModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface DataBarOptions {
3535
columnMax: number;
3636
axis: AxisOption;
3737
color: GridColor | GridColor[];
38-
textColor?: GridColor;
38+
textColor: GridColor;
3939
valuePlacement: ValuePlacementOption;
4040
opacity: number;
4141
markers: Marker[];

packages/grid/src/MockDataBarGridModel.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,23 @@ class MockDataBarGridModel extends GridModel implements DataBarGridModel {
143143
const color = value >= 0 ? positiveColor : negativeColor;
144144
const markers = this.markers.get(column) ?? [];
145145

146+
const hasGradient = Array.isArray(color) && color.length > 1;
147+
let textColor: string;
148+
if (hasGradient) {
149+
textColor = value >= 0 ? color[color.length - 1] : color[0];
150+
} else if (Array.isArray(color)) {
151+
const [first] = color;
152+
textColor = first;
153+
} else {
154+
textColor = color;
155+
}
156+
146157
return {
147158
columnMin,
148159
columnMax,
149160
axis,
150161
color,
162+
textColor,
151163
valuePlacement,
152164
opacity,
153165
markers,

0 commit comments

Comments
 (0)