Skip to content

Commit 1b7c126

Browse files
committed
add config option modeBarStyle, update logo
1 parent 9772ef6 commit 1b7c126

File tree

6 files changed

+87
-33
lines changed

6 files changed

+87
-33
lines changed

src/components/modebar/modebar.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ proto.update = function(graphInfo, buttons) {
5252
}
5353
else this.element.className = 'modebar';
5454

55+
if(context.modeBarStyle.orientation === 'v') {
56+
this.element.className += ' vertical';
57+
}
58+
this.element.style.backgroundColor = context.modeBarStyle.bgcolor;
59+
5560
// if buttons or logo have changed, redraw modebar interior
5661
var needsNewButtons = !this.hasButtons(buttons);
5762
var needsNewLogo = (this.hasLogo !== context.displaylogo);
@@ -62,7 +67,7 @@ proto.update = function(graphInfo, buttons) {
6267
if(needsNewButtons || needsNewLogo || needsNewLocale) {
6368
this.removeAllButtons();
6469

65-
this.updateButtons(buttons);
70+
this.updateButtons(buttons, context.modeBarStyle.iconColor);
6671

6772
if(context.displaylogo) {
6873
this.element.appendChild(this.getLogo());
@@ -73,7 +78,7 @@ proto.update = function(graphInfo, buttons) {
7378
this.updateActiveButton();
7479
};
7580

76-
proto.updateButtons = function(buttons) {
81+
proto.updateButtons = function(buttons, iconColor) {
7782
var _this = this;
7883

7984
this.buttons = buttons;
@@ -93,6 +98,7 @@ proto.updateButtons = function(buttons) {
9398
}
9499
_this.buttonsNames.push(buttonName);
95100

101+
buttonConfig.color = iconColor;
96102
var button = _this.createButton(buttonConfig);
97103
_this.buttonElements.push(button);
98104
group.appendChild(button);
@@ -157,6 +163,7 @@ proto.createButton = function(config) {
157163
if(config.toggle) d3.select(button).classed('active', true);
158164

159165
var icon = config.icon;
166+
if(config.color) icon.color = config.color;
160167
if(typeof icon === 'function') {
161168
button.appendChild(icon());
162169
}
@@ -173,31 +180,42 @@ proto.createButton = function(config) {
173180
* @Param {object} thisIcon
174181
* @Param {number} thisIcon.width
175182
* @Param {string} thisIcon.path
183+
* @Param {string} thisIcon.color
176184
* @Return {HTMLelement}
177185
*/
178186
proto.createIcon = function(thisIcon) {
179187
var iconHeight = isNumeric(thisIcon.height) ?
180188
Number(thisIcon.height) :
181189
thisIcon.ascent - thisIcon.descent,
182190
svgNS = 'http://www.w3.org/2000/svg',
183-
icon = document.createElementNS(svgNS, 'svg'),
184-
path = document.createElementNS(svgNS, 'path');
191+
icon = document.createElementNS(svgNS, 'svg');
185192

186193
icon.setAttribute('height', '1em');
187194
icon.setAttribute('width', (thisIcon.width / iconHeight) + 'em');
188195
icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));
189196

190-
path.setAttribute('d', thisIcon.path);
197+
if(thisIcon.path) {
198+
var path = document.createElementNS(svgNS, 'path');
199+
path.setAttribute('d', thisIcon.path);
191200

192-
if(thisIcon.transform) {
193-
path.setAttribute('transform', thisIcon.transform);
194-
}
195-
else if(thisIcon.ascent !== undefined) {
196-
// Legacy icon transform calculation
197-
path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');
201+
if(thisIcon.transform) {
202+
path.setAttribute('transform', thisIcon.transform);
203+
}
204+
else if(thisIcon.ascent !== undefined) {
205+
// Legacy icon transform calculation
206+
path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');
207+
}
208+
209+
if(thisIcon.color) {
210+
path.setAttribute('fill', thisIcon.color);
211+
}
212+
213+
icon.appendChild(path);
198214
}
199215

200-
icon.appendChild(path);
216+
if(thisIcon.svg) {
217+
icon.innerHTML = thisIcon.svg;
218+
}
201219

202220
return icon;
203221
};
@@ -272,7 +290,7 @@ proto.getLogo = function() {
272290
a.setAttribute('data-title', Lib._(this.graphInfo, 'Produced with Plotly'));
273291
a.className = 'modebar-btn plotlyjsicon modebar-btn--logo';
274292

275-
a.appendChild(this.createIcon(Icons.plotlylogo));
293+
a.appendChild(this.createIcon(Icons.newplotlylogo));
276294

277295
group.appendChild(a);
278296
return group;

src/css/_modebar.scss

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
top: 2px;
44
right: 2px;
55
z-index: 1001;
6-
background: rgba(255,255,255,0.7);
76
}
87

98
.modebar--hover {
@@ -23,13 +22,8 @@
2322
position: relative;
2423
vertical-align: middle;
2524
white-space: nowrap;
26-
27-
&:first-child {
28-
margin-left: 0px;
29-
}
3025
}
3126

32-
3327
.modebar-btn {
3428
position: relative;
3529
font-size: 16px;
@@ -43,20 +37,17 @@
4337
position: relative;
4438
top: 2px;
4539
}
40+
}
4641

47-
path {
48-
fill: rgba(0,31,95,0.3);
49-
}
50-
51-
&.active path, &:hover path {
52-
fill: rgba(0,22,72,0.5);
53-
}
54-
55-
&.modebar-btn--logo {
56-
padding: 3px 1px;
42+
.modebar.vertical {
43+
.modebar-group {
44+
display: block;
45+
float: none;
46+
margin: 0 auto;
5747

58-
path {
59-
fill: $color-brand-primary !important;
48+
.modebar-btn {
49+
display:block;
50+
text-align: center;
6051
}
6152
}
6253
}

src/fonts/ploticon/ploticon.svg

Lines changed: 14 additions & 0 deletions
Loading

src/plot_api/plot_api.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ function setPlotContext(gd, config) {
428428
keys = Object.keys(config);
429429
for(i = 0; i < keys.length; i++) {
430430
key = keys[i];
431-
if(key === 'editable' || key === 'edits') continue;
431+
if(key === 'editable' || key === 'edits' || key === 'modeBarStyle') continue;
432432
if(key in context) {
433433
if(key === 'setBackground' && config[key] === 'opaque') {
434434
context[key] = opaqueSetBackground;
@@ -465,6 +465,15 @@ function setPlotContext(gd, config) {
465465
}
466466
}
467467
}
468+
if(config.modeBarStyle) {
469+
keys = Object.keys(config.modeBarStyle);
470+
for(i = 0; i < keys.length; i++) {
471+
key = keys[i];
472+
if(key in context.modeBarStyle) {
473+
context.modeBarStyle[key] = config.modeBarStyle[key];
474+
}
475+
}
476+
}
468477
}
469478

470479
// staticPlot forces a bunch of others:

src/plot_api/plot_config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ module.exports = {
102102
// display the mode bar (true, false, or 'hover')
103103
displayModeBar: 'hover',
104104

105+
// mode bar style
106+
modeBarStyle: {
107+
orientation: 'h',
108+
bgcolor: 'rgba(255,255,255,0.7)',
109+
iconColor: 'rgba(0, 31, 95, 0.3)'
110+
},
111+
105112
/*
106113
* remove mode bar button by name
107114
* (see ../components/modebar/buttons.js for the list of names)

tasks/util/pull_font_svg.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs');
22
var xml2js = require('xml2js');
33

44
var parser = new xml2js.Parser();
5-
5+
var builder = new xml2js.Builder({ headless: true, rootName: 'g', renderOpts: {'newline': ''}});
66

77
module.exports = function pullFontSVG(data, pathOut) {
88
parser.parseString(data, function(err, result) {
@@ -28,6 +28,21 @@ module.exports = function pullFontSVG(data, pathOut) {
2828
};
2929
});
3030

31+
// Load SVG
32+
var svgs = result.svg.defs[0].g;
33+
svgs.forEach(function(g) {
34+
var name = g.$.id,
35+
width = parseFloat(g.$['data-width']),
36+
height = parseFloat(g.$['data-height']);
37+
delete g.$;
38+
chars[name] = {
39+
name: name,
40+
width: width,
41+
height: height,
42+
svg: builder.buildObject(g)
43+
};
44+
});
45+
3146
// turn remaining double quotes into single
3247
var charStr = JSON.stringify(chars, null, 4).replace(/\"/g, '\'');
3348

0 commit comments

Comments
 (0)