Skip to content

Commit 953e850

Browse files
committed
Use display: block for canvas elements and fix layout issues.
1 parent 903075d commit 953e850

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

js/src/mpl_widget.css

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
.ipympl_widget {
1+
.jupyter-matplotlib {
22
height: 500px;
3+
flex: 1 1 auto;
34
}
45

5-
.ipympl_button {
6+
/* Toolbar */
7+
8+
.jupyter-matplotlib-button {
69
width: 34px; /* calc(var(--jp-widgets-inline-width-tiny) / 2 - 2px) */
710
padding: 0;
811
}
912

10-
.ipympl_figure {
13+
/* Figure */
14+
15+
.jupyter-matplotlib-figure {
1116
width: 100%;
1217
height: 100%;
1318
}
1419

15-
.ipympl_canvas_div {
20+
.jupyter-matplotlib-canvas_div {
1621
margin: 2px;
17-
flex-grow: 1; /* Take all the remaining space after the header and footer is displayed */
18-
overflow: hidden;
22+
flex: 1 1 auto;
23+
}
24+
25+
.jupyter-matplotlib-canvas_div:focus {
26+
outline: 1px solid; /* 1px solid var(--jp-widgets-input-focus-border-color); */
1927
}

js/src/mpl_widget.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
3838

3939
this.figure = document.createElement('div');
4040
this.figure.addEventListener('remove', this.close.bind(this));
41-
this.figure.classList = 'ipympl_figure jupyter-widgets widget-container widget-box widget-vbox';
42-
this.el.appendChild(this.figure);
41+
this.figure.classList = 'jupyter-matplotlib-figure jupyter-widgets widget-container widget-box widget-vbox';
4342

4443
this._init_header();
4544
this._init_canvas();
@@ -87,7 +86,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
8786
update_toolbar_position: function() {
8887
var toolbar_position = this.model.get('toolbar_position');
8988
if (toolbar_position == 'top' || toolbar_position == 'bottom') {
90-
this.el.classList = 'jupyter-widgets widget-container widget-box widget-vbox ipympl_widget';
89+
this.el.classList = 'jupyter-widgets widget-container widget-box widget-vbox jupyter-matplotlib';
9190
this.model.get('toolbar').set('orientation', 'horizontal');
9291

9392
this.clear();
@@ -100,7 +99,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
10099
this.el.appendChild(this.toolbar_view.el);
101100
}
102101
} else {
103-
this.el.classList = 'jupyter-widgets widget-container widget-box widget-hbox ipympl_widget';
102+
this.el.classList = 'jupyter-widgets widget-container widget-box widget-hbox jupyter-matplotlib';
104103
this.model.get('toolbar').set('orientation', 'vertical');
105104

106105
this.clear();
@@ -132,7 +131,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
132131
var canvas_div = this.canvas_div = document.createElement('div');
133132
canvas_div.style.position = 'relative';
134133
canvas_div.style.clear = 'both';
135-
canvas_div.classList = 'jupyter-widgets ipympl_canvas_div';
134+
canvas_div.classList = 'jupyter-widgets jupyter-matplotlib-canvas_div';
136135

137136
canvas_div.addEventListener('keydown', this.key_event('key_press'));
138137
canvas_div.addEventListener('keyup', this.key_event('key_release'));
@@ -141,6 +140,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
141140
this.figure.appendChild(canvas_div);
142141

143142
var canvas = this.canvas = document.createElement('canvas');
143+
canvas.style.display = 'block';
144144
canvas.style.left = 0;
145145
canvas.style.top = 0;
146146
canvas.style.zIndex = 0;
@@ -157,6 +157,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
157157
this.ratio = (window.devicePixelRatio || 1) / backingStore;
158158

159159
var rubberband_canvas = this.rubberband_canvas = document.createElement('canvas');
160+
rubberband_canvas.style.display = 'block';
160161
rubberband_canvas.style.position = 'absolute';
161162
rubberband_canvas.style.left = 0;
162163
rubberband_canvas.style.top = 0;

js/src/toolbar_widget.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ var ToolbarModel = widgets.DOMWidgetModel.extend({
2121

2222
var ToolbarView = widgets.DOMWidgetView.extend({
2323
render: function() {
24+
this.el.classList = 'jupyter-widgets jupyter-matplotlib-toolbar';
25+
this.el.classList.add('widget-container', 'widget-box');
2426
this.create_toolbar();
25-
26-
this.el.appendChild(this.toolbar_container);
27-
2827
this.model_events();
2928
},
3029

@@ -33,11 +32,9 @@ var ToolbarView = widgets.DOMWidgetView.extend({
3332

3433
this.current_action = '';
3534

36-
this.toolbar_container = document.createElement('div');
37-
this.toolbar_container.classList = this.get_container_class();
3835
this.toggle_button = document.createElement('button');
3936

40-
this.toggle_button.classList = 'ipympl_button jupyter-widgets jupyter-button';
37+
this.toggle_button.classList = 'jupyter-matplotlib-button jupyter-widgets jupyter-button';
4138
this.toggle_button.setAttribute('href', '#');
4239
this.toggle_button.setAttribute('title', 'Toggle Interaction');
4340
this.toggle_button.style.outline = 'none';
@@ -47,12 +44,10 @@ var ToolbarView = widgets.DOMWidgetView.extend({
4744
icon.classList = 'center fa fa-bars';
4845
this.toggle_button.appendChild(icon);
4946

50-
this.toolbar_container.appendChild(this.toggle_button);
51-
47+
this.el.appendChild(this.toggle_button);
5248
this.toolbar = document.createElement('div');
53-
this.toolbar.classList = this.get_container_class();
54-
this.toolbar_container.appendChild(this.toolbar);
55-
49+
this.toolbar.classList = 'widget-container widget-box';
50+
this.el.appendChild(this.toolbar);
5651
this.buttons = [this.toggle_button];
5752

5853
for(var toolbar_ind in toolbar_items) {
@@ -63,7 +58,7 @@ var ToolbarView = widgets.DOMWidgetView.extend({
6358
if (!name) { continue; };
6459

6560
var button = document.createElement('button');
66-
button.classList = 'ipympl_button jupyter-widgets jupyter-button';
61+
button.classList = 'jupyter-matplotlib-button jupyter-widgets jupyter-button';
6762
button.setAttribute('href', '#');
6863
button.setAttribute('title', tooltip);
6964
button.style.outline = 'none';
@@ -78,15 +73,19 @@ var ToolbarView = widgets.DOMWidgetView.extend({
7873
this.toolbar.appendChild(button);
7974
}
8075

76+
this.set_orientation(this.el);
77+
this.set_orientation(this.toolbar);
8178
this.set_buttons_style();
8279
},
8380

84-
get_container_class: function() {
81+
set_orientation: function(el) {
8582
var orientation = this.model.get('orientation');
8683
if (orientation == 'vertical') {
87-
return 'jupyter-widgets widget-container widget-box widget-vbox';
84+
el.classList.remove('widget-hbox');
85+
el.classList.add('widget-vbox');
8886
} else {
89-
return 'jupyter-widgets widget-container widget-box widget-hbox';
87+
el.classList.add('widget-hbox');
88+
el.classList.remove('widget-vbox');
9089
}
9190
},
9291

@@ -159,8 +158,8 @@ var ToolbarView = widgets.DOMWidgetView.extend({
159158
},
160159

161160
update_orientation: function() {
162-
this.toolbar_container.classList = this.get_container_class();
163-
this.toolbar.classList = this.get_container_class();
161+
this.set_orientation(this.el);
162+
this.set_orientation(this.toolbar);
164163
}
165164
});
166165

0 commit comments

Comments
 (0)