Seite 1 von 1

Diagramm mit VectorDrawing

Verfasst: 15.11.2015 09:22
von Pelagio
Hallo und Guten Morgen,

ich bin dabei mit PB 5.4 mich etwas zu beschäftigen und fang mit VectorDrawing an.
Ich habe in der Vergangenheit öfters mal Diagrammdarstellungen programmiert und hierfür mir auch eine Include in 2D Drawing geschrieben.
Ich kann mir vorstellen das ich so etwas einfacher mit VectorDrawing bewerkstelligen könnte.
Ich habe schon einmal angefangen, bin aber irgendwie jetzt an einen Punkt angelangt wo es nicht mehr weiter geht.
Das Grundgerüst habe ich aber wie ich eine Kurve darstellen kann ist mir bis dato noch nicht ganz klar.
Vielleicht kann mir ja einer von Euch einen Tipp geben.
Ich hoffe, glaube das es einfacher als mit 2D Drawing gehen müsste aber vielleicht Irre ich mich damit ja auch.

Code: Alles auswählen

; Include Diagrammerstellung
;~~~~~~~~~~~~~~~~~~~~~~~~~~~

DeclareModule ctVectorChart

	Enumeration
		#ALL = -1
		#X
		#Y
		#Back
		#Front
	EndEnumeration

	EnumerationBinary -2
		#Number
		#DateTime
	EndEnumeration

	Structure strucData
		Color.i
		Thick.a
		List Daten.Point()
	EndStructure

;> SetAttributes
	Declare   SetInitialize         (vID.i = #PB_Any)
	Declare   SetChart_AxisData     (vX1.i, vY1.i, vX2.i, vY2.i)
	Declare   SetChart_Color        (vColor.i, vFlag.b = #ALL)
	Declare   SetChart_Rahmen       (vPeg.a = #True, vThick.a = 1, vColor = #PB_Any)
	Declare   SetChart_Lable        (vPeg.a = #True)
	Declare   SetChart_LableText    (vValue.s)
	Declare   SetChart_LableFont    (vFont.i)
	Declare   SetAxis_ScaleCount    (vCount.i, vFlag.b = #ALL)
	Declare   SetAxis_ScaleText     (vPeg.a = #True, vFlag.b = #ALL)
	Declare   SetAxis_ScaleData     (vX1.i, vY1.i, vX2.i, vY2.i)
	Declare   SetAxis_ScaleFont     (vFont.i, vFlag.b = #PB_Any)
	Declare   SetAxis_ScaleLinie    (vPeg.a = #True, vFlag.b = #ALL)
	Declare   SetAxis_ScaleFormat   (vMode.b = #Number, vMask.s = #Null$, vFlag.b = #All)
	Declare   SetAxis_Lable         (vPeg.a = #True, vFlag.b = #ALL)
	Declare   SetAxis_LableText     (vValue.s, vFlag.b = #ALL)
	Declare   SetAxis_LableFont     (vFont.i, vFlag.b = #ALL)
	Declare   SetAxis_Reticule      (vPeg.a = #True, vFlag.b = #ALL)
	Declare   SetAxis_ReticuleForm  (vThick.a = 1, vStyle.a = 3, vFlag.b = #ALL)

;> GetAttributes
	Declare.i GetChart_Color        (vFlag.b)

;> Methoden
	Declare   UseDrawNew         (vFlag.b = #PB_Any)
	Declare   UseDrawChart       ()

EndDeclareModule

Module ctVectorChart

;-{ Privat

	Declare   Table_Draw ()
	Declare   Axis_Draw  ()
	Declare.s Axis_Format(vFlag.b, vValue.d)

	Structure strucLable
		Hide.a
		Value.s
		Font.i
	EndStructure

	Structure strucReticule
		Hide.a
		Thick.a
		Style.a
	EndStructure

	Structure strucRahmen
		Hide.a
		Thick.a
		Color.i
	EndStructure

	Structure strucScale
		Count.i
		Linie.a
		Value.a
		Mode.b
		Mask.s
		Font.i
	EndStructure

	Structure strucAxis
		Minimum.i
		Maximum.i
		Scale.strucScale
		Lable.strucLable
		Reticule.strucReticule
	EndStructure

	Structure strucChart
		ID.i
		StartPoint.Point
		EndPoint.Point
		BackColor.i
		FrontColor.i
		Rahmen.strucRahmen
		Lable.strucLable
		Axis.strucAxis[2]
	EndStructure

	Define.strucChart mChartData

	Procedure Table_Draw()
		Shared mChartData
		Protected n.i, pValue.s, pSizeScale.Point, pLenScale.Point, pData.Point

;1 -> Konstruieren eines Pfades (englisch "path") mit Funktionen wie AddPathLine(), AddPathCurve(), etc. 
;2 -> Auswählen einer Zeichenquelle (englisch "drawing source") wie VectorSourceColor() 
;3 -> Zeichnen (stroke), Füllen (fill), Punkten (dot) oder Schraffieren des Pfades 

		With mChartData
			If StartVectorDrawing(CanvasVectorOutput(\ID))
				If \BackColor
					AddPathBox(\StartPoint\x, \StartPoint\y, \EndPoint\x, -\EndPoint\y)
					VectorSourceColor(\BackColor)
					FillPath()
				EndIf
				If \Rahmen\Hide
					AddPathBox(\StartPoint\x, \StartPoint\y, \EndPoint\x, -\EndPoint\y)
					VectorSourceColor(\Rahmen\Color)
					StrokePath(\Rahmen\Thick)
				Else
					MovePathCursor(\StartPoint\x, \StartPoint\y): AddPathLine(\EndPoint\x, 0, #PB_Path_Relative)
					MovePathCursor(\StartPoint\x, \StartPoint\y): AddPathLine(0, -\EndPoint\y, #PB_Path_Relative)
					VectorSourceColor(\Rahmen\Color)
					StrokePath(\Rahmen\Thick)
				EndIf
				If \Lable\Hide
					VectorFont(FontID(\Lable\Font))
					pValue  = StringField(\Lable\Value, 1, #LF$)
					pData\x = (GadgetWidth(\ID) - VectorTextWidth(pValue)) / 2
					pData\y = VectorTextHeight(pValue)
					MovePathCursor(pData\x, pData\y)
					DrawVectorText(\Lable\Value)
				EndIf
				StopVectorDrawing()
			EndIf
		EndWith
	EndProcedure

	Procedure Axis_Draw()
		Shared mChartData 
		Protected n.i, pValue.s
		Protected pLenScale.Point, pSizeScale.Point, pData.Point

;1 -> Konstruieren eines Pfades (englisch "path") mit Funktionen wie AddPathLine(), AddPathCurve(), etc. 
;2 -> Auswählen einer Zeichenquelle (englisch "drawing source") wie VectorSourceColor() 
;3 -> Zeichnen (stroke), Füllen (fill), Punkten (dot) oder Schraffieren des Pfades 

		With mChartData
			If StartVectorDrawing(CanvasVectorOutput(\ID))
				If \Axis[#X]\Scale\Linie: pLenScale\y = \EndPoint\y * 0.01: EndIf
				If \Axis[#Y]\Scale\Linie: pLenScale\x = \EndPoint\x * 0.01: EndIf
				pSizeScale\x = ((\EndPoint\x) / \Axis[#X]\Scale\Count)
				pSizeScale\y = ((\EndPoint\y) / \Axis[#Y]\Scale\Count)
				For n=0 To \Axis[#X]\Scale\Count
					pData\x = \StartPoint\x + (n * pSizeScale\x)
					pData\y = \StartPoint\y + pLenScale\y
					If \Axis[#X]\Reticule\Hide
						MovePathCursor(pData\x, pdata\y)
						AddPathLine(0, -(\EndPoint\y + pLenScale\y), #PB_Path_Relative)
					ElseIf \Axis[#X]\Scale\Linie
						MovePathCursor(pData\x, pData\y-pLenScale\y)
						AddPathLine(0, pLenScale\y, #PB_Path_Relative)
					EndIf
					If \Axis[#X]\Scale\Value
						VectorFont(FontID(\Axis[#X]\Scale\Font))
						pValue  = Str((\Axis[#X]\Maximum - \Axis[#X]\Minimum) / \Axis[#X]\Scale\Count * n + \Axis[#X]\Minimum)
						pValue = Axis_Format(#X, ValD(pValue))
						pData\x - (VectorTextWidth (pValue) / 2)
						pData\y + (VectorTextHeight(pValue) / 4)
						MovePathCursor(pData\x, pData\y)
						DrawVectorText(pValue)
					EndIf
				Next n
				VectorSourceColor(\Rahmen\Color)
				DotPath(\Axis[#X]\Reticule\Thick, \Axis[#X]\Reticule\Style)
				If \Axis[#X]\Lable\Hide
					VectorFont(FontID(\Axis[#X]\Lable\Font))
					pValue  = StringField(\Axis[#X]\Lable\Value, 1, #LF$)
					pData\x = (GadgetWidth (\ID) - VectorTextWidth(pValue)) / 2
					pData\y =  GadgetHeight(\ID) - (3 * VectorTextHeight(pValue))
					MovePathCursor(pData\x, pData\y)
					DrawVectorText(\Axis[#X]\Lable\Value)
				EndIf

				For n=0 To \Axis[#Y]\Scale\Count
					pData\x = \StartPoint\x - pLenScale\x
					pData\y = \StartPoint\y - (n * pSizeScale\y)
					If \Axis[#Y]\Reticule\Hide
						MovePathCursor(pData\x, pData\y)
						AddPathLine(\EndPoint\x + pLenScale\x, 0, #PB_Path_Relative)
					ElseIf \Axis[#Y]\Scale\Linie
						MovePathCursor(pData\x + pLenScale\x, pData\y)
						AddPathLine(-pLenScale\x, 0, #PB_Path_Relative)
					EndIf
					If \Axis[#Y]\Scale\Value
						VectorFont(FontID(\Axis[#Y]\Scale\Font))
						pValue  = Str((\Axis[#Y]\Maximum - \Axis[#Y]\Minimum) / \Axis[#Y]\Scale\Count * n + \Axis[#Y]\Minimum)
						pValue = Axis_Format(#Y, ValD(pValue))
						pData\x - VectorTextWidth  (pValue + "W")
						pData\y - (VectorTextHeight (pValue) / 2)
						MovePathCursor(pData\x, pData\y)
						DrawVectorText(pValue)
					EndIf
				Next n
				VectorSourceColor(\Rahmen\Color)
				DotPath(\Axis[#Y]\Reticule\Thick, \Axis[#Y]\Reticule\Style)
				If \Axis[#Y]\Lable\Hide
					VectorFont(FontID(\Axis[#X]\Lable\Font))
					pValue  = StringField(\Axis[#Y]\Lable\Value, 1, #LF$)
					pData\x = VectorTextHeight(pValue) / 2
					pData\y = (GadgetHeight(\ID) + VectorTextWidth(pValue)) / 2
					MovePathCursor(pData\x, pData\y)
					RotateCoordinates(pData\x, pData\y, -90)
					DrawVectorText(\Axis[#Y]\Lable\Value)
				EndIf
				StopVectorDrawing()
			EndIf
		EndWith
	EndProcedure

	Procedure.s Axis_Format(vFlag.b, vValue.d)
		Shared mChartData
		Protected pValue.s, pLen.a, pNKS.a, pVKS.a
		Protected pMode.b = mChartData\Axis[vFlag]\Scale\Mode
		Protected pMask.s = mChartData\Axis[vFlag]\Scale\Mask

		Select pMode
			Case #Number
				If FindString(pMask, Chr(46))
					pLen = Len(pMask)
					pVKS = FindString(pMask, Chr(46)) - 1
					pNKS = pLen - pVKS - 1
					vValue * Pow(10, pNKS)
					vValue = Round(vValue, #PB_Round_Nearest)
					vValue / Pow(10, pNKS)
					pValue = StrD(vValue, pNKS)
					If FindString(pMask, "0.")
						pValue = RSet(pValue, pLen, Chr(48))
					EndIf
				Else
					pValue = Str(vValue)
					mChartData\Axis[vFlag]\Scale\Mask = "#"
				EndIf
			Case #DateTime
				pValue = FormatDate(pMask, vValue)
		EndSelect
		ProcedureReturn pValue
	EndProcedure

;} EndPrivat

;-{ Public

;- SetAttributes

	Procedure SetInitialize(vID.i = #PB_Any)
		Shared mChartData
		Protected Dim pFont.i(2), pValue.i

		With mChartData
			If (vID>#PB_Any)
				pFont(0) = LoadFont(#PB_Any, "Courier New", 16)
				pFont(1) = LoadFont(#PB_Any, "Courier New", 12)
				pFont(2) = LoadFont(#PB_Any, "Courier New", 10)
				\ID                      = vID
				\StartPoint\x            = 100
				\BackColor               = #PB_Any
				\FrontColor              = #PB_Any
				\Rahmen\Hide             = #Null
				\Rahmen\Color            = RGBA(0, 0, 0, 255)
				\Rahmen\Thick            = 1
				\Lable\Hide              = #Null
				\Lable\Font              = pFont(0)
				\Lable\Value             = #Null$
				\Axis[#X]\Minimum        = 0
				\Axis[#X]\Maximum        = 10
				\Axis[#X]\Scale\Count    = 10
				\Axis[#X]\Scale\Linie    = #True
				\Axis[#X]\Scale\Font     = pFont(2)
				\Axis[#X]\Scale\Value    = #True
				\Axis[#X]\Scale\Mode     = #Number
				\Axis[#X]\Scale\Mask     = "#"
				\Axis[#X]\Lable\Hide     = #Null
				\Axis[#X]\Lable\Font     = pFont(1)
				\Axis[#X]\Lable\Value    = #Null$
				\Axis[#X]\Reticule\Hide  = #Null
				\Axis[#X]\Reticule\Style = 3
				\Axis[#X]\Reticule\Thick = 1
				\Axis[#Y]\Minimum        = 0
				\Axis[#Y]\Maximum        = 10
				\Axis[#Y]\Scale\Count    = 10
				\Axis[#Y]\Scale\Linie    = #True
				\Axis[#Y]\Scale\Font     = pFont(2)
				\Axis[#Y]\Scale\Value    = #True
				\Axis[#Y]\Scale\Mode     = #Number
				\Axis[#Y]\Scale\Mask     = "#"
				\Axis[#Y]\Lable\Hide     = #Null
				\Axis[#Y]\Lable\Font     = pFont(1)
				\Axis[#Y]\Lable\Value    = #Null$
				\Axis[#Y]\Reticule\Hide  = #Null
				\Axis[#Y]\Reticule\Style = 3
				\Axis[#Y]\Reticule\Thick = 1
			EndIf
			\StartPoint\y = GadgetHeight(\ID) - \StartPoint\x
			\EndPoint\x   = GadgetWidth (\ID) - \StartPoint\x * 1.4
			If \Lable\Hide
				\EndPoint\y = GadgetHeight(\ID) - \StartPoint\x * 2.0
			Else
				\EndPoint\y = GadgetHeight(\ID) - \StartPoint\x * 1.4
			EndIf
		EndWith
	EndProcedure

	Procedure SetChart_AxisData(vXmin.i, vYmin.i, vXmax.i, vYmax.i)
		Shared mChartData

		With mChartdata
			\StartPoint\x = vXmin
			\EndPoint\x   = vXmax
			\StartPoint\y = vYmin
			\EndPoint\y   = vYmax
		EndWith
	EndProcedure

	Procedure SetChart_Color(vColor.i, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#Back) : \BackColor = vColor: EndIf
			If (vFlag=#ALL) Or (vFlag=#Front): \FrontColor= vColor: EndIf
		EndWith
	EndProcedure

	Procedure SetChart_Rahmen(vPeg.a = #True, vThick.a = 1, vColor.i = #PB_Any)
		Shared mChartData

		If (vThick=0): vThick=1: EndIf
		With mChartData\Rahmen
			\Hide  = vPeg
			\Thick = vThick
			If (vColor=#PB_Any): vColor = RGBA(0, 0, 0, 255): EndIf
			\Color = vColor
		EndWith
	EndProcedure

	Procedure SetChart_Lable(vPeg.a = #True)
		Shared mChartData

		mChartData\Lable\Hide = vPeg
	EndProcedure

	Procedure SetChart_LableText(vValue.s)
		Shared mChartData

		mChartData\Lable\Value = vValue
	EndProcedure

	Procedure SetChart_LableFont(vFont.i)
		Shared mChartData

		mChartData\Lable\Font = vFont
	EndProcedure

	Procedure SetAxis_ScaleCount(vCount.i, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Scale\Count = vCount: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Scale\Count = vCount: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_ScaleText(vPeg.a = #True, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Scale\Value = vPeg: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Scale\Value = vPeg: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_ScaleData(vXmin.i, vYmin.i, vXmax.i, vYmax.i)
		Shared mChartData

		With mChartdata
			\Axis[#X]\Minimum = vXmin
			\Axis[#X]\Maximum = vXmax
			\Axis[#Y]\Minimum = vYmin
			\Axis[#Y]\Maximum = vYmax
		EndWith
	EndProcedure

	Procedure SetAxis_ScaleFont(vFont.i, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Scale\Font = vFont: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Scale\Font = vFont: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_ScaleLinie(vPeg.a = #True, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Scale\Linie = vPeg: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Scale\Linie = vPeg: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_ScaleFormat(vMode.b = #Number, vMask.s = #Null$, vFlag.b = #All)
		Shared mChartData

		vMask = ReplaceString(vMask, Chr(44), Chr(46))
		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X)
				\Axis[#X]\Scale\Mode = vMode
				\Axis[#X]\Scale\Mask = vMask
			EndIf
			If (vFlag=#ALL) Or (vFlag=#Y)
				\Axis[#Y]\Scale\Mode = vMode
				\Axis[#Y]\Scale\Mask = vMask
			EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_Lable(vPeg.a = #True, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Lable\Hide = vPeg: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Lable\Hide = vPeg: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_LableText(vValue.s, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Lable\Value = vValue: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Lable\Value = vValue: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_LableFont(vFont.i, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Lable\Font = vFont: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\lable\Font = vFont: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_Reticule(vPeg.a = #True, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X): \Axis[#X]\Reticule\Hide = vPeg: EndIf
			If (vFlag=#ALL) Or (vFlag=#Y): \Axis[#Y]\Reticule\Hide = vPeg: EndIf
		EndWith
	EndProcedure

	Procedure SetAxis_ReticuleForm(vThick.a = 1, vStyle.a = 3, vFlag.b = #ALL)
		Shared mChartData

		With mChartData
			If (vFlag=#ALL) Or (vFlag=#X)
				\Axis[#X]\Reticule\Thick = vThick
				\Axis[#X]\Reticule\Style = vStyle
			EndIf
			If (vFlag=#ALL) Or (vFlag=#Y)
				\Axis[#Y]\Reticule\Thick = vThick
				\Axis[#Y]\Reticule\Style = vStyle
			EndIf
		EndWith
	EndProcedure

;} EndSetAttributes

;- GetAttributes

	Procedure.i GetChart_Color(vFlag.b)
		Shared mChartData
		Protected pColor.i

		With mChartData
			If (vFlag=#Back) : pColor = \BackColor: EndIf
			If (vFlag=#Front): pColor = \FrontColor: EndIf
		EndWith
		ProcedureReturn pColor
	EndProcedure

;} EndGetAttributes

;- Methoden

	Procedure UseDrawNew(vFlag.b = #PB_Any)
		Shared mChartData

		SetInitialize(vFlag)
		Table_Draw   ()
		Axis_Draw    ()
	EndProcedure

	Procedure UseDrawChart()
		Shared mChartData
		Protected n.i, pSizeScale.Point, pLenScale.Point

		Table_Draw()
		Axis_Draw ()
	EndProcedure

;} EndMethoden

;} EndPublic

EndModule

; Programm: Diagrammerstellung
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EnableExplicit

Enumeration
	#WinID
	#TafID
	#BarID
	#Timer
	#btnExit
	#conArea
	#btnTitle
	#btnRahmen
	#btnBackColor
	#btnFrontColor
	#btnReticuleX
	#btnReticuleY
	#conX
	#btnLinieX
	#btnTextX
	#conY
	#btnLinieY
	#btnTextY
EndEnumeration

;IncludeFile "CT_VectorChart.pbi"

Global gXY.ctVectorChart::strucData
Global gTabWidth.i = 225

Declare   Main                ()
Declare   Window_Create       ()
Declare   StatusBar_Create    ()
Declare   Gadget_Create       ()
Declare   Timer_Event         ()
Declare   Size_Event          ()
Declare.a Gadget_Event        (vID.i)
Declare   Chart_Initialization()
Declare   Data_Read           ()

;-{ Command

Procedure Main()
	Protected pQuit.a, pEvent.i

	Window_Create()
	AddWindowTimer(#WinID, #Timer, 60000)
	ctVectorChart::SetInitialize(#TafID)
	Chart_Initialization()
	ctVectorChart::UseDrawChart()
	Repeat
		pEvent = WaitWindowEvent()
		Select pEvent
			Case #PB_Event_CloseWindow: pQuit = #True
			Case #PB_Event_SizeWindow : Size_Event()
			Case #PB_Event_Timer      : Timer_Event()
			Case #PB_Event_Gadget     : pQuit = Gadget_Event(EventGadget())
		EndSelect
	Until pQuit
EndProcedure

Procedure Timer_Event()

	StatusBarText(#BarID, 1, FormatDate("%dd.%mm.%yyyy", Date()), #PB_StatusBar_Center)
	StatusBarText(#BarID, 2, FormatDate("%hh:%ii"      , Date()), #PB_StatusBar_Center)
EndProcedure

Procedure Size_Event()
	Protected pX.i, pY.i, pWidth.i = WindowWidth(#WinID) - gTabWidth

	pX = pWidth + 10: ResizeGadget(#conArea , pX, #PB_Ignore, #PB_Ignore, #PB_Ignore)
	pX = pWidth + 10: ResizeGadget(#conX    , pX, #PB_Ignore, #PB_Ignore, #PB_Ignore)
	pX = pWidth + 10: ResizeGadget(#conY    , pX, #PB_Ignore, #PB_Ignore, #PB_Ignore)
	pX = (pWidth) + (gTabWidth - 80) / 2: pY = WindowHeight(#WinID) - 80
	ResizeGadget(#btnExit, pX, pY, #PB_Ignore, #PB_Ignore)
	FreeGadget(#TafID)
	CanvasGadget(#TafID, 5, 5, pWidth, WindowHeight(#WinID)-10-StatusBarHeight(#BarID), #PB_Canvas_Border)
	ctVectorChart::UseDrawNew()
EndProcedure

Procedure.a Gadget_Event(vID.i)
	Protected pQuit.a, pValue.s, pFlag.i
	Protected pColor.i, pRed.i, pGreen.i, pBlue.i

	Select vID
		Case #btnExit: pQuit = #True
		Case #btnTitle
			ctVectorChart::SetChart_Lable(GetGadgetState(vID))
			Size_Event()
		Case #btnRahmen
			ctVectorChart::SetChart_Rahmen(GetGadgetState(vID))
			Size_Event()
		Case #btnBackColor, #btnFrontColor
			pFlag  = ctVectorChart::#Back
			If (vID=#btnFrontColor): pFlag = ctVectorChart::#Front: EndIf
			pColor = ctVectorChart::GetChart_Color(pFlag)
			pRed   = Red(pColor): pGreen = Green(pColor): pBlue = Blue(pColor)
			pColor = ColorRequester(RGB(pRed, pGreen, pBlue))
			If (pColor<>#PB_Any)
				pRed   = Red(pColor): pGreen = Green(pColor): pBlue = Blue(pColor)
				ctVectorChart::SetChart_Color(RGBA(pRed, pGreen, pBlue, 255), pFlag)
				Size_Event()
			EndIf
		Case #btnReticuleX
			ctVectorChart::SetAxis_Reticule(GetGadgetState(vID), ctVectorChart::#X)
			Size_Event()
		Case #btnLinieX
			ctVectorChart::SetAxis_ScaleLinie(GetGadgetState(vID), ctVectorChart::#X)
			Size_Event()
		Case #btnTextX
			ctVectorChart::SetAxis_ScaleText(GetGadgetState(vID), ctVectorChart::#X)
			Size_Event()
		Case #btnReticuleY
			ctVectorChart::SetAxis_Reticule(GetGadgetState(vID), ctVectorChart::#Y)
			Size_Event()
		Case #btnLinieY
			ctVectorChart::SetAxis_ScaleLinie(GetGadgetState(vID), ctVectorChart::#Y)
			Size_Event()
		Case #btnTextY
			ctVectorChart::SetAxis_ScaleText(GetGadgetState(vID), ctVectorChart::#Y)
			Size_Event()
	EndSelect
	ProcedureReturn pQuit
EndProcedure

;} EndCommand

;-{ Design

Procedure Window_Create()
	Protected pWidth.i = 900 - gTabWidth

	If OpenWindow  (#WinID, 0, 0, 900, 600, "VectorDrawing", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget)
		StatusBar_Create()
		CanvasGadget(#TafID, 5, 5, pWidth, WindowHeight(#WinID)-10-StatusBarHeight(#BarID), #PB_Canvas_Border)
		Gadget_Create()
	EndIf
	ProcedureReturn
EndProcedure

Procedure StatusBar_Create()

	If CreateStatusBar(#BarID, WindowID(#WinID))
		AddStatusBarField(#PB_Ignore)
		AddStatusBarField(80)
		AddStatusBarField(60)
		Timer_Event()
	EndIf
EndProcedure

Procedure Gadget_Create()
	Protected pX.i, pY.i, pID.i
	Protected pWidth.i = WindowWidth(#WinID) - gTabWidth

	pX = (pWidth) + (gTabWidth - 80) / 2
	pY = WindowHeight(#WinID) - 80
	ButtonGadget(#btnExit, pX, pY, 80, 25, "Exit")
	pX = (pWidth) + 10: pY = 10
	If ContainerGadget(#conArea, pX, pY, gTabWidth - 20, 100)
		pID = FrameGadget(#PB_Any, 0, 0, gTabWidth - 20, 100, "Zeichnungsfläche")
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 20
		ButtonGadget(#btnTitle     , pX, pY, 80, 25, "Titel", #PB_Button_Toggle)
		pX = GadgetX(pID) + 105: pY = GadgetY(pID) + 20
		ButtonGadget(#btnRahmen    , pX, pY, 80, 25, "Rahmen", #PB_Button_Toggle)
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 60
		ButtonGadget(#btnBackColor , pX, pY, 80, 25, "BackColor")
		pX = GadgetX(pID) + 105: pY = GadgetY(pID) + 60
		ButtonGadget(#btnFrontColor, pX, pY, 80, 25, "FrontColor")
		CloseGadgetList()
	EndIf

	pX = pWidth + 10: pY = GadgetY(#conArea) + 110
	If ContainerGadget(#conX, pX, pY, gTabWidth - 20, 100)
		pID = FrameGadget(#PB_Any, 0, 0, gTabWidth - 20, 100, "X-Achse")
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 20
		ButtonGadget(#btnReticuleX , pX, pY, 80, 25, "Gitternetz", #PB_Button_Toggle)
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 60
		ButtonGadget(#btnLinieX    , pX, pY, 80, 25, "Linie Anzeige", #PB_Button_Toggle)
		pX = GadgetX(pID) + 105: pY = GadgetY(pID) + 60
		ButtonGadget(#btnTextX     , pX, pY, 80, 25, "Text Anzeige", #PB_Button_Toggle)
		CloseGadgetList()
	EndIf

	pX = pWidth + 10: pY = GadgetY(#conX) + 110
	If ContainerGadget(#conY, pX, pY, gTabWidth - 20, 100)
		pID = FrameGadget(#PB_Any, 0, 0, gTabWidth - 20, 100, "Y-Achse")
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 20
		ButtonGadget(#btnReticuleY , pX, pY, 80, 25, "Gitternetz", #PB_Button_Toggle)
		pX = GadgetX(pID) + 015: pY = GadgetY(pID) + 60
		ButtonGadget(#btnLinieY    , pX, pY, 80, 25, "Linie Anzeige", #PB_Button_Toggle)
		pX = GadgetX(pID) + 105: pY = GadgetY(pID) + 60
		ButtonGadget(#btnTextY     , pX, pY, 80, 25, "Text Anzeige", #PB_Button_Toggle)
		CloseGadgetList()
	EndIf
EndProcedure

;} Enddesign

;-{ Function

Procedure Chart_Initialization()

	UseModule ctVectorChart
		SetChart_Rahmen    (GetGadgetState(#btnRahmen))
		SetChart_Color     (RGBA(255, 255, 0, 255), #Back)
		SetChart_Color     (RGBA(255, 000, 0, 255), #Front)
		SetChart_LableText ("Dies ist ein Versuch" + #LF$ + "       [Test]")
		SetChart_Lable     (GetGadgetState(#btnTitle))
		SetAxis_Reticule   (GetGadgetState(#btnReticuleX), #X)
		SetAxis_Reticule   (GetGadgetState(#btnReticuleY), #Y)
		SetAxis_ScaleData  (2000, 0, 3500, 13500)
		SetAxis_ScaleFont  (LoadFont(#PB_Any, "Courier New", 10, #BOLD_FONTTYPE), #X)
		SetAxis_ScaleCount (10)
		SetAxis_ScaleLinie (GetGadgetState(#btnLinieX), #X)
		SetAxis_ScaleLinie (GetGadgetState(#btnLinieY), #Y)
		SetAxis_ScaleText  (GetGadgetState(#btnTextX) , #X)
		SetAxis_ScaleText  (GetGadgetState(#btnTextY) , #Y)
		;SetAxis_ScaleFormat(#DateTime, "%dd.%mm.%yyyy" + #LF$ + "   %hh:%ii", #X)
		;SetAxis_ScaleFormat(#Number, "#.00", #Y)
		SetAxis_LableText  ("[TEST]")
		SetAxis_Lable      (#True)
		SetInitialize      ()
	UnuseModule ctVectorChart
EndProcedure

Procedure Data_Read()
	Protected pDS.s, pRead.a = #True
	Protected Dim pData.Point(1)

	If ReadFile(0, "VectorChartTest.txt") ; Testdatenliste: X;Y
		gXY\Color = RGBA(0, 0, 255, 255)
		gXY\Thick = 1
		While Not Eof(0)
			pDS = ReadString(0)
			pRead + 1
			If pDS
				AddElement(gXY\Daten())
				gXY\Daten()\x = Val(StringField(pDS, 1, ";"))
				gXY\Daten()\y = Val(StringField(pDS, 2, ";"))
			EndIf
		Wend
	CloseFile(0)
	EndIf
EndProcedure

;} EndFunction

Data_Read()
Main()

End
Leider weiß ich nicht wie ich die Datei anhängen kann daher der gesamte Code im Codefenster.

Re: Diagramm mit VectorDrawing

Verfasst: 15.11.2015 12:53
von STARGÅTE
Klingt jetzt komisch, aber so wie du es sonst auch gemachst hast.

Wenn du 100 Datenpunkte hast, kannst du die ja einfach in einer Schleife ab arbeiten und mit AddPathLine() einfach diesen Punkt zum Pfad hinzufügen.
Danach kann mit StrokePath zeichnen.

Re: Diagramm mit VectorDrawing

Verfasst: 15.11.2015 13:30
von NicTheQuick
Wieso nutzt du #BOLD_FONTTYPE statt #PB_Font_Bold?
Es ist immer schon schlimm genug, dass es die Point-Structure in Linux nicht gibt, sie aber jeder nutzt.

Re: Diagramm mit VectorDrawing

Verfasst: 15.11.2015 15:28
von Pelagio
NicTheQuick hat geschrieben:Wieso nutzt du #BOLD_FONTTYPE statt #PB_Font_Bold?
du hast recht. Normalerweise würde ich #PB_Font_Bold nehmen aber in diesem Falle habe ich das ganze irgendwo heraus kopiert ohne lange nachzudenken.
STARGÅTE hat geschrieben:Klingt jetzt komisch, aber so wie du es sonst auch gemachst hast.
Ich habe die Aussage befürchtet.
Im Laufe meiner Jahre sind mir X Programmiersprachen über den Weg gelaufen (bei PB bin ich hängen geblieben) und ich habe irgendwo im Kopf behalten das es eine gab wo ich einen Bereich so konvertieren konnte das die Datenpunkte, ohne sie umrechnen zu müssen, in den Bereich eingeben konnte. Ich konnte also die Koordinaten eines Bereichs bestimmen Bspw. X=0,100 & Y = 50;80 und den Datenpunkt x=20/Y=60 eintragen. Ich habe gehofft das so etwas jetzt für VectorDrawing auch gehen würde.
:allright: DANKE für Eure Antworten.

Re: Diagramm mit VectorDrawing

Verfasst: 15.11.2015 19:24
von STARGÅTE
Du kannst mit TranslateCoordinates() und ScaleCoordinates() dein eigenes Koordinatensystem festlegen.
Beachte jedoch, dass bei ScaleCoordinates auch die Linien-Dicke skaliert wird.

Ansonsten tuts halt eine einfache Convert-Funktion:

Code: Alles auswählen

Structure Area
	X.f
	Y.f
	Width.f
	Height.f
EndStructure

Structure Coordinates
	Drawing.Area
	Source.Area
EndStructure

Global Coordinates.Coordinates

Procedure Coordinates(DrawingX.f, DrawingY.f, DrawingWidth.f, DrawingHeight.f, SourceX.f, SourceY.f, SourceWidth.f, SouceHeight.f)
	Coordinates\Drawing\X = DrawingX
	Coordinates\Drawing\Y = DrawingY
	Coordinates\Drawing\Width = DrawingWidth
	Coordinates\Drawing\Height = DrawingHeight
	Coordinates\Source\X = SourceX
	Coordinates\Source\Y = SourceY
	Coordinates\Source\Width = SourceWidth
	Coordinates\Source\Height = SouceHeight
EndProcedure

Procedure ConvertX(X.f)
	ProcedureReturn Coordinates\Drawing\X + Coordinates\Drawing\Width*(X-Coordinates\Source\X)/Coordinates\Source\Width
EndProcedure

Procedure ConvertY(Y.f)
	ProcedureReturn Coordinates\Drawing\Y + Coordinates\Drawing\Height*(Y-Coordinates\Source\Y)/Coordinates\Source\Height
EndProcedure

; Drawing-Bereich und Datenquellen-Bereich definieren
Coordinates(100, 200, 200, 100, -1, -1, 2, 2)

Debug ConvertX(0)
Debug ConvertY(0)
Debug ConvertX(1)
Debug ConvertY(1)