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

Commit fca1ac0

Browse filesBrowse files
committed
Factored out redraw
1 parent 3414453 commit fca1ac0
Copy full SHA for fca1ac0

File tree

2 files changed

+41
-16
lines changed
Filter options

2 files changed

+41
-16
lines changed

‎src/plot_api/plot_api.js

Copy file name to clipboardExpand all lines: src/plot_api/plot_api.js
+1-16Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var isNumeric = require('fast-isnumeric');
2020
var plots = Plotly.Plots;
2121

2222
Plotly.plot = require('./plot');
23+
Plotly.redraw = require('./redraw');
2324

2425
// Get the container div: we store all variables for this plot as
2526
// properties of this div
@@ -576,22 +577,6 @@ function emptyContainer(outer, innerStr) {
576577
(Object.keys(outer[innerStr]).length === 0);
577578
}
578579

579-
// convenience function to force a full redraw, mostly for use by plotly.js
580-
Plotly.redraw = function(gd) {
581-
gd = getGraphDiv(gd);
582-
583-
if(!Plotly.Lib.isPlotDiv(gd)) {
584-
console.log('This element is not a Plotly Plot', gd);
585-
return;
586-
}
587-
588-
gd.calcdata = undefined;
589-
return Plotly.plot(gd).then(function () {
590-
gd.emit('plotly_redraw');
591-
return gd;
592-
});
593-
};
594-
595580
/**
596581
* Convenience function to make idempotent plot option obvious to users.
597582
*

‎src/plot_api/redraw.js

Copy file name to clipboard
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var Lib = require('../lib');
2+
var plot = require('./plot');
3+
4+
module.exports = redraw;
5+
6+
// convenience function to force a full redraw, mostly for use by plotly.js
7+
function redraw(gd) {
8+
gd = getGraphDiv(gd);
9+
10+
if(!Lib.isPlotDiv(gd)) {
11+
console.log('This element is not a Plotly Plot', gd);
12+
return;
13+
}
14+
15+
gd.calcdata = undefined;
16+
return plot(gd).then(function () {
17+
gd.emit('plotly_redraw');
18+
return gd;
19+
});
20+
};
21+
22+
23+
function getGraphDiv(gd) {
24+
var gdElement;
25+
26+
if(typeof gd === 'string') {
27+
gdElement = document.getElementById(gd);
28+
29+
if(gdElement === null) {
30+
throw new Error('No DOM element with id \'' + gd + '\' exists on the page.');
31+
}
32+
33+
return gdElement;
34+
}
35+
else if(gd===null || gd===undefined) {
36+
throw new Error('DOM element provided is null or undefined');
37+
}
38+
39+
return gd; // otherwise assume that gd is a DOM element
40+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.