Skip to content

Commit 8b602e4

Browse files
committed
factor UndoManager out of plotly_util.js into polar/utils/
1 parent ca0c99d commit 8b602e4

File tree

3 files changed

+60
-54
lines changed

3 files changed

+60
-54
lines changed

shelly/plotlyjs/static/plotlyjs/src/plotly_util.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -568,55 +568,3 @@ util.deepExtend = function(destination, source) {
568568
}
569569
return destination;
570570
};
571-
572-
573-
//Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager
574-
//Copyright (c) 2010-2013 Arthur Clemens, [email protected]
575-
util.UndoManager = function(){
576-
var undoCommands = [],
577-
index = -1,
578-
isExecuting = false,
579-
callback;
580-
function execute(command, action){
581-
if(!command) return this;
582-
isExecuting = true;
583-
command[action]();
584-
isExecuting = false;
585-
return this;
586-
}
587-
return {
588-
add: function(command){
589-
if(isExecuting) return this;
590-
undoCommands.splice(index + 1, undoCommands.length - index);
591-
undoCommands.push(command);
592-
index = undoCommands.length - 1;
593-
return this;
594-
},
595-
setCallback: function(callbackFunc){ callback = callbackFunc; },
596-
undo: function(){
597-
var command = undoCommands[index];
598-
if(!command) return this;
599-
execute(command, 'undo');
600-
index -= 1;
601-
if(callback) callback(command.undo);
602-
return this;
603-
},
604-
redo: function(){
605-
var command = undoCommands[index + 1];
606-
if(!command) return this;
607-
execute(command, 'redo');
608-
index += 1;
609-
if(callback) callback(command.redo);
610-
return this;
611-
},
612-
clear: function(){
613-
undoCommands = [];
614-
index = -1;
615-
},
616-
hasUndo: function(){ return index !== -1; },
617-
hasRedo: function(){ return index < (undoCommands.length - 1); },
618-
getCommands: function(){ return undoCommands; },
619-
getPreviousCommand: function(){ return undoCommands[index-1]; },
620-
getIndex: function(){ return index; }
621-
};
622-
};

shelly/plotlyjs/static/plotlyjs/src/polar/micropolar_manager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
/* global d3:false */
44

55
var manager = module.exports = {},
6-
Plotly = require('../plotly');
6+
Plotly = require('../plotly'),
7+
UndoManager = require('./utils/undo_manager');
78

89
manager.framework = function(_gd){
910
var config, previousConfigClone, plot, convertedInput, container;
10-
var undoManager = new Plotly.util.UndoManager();
11+
var undoManager = new UndoManager();
12+
1113
function exports(_inputConfig, _container){
1214
if(_container) container = _container;
1315
d3.select(d3.select(container).node().parentNode).selectAll('.svg-container>*:not(.chart-root)').remove();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
//Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager
4+
//Copyright (c) 2010-2013 Arthur Clemens, [email protected]
5+
module.exports = function UndoManager() {
6+
var undoCommands = [],
7+
index = -1,
8+
isExecuting = false,
9+
callback;
10+
11+
function execute(command, action){
12+
if(!command) return this;
13+
14+
isExecuting = true;
15+
command[action]();
16+
isExecuting = false;
17+
18+
return this;
19+
}
20+
21+
return {
22+
add: function(command){
23+
if(isExecuting) return this;
24+
undoCommands.splice(index + 1, undoCommands.length - index);
25+
undoCommands.push(command);
26+
index = undoCommands.length - 1;
27+
return this;
28+
},
29+
setCallback: function(callbackFunc){ callback = callbackFunc; },
30+
undo: function(){
31+
var command = undoCommands[index];
32+
if(!command) return this;
33+
execute(command, 'undo');
34+
index -= 1;
35+
if(callback) callback(command.undo);
36+
return this;
37+
},
38+
redo: function(){
39+
var command = undoCommands[index + 1];
40+
if(!command) return this;
41+
execute(command, 'redo');
42+
index += 1;
43+
if(callback) callback(command.redo);
44+
return this;
45+
},
46+
clear: function(){
47+
undoCommands = [];
48+
index = -1;
49+
},
50+
hasUndo: function(){ return index !== -1; },
51+
hasRedo: function(){ return index < (undoCommands.length - 1); },
52+
getCommands: function(){ return undoCommands; },
53+
getPreviousCommand: function(){ return undoCommands[index-1]; },
54+
getIndex: function(){ return index; }
55+
};
56+
};

0 commit comments

Comments
 (0)