home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / plotter.zip / PCMAG.SBP < prev   
Text File  |  1990-07-11  |  10KB  |  417 lines

  1. SBP
  2.   ╜ *** Written by: Mark C. Johnson
  3.   ╜  **         on: Jul 10, 1990
  4.   ╜   * Setup Windows SDK Calls and Variables
  5.  
  6.   ç
  7.   Γ e
  8.   ╦ e
  9.   ¼ à
  10.   ε à
  11.   ε"User","GetActiveWindow","I"
  12.   ε"User","GetDC","II"
  13.   ε"User","ReleaseDC","III"
  14.   ε"GDI","CreatePen","IIIJ"
  15.   ε"GDI","SelectObject","III"
  16.   ε"GDI","DeleteObject","II"
  17.   ε"GDI","CreateSolidBrush","IJ"
  18.   ε"GDI","MoveTo","IIII"
  19.   ε"GDI","LineTo","AIII"
  20.   ε"GDI","Rectangle","AIIIII"
  21.   ε"Kernel","GetTempFileName","IDFIF"
  22.   ε"GDI","Pie","AIIIIIIIII"
  23.  
  24.   ╜ *** Ask User What File They Want
  25.  
  26. Start: 
  27.  fln$ "*.SBD"
  28.   ┬"Select Database to Graph:","",18,n%,fln$
  29.   ín% 0 p Æ
  30.   í J(fln$) 0 p ┬"Can't find database",fln$,100: wStart
  31.  
  32.   ╜ *** Build array full of Numeric, Date, and Time fields so user can choose
  33.   ╜  ** which one they want to report on.  Build array for all fields at
  34.   ╜   * same time (for X axis).
  35.  
  36.   ¼1,0,1,"Reading"
  37.   ¼2,0,1,"File..."
  38.   ¼ │a%,b%
  39.  x%%  â("GetTempFileName","C",a$,0,tf$)
  40.   òXopt$,Yopt$
  41.  fl$  σroot(fln$)
  42.   ┤ Ö α,4fl$
  43.   ┤tf$ ¢ ╢
  44.  { ╦ Öfl$
  45.   å ╢
  46.   ┤tf$ ¢ ñ
  47.  ╪ O(a$ "*Field Count*")
  48.  ñ ca$
  49.  ┘
  50. numfld%  0( ,(a$,39))
  51.  ╫Xopt$(numfld% 1),Yopt$(numfld% 1)
  52. nc% 0:xc% 0
  53.  ╪ O(a$ "Formu*")
  54.  ñ ca$
  55.  ┘
  56.  ñ ca$
  57.  ñ ca$
  58.  ╪xc% numfld%
  59. xc% xc% 1
  60.  ╔ µ ,(a$,17,3)
  61.  µ"NMI","NUM","NML"
  62.  Yopt$(nc%)  F( +(a$,16))
  63.  nc% nc% 1
  64.  µ"VNU","VNI","VNL"
  65.  Yopt$(nc%)  F( +(a$,16))
  66.  nc% nc% 1
  67.  µ"TXT","VTX"
  68.  Xopt$(xz%)  F( +(a$,16))
  69.  xz% xz% 1
  70.  Æ ╔
  71. a$ ""
  72.  ╪( +(a$,1) " "  /(a$) 
  73. 1)
  74.  í B("*") wDone
  75.  ñ ca$
  76.  ┘
  77.  ┘
  78. Done: 
  79.   å ñ
  80.   ìtf$
  81.   ¼ à
  82.   ínc% 0 p ┬"No Numeric field to Graph on!","",100: wStart
  83.  
  84.   ╜ *** Now get what kind of graph the user wants
  85.   ╜  ** Line   = 1
  86.   ╜   * Bar    = 2
  87.   ╜     Pie    = 3
  88.   ╜     (Other types could easily be supported)
  89.  
  90. GetGraphType: 
  91.   ë £"GrphSlct"
  92.   ╩ £ ╓0,0
  93.   ╩ £ ╤9
  94.   ╩ £ ╥9
  95.   ╩ £ o"Helv,24,0"
  96.   ╩ £ s0
  97.   | £1,0,0,750,950
  98.   ╩ £ ╤0
  99.   | £5,23,10,"Select Desired Graph Type:"
  100.   ╩ £ ╓7,22
  101.   ╩ £ ╤10,1
  102.   ╩ £ ╥8
  103.   ╩ £ o"Tms Rmn,14,0"
  104.   | £8,52,15,50,10,bt1$,0,"drawflag%=1:GOTO DoPlot"
  105.   | £8,52,30,50,10,bt2$,0,"drawflag%=2:GOTO DoPlot"
  106.   | £8,52,45,50,10,bt3$,0,"drawflag%=3:GOTO DoPlot"
  107.   ╩ £ o"Tmns Rmn,24,0"
  108.   ╩ £ ╤0,1
  109.   | £8,42,75,70,15,bt4$,0,"GOTO QuitIt"
  110.  bt1$ "&Line Graph"
  111.  bt2$ "&Bar Chart"
  112.  bt3$ "&Pie Chart"
  113.  bt4$ "&Quit"
  114.   £1
  115. GetOpt: 
  116.   ╧ ▀  Ñ
  117.   ¥g$
  118.   íg$  (27) pg$ "Q"
  119.  g%  ?("LBPQ", >(g$))
  120.   íg% 4 wQuitIt
  121.  drawflag% g%
  122.   íg% wDoPlot
  123.   wGetOpt
  124. QuitIt: 
  125.   Γ │
  126.   ╦ │
  127.   å t
  128.   ε à
  129.   ç
  130.   Æ
  131. DoPlot: 
  132.  
  133.   ╜ *** Now we know what kind of plot to do, let's ask the user what field
  134.   ╜  ** they want for the X and Y axis.
  135.  
  136.   íagn% pagn% 0: wPlotData
  137.  plotdata$ ""
  138.   ┬"Select Field to Chart:","",20,n%,plotdata$,16,Yopt$
  139.   ín% 0 wQuitIt
  140.   ¢x% 0 qnc% 1
  141.  í >(Yopt$(x%))  >(plotdata$) wGetX
  142.   ▒x%
  143.   wDoPlot
  144. GetX: 
  145.  against$ ""
  146.   ┬"Plotted against what field:","",20,n%,against$,16,Xopt$
  147.   ín% 0 wDoPlot
  148.   ¢x% 0 qxc% 1
  149.  í >(Xopt$(x%))  >(against$) wFindMinMax
  150.   ▒x%
  151.   wGetX
  152.  
  153. FindMinMax: 
  154.  
  155.   ╜ *** Got the axis fields, now find all unique X's and corresponding
  156.   ╜  ** plot (y) values.  If there are duplicate X's, this plot routine
  157.   ╜   * takes the total of all Y values.  This can easily be modified.
  158.  
  159.   å £
  160.   í >(against$)  >(plotdata$) p ┬"Cannot plot field against itself!","",100: wDoPlot
  161.  numunique% 0
  162.   │ _ wNotIndex
  163.   úagainst$$
  164.   │ _
  165. FMM1: 
  166.   ¼1,0,1,"Collecting"
  167.   ¼2,0,1,"Data..."
  168.   ¼ │a%,b%
  169.   ç
  170.   ╔ `
  171.  rc% 1
  172.  old$ "[[[["
  173.   ╪old$ against$$
  174. old$ against$$
  175. numunique% numunique% 1
  176.  {&4.0(numunique%);against$$; (13);
  177.  ╔ Ñagainst$$ " !"
  178.   ┘
  179.   ç
  180.   òplot$,amt%
  181.   ¼1,0,1,"Processing"
  182.   ¼2,0,1,"Data..."
  183.   ¼ │a%,b%
  184.  div% 1
  185.   ínumunique% 50 pdiv% (numunique% 50):numunique% 50
  186.  cnt% div%:stp% 0:arr% 1
  187.   ╫plot$(numunique%),amt%(numunique%)
  188.   ╔ `
  189.   ╪ B("") 0
  190. stp% stp% 1
  191.  ístp%  (cnt%) p
  192. plot$(arr%) against$$
  193. cnt% cnt% div%
  194.  ╪plot$(arr%) against$$   B("") 0
  195. amt%(arr%) amt%(arr%) plotdata$$
  196.  ╔ ▒
  197.  ┘
  198.  {&2.0(arr%);plot$(arr%); '(80); (13);
  199. arr% arr% 1
  200.  ^
  201. z$ against$$
  202.  ╪z$ against$$   B("") 0
  203.  ╔ ▒
  204.  ┘
  205.  Æ í
  206.   ┘
  207.  
  208.   ╜ *** Draw Axis routine.  This routine can be skipped for Pie Charts
  209.   ╜  ** First plot hi and low vals, then step vals, title, then find
  210.   ╜   * num fields on bottom and scale bottom to fit.
  211.  
  212. PlotData: 
  213.   ¼1,0,1,"Plotting"
  214.   ¼2,0,1,"Graph..."
  215.   ¼ │a%,b%
  216.   ídrawflag% 3 wDoPie
  217. sc: 
  218.  hi%  ô(amt%)
  219.  lo%  ┌(amt%)
  220.   ílo% hi% p ┬"No information to plot!","",100: wStart
  221.   ë £"PlotScrn"
  222.   ╩ £ ╓0,0
  223.   ╩ £ ╤9
  224.   ╩ £ ╥9
  225.   | £1,0,0,750,950
  226.   ╩ £ ╤0
  227.   ╩ £ o"Tms Rmn,18,0"
  228.  title$ plotdata$ " vs. " against$ ":"
  229.  x% 60 ( /(title$) 2)
  230.   | £5,x%,6,title$
  231.   ╩ £ o"Helv,8,0"
  232.   ╩ £ s0
  233.   | £3,10,10,1,70
  234.   | £3,10,80,150,1
  235.  ct% 11
  236.   ╩ £ ╓17,2
  237.  stp% ((hi% lo%) 10)
  238.   ¢x% lo% q(hi% (stp% .5)) kstp%
  239.  | £5,1,(7 (ct% 1)) 11, F( (x%,"9999.9"))
  240.  | £3,9,(7 (ct% 1)) 10,2,1
  241. ct% ct% 1
  242.   ▒x%
  243.  xdiv% 150 numunique%
  244.  hWND%%  â("GetActiveWindow")
  245.  hDC%%  â("GetDC",hWND%%)
  246.   ╜ Set color of lines here (RED=default).  Format = 8 bits each for Blue, Green, and Red.
  247.  clr% 255
  248.  xloc% 10
  249.  Xorg% 40
  250.  Xstep% (( σsys(6) Xorg%) 35) numunique%
  251.  Yorg% .63  σsys(7)
  252.  Yscale% (hi% 250)
  253.   ¢x% 1 qnumunique%
  254.  | £3,xloc% (xdiv% 2),79,1,2
  255. x$ plot$(x%)
  256.  vAddDown
  257. xloc% xloc% xdiv%
  258.   ▒x%
  259.   £1
  260.  xloc% 10
  261.   ¢x% 1 qnumunique%
  262. x1%% Xorg% ((x% 1) Xstep%)
  263. y1%% Yorg% (amt%(x%) Yscale%)
  264.  ídrawflag% 1 p
  265. x1%% x1%% (.5 Xstep%)
  266. pr%%  â("CreatePen",0,0,clr%)
  267. ob%%  â("SelectObject",hDC%%,pr%%)
  268.  íx% 1 p
  269. err%%  â("MoveTo",hDC%%,x1%%,y1%%)
  270.  ^
  271. err%%  â("LineTo",hDC%%,x1%%,y1%%)
  272.  Æ í
  273. br%%  â("SelectObject",hDC%%,ob%%)
  274. err%%  â("DeleteObject",br%%)
  275.  ^
  276. pr%%  â("CreatePen",0,0,clr%)
  277. br%%  â("CreateSolidBrush",16777215  (1))
  278. ob1%%  â("SelectObject",hDC%%,pr%%)
  279. ob%%  â("SelectObject",hDC%%,br%%)
  280. x2%% (Xorg% (x% Xstep%))
  281. err%%  â("Rectangle",hDC%%,x1%%,y1%%,x2%%,Yorg%)
  282. br%%  â("SelectObject",hDC%%,ob%%)
  283. err%%  â("DeleteObject",br%%)
  284. br%%  â("SelectObject",hDC%%,pr%%)
  285. err%%  â("DeleteObject",br%%)
  286.  Æ í
  287.   ▒x%
  288.  err%%  â("ReleaseDC",hWND%%,hDC%%)
  289.  
  290. EndPlot: 
  291.   ¼1,0,1,"{Any"
  292.   ¼2,0,1,"key"
  293.   ¼3,0,1,"to"
  294.   ¼4,0,1,"Continue...}"
  295.   ¼ │a%,b%
  296.   ╧ Ña$
  297.   ¼ à
  298.   ┬"Another Plot?","",135,n%
  299.   ín% 0 p
  300.  ε à
  301.  ç
  302.  å t
  303.  Æ
  304.   Æ í
  305.   ┬"Same Data?","",135,n%
  306.   ín% 0 p ─
  307.  agn% 9
  308.   wGetGraphType
  309.  
  310. DoPie: 
  311.  hWND%%  â("GetActiveWindow")
  312.  hDC%%  â("GetDC",hWND%%)
  313.  tot%  l(amt%)
  314.   òprct%
  315.   ╫prct%(numunique%)
  316.   ¢x% 1 qnumunique%
  317. prct%(x%) (amt%(x%) tot%) 100
  318.   ▒x%
  319.   ë £"PlotScrn"
  320.   ╩ £ ╓0,0
  321.   ╩ £ ╤9
  322.   ╩ £ ╥9
  323.   | £1,0,0,750,950
  324.   ╩ £ ╤0
  325.   ╩ £ o"Tms Rmn,18,0"
  326.  title$ plotdata$ " vs. " against$ ":"
  327.  x% 60 ( /(title$) 2)
  328.   | £5,x%,6,title$
  329.   ╩ £ o"Helv,8,0"
  330.   ╩ £ s0
  331.   ╩ £ ╓17,2
  332.   ╜ Determine whether titles should go on left or right, then store
  333.   ╜ in array of points.
  334.   òXtitle%,Ytitle%
  335.   ╫Xtitle%(numunique%),Ytitle%(numunique%)
  336.  pie% 0
  337.   ¢x% 1 qnumunique%
  338. piepos% pie% ((prct%(x%) 100)  P)
  339. pie% pie% ((prct%(x%) 100) (2  P))
  340.  ípiepos% 
  341.  P p ▒x%
  342.  
  343.   ╜ (Just found the Start of the left hand side)
  344.  left% x%
  345.  
  346.   ╜ Now find spacing of titles down left and right sides
  347.  nr% 90 (left% 1)
  348.  ns% 10
  349.  Xsc%  σsys(6) 170
  350.  Ysc%  σsys(7) 130
  351.   ¢x% 1 qleft% 1
  352. Xtitle%(x%) 140
  353. Ytitle%(x%) ns% ((left% x%) nr%)
  354.  | £5,Xtitle%(x%),Ytitle%(x%),plot$(x%)
  355. Xtitle%(x%) (Xtitle%(x%) Xsc%) 3
  356. Ytitle%(x%) Ytitle%(x%) Ysc%
  357.   ▒x%
  358.  nr1% 90 (numunique% left%)
  359.   ¢x% left% qnumunique%
  360. Xtitle%(x%) 1
  361. Ytitle%(x%) ns% ((x% left%) nr1%)
  362.  | £5,Xtitle%(x%),Ytitle%(x%), +(plot$(x%),13)
  363. Xtitle%(x%) (20 Xsc%) 3
  364. Ytitle%(x%) Ytitle%(x%) Ysc%
  365.   ▒x%
  366.   £1
  367.  XCent%  σsys(6) 2
  368.  YCent%  σsys(7) 2
  369.  pie% 0
  370.  xlow%  σsys(6) 7
  371.  ylow%  σsys(7) 10
  372.  xhi%  σsys(6) (1.5 xlow%)
  373.  yhi%  σsys(7) (1.5 ylow%)
  374.  clr% 1
  375.  xrad% ((xhi% xlow%) 2) 1.12
  376.  yrad% ((yhi% ylow%) 2) .98
  377.   ¢x% 1 qnumunique%
  378. pr%%  â("CreatePen",0,0,16777215)
  379. red% (clr% 3 0) {0:(clr% 3 1) {127:255
  380. blu% ( (clr% 3) 3 0) {0:( (clr% 3) 3 1) {127:255
  381. grn% ( (clr% 9) 3 0) {0:( (clr% 9) 3 1) {127:255
  382. clr% (clr% 1) 26
  383. colr% (blu% 65536) (grn% 256) red%
  384. br%%  â("CreateSolidBrush",colr%)
  385. ob1%%  â("SelectObject",hDC%%,pr%%)
  386. ob%%  â("SelectObject",hDC%%,br%%)
  387. x1%  (xrad%  (pie%)) XCent%
  388. y1%  (yrad%  (pie%)) YCent%
  389. xh%  (xrad%  (pie% ((prct%(x%) 100)  P))) XCent%
  390. yh%  (yrad%  (pie% ((prct%(x%) 100)  P))) YCent%
  391. pie% pie% ((prct%(x%) 100) (2  P))
  392. x2%  ((xrad%  (pie%))) XCent%
  393. y2%  ((yrad%  (pie%))) YCent%
  394.  íx1% x2%  y1% y2% wNextOne
  395. err%%  â("Pie",hDC%%,xlow%,ylow%,xhi%,yhi%,x1%,y1%,x2%,y2%)
  396. NextOne: 
  397. err%%  â("Rectangle",hDC%%,Xtitle%(x%) 4,Ytitle%(x%) 4,Xtitle%(x%) 4,Ytitle%(x%) 4)
  398. br%%  â("SelectObject",hDC%%,ob%%)
  399. err%%  â("DeleteObject",br%%)
  400. br%%  â("SelectObject",hDC%%,pr%%)
  401. err%%  â("DeleteObject",br%%)
  402.   ▒x%
  403.  err%%  â("ReleaseDC",hWND%%,hDC%%)
  404.   wEndPlot
  405. AddDown: 
  406.   ¢zz% 1 q /(x$)
  407.  | £5,xloc% 1,81 (zz% 3), ,(x$,zz%,1)
  408.   ▒zz%
  409.   ├
  410. NotIndex: 
  411.   ¼1,0,1,"Creating"
  412.   ¼2,0,1,"Index..."
  413.   ¼ │a%,b%
  414.   ë ú │against$$
  415.   yFMM1
  416.  
  417.