1
+ 'use strict' ;
2
+
1
3
var Plotly = require ( '@lib/index' ) ;
2
4
var Registry = require ( '@src/registry' ) ;
3
5
@@ -7,17 +9,25 @@ var createGraphDiv = require('../assets/create_graph_div');
7
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
8
10
var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
9
11
10
- 'use strict' ;
11
-
12
12
module . exports = function checkTextTemplate ( mock , selector , tests , skipExtra ) {
13
- var isGL = Registry . traceIs ( mock [ 0 ] . type , 'gl' ) ;
14
- var isPolar = Registry . traceIs ( mock [ 0 ] . type , 'polar' ) ;
15
- var isScatterLike = Registry . traceIs ( mock [ 0 ] . type , 'scatter-like' ) ;
16
- var isBarLike = Registry . traceIs ( mock [ 0 ] . type , 'bar-like' ) ;
13
+ var data ;
14
+ var layout ;
15
+ if ( Array . isArray ( mock ) ) {
16
+ data = mock ;
17
+ layout = { } ;
18
+ } else {
19
+ data = mock . data ;
20
+ layout = mock . layout || { } ;
21
+ }
22
+
23
+ var isGL = Registry . traceIs ( data [ 0 ] . type , 'gl' ) ;
24
+ var isPolar = Registry . traceIs ( data [ 0 ] . type , 'polar' ) ;
25
+ var isScatterLike = Registry . traceIs ( data [ 0 ] . type , 'scatter-like' ) ;
26
+ var isBarLike = Registry . traceIs ( data [ 0 ] . type , 'bar-like' ) ;
17
27
18
28
it ( 'should not coerce textinfo when texttemplate is defined' , function ( ) {
19
29
var gd = { } ;
20
- gd . data = Lib . extendDeep ( [ ] , mock ) ;
30
+ gd . data = Lib . extendDeep ( [ ] , data ) ;
21
31
gd . data [ 0 ] . textinfo = 'text' ;
22
32
gd . data [ 0 ] . texttemplate = 'texttemplate' ;
23
33
supplyAllDefaults ( gd ) ;
@@ -27,7 +37,7 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
27
37
if ( isScatterLike ) {
28
38
it ( 'should not coerce texttemplate when mode has no `text` flag' , function ( ) {
29
39
var gd = { } ;
30
- gd . data = Lib . extendDeep ( [ ] , mock ) ;
40
+ gd . data = Lib . extendDeep ( [ ] , data ) ;
31
41
gd . data [ 0 ] . mode = 'markers' ;
32
42
gd . data [ 0 ] . texttemplate = 'texttemplate' ;
33
43
supplyAllDefaults ( gd ) ;
@@ -38,7 +48,7 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
38
48
if ( isBarLike ) {
39
49
it ( 'should not coerce texttemplate when textposition is `none`' , function ( ) {
40
50
var gd = { } ;
41
- gd . data = Lib . extendDeep ( [ ] , mock ) ;
51
+ gd . data = Lib . extendDeep ( [ ] , data ) ;
42
52
gd . data [ 0 ] . textposition = 'none' ;
43
53
gd . data [ 0 ] . texttemplate = 'texttemplate' ;
44
54
supplyAllDefaults ( gd ) ;
@@ -56,19 +66,19 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
56
66
for ( i = 0 ; i < N ; i ++ ) {
57
67
customdata . push ( Lib . randstr ( { } ) ) ;
58
68
}
59
- mock [ 0 ] . customdata = customdata ;
69
+ data [ 0 ] . customdata = customdata ;
60
70
tests . push ( [ '%{customdata}' , customdata ] ) ;
61
71
62
72
// Generate meta
63
- mock [ 0 ] . meta = { 'colname' : 'A' } ;
73
+ data [ 0 ] . meta = { 'colname' : 'A' } ;
64
74
var metaSolution = [ ] ;
65
75
for ( i = 0 ; i < N ; i ++ ) {
66
- metaSolution . push ( mock [ 0 ] . meta . colname ) ;
76
+ metaSolution . push ( data [ 0 ] . meta . colname ) ;
67
77
}
68
78
tests . push ( [ '%{meta.colname}' , metaSolution ] ) ;
69
79
70
80
// Make sure that empty text shows up as an empty string
71
- var emptyTextMock = Lib . extendDeep ( [ ] , mock ) ;
81
+ var emptyTextMock = Lib . extendDeep ( [ ] , data ) ;
72
82
var emptyTextSolution = [ ] ;
73
83
emptyTextMock [ 0 ] . text = [ ] ;
74
84
for ( i = 0 ; i < N ; i ++ ) {
@@ -81,9 +91,9 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
81
91
tests . forEach ( function ( test ) {
82
92
it ( '@gl should support texttemplate' , function ( done ) {
83
93
var gd = createGraphDiv ( ) ;
84
- var mockCopy = Lib . extendDeep ( [ ] , test [ 2 ] || mock ) ;
85
- mockCopy [ 0 ] . texttemplate = test [ 0 ] ;
86
- Plotly . newPlot ( gd , mockCopy )
94
+ var dataCopy = Lib . extendDeep ( [ ] , test [ 2 ] || data ) ;
95
+ dataCopy [ 0 ] . texttemplate = test [ 0 ] ;
96
+ Plotly . newPlot ( gd , dataCopy , Lib . extendDeep ( { } , layout ) )
87
97
. then ( function ( ) {
88
98
var glText ;
89
99
if ( isPolar ) {
@@ -113,9 +123,9 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
113
123
tests . forEach ( function ( test ) {
114
124
it ( 'should support texttemplate' , function ( done ) {
115
125
var gd = createGraphDiv ( ) ;
116
- var mockCopy = Lib . extendDeep ( [ ] , test [ 2 ] || mock ) ;
117
- mockCopy [ 0 ] . texttemplate = test [ 0 ] ;
118
- Plotly . newPlot ( gd , mockCopy )
126
+ var dataCopy = Lib . extendDeep ( [ ] , test [ 2 ] || data ) ;
127
+ dataCopy [ 0 ] . texttemplate = test [ 0 ] ;
128
+ Plotly . newPlot ( gd , dataCopy , Lib . extendDeep ( { } , layout ) )
119
129
. then ( function ( ) {
120
130
var pts = Plotly . d3 . selectAll ( selector ) ;
121
131
expect ( pts . size ( ) ) . toBe ( test [ 1 ] . length ) ;
0 commit comments