-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Vanishing titles #1351
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
Vanishing titles #1351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
module.exports = { | ||
/** | ||
* Timing information for interactive elements | ||
*/ | ||
SHOW_PLACEHOLDER: 100, | ||
HIDE_PLACEHOLDER: 1000 | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
var d3 = require('d3'); | ||
|
||
var Plotly = require('@lib/index'); | ||
var interactConstants = require('@src/constants/interactions'); | ||
|
||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var mouseEvent = require('../assets/mouse_event'); | ||
|
||
describe('editable titles', function() { | ||
'use strict'; | ||
|
||
var data = [{x: [1, 2, 3], y: [1, 2, 3]}]; | ||
|
||
var gd; | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
function checkTitle(letter, text, opacityOut, opacityIn) { | ||
var titleEl = d3.select('.' + letter + 'title'); | ||
expect(titleEl.text()).toBe(text); | ||
expect(+titleEl.style('opacity')).toBe(opacityOut); | ||
|
||
var bb = titleEl.node().getBoundingClientRect(), | ||
xCenter = (bb.left + bb.right) / 2, | ||
yCenter = (bb.top + bb.bottom) / 2, | ||
done, | ||
promise = new Promise(function(resolve) { done = resolve; }); | ||
|
||
mouseEvent('mouseover', xCenter, yCenter); | ||
setTimeout(function() { | ||
expect(+titleEl.style('opacity')).toBe(opacityIn); | ||
|
||
mouseEvent('mouseout', xCenter, yCenter); | ||
setTimeout(function() { | ||
expect(+titleEl.style('opacity')).toBe(opacityOut); | ||
done(); | ||
}, interactConstants.HIDE_PLACEHOLDER + 50); | ||
}, interactConstants.SHOW_PLACEHOLDER + 50); | ||
|
||
return promise; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely done. 🎉 If you're up for a challenge, you could try adding a test for title edits like I did here for legend/trace name edits. |
||
} | ||
|
||
function editTitle(letter, attr, text) { | ||
return new Promise(function(resolve) { | ||
gd.once('plotly_relayout', function(eventData) { | ||
expect(eventData[attr]).toEqual(text, [letter, attr, eventData]); | ||
setTimeout(resolve, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etpinard nice editing tests in finance! And good call to include a test like that here too. The only thing I did differently is this: put resolve in a short There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good eyes on that 0-second transition 🔬 |
||
}); | ||
|
||
var textNode = document.querySelector('.' + letter + 'title'); | ||
textNode.dispatchEvent(new window.MouseEvent('click')); | ||
|
||
var editNode = document.querySelector('.plugin-editable.editable'); | ||
editNode.dispatchEvent(new window.FocusEvent('focus')); | ||
editNode.textContent = text; | ||
editNode.dispatchEvent(new window.FocusEvent('focus')); | ||
editNode.dispatchEvent(new window.FocusEvent('blur')); | ||
}); | ||
} | ||
|
||
it('shows default titles semi-opaque with no hover effects', function(done) { | ||
Plotly.plot(gd, data, {}, {editable: true}) | ||
.then(function() { | ||
return Promise.all([ | ||
// Check all three titles in parallel. This only works because | ||
// we're using synthetic events, not a real mouse. It's a big | ||
// win though because the test takes 1.2 seconds with the | ||
// animations... | ||
checkTitle('x', 'Click to enter X axis title', 0.2, 0.2), | ||
checkTitle('y', 'Click to enter Y axis title', 0.2, 0.2), | ||
checkTitle('g', 'Click to enter Plot title', 0.2, 0.2) | ||
]); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('has hover effects for blank titles', function(done) { | ||
Plotly.plot(gd, data, { | ||
xaxis: {title: ''}, | ||
yaxis: {title: ''}, | ||
title: '' | ||
}, {editable: true}) | ||
.then(function() { | ||
return Promise.all([ | ||
checkTitle('x', 'Click to enter X axis title', 0, 1), | ||
checkTitle('y', 'Click to enter Y axis title', 0, 1), | ||
checkTitle('g', 'Click to enter Plot title', 0, 1) | ||
]); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('has no hover effects for titles that used to be blank', function(done) { | ||
Plotly.plot(gd, data, { | ||
xaxis: {title: ''}, | ||
yaxis: {title: ''}, | ||
title: '' | ||
}, {editable: true}) | ||
.then(function() { | ||
return editTitle('x', 'xaxis.title', 'XXX'); | ||
}) | ||
.then(function() { | ||
return editTitle('y', 'yaxis.title', 'YYY'); | ||
}) | ||
.then(function() { | ||
return editTitle('g', 'title', 'TTT'); | ||
}) | ||
.then(function() { | ||
return Promise.all([ | ||
checkTitle('x', 'XXX', 1, 1), | ||
checkTitle('y', 'YYY', 1, 1), | ||
checkTitle('g', 'TTT', 1, 1) | ||
]); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix is just this line. All the rest is cleanup and testing :)