Skip to content

Commit 908fc81

Browse files
authored
Merge pull request #254 from jpmorganchase/hypergrid-css
Added positive/negative color & font to Hypergrid CSS style
2 parents 2b249e2 + c6fbfec commit 908fc81

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

packages/perspective-viewer-hypergrid/src/html/hypergrid.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<tr class='hover'>
1818
<td class='hover'></td>
1919
</tr>
20+
<tr>
21+
<td class='positive'></td>
22+
<td class='negative'></td>
23+
</tr>
2024
</table>
2125
</div>
2226
<div id='gridWrapper'>

packages/perspective-viewer-hypergrid/src/js/PerspectiveDataModel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ function cellStyle(gridCellConfig) {
162162
} else if (isNaN(gridCellConfig.value)) {
163163
gridCellConfig.value = "-";
164164
} else {
165-
gridCellConfig.color =
166-
gridCellConfig.value >= 0 ? gridCellConfig.columnHeaderBackgroundNumberPositive || "rgb(160,207,255)" : gridCellConfig.columnHeaderBackgroundNumberNegative || "rgb(255,136,136)";
165+
if (gridCellConfig.value > 0) {
166+
gridCellConfig.color = gridCellConfig.columnColorNumberPositive || "rgb(160,207,255)";
167+
gridCellConfig.backgroundColor = gridCellConfig.columnBackgroundColorNumberPositive ? gridCellConfig.columnBackgroundColorNumberPositive : gridCellConfig.backgroundColor;
168+
} else {
169+
gridCellConfig.color = gridCellConfig.columnColorNumberNegative || "rgb(255,136,136)";
170+
gridCellConfig.backgroundColor = gridCellConfig.columnBackgroundColorNumberNegative ? gridCellConfig.columnBackgroundColorNumberNegative : gridCellConfig.backgroundColor;
171+
}
167172
}
168173
} else if (type === "boolean") {
169174
gridCellConfig.value = String(gridCellConfig.value);

packages/perspective-viewer-hypergrid/src/js/hypergrid.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ const light_theme_overrides = {
101101
columnHeaderBackgroundColor: "#fff",
102102
columnHeaderForegroundSelectionColor: "#333",
103103
columnHeaderBackgroundSelectionColor: "#40536d",
104-
columnHeaderBackgroundNumberPositive: "#1078d1",
105-
columnHeaderBackgroundNumberNegative: "#de3838",
106104
rowHeaderForegroundSelectionFont: "12px Arial, Helvetica, sans-serif",
107105
treeHeaderColor: "#666",
108106
treeHeaderBackgroundColor: "#fff",
@@ -192,6 +190,9 @@ bindTemplate(TEMPLATE)(
192190
const header = window.getComputedStyle(this.querySelector("th"), null);
193191
const row_hover = window.getComputedStyle(this.querySelector("tr.hover"), null);
194192
const cell_hover = window.getComputedStyle(this.querySelector("td.hover"), null);
193+
const cell_positive = window.getComputedStyle(this.querySelector("td.positive"), null);
194+
const cell_negative = window.getComputedStyle(this.querySelector("td.negative"), null);
195+
const table = window.getComputedStyle(this.querySelector("table"));
195196

196197
grid_properties["showRowNumbers"] = grid_properties["showCheckboxes"] || grid_properties["showRowNumbers"];
197198
grid_properties["treeHeaderBackgroundColor"] = grid_properties["backgroundColor"] = style.getPropertyValue("background-color");
@@ -200,6 +201,19 @@ bindTemplate(TEMPLATE)(
200201
grid_properties["columnHeaderSeparatorColor"] = header.getPropertyValue("border-color");
201202
grid_properties["columnHeaderColor"] = header.getPropertyValue("color");
202203

204+
grid_properties["columnColorNumberPositive"] = cell_positive.getPropertyValue("color");
205+
grid_properties["columnColorNumberNegative"] = cell_negative.getPropertyValue("color");
206+
grid_properties["columnBackgroundColorNumberPositive"] = cell_positive.getPropertyValue("background-color");
207+
grid_properties["columnBackgroundColorNumberNegative"] = cell_negative.getPropertyValue("background-color");
208+
209+
const font = `${table.getPropertyValue("font-size")} ${table.getPropertyValue("font-family")}`;
210+
const headerfont = `${header.getPropertyValue("font-size")} ${header.getPropertyValue("font-family")}`;
211+
212+
grid_properties["columnHeaderFont"] = headerfont;
213+
grid_properties["font"] = font;
214+
grid_properties["rowHeaderFont"] = font;
215+
grid_properties["treeHeaderFont"] = font;
216+
203217
grid_properties["hoverRowHighlight"]["backgroundColor"] = row_hover.getPropertyValue("background-color");
204218
grid_properties["hoverRowHighlight"]["color"] = row_hover.getPropertyValue("color");
205219
grid_properties["hoverCellHighlight"]["backgroundColor"] = cell_hover.getPropertyValue("background-color");

packages/perspective-viewer-hypergrid/src/less/hypergrid.less

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ perspective-hypergrid {
1111
position: relative;
1212
color: #666;
1313

14+
table {
15+
font: 12px "open sans", helvetica, sans-serif;
16+
}
17+
1418
td.hover {
1519
background-color: #eeeeee;
1620
}
@@ -19,6 +23,14 @@ perspective-hypergrid {
1923
background-color: #f6f6f6;
2024
}
2125

26+
td.positive {
27+
color: #1078d1;
28+
}
29+
30+
td.negative {
31+
color: #de3838;
32+
}
33+
2234
#app perspective-hypergrid {
2335
position: absolute;
2436
}

0 commit comments

Comments
 (0)