File tree 2 files changed +41
-16
lines changed
Filter options
2 files changed +41
-16
lines changed
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ var isNumeric = require('fast-isnumeric');
20
20
var plots = Plotly . Plots ;
21
21
22
22
Plotly . plot = require ( './plot' ) ;
23
+ Plotly . redraw = require ( './redraw' ) ;
23
24
24
25
// Get the container div: we store all variables for this plot as
25
26
// properties of this div
@@ -576,22 +577,6 @@ function emptyContainer(outer, innerStr) {
576
577
( Object . keys ( outer [ innerStr ] ) . length === 0 ) ;
577
578
}
578
579
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
-
595
580
/**
596
581
* Convenience function to make idempotent plot option obvious to users.
597
582
*
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments