@@ -5,12 +5,21 @@ class Chart {}
55const canvas = document . getElementById ( "canvas" ) ;
66const coord = document . getElementById ( "coord" ) ;
77const plotType = document . getElementById ( "plot-type" ) ;
8+ const pitch = document . getElementById ( "pitch" ) ;
9+ const yaw = document . getElementById ( "yaw" ) ;
10+ const control = document . getElementById ( "3d-control" ) ;
811const status = document . getElementById ( "status" ) ;
912
1013let chart = null ;
1114
1215/** Main entry point */
1316export function main ( ) {
17+ let hash = location . hash . substr ( 1 ) ;
18+ for ( var i = 0 ; i < plotType . options . length ; i ++ ) {
19+ if ( hash == plotType . options [ i ] . value ) {
20+ plotType . value = hash ;
21+ }
22+ }
1423 setupUI ( ) ;
1524 setupCanvas ( ) ;
1625}
@@ -24,6 +33,10 @@ export function setup(WasmChart) {
2433function setupUI ( ) {
2534 status . innerText = "WebAssembly loaded!" ;
2635 plotType . addEventListener ( "change" , updatePlot ) ;
36+ yaw . addEventListener ( "change" , updatePlot ) ;
37+ pitch . addEventListener ( "change" , updatePlot ) ;
38+ yaw . addEventListener ( "input" , updatePlot ) ;
39+ pitch . addEventListener ( "input" , updatePlot ) ;
2740 window . addEventListener ( "resize" , setupCanvas ) ;
2841 window . addEventListener ( "mousemove" , onMouseMove ) ;
2942}
@@ -58,6 +71,13 @@ function onMouseMove(event) {
5871 }
5972}
6073
74+ function updatePlot3d ( ) {
75+ let yaw_value = Number ( yaw . value ) / 100.0 ;
76+ let pitch_value = Number ( pitch . value ) / 100.0 ;
77+ Chart . plot3d ( canvas , pitch_value , yaw_value ) ;
78+ coord . innerText = `Pitch:${ pitch_value } , Yaw:${ yaw_value } `
79+ }
80+
6181/** Redraw currently selected plot. */
6282function updatePlot ( ) {
6383 const selected = plotType . selectedOptions [ 0 ] ;
@@ -66,24 +86,18 @@ function updatePlot() {
6686 const start = performance . now ( ) ;
6787 switch ( selected . value ) {
6888 case "mandelbrot" :
89+ control . classList . add ( "hide" ) ;
6990 chart = Chart . mandelbrot ( canvas ) ;
7091 break ;
71- case "3d-plot" : {
72- var yaw = 0 ;
73- var update = function ( ) {
74- if ( plotType . selectedOptions [ 0 ] . value != "3d-plot" )
75- return ;
76- Chart . plot3d ( canvas , yaw ) ;
77- yaw += 3.14 / 200 ;
78- setTimeout ( update , 50 ) ;
79- } ;
80- update ( ) ;
81- }
92+ case "3d-plot" :
93+ control . classList . remove ( "hide" ) ;
94+ updatePlot3d ( ) ;
8295 break ;
8396 default :
84- Chart . power ( "canvas" , Number ( selected . value ) )
97+ control . classList . add ( "hide" ) ;
98+ chart = Chart . power ( "canvas" , Number ( selected . value ) )
8599 }
86-
100+
87101 const end = performance . now ( ) ;
88102 status . innerText = `Rendered ${ selected . innerText } in ${ Math . ceil ( end - start ) } ms` ;
89103}
0 commit comments