1+ var Fuse = require ( 'fuse.js' ) ;
2+ var mocks = require ( './mocks.json' ) ;
3+
4+
15// Our gracious testing object
26var Tabs = {
37
8+ // Return the specified plot container (or default one)
49 getGraph : function ( id ) {
510 id = id || 'graph' ;
611 return document . getElementById ( id ) ;
712 } ,
813
14+ // Create a new plot container
915 fresh : function ( id ) {
1016 id = id || 'graph' ;
1117
@@ -25,14 +31,18 @@ var Tabs = {
2531 return graphDiv ;
2632 } ,
2733
34+ // Plot a mock by name (without .json) to the default or specified container
2835 plotMock : function ( mockName , id ) {
2936 var mockURL = '/test/image/mocks/' + mockName + '.json' ;
3037
3138 window . Plotly . d3 . json ( mockURL , function ( err , fig ) {
3239 window . Plotly . plot ( Tabs . fresh ( id ) , fig . data , fig . layout ) ;
40+
41+ console . warn ( 'Plotting:' , mockURL ) ;
3342 } ) ;
3443 } ,
3544
45+ // Save a png snapshot and display it below the plot
3646 snapshot : function ( id ) {
3747 var gd = Tabs . getGraph ( id ) ;
3848
@@ -52,9 +62,10 @@ var Tabs = {
5262 } ) ;
5363 } ,
5464
65+ // Remove all plots and snapshots from the page
5566 purge : function ( ) {
5667 var plots = document . getElementsByClassName ( 'dashboard-plot' ) ;
57- var images = document . getElementsById ( 'snapshot' ) ;
68+ var images = document . getElementById ( 'snapshot' ) ;
5869
5970 while ( images . firstChild ) {
6071 images . removeChild ( images . firstChild ) ;
@@ -65,10 +76,12 @@ var Tabs = {
6576 }
6677 } ,
6778
79+ // Specify what to do after each plotly.js script reload
6880 onReload : function ( ) {
6981 return ;
7082 } ,
7183
84+ // Refreshes the plotly.js source without needing to refresh the page
7285 reload : function ( ) {
7386 var source = document . getElementById ( 'source' ) ;
7487 var reloaded = document . getElementById ( 'reload-time' ) ;
@@ -92,6 +105,8 @@ var Tabs = {
92105} ;
93106
94107
108+ // Bind things to the window
109+ window . Tabs = Tabs ;
95110setInterval ( function ( ) {
96111 window . gd = Tabs . getGraph ( ) || Tabs . fresh ( ) ;
97112 window . fullLayout = window . gd . _fullLayout ;
@@ -100,10 +115,19 @@ setInterval(function() {
100115
101116
102117// Mocks search and plotting
103- var f = new window . Fuse ( window . MOCKS , { keys : [ 'name' ] } ) ;
118+ var f = new Fuse ( mocks , {
119+ keys : [ {
120+ name : 'name' ,
121+ weight : 0.7
122+ } , {
123+ name : 'keywords' ,
124+ weight : 0.3
125+ } ]
126+ } ) ;
104127
105128var searchBar = document . getElementById ( 'mocks-search' ) ;
106129var mocksList = document . getElementById ( 'mocks-list' ) ;
130+
107131searchBar . addEventListener ( 'keyup' , function ( e ) {
108132
109133 // Clear results.
@@ -120,10 +144,10 @@ searchBar.addEventListener('keyup', function(e) {
120144 result . innerText = r . name ;
121145
122146 result . addEventListener ( 'click' , function ( ) {
147+
123148 // Clear plots and plot selected.
124149 Tabs . purge ( ) ;
125150 Tabs . plotMock ( r . file . slice ( 0 , - 5 ) ) ;
126- console . warn ( 'Plotting:' , r . file ) ;
127151
128152 // Clear results.
129153 while ( mocksList . firstChild ) {
0 commit comments