Skip to content

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
Show file tree
Hide file tree
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
27 changes: 10 additions & 17 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ dragElement.unhoverRaw = unhover.raw;

/**
* Abstracts click & drag interactions
*
* During the interaction, a "coverSlip" element - a transparent
* div covering the whole page - is created, which has two key effects:
* - Lets you drag beyond the boundaries of the plot itself without
* dropping (but if you drag all the way out of the browser window the
* interaction will end)
* - Freezes the cursor: whatever mouse cursor the drag element had when the
* interaction started gets copied to the coverSlip for use until mouseup
*
* @param {object} options with keys:
* element (required) the DOM element to drag
* prepFn (optional) function(event, startX, startY)
Expand All @@ -44,10 +53,6 @@ dragElement.unhoverRaw = unhover.raw;
* numClicks is how many clicks we've registered within
* a doubleclick time
* e is the original event
* setCursor (optional) function(event)
* executed on mousemove before mousedown
* the purpose of this callback is to update the mouse cursor before
* the click & drag interaction has been initiated
*/
dragElement.init = function init(options) {
var gd = options.gd,
Expand All @@ -57,15 +62,11 @@ dragElement.init = function init(options) {
startY,
newMouseDownTime,
dragCover,
initialTarget,
initialOnMouseMove;
Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing. Thanks for 🔪 that!

initialTarget;

if(!gd._mouseDownTime) gd._mouseDownTime = 0;

function onStart(e) {
// disable call to options.setCursor(evt)
options.element.onmousemove = initialOnMouseMove;

// make dragging and dragged into properties of gd
// so that others can look at and modify them
gd._dragged = false;
Expand Down Expand Up @@ -116,10 +117,6 @@ dragElement.init = function init(options) {
}

function onDone(e) {
// re-enable call to options.setCursor(evt)
initialOnMouseMove = options.element.onmousemove;
if(options.setCursor) options.element.onmousemove = options.setCursor;

dragCover.onmousemove = null;
dragCover.onmouseup = null;
dragCover.onmouseout = null;
Expand Down Expand Up @@ -166,10 +163,6 @@ dragElement.init = function init(options) {
return Lib.pauseEvent(e);
}

// enable call to options.setCursor(evt)
initialOnMouseMove = options.element.onmousemove;
if(options.setCursor) options.element.onmousemove = options.setCursor;

options.element.onmousedown = onStart;
options.element.style.pointerEvents = 'all';
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/shapes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
var xa, ya, x2p, y2p, p2x, p2y;

var dragOptions = {
setCursor: updateDragMode,
element: shapePath.node(),
gd: gd,
prepFn: startDrag,
Expand All @@ -141,6 +140,8 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {

dragElement.init(dragOptions);

shapePath.node().onmousemove = updateDragMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Referencing the ticket for annotation edits -> #679


function updateDragMode(evt) {
// choose 'move' or 'resize'
// based on initial position of cursor within the drag element
Expand Down
1 change: 0 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ Plotly.plot = function(gd, data, layout, config) {
drawFramework,
marginPushers,
marginPushersAgain,
initInteractions,
positionAndAutorange,
subroutines.layoutStyles,
drawAxes,
Expand Down