GraphOps.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited:
Sweetsun Chen, November 21, 1985 8:24:48 pm PST
DIRECTORY
Graph USING [CaretIndex, CaretSpec, ColorIndex, Entity, FontIndex, GraphColors, GraphFonts, GraphHandle, GraphProc, JustifX, JustifY, Mark, NullBox, ROPE, TargetSpec, Text, UnitLineWidth, ValueList, XY],
Imager USING [Box, VEC];
GraphOps:
CEDAR
DEFINITIONS = {
OPEN Graph;
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: ROPE ← NIL,
autoBounds, autoDivisions: BOOL ← TRUE,
bounds: Imager.Box ← NullBox, -- [xmin, ymin, xmax, ymax]
divisions: ARRAY XY OF INT ← ALL[5],
grids: ARRAY XY OF BOOL ← ALL[FALSE], -- true: on.
targets: ARRAY XY OF TargetSpec ← ALL[NIL],
carets: ARRAY CaretIndex OF CaretSpec ← ALL[NIL],
showSlope: BOOL ← FALSE, -- slope between primary and secondary carets
colors: GraphColors ← NIL,
fonts: GraphFonts ← NIL,
oldGraph: GraphHandle ← NIL, -- Create new viewer iff nil.
replace: BOOL ← FALSE -- 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; or
2. EnlistEntities then call AddCrossSection to append y values for each x (x must be in ascending order).
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 ← 0,
colorIndex: ColorIndex ← 15, -- black
rotation: REAL ← 0.0, -- angle of rotation, ccw, in degrees.
justifX: JustifX ← left,
justifY: JustifY ← bottom
] RETURNS [text: Text];
If handle or rope are nil, then return nil and no Text is created.
SetXValues:
PROC [handle: GraphHandle, values: ValueList, groupId:
INT ← 0, reverse, discard:
BOOL ←
TRUE]
RETURNS [xEntity: Entity];
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, values: ValueList, groupId:
INT ← 0,
name, comment: ROPE ← NIL,
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,
reverse, discard: BOOL ← TRUE -- refer to values
] RETURNS [curve: Entity];
If number of values # number of x values, then return nil and no curve is created.
reverse: the order of ValueList is reversed.
discard: client no longer holds ownership of the ValueList.
EnlistEntity:
PROC [handle: GraphHandle,
groupId: INT ← 0,
name, comment: ROPE ← NIL,
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
] RETURNS [curve: Entity ← NIL];
AddCrossSection:
PROC [
handle: GraphHandle, x: REAL, yvalues: ValueList,
groupId: INT ← 0, reverse, discard: BOOL ← TRUE];
append trailing values for all curves for each new x.
If yvalues = nil then noop.
If number of y values is not the same as before then the cross section is not appended.
reverse: the order of ValueList is reversed.
discard: client no longer holds ownership of the ValueList.
SaveGraph:
PROC[handle: GraphHandle, plottedOnly:
BOOL ←
TRUE]
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.