NewHistograph:
PUBLIC PROC [
dataWidth:
NAT ¬ 480,
-- # of samples buffered for display
dataHeight:
NAT ¬ 100,
-- # of vertical units for samples
maxSample:
INT ¬ 100,
-- sample corresponding to the height
averageFactor:
REAL ¬ 0.9,
-- used to compute declining average
vertiLog:
NAT ¬ 0,
-- log base to use on Y-axis (0, 1 => linear)
title:
ROPE ¬
NIL,
-- graph title
subTitle:
ROPE ¬
NIL,
-- graph sub-title
firstSampleX:
NAT ¬ 64,
-- x position of first sample
numberW:
INTEGER ¬ 32,
-- # of units for displaying numbers
name:
ROPE ¬
NIL,
-- name to use if top-level viewer
parent: Viewer ¬
NIL,
-- parent viewer
wx:
INTEGER ¬ 0,
-- x position in parent
wy:
INTEGER ¬ 0,
-- y position in parent
historical:
BOOL ¬
TRUE,
-- => strip chart style, else random access
border:
BOOL ¬
FALSE,
-- => give returned viewer a border
childXbound:
BOOL ¬
FALSE,
-- => make right bound match parent
tickX:
NAT ¬ 60,
-- # of units to use between horizontal ticks
tickY:
NAT ¬ 25,
-- # of units to use between vertical ticks
numberFont: Font ¬
NIL,
-- font for numbers (default: Helvetica8)
smallFont: Font ¬
NIL,
-- font for subTitle (default: Helvetica8)
largeFont: Font ¬
NIL]
-- font for title (default: Helvetica10)
RETURNS [Viewer] = {
viewer: Viewer ¬ NIL;
hist: HistographData ¬ NIL;
flexible: BOOL ¬ FALSE;
hPlus, hPlusCaption: NAT;
IF historical
AND childXbound
AND parent #
NIL
AND parent.class.flavor = $Container
THEN
flexible ¬ TRUE;
IF numberFont = NIL THEN numberFont ¬ DefaultFont[0];
IF smallFont = NIL THEN smallFont ¬ DefaultFont[0];
IF largeFont = NIL THEN largeFont ¬ DefaultFont[2];
SELECT tickX
FROM
< 8 => tickX ¬ 8;
> 1024 => tickX ¬ 1024;
ENDCASE;
SELECT tickY
FROM
< 8 => tickY ¬ 8;
> 1024 => tickY ¬ 1024;
ENDCASE;
SELECT dataWidth
FROM
< tickX => dataWidth ¬ tickX;
> 4096 => dataWidth ¬ 4096;
ENDCASE;
SELECT dataHeight
FROM
< 8 => dataHeight ¬ 8;
> 1024 => dataWidth ¬ 1024;
ENDCASE;
SELECT numberW
FROM
< 8 => numberW ¬ 8;
> 128 => numberW ¬ 128;
ENDCASE;
SELECT firstSampleX
FROM
< numberW*2 => firstSampleX ¬ numberW*2;
> numberW*4 => firstSampleX ¬ numberW*4;
ENDCASE;
SELECT averageFactor
FROM
< 0.0 => averageFactor ¬ 0.0;
> 1.0 => averageFactor ¬ 1.0;
ENDCASE;
hist ¬ NEW[HistographDataRep[dataWidth]];
hist.height ¬ dataHeight;
hist.width ¬ dataWidth;
hist.flexible ¬ flexible;
hist.historical ¬ historical;
hist.firstSampleX ¬ firstSampleX;
hist.tickX ¬ tickX;
hist.tickY ¬ tickY;
hist.vertiLog ¬ vertiLog;
hist.averageFactor ¬ averageFactor;
hist.numberW ¬ numberW;
hist.maxSample ¬ IF maxSample <= 0.0 THEN 1.0 ELSE REAL[maxSample];
hist.scale ¬ dataHeight/ (IF vertiLog > 2 THEN RealFns.Log[vertiLog, maxSample] ELSE REAL[maxSample]);
hist.title ¬ title;
hist.subTitle ¬ subTitle;
hist.numberFont ¬ numberFont;
hist.smallFont ¬ smallFont;
hist.largeFont ¬ largeFont;
{
wh: INTEGER ¬ numberYInit;
ext: ImagerFont.Extents ¬ ImagerFont.RopeBoundingBox[numberFont, "0123456789"];
rh: INTEGER ¬ hist.numberH ¬ Real.Round[ext.ascent];
curTop: INTEGER ¬ dataHeight+rh;
IF hist.subTitle #
NIL
THEN {
Allow room for the subtitle
ext ¬ ImagerFont.RopeBoundingBox[smallFont, hist.title];
wh ¬ wh + Real.Round[ext.ascent] + subTitlePad;
};
IF hist.title #
NIL
THEN {
Allow room for the title
ext ¬ ImagerFont.RopeBoundingBox[largeFont, hist.title];
wh ¬ wh + Real.Round[ext.ascent] + titlePad;
};
wh ¬ wh + (rh + 4)*2;
Always allow room for the numbers
IF wh < curTop THEN wh ¬ curTop;
hPlus ¬ wh+hist.firstSampleY;
hPlusCaption ¬ hPlus+ViewerSpecs.captionHeight;
};
viewer ¬ ViewerOps.CreateViewer[
flavor: $Histograph,
info: [name: name, data: hist,
openHeight: IF parent#NIL THEN hPlus ELSE hPlusCaption,
parent: parent,
wx: wx, wy: wy, border: border,
ww: dataWidth+firstSampleX+numberW+2,
wh: IF parent#NIL THEN hPlus ELSE hPlusCaption],
paint: FALSE];
IF flexible THEN Containers.ChildXBound[parent, viewer];
RETURN [viewer];
};