@@ -11,6 +11,7 @@ var subroutines = require('@src/plot_api/subroutines');
11
11
var d3 = require ( 'd3' ) ;
12
12
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
13
13
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
14
+ var fail = require ( '../assets/fail_test' ) ;
14
15
15
16
16
17
describe ( 'Test plot api' , function ( ) {
@@ -22,6 +23,69 @@ describe('Test plot api', function() {
22
23
} ) ;
23
24
} ) ;
24
25
26
+ describe ( 'Plotly.plot' , function ( ) {
27
+ var gd ;
28
+
29
+ beforeEach ( function ( ) {
30
+ gd = createGraphDiv ( ) ;
31
+ } ) ;
32
+
33
+ afterEach ( destroyGraphDiv ) ;
34
+
35
+ it ( 'accepts gd, data, layout, and config as args' , function ( done ) {
36
+ Plotly . plot ( gd ,
37
+ [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] ,
38
+ { width : 500 , height : 500 } ,
39
+ { editable : true }
40
+ ) . then ( function ( ) {
41
+ expect ( gd . layout . width ) . toEqual ( 500 ) ;
42
+ expect ( gd . layout . height ) . toEqual ( 500 ) ;
43
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
44
+ expect ( gd . _context . editable ) . toBe ( true ) ;
45
+ } ) . catch ( fail ) . then ( done ) ;
46
+ } ) ;
47
+
48
+ it ( 'accepts gd and an object as args' , function ( done ) {
49
+ Plotly . plot ( gd , {
50
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] ,
51
+ layout : { width : 500 , height : 500 } ,
52
+ config : { editable : true } ,
53
+ frames : [ { y : [ 2 , 1 , 0 ] , name : 'frame1' } ]
54
+ } ) . then ( function ( ) {
55
+ expect ( gd . layout . width ) . toEqual ( 500 ) ;
56
+ expect ( gd . layout . height ) . toEqual ( 500 ) ;
57
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
58
+ expect ( gd . _transitionData . _frames . length ) . toEqual ( 1 ) ;
59
+ expect ( gd . _context . editable ) . toBe ( true ) ;
60
+ } ) . catch ( fail ) . then ( done ) ;
61
+ } ) ;
62
+
63
+ it ( 'allows adding more frames to the initial set' , function ( done ) {
64
+ Plotly . plot ( gd , {
65
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] ,
66
+ layout : { width : 500 , height : 500 } ,
67
+ config : { editable : true } ,
68
+ frames : [ { y : [ 7 , 7 , 7 ] , name : 'frame1' } ]
69
+ } ) . then ( function ( ) {
70
+ expect ( gd . layout . width ) . toEqual ( 500 ) ;
71
+ expect ( gd . layout . height ) . toEqual ( 500 ) ;
72
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
73
+ expect ( gd . _transitionData . _frames . length ) . toEqual ( 1 ) ;
74
+ expect ( gd . _context . editable ) . toBe ( true ) ;
75
+
76
+ return Plotly . addFrames ( gd , [
77
+ { y : [ 8 , 8 , 8 ] , name : 'frame2' } ,
78
+ { y : [ 9 , 9 , 9 ] , name : 'frame3' }
79
+ ] ) ;
80
+ } ) . then ( function ( ) {
81
+ expect ( gd . _transitionData . _frames . length ) . toEqual ( 3 ) ;
82
+ expect ( gd . _transitionData . _frames [ 0 ] . name ) . toEqual ( 'frame1' ) ;
83
+ expect ( gd . _transitionData . _frames [ 1 ] . name ) . toEqual ( 'frame2' ) ;
84
+ expect ( gd . _transitionData . _frames [ 2 ] . name ) . toEqual ( 'frame3' ) ;
85
+ } ) . catch ( fail ) . then ( done ) ;
86
+ } ) ;
87
+ } ) ;
88
+
25
89
describe ( 'Plotly.relayout' , function ( ) {
26
90
var gd ;
27
91
0 commit comments