GraphOps.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited:
Sweetsun Chen, April 23, 1986 2:29:37 pm PST
Pradeep Sindhu April 8, 1986 11:20:33 am PST
DIRECTORY
Graph USING [CaretIndex, CaretSpec, ColorIndex, Curve, FontIndex, GraphColors, GraphFonts, GraphHandle, GraphProc, JustifX, JustifY, Mark, NullBox, ROPE, TargetSpec, Text, UnitLineWidth, ValueList, XY],
Imager USING [Box, VEC];
GraphOps: CEDAR DEFINITIONS = { OPEN Graph;
constants:
The following color and font indicies are merely some INT's. They are listed just for convenience when client doesn't change the default colors or fonts.
color indicies
White: ColorIndex = 0; -- reserved. better not to change this color.
Red: ColorIndex = 1;
Green: ColorIndex = 2;
Blue: ColorIndex = 3;
Yellow: ColorIndex = 4;
Orange: ColorIndex = 5;
Purple: ColorIndex = 6;
GreenBlue: ColorIndex = 7;
PurpleRed: ColorIndex = 8;
OrangeYellow: ColorIndex = 9;
GreenishBlue: ColorIndex = 10;
YellowishOrange: ColorIndex = 11;
YellowGreen: ColorIndex = 12;
Gray: ColorIndex = 13; -- reserved.
DarkGray: ColorIndex = 14; -- reserved.
Black: ColorIndex = 15; -- reserved.
font indicies
TimesRoman10, LabelFont: FontIndex = 0; -- reserved.
TimesRoman8, LegendFont: FontIndex = 1; -- reserved.
TimesRoman12B: FontIndex = 2;
TimesRoman10I: FontIndex = 3;
TimesRoman10B: FontIndex = 4;
Helvetica10: FontIndex = 5;
Helvetica14B: FontIndex = 6;
Gacha10: FontIndex = 7;
Gacha8: FontIndex = 8;
Hippo10: FontIndex = 9;
Logo14: FontIndex = 10;
Math8: FontIndex = 11; -- reserved.
To ensure data integrity, it's better to lock/unlock the GraphHandle before/after calling the following procs, except when calling NewGraph with oldGraph nil.
Lock, Unlock: GraphProc;
NewGraph: PROC [
all the arguments below can be unspecified.
fileName, -- suggested file name to save the graph.
This suggested file name to save the graph may or may not be used, depending on whether the oldGraph and the original fileName is nil.
If oldGraph is nil, this suggested name (or "Graph.graph", if it is empty) will be used;
otherwise this suggested name will be used, if and only if the original file name for oldGraph is empty.
groupName, -- name of the group of curves in this graph being created.
comment, -- will show up on graph table following the name, but not on graph viewer.
xName: ROPENIL,
autoBounds, autoDivisions: BOOLTRUE,
bounds: Imager.Box ← NullBox, -- [xmin, ymin, xmax, ymax]
divisions: ARRAY XY OF INTALL[5],
grids: ARRAY XY OF BOOLALL[FALSE], -- true: on.
targets: ARRAY XY OF TargetSpec ← ALL[NIL],
carets: ARRAY CaretIndex OF CaretSpec ← ALL[NIL],
showSlope: BOOLFALSE, -- slope between primary and secondary carets
colors: GraphColors ← NIL,
fonts: GraphFonts ← NIL,
oldGraph: GraphHandle ← NIL, -- Create new viewer iff nil.
replace: BOOLFALSE -- true: remove all existing curves and texts on old handle; false: merge new curves and texts with existing ones.
] RETURNS [newGraph: GraphHandle, groupId: INT];
Two methods to set x and y data after calling NewGraph:
1. SetXValues then call AddCurve for each y with values; or
2. AddCurve (without values) for each y, then call AppendValues to append x and y values in ascending order of x.
AddText: PROC [handle: GraphHandle, rope: ROPE,
all following arguments may be defaulted.
place: Imager.VEC ← [0.0, 0.0], -- location with respect to origion and relative to size of axes box
fontIndex: FontIndex ← TimesRoman10,
colorIndex: ColorIndex ← 15, -- black
rotation: REAL ← 0.0, -- angle of rotation, ccw, in degrees.
justifX: JustifX ← left, -- can be left, center, or right.
justifY: JustifY ← bottom -- can be top, center, or bottom.
] RETURNS [text: Text];
If handle or rope are nil, then return nil and no Text is created.
SetXValues: PROC [handle: GraphHandle, groupId: INT, values: ValueList,
reverse, discard: BOOLTRUE] RETURNS [x: Curve];
If values is nil then return nil without setting x values.
reverse: the order of ValueList is reversed.
discard: client no longer holds ownership of the ValueList.
AddCurve: PROC [handle: GraphHandle, groupId: INT,
name, comment: ROPENIL,
colorIndex: ColorIndex ← 0, -- If this argument is zero, a nonzero color index will be assigned for this curve automatically when it is plotted.
mark: Mark ← none,
width: REAL ← UnitLineWidth,
values: ValueList ← NIL, reverse, discard: BOOLTRUE -- refer to values
] RETURNS [curve: Curve];
If handle = nil, or if number of values # number of x values for the group, then return nil and no curve is created.
If x values has been set by calling SetXValues, then values must have the same length as the x values.
If x values have not been set, then values must be nil, and x and y values should be appended by calling AppendValues.
reverse: the order of ValueList is reversed.
discard: client no longer holds ownership of the ValueList.
AppendValues: PROC [
handle: GraphHandle, groupId: INT, x: REAL, yvalues: ValueList,
reverse, discard: BOOLTRUE];
Append trailing values for all curves for each new x.
If yvalues = nil then noop.
Make sure that the number of y values agrees with the total number of curves in this group. And the order of values agrees with the order in which curves were added to the group by calling AddCurve, or its reverse if reverse is true.
reverse: the order of yvalues is reversed.
discard: client no longer holds ownership of the ValueList.
SaveGraph: PROC[handle: GraphHandle, plottedOnly: BOOLTRUE] RETURNS [msg: ROPE];
save currently plotted data (or all data on handle) to a file with handle.graph.fileName as name.
msg is not nil if there is any problem saving the graph.
}.
LOG.
SChen, October 26, 1985 3:48:07 pm PDT, created.