Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Misc perf improvements #1772

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

Merged
merged 14 commits into from
Jun 11, 2017
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
short-circuit title draw if there's no title
  • Loading branch information
alexcjohnson committed Jun 9, 2017
commit c02204f13f6508b26039ea14b54944d4352ff7c8
52 changes: 29 additions & 23 deletions 52 src/components/titles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Color = require('../color');
var svgTextUtils = require('../../lib/svg_text_utils');
var interactConstants = require('../../constants/interactions');

var PLACEHOLDER_RE = /Click to enter .+ title/;

var Titles = module.exports = {};

Expand Down Expand Up @@ -52,29 +53,34 @@ var Titles = module.exports = {};
* title, include here. Otherwise it will go in fullLayout._infolayer
*/
Titles.draw = function(gd, titleClass, options) {
var cont = options.propContainer,
prop = options.propName,
traceIndex = options.traceIndex,
name = options.dfltName,
avoid = options.avoid || {},
attributes = options.attributes,
transform = options.transform,
group = options.containerGroup,

fullLayout = gd._fullLayout,
font = cont.titlefont.family,
fontSize = cont.titlefont.size,
fontColor = cont.titlefont.color,

opacity = 1,
isplaceholder = false,
txt = cont.title.trim();
var cont = options.propContainer;
var prop = options.propName;
var traceIndex = options.traceIndex;
var name = options.dfltName;
var avoid = options.avoid || {};
var attributes = options.attributes;
var transform = options.transform;
var group = options.containerGroup;

var fullLayout = gd._fullLayout;
var font = cont.titlefont.family;
var fontSize = cont.titlefont.size;
var fontColor = cont.titlefont.color;

var opacity = 1;
var isplaceholder = false;
var txt = cont.title.trim();
var editable = gd._context.editable;

if(txt === '') opacity = 0;
if(txt.match(/Click to enter .+ title/)) {
if(txt.match(PLACEHOLDER_RE)) {
opacity = 0.2;
isplaceholder = true;
if(!editable) txt = '';
}

var elShouldExist = txt || editable;

if(!group) {
group = fullLayout._infolayer.selectAll('.g-' + titleClass)
.data([0]);
Expand All @@ -83,7 +89,7 @@ Titles.draw = function(gd, titleClass, options) {
}

var el = group.selectAll('text')
.data([0]);
.data(elShouldExist ? [0] : []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🍺

el.enter().append('text');
el.text(txt)
// this is hacky, but convertToTspans uses the class
Expand All @@ -92,6 +98,9 @@ Titles.draw = function(gd, titleClass, options) {
// correct one (only relevant for colorbars, at least
// for now) - ie don't use .classed
.attr('class', titleClass);
el.exit().remove();

if(!elShouldExist) return;

function titleLayout(titleEl) {
Lib.syncOrAsync([drawTitle, scootTitle], titleEl);
Expand Down Expand Up @@ -205,7 +214,7 @@ Titles.draw = function(gd, titleClass, options) {
});
}

if(gd._context.editable) {
if(editable) {
if(!txt) setPlaceholder();
else el.on('.opacity', null);

Expand All @@ -224,8 +233,5 @@ Titles.draw = function(gd, titleClass, options) {
.attr(attributes);
});
}
else if(!txt || txt.match(/Click to enter .+ title/)) {
el.remove();
}
el.classed('js-placeholder', isplaceholder);
};
Morty Proxy This is a proxified and sanitized view of the page, visit original site.