Have you any a line diagram code?

Just starting out? Need help? Post your questions and find answers here.
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: Have you any a line diagram code?

Post by ostapas »

Thank you Ostapas
Thanks to uwekel, not me :)
Lubos
Enthusiast
Enthusiast
Posts: 167
Joined: Tue Feb 03, 2004 12:32 am
Contact:

Re: Have you any a line diagram code?

Post by Lubos »

uwekel wrote:Hi,
i just posted my own chart gadget source file here:
http://www.purebasic.fr/english/viewtop ... 14&t=59038
Maybe you can use it.
Best regards
Uwe
Hi Uwe,
thank you very much.
This could be what I was looking for. I think I can adjust it quite easily.
With best regards
Lubos
Windows 7 Professional / Service Pack 1 - 32bit, PureBasic 5.46 LTS (x86)
My mother tongue is Czech. I have a Czech version of Windows.
Who is not afraid of GOTO, the one need not afraid any things!
Lubos
Enthusiast
Enthusiast
Posts: 167
Joined: Tue Feb 03, 2004 12:32 am
Contact:

Re: Have you any a line diagram code?

Post by Lubos »

ostapas wrote:
Thank you Ostapas
Thanks to uwekel, not me :)
Your willingly submitting information deserves thanks anyway.
Lubos
Windows 7 Professional / Service Pack 1 - 32bit, PureBasic 5.46 LTS (x86)
My mother tongue is Czech. I have a Czech version of Windows.
Who is not afraid of GOTO, the one need not afraid any things!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Have you any a line diagram code?

Post by RASHAD »

Hi Lobus
I just picked the simplest method to hit your request :P
- You have to manage how to represent the real data to
X-Axis,Y-Axis (Scale_X,Scale_y)
- You have to manage how to read the data in(exam. from file etc.. )
- You can add the legend and any thing else as per your requirements
- Press Run to plot the data and any new data

Have fun
RASHAD

Code: Select all

Global Dim Diag_1.f(25,2)
Global Dim Diag_2.f(25,2)
Global Dim Diag_3.f(25,2)
Global Dim Diag_4.f(25,2)

Global penl_1,penl_2,penl_3,penl_4

penl_1 = CreatePen_(#PS_SOLID, 1, $11F605)
penl_2 = CreatePen_(#PS_DASHDOT	, 1, $E914E9)
penl_3 = CreatePen_(#PS_DASH	, 1, $E7DC14)
penl_4 = CreatePen_(#PS_DASHDOTDOT, 1, #Yellow)

Diag_1(0,0) = 100
Diag_1(0,1) = 600

Diag_1(1,0) = 150
Diag_1(1,1) = 550

Diag_1(2,0) = 200
Diag_1(2,1) = 550

Diag_1(3,0) = 250
Diag_1(3,1) = 450

Diag_1(4,0) = 300
Diag_1(4,1) = 400

Diag_2(0,0) = 100
Diag_2(0,1) = 500

Diag_2(1,0) = 150
Diag_2(1,1) = 450

Diag_2(2,0) = 200
Diag_2(2,1) = 550

Diag_2(3,0) = 250
Diag_2(3,1) = 600

Diag_2(4,0) = 300
Diag_2(4,1) = 350

;Scale_X = 100 to 950 represent 0.01 to 655.36
;Scale_Y = 600 to 100 represent 10 to 110 

Procedure Plot_Data()
CopyImage(1,2)
hdc = StartDrawing(ImageOutput(2))
  SelectObject_(hdc,ImageID(2))
  SetBkMode_(hdc,#TRANSPARENT	)
    
  SelectObject_(hdc, penl_1)
  For i = 0 To 3
      MoveToEx_(hdc, Diag_1(i,0),Diag_1(i,1), old.POINT)
      LineTo_(hdc, Diag_1(i+1,0),Diag_1(i+1,1))
  Next
  
  SelectObject_(hdc, penl_2)
  For i = 0 To 3
      MoveToEx_(hdc, Diag_2(i,0),Diag_2(i,1), old.POINT)
      LineTo_(hdc, Diag_2(i+1,0),Diag_2(i+1,1))
  Next
  
  SelectObject_(hdc, penl_3)
  For i = 0 To 10
      MoveToEx_(hdc, Diag_3(i,0),Diag_3(i,1), old.POINT)
      LineTo_(hdc, Diag_3(i+1,0),Diag_3(i+1,1))
  Next
  
  SelectObject_(hdc, penl_4)
  For i = 0 To 10
      MoveToEx_(hdc, Diag_4(i,0),Diag_4(i,1), old.POINT)
      LineTo_(hdc, Diag_4(i+1,0),Diag_4(i+1,1))
  Next
 StopDrawing()
 SetGadgetState(5,ImageID(2))   
EndProcedure

OpenWindow(0,0,0,1280,800,"Line Diagram",#PB_Window_SystemMenu| #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,#Black)
CreateImage(0,200,200)

hdc = StartDrawing(ImageOutput(0))
  SelectObject_(hdc,ImageID(0))
  SetBkMode_(hdc,#TRANSPARENT	)  
  SelectObject_(hdc, penl_1)
  DrawText(10,10,"Line #1 Scheme :",$11F605)
  MoveToEx_(hdc, 130,18, old.POINT)
  LineTo_(hdc, 190,18)
  SelectObject_(hdc, penl_2)
  DrawText(10,30,"Line #2 Scheme :",$E914E9)
  MoveToEx_(hdc, 130,38, old.POINT)
  LineTo_(hdc, 190,38)
  SelectObject_(hdc, penl_3)
  DrawText(10,50,"Line #3 Scheme :",$E7DC14)
  MoveToEx_(hdc, 130,58, old.POINT)
  LineTo_(hdc, 190,58)
  SelectObject_(hdc, penl_4)
  DrawText(10,70,"Line #4 Scheme :",#Yellow)
  MoveToEx_(hdc, 130,78, old.POINT)
  LineTo_(hdc, 190,78)
StopDrawing()
ImageGadget(0,10,10,200,200,ImageID(0))

ButtonGadget(1,10,740,80,20,"Line Scheme")
ButtonGadget(2,10,770,80,20,"Run")


CreateImage(1,1100,750)
hdc = StartDrawing(ImageOutput(1))
  SelectObject_(hdc,ImageID(1))
  pen = CreatePen_(#PS_SOLID, 2, #White)
  Brush = CreateSolidBrush_(#Black)
  SelectObject_(hdc, pen) 
  SelectObject_(hdc, Brush)
  Rectangle_(hdc,50,50,1000,650)
  pen2 = CreatePen_(#PS_SOLID, 1, #Gray)
  SelectObject_(hdc, pen2)
  Restore Y_Axis
  For y = 600 To 100 Step -50
       MoveToEx_(hdc, 50,y, old.POINT)
       LineTo_(hdc, 1000,y)
       ;SetTextColor_(hdc, #Yellow)
       SetBkMode_(hdc,#TRANSPARENT	)
       Read.l a
       DrawText(10,y-5,Str(a),#Yellow)
  Next
  pen3 = CreatePen_(#PS_DASH	, 1, #Gray)
  SetBkMode_(hdc,#TRANSPARENT	)
  SelectObject_(hdc, pen3)
  Restore X_Axis
  For x = 100 To 950 Step 50
     Read.f b.f
     MoveToEx_(hdc, x,50, old.POINT)
     LineTo_(hdc, x,650)
     DrawRotatedText(x-5, 705, StrF(b,2),90,#Yellow)
  Next
StopDrawing()
DeleteObject_(pen)
DeleteObject_(Brush)
DeleteObject_(pen2)
DeleteObject_(pen3)

CopyImage(1,2)

ImageGadget(5,240,80,1000,650,ImageID(2))

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Menu
          Select EventMenu()
           Case 1            
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
           
           
           Case 2
                   Plot_Data()
           
                       
          EndSelect
  EndSelect 

Until Quit = 1
End

DataSection
  X_Axis:
  Data.f 0.01,0.02,0.04,0.08,0.16,0.32,0.64,1.28,2.56,5.12, 10.24,20.48,40,96,81.92,163.84,327.68,655.36
  Y_Axis:
  Data.l 10,20,30,40,50,60,70,80,90,100,110,120,130, 140,150
EndDataSection
Egypt my love
Lubos
Enthusiast
Enthusiast
Posts: 167
Joined: Tue Feb 03, 2004 12:32 am
Contact:

Re: Have you any a line diagram code?

Post by Lubos »

RASHAD wrote:Hi Lobus
I just picked the simplest method to hit your request :P
Hi Rashad,
you are clever and very affectionate. Your solution is done really as a "tailor made". And you were much faster than you promised. :shock:

Best regards
Lubos
Windows 7 Professional / Service Pack 1 - 32bit, PureBasic 5.46 LTS (x86)
My mother tongue is Czech. I have a Czech version of Windows.
Who is not afraid of GOTO, the one need not afraid any things!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Have you any a line diagram code?

Post by RASHAD »

Hi Lubos
- Modified the code for better performance
- Further step now you can use the Real Data it will be converted
to the exact plot points

Code: Select all

ExamineDesktops()

Global Dim Diag_1.f(25,2)
Global Dim Diag_2.f(25,2)
Global Dim Diag_3.f(25,2)
Global Dim Diag_4.f(25,2)

Global penl_1,penl_2,penl_3,penl_4,ResultX.f,Old_X.f,ResultY,LastPt

penl_1 = CreatePen_(#PS_SOLID, 1, $11F605)
penl_2 = CreatePen_(#PS_DASHDOT	, 1, $E914E9)
penl_3 = CreatePen_(#PS_DASH	, 1, $E7DC14)
penl_4 = CreatePen_(#PS_DASHDOTDOT, 1, #Yellow)

LastPt = 4

Diag_1(0,0) = 0.015
Diag_1(0,1) = 18

Diag_1(1,0) = 0.028
Diag_1(1,1) = 30

Diag_1(2,0) = 0.08
Diag_1(2,1) = 30

Diag_1(3,0) = 0.32
Diag_1(3,1) = 50

Diag_1(4,0) = 0.64
Diag_1(4,1) = 70

;*****************************************
Diag_2(0,0) = 0.02
Diag_2(0,1) = 10

Diag_2(1,0) = 0.08
Diag_2(1,1) = 50

Diag_2(2,0) = 0.16
Diag_2(2,1) = 60

Diag_2(3,0) = 0.64
Diag_2(3,1) = 60

Diag_2(4,0) = 1.28
Diag_2(4,1) = 70

;*****************************************
Diag_3(0,0) = 0.02
Diag_3(0,1) = 20

Diag_3(1,0) = 0.08
Diag_3(1,1) = 60

Diag_3(2,0) = 0.16
Diag_3(2,1) = 60

Diag_3(3,0) = 0.64
Diag_3(3,1) = 50

Diag_3(4,0) = 1.28
Diag_3(4,1) = 70

;*****************************************
Diag_4(0,0) = 0.02
Diag_4(0,1) = 30

Diag_4(1,0) = 0.08
Diag_4(1,1) = 30

Diag_4(2,0) = 0.16
Diag_4(2,1) = 60

Diag_4(3,0) = 0.64
Diag_4(3,1) = 70

Diag_4(4,0) = 1.28
Diag_4(4,1) = 80

;******************************************

Procedure ConvertX(x.f)
ResultX.f = x
;Old_X = 0
If ResultX = 0.01
    ResultX = 100
ElseIf ResultX > 0.01
    For i = 1 To 20
       ResultX = ResultX/2       
       If ResultX <= 0.01
         Break
       EndIf
     Next
     ResultX = i*50 + 100 + (ResultX-0.01)/0.01*100
 EndIf
 ProcedureReturn ResultX
EndProcedure

Procedure ConvertY(y)
ResultY = y
  For i = 1 To 20
     ResultY = ResultY-10
     If ResultY <= 10
       Break
      EndIf
   Next
   ResultY = 600 - i*50 + (10 - ResultY)*5
 ProcedureReturn ResultY
EndProcedure

Procedure Plot_Data()
CopyImage(1,2)
hdc = StartDrawing(ImageOutput(2))
  SelectObject_(hdc,ImageID(2))
  SetBkMode_(hdc,#TRANSPARENT	)    
  SelectObject_(hdc, penl_1)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_1(i,0))
      y1 = ConvertY(Diag_1(i,1))
      x2 = ConvertX(Diag_1(i+1,0))
      y2 = ConvertY(Diag_1(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_2)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_2(i,0))
      y1 = ConvertY(Diag_2(i,1))
      x2 = ConvertX(Diag_2(i+1,0))
      y2 = ConvertY(Diag_2(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_3)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_3(i,0))
      y1 = ConvertY(Diag_3(i,1))
      x2 = ConvertX(Diag_3(i+1,0))
      y2 = ConvertY(Diag_3(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_4)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_4(i,0))
      y1 = ConvertY(Diag_4(i,1))
      x2 = ConvertX(Diag_4(i+1,0))
      y2 = ConvertY(Diag_4(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
 StopDrawing()
 SetGadgetState(5,ImageID(2))   
EndProcedure

OpenWindow(0,0,0,1280,800,"Line Diagram",#PB_Window_SystemMenu| #PB_Window_MinimizeGadget| #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
SetWindowColor(0,#Black)
WindowBounds(0,1280,800,DesktopWidth(0),DesktopHeight(0))
CreateImage(0,200,200)

hdc = StartDrawing(ImageOutput(0))
  SelectObject_(hdc,ImageID(0))
  SetBkMode_(hdc,#TRANSPARENT	)  
  SelectObject_(hdc, penl_1)
  DrawText(10,10,"Line #1 Scheme :",$11F605)
  MoveToEx_(hdc, 130,18, old.POINT)
  LineTo_(hdc, 190,18)
  SelectObject_(hdc, penl_2)
  DrawText(10,30,"Line #2 Scheme :",$E914E9)
  MoveToEx_(hdc, 130,38, old.POINT)
  LineTo_(hdc, 190,38)
  SelectObject_(hdc, penl_3)
  DrawText(10,50,"Line #3 Scheme :",$E7DC14)
  MoveToEx_(hdc, 130,58, old.POINT)
  LineTo_(hdc, 190,58)
  SelectObject_(hdc, penl_4)
  DrawText(10,70,"Line #4 Scheme :",#Yellow)
  MoveToEx_(hdc, 130,78, old.POINT)
  LineTo_(hdc, 190,78)
StopDrawing()
ImageGadget(0,10,10,200,200,ImageID(0))

ButtonGadget(1,10,740,80,20,"Line Scheme")
ButtonGadget(2,10,770,80,20,"Run")

CreateImage(1,1100,750)
hdc = StartDrawing(ImageOutput(1))
  SelectObject_(hdc,ImageID(1)) 
  pen = CreatePen_(#PS_SOLID, 2, #White)
  Brush = CreateSolidBrush_(#Black)
  SelectObject_(hdc, pen) 
  SelectObject_(hdc, Brush)
  Rectangle_(hdc,48,48,1002,652)
  pen2 = CreatePen_(#PS_SOLID, 1, $343435)
  pen2_2 = CreatePen_(#PS_SOLID, 1, $474748)
  
  For y = 50 To 645 Step 10
    If (y % 50 ) = 0 And y > 50
       SelectObject_(hdc, pen2_2)
       MoveToEx_(hdc, 50,y, old.POINT)
       LineTo_(hdc, 1000,y)
    Else
       SelectObject_(hdc, pen2)
       SetBkMode_(hdc,#TRANSPARENT	)
       MoveToEx_(hdc, 50,y, old.POINT)
       LineTo_(hdc, 1000,y)
    EndIf
  Next
  
  Restore Y_Axis
  For y = 100 To 600 Step 50
       Read.l a
       DrawText(10,y-8,Str(a),#Yellow)
  Next
  DrawText(10,45,"[ % ]",#Yellow) 
    
  For x = 50 To 995 Step 10
    If (x % 50 ) = 0
     SelectObject_(hdc, pen2_2)
     MoveToEx_(hdc, x,50, 0)
     LineTo_(hdc, x,650)
    Else
     SelectObject_(hdc, pen2)
     SetBkMode_(hdc,#TRANSPARENT	)
     MoveToEx_(hdc, x,50, 0)
     LineTo_(hdc, x,650) 
     EndIf
  Next
  Restore X_Axis
  For x = 50 To 900 Step 50
     Read.f b.f
     DrawRotatedText(x+40, 705, StrF(b,2),90,#Yellow)
  Next
  DrawText(980,680,"[ mn ]",#Yellow) 
StopDrawing()

DeleteObject_(pen)
DeleteObject_(Brush)
DeleteObject_(pen2)
DeleteObject_(pen2_2)
DeleteObject_(pen3)
DeleteObject_(pen3_3)

CopyImage(1,2)

ImageGadget(5,240,80,1000,650,ImageID(2))

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
            
      Case #WM_EXITSIZEMOVE
            CopyImage(1,2)
            If PlotFlag = 1
               Plot_Data()
            EndIf
            ResizeGadget(1,#PB_Ignore,WindowHeight(0)-60, #PB_Ignore,#PB_Ignore)
            ResizeGadget(2,#PB_Ignore,WindowHeight(0)-30, #PB_Ignore,#PB_Ignore)
            ResizeImage(2,WindowWidth(0) - 180,WindowHeight(0)-50,#PB_Image_Smooth)
            ResizeGadget(5,#PB_Ignore,#PB_Ignore,WindowWidth(0) - 180,WindowHeight(0)-50)
            SetGadgetState(5,ImageID(2))
      
      Case #PB_Event_Menu
          Select EventMenu()
           Case 1            
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
                             
           
           Case 2
                   PlotFlag = 1
                   Plot_Data()
           
                       
          EndSelect
  EndSelect 

Until Quit = 1
End

DataSection
  X_Axis:
  Data.f 0.01,0.02,0.04,0.08,0.16,0.32,0.64,1.28,2.56,5.12,10.24, 20.48, 40.96,81.92,163.84,327.68,655.36, 1310.72
  Y_Axis:
  Data.l 110,100,90,80,70,60,50,40,30,20,10
EndDataSection
Edit :Modified for more accurate plotting
Added more features
Last edited by RASHAD on Fri Apr 18, 2014 3:19 am, edited 1 time in total.
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Have you any a line diagram code?

Post by RASHAD »

Previous post updated for more accurate data plotting
Have fun
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Have you any a line diagram code?

Post by rsts »

Pretty, but all I see is an empty graph. I can't seem to so or see an plotting. I don't even believe I am seeing the entire graph at fullscreen.

PB 522 LTS x86
win 8.1 x64

Best to you RASHAD
Zach
Addict
Addict
Posts: 1656
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Have you any a line diagram code?

Post by Zach »

Hitting the "Run" button in the bottom-left corner of the Application Window ?

Or if your screen resolution is less than 1280x800 it may be getting cut off
Image
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Have you any a line diagram code?

Post by rsts »

Zach wrote: Or if your screen resolution is less than 1280x800 it may be getting cut off
Thanks Zach, resolution @ 1600x900, but no button here ;)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Have you any a line diagram code?

Post by RASHAD »

Hi rsts
I just changed almost every thing
Now using Enhanced Meta File we will get better performance
specially for resizing

Code: Select all

ExamineDesktops()

Global Dim Diag_1.f(25,2)
Global Dim Diag_2.f(25,2)
Global Dim Diag_3.f(25,2)
Global Dim Diag_4.f(25,2)

Global penl_1,penl_2,penl_3,penl_4,ResultX.f,Old_X.f, ResultY, LastPt, emfhandle, Font, Font90

penl_1 = CreatePen_(#PS_SOLID, 1, $11F605)
penl_2 = CreatePen_(#PS_DASHDOT	, 1, $E914E9)
penl_3 = CreatePen_(#PS_DASH	, 1, $E7DC14)
penl_4 = CreatePen_(#PS_DASHDOTDOT, 1, #Yellow)
Font = CreateFont_(12,0,0,0,0,0,0,0,0,0,0,0,0,"Arial") 
Font90 = CreateFont_(12,0,900,0,0,0,0,0,0,0,0,0,0,"Arial") 

LastPt = 4

Diag_1(0,0) = 0.015
Diag_1(0,1) = 18

Diag_1(1,0) = 0.028
Diag_1(1,1) = 30

Diag_1(2,0) = 0.08
Diag_1(2,1) = 30

Diag_1(3,0) = 0.32
Diag_1(3,1) = 50

Diag_1(4,0) = 0.64
Diag_1(4,1) = 70

;*****************************************
Diag_2(0,0) = 0.02
Diag_2(0,1) = 10

Diag_2(1,0) = 0.08
Diag_2(1,1) = 50

Diag_2(2,0) = 0.16
Diag_2(2,1) = 60

Diag_2(3,0) = 0.64
Diag_2(3,1) = 60

Diag_2(4,0) = 1.28
Diag_2(4,1) = 70

;*****************************************
Diag_3(0,0) = 0.02
Diag_3(0,1) = 20

Diag_3(1,0) = 0.08
Diag_3(1,1) = 30

Diag_3(2,0) = 0.16
Diag_3(2,1) = 45

Diag_3(3,0) = 0.64
Diag_3(3,1) = 75

Diag_3(4,0) = 1.28
Diag_3(4,1) = 70

;*****************************************
Diag_4(0,0) = 0.008
Diag_4(0,1) = 6

Diag_4(1,0) = 0.08
Diag_4(1,1) = 30

Diag_4(2,0) = 0.16
Diag_4(2,1) = 60

Diag_4(3,0) = 0.64
Diag_4(3,1) = 70

Diag_4(4,0) = 1.28
Diag_4(4,1) = 80

;******************************************

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents 
  Select uMsg
      Case #WM_SIZE,#WM_SIZING,#WM_MOVE,#WM_MOVING
              CreateImage(1,WindowWidth(0) - 240, WindowHeight(0)-150)
              hDC = StartDrawing(ImageOutput(1))
                  r.RECT
                  r\left = 0
                  r\right = WindowWidth(0) - 240
                  r\top = 0
                  r\bottom = WindowHeight(0) - 150
              PlayEnhMetaFile_(hDC,emfhandle,r)
              StopDrawing()
              ResizeGadget(5,210,80,WindowWidth(0) - 240, WindowHeight(0)-150)
              SetGadgetState(5,ImageID(1)) 
             
  EndSelect
  ProcedureReturn Result 
EndProcedure 

Procedure ConvertX(x.f)
ResultX.f = x
If ResultX = 0.00
    ResultX = 50
ElseIf ResultX < 0.01
    ResultX = 100 - x*50/0.01
ElseIf ResultX = 0.01
    ResultX = 100
ElseIf ResultX > 0.01
    For i = 1 To 20
       ResultX = ResultX/2       
       If ResultX <= 0.01
         Break
       EndIf
     Next
     ResultX = i*50 + 100 + (ResultX-0.01)/0.01*100
 EndIf
 ProcedureReturn ResultX
EndProcedure

Procedure ConvertY(y)
ResultY = y
If ResultY = 0.00
    ResultY = 650
ElseIf  ResultY < 10
    ResultY = 650 - y*5
ElseIf  ResultY >= 10
  For i = 1 To 20
     ResultY = ResultY-10
     If ResultY <= 10
       Break
      EndIf
   Next
   ResultY = 600 - i*50 + (10 - ResultY)*5
  EndIf
 ProcedureReturn ResultY
EndProcedure

Procedure Creat_Diagram()
hdc = CreateEnhMetaFile_(0,0,0,0)
  pen2 = CreatePen_(#PS_SOLID, 1, $343435)
  pen2_2 = CreatePen_(#PS_SOLID, 1, $474748)
  
  For y = 50 To 645 Step 10
    If (y % 50 ) = 0 And y > 50
       SelectObject_(hdc, pen2_2)
       MoveToEx_(hdc, 50,y, old.POINT)
       LineTo_(hdc, 1000,y)
    Else
       SelectObject_(hdc, pen2)
       SetBkMode_(hdc,#TRANSPARENT	)
       MoveToEx_(hdc, 50,y, old.POINT)
       LineTo_(hdc, 1000,y)
    EndIf
  Next
  
  Restore Y_Axis
  SelectObject_(hdc,Font)
  For y = 100 To 600 Step 50
       Read.l a
       SetBkMode_(hdc, #TRANSPARENT)
       SetTextColor_(hdc, #Yellow)      
       ExtTextOut_(hdc, 20,y-4,#ETO_CLIPPED	 ,r,Str(a),Len(Str(a)),0 ) 
  Next
  SetBkMode_(hdc, #TRANSPARENT)
  SetTextColor_(hdc, #Yellow)
  ExtTextOut_(hdc, 20,45,0 ,r,"[ % ]",Len("[ % ]"),0 )
    
  For x = 50 To 995 Step 10
    If (x % 50 ) = 0
     SelectObject_(hdc, pen2_2)
     MoveToEx_(hdc, x,50, 0)
     LineTo_(hdc, x,650)
    Else
     SelectObject_(hdc, pen2)
     SetBkMode_(hdc,#TRANSPARENT	)
     MoveToEx_(hdc, x,50, 0)
     LineTo_(hdc, x,650) 
     EndIf
  Next
  
  Restore X_Axis
  SelectObject_(hdc,Font90)
  For x = 50 To 900 Step 50
     Read.f b.f
       SetBkMode_(hdc, #TRANSPARENT)
       SetTextColor_(hdc, #Yellow)
       SetTextAlign_(hdc,#TA_BASELINE)       
       ExtTextOut_(hdc, x+54,700,#ETO_CLIPPED	 ,r,StrF(b,2),Len(StrF(b,2)),0 ) 
  Next
  SetBkMode_(hdc, #TRANSPARENT)
  SetTextColor_(hdc, #Yellow)
  SelectObject_(hdc,Font)
  ExtTextOut_(hdc, x+35,680,0 ,r,"[ mn ]",Len("[ mn ]"),0 )
  
  pen = CreatePen_(#PS_SOLID, 1, #White)
  Brush = GetStockObject_(#NULL_BRUSH)
  SelectObject_(hdc, pen) 
  SelectObject_(hdc, Brush)  
  Rectangle_(hdc,50,50,1000,650)

  SetBkMode_(hdc,#TRANSPARENT	)    
  SelectObject_(hdc, penl_1)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_1(i,0))
      y1 = ConvertY(Diag_1(i,1))
      x2 = ConvertX(Diag_1(i+1,0))
      y2 = ConvertY(Diag_1(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_2)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_2(i,0))
      y1 = ConvertY(Diag_2(i,1))
      x2 = ConvertX(Diag_2(i+1,0))
      y2 = ConvertY(Diag_2(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_3)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_3(i,0))
      y1 = ConvertY(Diag_3(i,1))
      x2 = ConvertX(Diag_3(i+1,0))
      y2 = ConvertY(Diag_3(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  
  SelectObject_(hdc, penl_4)
  For i = 0 To LastPt - 1
      x1 = ConvertX(Diag_4(i,0))
      y1 = ConvertY(Diag_4(i,1))
      x2 = ConvertX(Diag_4(i+1,0))
      y2 = ConvertY(Diag_4(i+1,1))
      MoveToEx_(hdc, x1,y1, old.POINT)
      LineTo_(hdc, x2,y2)
  Next
  emfhandle = CloseEnhMetaFile_(hdc) 
EndProcedure

OpenWindow(0,0,0,900,600,"Line Diagram",#PB_Window_SystemMenu| #PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
SetWindowColor(0,#Black)
WindowBounds(0,400,300, DesktopWidth(0), DesktopHeight(0))
CreateImage(0,200,100)

hdc = StartDrawing(ImageOutput(0))
  SelectObject_(hdc,ImageID(0))
  SetBkMode_(hdc,#TRANSPARENT	)  
  SelectObject_(hdc, penl_1)
  DrawText(10,10,"Line #1 Scheme :",$11F605)
  MoveToEx_(hdc, 130,18, old.POINT)
  LineTo_(hdc, 190,18)
  SelectObject_(hdc, penl_2)
  DrawText(10,30,"Line #2 Scheme :",$E914E9)
  MoveToEx_(hdc, 130,38, old.POINT)
  LineTo_(hdc, 190,38)
  SelectObject_(hdc, penl_3)
  DrawText(10,50,"Line #3 Scheme :",$E7DC14)
  MoveToEx_(hdc, 130,58, old.POINT)
  LineTo_(hdc, 190,58)
  SelectObject_(hdc, penl_4)
  DrawText(10,70,"Line #4 Scheme :",#Yellow)
  MoveToEx_(hdc, 130,78, old.POINT)
  LineTo_(hdc, 190,78)
StopDrawing()
ImageGadget(0,10,10,200,100,ImageID(0))

ImageGadget(5,210,80,1000,600,0)

ContainerGadget(10,20,120,100,70,#PB_Container_Flat)
    ButtonGadget(11,0,0,100,20,"New Diagram")
    ButtonGadget(12,0,25,100,20,"Create Diagram")
    ButtonGadget(13,0,50,100,20,"Plot the Diagram ")
CloseGadgetList()
SetGadgetColor(10,#PB_Gadget_BackColor,#Black)

SetWindowCallback(@WndProc()) 
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
            
;       Case #PB_Event_Menu
;           Select EventMenu()
;            Case 1            
;           EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 11
;                     If emfhandle <> 0
;                         DeleteMetaFile_(emfhandle)
;                         InvalidateRect_(GadgetID(5),0,1)
;                         ;Creat_Diagram()
;                     EndIf
                    
           Case 12
                   If emfhandle = 0                                      
                      Creat_Diagram()
                      Flag = 1
                  EndIf 
           
            Case 13
                    If Flag = 1
                       Flag = 0
                        CreateImage(1,WindowWidth(0) - 240, WindowHeight(0)-150)
                        hDC = StartDrawing(ImageOutput(1))
                            r.RECT
                            r\left = 0
                            r\right = WindowWidth(0) - 240
                            r\top = 0
                            r\bottom = WindowHeight(0) - 150
                            PlayEnhMetaFile_(hDC,emfhandle,r)
                        StopDrawing()
                        SetGadgetState(5,ImageID(1))
                   EndIf                       
         EndSelect
  EndSelect 

Until Quit = 1
  DeleteObject_(pen)
  DeleteObject_(Brush)
  DeleteObject_(pen2)
  DeleteObject_(pen2_2)
  DeleteObject_(pen3)
  DeleteObject_(pen3_3) 
End

DataSection
  X_Axis:
  Data.f 0.01,0.02,0.04,0.08,0.16,0.32,0.64,1.28,2.56,5.12,10.24, 20.48,40.96,81.92, 163.84, 327.68, 655.36, 1310.72
  Y_Axis:
  Data.l 110,100,90,80,70,60,50,40,30,20,10
EndDataSection
Edit :Modified again (Sorry :mrgreen: )
Edit 2:Ok guys you asked for it :D
Press Create first then Plot
Edit 3:No flickering
Last edited by RASHAD on Sat Apr 19, 2014 2:27 am, edited 3 times in total.
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Have you any a line diagram code?

Post by rsts »

Now that one I can see :)

Very nice presentation. I may well be doing something with this.

cheers
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Have you any a line diagram code?

Post by davido »

RASHAD wrote: Edit :Modified again (Sorry :mrgreen: )
Really?
Every time you modify the code, it just gets better.
Thank you for sharing. :D
DE AA EB
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: Have you any a line diagram code?

Post by ostapas »

Rashad, you outbeat C Boss in Winapi :mrgreen: Kidding, sorry :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Have you any a line diagram code?

Post by RASHAD »

OK guys I never stop be tuned ,edit again
- Less flicker
- Optimized code
- Every bit of the sheet is now supported for X & Y
- Ready to use more than one punch of data in the same session

Have fun
RASHAD
Egypt my love
Post Reply