ࡱ> NPMG #bjbjَ -h]     LV< VXXXXXX${||    V  V L VV)Mw  jV''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' QLineGraph ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright (c) Jonathan Boles 2002 ''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' PROPERTIES '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Height AS Integer - self explanatory ' ' Width AS Integer - ' ' Top AS Integer - ' ' Left AS Integer - ' ' ExtrapolateToZero AS Boolean - whether the graph should start at 0,0 ' ' AxisColour AS Integer - Colour for axes ' ' TextColour AS Integer - Colour for text ' ' BackColour AS Integer - Colour for background ' ' LineColour AS Integer - Colour for plotted line ' ' XTitle AS String - X axis title ' ' YTitle AS String - Y axis title ' ' Title AS String - Title for graph ' ' Data AS QStringGrid - Graph data, stored in form ' ' - x=Data.Cell(0,i) y=Data.Cell(1,i) where ' ' - i is an integer ' ' TextFont AS QFont - Font for graph text ' ' Visible AS Boolean - ' ' Hint AS String - ' ' ShowHint AS Boolean - ' ' Cursor AS Integer - Cursor for the graph ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' METHODS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' SUB Initialise - Initialise graphsystem ' ' SUB SaveToFile - save graph to .bmp (can't get this 2 work ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' TYPE QLineGraph EXTENDS QOBJECT Height AS INTEGER Width AS INTEGER Top AS INTEGER Left AS INTEGER ExtrapolateToZero AS INTEGER AxisColour AS INTEGER TextColour AS INTEGER BackColour AS INTEGER XTitle AS STRING*50 YTitle AS STRING*50 Title AS STRING*100 XScale AS SINGLE YScale AS SINGLE LineColour AS INTEGER DATA AS QSTRINGGRID Visible AS INTEGER Hint AS STRING*100 TextFont AS QFONT Cursor AS INTEGER ShowHint AS INTEGER image AS QCANVAS maxX AS SINGLE maxY AS SINGLE powerX AS INTEGER powerY AS INTEGER roundedupX AS LONG roundedupY AS LONG CONSTRUCTOR Left=0 Width=400 Top=0 Height=300 AxisColour=0 TextColour=0 LineColour=&HFF BackColour=&HFFFFFF XTitle="X Axis" YTitle="Y Axis" Title="X Axis vs. Y Axis" ExtrapolateToZero=1 Visible=1 END CONSTRUCTOR SUB Paint WITH QLineGraph .image.visible=.visible .image.hint=.hint .image.font=.textfont .image.cursor=.cursor .image.showhint=.showhint ''''''''''' set size'''''''''''''''' .image.height=.Height .image.width=.Width .image.left=.Left .image.top=.Top '''''''''' Clear the canvas ''''''''' .image.fillrect(0,0, .image.width, .image.height, clWhite) '''''''''' write title '''''''''''''' .image.textout(INT(0.5*.image.width)-INT(.image.textwidth(RTRIM$(.Title))/2),INT(0.02*.image.height), RTRIM$(.Title),.TextColour,.BackColour) '''''''''' write axis titles '''''''' .image.textout(INT(0.52*.image.width)-INT(.image.textwidth(RTRIM$(.YTitle))/2),INT(0.93*.image.height),RTRIM$(.XTitle),.TextColour,.BackColour) .image.textout(INT(0.02*.image.width),INT(0.45*.image.height),RTRIM$(.YTitle),.TextColour,.BackColour) '''''''''' draw the axes '''''''''''' .image.line(INT(0.15*.image.width), INT(0.85*.image.height), INT(0.9*.image.width), INT(0.85*.image.height),AxisColour) .image.line(INT(0.15*.image.width), INT(0.1*.image.height), INT(0.15*.image.width), INT(0.85*.image.height),AxisColour) '''''''''' calculate scale '''''''''' FOR i=0 TO .Data.RowCount IF VAL(.Data.Cell(0,i))>.maxX THEN .maxX=INT(VAL(.Data.Cell(0,i)))+1 NEXT FOR i=0 TO .Data.RowCount IF VAL(.Data.Cell(1,i))>.maxY THEN .maxY=INT(VAL(.Data.Cell(1,i)))+1 NEXT 'if int(log(.maxX)/log(10))+1=1 then .powerX=INT(LOG(.maxX)/LOG(10))+1 FOR i=10^(.powerX-1) TO 10^.powerX STEP 10^(.powerX-1) IF i>.maxX THEN EXIT FOR NEXT .roundedupX=i 'end if 'if int(log(.maxY)/log(10))+1=1 then .powerY=INT(LOG(.maxY)/LOG(10))+1 FOR i=10^(.powerY-1) TO 10^.powerY STEP 10^(.powerY-1) IF i>.maxY THEN EXIT FOR NEXT .roundedupY=i 'end if ''''''''' Draw scale '''''''''''''' FOR i=0 TO .roundedupX STEP 10^(.powerX-1) ''''''''''' X .image.pset(INT(0.15*.image.width)+(i/.roundedupX*INT(0.74*.image.width)),INT(0.85*.image.height)+2,AxisColour) .image.pset(INT(0.15*.image.width)+(i/.roundedupX*INT(0.74*.image.width)),INT(0.85*.image.height)+1,AxisColour) .image.textout(INT(0.15*.image.width)+(i/.roundedupX*INT(0.74*.image.width))-.image.textwidth(STR$(i))/2,INT(0.85*.image.height)+5,STR$(i),.TextColour,.BackColour) NEXT FOR i=0 TO .roundedupY STEP 10^(.powerY-1) ''''''''''' Y .image.pset(INT(0.15*.image.width)-1,INT(0.85*.image.height)-(i/.roundedupY*INT(0.74*.image.height)),AxisColour) .image.pset(INT(0.15*.image.width)-2,INT(0.85*.image.height)-(i/.roundedupY*INT(0.74*.image.height)),AxisColour) .image.textout(INT(0.15*.image.width)-5-.image.textwidth(STR$(i)),INT(0.85*.image.height)-(i/.roundedupY*INT(0.74*.image.height))-INT(.image.textheight(STR$(i))/2),STR$(i),.TextColour,.BackColour) NEXT '''''''''' plot points '''''''''''' IF ExtrapolateToZero THEN .image.line(INT(0.15*.image.width),INT(0.85*.image.height), _ INT(0.15*.image.width)+(VAL(.Data.Cell(0,i))/.roundedupX*INT(0.74*.image.width)),INT(0.85*.image.height)-(VAL(.Data.Cell(1,i))/.roundedupY*INT(0.74*.image.height)),.LineColour) END IF FOR i=1 TO .Data.RowCount-1 .image.line(INT(0.15*.image.width)+(VAL(.Data.Cell(0,i-1))/.roundedupX*INT(0.74*.image.width)),INT(0.85*.image.height)-(VAL(.Data.Cell(1,i-1))/.roundedupY*INT(0.74*.image.height)), _ INT(0.15*.image.width)+(VAL(.Data.Cell(0,i))/.roundedupX*INT(0.74*.image.width)),INT(0.85*.image.height)-(VAL(.Data.Cell(1,i))/.roundedupY*INT(0.74*.image.height)),.LineColour) NEXT END WITH END SUB SUB Initialise WITH QLineGraph QLineGraph.image.height=QLineGraph.Height QLineGraph.image.width=QLineGraph.Width QLineGraph.image.left=QLineGraph.Left QLineGraph.image.top=QLineGraph.Top QLineGraph.image.onpaint=QLineGraph.Paint .image.visible=.visible END WITH END SUB SUB SaveToFile(file AS STRING) WITH QLineGraph DIM d AS QRECT, bmp AS QBITMAP bmp.height=.image.height bmp.width=.image.width d.top=0 d.left=0 d.right=.image.width d.bottom=.image.height .image.copyrect(d, bmp, d) bmp.savetofile(file) END WITH END SUB END TYPE  #%&-8:;BNPQXqst{+-.4BDEK]_`gnrsuv  ! B*OJQJOJQJ B* OJQJ^J(rP.x V4 ~  \ :  b  v%J(rP.x V4 ~  \ :  b @ .CY|5Lh+@Xp2Md{&@^|7edb @ .CY|5Lh v%+@Xp2Md{ v%!#$*689?MOPWegho\bsy7e|}%')*+./ABDJKQRjkl B*OJQJ B* OJQJ B* OJQJOJQJ B*OJQJY&@^|7el2Omz v%l2Omz%O;z?1.")KM\@ !!&!'!STWXijklz}~  !"/0HILM^_ B* OJQJ B*OJQJOJQJ B*OJQJ\_`aors  -BCFGXY\_`rstu !9:=>OPcdhijlm B* OJQJ B*OJQJ B*OJQJOJQJ\mpq)13FJ_`cduvwz{  '*+=?KLUXY[dg B* OJQJOJQJ B*OJQJ B*OJQJ\KM\@ !!&!'! _PID_GUIDAN{F9E5C8C0-E2CC-11D6-A06A-0060970A26E3}  !"#$%&'()*+,-./012346789:;<>?@ABCDFGHIJKLORoot Entry