Talk:How to manipulate Canvas elements: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎Graphic: new section)
 
Line 26: Line 26:
</syntaxhighlight>  
</syntaxhighlight>  
--[[User:Hooray|Hooray]] ([[User talk:Hooray|talk]]) 14:50, 5 December 2017 (EST)
--[[User:Hooray|Hooray]] ([[User talk:Hooray|talk]]) 14:50, 5 December 2017 (EST)
== Graphic ==
My suggestion would be rename "graphic" to "graph" or "graph2D" - and maybe consider using a wrapper class to make the 2 axes part of a helper, so that tic marks can be added to the graph more easily - otherwise, the function plotting the values would not even know where the surrounding axes are. That way, it would also be possible to not just accept a vector with data point, but also a callback that is to be executed to get a vector of values. And we could have a flag that specifies whether the new values are appended to the existing plot, or if they are to replace the plot. Higher level classes to do property plotting against time (or altitude) would also be easier to implement that way, because they could inherit from a single Graph2D class. --[[User:Hooray|Hooray]] ([[User talk:Hooray|talk]]) 15:29, 5 December 2017 (EST)

Latest revision as of 20:29, 5 December 2017

named arguments in examples ?

Hi there, fantastic job ! May I suggest that we use named function arguments, i.e. in the form:

var foo = func(altitude, label) {
}


foo(altitude:100, label:"hello world");

I feel that this would help make the code more self-explanatory, what do you think ? --Hooray (talk) 14:21, 5 December 2017 (EST)

plot2D namespace detection

I think, the following should work:

if (!canvas['plot2D']) {
 var root = getprop("/sim/fg-root");
 io.load_nasal( root ~ '/Nasal/plot2D.nas', "canvas" );
}

--Hooray (talk) 14:50, 5 December 2017 (EST)

Graphic

My suggestion would be rename "graphic" to "graph" or "graph2D" - and maybe consider using a wrapper class to make the 2 axes part of a helper, so that tic marks can be added to the graph more easily - otherwise, the function plotting the values would not even know where the surrounding axes are. That way, it would also be possible to not just accept a vector with data point, but also a callback that is to be executed to get a vector of values. And we could have a flag that specifies whether the new values are appended to the existing plot, or if they are to replace the plot. Higher level classes to do property plotting against time (or altitude) would also be easier to implement that way, because they could inherit from a single Graph2D class. --Hooray (talk) 15:29, 5 December 2017 (EST)