@@ -88,6 +88,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
8888 type : 'scatter' ,
8989 displayModeBar : false ,
9090 orientation : 'v' ,
91+ autotrace : false ,
9192 } ,
9293 layout : {
9394 barmode : 'group' ,
@@ -563,15 +564,51 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
563564
564565 onDataReceived ( dataList ) {
565566 const finfo : SeriesWrapper [ ] = [ ] ;
567+ const autotrace = this . cfg . settings . autotrace ;
566568 let seriesHash = '/' ;
569+ let autotraceDataSeries = { } ;
567570 if ( dataList && dataList . length > 0 ) {
571+ if ( autotrace ) {
572+ // Check input is of expected form.
573+ dataList . forEach ( ( series , sidx ) => {
574+ if ( series . columns && series . columns . length === 3 && series . type === 'table' ) {
575+ series . rows . forEach ( ( val ) => {
576+ const sname = val [ 0 ] ;
577+ if ( ! ( sname in autotraceDataSeries ) ) {
578+ autotraceDataSeries [ sname ] = {
579+ columns : series . columns ,
580+ rows : [ ] ,
581+ type : 'table' ,
582+ name : sname ,
583+ }
584+ } ;
585+ autotraceDataSeries [ sname ] . rows . push ( val ) ;
586+ } ) ;
587+ } else {
588+ console . error ( 'Autotrace needs table input with 3 columns' , sidx , series ) ;
589+ throw new Error ( 'Autotrace needs table input with 3 columns' ) ;
590+ }
591+ } ) ;
592+
593+ let autotraceDataList : any = [ ] ;
594+ for ( var key in autotraceDataSeries ) {
595+ autotraceDataList . push ( autotraceDataSeries [ key ] ) ;
596+ }
597+ this . _updateAutoTraces ( autotraceDataSeries ) ;
598+ dataList = autotraceDataList ;
599+ }
600+
568601 const useRefID = dataList . length === this . panel . targets . length ;
569602 dataList . forEach ( ( series , sidx ) => {
570603 let refId = '' ;
571- if ( useRefID ) {
572- refId = _ . get ( this . panel , 'targets[' + sidx + '].refId' ) ;
573- if ( ! refId ) {
574- refId = String . fromCharCode ( 'A' . charCodeAt ( 0 ) + sidx ) ;
604+ if ( autotrace ) {
605+ refId = series . name ;
606+ } else {
607+ if ( useRefID ) {
608+ refId = _ . get ( this . panel , 'targets[' + sidx + '].refId' ) ;
609+ if ( ! refId ) {
610+ refId = String . fromCharCode ( 'A' . charCodeAt ( 0 ) + sidx ) ;
611+ }
575612 }
576613 }
577614 if ( series . columns ) {
@@ -661,6 +698,10 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
661698
662699 // This will update all trace settings *except* the data
663700 _updateTracesFromConfigs ( ) {
701+ // If we're in autotrace mode, trace creation happens elsewhere.
702+ if ( this . cfg . settings . autotrace )
703+ return ;
704+
664705 this . dataWarnings = [ ] ;
665706
666707 // Make sure we have a trace
@@ -726,16 +767,48 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
726767 } ) ;
727768 }
728769
770+ // Autotrace. Recreate the traces to those found in the data.
771+ _updateAutoTraces ( series ) {
772+ this . dataWarnings = [ ] ;
773+
774+ delete this . traces ;
775+
776+ this . traces = [ ] ;
777+
778+ for ( var key in series ) {
779+ const trace : any = {
780+ name : key ,
781+ type : this . cfg . settings . type ,
782+ orientation : this . cfg . settings . orientation ,
783+ __set : [ ] , // { key:? property:? }
784+ } ;
785+
786+ // Set the text
787+ this . __addCopyPath ( trace , key + '/' + series [ key ] . columns [ 1 ] . text , 'x' ) ;
788+ this . __addCopyPath ( trace , key + '/' + series [ key ] . columns [ 2 ] . text , 'y' ) ;
789+ if ( trace . orientation === 'v' )
790+ this . __addCopyPath ( trace , key + '/' + series [ key ] . columns [ 2 ] . text , 'text' ) ;
791+ else
792+ this . __addCopyPath ( trace , key + '/' + series [ key ] . columns [ 1 ] . text , 'text' ) ;
793+
794+ this . traces . push ( trace ) ;
795+ }
796+
797+ if ( this . traces . length < 1 ) {
798+ this . traces = [ _ . cloneDeep ( PlotlyPanelCtrl . defaultTrace ) ] ;
799+ }
800+ }
801+
729802 // Fills in the required data into the trace values
730803 _updateTraceData ( force = false ) : boolean {
731804 if ( ! this . series ) {
732- // console.log('NO Series data yet!');
805+ // console.log('No series data yet!');
733806 return false ;
734807 }
735808
736809 if ( force || ! this . traces ) {
737810 this . _updateTracesFromConfigs ( ) ;
738- } else if ( this . traces . length !== this . cfg . traces . length ) {
811+ } else if ( ! this . cfg . settings . autotrace && this . traces . length !== this . cfg . traces . length ) {
739812 console . log (
740813 'trace number mismatch. Found: ' +
741814 this . traces . length +
0 commit comments