## `plot::Pointlist` -- graphical primitive for a list of points

#### Introduction

`plot::Pointlist``(p1, p2...)` represents a plot of either two- or three-dimensional points. Several drawing options exist such as drawing a line from point to point, or drawing a horizontal or vertical line from the axes to each point.

#### Creating Elements

`plot::Pointlist(p1, p2... <, option1, option2...>)`

#### Parameters

`p1, p2` | - | plot points, i.e., objects that can be converted into the domain `plot::Point`; the points must have the same dimension
`option1, option2, ...` | - | plot option(s) of the form `OptionName = value`

#### Related Domains

`plot::Point`, `plot::Scene`

#### Related Functions

`plot`, `plot2d`, `plot3d`, `plot::copy`

#### Details

- Objects generated by `plot::Pointlist` represent graphical primitives for lists of two- or three-dimensional points that can be displayed via `plot`, or used with other graphical primitives of the `plot` library.
- Points `p1`, `p2`... of the represented list which are not given as objects of the domain `plot::Point`, are converted into objects of this domain. See the help page of this domain for information about the default plot options used in this case.
- Use the option DrawMode to connect every two points of the list with a line, or to draw a line from the x-axis and y-axis, respectively, to each point of the list.
- An object of `plot::Pointlist` has type `"graphprim"`, i.e., if `o` is such an object, then the result of `type(o)` is the string `"graphprim"`.
- Options `option1`, `option2`... are specified by equations `OptionName = value`. The following table gives an overview of the available options:

  `OptionName` | admissible values | default value
  Color | `[Flat]`, `[Flat, [r,g,b]]`, `[Height]`, `[Height, [r,g,b], [R,G,B]]`, `[Function, f]` | `[Height]`
  DrawMode | None, Connected, Horizontal, Vertical, set of these values | None
  LineStyle | SolidLines, DashedLines | SolidLines
  LineWidth | positive integers | `1`
  PointStyle | Circles, FilledCircles, FilledSquares, Squares | FilledSquares
  PointWidth | positive integers | `30`
  Title | strings |
  TitlePosition | `[x, y]` |

  See `plot2d` for further details on each option, except of DrawMode that is explained in detail below.
- Plot options acts on every point of the list as well as on the connecting lines (see option DrawMode). One can specify plot options for each point individually by creating the list of points with objects of the domain `plot::Point`. See example 2.

- Scene options for the parameters `option1`, `option2`... are not allowed! One may pass scene options to the function `plot`, or use `plot::Scene` to create an object representing a graphical scene.

- A so-called attribute of a graphical primitive is a named entry of the object which can be accessed via the slot operator `::`.

  Each attribute has the property ``read'', i.e., the value of an attribute `attr` of a graphical primitive `o` can be read with `o::attr`. If the attribute also has the ``write'' property, then the value of the attribute can be changed with `o::attr := new_value`.

  The following attributes are available for a point-list primitive:

  attribute | meaning | properties
  `objects` | A list of objects of the domain `plot::Point`, the points of the point-list primitive. The initial value is the list `[p1, p2...]` of the parameters `p1`, `p2`..., where each parameter was converted into an object of the domain `plot::Point`. Note that if you extract an object of this list and do some changes on this object, then you must set the value of the attribute `refreshPlotdata` to `TRUE` in order to force a rebuild of the plot data of the point list. | read/write
  `options` | A table of plot options of the point-list primitive. Note that if you change the value of this attribute, the entries of the assigned table are not checked to be valid plot options for point-list primitives. Invalid entries lead to runtime errors. The initial value of this attribute is the table stored under the domain entry `"defaultOptions"`, where such options are replaced and added, respectively, which are given with the parameters `option1`, `option2`... of the creating call. | read/write
  `plotdata` | List of the plot data of the point-list primitive in a `plot2d` and `plot3d` conforming syntax, respectively (see the method `"getPlotdata"` below). Note that the value of this attribute should only be used if the attribute `refreshPlotdata` has the value `FALSE` (see below). | read
  `refreshPlotdata` | A boolean value which signals whether the plot data of the point-list primitive must be (re-)build with the method `"getPlotdata"` (see below). If its value is `FALSE`, then the plot data of the point-list primitive is stored in the attribute `plotdata`. The initial value is `TRUE`. | read/write

  See the help page of `plot::Curve2d` for examples for working with attributes of graphical primitives.

#### Option: DrawMode =

`value`

- With this option lines between points and axes can be drawn. Admissible values are None, Connected, Horizontal, Vertical, or a combination of Connected, Horizontal and Vertical given in form of a set; the default is DrawMode = None.
  - DrawMode = None disables lines between the points.
  - DrawMode = Connected enables lines from point to point.
  - DrawMode = Horizontal enables lines from the y-axis to each point.
  - DrawMode = Vertical enables lines from the x-axis to each point.
  - DrawMode = `modes` enables the modes given in the set `modes`. For example, with `DrawMode= {Horizontal, Vertical}`, a line from the x-axis to each point and a line from the y-axis to each point is drawn.
- Each line is a polygon with two vertices. Use the plot options of the point-list object to change their color or width, for example. See example 2.
- This option is only available for lists of two-dimensional points.

#### Operands

The operands of an object of `plot::Pointlist` are the parameters `p1`, `p2`... (in this order).

#### Important Operations

Operands of a point-list primitive can be accessed either using the system function `op`, the index operator `[ ]`, or using the attribute `objects` described above. For example, if `pointlist` is such an object, then the calls `op(pointlist,1)`, `pointlist[1]` and `pointlist::objects[1]` return the first point of `pointlist`.

Via `pointlist[1] := new_point` or `pointlist::objects[1] := new_point`, the first point of `pointlist` is replaced by `new_point`.

See the methods `"op"`, `"_index"`, `"set_index"` and `"slot"` below.

Use the slot operator `::` to get or set plot options of such objects afterwards, i.e., when they have been created. For example, if `pointlist` is such an object, then `pointlist::Color := RGB::Red` changes the color of each point of `pointlist` to red.

#### Result of Evaluation

Evaluating an object of type `plot::Pointlist` returns itself.

#### Function Call

Calling an object of `plot::Pointlist` primitive as a function yields the object itself, regardless of the arguments. The arguments are not evaluated.

#### Entries

defaultOptions

  is a table of plot options for point-list primitives and their default values. Each entry has the form `OptionName = default_value`.

  When an object of the domain `plot::Pointlist` is created, then a copy of this table is stored under the attribute `options` (see the table of attributes above), where those options are added and replaced, respectively, which are given by the (optional) parameters `option1`, `option2`... of the creating call (see ``Creating Elements'' above).

  Plot options, which are not contained in the table stored under the attribute `options` will not be included in the plot data of the object created by the method `"getPlotdata"` (see below).

  For those options, the corresponding default value either is set by a graphical scene, if the option also exists as a scene option (such as the option PointWidth), or it is internally set by the function `plot2d` and `plot3d`, respectively, which are used to plot the object. See the table of plot options above, which gives a summary of the available plot options for point-list primitives and their default values.

  To change the default value of some plot options, the option name and its default value may be added to the table `"defaultOptions"`, or replaced by a new value, respectively.

optionNames

  is a set of the available option names for plots of point-lists.

#### Method _index: indexed access to the operands of a point-list primitive

- `_index(dom pointlist, positive integer i)`
- - Returns the `i`th point of `pointlist`. If `i` is greater than the number of points of `pointlist`, then `FAIL` is returned.
  - This method overloads the system function `_index`, i.e., one may use it in the form `pointlist[i]`, or in functional notation `_index(pointlist, i)`.

#### Method dimension: dimension of a point-list primitive

- `dimension(dom pointlist)`
- - Returns the integer 2 or 3.

#### Method getPlotdata: create the plot data of a point-list primitive

- `getPlotdata(dom pointlist)`
- - Returns a list of an inner list, where the inner list is a plot description of `pointlist` in a `plot2d` and `plot3d` conforming syntax, respectively, i.e., it has the form `[Mode = List, [point(...), ...]]`.

    For example, with `s := plot::Pointlist::getPlotdata(pointlist)` the call `plot2d(s[1])` and `plot3d(s[1])`, respectively, gives a plot of `pointlist`.

  - Only those plot options will be included in the plot data of the point-list, that are contained in the table stored under the attribute `options` (see the table of attributes above). For any other plot option not contained in this table, the corresponding default value set by the function `plot2d` and `plot3d`, respectively, for lists of primitives is used when plotting the object.
  - The result is stored as the value of the attribute `plotdata` of `pointlist`.
  - A call of this method sets the value of the attribute `refreshPlotdata` of `pointlist` to `FALSE`.
  - This method is called from `plot::Scene` to build the plot data of the graphical scene.

#### Method nops: number of operands of a point-list primitive

- `nops(dom pointlist)`
- - Returns the number of points of `pointlist`.
  - This method overloads the system function `nops`, i.e., one may use it in the form `nops(pointlist)`.

#### Method op: extract operands of a point-list primitive

- `op(dom pointlist, positive integer i)`
- - Returns the `i`th point of `pointlist`. If `i` is greater than the number of points of `pointlist`, then `FAIL` is returned.
  - This method overloads the system function `op`, i.e., one may use it in the form `op(pointlist, i)`.

#### Method set_index: set operands of a point-list primitive

- `set_index(dom pointlist, positive integer i, plot::Point p)`
- - Replaces the `i`th point of `pointlist` by the point `p`.
  - If `i` is greater than the number of coordinates of `pointlist`, or if `p` not an object of the domain `plot::Point`, then a warning message is issued. In this case the call of this method has no effect on the object `pointlist`.
  - A call of this method sets the value of the attribute `refreshPlotdata` of `pointlist` to `TRUE`.

#### Method slot: read and write attributes and plot options

- `slot(dom pointlist, string slotname)`
- - Reads the value of the slot `slotname` of `pointlist`. `slotname` may either be the name of an attribute or the name of a plot option. See the tables of available plot options and attributes above.
  - If `slotname` is the name of a plot option, but the option is not contained in the table stored under the attribute `options`, then `FAIL` is returned.

    If `slotname` is an invalid attribute or option, then an error message is issued.

  - This method overloads the system function `slot`, i.e., one may use it in the form `pointlist::slotname_id` (here, `slotname_id` must be the identifier corresponding to the string `slotname`), or in functional notation `slot(pointlist, slotname)`.
- `slot(dom pointlist, string slotname, any val)`
- - Changes the value of the attribute or option with the name `slotname` to the value `val`.
  - If there is no attribute or option with the name `slotname`, or if `val` is not an admissible value for `slotname`, then a warning message is issued. In this case, the value of `slotname` remains unchanged.
  - This method overloads the system function `slot`, i.e., one may use it in the form `pointlist::slotname_id := val` (here, `slotname_id` must be the identifier corresponding to the string `slotname`), or in functional notation `slot(pointlist, slotname, val)`.
  - The value of the attribute `refreshPlotdata` of `point` is set to `TRUE`.

#### Method checkOption: check a plot option

- `checkOption(equation OptionName = value)`
- - This method checks whether `OptionName` is a known plot option for point-list primitives (see the table of available plot options above), and `value` is an admissible value for this option.
  - If both is correct, then the list `[TRUE, OptionName, newValue]` is returned. Note that the value of the option could have been converted into an admissible format. Thus, `newValue` must be used as the value of the option `OptionName` instead of `value`.
  - Otherwise, the list `[FALSE, error_msg]` is returned. The string `error_msg` is a description of the located problem, which can be passed, for example, to the system function `error` to raise a user-specified exception.

#### Method copy: create a copy of a point-list primitive

- `copy(dom pointlist)`
- - Returns a copy of the object `pointlist`.
  - This method is called from the function `plot::copy`. See its help page for details.

#### Method expose: expose the definition of a point-list

- `expose(dom pointlist)`
- - This method returns a sequence of the points of `pointlist`.
  - This method overloads the system function `expose`, i.e., one may use it in the form `expose(pointlist)`.

#### Method modify: modify a copy of a point-list primitive

- `modify(dom pointlist, equation(s) Name1 = value1...)`
- - Creates a copy of the object `pointlist` and changes the slots `Name1`... of this copy to the new values `value1`...
  - The identifiers `Name1`... must be names of attributes or plot options of the domain `plot::Pointlist`. Otherwise a warning message is issued, and the slot remains unchanged. Also, if one of the values `value1`... is not an admissible value for the corresponding attribute or plot option, respectively, the change of the slot is ignored.

    See the tables of available options and attributes above.

  - A call of this method sets the value of the attribute `refreshPlotdata` of the copy of `pointlist` to `TRUE`.
  - This method is called from the function `plot::modify`.

#### Method print: print a point-list primitive

- `print(dom pointlist)`
- - This method returns an unevaluated expression of the form `plot::Pointlist()`. It is used to print objects of `plot::Pointlist` to the screen.
  - Call `expose(pointlist)` to expose the points of `pointlist`.
  - See the system function `print` for details.

#### Example 1

This example illustrates the different modes for plotting lists of points. We start with the default mode, that is plotting each point of the list in the order as specified:

    >> p1 := plot::Pointlist(
         plot::Point(i, exp(i)) $ i = 1..5
       )

                                 plot::Pointlist()

To plot the list of points created, call:

    >> plot(p1)

If you want to connect every two points by a line, then use the option `DrawMode=Connected`:

    >> p2 := plot::Pointlist(
         plot::Point(i, exp(i)) $ i = 1..5, DrawMode = Connected
       ):
       plot(p2)

Set the value of the option DrawMode to Vertical or Horizontal in order to draw a line from the x-axis and the y-axis, respectively, to each point of the list:

    >> p2::DrawMode := Vertical:
       plot(p2)

    >> p2::DrawMode := Horizontal:
       plot(p2)

Here, we used the slot operator `::` to change the value of some plot options of the graphical primitive `p2`.

One can also combine plot modes for lists of points, such as plotting vertical and horizontal lines to each point:

    >> p2::DrawMode := {Horizontal, Vertical}:
       plot(p2)

#### Example 2

One can specify plot options for each point of the list. For example, to plot the points of a list in different sizes, enter:

    >> p := plot::Pointlist(
         plot::Point(i, sin(i), PointWidth = 10*i) $ i = 1..10
       ):
       plot(p)

A plot option of the object `p` acts on every point of the list, except of the points of the list, for which a plot option is set explicitely.

For example, if we change the value of the option Color of the object `p` to blue, then every point is drawn in blue color:

    >> p::Color := RGB::Blue:
       plot(p)

To set the color option for some points explicitely, such as changing the color of the last point to red, one may enter:

    >> (p[10])::Color := RGB::Red:
       plot(p)

The plot options of a plot-list object (here: `p`) also act on the connecting lines, if the option DrawMode is used.

For example, if we create a point-list and set the color of the points explicitely to blue, then connecting lines are still drawn in the default color of objects of the domain `plot::Pointlist`, i.e., in red color:

    >> p2 := plot::Pointlist(
         plot::Point(i, i^2, Color = RGB::Blue) $ i = -5..5,
         DrawMode = Connected
       ):
       plot(p2)

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000