Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modeBar styling #3068

Merged
merged 24 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1b7c126
add config option modeBarStyle, update logo
antoinerg Oct 2, 2018
947eaf2
fix margins and alignments of modeBar buttons
antoinerg Oct 2, 2018
212612b
specify default style in modebar tests
antoinerg Oct 2, 2018
3795223
increase sizeo of plot.ly logo
antoinerg Oct 2, 2018
e870e34
fix rendering of logo in IE
antoinerg Oct 2, 2018
a4d3948
fix no-multiple-empty-lines
antoinerg Oct 2, 2018
61d1c7b
slurp entire SVG, uses DOMParser instead of innerHTML
antoinerg Oct 2, 2018
1d4ac7e
add build artefact for icons
antoinerg Oct 2, 2018
ff9d801
move plot.ly logo on top for vertical modebar
antoinerg Oct 3, 2018
397a6de
move modeBarStyle from config to layout options
antoinerg Oct 3, 2018
baeb1bc
update modebar tests with modeBarStyle in layout instead of config
antoinerg Oct 3, 2018
254f158
set proper editType on layout attribute modeBar
antoinerg Oct 3, 2018
f9e8777
modeBarStyle managed in css, new layout attribute activeIconColor
antoinerg Oct 3, 2018
fc47c72
remove 🐫 in modebar layout attributes
antoinerg Oct 3, 2018
0046f12
more robust test for modeBar.destroy
antoinerg Oct 4, 2018
b7c2355
place tooltips on the left of vertical modebars
antoinerg Oct 4, 2018
31d6fb2
in modebar plotly logo has same position in both orientations (v|h)
antoinerg Oct 4, 2018
97f25e2
fix to change modebar style on relayout
antoinerg Oct 4, 2018
dc7877b
trim whitespace in plotly logo's svg
antoinerg Oct 4, 2018
f5cc0e9
🔒 down modebar styling option
antoinerg Oct 4, 2018
452f9bc
by default modebar colors contrasts with paper_bgcolor
antoinerg Oct 5, 2018
266d63b
fix default modebar colors
antoinerg Oct 5, 2018
ff3f9f6
improve default modebar colors
antoinerg Oct 5, 2018
db9edd1
improve default modebar color
antoinerg Oct 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
var Icons = require('../../../build/ploticon');

var Parser = new DOMParser();

/**
* UI controller for interactive plots
Expand Down Expand Up @@ -52,6 +52,11 @@ proto.update = function(graphInfo, buttons) {
}
else this.element.className = 'modebar';

if(context.modeBarStyle.orientation === 'v') {
this.element.className += ' vertical';
}
this.element.style.backgroundColor = context.modeBarStyle.bgcolor;

// if buttons or logo have changed, redraw modebar interior
var needsNewButtons = !this.hasButtons(buttons);
var needsNewLogo = (this.hasLogo !== context.displaylogo);
Expand All @@ -62,7 +67,7 @@ proto.update = function(graphInfo, buttons) {
if(needsNewButtons || needsNewLogo || needsNewLocale) {
this.removeAllButtons();

this.updateButtons(buttons);
this.updateButtons(buttons, context.modeBarStyle.iconColor);

if(context.displaylogo) {
this.element.appendChild(this.getLogo());
Expand All @@ -73,7 +78,7 @@ proto.update = function(graphInfo, buttons) {
this.updateActiveButton();
};

proto.updateButtons = function(buttons) {
proto.updateButtons = function(buttons, iconColor) {
var _this = this;

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

buttonConfig.color = iconColor;
var button = _this.createButton(buttonConfig);
_this.buttonElements.push(button);
group.appendChild(button);
Expand Down Expand Up @@ -161,6 +167,7 @@ proto.createButton = function(config) {
button.appendChild(icon());
}
else {
if(icon) icon.color = config.color;
button.appendChild(this.createIcon(icon || Icons.question));
}
button.setAttribute('data-gravity', config.gravity || 'n');
Expand All @@ -173,31 +180,45 @@ proto.createButton = function(config) {
* @Param {object} thisIcon
* @Param {number} thisIcon.width
* @Param {string} thisIcon.path
* @Param {string} thisIcon.color
* @Return {HTMLelement}
*/
proto.createIcon = function(thisIcon) {
var iconHeight = isNumeric(thisIcon.height) ?
Number(thisIcon.height) :
thisIcon.ascent - thisIcon.descent,
svgNS = 'http://www.w3.org/2000/svg',
icon = document.createElementNS(svgNS, 'svg'),
path = document.createElementNS(svgNS, 'path');
icon;

icon.setAttribute('height', '1em');
icon.setAttribute('width', (thisIcon.width / iconHeight) + 'em');
icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));
if(thisIcon.path) {
icon = document.createElementNS(svgNS, 'svg');
icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));

path.setAttribute('d', thisIcon.path);
var path = document.createElementNS(svgNS, 'path');
path.setAttribute('d', thisIcon.path);

if(thisIcon.transform) {
path.setAttribute('transform', thisIcon.transform);
if(thisIcon.transform) {
path.setAttribute('transform', thisIcon.transform);
}
else if(thisIcon.ascent !== undefined) {
// Legacy icon transform calculation
path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');
}

if(thisIcon.color) {
path.setAttribute('fill', thisIcon.color);
}

icon.appendChild(path);
}
else if(thisIcon.ascent !== undefined) {
// Legacy icon transform calculation
path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');

if(thisIcon.svg) {
var svgDoc = Parser.parseFromString(thisIcon.svg, 'application/xml');
icon = svgDoc.childNodes[0];
}

icon.appendChild(path);
icon.setAttribute('height', '1em');
icon.setAttribute('width', '1em');

return icon;
};
Expand Down Expand Up @@ -272,7 +293,7 @@ proto.getLogo = function() {
a.setAttribute('data-title', Lib._(this.graphInfo, 'Produced with Plotly'));
a.className = 'modebar-btn plotlyjsicon modebar-btn--logo';

a.appendChild(this.createIcon(Icons.plotlylogo));
a.appendChild(this.createIcon(Icons.newplotlylogo));

group.appendChild(a);
return group;
Expand Down
29 changes: 13 additions & 16 deletions src/css/_modebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
top: 2px;
right: 2px;
z-index: 1001;
background: rgba(255,255,255,0.7);
}

.modebar--hover {
Expand All @@ -23,17 +22,13 @@
position: relative;
vertical-align: middle;
white-space: nowrap;

&:first-child {
margin-left: 0px;
}
}


.modebar-btn {
position: relative;
font-size: 16px;
padding: 3px 4px;
height: 22px;
/* display: inline-block; including this breaks 3d interaction in .embed mode. Chrome bug? */
cursor: pointer;
line-height: normal;
Expand All @@ -44,19 +39,21 @@
top: 2px;
}

path {
fill: rgba(0,31,95,0.3);
}

&.active path, &:hover path {
fill: rgba(0,22,72,0.5);
&.modebar-btn--logo {
font-size: 20px;
}
}

&.modebar-btn--logo {
padding: 3px 1px;
.modebar.vertical {
.modebar-group {
display: block;
float: none;
margin-left: 0px;
margin-top: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peek 2018-10-04 13-41

Looks like the vertical orientation has more top margin than the what the horizontal orientation has to its right.

Is this on purpose? This is just something I noticed, I don't have a strong opinion on what this should look like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 👀 ! No, it's not on purpose. I'd rather have the logo at the top. Fixing this right now!


path {
fill: $color-brand-primary !important;
.modebar-btn {
display:block;
text-align: center;
}
}
}
36 changes: 34 additions & 2 deletions src/fonts/ploticon/ploticon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function setPlotContext(gd, config) {
keys = Object.keys(config);
for(i = 0; i < keys.length; i++) {
key = keys[i];
if(key === 'editable' || key === 'edits') continue;
if(key === 'editable' || key === 'edits' || key === 'modeBarStyle') continue;
if(key in context) {
if(key === 'setBackground' && config[key] === 'opaque') {
context[key] = opaqueSetBackground;
Expand Down Expand Up @@ -465,6 +465,15 @@ function setPlotContext(gd, config) {
}
}
}
if(config.modeBarStyle) {
keys = Object.keys(config.modeBarStyle);
for(i = 0; i < keys.length; i++) {
key = keys[i];
if(key in context.modeBarStyle) {
context.modeBarStyle[key] = config.modeBarStyle[key];
}
}
}
}

// staticPlot forces a bunch of others:
Expand Down
7 changes: 7 additions & 0 deletions src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ module.exports = {
// display the mode bar (true, false, or 'hover')
displayModeBar: 'hover',

// mode bar style
modeBarStyle: {
orientation: 'h',
bgcolor: 'rgba(255,255,255,0.7)',
iconColor: 'rgba(0, 31, 95, 0.3)'
},

/*
* remove mode bar button by name
* (see ../components/modebar/buttons.js for the list of names)
Expand Down
13 changes: 12 additions & 1 deletion tasks/util/pull_font_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');
var xml2js = require('xml2js');

var parser = new xml2js.Parser();

var builder = new xml2js.Builder({ headless: true, rootName: 'svg', renderOpts: {'newline': ''}});

module.exports = function pullFontSVG(data, pathOut) {
parser.parseString(data, function(err, result) {
Expand All @@ -28,6 +28,17 @@ module.exports = function pullFontSVG(data, pathOut) {
};
});

// Load SVG
var svgs = result.svg.defs[0].svg;
svgs.forEach(function(svg) {
var name = svg.$.id;
delete svg.$.id;
chars[name] = {
name: name,
svg: builder.buildObject(svg)
};
});

// turn remaining double quotes into single
var charStr = JSON.stringify(chars, null, 4).replace(/\"/g, '\'');

Expand Down
5 changes: 5 additions & 0 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ describe('ModeBar', function() {
_context: {
displaylogo: true,
displayModeBar: true,
modeBarStyle: {
orientation: 'h',
bgcolor: 'rgba(255,255,255,0.7)',
iconColor: 'rgba(0, 31, 95, 0.3)'
},
modeBarButtonsToRemove: [],
modeBarButtonsToAdd: [],
locale: 'en',
Expand Down