|
11 | 11 | } |
12 | 12 | .blink{ |
13 | 13 | color:red; |
14 | | - text-decoration: blink; |
15 | | - -webkit-animation-name: blinker; |
16 | | - -webkit-animation-duration: 0.6s; |
17 | | - -webkit-animation-iteration-count:infinite; |
18 | | - -webkit-animation-timing-function:ease-in-out; |
19 | | - -webkit-animation-direction: alternate; |
| 14 | + text-decoration: blink; |
| 15 | + -webkit-animation-name: blinker; |
| 16 | + -webkit-animation-duration: 0.6s; |
| 17 | + -webkit-animation-iteration-count:infinite; |
| 18 | + -webkit-animation-timing-function:ease-in-out; |
| 19 | + -webkit-animation-direction: alternate; |
20 | 20 | } |
21 | 21 | html, body{ |
22 | 22 | margin:0 auto; |
|
71 | 71 | background-color:yellow; |
72 | 72 | cursor:pointer; |
73 | 73 | } |
74 | | -.controlBox{ |
75 | | - margin: 10px; |
76 | | - background-color: antiquewhite; |
77 | | - font-size: initial; |
78 | | - overflow:hidden; |
79 | | - display:none; |
80 | | -} |
81 | 74 | </style> |
82 | 75 | <script src="https://code.jquery.com/jquery-3.2.1.js"></script> |
83 | 76 | <body> |
84 | 77 | <p id="linkBar"><a class="systemLink" href="/">HOME</a></p> |
85 | 78 | <h1 id="hostName">ESP8266-temp-server</h1> |
86 | 79 | <div id="graphContainer"> |
87 | 80 | <canvas class="" id="editorCanvas" width="800px" height="400px"></canvas> |
88 | | -<div id="fileList" class=" controlBox"></div> |
| 81 | +<div id="fileList"></div> |
89 | 82 | </div> |
90 | 83 | <script> |
91 | | -//const hostName = 'http://192.168.0.182'; //debug/develop |
92 | | -const hostName = ''; |
93 | | - |
| 84 | +const hostName = 'http://192.168.0.182'; //debug/develop |
| 85 | +//const hostName = ''; |
94 | 86 | $( document ).ready( function() { |
95 | | - editorCanvas.width = editorCanvas.width; |
96 | | - if ( hostName ) $('#hostName').append( '<p class="blink">!!!!!debug enabled!!!!!</p>'); |
97 | | - $.get( hostName + '/files', function( data ) |
| 87 | + editorCanvas.width = editorCanvas.width; |
| 88 | + if ( hostName ) $('#hostName').append( '<p class="blink">!!!!!debug enabled!!!!!</p>'); |
| 89 | + $.get( hostName + '/files', function( data ) |
| 90 | + { |
| 91 | + var fileArray = data.split('\n'); |
| 92 | + fileArray.sort(); |
| 93 | + for ( f = 0; f < fileArray.length; f++ ) |
| 94 | + if ( fileArray[f].endsWith( '.log' ) ) $('#fileList').append( '<div class="logFile">'+ fileArray[f].substring( 1, 11 ) + "</div>" ); |
| 95 | + if ( !$('.logFile').length ) |
| 96 | + $('#loaderBox').html( "NO LOGS FOUND" ); |
| 97 | + else |
98 | 98 | { |
99 | | - var fileArray = data.split('\n'); |
100 | | - fileArray.sort(); |
101 | | - for ( f = 0; f < fileArray.length; f++ ) |
102 | | - { |
103 | | - if ( fileArray[f].endsWith( '.log' ) ) $('#fileList').append( '<div class="logFile">'+ fileArray[f].substring( 1, 11 ) + "</div>" ); |
104 | | - } |
105 | | - if ( !$('.logFile').length ) |
106 | | - $('#loaderBox').html( "NO LOGS FOUND" ); |
107 | | - else |
108 | | - { |
109 | | - $('#loaderBox').hide(); |
110 | | - $('#editorCanvas, #sideBox, .controlBox').show(); |
111 | | - $('.logFile').last().click(); |
112 | | - } |
113 | | - }); |
| 99 | + $('#loaderBox').hide(); |
| 100 | + $('#editorCanvas, #sideBox, .controlBox').show(); |
| 101 | + $('.logFile').last().click(); |
| 102 | + } |
| 103 | + }); |
114 | 104 | }); |
115 | | - |
116 | 105 | $('#fileList').on('click','.logFile',function() |
117 | 106 | { |
118 | | - var url = hostName + "/" + $(this).text() + ".log"; |
119 | | - var timeVal=[]; |
120 | | - var tempVal=[]; |
121 | | - var maxTemp, minTemp; |
122 | | - $.get( url, function( data ) |
| 107 | + var url = hostName + "/" + $(this).text() + ".log"; |
| 108 | + var timeVal=[]; |
| 109 | + var tempVal=[]; |
| 110 | + var maxTemp, minTemp; |
| 111 | + $.get( url, function( data ) |
| 112 | + { |
| 113 | + var measurements = data.split('\n'); |
| 114 | + measurements.forEach( function( item, index ) |
123 | 115 | { |
124 | | - var measurements = data.split('\n'); |
125 | | - measurements.forEach( function( item, index ) |
126 | | - { |
127 | | - if (item) |
128 | | - { |
129 | | - var temp = item.split(','); |
130 | | - if ( temp[0] && temp[1] && temp[1].length < 8 ) |
131 | | - { |
132 | | - var date = new Date( parseInt(temp[0]) * 1000 ); |
133 | | - var secondsToday = date.getHours() * 3600; |
134 | | - secondsToday += date.getMinutes() * 60; |
135 | | - secondsToday += date.getSeconds(); |
136 | | - timeVal.push(secondsToday); |
137 | | - tempVal.push(parseFloat(temp[1])); |
138 | | - } |
139 | | - } |
140 | | - }); |
141 | | - maxTemp = Math.max.apply(null,tempVal) + 1; |
142 | | - minTemp = Math.min.apply(null,tempVal) - 1; |
143 | | - //console.log("min:"+minTemp + " max:"+maxTemp) |
144 | | - if ( isNaN(minTemp) || isNaN(maxTemp) ) |
| 116 | + if (item) |
| 117 | + { |
| 118 | + var temp = item.split(','); |
| 119 | + if ( temp[0] && temp[1] && temp[1].length < 8 ) |
145 | 120 | { |
146 | | - const ctx = editorCanvas.getContext( "2d" ); |
147 | | - ctx.clearRect(0, 0, editorCanvas.width, editorCanvas.height); |
148 | | - return; |
| 121 | + var date = new Date( parseInt(temp[0]) * 1000 ); |
| 122 | + var secondsToday = date.getHours() * 3600; |
| 123 | + secondsToday += date.getMinutes() * 60; |
| 124 | + secondsToday += date.getSeconds(); |
| 125 | + timeVal.push(secondsToday); |
| 126 | + tempVal.push(parseFloat(temp[1])); |
149 | 127 | } |
150 | | - drawBackground( minTemp, maxTemp); |
151 | | - //draw the actual values |
152 | | - var ctx = editorCanvas.getContext( "2d" ); |
153 | | - ctx.strokeStyle = 'rgba( 255, 0, 0, 1)'; |
154 | | - ctx.setLineDash([]); |
155 | | - ctx.beginPath(); |
156 | | - timeVal.forEach( function( item, index ) |
157 | | - { |
158 | | - var x = map( item, 0, 86400, 0, editorCanvas.width ); |
159 | | - var y = map( tempVal[index], minTemp, maxTemp, editorCanvas.height, 0 ); |
160 | | - ctx.lineTo( x, y ); |
161 | | - }); |
162 | | - ctx.stroke(); |
| 128 | + } |
| 129 | + }); |
| 130 | + maxTemp = Math.trunc( Math.max.apply(null,tempVal) + 2 ); |
| 131 | + minTemp = Math.trunc( Math.min.apply(null,tempVal) - 2 ); |
| 132 | + //console.log("min:"+minTemp + " max:"+maxTemp) |
| 133 | + if ( isNaN(minTemp) || isNaN(maxTemp) ) |
| 134 | + { |
| 135 | + const ctx = editorCanvas.getContext( "2d" ); |
| 136 | + ctx.clearRect(0, 0, editorCanvas.width, editorCanvas.height); |
| 137 | + return; |
| 138 | + } |
| 139 | + drawBackground( minTemp, maxTemp); |
| 140 | + //draw the actual values |
| 141 | + var ctx = editorCanvas.getContext( "2d" ); |
| 142 | + ctx.strokeStyle = 'rgba( 255, 0, 0, 1)'; |
| 143 | + ctx.setLineDash([]); |
| 144 | + ctx.beginPath(); |
| 145 | + timeVal.forEach( function( item, index ) |
| 146 | + { |
| 147 | + var x = map( item, 0, 86400, 0, editorCanvas.width ); |
| 148 | + var y = map( tempVal[index], minTemp, maxTemp, editorCanvas.height, 0 ); |
| 149 | + ctx.lineTo( x, y ); |
163 | 150 | }); |
| 151 | + ctx.stroke(); |
| 152 | + }); |
164 | 153 | }); |
165 | | - |
166 | 154 | function drawBackground(minTemp,maxTemp ) |
167 | 155 | { |
168 | 156 | const opacity = 0.3; |
|
0 commit comments