home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l216 / 1.ddi / GBAR.PRO < prev    next >
Encoding:
Prolog Source  |  1987-03-23  |  4.0 KB  |  121 lines

  1.  
  2.     /************************************************
  3.  
  4.          Turbo Prolog Toolbox
  5.          (C) Copyright 1987 Borland International.
  6.  
  7.             GRAPHBAR.PRO            
  8.      Graphbar contains predicates and clauses for
  9.      the BARGRAPH predicate.            
  10.     ************************************************/
  11.     
  12. predicates
  13.   BarGraph3d(col,row,col,row,barratio,theta,barlist,factor)
  14.   BarGraph(col,row,col,row,barratio,barlist,factor)
  15.   countBars(barlist,vheigth,integer,vheigth)
  16.   drawBarl(Vrow,Vcol,Vwidth,BarRatio,theta,factor,barlist)
  17.   drawBar(Vrow,Vcol,Vwidth,theta,factor,bar)
  18.   threeD_box(Vrow,Vcol,Vrow,Vcol,Vwidth,theta,color,color)
  19.   determ_fill(Color,Fill)
  20.   place_label(Vrow,Vrow,Vcol,Vwidth,VHeigth,string,color,kind)
  21.   to_range(integer,integer,integer,integer)
  22.  
  23. Clauses
  24.   to_range(X,MIN,_,MIN):- X<=MIN,!.
  25.   to_range(X,_,MAX,MAX):- X>MAX,!.
  26.   to_range(X,_,_,X).
  27.      
  28.  
  29.  BarGraph3D(Left,Bottom,Right,Top,BarWidthRatio,Theta,BarList,Factor):-
  30.     countBars(BarList,0,Number,MaxBarHigth),
  31.     windowarea(Rows,Cols),/*The size of the current window*/
  32.     
  33.     /*virtual coordinates for the lower border*/
  34.     Rl=Rows-Bottom,
  35.     virtual_text(Rlow,Clow,Rl,Left),
  36.     
  37.     /*Virtual coordinates for the height and width of the graph*/
  38.     H=Rows-Bottom-Top,
  39.     W=Cols-Left-Right,
  40.     virtual_text(VirHigth,VirWidth,H,W),
  41.     
  42.       BarWidth=BarWidthRatio*VirWidth/(Number+2),
  43.     Factor=VirHigth/MaxBarHigth*0.9,
  44.       drawBarl(Rlow,Clow,BarWidth,BarWidthRatio,Theta,Factor,BarList).
  45.  
  46.   BarGraph(Left,Bottom,Right,Top,BarWidthRatio,BarList,Factor):-
  47.     BarGraph3D(Left,Bottom,Right,Top,BarWidthRatio,0,BarList,Factor).
  48.  
  49.   countBars([bar(H,_,_,_)|T],High,Count,Highest):-
  50.       H>High,!,
  51.     countBars(T,H,N1,Highest),Count=N1+1.
  52.   countBars([_|T],High,Count,Highest):-
  53.     countBars(T,High,N1,Highest),Count=N1+1.
  54.   countBars([],H,0,H).
  55.  
  56.  
  57.   drawBarl(BottomRow,AtCol,BarWidth,BarRatio,Theta,Factor,[Bar|Rest]):-!,
  58.     drawBar(BottomRow,AtCol,BarWidth,Theta,Factor,Bar),
  59.     NextCol=AtCol+BarWidth/BarRatio,
  60.     drawBarl(BottomRow,NextCol,BarWidth,BarRatio,Theta,Factor,Rest).
  61.   drawBarl(_,_,_,_,_,_,[]).
  62.  
  63.  
  64.   drawBar(Row1,Col1,Width,0,Factor,bar(Higth,Label,BoxColor,FillColor)):-!,
  65.     Row2=Row1-Higth*Factor,
  66.     Col2=Col1+Width,
  67.     F=FillColor,sign(F,F2),Fill=F2,
  68.     box(Row1,Col1,Row2,Col2,BoxColor,FillColor,Fill),
  69.     LabelKind=2,
  70.     place_label(Row1,Row2,Col1,Width,Higth,Label,BoxColor,LabelKind).
  71.   drawBar(Row1,Col1,Width,Theta,Factor,bar(Higth,Label,BoxColor,FillColor)):-
  72.     Row2=Row1-Higth*Factor,
  73.     Col2=Col1+Width,
  74.     threeD_box(Row1,Col1,Row2,Col2,Width,Theta,BoxColor,FillColor),
  75.     LabelKind=2,
  76.     place_label(Row1,Row2,Col1,Width,Higth,Label,BoxColor,LabelKind).
  77.   drawBar(_,_,_,_,_,space).
  78.  
  79.  
  80.   place_label(Row1,Row2,Col1,Width,Value,Label,BoxColor,LabelKind):-
  81.     /*  (Row2,Col1)
  82.         +-------------+              Labelkind:
  83.         | <--Width--> |  Print Label only:     0
  84.         |             |  Label and value:    1
  85.         +-------------+
  86.          (Row1,Col1) */
  87.  
  88.     str_len(Label,LblLen),
  89.     Center=Col1+(Width+1) div 2,
  90.     virtual_text(Row1,Center,R1,C1),
  91.     R2=R1+1,
  92.     C2=C1-LblLen div 2+1,
  93.     windowarea(Rows,Cols),MaxRow=Rows-1,MaxCol=Cols-1,
  94.     to_range(R2,0,MaxRow,Rlbl),
  95.     to_range(C2,0,MaxCol,Clbl),
  96.     cursor(Rlbl,Clbl),attribute(BoxColor),write(Label),
  97.     LabelKind>0,!,
  98.     virtual_text(Row2,Col1,R3,_),
  99.     str_int(ValStr,Value),str_len(ValStr,ValueLen),
  100.     C4=C1+1-round(ValueLen/2),
  101.     R4=R3-2,
  102.     to_range(R4,0,MaxRow,Rv),Rv1=Rv,
  103.     to_range(C4,0,MaxCol,Cv),Cv1=Cv,
  104.     str_real(String,Value),
  105.     gwrite(Rv1,Cv1,String,BoxColor,0).
  106.   place_label(_,_,_,_,_,_,_,_).
  107.  
  108.   threeD_box(Row1,Col1,Row2,Col2,Width,Theta,BoxColor,FillColor):-
  109.     Dx=cos(Theta)*Width,Dy=sin(Theta)*Width,
  110.     Row1Dy=Row1-Dy,Row2Dy=Row2-Dy,Col1Dx=Col1+Dx,Col2Dx=Col2+Dx,
  111.     determ_fill(Fillcolor,Fill),
  112.     box(Row1,Col1,Row2,Col2,BoxColor,FillColor,Fill),
  113.     LineShade(Row2,Col1,Row2dy,Col1Dx,Col2,BoxColor,3),
  114.     LineShade(Row2,Col2,Row2dy,Col2Dx,Col2,BoxColor,2),
  115.     LineShade(Row1,Col2,Row1dy,Col2Dx,Row1dy,BoxColor,0),
  116.     LineShade(Row2,Col2,Row2dy,Col2Dx,Row1dy,BoxColor,1).
  117.  
  118.   /* Fillcolor 0 gives no fill */
  119.   determ_fill(0,0):-!.
  120.   determ_fill(_,1).
  121.