@@ -507,7 +507,7 @@ class ChartInspector {
507507 }
508508
509509 //console.log("Hello World from new ChartInspector: " + this[CHARTINSPECTORNAME] + ", prefix: " + data.who);
510- this . showInspectorOverlay ( ) ;
510+ this . showInspectorOverlay ( { } ) ;
511511 }
512512
513513 get name ( ) { return this [ CHARTINSPECTORNAME ] ; }
@@ -536,20 +536,31 @@ class ChartInspector {
536536 }
537537 if ( this . hScale < 1 ) this . hScale = 1 ;
538538 //console.log("hScale now = " + this.hScale);
539- this . showInspectorOverlay ( ) ;
539+ this . showInspectorOverlay ( { } ) ;
540540 } else if ( e . key == "ArrowRight" ) {
541541 if ( e . shiftKey ) {
542542 this . hScale += 10 ;
543543 } else {
544544 this . hScale += 1 ;
545545 }
546546 //console.log("hScale now = " + this.hScale);
547- this . showInspectorOverlay ( ) ;
547+ this . showInspectorOverlay ( { } ) ;
548+ } else if ( e . deltaY < 0 ) {
549+ //console.log("addInspectorKeyboardHandler() at: " + e.clientX + "," + e.clientY + " (" + e.deltaX + "," + e.deltaY + "," + e.deltaZ + ")");
550+ this . hScale += 1 ;
551+ this . showInspectorOverlay ( { "xpos" :e . clientX } ) ;
552+ } else if ( e . deltaY > 0 ) {
553+ //console.log("addInspectorKeyboardHandler() at: " + e.clientX + "," + e.clientY + " (" + e.deltaX + "," + e.deltaY + "," + e.deltaZ + ")");
554+ this . hScale -= 1 ;
555+ if ( this . hScale < 1 ) this . hScale = 1 ;
556+ this . showInspectorOverlay ( { "xpos" :e . clientX } ) ;
557+ } else {
558+ console . log ( "addInspectorKeyboardHandler(): ???" ) ;
548559 }
549560 }
550561 }
551562
552- showInspectorOverlay ( ) {
563+ showInspectorOverlay ( options ) {
553564 //console.log("showInspectorOverlay() for " + this.elementName);
554565 var inspectorExists = document . getElementById ( this . elementName ) ;
555566 var svgWidth , svgHeight ;
@@ -558,6 +569,7 @@ class ChartInspector {
558569 if ( ! this . hasBindListener ) {
559570 this . bindListener = this . addInspectorKeyboardHandler . bind ( this ) ;
560571 document . body . addEventListener ( "keydown" , this . bindListener ) ;
572+ document . body . addEventListener ( "wheel" , this . bindListener ) ;
561573 this . hasBindListener = true ;
562574 }
563575
@@ -634,6 +646,7 @@ class ChartInspector {
634646 renderArgs . data = runningData [ this [ CHARTINSPECTORNAME ] ] ;
635647 }
636648 renderArgs . who = this [ CHARTINSPECTORIDBASE ] ;
649+ if ( options . xpos ) renderArgs . xpos = options . xpos ;
637650
638651 renderChart ( renderArgs ) ;
639652 }
@@ -647,7 +660,7 @@ class ChartInspector {
647660 if ( inspector ) {
648661 //console.log("inspector display = " + inspector.style.display);
649662 if ( inspector . style . display != "none" ) {
650- this . showInspectorOverlay ( ) ;
663+ this . showInspectorOverlay ( { } ) ;
651664 }
652665 }
653666 }
@@ -691,6 +704,10 @@ function renderChart(options) {
691704 var data = options . data ;
692705 var graphWidthScale = options . hScale ;
693706 var who = options . who ;
707+ var scrollTarget = options . xpos || undefined ;
708+
709+ var holder ;
710+ var currentScrollPos ;
694711
695712 // elapsedJobTime only used for running jobs
696713 var elapsedJobTime ;
@@ -727,12 +744,22 @@ function renderChart(options) {
727744 //console.log("renderChart(): elapsedJobTime = " + elapsedJobTime);
728745 }
729746
747+ var viewport = select ( "#" + nameBase + "chartHolder_" + longName ) . node ( ) . getBoundingClientRect ( ) ;
748+ //console.log("viewport size = " + viewport.width + "," + viewport.height);
749+
750+ // Store current scroll position
751+ if ( scrollTarget ) {
752+ holder = document . getElementById ( svgParentName ) ;
753+ holder . onscroll = function ( ) {
754+ console . log ( "scroll pos = " + holder . scrollLeft ) ;
755+ } ;
756+ currentScrollPos = holder . scrollLeft ;
757+ console . log ( "current scroll = " + currentScrollPos + " (" + ( currentScrollPos % viewport . width ) + ")" ) ;
758+ }
759+
730760 // Now (re)draw graph
731761
732- //select("#" + this[CHARTINSPECTORIDBASE] + "svg_" + this[CHARTINSPECTORNAME]).remove();
733762 select ( "#" + nameBase + "svg_" + longName ) . remove ( ) ;
734- //var jobElementGraphInspector = document.getElementById(this.elementName);
735- //var jobElementGraphInspector = document.getElementById(this[CHARTINSPECTORIDBASE] + "chartHolder_" + this[CHARTINSPECTORNAME]);
736763 var jobElementGraphInspector = document . getElementById ( svgParentName ) ;
737764
738765 var svg = select ( jobElementGraphInspector ) . append ( "svg" ) ;
@@ -907,7 +934,8 @@ function renderChart(options) {
907934 var sensorId = select ( this ) . attr ( "id" ) ;
908935 //console.log("sensor name: " + sensorId);
909936 /* We don't know what the values to be shown in the popup are.
910- Therefore make a dummy version first that's close enough to measure a bounding box.
937+ Therefore make a dummy version first that's close enough to measure a bounding box,
938+ otherwise we can't centre the first line like we want to.
911939 Finally delete the dummy, then fill & position the real popup.
912940 */
913941 var viewport = select ( "#" + nameBase + "chartHolder_" + longName ) . node ( ) . getBoundingClientRect ( ) ;
@@ -1042,6 +1070,42 @@ function renderChart(options) {
10421070 }
10431071 }
10441072
1073+ /*
1074+ svg.on("mousemove", function() {
1075+ inspectorCoords = mouse(this);
1076+ });
1077+ svg.on("click", function() {
1078+ var holder = document.getElementById(svgParentName);
1079+ console.log("click at " + inspectorCoords[0] + "," + inspectorCoords[1] + " scroll = " + holder.scrollLeft);
1080+ console.log("and remainder = " + inspectorCoords[1]%svgWidth);
1081+ });
1082+ var holder = document.getElementById(svgParentName);
1083+ //holder.scrollLeft = (svgWidth * (graphWidthScale - 1)) - (svgWidth - (svgWidth%inspectorCoords[1]));
1084+ console.log("Remainder = " + inspectorCoords[1]%svgWidth);
1085+ holder.scrollLeft = graphWidthScale*(graphWidthScale - 1) - graphWidthScale*(inspectorCoords[1]%svgWidth);
1086+ svg.call(zoom().on("zoom", function () {
1087+ inspectorCoords = mouse(this);
1088+ var holder = document.getElementById(svgParentName);
1089+ console.log("click at " + inspectorCoords[0] + "," + inspectorCoords[1] + " scroll = " + holder.scrollLeft);
1090+ //console.log("Zoom = " + (-event.deltaY * (event.deltaMode ? 120 : 1) / 500));
1091+ console.log("Zoom = " + event.deltaY);
1092+ }));
1093+ */
1094+
1095+ // Attempt to reposition graph to keep scrollTarget in view
1096+ if ( scrollTarget ) {
1097+ console . log ( "scrollTarget = " + scrollTarget ) ;
1098+ //currentScrollPos
1099+
1100+ holder = document . getElementById ( svgParentName ) ;
1101+ holder . scrollLeft = ( scrollTarget - graphMargin . left ) * ( graphWidthScale - 1 ) ;
1102+ //console.log("scrollTarget = " + scrollTarget + " (" + holder.scrollLeft%viewport.width + ")");
1103+ //console.log("Propose: " + (holder.scrollLeft/viewport.width + scrollTarget) + " (" + (holder.scrollLeft/viewport.width + scrollTarget)%viewport.width + ")");
1104+ //holder.scrollLeft = Math.floor(holder.scrollLeft/viewport.width + scrollTarget);
1105+ console . log ( "scroll result = " + holder . scrollLeft ) ;
1106+ }
1107+
1108+
10451109
10461110 /*
10471111 Show time & value as a tooltip at any particular point of the graph.
@@ -2931,7 +2995,7 @@ window.onload = function () {
29312995
29322996 if ( jobHistoryInspectors [ jobLongName ] ) {
29332997 console . log ( "Already have an Inspector for " + jobLongName ) ;
2934- jobHistoryInspectors [ jobLongName ] . showInspectorOverlay ( ) ;
2998+ jobHistoryInspectors [ jobLongName ] . showInspectorOverlay ( { } ) ;
29352999 } else if ( historyData [ jobLongName ] ) {
29363000 console . log ( "Don't have an Inspector for " + jobLongName + " yet but already have the data" ) ;
29373001 var hdata = historyData [ jobLongName ] ;
@@ -3006,7 +3070,7 @@ window.onload = function () {
30063070
30073071 if ( jobHistoryInspectors [ jobLongName ] ) {
30083072 console . log ( "Already have an Inspector for " + jobLongName ) ;
3009- jobHistoryInspectors [ jobLongName ] . showInspectorOverlay ( ) ;
3073+ jobHistoryInspectors [ jobLongName ] . showInspectorOverlay ( { } ) ;
30103074 } else if ( runningData [ jobLongName ] ) {
30113075 console . log ( "Don't have an Inspector for " + jobLongName + " yet but already have the data" ) ;
30123076 var hdata = runningData [ jobLongName ] ;
@@ -3709,7 +3773,7 @@ window.onload = function () {
37093773 if ( jobHistoryInspectors [ item ] . overlay . style . display == "none" ) {
37103774 console . log ( "Not redrawing: " + jobHistoryInspectors [ item ] . name ) ;
37113775 } else {
3712- jobHistoryInspectors [ item ] . showInspectorOverlay ( ) ;
3776+ jobHistoryInspectors [ item ] . showInspectorOverlay ( { } ) ;
37133777 }
37143778 } ) ;
37153779
0 commit comments