@@ -56,10 +56,26 @@ function Loadtostore() {
5656 checkConf ( 'serviceListattr' ) ;
5757 checkConf ( 'serviceListattrnest' ) ;
5858}
59+ let processData = processData_old ;
5960
6061//***********************
6162Loadtostore ( ) ;
6263//***********************
64+ // START: loader spinner settings ****************************
65+ var opts = {
66+ lines : 25 , // The number of lines to draw
67+ length : 15 , // The length of each line
68+ width : 5 , // The line thickness
69+ radius : 25 , // The radius of the inner circle
70+ color : '#f00' , // #rgb or #rrggbb or array of colors
71+ speed : 2 , // Rounds per second
72+ trail : 50 , // Afterglow percentage
73+ className : 'spinner' , // The CSS class to assign to the spinner
74+ } ;
75+ var target = document . getElementById ( 'loadingSpinner' ) ;
76+ var spinner ;
77+ // END: loader spinner settings ****************************
78+
6379var undefinedValue = undefined ;
6480var undefinedColor = "#666" ;
6581var colorscale = d3 . scaleOrdinal ( d3 . schemeCategory10 ) ;
@@ -70,7 +86,7 @@ let legendw= 80;
7086let legendh = 20 ;
7187let barw = 300 ;
7288let barScale = d3 . scaleLinear ( ) ;
73-
89+ let db = 'nagios' ;
7490const collator = new Intl . Collator ( undefined , { numeric : true , sensitivity : 'base' } ) ;
7591Array . prototype . naturalSort = function ( _ ) {
7692 if ( arguments . length ) {
@@ -125,7 +141,6 @@ $( document ).ready(function() {
125141 } ) . on ( 'change' , function ( d ) {
126142 const pdata = d3 . select ( this . parentElement . parentElement ) . datum ( ) ;
127143 d . value = this . checked ;
128- console . log ( pdata . arr )
129144 if ( this . checked ) {
130145 add_axis ( pdata . arr , g ) ;
131146 d3 . select ( this . parentElement . parentElement ) . classed ( 'disable' , false ) ;
@@ -221,8 +236,74 @@ $( document ).ready(function() {
221236 // _.bind(dragged,chosenAxis.node(),chosenAxis.datum(),'table')();
222237 // }));
223238 d3 . select ( "#DarkTheme" ) . on ( "click" , switchTheme ) ;
224- init ( ) ;
239+
240+ // data
241+ d3 . select ( '#datacom' ) . on ( "change" , function ( ) {
242+ d3 . select ( '.cover' ) . classed ( 'hidden' , false ) ;
243+ spinner . spin ( target ) ;
244+ const choice = this . value ;
245+ const choicetext = d3 . select ( '#datacom' ) . node ( ) . selectedOptions [ 0 ] . text ;
246+ setTimeout ( ( ) => {
247+ if ( choice !== "nagios" && choice !== "influxdb" )
248+ d3 . json ( "../HiperView/data/" + choice + ".json" ) . then ( function ( data ) {
249+ sampleS = data ;
250+ if ( choice . includes ( 'influxdb' ) ) {
251+ // processResult = processResult_influxdb;
252+ db = "influxdb" ;
253+ realTimesetting ( false , "influxdb" ) ;
254+ } else {
255+ // processResult = processResult_old;
256+ realTimesetting ( false ) ;
257+ }
258+ d3 . select ( ".currentDate" )
259+ . text ( "" + d3 . timeParse ( "%d %b %Y" ) ( choicetext ) . toDateString ( ) ) ;
260+ resetRequest ( ) ;
261+ d3 . select ( '.cover' ) . classed ( 'hidden' , true ) ;
262+ spinner . stop ( ) ;
263+ } ) ;
264+ else {
265+ realTimesetting ( true , choice ) ;
266+ db = choice ;
267+ requestService = eval ( 'requestService' + choice ) ;
268+ processResult = eval ( 'processResult_' + choice ) ;
269+ d3 . select ( '.cover' ) . classed ( 'hidden' , true ) ;
270+ spinner . stop ( ) ;
271+ }
272+ } , 0 ) ;
273+ } ) ;
274+ spinner = new Spinner ( opts ) . spin ( target ) ;
275+
276+
277+ setTimeout ( ( ) => {
278+ d3 . json ( "../HiperView/data/" + d3 . select ( '#datacom' ) . node ( ) . value + ".json" ) . then ( function ( data ) {
279+ d3 . select ( ".cover" ) . select ( 'h5' ) . text ( 'drawLegend...' ) ;
280+ d3 . select ( ".currentDate" )
281+ . text ( "" + d3 . timeParse ( "%d %b %Y" ) ( d3 . select ( '#datacom' ) . select ( '[selected="selected"]' ) . text ( ) ) . toDateString ( ) ) ;
282+ // drawLegend(initialService, arrThresholds, arrColor, dif);
283+ sampleS = data ;
284+ init ( ) ;
285+ d3 . select ( ".cover" ) . select ( 'h5' ) . text ( 'loading data...' ) ;
286+ // addDatasetsOptions(); // Add these dataset to the select dropdown, at the end of this files
287+ d3 . select ( '.cover' ) . classed ( 'hidden' , true ) ;
288+ spinner . stop ( ) ;
289+ } ) ;
290+ } , 0 ) ;
291+ // Spinner Stop ********************************************************************
292+
293+ // init();
225294} ) ;
295+
296+ function realTimesetting ( option , db ) {
297+ isRealtime = option ;
298+ // getDataWorker.postMessage({action:'isRealtime',value:option,db: db});
299+ if ( option ) {
300+ processData = eval ( 'processData_' + db ) ;
301+ } else {
302+ processData = db ?eval ( 'processData_' + db ) :processData_old ;
303+ }
304+ resetRequest ( ) ;
305+ }
306+
226307function getBrush ( d ) {
227308 return d3 . brushY ( yscale [ d ] )
228309 . extent ( [ [ - 10 , 0 ] , [ 10 , h ] ] )
@@ -287,7 +368,6 @@ function dragend(d) {
287368 var extent = d3 . brushSelection ( this ) ;
288369 if ( extent )
289370 extent = extent . map ( yscale [ d ] . invert ) . sort ( ( a , b ) => a - b ) ;
290- console . log ( extent )
291371 }
292372
293373 // remove axis if dragged all the way left
@@ -444,6 +524,22 @@ function init() {
444524 brush ( ) ;
445525}
446526
527+ function resetRequest ( ) {
528+ // Convert quantitative scales to floats
529+ data = object2DataPrallel ( readData ( ) ) ;
530+ d3 . keys ( data [ 0 ] ) . filter ( function ( k ) {
531+ return ( ( ( _ . isDate ( data [ 0 ] [ k ] ) ) && ( yscale [ k ] = d3 . scaleTime ( )
532+ . domain ( d3 . extent ( data , function ( d ) {
533+ return d [ k ] ;
534+ } ) )
535+ . range ( [ h , 0 ] ) ) || ( _ . isNumber ( data [ 0 ] [ k ] ) ) && ( yscale [ k ] = d3 . scaleLinear ( )
536+ . domain ( d3 . extent ( data , function ( d ) {
537+ return + d [ k ] ;
538+ } ) )
539+ . range ( [ h , 0 ] ) ) ) ) ;
540+ } ) ;
541+ brush ( ) ;
542+ }
447543function setColorsAndThresholds ( s ) {
448544 for ( var i = 0 ; i < serviceList . length ; i ++ ) {
449545 if ( s == serviceList [ i ] ) {
@@ -660,8 +756,6 @@ function highlight(d) {
660756 const val = d [ selectedService ] ;
661757 const gourpBeloing = orderLegend . find ( dv => val >= dv . minvalue && val < dv . value ) || { text :undefined } ;
662758
663- console . log ( val ) ;
664- console . log ( gourpBeloing ) ;
665759 d3 . select ( "#colorContinuos" ) . selectAll ( ".row" ) . style ( "opacity" , function ( p ) { return ( gourpBeloing . text === p ) ? null : "0.3" } ) ;
666760 } else {
667761 d3 . select ( "#legend" ) . selectAll ( ".row" ) . style ( "opacity" , function ( p ) {
@@ -696,7 +790,8 @@ function invert_axis(d) {
696790 // Get extents of brush along each active selection axis (the Y axes)
697791 extent = d3 . brushSelection ( this ) . map ( yscale [ d ] . invert ) ;
698792 } ) ;
699- console . log ( extent )
793+
794+
700795 if ( yscale [ d ] . inverted == true ) {
701796 yscale [ d ] . range ( [ h , 0 ] ) ;
702797 d3 . selectAll ( '.label' )
@@ -743,7 +838,6 @@ function path(d, ctx, color) {
743838 var x = xscale ( p ) ,
744839 y = yscale [ p ] ( d [ p ] ) ;
745840 if ( y === undefined ) {
746- console . log ( p )
747841 if ( valid ) {
748842 ctx . stroke ( ) ;
749843 ctx . beginPath ( ) ;
0 commit comments