Board index FlightGear Development Canvas

Plot2D and graph helpers

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Plot2D and graph helpers

Postby rleibner » Thu Dec 28, 2017 5:01 pm

I'm moving here the discussion we begun at the Spoken GCA topic

Hooray wrote in Thu Dec 28, 2017 1:44 pm: it would seem pretty straightforward to show a Canvas UI dialog and let people configure the axes/properties using a simple "UI"
May be the more useful will be to create a new FGoscilloscope addon and move there the plot2D and graph files. At least for the testing and debugging times.

As a real oscilloscope, it should have 2 (or more) Channels each one linked to a property and having a Gain and Offset adjustments.
For the customization, may be a tabbed-UI (a General tab for screen size, axes config, etc. and some others Channel tabs for color, propNode, gain, offset...).
Or may be an UI based on your Canvas Menubar?

Later we can add a Trigger input to let us store and plot the historic data.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Thu Dec 28, 2017 5:10 pm

Depending on what you are having in mind, you will find that the Canvas GUI API is lacking many widgets that would be useful:

http://wiki.flightgear.org/Canvas_Widget_Matrix
http://wiki.flightgear.org/Howto:Creati ... GUI_Widget

Thus, you would end up using either a conventional PUI dialog, or create custom widgets from scratch.

Alternatively, a good/better workaround may be to use a raster image and register event listeners, to show an embedded canvas with the actual graph - that is an approach that F-JJTH originally came up with. Basically, you'd have a "shell" with controls (think widgets) and an inner canvas showing the actual graph, which is accomplished using clipping (you can treat another canvas as a raster image and place it in an outer canvas) - for example, the red area is treated as a screen region, where the instrument is displayed, whereas the outer area is just a conventional raster image that responds to "events" to set up the instrument/oscilloscope):

Image

Note that this would make it possible to have all sorts of custom "skins" (think themes) for your "oscilloscope" - if that's what you are having in mind, i.e. without having to create any missing GUI widgets from scratch, and also without having to use the legacy PUI engine.

It also seems that there is quite a bit of existing artwork available at wikimedia commons:
https://commons.wikimedia.org/w/index.p ... zi0zvzb9rk
Image


If that's something that you'd like to explore, the relevant pointers are these:


PS: obviously, the "skin" could just as well be an SVG/vector image, too - I once shared code demonstrating how to make the svg parser deal with raster images, too: http://wiki.flightgear.org/Howto:Extend ... SVG_module
I am not sure though, If I would necessarily use the "FG" prefix for most addons, because the existing ones don't seem to be using one neither, and FG addons are FG specific anyway...
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Sat Jan 06, 2018 3:19 pm

Oscilloscope is working.
This screenshot shows the usual c172p "magnetos checking" :
Image
Channel 1 (yellow) is rpm (100 rpm / div).
Channel 2 (mauve) is magnetos (1 / div).
Time sweep is 200 ms / div.

The idea is to share it as an addon. Mainly to have some feedback about plot2D/graph.
But I found an issue when loading the skin image:
Code: Select all
skin = root.createChild("image").set("src", "osc2.png");
it only works when the png file is located under the $FG-ROOT or $FG-HOME folders !
Should I include some code into the main.nas in order to move the png to $FG-HOME ?
I unsuccessfully tried:
Code: Select all
  var path = getprop("/sim/fg-home") ~ '/osc2.png';
  var img = io.readfile(root ~ "/osc2.png");
  var file = io.open(path,"w");
  io.write(file, img);
  io.close(file);
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Sat Jan 06, 2018 4:08 pm

Just briefly, and also just a guess:
  • copying the file like you tried won't work
  • are you sure that you are using the correct path, I believe there is a property for each addon that contains the correct path for the addon ?
  • are you seeing any warnings/error messages in the console when trying to access the file from an addon-specific path (fgfs.log) ?
  • have you tried explicitly adding to $FG_ROOT/Nasal/IORules (wiki!) to see if the problem is security related ?

Apart from that, I think slawekmikula also noticed similar issues when he was doing some addon related work - I believe it was Florent (rominet) who fixed the underlying C++ code - there is the equivalent of a C++ API that looks up base package and aircraft/fg_home resources, and some of these APIs may not yet have been updated to support the addon use-case presumably.


PS: That's once again looking pretty cool already !
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Sat Jan 06, 2018 7:47 pm

In the meantime, I've just updated the addon "as it is". Please see the included Readme.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Sun Jan 07, 2018 7:00 pm

I do think that it is the right way to have a setter() method that sets a callback to update the values used in a plot, but like I mentioned previously, I would also make the update semantics configurable - as in, either clearing the previous set of points completely, or appending the new data to the previous plot.

By the way, using a callback for the update also means, that it would be trivial to provide helper functions that builds the vector with the updated data from different sources, for example:
  • properties
  • API calls
  • CSV (comma separated values)
  • I/O protocols

By the way, having a way to make log10/non-linear scales for an axis might be useful, what do you think ?
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Wed Jan 10, 2018 12:16 am

The new skinnable class includes:
members
    * skinnable.window
    * skinnable.canvas
    * skinnable.root
methods
    * skinnable.new(size) : size as [width, height]
    * skinnable.addSkin(filename)
    * skinnable.pickClickCoords() : to be called at designing time only!

It allows as many skin-layers as you want.
There's not a dedicated wiki page yet, but the Oscilloscope's code shows how to use it.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Wed Jan 10, 2018 1:46 am

That looks pretty good to me, I would definitely suggest to review your existing code to see if there is anything else that could be generalized and moved into that helper class - e.g. having a helper for "hotspots" - the skinnable class could then maintain a vector of hotspots, that would work analogous to your current hash. Maybe in conjunction with an optional tooltip string and mouse-over effect (callback). Having a way to respond to the click event of the hotspot would even allow people to animate their hotspots while they are being clicked (think, pressed buttons).

PS: Some of your other helper modules may be better off being moved into $FG_ROOT/Nasal/canvas meanwhile - and that may include the skinnable class when it is finished.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Wed Jan 17, 2018 10:38 pm

Here I am again :D
Among tons of things I've loose (domestic sceneries, useful scripts, codes on which I was working, etc), I can't remember my username and password for the SF commits.
Must I write to the devel-list?
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Wed Jan 17, 2018 11:15 pm

no, they cannot help you - you will need to go to the sourceforge login and click on "password forgotten" (or something along those lines), to have a new one (reset link) sent to you.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Sat Jan 20, 2018 10:23 pm

Now the Oscilloscope channels do accepts not only Properties but callback functions too:
Example:
Code: Select all
var Osc = oscilloscope.show.new();
var myFunc = func {return 10+4*math.sin(D2R*int(100*systime()));};
Osc.setChannelInput(1, myFunc);
Osc.setChannelInput(2,'controls/engines/engine/magnetos');
Osc.setGain(channel:1, gain:2);

Image Great when you manage the instrument from a script (as above).
But you can also work interactively, by pressing the buttons and clicking the connectors ... and here is a handicap that I did not know how to solve:
Clicking the connector (CH-1 or CH-2) opens an Input Dialog, if I enter /engines/engine/rpm it works fine.

But how can I "parse" the entered string in order to allow (p.example) myFunc, or even func{return 2*foo;} ?
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Sat Jan 20, 2018 10:31 pm

Not sure I understand your question correctly - do you want to support some custom "code" or only valid nasal code ?
If it is the latter, I suggested to read up on the compile() and call() APIs (see the wiki for details).
If you'd like to support your own custom syntax, you would need to write a parser of your own (not sure if it's worth the hassle though).
That being said, my suggest would be to design the lowest level API so that it deals with a vector of values, and provide higher-level wrappers for function calls/properties - simply because a property is basically a func getprop("foo") -> thus, doing this in a loop can be used to populate a vector.

Anyway, if you'd like to support Nasal code, you will want to read up on the compile() and call() functions:

http://wiki.flightgear.org/Nasal_library#compile.28.29
http://wiki.flightgear.org/Nasal_library#call.28.29
http://wiki.flightgear.org/Nasal_library#bind.28.29
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Thu Jan 25, 2018 9:06 pm

Hooray wrote in Sat Jan 20, 2018 10:31 pm:do you want to support some custom "code" or only valid nasal code ?
The latter. And it's done (using compile() ).

Hooray wrote in Sat Jan 20, 2018 10:31 pm: my suggest would be to design the lowest level API so that it deals with a vector of values, and provide higher-level wrappers for function calls/properties
I'm not sure I understand your point:
At it is, setPlotProperty() and plotProperty() do plot a property (or a function) vs. time.
For plotting a vector of values we have the generic plot2D.graphic().
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Plot2D and graph helpers

Postby Hooray » Thu Jan 25, 2018 9:30 pm

sounds good to me - my point was merely that higher-level methods (for properties or functions) would ultimately end up using the function that processes a vector of values.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Plot2D and graph helpers

Postby rleibner » Thu Jan 25, 2018 10:01 pm

About legal stuff:
The skin image that I'm using in Oscilloscope is from my own. There's not such oscilloscope ITRW.
However I was inspired in a known instrumment's brand. (for aesthetic, control positions, aspect ...) and modified (a lot) the original image.
Do you think we must ask for an explicit permission ?

The original
... and mine
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 269
Joined: Fri May 19, 2017 8:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 5 guests