Polynominals chart - plots library based on WinApi & FbEdit designer.

User projects written in or related to FreeBASIC.
Post Reply
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Hello!

This program allows to draw diagrams with chart library, that can be used with dialog applications,
based on the RC files designers (such as FbEdit for example). This is the one of the fastest way to create
window application with visual design methods, and implement into it an ellegant and flexible chart,
that can be choosen from four different diagram kinds.

Project site on SourceForge: https://sourceforge.net/projects/fb-chart-designer/

The charts library (Chart.bas) has been written by Lothar Schirm, who previously created it on the base of
the other way of visual making window forms - the FiryFly designer by Paul Squires (with some code of Jose Roca).

This program is the new solution to adapt the previous idea to the other visual designer - FbEdit.
It shows the complete example of connection those mentioned solutions to achieve thiny file and less code project.
It makes more simply to analyze code and provides faster implementation of rebuilted chart library.

Here is some screenshoot:
Image

I hope, that it will be useful!
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

Minor cosmetic change to offer:

Code: Select all

				Case IDC_BTN1		'Function plot y = ax^4 + bx^3 + cx^2 + gx + n
					Dim As Integer i
					Dim As Double dx, x(), y()
					Dim Pattern_ As String
					'
					Dim As String*5 ScaleXminS, ScaleXmaxS, ScaleGridXS, ScaleGridYS
					Dim As Double ScaleXmin, ScaleXmax, ScaleYmin, ScaleYmax
					Dim As Integer ScaleGridX, ScaleGridY
					'
					Dim ExpBaseS(0 To 4) As String*9
					Dim ExpBase(0 To 4) As Double
					'
					GetDlgItemText(hWin, IDC_EDT1, ExpBaseS(4), Sizeof(ExpBaseS(4)))
					GetDlgItemText(hWin, IDC_EDT2, ExpBaseS(3), Sizeof(ExpBaseS(3)))
					GetDlgItemText(hWin, IDC_EDT3, ExpBaseS(2), Sizeof(ExpBaseS(2)))
					GetDlgItemText(hWin, IDC_EDT4, ExpBaseS(1), Sizeof(ExpBaseS(1)))
					GetDlgItemText(hWin, IDC_EDT5, ExpBaseS(0), Sizeof(ExpBaseS(0)))
					'ExpBase(4) = Val(ExpBaseS(4))
					'ExpBase(3) = Val(ExpBaseS(3))
					'ExpBase(2) = Val(ExpBaseS(2))
					'ExpBase(1) = Val(ExpBaseS(1))
					'ExpBase(0) = Val(ExpBaseS(0))
					'
					'Pattern = "y= "
					'i = 4
					'Do While i <> 1
					'	If ExpBase(i) <> 0 Then Pattern = Pattern & ExpBaseS(i) & "x^" & i & " + "
					'	i = i - 1
					'Loop
					'If ExpBase(1) <> 0 Then Pattern = Pattern & ExpBaseS(1) & "x" & " + "
					'If ExpBase(0) <> 0 Then Pattern = Pattern & ExpBaseS(0) Else Pattern = RTrim(Pattern, "+ ")
					'
					For i = UBound(ExpBase) To 0 Step -1
						ExpBase(i) = Val(ExpBaseS(i))
						If ExpBase(i) <> 0 Then
							'Ambigious len(), referring to type alias PATTERN, instead of variable PATTERN
							If Len(Pattern_) > 0 Then
								If ExpBase(i) > 0 Then
									Pattern_ += " + "
								Else
									Pattern_ += " - "
								EndIf
								If i > 0 Then
									'If base is 1, no need for value
									If Abs(ExpBase(i)) <> 1 Then Pattern_ += Str(Abs(ExpBase(i)))
									Pattern_ += "x"
									If i > 1 Then Pattern_ += "^" + Str(i)
								Else
									Pattern_ += Str(Abs(ExpBase(i)))
								EndIf
							Else
								'first non-zero value
								If i = 0 Then
									'just constant
									Pattern_ = ExpBaseS(0)
								Else
									If ExpBase(i) = -1 Then
										Pattern_ = "-x"
									ElseIf ExpBase(i) = 1 Then
										Pattern_ = "x"
									Else
										Pattern_ = ExpBaseS(i) + "x"
									EndIf
									If i > 1 Then Pattern_ += "^" + Str(i)
								EndIf
							EndIf
						EndIf
					Next
					'
					GetDlgItemText(hWin, IDC_EDT6, ScaleXminS, Sizeof(ScaleXminS))
					GetDlgItemText(hWin, IDC_EDT7, ScaleXmaxS, Sizeof(ScaleXmaxS))
					GetDlgItemText(hWin, IDC_EDT8, ScaleGridXS, Sizeof(ScaleGridXS))
					GetDlgItemText(hWin, IDC_EDT9, ScaleGridYS, Sizeof(ScaleGridYS))
					ScaleXmin = Val(ScaleXminS)
					ScaleXmax = Val(ScaleXmaxS)
					ScaleGridX = Val(ScaleGridXS)
					ScaleGridY = Val(ScaleGridYS)
					'
					dx = 0.1  ' Step (accuracy, precision) for x axis points distances (math values)
					'
					ReDim x(0 To Int((ScaleXmax - ScaleXmin)/dx)+1)
					ReDim y(0 To Int((ScaleXmax - ScaleXmin)/dx)+1)
					'
					For i = 0 To Int((ScaleXmax - ScaleXmin)/dx)+1
						x(i) = ScaleXmin + i * dx
						y(i) = ExpBase(4) * x(i)^4 +  ExpBase(3) * x(i)^3 + ExpBase(2) * x(i)^2 + ExpBase(1) * x(i) + ExpBase(0)
					Next
					'
					For i = 1 To Int((ScaleXmax - ScaleXmin)/dx)+1
						If y(i) > y(i-1) And y(i) > ScaleYmax Then
							ScaleYmax = y(i)
						EndIf
						If y(i) < y(i-1) And y(i) < ScaleYmin Then
							ScaleYmin = y(i)
						EndIf
					Next
					'
					ScaleGridX = (ScaleXmax - ScaleXmin) / ScaleGridX
					ScaleGridY = (ScaleYmax - ScaleYmin) / ScaleGridY
					'
					If ScaleGridX = 0 Or ScaleGridY = 0 Then
						ScaleXmin = -10
						ScaleXmax = 10
						ScaleYmin = -100
						ScaleYmax = 100
						ScaleGridX = 20
						ScaleGridY = 20
						Pattern_ = "Constable function or settings error."
					EndIf
					'
					'FF_Control_Redraw(HWND_FORM1_PICTURE1)
					RedrawWindow(hWin,NULL,NULL,RDW_INVALIDATE)
					DrawCoordSys(HWND_FORM1_PICTURE1, ScaleXmin, ScaleYmin, ScaleXmax, ScaleYmax, ScaleGridX, ScaleGridY, "x", "y", "f(x) = " + Pattern_)
					Chart_Line(HWND_FORM1_PICTURE1, x(), y(), BGR_Red)
					'Chart_Line(HWND_FORM1_PICTURE1, x1(), y1(), BGR_Yellow)
I changed the string variable name. See note in loop.
Last edited by bcohio2001 on Jul 04, 2019 0:55, edited 1 time in total.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Hello bcohio2001,

Thanks for reply and offer of changes! There is unfortunately still some bugs in your solution.

In case of ExpBase(4) = 0 or empty field, there is still fourth degree addition in the pattern (please check it).
In case of ExpBase(0) = -1 or ExpBase(0) = 1 there is lonely sign (- or +) at the end of pattern.

So your changes offer still needs corrections...

Greetings!
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

A little better.

I did not look at the Chart.bas code too much. You might be able to modify even further to display two functions?????
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Yes, I think that it is possible. Thanks for changes, i will try it. I have recently wasted my time on searching some way to implement up-down buttons in win-api, and did not find any good idea...

In my plans I would like to add ability to draw more than one plot and more than four degrees of polinominal. But it will require time on learning win-api, so be patient please... ;)

Greetings!
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

I agree that plotting 2 or more graphs can be done. A LOT of work involved in it.
I can help if I can.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Thanks for help! I have checked it and know, that it already works fine. I will add it to code with the next update.

Yes, the changes involves a lot of work. Although for advanced programmer it takes not a long time. Generally WinApi is not friendly enviroment for begginers, so it took me a long to get basic skills. Making controls with commands causes the code to be too long and complicated, so thats why I am so excited with FbEdit, that allows to draw it similar to MS visual Basic and has templates with good working, and fast examples.

In this case there is need to make a new solution to collect data in the window and create new, more complicated dynamic structure to store this data in memory. I have plan, to make it visual friendly for user and not difficult to understand during code analyzing. So thanks for help, and if I had such need, or if you have some suggestions, Im ready for this and you are welcome bcohio.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

A few words of advice, not criticizing.
1) Comment your code more. When others look at your code, or when you come back to it months/years later, it will be easier to remember what that piece of code was for.
2) In designing your form. Use names that are more descriptive.
Example: FBEdit - IDC_EDT1, IDC_EDT2 ….. Yours: IDC_EDT_FirstName, IDC_EDT_LastName

Look on here in the forum for examples of code that fit what you are trying to accomplish.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Hello,

I' ve just updated my Polynominals Chart Designer.
To ensure that you find it quickly, here is the project site link again:

https://sourceforge.net/projects/fb-chart-designer/

In new version of program, as I ' ve been asked by user "bcohio2001", I decided to add option to draw more than one plot in the same window.
The idea od building plots matrix is not complicated. Once you define amount of plots, then you select one of them to set next arguments.
So after selecting the plot, you can define its degree. After that, you similar to the previous step select some level of this degree, to set its factor. The factor can be inputed manually, or by buttons with some step ( 0,1 ) . To set inputed factor for selected plot and degree level, you should just click "Set factor" button, and do it so many times, as you finally input factors for all degree levels of all the plots.

The last selected plot has the red color on the chart (so you can set in in editbox "Plot No.", and click the "Calculate" button again). The plot selected in this way is red and you can see its pattern on the right side of the buttons.

The list boxes are inactive yet. And here is the message for YOU GUYS ;)
If You know WinApi, you can offer some help. The "Plot" Listbox must be clicked to show list of the degree level and its factor in the second List box on the right side. It would be pretty good, if clicking the plot on the list will change also the text with pattern (alternative way for existing solution) and mark it red.

If you can help, you are WELCOME!
Enjoy!

Image
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

I haven't looked at the code yet, but from the screenshots at sourceforge, looks pretty good.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

Finally got around to working on your request.
I have made a slight modification to the rc file.
I think that you wanted to use a "Listview" instead of a "Listbox" for the display of degree/factors.

The fact that I do not have a sourceforge account means that I cannot send the changes. (I have had problems in the past in posting an rc file.)
Send me an email to bcohio2001 [at] yahoo [dot] com and I will send you a zip file of my changes.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Hello,
Thanks for reply. I have been contacting with You by e-mail. OK, no problem with editing rc file. Every changes are welcome.
Regards.
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

Hello,
I have updated Chart Designer again. In version V3 there is working list of factors, what replaced the matrix textbox from version V2.
There is some disadvantage that I couldn't fix, so after clicking on the "Set factor" button, list of the factors displays the same factor for all degrees. It changes after clicking the plot number on the list.

Image

I would rather not develop this program again in the future. The goal of this app was to show, how can we implement the chart library based on solutions from FireFly. The main goal has been reached, so I don't feel the need to continue work on it so on.

I've started to search the flexible chart library, due to my other program - called "FreeBalistic".
I just want to replace the graphic in the main window by the chart created in similar way like here.
It will also allow spread the scopes from 0 to 18 and display the full ballistic curve in case of achieve large value results. That would require also making changes in all calculating functions of this app.

For those who want to help in developping "FreeBalistic", here is the link to application:

https://sourceforge.net/projects/free-balistic/

Every help is welcome.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by bcohio2001 »

First of all, thanks for the acknowledgement in the program title bar. (Ah, to see my name in the bright lights …)

I am interested in your other development ...
peter-cat
Posts: 18
Joined: Feb 18, 2019 8:03

Re: Polynominals chart - plots library based on WinApi & FbEdit designer.

Post by peter-cat »

OK, that's great!
See the Freebasic Forum topic: viewtopic.php?f=8&t=27484
Post Reply