GraphOps.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited:
Sweetsun Chen, November 17, 1985 2:52:40 am 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;
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, depend on whether the oldGraph is nil. If oldGraph is nil, this name (or "Graph.graph", if it is empty) will be used, otherwise the original file name for oldGraph retains.
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; or
2. EnlistEntities then call AddCrossSection to append y values for each x (x must be in ascending order).
To ensure data integrity, it's better to acquire lock on the handle calling the following procs. (I.e.,
GraphPrivate.Lock[handle];
procA[handle, ...];
procB[handle, ...];
...
GraphPrivate.Unlock[handle];
)
Lock, Unlock: GraphProc;
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: BOOLTRUE] 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: 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,
reverse, discard: BOOLTRUE -- 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: 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
] RETURNS [curve: Entity ← NIL];
AddCrossSection: PROC [
handle: GraphHandle, x: REAL, yvalues: ValueList,
groupId: INT ← 0, reverse, discard: BOOLTRUE];
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.
}.
LOG.
SChen, October 26, 1985 3:48:07 pm PDT, created.