Would be good to add to the newnew %pl continuously adjustable smoothing of graph lines same way as very nicely in newnew %pl the antialiasing smoothing is done - you just click and see the effect. Something which with the slider you can adjust between link=lines and link=curves. I have no specific method in mind may be someone has an idea. The current default link=curves is too harshly smoothing everything very often causing severe distortions of lines compared to just linear interpolation between the points. In most my cases i can not use this option, specifically with the LOG plots, so i'm forced to use only simplest linear interpolation link=lines
Adjustable curve spline
Dan
I am not clear about what you are asking for. At the moment there are 5 possible values for [smoothing=v] and these are v=0 to v=5.
There are 5 possible settngs for [line=s] and these are s='none', s='lines', s='curves', s='columns', s='bars' and s='user'.
'lines' are straight lines. 'curves' are cardinal splines.
In theory you could set [lines=user] and then call draw_beziersD@ from a %pl callback function. But bezier splines are quite specialized and the control points and their number must be carefully chosen. The GDI+ function used in ClearWin+ for beziers is described here...
https://docs.microsoft.com/en-us/previous-versions//ms536147(v=vs.85).
p.s. I can't get the link to display correctly so a manual copy is required.
Dan
May be you could have a look to the Akima method of interpolation and smooth, which is quite 'soft', see Akima, H. (1970).* A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures*. Journal of the ACM, 17(4), pp. 589–602.
The link to the Bézier function used in GDI+ might be the following https://docs.microsoft.com/en-us/previous-versions/ms536147(v=vs.85) (v=vs.85) belongs to the URL, so use copy and paste.
Paul,
If the 'curves' are cardinal splines, is there any possibility of providing a setting for the “tension” parameter? I think that may be what Dan is looking for.
Ken and Dan
It would be possible to add a cardinal spline tension parameter.
Please let me know if that would be useful.
Paul,
This would certainly provide control over the path taken by [link=curves] and as such would be a valuable general addition to the %pl[native] functionality.
I have seen cases where the curve has “bowed out” and an increase in “tension” would have reduced that.
Ken
OK. It should be fairly easy to implement.
I think that the tension parameter is 1.0 by default and 0.0 gives maximum tension - a straight line.
Ken and Dan
I have added this feature and you can get new DLLs via the sticky post.
You can set the tension for each curve using...
CALL winop@('%pl[tension=1.0]')
The setting for [link=v] becomes redundant when tension is added.
tension=0.0 is the same as [link=lines].
I had assumed the tension=1.0 would be the same as [link=curves] but my tests do not confirm this.
Paul,
Thanks for this addition. A few quick tests confirm the expected responses (tests 2 and 3 below).
With n_graphs > 1 mixing the different approaches [link=lines/curves] and [tension=X] runs into problems (tests 4 and 5). Is this to be expected (and so mixing approaches avoided)?
For Dan’s “continuously adjustable smoothing of graph lines”, I wonder if the value of tension could be added to the parameters that can be changed by CHANGE_PLOT_DBL@ ?
!Tension test 05/05/2021
winapp
module test
use clrwin
implicit none
integer, parameter :: dp = kind(1.d0), n = 10
real(kind=dp) x_array(1:n), y_array(1:n)
integer :: npl(3) = n
contains
integer function plot()
integer iw
do iw = 1, n, 1 ; x_array(iw) = iw - 1 ; y_array(iw) = random@() ; end do
iw = winio@('Test 1&')
iw = winio@('%nl2 graphs %nlRED link=lines, BLUE link = curves&')
iw = winio@('%nlThis is the previous behaviour&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=lines,symbol=6]')
call winop@('%pl[colour=blue,link=curves]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 2&')
iw = winio@('%nl2 graphs, both have specified tension. %nlRED tension=0.0, BLUE tension=0.5&')
iw = winio@('%nlTension = 0 is equivalent to link=lines, and tension=0.5 is equivalent to link=curves&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,tension=0.0,symbol=6]')
call winop@('%pl[colour=blue,tension=0.5]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 3&')
iw = winio@('%nl3 graphs, all have specified tension&')
iw = winio@('%nlRED tension=0.0, BLUE tension=0.25, GREEN tension = 0.5&')
iw = winio@('%nlBlue curve has an intermediate tension between link=lines and link=curves&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=3]')
call winop@('%pl[colour=red,tension=0.0,symbol=6]')
call winop@('%pl[colour=blue,tension=0.25]')
call winop@('%pl[colour=green,tension=0.5]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 4&')
iw = winio@('%nl2 graphs, mixing link=lines and tension %nlRED link = lines, BLUE tension=0.0&')
iw = winio@('%nlRED line is correct, BLUE line is the same as previous link=curves, but should be like link=lines&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=lines,symbol=6]')
call winop@('%pl[colour=blue,tension=0.0]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 5&')
iw = winio@('%nl2 graphs, mixing link=curves and tension %nlRED link = curves, BLUE tension=0.0&')
iw = winio@('%nlRed is linked with lines instead of curves.&')
iw = winio@('Blue curve looks like tension=0.5 rather than tension=0&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=curves,symbol=6]')
call winop@('%pl[colour=blue,tension=0.0]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
plot = 1
end function plot
end module test
Thanks all for help, discussion and solutions,
Paul, this tension adjustment works exactly how i wanted it, you've done great job. Would be nice to add it to newest %pl (the Designer %pl how you call it?). Adjusting the smoothing with the slider for anyone liking would be great
The only major thing i'd change in the designer is how it is made to adjust the plot: the visual way where user clicks on picture (be it line or axis or title etc) and change parameters in the supplied popup box would be much better and faster and more pleasant to do! Here is a 'reference plot' what should pop first when user clicks on 'Adjust' icon

We users can make nicer example picture for it.
Other minor suggestions: after some testing i'd also add to Designer some switch of Linear to LOG plots, title and axis names change, font change and saving the plot into png and jpg formats - that would be almost all essential things which are now missing. And ESC has to be added to quit Designer mode. This new PL will be then a bomb !
UPDATE BTW, here is the text for snapshot i use with %PL. Filenames are automatically updated each time. Ideally this name has to be the same as in %pl[file=zDesignerPL.set... the 'DDrates.date.time.png' as in my case below so they will be easier to find among 1000s of others
use clrwin
integer, external :: SnapshotPL
parameter (N=6)
real*8 X(N), Y(N)
Data X/1., 1e1, 1e2, 1e3, 1e4, 1e5/
Data Y/0.01, 10.2, 1266, 8333, 2111, 77/
i=winio@('%ww%pv%pl[file=DDrates.set,title='D-D fusion',x_axis='Energy (keV)', &
& y_axis='Fusion crs',x_array,scale=log_log,n_graphs=1,y_min=1.e-2,y_max=1.e4]&', &
480,360, n, X, Y)
i=winio@('%ff%cn%^tt[Snapshot]%es', SnapshotPL)
end
!......................................................
! ____ __ _ __ ____ ____ _ _ __ ____
! / ___)( ( \ / _\ ( _ \/ ___)/ )( \ / \ (_ _)
! \___ \/ // \ ) __/\___ \) __ (( O ) )(
! (____/\_)__)\_/\_/(__) (____/\_)(_/ \__/ (__)
!......................................................
integer function SnapshotPL ()
use clrwin
character PNGfilename*256, chdate*8, chtime*10, chzone*5
integer ivalues(8)
call DATE_AND_TIME(chdate, chtime, chzone, ivalues ) ! chdate format 20210504
PNGfilename = 'zDesignerPL_'//chdate(1:8)//'_'//chtime(1:6)//'.png'
i = export_image@(trim(PNGfilename))
call sound@(3000,1)
call sound@(1000,1)
call sound@(2000,1)
SnapshotPL = 2
end function
Ken and Dan
Thank you for the feedback. I will see what can be done.
The idea of interacting with the graph when in design mode would 'take it to another level' as they say on Youtube. But I will give this some thought.
This example illustrates (by a different more complex route), what was behind my thoughts for requesting changing the tension value via CHANGE_PLOT_DBL@
!Tension + slider 06/05/2021
winapp
module test
use clrwin
implicit none
integer, parameter :: dp = kind(1.d0), n = 11
real(kind=dp) x_array(1:n), y_array(1:n)
real(kind=dp) :: tension = 0.d0
integer :: uid1=1000, uid2=1001
contains
integer function plot()
integer iw
do iw = 1, n, 1 ; x_array(iw) = iw - 1 ; y_array(iw) = random@() ; end do
iw = winio@('%mn[Exit]&','exit')
iw = winio@('%2.1ob[invisible]&')
iw = winio@('%`gr&',800,600,uid2)
iw = winio@('%cb&')
iw = winio@('Tension%nl%`5rf&',tension)
iw = winio@('%nl%^24sl[vertical]&',tension,0.d0,1.d0, create_pl)
iw = winio@('%sc&',create_pl)
iw = winio@('%cb&')
iw = winio@('')
plot = 1
end function plot
integer function create_pl()
integer i, iw, control
character(len=28) ten_string
write(ten_string,'('%pl[tension=',F5.3,']')') tension
i = create_graphics_region@(uid1,800,600)
call winop@('%pl[native,frame,etched,gridlines,width=3,x_array,independent,n_graphs=1]')
call winop@(ten_string)
call winop@('%pl[colour=blue,symbol=6]')
call winop@('%pl[x_min=0,x_max=10,dx=2,y_min=0,y_max=1]')
iw = winio@('%ff%pl[external]&',n,x_array,y_array)
iw = winio@('%lw&', control)
iw = winio@('')
i = COPY_GRAPHICS_REGION@(uid2, 1, 1, 800, 600, &
uid1, 1, 1, 800, 600, &
13369376 )
i = DELETE_GRAPHICS_REGION@(uid1)
create_pl = 1
end function create_pl
end module test
program main
use test
i = plot()
end program main
Ken
I have fixed the issue illustrated in your first sample. The line index for the tension was not in sync. I have also added the option 'tension' to CHANGE_PLOT_DBL@. I will provide new DLLs shortly so that you can see if it does what you want. I have also added draw_curves2D@ which is like draw_curvesD@ but with an extra double precision argument for the tension.
Dan
I have considered your suggestions for improvement. Unfortunately even your simplest request (to add tension to the designer) would take more that half a day's work. Extending the designer to interact with the graph would take a week or more. So, as is often the case, there would be a vast amount of work for very little gain.
Ken, That functionality with the slider in Designer mode like in your last example is what i was talking about. Hopefully with the new addition Paul added this will be much easier to implement in regular Programming mode too
Paul, Of course all beautifications and perfections take a lot of time to implement. It might take weeks, months and years till you'll say that it's completely done.
Meantime can you please look at this my demo example above because it exposes some defect of %pl ? It works initially but if you change something like position of X or Y axis in Designer mode, it fails. There exist a problem with LOG plotting in %pl, it often claims negative values where there actually are none even without smoothing like in my example. Smoothing often can generate some part of plot being below zero and plot fails in LOG mode and offers to switch to linear mode. Solution for that is to check the plotting data limits after smoothing plus the user has to set externally y_min=positive_value (ideally such message has to appear as a warning). Currently even setting y_min does not help
Similar visually but different by nature effect also exists in 'linear' plotting for both x and y too when due to smoothing the curve may get way out of frame or axis limits. I suspect that PL has some defect while checking plotting limits. To demonstrate that effect it is necessary to take the function with sharp peak.
In my description above I wrote that the 'link' value is redundant when 'tension' is applied. This makes the logic in the ClearWin+ code very tricky so I will change this to... you can set the link value or the tension but not both.
Dan
Thank you for the feedback. The thought that I might look forward to years of further development is actuallly quite encouraging but maybe not on %pl. My initial plan was to port the original %pl (that uses SimplePlot) to 64 bits. A friend advised me that it was unwise to do this because there will always be requests for changes and more features. Perhaps he was right. As it is I am quite happy to make some corrections and add new features as time permits.
It took me a lot of efforts to make my own graphs library. But i saw many cases in life when the same or perhaps with better quality was done literally in no time. And when done abandoned in no time. All depends on person and right tools and skills and inclination and funds and amount of supporters. Of course my graphics was made in spare time with zero skills in this area.
Perhaps the most amazing graphics program was created by two 9-graders under supervision of professional graphics designers but they were already retired for many years, and in the past by themselves they have not succeeded in making their product of such superb quality like two these students have done
https://www.youtube.com/watch?v=XxdY-pJNAvI
How about hiring these kids ? They would work literally for candies. I downloaded Bridplot , it costs just 2 dollars
They would make the Bridplot version for FTN95 or any other compiler, give you the right to edit the sources, and we would pay them for their efforts
Dan
The link that you provide is actually quite interesting and imples a connection with the original BUSS SimplePlot. I won't comment on your suggestions.
Paul,
“Requests for changes and more features” demonstrates that people are using %pl[native]. It’s use shows that porting the functionality of the old DLL was successful.
Unfortunately we users will only be satisfied for a short time as we use %pl[native] and ponder questions like “I wonder if the %pl[native] could…….?”.
Such questions have actually seen the %pl[native] been taken to the “next level” a number of times in recent years; reviewing the enhancements file clearly documents these incremental steps (and there are more to be added to the list with the next update to the enhancement file).
I guess we users overwhelm you at times, and you get a bit fed up revisiting the same part of the Clearwin code again and again, but this is the result of your successful porting of the old DLL, and the relatively diverse range of end uses of the code – it’s not just an X-Y plotting routine.
I hope these improvements will continue resources/time permitting. I think you set a time delivery record with the implementation of the “tension” parameter. Well done.