home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / NMK / Historian / HistogramView.m < prev    next >
Encoding:
Text File  |  1993-01-18  |  1.5 KB  |  80 lines

  1. /***** HistogramView.m -- histogram data display object implementation
  2.     NeXTstep Measurement Kit
  3.     by Alex Meyer <ameyer@phoenix.Princeton.EDU>
  4.     for computer science senior thesis
  5.     19 April 1992 -- created
  6. *****/
  7.  
  8. #import <stdlib.h>
  9. #import <dpsclient/wraps.h>
  10. #import "HistogramView.h"
  11.  
  12. @implementation HistogramView
  13.  
  14. - drawBar:(int)ind
  15.     inRect:(NXRect *)rect
  16. {
  17.     double fraction;
  18.     NXRect myRect;
  19.  
  20.     myRect = *rect;
  21.     NXInsetRect(&myRect,5,0);
  22.     myRect.size.height -= 5;
  23.     fraction = ((double) data[ind] - smallest) / (largest - smallest);
  24.     myRect.size.height *= fraction;
  25.     PSsetgray(NX_DKGRAY);
  26.     NXRectFill(&myRect);
  27.     return (self);
  28. }
  29.  
  30.  
  31. - drawSelf:(const NXRect *)rects    /* should only draw what's needed */
  32.     :(int)rectCount
  33. {
  34.     int i;
  35.     NXRect bigRect,smallRect;
  36.  
  37.     PSsetgray(NX_LTGRAY);
  38.     NXRectFill(&bounds);
  39.     bigRect = bounds;
  40.     NXInsetRect(&bigRect,5,5);
  41.     NXDrawWhiteBezel(&bigRect,&bounds);
  42.     NXInsetRect(&bigRect,5,5);
  43.     PSnewpath();
  44.     PSmoveto(bigRect.origin.x,bigRect.origin.y);
  45.     PSrlineto(bigRect.size.width,0);
  46.     PSclosepath();
  47.     PSsetgray(NX_BLACK);
  48.     PSstroke();
  49.     smallRect = bigRect;
  50.     smallRect.size.width /= numData;
  51.     for (i = 0;i < numData;++i) {
  52.         [self drawBar:i
  53.             inRect:&smallRect];
  54.         smallRect.origin.x += smallRect.size.width;
  55.     }
  56.     return (self);
  57. }
  58.  
  59.  
  60. - copyInNum:(int)num
  61.     data:(unsigned *)ptr
  62. {
  63.     int i;
  64.  
  65.     numData = num;
  66.     data = malloc(num * sizeof(*data));
  67.     largest = 0;
  68.     smallest = 0;
  69.     for (i = 0;i < num;++i) {
  70.         data[i] = ptr[i];
  71.         if (data[i] > largest)
  72.             largest = data[i];
  73.         if (data[i] < smallest)
  74.             smallest = data[i];
  75.     }
  76.     return (self);
  77. }
  78.  
  79. @end
  80.