BBC BASIC for Windows
« Generic Graphing routine »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Generic Graphing routine  (Read 403 times)
AndrewCool
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Generic Graphing routine
« Thread started on: Jan 10th, 2017, 11:30pm »

Hi All,

Before I reinvent the wheel (badly), does anyone have a generic graphing routine that will produce a graph with axis, ticks, labels and titles?

Something like :-

Graph, data, xrange=[0,10], yrange=[0,100], title='Graph Test', xtitle='Distance(km)', ytitle='Temperature(C)'

I can't be the first person to want to do this, surely?


Regards,

Andrew
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Generic Graphing routine
« Reply #1 on: Jan 11th, 2017, 04:04am »

If you look in the tool section, there is a link to RETROLIB 10... There is FNbuttonz for easy to use buttons and FNinput for sizeable text input and PROCpr which prints text with a custom background color. (palette)

If you need a more direct version of a screen print, I can make a link to RETROLIB 11, which has had a few more special commands.

As for the graph idea.. I think you would have to design that, as there are limitless ways to make graphs.

I also included a reference.

You may also want to look at the FNcolormix tool. It uses PROCsbox for gauges that can be repositioned with your mouse. PROCsbox is very versatile.
« Last Edit: Jan 11th, 2017, 04:17am by michael » User IP Logged

I like making program generators and like reinventing the wheel
DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Generic Graphing routine
« Reply #2 on: Jan 11th, 2017, 12:05pm »

Hi Andrew,

It's certainly been discussed before, though I can't find the thread - it may have been on the Yahoo forum - yes, I can find some threads on the Groups.io forum you could have a look at.

Yes, found the thread:
https://groups.io/g/bb4w/topic/a_simple_line_graph_plotter/1143104?p=,,,20,0,0,0::Relevance,,graphs,20,2,0,1143104

The link doesn't seem to be complete, so you'll probably need to copy and paste, rather than just clicking.

That may give some context, and some other ideas.

Here's some code I wrote at that time. It doesn't (yet) label axes or put in tick marks, but on the other hand it allows you to specify the size, location, and colour of your graphs.

You are very welcome to use/adapt my code if it is at all useful.

Best wishes,

D
Best wishes,

D
Code:
      MODE 21

      DIM graphformat{bboxwidth%,bboxheight%,bboxbackcol%,bboxcol%,     \ Set characteristics for the bounding box
      \               gwidth%,gheight%,gbackcol%,gboxcol%,              \ Set characteristics for the graph area itself
      \               xcol%,xthick%,xmin,xmax,xdivs%,                   \ Set characteristics of the x axis
      \               ycol%,ythick%,ymin,ymax,ydivs%,                   \ Set characteristics of the y axis
      \               title$,titlecol%,titlesize%,titlex%,titley%,      \ Set characteristics of the chart title
      \               xlabel$,xlabelcol%,xlabelsize%,xlabelx%,xlabely%, \ Set characteristics of the x axis label
      \               ylabel$,ylabelcol%,ylabelsize%,ylabelx%,ylabely%} : REM  Set characteristics of the y axis label

      REM set up default values
      graphformat.bboxwidth%=800
      graphformat.bboxheight%=600
      graphformat.bboxbackcol%=15
      graphformat.bboxcol%=15
      graphformat.gwidth%=600
      graphformat.gheight%=400
      graphformat.gbackcol%=15
      graphformat.gboxcol%=0
      graphformat.xcol%=0
      graphformat.xthick%=1
      graphformat.xmin=0
      graphformat.xmax=0
      graphformat.xdivs%=1
      graphformat.ycol%=0
      graphformat.ythick%=1
      graphformat.ymin=0
      graphformat.ymax=0
      graphformat.ydivs%=1

      DIM data(11,2)
      REM Note: the first column (x=0) will contain the number of data points, and the n+1st will contain the data marker specification
      FOR x%=0 TO 10
        FOR y%=0 TO 2
          READ data(x%,y%)
        NEXT y%
      NEXT x%

      DATA 10,10,10,3,4,5,4,4,6,6,8,7,8,8,10,10,10,10,11,8,6,12,6,8,14,10,12,16,14,20,18,20,20

      REM set data marker specifications: colour (0-15) +
      REM                                 line style (16 x:   0=solid,1=dotted, 2=dashed, 3=broken, 4=none) +
      REM                                 marker type(256 x:  0=+, 1=x, 2=dot,3=circle, 4=square, 5=none)
      REM                                 marker size(65536x: 4 BB4W graphics units plus value)
      data(data(0,0)+1,0)=0
      data(data(0,1)+1,1)=1+16*2+256*3+65536*5
      data(data(0,2)+1,2)=4+16*1+256*2+65536*5



      REM make a "nice" background so we can see where the graph is
      GCOL 128+6
      CLG


      PROClinegraph(100,100,graphformat{},data(),3)  :REM Plot a linegraph at the coordinates given, in the format specified, using the data block, showing 3 series

      REM OK, Let's play around a bit
      graphformat.bboxwidth%=400
      graphformat.bboxheight%=300
      graphformat.gwidth%=350
      graphformat.gheight%=200
      data(data(0,0)+1,0)=7+16*4+256*1
      data(data(0,1)+1,1)=2+16*3+256*4+65536*3
      data(data(0,2)+1,2)=3+16*1+256*5+65536*5
      PROClinegraph(1000,100,graphformat{},data(),3)  :REM Plot a linegraph at the coordinates given, in the format specified, using the data block, showing 3 series

      graphformat.bboxwidth%=1200
      graphformat.bboxheight%=400
      graphformat.gwidth%=1100
      graphformat.gheight%=300
      graphformat.bboxbackcol%=8
      graphformat.bboxcol%=1
      graphformat.gbackcol%=4
      graphformat.gboxcol%=15
      graphformat.xcol%=15
      graphformat.ycol%=15
      PROClinegraph(100,750,graphformat{},data(),3)  :REM Plot a linegraph at the coordinates given, in the format specified, using the data block, showing 3 series


      END
      :
      DEFPROClinegraph(px%,py%,gform{},d(),ns%)
      LOCAL xoff%,yoff%,xscale,yscale,xsep,maxx%,maxy,miny,x%,y%,linestyle%,mtype%,msize%
      GCOL gform.bboxbackcol%
      RECTANGLE FILL px%,py%,gform.bboxwidth%,gform.bboxheight%
      GCOL gform.bboxcol%
      RECTANGLE px%,py%,gform.bboxwidth%,gform.bboxheight%
      xoff%=px%+(gform.bboxwidth%-gform.gwidth%) DIV 2
      yoff%=py%+(gform.bboxheight%-gform.gheight%) DIV 2

      GCOL gform.gbackcol%
      RECTANGLE FILL xoff%,yoff%,gform.gwidth%,gform.gheight%
      GCOL gform.gboxcol%
      RECTANGLE xoff%,yoff%,gform.gwidth%,gform.gheight%


      IF gform.xmin=gform.xmax THEN xsep=1:xmax=maxx%-1
      miny=d(0,1)
      FOR y%=0 TO ns%-1
        IF d(0,y%)>maxx% THEN maxx%=d(0,y%)
        FOR x%=1 TO d(0,y%)
          IF d(x%,y%)>maxy THEN maxy=d(x%,y%)
          IF d(x%,y%)<miny THEN miny=d(x%,y%)
        NEXT x%
      NEXT y%
      IF gform.xmax=gform.xmin THEN
        xscale=gform.gwidth%/maxx%
        xsep=1
        xmax=maxx%-1
      ELSE
        xscale=gform.gwidth%/(gform.xmax-gform.xmin)
        xsep=(gform.xmax-gform.xmin)/maxx
      ENDIF
      IF gform.ymax=gform.ymin THEN yscale=gform.gheight%/maxy  ELSE yscale=gform.height%/(gform.ymax-gform.ymin)



      GCOL gform.ycol%
      LINE xoff%,yoff%,xoff%,gform.gheight%+yoff%
      REM add tick  marks here...
      GCOL gform.xcol%
      LINE xoff%,yoff%,xoff%+gform.gwidth%,yoff%
      REM add tick  marks here...

      FOR y%=0 TO ns%-1
        IF d(0,y%)>1 THEN
          GCOL d(d(0,y%)+1,y%) MOD 16
          linestyle%= (d(d(0,y%)+1,y%) DIV 16) MOD 16
          CASE linestyle% OF
            WHEN 1:linestyle%=21
            WHEN 2:linestyle%=37
            WHEN 3:linestyle%=53
            WHEN 4:linestyle%=0
            OTHERWISE linestyle%=5
          ENDCASE
          mtype%=(d(d(0,y%)+1,y%) DIV 256) MOD 16
          msize%=4+((d(d(0,y%)+1,y%) DIV 65536) MOD 256)
          MOVE xoff%,yoff%+yscale*d(1,y%)
          FOR x%=2 TO d(0,y%)
            PLOT linestyle%, xoff%+xscale*(x%-1),yoff%+yscale*d(x%,y%)
          NEXT x%
    
          IF mtype%<5 THEN
            FOR x%=1 TO d(0,y%)
              MOVE xoff%+xscale*(x%-1),yoff%+yscale*d(x%,y%)
              CASE mtype% OF
                WHEN 0:
                  MOVE BY -msize%,0
                  DRAW BY msize%*2,0
                  MOVE BY -msize%,-msize%
                  DRAW BY 0,msize%*2
                WHEN 1:
                  MOVE BY -msize%,-msize%
                  DRAW BY msize%*2,msize%*2
                  MOVE BY -msize%*2,0
                  DRAW BY msize%*2,-msize%*2
                WHEN 2: CIRCLE FILL xoff%+xscale*(x%-1),yoff%+yscale*d(x%,y%),msize%
                WHEN 3: CIRCLE  xoff%+xscale*(x%-1),yoff%+yscale*d(x%,y%),msize%
                WHEN 4:
                  RECTANGLE xoff%+xscale*(x%-1)-msize%,yoff%+yscale*d(x%,y%)-msize%,msize%*2
              ENDCASE
            NEXT x%
      
      
          ENDIF
        NEXT y%
        ENDPROC
 
User IP Logged

BrianM
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx Re: Generic Graphing routine
« Reply #3 on: Jan 12th, 2017, 1:32pm »

The book "Graphs and Charts on the BBC Microcomputer" by R D Harding might be useful. It describes with source programs and libraries for creating many types of graphs and charts. Due to memory and language restrictions of the old BBC micro, the source code is not nice (short variable names and too many multi-statement lines). However the code should run with little change as BB4W is a superset of the old BBC Basic.

You can find the book with source code on this web site
http://www.8bs.com/othrdnld/manuals/publications.shtml

Brian Matthews
User IP Logged

AndrewCool
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: Generic Graphing routine
« Reply #4 on: Jan 13th, 2017, 01:12am »


Hi D,

Thanks for the code you posted. I had to maek a couple of mode to get it working - you had a variable name data that showed up as a reserved word, and another called linestyle% that did he same with "line." Otherwise it does some looking plots!

Ta!

Andrew

[quote author=DDRM link=board=language&num=1484094606&start=2#0 date=1484139955]Hi Andrew,

It's certainly been discussed before, though I can't find the thread - it may have been on the Yahoo forum - yes, I can find some threads on the Groups.io forum you could have a look at.

Yes, found the thread:
https://groups.io/g/bb4w/topic/a_simple_line_graph_plotter/1143104?p=,,,20,0,0,0::Relevance,,graphs,20,2,0,1143104

The link doesn't seem to be complete, so you'll probably need to copy and paste, rather than just clicking.

That may give some context, and some other ideas.

Here's some code I wrote at that time. It doesn't (yet) label axes or put in tick marks, but on the other hand it allows you to specify the size, location, and colour of your graphs.

You are very welcome to use/adapt my code if it is at all useful.

Best wishes,

D
User IP Logged

AndrewCool
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: Generic Graphing routine
« Reply #5 on: Jan 13th, 2017, 01:15am »

Hi Brian,

>The book "Graphs and Charts on the BBC Microcomputer"

Bugga! I had a copy of that in the 80's, but sold it with my Beebs
a few years ago.

I'll check out the online version.

Thanks,

Andrew

>You can find the book with source code on this web site
>http://www.8bs.com/othrdnld/manuals/publications.shtml

User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Generic Graphing routine
« Reply #6 on: Jan 13th, 2017, 07:50am »

Hi Andrew,

Glad you think it looks useful. Yes, I always use uppercase keywords, so my variables may contain clashes with lowercase ones...

I've done a bit of work on it since posting - got axis tickmarks and numbering working, and nearly the title. I'll try to finish tidying that up, and maybe implement XY (scatter graphs), and post a revised version.

The code as written is designed to take a lot a parameters, which allows lots of control - but also requires the programmer to supply a lot of decision making. I'd like to set it up with more "default" control, which would result in a sensible output with less demanding input, but leave you with the OPTION to specify large red letters on your X axis and small blue ones on the Y axis if you really want it. I'll see what time and enthusiasm permits...

Best wishes,

D

PS Brian, thanks, that looks like a great resource! smiley
« Last Edit: Jan 13th, 2017, 07:57am by DDRM » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls