Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8841db

Browse files
committed
Implement spacers in nbagg toolbar.
For nbAgg, encapsulate buttons in a button group, and create new groups whenever we encounter a spacer. Change the toolbar's style to use Bootstrap.
1 parent 4b182e2 commit d8841db

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/matplotlib/backends/web_backend/js/nbagg_mpl.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mpl.figure.prototype._init_toolbar = function () {
9494
var fig = this;
9595

9696
var toolbar = document.createElement('div');
97-
toolbar.setAttribute('style', 'width: 100%');
97+
toolbar.classList = 'btn-toolbar';
9898
this.root.appendChild(toolbar);
9999

100100
function on_click_closure(name) {
@@ -109,6 +109,8 @@ mpl.figure.prototype._init_toolbar = function () {
109109
};
110110
}
111111

112+
var buttonGroup = document.createElement('div');
113+
buttonGroup.classList = 'btn-group';
112114
var button;
113115
for (var toolbar_ind in mpl.toolbar_items) {
114116
var name = mpl.toolbar_items[toolbar_ind][0];
@@ -117,6 +119,12 @@ mpl.figure.prototype._init_toolbar = function () {
117119
var method_name = mpl.toolbar_items[toolbar_ind][3];
118120

119121
if (!name) {
122+
/* Instead of a spacer, we start a new button group. */
123+
if (buttonGroup.hasChildNodes()) {
124+
toolbar.appendChild(buttonGroup);
125+
}
126+
buttonGroup = document.createElement('div');
127+
buttonGroup.classList = 'btn-group';
120128
continue;
121129
}
122130

@@ -127,13 +135,16 @@ mpl.figure.prototype._init_toolbar = function () {
127135
button.innerHTML = '<i class="fa ' + image + ' fa-lg"></i>';
128136
button.addEventListener('click', on_click_closure(method_name));
129137
button.addEventListener('mouseover', on_mouseover_closure(tooltip));
130-
toolbar.appendChild(button);
138+
buttonGroup.appendChild(button);
139+
}
140+
141+
if (buttonGroup.hasChildNodes()) {
142+
toolbar.appendChild(buttonGroup);
131143
}
132144

133145
// Add the status bar.
134146
var status_bar = document.createElement('span');
135-
status_bar.classList = 'mpl-message';
136-
status_bar.setAttribute('style', 'text-align:right; float: right;');
147+
status_bar.classList = 'mpl-message pull-right';
137148
toolbar.appendChild(status_bar);
138149
this.message = status_bar;
139150

0 commit comments

Comments
 (0)