44/* eslint-disable @typescript-eslint/no-unsafe-call */
55/* eslint-disable @typescript-eslint/no-explicit-any */
66
7-
87interface Plot {
98 // unique ID for this plot (w.r.t. this connection/device)
109 id : string ;
@@ -24,94 +23,90 @@ const vscode = acquireVsCodeApi();
2423let oldHeight = - 1 ;
2524let oldWidth = - 1 ;
2625
27-
2826const handler = document . querySelector ( '#handler' ) as HTMLDivElement ;
2927const largePlotDiv = document . querySelector ( '#largePlot' ) as HTMLDivElement ;
3028const largeSvg = largePlotDiv . querySelector ( 'svg' ) as SVGElement ;
3129const cssLink = document . querySelector ( 'link.overwrites' ) as HTMLLinkElement ;
3230const smallPlotDiv = document . querySelector ( '#smallPlots' ) as HTMLDivElement ;
3331
34-
3532function getSmallPlots ( ) : HTMLAnchorElement [ ] {
3633 const smallPlots : HTMLAnchorElement [ ] = [ ] ;
37- document . querySelectorAll ( 'a.focusPlot' ) . forEach ( elm => {
34+ document . querySelectorAll ( 'a.focusPlot' ) . forEach ( ( elm ) => {
3835 smallPlots . push ( elm as HTMLAnchorElement ) ;
3936 } ) ;
4037 return smallPlots ;
4138}
4239
4340let isHandlerDragging = false ;
4441
45-
4642let isFullWindow = false ;
4743
48- function postResizeMessage ( userTriggered : boolean = false ) {
44+ function postResizeMessage ( userTriggered : boolean = false ) {
4945 let newHeight = largePlotDiv . clientHeight ;
5046 let newWidth = largePlotDiv . clientWidth ;
51- if ( isFullWindow ) {
47+ if ( isFullWindow ) {
5248 newHeight = window . innerHeight ;
5349 newWidth = window . innerWidth ;
5450 }
55- if ( userTriggered || newHeight !== oldHeight || newWidth !== oldWidth ) {
51+ if ( userTriggered || newHeight !== oldHeight || newWidth !== oldWidth ) {
5652 const msg : ResizeMessage = {
5753 message : 'resize' ,
5854 height : newHeight ,
5955 width : newWidth ,
60- userTriggered : userTriggered
56+ userTriggered : userTriggered ,
6157 } ;
6258 vscode . postMessage ( msg ) ;
6359 oldHeight = newHeight ;
6460 oldWidth = newWidth ;
6561 }
6662}
6763
68- function postLogMessage ( content : any ) {
64+ function postLogMessage ( content : any ) {
6965 console . log ( content ) ;
7066 vscode . postMessage ( {
7167 message : 'log' ,
72- body : content
68+ body : content ,
7369 } ) ;
7470}
7571
7672window . addEventListener ( 'message' , ( ev : MessageEvent < InMessage > ) => {
7773 const msg = ev . data ;
78- if ( msg . message === 'updatePlot' ) {
74+ if ( msg . message === 'updatePlot' ) {
7975 updatePlot ( {
8076 id : String ( msg . plotId ) ,
81- svg : msg . svg
77+ svg : msg . svg ,
8278 } ) ;
83- } else if ( msg . message === 'focusPlot' ) {
79+ } else if ( msg . message === 'focusPlot' ) {
8480 focusPlot ( String ( msg . plotId ) ) ;
85- } else if ( msg . message === 'toggleStyle' ) {
81+ } else if ( msg . message === 'toggleStyle' ) {
8682 toggleStyle ( msg . useOverwrites ) ;
87- } else if ( msg . message === 'hidePlot' ) {
83+ } else if ( msg . message === 'hidePlot' ) {
8884 hidePlot ( msg . plotId ) ;
89- } else if ( msg . message === 'addPlot' ) {
85+ } else if ( msg . message === 'addPlot' ) {
9086 addPlot ( msg . html ) ;
91- } else if ( msg . message === 'togglePreviewPlotLayout' ) {
87+ } else if ( msg . message === 'togglePreviewPlotLayout' ) {
9288 togglePreviewPlotLayout ( msg . style ) ;
93- } else if ( msg . message === 'toggleFullWindow' ) {
89+ } else if ( msg . message === 'toggleFullWindow' ) {
9490 toggleFullWindowMode ( msg . useFullWindow ) ;
9591 }
9692} ) ;
9793
98- function addPlot ( html : string ) {
94+ function addPlot ( html : string ) {
9995 const wrapper = document . createElement ( 'div' ) ;
10096 wrapper . classList . add ( 'wrapper' ) ;
10197 wrapper . innerHTML = html ;
10298 smallPlotDiv . appendChild ( wrapper ) ;
10399}
104100
105101function focusPlot ( plotId : string ) : void {
106-
107102 const smallPlots = getSmallPlots ( ) ;
108103
109104 const ind = findIndex ( plotId , smallPlots ) ;
110- if ( ind < 0 ) {
105+ if ( ind < 0 ) {
111106 return ;
112107 }
113108
114- for ( const elm of smallPlots ) {
109+ for ( const elm of smallPlots ) {
115110 elm . classList . remove ( 'active' ) ;
116111 }
117112
@@ -123,17 +118,16 @@ function focusPlot(plotId: string): void {
123118}
124119
125120function updatePlot ( plt : Plot ) : void {
126-
127121 const smallPlots = getSmallPlots ( ) ;
128122
129123 const ind = findIndex ( plt . id , smallPlots ) ;
130- if ( ind < 0 ) {
124+ if ( ind < 0 ) {
131125 return ;
132126 }
133127
134128 smallPlots [ ind ] . innerHTML = plt . svg ;
135129
136- if ( smallPlots [ ind ] . classList . contains ( 'active' ) ) {
130+ if ( smallPlots [ ind ] . classList . contains ( 'active' ) ) {
137131 largePlotDiv . innerHTML = plt . svg ;
138132 }
139133}
@@ -142,11 +136,11 @@ function hidePlot(plotId: string): void {
142136 const smallPlots = getSmallPlots ( ) ;
143137
144138 const ind = findIndex ( plotId , smallPlots ) ;
145- if ( ind < 0 ) {
139+ if ( ind < 0 ) {
146140 return ;
147141 }
148142
149- if ( smallPlots [ ind ] . classList . contains ( 'active' ) ) {
143+ if ( smallPlots [ ind ] . classList . contains ( 'active' ) ) {
150144 largePlotDiv . innerHTML = '' ;
151145 }
152146
@@ -155,8 +149,8 @@ function hidePlot(plotId: string): void {
155149
156150function findIndex ( plotId : string , smallPlots ?: Element [ ] ) : number {
157151 smallPlots ||= getSmallPlots ( ) ;
158- const ind = smallPlots . findIndex ( elm => elm . getAttribute ( 'plotId' ) === String ( plotId ) ) ;
159- if ( ind < 0 ) {
152+ const ind = smallPlots . findIndex ( ( elm ) => elm . getAttribute ( 'plotId' ) === String ( plotId ) ) ;
153+ if ( ind < 0 ) {
160154 console . warn ( `plotId not found: ${ plotId } ` ) ;
161155 }
162156 return ind ;
@@ -173,7 +167,7 @@ function togglePreviewPlotLayout(newStyle: PreviewPlotLayout): void {
173167
174168function toggleFullWindowMode ( useFullWindow : boolean ) : void {
175169 isFullWindow = useFullWindow ;
176- if ( useFullWindow ) {
170+ if ( useFullWindow ) {
177171 document . body . classList . add ( 'fullWindow' ) ;
178172 window . scrollTo ( 0 , 0 ) ;
179173 } else {
@@ -191,12 +185,10 @@ window.onload = () => {
191185 postResizeMessage ( true ) ;
192186} ;
193187
194-
195188////
196189// Resize bar
197190////
198191
199-
200192document . addEventListener ( 'mousedown' , ( e ) => {
201193 // If mousedown event is fired from .handler, toggle flag to true
202194 if ( ! isFullWindow && e . target === handler ) {
@@ -227,7 +219,7 @@ document.addEventListener('mousemove', (e) => {
227219 const newHeight = Math . max ( largePlotMinHeight , pointerRelativeYpos - 5 ) ; // <- why 5?
228220 const newHeightString = `${ newHeight } px` ;
229221
230- if ( largePlotDiv . style . height !== newHeightString ) {
222+ if ( largePlotDiv . style . height !== newHeightString ) {
231223 largePlotDiv . style . height = newHeightString ;
232224 postResizeMessage ( ) ;
233225 }
@@ -237,11 +229,10 @@ window.onresize = () => postResizeMessage();
237229
238230document . addEventListener ( 'mouseup' , ( ) => {
239231 // Turn off dragging flag when user mouse is up
240- if ( isHandlerDragging ) {
232+ if ( isHandlerDragging ) {
241233 postResizeMessage ( true ) ;
242234 document . body . style . cursor = '' ;
243235 }
244236 handler . classList . remove ( 'dragging' ) ;
245237 isHandlerDragging = false ;
246238} ) ;
247-
0 commit comments