WMSimpleGraphs.Mod 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. MODULE WMSimpleGraphs; (** AUTHOR "Patrick Hunziker"; PURPOSE "Minimum-overhead graph drawing and storing"; *)
  2. (** right-click on navigator thumbnail allows window storage as image file *)
  3. (*ToDo: ticks for Graph. labels on axes *)
  4. (*ToDo: catch NaN and Inf in data and other strategies to avoid erratic window sizes*)
  5. IMPORT Strings, WMGraphics, WMRectangles, Modules, Reals, WM:=WMWindowManager, MathL;
  6. CONST Colors=[WMGraphics.Red,WMGraphics.Blue,WMGraphics.Green,WMGraphics.Yellow, WMGraphics.Magenta, WMGraphics.Cyan, WMGraphics.Gray];
  7. MinSize=30;
  8. MaxSize=2048;
  9. TYPE
  10. Regressor=PROCEDURE{DELEGATE}(CONST data: ARRAY [*,*] OF LONGREAL; VAR slope,intercept: LONGREAL);
  11. TYPE
  12. Window=OBJECT(WM.Window);
  13. VAR width,height:LONGINT;
  14. END Window;
  15. Histogram* = OBJECT (Window);
  16. VAR
  17. data:ARRAY [*] OF LONGREAL;
  18. PROCEDURE &New*(CONST data: ARRAY [*] OF LONGREAL; CONST title: ARRAY OF CHAR);
  19. VAR max:LONGREAL; w0,h0:LONGINT;
  20. BEGIN
  21. SELF.data:=data;
  22. max:=MAX(data);
  23. width:=LEN(data,0); height:=ENTIER(max)+1;
  24. IF (width<MinSize) THEN w0:=10*width ELSE w0:=MIN(width,MaxSize) END;
  25. IF height<MinSize THEN h0:=10*height ELSE h0:=height END;
  26. Init(w0,h0,FALSE);
  27. WM.GetDefaultManager().Add(PosX, PosY, SELF, {WM.FlagFrame,WM.FlagClose});
  28. NewWindowPos(GetWidth());
  29. SetTitle(Strings.NewString(title));
  30. SetPointerInfo(manager.pointerCrosshair);
  31. END New;
  32. PROCEDURE NewData*(CONST data: ARRAY [*] OF LONGREAL);
  33. BEGIN
  34. SELF.data:=data;
  35. Invalidate(WMGraphics.MakeRectangle(0,0,GetWidth(), GetHeight()));
  36. END NewData;
  37. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  38. VAR i:LONGINT;
  39. BEGIN
  40. IF Reals.IsNaNL(data[i]) THEN RETURN END;
  41. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), WMGraphics.White, WMGraphics.ModeCopy);
  42. FOR i:=0 TO LEN(data,0)-1 DO
  43. canvas.Fill(WMRectangles.MakeRect( i*w DIV width , h-ENTIER(data[i]*h / height),
  44. (i+1)*w DIV width , h), WMGraphics.Black, WMGraphics.ModeCopy);
  45. END;
  46. INC(timestamp);
  47. END Draw;
  48. END Histogram;
  49. (** display matrix values in checkerboard like fashion. positive values are in black/grey/white, negative values in red*)
  50. Matrix* = OBJECT (Window);
  51. VAR
  52. data:ARRAY [*,*] OF LONGREAL;
  53. max,min, offset, gain:LONGREAL;
  54. PROCEDURE &New*(CONST data: ARRAY [*,*] OF LONGREAL; CONST title: ARRAY OF CHAR);
  55. BEGIN
  56. SELF.data:=data;
  57. min:=MIN(data); max:=MAX(data);
  58. max:=MAX(ABS(min), ABS(max));
  59. min:=MIN(0, min);
  60. IF max=0 THEN max:=1 END;
  61. width:=MIN(MaxSize, MAX(1,LEN(data,0)));
  62. height:=MIN(MaxSize, MAX(1,LEN(data,1)));
  63. Init(width, height, TRUE);
  64. offset:=0; gain:=255/max;
  65. IF( width<10) OR (height<10) THEN
  66. bounds := WMGraphics.MakeRectangle(0, 0, 10*width, 10*height);(* grow small images *)
  67. END;
  68. WM.GetDefaultManager().Add(PosX, PosY, SELF, {WM.FlagFrame,WM.FlagClose});
  69. NewWindowPos(GetWidth());
  70. SetTitle(Strings.NewString(title));
  71. SetPointerInfo(manager.pointerCrosshair);
  72. END New;
  73. PROCEDURE NewData*(CONST data: ARRAY [*,*] OF LONGREAL);
  74. BEGIN
  75. SELF.data:=data;
  76. min:=MIN(data); max:=MAX(data);
  77. max:=MAX(ABS(min), ABS(max));
  78. min:=MIN(0, min);
  79. IF max=0 THEN max:=1 END;
  80. offset:=0; gain:=255/max;
  81. Invalidate(WMGraphics.MakeRectangle(0,0,GetWidth(), GetHeight()));
  82. END NewData;
  83. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  84. VAR col: WMGraphics.Color; x,y:LONGINT; val:LONGREAL; valI:LONGINT;
  85. BEGIN
  86. FOR y:=0 TO LEN(data,0)-1 DO
  87. FOR x:=0 TO LEN(data,1)-1 DO
  88. val:=data[y,x]; IF Reals.IsNaNL(val) THEN val:=0 END;
  89. valI:=ENTIER(offset+gain*val);
  90. valI:=MAX(-255, MIN( 255, valI));
  91. IF valI>=0 THEN col:=WMGraphics.RGBAToColor(valI,valI,valI,255);
  92. ELSE col:=WMGraphics.RGBAToColor(-valI,0,0,255);
  93. END;
  94. canvas.Fill(WMRectangles.MakeRect(x*w DIV width, h-ENTIER(0.5+(y+1)*h/height),
  95. (x+1)*w DIV width, h-ENTIER(0.5+y*h/height)),
  96. col, WMGraphics.ModeCopy);
  97. END;
  98. END;
  99. INC(timestamp);
  100. END Draw;
  101. END Matrix;
  102. Graph* = OBJECT (Window);
  103. CONST border=5;
  104. VAR
  105. data:ARRAY [*] OF LONGREAL;
  106. max,min:LONGREAL;
  107. PROCEDURE &New*(CONST data: ARRAY [*] OF LONGREAL; CONST title: ARRAY OF CHAR);
  108. VAR w0,h0:LONGINT;
  109. BEGIN
  110. SELF.data:=data;
  111. max:=MAX(1, MAX(data));
  112. min:=MIN(0, MIN(data));
  113. width:=LEN(data,0); height:=ENTIER(max-min)+1;
  114. IF Reals.IsNaNL(width) THEN width:=100 END;
  115. IF Reals.IsNaNL(height) THEN height:=100 END;
  116. IF (width<MinSize) THEN w0:=10*width ELSE w0:=MIN(MaxSize, width) END;
  117. IF height<MinSize THEN h0:=10*height ELSE h0:=MIN(MaxSize, height) END;
  118. Init(w0,h0,FALSE);
  119. WM.GetDefaultManager().Add(PosX, PosY, SELF, {WM.FlagFrame,WM.FlagClose});
  120. NewWindowPos(GetWidth());
  121. SetTitle(Strings.NewString(title));
  122. SetPointerInfo(manager.pointerCrosshair);
  123. END New;
  124. PROCEDURE NewData*(CONST data: ARRAY [*] OF LONGREAL);
  125. BEGIN
  126. SELF.data:=data;
  127. max:=MAX(1, MAX(data));
  128. min:=MIN(0, MIN(data));
  129. Invalidate(WMGraphics.MakeRectangle(0,0,GetWidth(), GetHeight()));
  130. END NewData;
  131. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  132. VAR i:LONGINT; mn,mx,x0,y0,x1,y1:LONGINT;
  133. BEGIN
  134. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), WMGraphics.White, WMGraphics.ModeCopy);
  135. mn:=-border+ENTIER(0.5+min*h / height);
  136. mx:=ENTIER(0.5+max*h / height);
  137. FOR i:=0 TO LEN(data,0)-2 DO
  138. IF ~Reals.IsNaNL(data[i]) &~Reals.IsNaNL(data[i+1]) THEN
  139. x0:=border+i*w DIV width;
  140. y0:=h+mn-ENTIER(0.5+data[i]*h / height);
  141. x1:=border+(i+1)*w DIV width;
  142. y1:=h+mn-ENTIER(0.5+data[i+1]*h / height);
  143. canvas.Line(x0,y0,x1,y1, WMGraphics.Black, WMGraphics.ModeCopy);
  144. END;
  145. END;
  146. IF mn#0 THEN canvas.Line(0, h+mn, w, h+mn, WMGraphics.Black, WMGraphics.ModeCopy); END;
  147. INC(timestamp);
  148. END Draw;
  149. END Graph;
  150. Graphs* = OBJECT (Window);
  151. CONST border=5;
  152. VAR
  153. data:ARRAY [*,*] OF LONGREAL;
  154. max,min:LONGREAL;
  155. PROCEDURE &New*(CONST data: ARRAY [*,*] OF LONGREAL; CONST title: ARRAY OF CHAR);
  156. VAR w0,h0:LONGINT;
  157. BEGIN
  158. SELF.data:=data;
  159. max:=MAX(1, MAX(data));
  160. min:=MIN(0, MIN(data));
  161. width:=MAX(2,LEN(data,1)); height:=MAX(2, ENTIER(max-min)+1);
  162. IF Reals.IsNaNL(width) THEN width:=100 END;
  163. IF Reals.IsNaNL(height) THEN height:=100 END;
  164. IF width<MinSize THEN w0:=10*width ELSE w0:=MIN(width,MaxSize) END;
  165. IF height<MinSize THEN h0:=10*height ELSE h0:=MIN(height,MaxSize) END;
  166. Init(w0,h0,FALSE);
  167. WM.GetDefaultManager().Add(PosX, PosY, SELF, {WM.FlagFrame,WM.FlagClose});
  168. NewWindowPos(GetWidth());
  169. SetTitle(Strings.NewString(title));
  170. SetPointerInfo(manager.pointerCrosshair);
  171. END New;
  172. PROCEDURE NewData*(CONST data: ARRAY [*,*] OF LONGREAL);
  173. BEGIN
  174. SELF.data:=data;
  175. max:=MAX(1, MAX(data));
  176. min:=MIN(0, MIN(data));
  177. Invalidate(WMGraphics.MakeRectangle(0,0,GetWidth(), GetHeight()));
  178. END NewData;
  179. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  180. VAR i,j:LONGINT; mn,mx, x0,x1,y0,y1:LONGINT;
  181. BEGIN
  182. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), WMGraphics.White, WMGraphics.ModeCopy);
  183. mn:=-border+ENTIER(0.5+min*h / height);
  184. mx:=ENTIER(0.5+max*h / height);
  185. FOR j:=0 TO LEN(data,0)-1 DO
  186. FOR i:=0 TO LEN(data,1)-2 DO
  187. IF ~Reals.IsNaNL(data[j,i]) &~Reals.IsNaNL(data[j,i+1]) THEN
  188. x0:=border+i*w DIV width;
  189. y0:=h+mn-ENTIER(0.5+data[j,i]*h / height);
  190. x1:=border+(i+1)*w DIV width;
  191. y1:=h+mn-ENTIER(0.5+data[j,i+1]*h / height);
  192. canvas.Line(x0, y0, x1, y1, Colors[j MOD LEN(Colors,0)], WMGraphics.ModeCopy);
  193. END;
  194. END;
  195. END;
  196. IF mn#0 THEN canvas.Line(0, h+mn, w, h+mn, WMGraphics.Black, WMGraphics.ModeCopy); END;
  197. INC(timestamp);
  198. END Draw;
  199. END Graphs;
  200. GraphXY* = OBJECT (Window);
  201. CONST border=5; scaleRatio=0.95;
  202. VAR
  203. data:ARRAY [*,*] OF LONGREAL;
  204. minx,miny,maxx,maxy:LONGREAL;
  205. ticks: ARRAY [*,*] OF LONGREAL;
  206. PROCEDURE &New*(CONST data: ARRAY [*,*] OF LONGREAL; CONST title: ARRAY OF CHAR);
  207. VAR w0,h0:LONGINT;
  208. BEGIN
  209. SELF.data:=data;
  210. maxx:=MAX(0,MAX(data[0]));maxy:=MAX(0,MAX(data[1]));
  211. minx:=MIN(0, MIN(data[0])); miny:=MIN(0, MIN(data[1]));
  212. width:=ENTIER(maxx-minx)+1; height:=ENTIER(maxy-miny)+1;
  213. IF Reals.IsNaNL(width) THEN width:=100 END;
  214. IF Reals.IsNaNL(height) THEN height:=100 END;
  215. IF (width<MinSize) THEN w0:=10*width ELSE w0:=MIN(MaxSize,width) END;
  216. IF height<MinSize THEN h0:=10*height ELSE h0:=MIN(MaxSize, height) END;
  217. Init(w0,h0,FALSE);
  218. WM.GetDefaultManager().Add(PosX, PosY, SELF, {WM.FlagFrame,WM.FlagClose});
  219. NewWindowPos(GetWidth());
  220. SetTitle(Strings.NewString(title));
  221. SetPointerInfo(manager.pointerCrosshair);
  222. GetTicks;
  223. END New;
  224. PROCEDURE NewData*(CONST data: ARRAY [*,*] OF LONGREAL);
  225. BEGIN
  226. SELF.data:=data;
  227. maxx:=MAX(0,MAX(data[0]));maxy:=MAX(0,MAX(data[1]));
  228. minx:=MIN(0, MIN(data[0])); miny:=MIN(0, MIN(data[1]));
  229. Invalidate(WMGraphics.MakeRectangle(0,0,GetWidth(), GetHeight()));
  230. END NewData;
  231. PROCEDURE GetTicks ; (*ticks along X, along Y, at decimal units*)
  232. VAR maxx,maxy,stepx,stepy: LONGREAL; log:LONGREAL; steps,i:LONGINT;
  233. BEGIN
  234. maxx:=MAX(ABS(data[0]));
  235. log:=Log10(maxx);
  236. stepx:=Exp10(log);
  237. maxy:=MAX(ABS(data[1]));
  238. log:=Log10(maxy);
  239. stepy := Exp10(log);
  240. steps:=MAX(ENTIER(maxx/stepx), ENTIER(maxy/stepy));
  241. NEW(ticks,2,steps);
  242. FOR i:=0 TO steps-1 DO
  243. ticks[0,i]:=(i+1)*stepx;
  244. ticks[1,i]:=(i+1)*stepy;
  245. END;
  246. END GetTicks;
  247. PROCEDURE Axes(canvas: WMGraphics.Canvas; w,h,mnw,mnh:LONGINT; scalex,scaley:REAL);
  248. VAR i:LONGINT;
  249. BEGIN
  250. IF mnh#0 THEN canvas.Line(0, h+mnh, w, h+mnh, WMGraphics.Black, WMGraphics.ModeCopy) END;
  251. IF mnw#0 THEN canvas.Line(-mnw, 0, -mnw, h, WMGraphics.Black, WMGraphics.ModeCopy) END;
  252. FOR i:=0 TO LEN(ticks,1)-1 DO
  253. canvas.Line(-mnw+ENTIER(0.5+ticks[0,i]*scalex), h+mnh-1, -mnw+ENTIER(0.5+ticks[0,i]*scalex), h+mnh+1, WMGraphics.Black, WMGraphics.ModeCopy); (* ticks are at multiples of largest decimal unit *)
  254. canvas.Line(-mnw-1, h+mnh-ENTIER(0.5+ticks[1,i]*scaley), -mnw+1, h+mnh-ENTIER(0.5+ticks[1,i]*scaley), WMGraphics.Black, WMGraphics.ModeCopy)
  255. END;
  256. END Axes;
  257. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  258. VAR i:LONGINT; mnw,mnh,mxw,mxh,x0,x1,y0,y1:LONGINT; scalex,scaley:REAL;
  259. BEGIN
  260. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), WMGraphics.White, WMGraphics.ModeCopy);
  261. scalex:=scaleRatio*w/width; scaley:=scaleRatio*h/height;
  262. mnw:=-border+ENTIER(0.5+minx* scalex); mxw:=ENTIER(0.5+maxx* scalex);
  263. mnh:=-border+ENTIER(0.5+miny* scaley); mxh:=ENTIER(0.5+maxy* scaley);
  264. FOR i:=0 TO LEN(data,1)-2 DO
  265. IF ~Reals.IsNaNL(data[0,i]) &~Reals.IsNaNL(data[1,i]) & ~Reals.IsNaNL(data[0,i+1]) &~Reals.IsNaNL(data[1,i+1])THEN
  266. x0:=-mnw+ENTIER(0.5+data[0,i]*scalex);
  267. y0:= h+mnh-ENTIER(0.5+data[1,i]*scaley);
  268. x1:= -mnw+ENTIER(0.5+data[0,i+1]*scalex);
  269. y1:= h+mnh-ENTIER(0.5+data[1,i+1]*scaley);
  270. canvas.Line(x0,y0,x1,y1, WMGraphics.Blue, WMGraphics.ModeCopy);
  271. END;
  272. END;
  273. Axes(canvas, w,h,mnw,mnh,scalex,scaley);
  274. INC(timestamp);
  275. END Draw;
  276. END GraphXY;
  277. (** scatter plot with optional error bars.
  278. data[0,..]: x coordinates
  279. data[1,..]: y coordinates
  280. optional data[2,..]: y error bars
  281. optional data[3,..]: x error bars *)
  282. TYPE Scatter* = OBJECT (GraphXY);
  283. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  284. VAR i:LONGINT; mnw,mnh,mxw,mxh, x,y, ex,ey:LONGINT; scalex,scaley:REAL; rect:WMRectangles.Rectangle;
  285. BEGIN
  286. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), WMGraphics.White, WMGraphics.ModeCopy);
  287. scalex:=scaleRatio*w/width;
  288. scaley:=scaleRatio*h/height;
  289. mnw:=-border+ENTIER(0.5+minx* scalex); mxw:=ENTIER(0.5+maxx* scalex);
  290. mnh:=-border+ENTIER(0.5+miny* scaley); mxh:=ENTIER(0.5+maxy* scaley);
  291. FOR i:=0 TO LEN(data,1)-1 DO
  292. x:=-mnw+ENTIER(0.5+data[0,i]*scalex);
  293. y:=h+mnh-ENTIER(0.5+data[1,i]*scaley);
  294. WMRectangles.SetRect(rect, x-1,y-1,x+2,y+2 );
  295. canvas.Fill(rect, WMGraphics.Black, WMGraphics.ModeCopy);
  296. IF LEN(data,0)>2 THEN (* vertical error bars*)
  297. ey:=ENTIER(0.5+data[2,i]*scaley);
  298. canvas.Line(x, y-ey, x, y+ey,WMGraphics.Blue, WMGraphics.ModeCopy);
  299. IF LEN(data,0)>3 THEN (*horizontal error bars*)
  300. ex:=ENTIER(0.5+data[3,i]*scalex);
  301. canvas.Line(x-ex, y, x+ex, y,WMGraphics.Red, WMGraphics.ModeCopy);
  302. END;
  303. END;
  304. END;
  305. Axes(canvas,w,h,mnw,mnh,scalex,scaley);
  306. INC(timestamp);
  307. END Draw;
  308. END Scatter;
  309. (** Regression plot. requires computation of slope,intercept by suited procedure, e.g. derived from /Matrix/StatisticsLinearRegression.SimpleRegression() *)
  310. TYPE Regression*= OBJECT (Scatter)
  311. VAR slope,intercept: LONGREAL; regressor:Regressor;
  312. PROCEDURE &Initialize*(CONST data: ARRAY [*,*] OF LONGREAL; CONST title: ARRAY OF CHAR; regress:Regressor);
  313. BEGIN
  314. regressor:=regress;
  315. regressor(data,slope,intercept);
  316. New(data,title);
  317. END Initialize;
  318. PROCEDURE NewData*(CONST data: ARRAY [*,*] OF LONGREAL);
  319. BEGIN
  320. regressor(data,slope,intercept);
  321. NewData^(data);
  322. END NewData;
  323. PROCEDURE Draw*(canvas : WMGraphics.Canvas; w, h, q : LONGINT);
  324. VAR mnw,mnh,x,y,xx,yy:LONGINT; scalex,scaley, x0, y0, x1, y1:LONGREAL;
  325. BEGIN
  326. Draw^(canvas,w,h,q);
  327. x0:= minx; y0:= x0*slope+intercept;
  328. IF (y0<miny) THEN y0:=miny; x0:=(y0-intercept)/slope;
  329. ELSIF y1>maxy THEN y0:=maxy; x0:=(y0-intercept)/slope;
  330. END;
  331. x1:=maxx; y1:=x1*slope+intercept;
  332. IF (y1<miny) THEN y1:=miny; x1:=(y1-intercept)/slope;
  333. ELSIF y1>maxy THEN y1:=maxy; x1:=(y1-intercept)/slope;
  334. END;
  335. scalex:=scaleRatio*w/width;
  336. scaley:=scaleRatio*h/height;
  337. mnw:=-border+ENTIER(0.5+minx* scalex); mnh:=-border+ENTIER(0.5+miny* scaley);
  338. x:=-mnw+ENTIER(0.5+x0*scalex); y:=h+mnh-ENTIER(0.5+y0*scaley);
  339. xx:=-mnw+ENTIER(0.5+x1*scalex); yy:=h+mnh-ENTIER(0.5+y1*scaley);
  340. canvas.Line(x,y,xx,yy,WMGraphics.Red, WMGraphics.ModeCopy);
  341. END Draw;
  342. END Regression;
  343. PROCEDURE NewWindowPos(dx:LONGINT);
  344. BEGIN
  345. INC(Pos,dx);
  346. PosX:=Pos MOD 700;
  347. PosY:=100+ (Pos DIV 700)*50 MOD 700;
  348. END NewWindowPos;
  349. PROCEDURE Log10(x:LONGREAL):LONGREAL;
  350. BEGIN RETURN MathL.ln(x)/MathL.ln(10);
  351. END Log10;
  352. PROCEDURE Exp10(x:LONGREAL):LONGREAL;
  353. BEGIN RETURN MathL.exp(ENTIER(x)*MathL.ln(10));
  354. END Exp10;
  355. PROCEDURE DummyRegressor(CONST data: ARRAY [*,*] OF LONGREAL; VAR slope,intercept:LONGREAL);
  356. BEGIN
  357. slope:=1; intercept:=2;
  358. END DummyRegressor;
  359. VAR Pos, PosX,PosY: LONGINT;
  360. PROCEDURE Demo*;
  361. VAR h:Histogram; g:Graph; k: Graphs; gx:GraphXY; m:Matrix; s:Scatter; r:Regression;
  362. BEGIN {EXCLUSIVE}
  363. NEW(h, [4,7,8,4,5,9,6,5,3,2,12,17,3,0,2], "Histogram");
  364. NEW(g, [4,7,8,4,5,9,6,5,3,2,12,17,3,-3,2], "Graph");
  365. NEW(k, [[-2,7,8,4,5,9,6,4,7,8,4,5,9,6],
  366. [5,3,2,12,21,3,0,5,3,-2,12,17,4,1]], "MultiGraph");
  367. NEW(gx, [[0.2,-1,0,1,5,9,6,4,7,3,4,5,9,6],
  368. [0.2,3,4,7,12,3,0,5,3,-2,12,17,4,1]], "GraphXY");
  369. NEW(s, [ [0.2,-1,0,1,5,9,6,4,7,3,4,5,9,6],
  370. [0.2,3,4,7,12,3,0,5,3,-2,12,17,4,1],
  371. [1,0.6,1.1,1,1.4,1,1,1,0.7,1,1,0.8,1,1],
  372. [0.5,0.3,0.6,0.4,0.5,0.3,0.6,0.5,0.5,0.4,0.7,0.5,0.5,0.5]], "Scatter with x and y error bars");
  373. NEW(r, [ [0.2,-1,0,1,5,9,6,4,7,3,4,5,9,6],
  374. [0.2,3,4,7,12,3,0,5,3,-2,12,17,4,1],
  375. [1,1,1,1,1,1,1,1,1,1,1,1,1,1]], "Regression with y error bars", DummyRegressor);
  376. NEW(m, [[1,2,3,4],[4,3,2,4],[5,4,-2,-6],[3,1,0,-1]], "Matrix");
  377. END Demo;
  378. (*PROCEDURE Demo1*; (*associate new dataset with existing graph*)
  379. VAR h:Histogram; g:Graph; k: Graphs; gx:GraphXY; m:Matrix; s:Scatter; r:Regression; i:LONGINT;
  380. BEGIN {EXCLUSIVE}
  381. NEW(k, [[-2,7,8,4,5,9,6,4,7,8,4,5,9,6],
  382. [5,3,2,12,21,3,0,5,3,-2,12,17,4,1]], "MultiGraph");
  383. NEW(g, [4,7,8,4,5,9,6,5,3,2,12,17,3,-3,2], "Graph");
  384. FOR i:=0 TO 100000000 DO END;
  385. k.NewData(
  386. [[5,3,2,12,21,3,0,5,3,-2,12,17,4,1],
  387. [-2,7,8,4,5,9,6,4,7,8,4,5,9,6],
  388. [5-1,3,2-1,12,21-1,3,0,5-1,3,-2,12-1,17,4,1]]
  389. );
  390. g.NewData([-2,7,8,4,5,9,6,4,7,8,4,5,9,6]);
  391. END Demo1;*)
  392. PROCEDURE Cleanup;
  393. VAR manager:WM.WindowManager; w,remove:WM.Window;
  394. BEGIN {EXCLUSIVE}
  395. manager:=WM.GetDefaultManager();
  396. manager.lock.AcquireWrite;
  397. w:=manager.GetFirst();
  398. WHILE w#NIL DO
  399. remove:=w;
  400. w:=manager.GetNext(w);
  401. IF (remove#NIL) & (remove IS Window) THEN manager.Remove(remove) END;
  402. END;
  403. manager.lock.ReleaseWrite;
  404. END Cleanup;
  405. BEGIN
  406. Modules.InstallTermHandler(Cleanup);
  407. Pos:=50; NewWindowPos(0);
  408. END WMSimpleGraphs.
  409. SystemTools.Free WMSimpleGraphs ~
  410. SystemTools.FreeDownTo MatrixBase ~
  411. Compiler.Compile -p=Win32G WMSimpleGraphs.Mod ~
  412. WMSimpleGraphs.Demo1 ~