Skip to content

Commit 8c198a1

Browse files
committed
ENH: Background color matches JupyterLab theme color
1 parent ccf349c commit 8c198a1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

examples/3DImage.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 3,
44+
"execution_count": 4,
4545
"metadata": {},
4646
"outputs": [
4747
{
4848
"data": {
4949
"application/vnd.jupyter.widget-view+json": {
50-
"model_id": "07a7f605229a4f8aa85ccd388ea88d47",
50+
"model_id": "128f87def74b440baed35bb99b28198a",
5151
"version_major": 2,
5252
"version_minor": 0
5353
},
@@ -63,6 +63,13 @@
6363
"image = itk.imread(file_name)\n",
6464
"view(image, rotate=True, vmin=4000, vmax=17000, gradient_opacity=0.4)"
6565
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"metadata": {},
71+
"outputs": [],
72+
"source": []
6673
}
6774
],
6875
"metadata": {

js/lib/viewer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,19 @@ const createRenderingPipeline = (domWidgetView, { rendered_image, point_sets, ge
127127
overflow: 'hidden',
128128
display: 'block-inline'
129129
};
130+
let backgroundColor = [1.0, 1.0, 1.0];
131+
const bodyBackground = getComputedStyle(document.body).getPropertyValue('background-color');
132+
if (!!bodyBackground) {
133+
// Separator can be , or space
134+
const sep = bodyBackground.indexOf(",") > -1 ? "," : " ";
135+
// Turn "rgb(r,g,b)" into [r,g,b]
136+
const rgb = bodyBackground.substr(4).split(")")[0].split(sep);
137+
backgroundColor[0] = rgb[0] / 255.0;
138+
backgroundColor[1] = rgb[1] / 255.0;
139+
backgroundColor[2] = rgb[2] / 255.0;
140+
}
130141
const viewerStyle = {
131-
backgroundColor: [1.0, 1.0, 1.0],
142+
backgroundColor,
132143
containerStyle: containerStyle,
133144
};
134145
let is3D = true

0 commit comments

Comments
 (0)