Reloading web page

If doesn't fit into any other category ....
Post Reply
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Reloading web page

Post by BeanieBots »

I've been playing around with alternative graphing sources because Firefox (my preferred browser) has issues with Google charts, Chartjs does not have a gauge chart etc. etc.
I found echarts which, with a little trial and error seems to do it all but at the expense of significant configuration.
That said, I've come across an issue which I have been unable to resolve.

To do the testing, I've been using two computers. One simply having the output page open in Firefox, the other being used to edit code.
For testing, the code has some basic html, a little script to configure the chart and another script to randomly update the chart.
This was working well and as expected until I tried to implement 'onhtmlreload'. I'll do my best to describe the issue.

Scenario:
Computer 1 being used to edit.
Computer 2 showing output page.
Compuer 1 switched to show output page -> Computer 2 now has two instances of the random number generator running.
Press F5 on computer 2. Computer 2 now OK but computer 1 has two instances of the script.

I tried to seperate out the script which now gives only one instance but (obviously) NO instance on first load.
Is there any way around the problem?
In 'real life' it will be Annex BASIC doing the updates, so probably not a real problem but might be if I ty to implement any data manipulation scripts.

Example that exhibits the issue.

Code: [Local Link Removed for Guests]


onhtmlreload Reload
Gosub LoadPage
Gosub LoadScript
wait
'----------------------------------------------------------------------
Reload:
Gosub LoadPage
'Gosub LoadScript
Return
'----------------------------------------------------------------------
LoadPage:
jsexternal "https://fastly.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"
pause 500
cls
A$ = ||
A$ = A$ + ||
A$ = A$ + |<!DOCTYPE html>|
A$ = A$ + |<html lang="en" style="height: 100%">|
A$ = A$ + |<head>|
A$ = A$ + |  <meta charset="utf-8">|
A$ = A$ + |</head>|
A$ = A$ + |<body style="height: 100%; margin: 2">|
A$ = A$ + |  <div id="myChart" style="height: 100%"></div>|
A$ = A$ + |</body>|
A$ = A$ + |</html>|
html a$

B$ = ||
B$ = B$ + |var chartDom = document.getElementById('myChart');|
B$ = B$ + |var myChart = echarts.init(chartDom, 'dark');|
B$ = B$ + |var option;|
B$ = B$ + ||
B$ = B$ + |option = {|
B$ = B$ + |  series: [|
B$ = B$ + |    {|
B$ = B$ + |      type: 'gauge',|
B$ = B$ + |      axisLine: {|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          width: 30,|
B$ = B$ + |          color: [|
B$ = B$ + |            [0.3, '#67e0e3'],|
B$ = B$ + |            [0.7, '#37a2da'],|
B$ = B$ + |            [1, '#fd666d']|
B$ = B$ + |          ]|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      pointer: {|
b$ = b$ + |        width: 30,|
b$ = b$ + |        length: '90%',|
b$ = b$ + |        icon: 'path://M7 0C6 4 0 4 0 7 0 9 1 8 3 7 6 6 5 4 5 11L5 43C5 45 9 45 9 43L9 11C9 4 8 6 11 7 13 8 14 9 14 7 14 4 8 4 7 0Z',|
B$ = B$ + |        itemStyle: {|
'B$ = B$ + |          color: 'inherit'|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      axisTick: {|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        length: 8,|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          color: '#fff',|
B$ = B$ + |          width: 2|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      splitLine: {|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        length: 30,|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          color: '#fff',|
B$ = B$ + |          width: 4|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      axisLabel: {|
B$ = B$ + |        color: 'inherit',|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        fontSize: 20|
B$ = B$ + |      },|
B$ = B$ + |      detail: {|
B$ = B$ + |        valueAnimation: true,|
B$ = B$ + |        formatter: '{value} %',|
B$ = B$ + |        color: 'inherit'|
B$ = B$ + |      },|
B$ = B$ + |      data: [|
B$ = B$ + |        {|
B$ = B$ + |          value: 73,|
b$ = b$ + |          name: 'Data Name'|
B$ = B$ + |        }|
B$ = B$ + |      ]|
B$ = B$ + |    }|
B$ = B$ + |  ]|
B$ = B$ + |};|
jscript b$
Pause 500
b$=""
jscript "myChart.setOption(option);"
Return
'----------------------------------------------------------------------
LoadScript:
B$ = B$ + |setInterval(function () {|
B$ = B$ + |  myChart.setOption({|
B$ = B$ + |    series: [|
B$ = B$ + |      {|
B$ = B$ + |        data: [|
B$ = B$ + |          {|
B$ = B$ + |            value: +(Math.random() * 100).toFixed(1)|
B$ = B$ + |          }|
B$ = B$ + |        ]|
B$ = B$ + |      }|
B$ = B$ + |    ]|
B$ = B$ + |  });|
B$ = B$ + |}, 3000);|
B$ = B$ + ||
B$ = B$ + |option && myChart.setOption(option);|
B$ = B$ + ||
jscript b$
'jscript "option && myChart.setOption(option);"
'jscript "myChart.setOption(option);"
Return
User avatar
cicciocb
Site Admin
Posts: 2092
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 448 times
Been thanked: 1385 times
Contact:

Re: Reloading web page

Post by cicciocb »

You just need to stop the 'setInterval' function using 'clearInterval' in javascript

try this code :

Code: [Local Link Removed for Guests]


onhtmlreload Reload
Gosub LoadPage
Gosub LoadScript
wait
'----------------------------------------------------------------------
Reload:
Gosub LoadPage
Gosub LoadScript
Return
'----------------------------------------------------------------------
LoadPage:
jsexternal "https://fastly.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"
pause 500
cls
A$ = ||
A$ = A$ + ||
A$ = A$ + |<!DOCTYPE html>|
A$ = A$ + |<html lang="en" style="height: 100%">|
A$ = A$ + |<head>|
A$ = A$ + |  <meta charset="utf-8">|
A$ = A$ + |</head>|
A$ = A$ + |<body style="height: 100%; margin: 2">|
A$ = A$ + |  <div id="myChart" style="height: 100%"></div>|
A$ = A$ + |</body>|
A$ = A$ + |</html>|
html a$

B$ = ||
B$ = B$ + |var chartDom = document.getElementById('myChart');|
B$ = B$ + |var myChart = echarts.init(chartDom, 'dark');|
B$ = B$ + |var option;|
B$ = B$ + ||
B$ = B$ + |option = {|
B$ = B$ + |  series: [|
B$ = B$ + |    {|
B$ = B$ + |      type: 'gauge',|
B$ = B$ + |      axisLine: {|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          width: 30,|
B$ = B$ + |          color: [|
B$ = B$ + |            [0.3, '#67e0e3'],|
B$ = B$ + |            [0.7, '#37a2da'],|
B$ = B$ + |            [1, '#fd666d']|
B$ = B$ + |          ]|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      pointer: {|
b$ = b$ + |        width: 30,|
b$ = b$ + |        length: '90%',|
b$ = b$ + |        icon: 'path://M7 0C6 4 0 4 0 7 0 9 1 8 3 7 6 6 5 4 5 11L5 43C5 45 9 45 9 43L9 11C9 4 8 6 11 7 13 8 14 9 14 7 14 4 8 4 7 0Z',|
B$ = B$ + |        itemStyle: {|
'B$ = B$ + |          color: 'inherit'|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      axisTick: {|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        length: 8,|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          color: '#fff',|
B$ = B$ + |          width: 2|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      splitLine: {|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        length: 30,|
B$ = B$ + |        lineStyle: {|
B$ = B$ + |          color: '#fff',|
B$ = B$ + |          width: 4|
B$ = B$ + |        }|
B$ = B$ + |      },|
B$ = B$ + |      axisLabel: {|
B$ = B$ + |        color: 'inherit',|
B$ = B$ + |        distance: -30,|
B$ = B$ + |        fontSize: 20|
B$ = B$ + |      },|
B$ = B$ + |      detail: {|
B$ = B$ + |        valueAnimation: true,|
B$ = B$ + |        formatter: '{value} %',|
B$ = B$ + |        color: 'inherit'|
B$ = B$ + |      },|
B$ = B$ + |      data: [|
B$ = B$ + |        {|
B$ = B$ + |          value: 73,|
b$ = b$ + |          name: 'Data Name'|
B$ = B$ + |        }|
B$ = B$ + |      ]|
B$ = B$ + |    }|
B$ = B$ + |  ]|
B$ = B$ + |};|
jscript b$
Pause 500
b$=""
jscript "myChart.setOption(option);"
Return
'----------------------------------------------------------------------
LoadScript:
B$ = ""
B$ = B$ + |if (typeof myInterval != 'undefined') clearInterval(myInterval);|
B$ = B$ + |var myInterval = setInterval(function () {|
B$ = B$ + |  myChart.setOption({|
B$ = B$ + |    series: [|
B$ = B$ + |      {|
B$ = B$ + |        data: [|
B$ = B$ + |          {|
B$ = B$ + |            value: +(Math.random() * 100).toFixed(1)|
B$ = B$ + |          }|
B$ = B$ + |        ]|
B$ = B$ + |      }|
B$ = B$ + |    ]|
B$ = B$ + |  });|
B$ = B$ + |}, 3000);|
B$ = B$ + ||
B$ = B$ + |option && myChart.setOption(option);|
B$ = B$ + ||
jscript b$
'jscript "option && myChart.setOption(option);"
'jscript "myChart.setOption(option);"
Return
I suggest you to use canvas-gauges.js
https://canvas-gauges.com/
https://github.com/Mikhus/canvas-gauges
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Reloading web page

Post by BeanieBots »

You just need to stop the 'setInterval' function using 'clearInterval' in javascript
:)
You say that like I have a clue ;)
None-the-less, it now works fine. Thanks.

I tried 'canvas-gauges' a while ago and again just now. Even their example page still has the same problem when used with Firefox.
After a short while, a gauge which is fequently updated suddenly starts to render with its center in the top left of the canvas.
Works fine in Edge.

Try this in Firefox:- (click 'animate' to see the problem)
https://rawgit.com/Mikhus/canvas-gauges ... onent.html
User avatar
cicciocb
Site Admin
Posts: 2092
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 448 times
Been thanked: 1385 times
Contact:

Re: Reloading web page

Post by cicciocb »

I see the problem.
Unfortunately Firefox is becoming slowly "out of standard" with the standard dictated by the "chromium" core.
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Reloading web page

Post by BeanieBots »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Jun 25, 2023 4:23 pm Unfortunately Firefox is becoming slowly "out of standard" with the standard dictated by the "chromium" core.
Indeed, that combined with it not supporting serial is making me re-consider my browser of choice :(

Essentially, I'm after a gauge which can have three needles and be very customisable. In particular, to avoid crowding, one of the needles needs to be either on the outer ring or possibly outside pointing in. I've considered using something like 'canvas-gauges' with multiple instances on top of each other but don't really know how feasable that is without trying it. The same page will also need a line graph. Not sure if it's a real issue but I was trying to avoid needing a whole bunch of jsexternal lines.

echarts, although a bit large and combersome (about 1Mb if downloaded as .min.js), does appear to be a one-stop-shop with everything you could ever desire in just about every type of chart. The documentation and examples are also very comprehensive.

The basic but very easy to use .min.js.gz files that come with Annex are just a bit too basic for what I'm trying to do.
Do you have any thoughts about RGraph? Their gauge has a very nice feature 'adjustable=true' which allows you to drag and drop the needle with a mouse pointer. A bit like a very fancy 'knob'. It also supports multiple needles. Ideal for a project requiring 'setpoint' and 'actual' to be shown on the same gauge. Or maybe an old-school type barometer with 'now' and 'three hours ago'. (and it works with Firefox!).
User avatar
cicciocb
Site Admin
Posts: 2092
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 448 times
Been thanked: 1385 times
Contact:

Re: Reloading web page

Post by cicciocb »

BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Reloading web page

Post by BeanieBots »

Not yet.
I'll have a go tomorrow and post the results.
User avatar
cicciocb
Site Admin
Posts: 2092
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 448 times
Been thanked: 1385 times
Contact:

Re: Reloading web page

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Jun 25, 2023 6:02 pm
echarts, although a bit large and combersome (about 1Mb if downloaded as .min.js), does appear to be a one-stop-shop with everything you could ever desire in just about every type of chart. The documentation and examples are also very comprehensive.

The basic but very easy to use .min.js.gz files that come with Annex are just a bit too basic for what I'm trying to do.
Do you have any thoughts about RGraph? Their gauge has a very nice feature 'adjustable=true' which allows you to drag and drop the needle with a mouse pointer. A bit like a very fancy 'knob'. It also supports multiple needles. Ideal for a project requiring 'setpoint' and 'actual' to be shown on the same gauge. Or maybe an old-school type barometer with 'now' and 'three hours ago'. (and it works with Firefox!).
The libraries I included aims to be hosted directly in the chip itself, so the (little) size is important.
If your browser has access to internet, there are no particular limits on the number and the size of the libraries.

If you plan to use the project in an isolated network, then you could compress the library using gzip
BeanieBots
Posts: 351
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 187 times
Been thanked: 113 times

Re: Reloading web page

Post by BeanieBots »

I think (and plan to try) that echarts could be fully hosted even on a ESP8266.
They have a "builder" which can be used to just build the bits that you need.
https://echarts.apache.org/en/builder.html
By combining that with your suggestion of using gzip it should come down to a more manageable size.
I'll have a go and report back my findings. Might not be until next week though.

I didn't get a chance to try the canvas-gauge work-around but reading further it sounds like it is bit of a memory-leak issue in that the browser cache keeps growing with each update. Something to look out for.

I found that even echarts has an issue with Firefox. If you select svg for the render (which IMHO gives a sharper image, especially text) sometimes the render is incomplete. Particularly noticeable with a gauge that has a needle which points below the horizontal. It actually dissapears completely!
Post Reply