src/ginger

Search:
Group by:
Source   Edit  

backendLayer implements the prototype backend layerbaseLayer implements the prototype base layer

########## INIT FUNCTIONS

Default line spread to use for multi line text. Feel free to override!

######## DRAWING FUNCTIONS

gogLayer implements the prototype GoG layer

Vars

LineSpread = 1.4
Source   Edit  

Consts

black = (r: 0.0, g: 0.0, b: 0.0, a: 1.0)
Source   Edit  
DPI = 72.0
Source   Edit  
grey20 = (r: 0.2, g: 0.2, b: 0.2, a: 1.0)
Source   Edit  
grey92 = (r: 0.92, g: 0.92, b: 0.92, a: 1.0)
Source   Edit  
transparent = (r: 0.0, g: 0.0, b: 0.0, a: 0.0)
Source   Edit  
white = (r: 1.0, g: 1.0, b: 1.0, a: 1.0)
Source   Edit  

Procs

func `$`(gobj: GraphObject): string {....raises: [ValueError], tags: [],
                                      forbids: [].}
Source   Edit  
proc `*`(c1, c2: Coord1D): Coord1D {....raises: [Exception, ValueError, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc `+`(c1, c2: Coord1D): Coord1D {....raises: [Exception, ValueError, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc `+`(c: Coord1D; q: Quantity): Coord1D {....raises: [ValueError], tags: [],
    forbids: [].}
Source   Edit  
proc `-`(c1, c2: Coord1D): Coord1D {....raises: [Exception, ValueError, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc `-`(c: Coord1D; q: Quantity): Coord1D {....raises: [ValueError], tags: [],
    forbids: [].}
Source   Edit  
proc `/`(c1, c2: Coord1D): Coord1D {....raises: [Exception, ValueError, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc `==`(c1, c2: Coord): bool {....raises: [ValueError, Exception, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
Source   Edit  
proc `==`(c1, c2: Coord1D): bool {....raises: [ValueError, Exception, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
TODO: after certain conversion we may end up with unequal values due to floating point errors. Handle? Source   Edit  
proc `[]`(view: var Viewport; idx: int): var Viewport {....raises: [], tags: [],
    forbids: [].}
returns the idx child of view as a mutable object Source   Edit  
proc `[]`(view: Viewport; idx: int): Viewport {....raises: [], tags: [],
    forbids: [].}
returns the idx child of view Source   Edit  
proc `[]=`(view: var Viewport; idx: int; viewToSet: Viewport) {....raises: [],
    tags: [], forbids: [].}
override the idx child of view with viewToSet Source   Edit  
proc add(q1, q2: Quantity; length: Option[Quantity] = none();
         scale: Option[Scale] = none(); asCoordinate = false): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
multiplication of two quantities. If one of the quantities is absolute the result will also be absolute! If asCoordinate is true and on of the quantities is given in ukData, the addition will be handled by interpreting the value q as belonging to a coordinate on the scale instead of a distance defined by the total scale length (scale.high - scale.low). In practice this means scale.low is subtracted from the q beforehand. Source   Edit  
func addObj(view: Viewport; obj: GraphObject) {....raises: [], tags: [],
    forbids: [].}
adds the given obj to the viewport's objects and makes sure it inherits all properties, e.g. Style and data scales Source   Edit  
func addObj(view: Viewport; objs: varargs[GraphObject]) {....raises: [], tags: [],
    forbids: [].}
adds the objs to the viewport's objects and makes sure they inherit all properties, e.g. Style and data scales Source   Edit  
proc addViewport(view: Viewport; left = 0.0; bottom = 0.0; width = 1.0;
                 height = 1.0; style = none(); xScale = none(); yScale = none();
                 rotate = none(); scale = none(); name = "";
                 dataAsBitmap = false): Viewport {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
add a new viewport with the given settings to the view, set at relative coordinates (left, bottom), (width, height) TODO: Do not return viewchild??? Source   Edit  
proc addViewport(view: Viewport; origin: Coord; width, height: Quantity;
                 style = none(); xScale = none(); yScale = none();
                 rotate = none(); scale = none(); name = "";
                 dataAsBitmap = false): Viewport {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
add a new viewport with the given settings to the view TODO: do not return viewchild??? Source   Edit  
proc axisCoord(c: Coord1D; axKind: AxisKind; isSecondary = false): Coord {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
A convenience proc, which returns a Coord on the given axKind. c is the Coord1D along that axis. Source   Edit  
proc background(view: Viewport; style: Option[Style] = none(); name = "") {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c(cx, cy: Coord1D): Coord {....raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
proc calcTickLocations(scale: Scale; numTicks: int): (Scale, float, int) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Source   Edit  
proc divide(q1, q2: Quantity; length: Option[Quantity] = none();
            scale: Option[Scale] = none(); asCoordinate = false): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
multiplication of two quantities. If one of the quantities is absolute the result will also be absolute! If asCoordinate is true and on of the quantities is given in ukData, the division will be handled by interpreting the value q as belonging to a coordinate on the scale instead of a distance defined by the total scale length (scale.high - scale.low). In practice this means scale.low is subtracted from the q beforehand. Source   Edit  
proc draw(view: Viewport; filename: string;
          texOptions: TeXOptions = TeXOptions()) {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect,
    TimeEffect], forbids: [].}

Handles the drawing of the given Viewport and if applicable stores it in the given filename.

Currently this procedure provides the interface between the runtime based BackendKind exposed to ggplotnim and the internal compile time based dispatch between the different supported backends.

Backends need to be activated by demand using use<Backend>. The default nim.cfg shipped with this library activates the Cairo and TikZ backend by default.

Source   Edit  
proc draw[T](img: var BImage[T]; gobj: GraphObject)
draws the given graph object on the image Source   Edit  
proc draw[T](img: var BImage[T]; view: Viewport)
Source   Edit  
proc drawBoundary(view: Viewport; color = none(); writeName = false;
                  writeNumber = none(); style = none()) {....raises: [], tags: [],
    forbids: [].}
Adds a boundary (a rectangle) around the given viewport Source   Edit  
proc embedAsRelative(view: var Viewport; idx: int; viewToEmbed: Viewport) {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}

embeds the viewToEmbed into view at child index idx while converting all quantities and coordinates into relative coordinates. This should lead to a proper scaling, if the viewports are nested, absolute scales are used and/or the aspect ratio is different.

This proc updates the widths and heights to the view.wImg, view.hImg of all viewToEmbed children. This proc is to be used if one wishes to assign to viewToEmbed to a child of view, which have different sizes. Useful to combine two or more finished views to e.g. a grid.

Source   Edit  
proc embedAt(view: var Viewport; idx: int; viewToEmbed: Viewport) {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
embeds the viewToEmbed into view at child index idx. This proc updates the widths and heights to the view.wImg, view.hImg of all viewToEmbed children. This proc is to be used if one wishes to assign to viewToEmbed to a child of view, which have different sizes. Useful to combine two or more finished views to e.g. a grid. Source   Edit  
proc embedInto(q: Quantity; axKind: AxisKind; view: Viewport): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Embeds the quantity q into the viewport view NOTE: Embedding a quantity is a special case. A quantity (in our case) describes a length. This means that any absolute quantity must not be scaled, whereas a relative quantity "0.2 * viewport size" must be. Source   Edit  
func formatTickValue(f: float; scale = 0.0): string {....raises: [], tags: [],
    forbids: [].}

performs the formatting of tick labels from the given values Uses fixed point notation for values < 1e5 and > 1e-5. Otherwise exponential notation with precision 4, zeros are trimmed. A scale, which is (if possible) just the diff of two tick places is used to determine whether the given value f is supposed to be the zero value on the scale. From e.g. linspace we might end up with 5.1234e-17 for the string representation of zero. The scale is required to know whether the values aren't inherently this small.

The {.intdefine.} compile time constants TickPrecisionCutoff and TickPrecision can be used to adjust the

  • TickPrecisionCutoff: decimal of the 10^((-)TickPrecisionCutoff) value within which the tick labels are printed as decimal values and outside in exp notation
  • TickPrecision: the number of digits used as precision as an argument to formatBiggestFloat.
Source   Edit  
proc getCenter(view: Viewport): (float, float) {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
returns the center position of the given viewport in relative coordinates NOTE: it is not (0.5, 0.5), because the coordinates of the viewport are described in the coordinate system of the parent! Source   Edit  
proc getStrHeight(backend: BackendKind; fType: FiletypeKind; text: string;
                  font: Font): Quantity {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
returns a quantity of the height of the given text under the given font, taking into account multiple lines. The result is of kind ukPoint. NOTE: This currently uses a hardcoded line spacing, which is the same as the one used in initMultiLineText below! Source   Edit  
proc getStrHeight(view: Viewport; text: string; font: Font): Quantity {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
proc getStrWidth(backend: BackendKind; fType: FiletypeKind; text: string;
                 font: Font): Quantity {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
returns a Quantity of kind ukStrWidth for the given string under the font font of unit kind ukPoint Source   Edit  
proc getStrWidth(view: Viewport; text: string; font: Font): Quantity {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
func ggColorHue(num: int; hueStart = 15.0; chroma = 100.0; luminance = 65.0): seq[
    Color] {....raises: [], tags: [], forbids: [].}
returns the default ggplot2 color hue for num colors Source   Edit  
proc height(view: Viewport): Quantity {....raises: [ValueError, Exception],
                                        tags: [], forbids: [].}
returns the height of the Viewport in ukRelative NOTE: this procedure is a no-op, if the height is already stored as a ukRelative! Source   Edit  
proc high(view: Viewport): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc initCoord(view: Viewport; x, y: float; kind: UnitKind = ukRelative): Coord {.
    ...raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
length and scale aware (using Viewport) initCoord, that automatically assigns the correct length and scale for absolute / data coords Source   Edit  
proc initCoord(x, y: float; kind: UnitKind = ukRelative): Coord {....raises: [],
    tags: [], forbids: [].}
returns a coordinate at coordinates x, y of kind kind Source   Edit  
func initCoord1D(at: float; kind: UnitKind = ukRelative; axKind: AxisKind = akX): Coord1D {.
    ...raises: [], tags: [], forbids: [].}
returns a Coord1D at coordinate at of kind kind Source   Edit  
proc initCoord1D(view: Viewport; at: float; axKind: AxisKind;
                 kind: UnitKind = ukPoint): Coord1D {.
    ...raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
Full name should be initCoord1D, but since it's a convenience function given name is short. initialize a Coord1D based on the given viewport. This is useful for absolute or data variables, which depend on the absolute sizes or scales Source   Edit  
proc initErrorBar(view: Viewport; pt: Coord; errorUp: Coord1D;
                  errorDown: Coord1D; axKind: AxisKind; ebKind: ErrorBarKind;
                  style: Option[Style] = none(); name = "errorBar"): GraphObject {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
creates an error bar for the point pt of kind ebKind with the errors given by errorUp and errorDown along the axis axKind. If the axKind is akX, errorUp will describe the increase along the X axis (to the right). NOTE: this proc assumes that if the errors are given as ukData, the scales associated are the same as for the data point! Source   Edit  
proc initErrorBar(view: Viewport; pt: Point; errorUp: Coord1D;
                  errorDown: Coord1D; axKind: AxisKind; ebKind: ErrorBarKind;
                  style: Option[Style] = none(); name = "errorBar"): GraphObject {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
This version of initErrorBar uses the errorUp and errorDown values as absolute values. There is no reference point. The given pt is used to determine the x or y value of the orthogonal axis. Source   Edit  
proc initGridLines(view: Viewport; xticks: Option[seq[GraphObject]] = none();
                   yticks: Option[seq[GraphObject]] = none(); major = true;
                   style: Option[Style] = none(); name = "GridLines"): GraphObject {.
    ...raises: [Exception, ValueError, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
proc initLine(view: Viewport; start: Coord; stop: Coord;
              style: Option[Style] = none(); name = "line"): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func initManyPoint(view: Viewport; pos: seq[Coord]; style: Style;
                   name = "many_points"): GraphObject {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc initMultiLineText(view: Viewport; origin: Coord; text: string;
                       textKind: static GraphObjectKind;
                       alignKind: TextAlignKind;
                       fontOpt: Option[Font] = none[Font]();
                       rotate = none[float](); name = "multiLineText";
                       useRealText = true): seq[GraphObject]
Creates a text based GraphObject of kind textKind. This proc will split the input text by lines and return a properly spaced sequence of text objects, which conform to the desired text alignment and font while keeping a spacing of 0.75 of the text height. NOTE: The current spacing of 0.75 seems excessive to me. As far as I'm aware typical spacings range from 0.2 to 0.45 Maybe our calculation for the string height or the addition of those coordinates is off! Thus for the time being, we leave this hardcoded, since this works for now. Source   Edit  
proc initPoint(view: Viewport; pos: Coord; size = 3.0;
               marker: MarkerKind = mkCircle; color = color(0.0, 0.0, 0.0);
               name = "point"): GraphObject {.inline, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
func initPoint(view: Viewport; pos: Coord; style: Style; name = "point"): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc initPoint(view: Viewport; pos: Point; size = 3.0;
               marker: MarkerKind = mkCircle; color = color(0.0, 0.0, 0.0);
               name = "point"): GraphObject {.inline, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc initPolyLine(view: Viewport; pos: seq[Coord];
                  style: Option[Style] = none(); name = "polyLine"): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc initPolyLine(view: Viewport; pos: seq[Point];
                  style: Option[Style] = none(); name = "polyLine"): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc initRaster(view: Viewport; origin: Coord; width, height: Quantity;
                numX, numY: int; drawCb: proc (): seq[uint32]; rotate = none();
                name = "raster"): GraphObject {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc initRect(view: Viewport; left, bottom, width, height: float;
              color = color(0.0, 0.0, 0.0); gradient = none(); style = none();
              name = "rect"): GraphObject {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc initRect(view: Viewport; origin: Coord; width, height: Quantity;
              color = color(0.0, 0.0, 0.0); gradient = none(); style = none();
              rotate = none(); name = "rect"): GraphObject {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc initText(view: Viewport; origin: Coord; text: string;
              textKind: static GraphObjectKind; alignKind: TextAlignKind;
              font: Option[Font] = none[Font](); rotate = none[float]();
              name = "text"): GraphObject
Creates a text based GraphObject of kind textKind. This proc does not support multiple lines! Use initMultiText instead if that is required. Source   Edit  
proc initTicks(view: Viewport; axKind: AxisKind; numTicks: int = 0;
               tickLocs: seq[Coord] = @[]; tickKind: TickKind = tkOneSide;
               major = true; style: Option[Style] = none(); updateScale = true;
               isSecondary = false; boundScale = none()): seq[GraphObject] {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Initializes the tick positions for the given axKind for either major or minor (major == false) ticks. If updateScale is true will recursively update all data scales associated to the viewports children and objects. Set updateScale to false only if you're certain that the update is unnecessary! boundScale can be used to bound the possible range of the range in which any ticks will be created. The algorithm will run as it does without, but only those ticks inside of the bounds will actually be added. This however does not affect the result if called with tickLocs! In that case the caller is responsible for selecting the ticks. Also the updated data scale of the viewport may lie outside the boundScale! Source   Edit  
proc initViewport(left = 0.0; bottom = 0.0; width = 1.0; height = 1.0;
                  style = none(); xScale = none(); yScale = none();
                  rotate = none(); scale = none(); name = ""; parent = "";
                  wImg = 640.0; hImg = 480.0; backend = bkCairo; fType = fkPng;
                  dataAsBitmap = false): Viewport {....raises: [], tags: [],
    forbids: [].}
convenience init function for Viewport using relative coordinates NOTE: this function should only be used to create a Viewport within the main image viewport! Otherwise use the addViewport procs on a viewport! Source   Edit  
proc initViewport(origin: Coord; width, height: Quantity; style = none();
                  xScale = none(); yScale = none(); rotate = none();
                  scale = none(); name = ""; parent = ""; wImg = 640.0;
                  hImg = 480.0; wParentView: Option[Quantity] = none();
                  hParentView: Option[Quantity] = none(); backend = bkCairo;
                  fType = fkPng; dataAsBitmap = false): Viewport {....raises: [],
    tags: [], forbids: [].}
initializes a Viewport with origin in any coordinate system with 1D coordinates providing width and height Uses Coord1D to allow to define sizes in arbitrary units Source   Edit  
proc layout(view: Viewport; cols, rows: int; colWidths: seq[Quantity] = @[];
            rowHeights: seq[Quantity] = @[];
            margin: Quantity = quant(0.0, ukRelative); ignoreOverflow = false) {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
creates a layout of viewports within the given view of cols columns and rows rows. Optionally the widths and heights of the cols / rows may be set. If none are given, the widths / heights will be evenly sized. Any width or height that has a relative size of 0.0, will be considered as unspecified. In this case we split the remaining space after the other sizes are summed between those. If a margin is given, each viewport created will be surrounded by that margin in all directions. If ignoreOverflow is true a layout which technically does not fit into the existing view will still be allowed. Otherwise (default) a ValueError is raised. Source   Edit  
proc len(view: Viewport): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc pointHeight(view: Viewport): Quantity {.inline,
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Source   Edit  
proc pointWidth(view: Viewport): Quantity {.inline,
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Source   Edit  
func pretty(gobj: GraphObject; indent = 0): string {....raises: [ValueError],
    tags: [], forbids: [].}
Source   Edit  
func quant(val: float; unit: UnitKind): Quantity {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc relativeTo(view: Viewport; to: Viewport): Viewport {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
proc strHeight(backend: BackendKind; fType: FiletypeKind; val: float;
               font: Font; text = "M"): Coord1D {....raises: [], tags: [],
    forbids: [].}
returns a Coord1D of kind ukStrHeight for the given number of times the string height val for font font. We use 'M' to determine the height of the given font Source   Edit  
proc strHeight(view: Viewport; val: float; font: Font; text = "W"): Coord1D {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc strWidth(backend: BackendKind; fType: FiletypeKind; val: float; font: Font;
              text = "M"): Coord1D {....raises: [], tags: [], forbids: [].}
returns a Coord1D of kind ukStrWidth for the given number of times the string height val for font font. We use 'M' to determine the height of the given font Source   Edit  
proc strWidth(view: Viewport; val: float; font: Font; text = "W"): Coord1D {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc sub(q1, q2: Quantity; length: Option[Quantity] = none();
         scale: Option[Scale] = none(); asCoordinate = false): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
subtraction of two quantities. If one of the quantities is absolute the result will also be absolute! If asCoordinate is true and on of the quantities is given in ukData, the subtraction will be handled by interpreting the value q as belonging to a coordinate on the scale instead of a distance defined by the total scale length (scale.high - scale.low). In practice this means scale.low is subtracted from the q beforehand. Source   Edit  
proc tickLabels(view: Viewport; tickPos: seq[Coord1D]; tickLabels: seq[string];
                axKind: AxisKind; font: Option[Font] = none();
                isSecondary = false; rotate = none(); margin = none();
                alignToOverride = none(); style = none();
                tickKind: TickKind = tkOneSide): (seq[GraphObject],
    seq[GraphObject]) {....raises: [ValueError, Exception, OSError, IOError,
                                 KeyError], tags: [ReadEnvEffect, ReadIOEffect,
    ExecIOEffect, RootEffect, WriteIOEffect], forbids: [].}
Overload of tickLabels, which allows to define custom tick label texts for ticks at positions tickPos Source   Edit  
proc tickLabels(view: Viewport; ticks: seq[GraphObject];
                font: Option[Font] = none(); margin = none();
                isSecondary = false; format: proc (x: float): string = nil;
                rotate = none(); alignToOverride = none()): seq[GraphObject] {.
    ...raises: [Exception, ValueError, OSError, IOError, KeyError], tags: [
    RootEffect, ReadEnvEffect, ReadIOEffect, ExecIOEffect, WriteIOEffect],
    forbids: [].}
returns all tick labels for the given ticks TODO: Clean up the auto subtraction code! Source   Edit  
proc times(q1, q2: Quantity; length: Option[Quantity] = none();
           scale: Option[Scale] = none(); asCoordinate = false): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
multiplication of two quantities. If one of the quantities is absolute the result will also be absolute! If asCoordinate is true and on of the quantities is given in ukData, the multiplication will be handled by interpreting the value q as belonging to a coordinate on the scale instead of a distance defined by the total scale length (scale.high - scale.low). In practice this means scale.low is subtracted from the q beforehand. Source   Edit  
proc to(p: Coord1D; toKind: UnitKind; absLength = none(); datScale = none();
        datAxis = none(); strText = none(); strFont = none()): Coord1D {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
converts the given 1D Coordinate position in a certain coordinate system to the same position in a target coordinate system NOTE: this procedure is a potentially lossy conversion! Source   Edit  
proc to(p: Coord; toKind: UnitKind; absWidth = none(); absHeight = none();
        datXScale = none(); datYScale = none(); strText = none();
        strFont = none()): Coord {....deprecated: "Please use `to` for the individual `Coord1D` objects instead!", raises: [
    ValueError, Exception, OSError, IOError, KeyError], tags: [ReadEnvEffect,
    ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect], forbids: [].}
Deprecated: Please use `to` for the individual `Coord1D` objects instead!
converts the given Coordinate position in a certain coordinate system to the same position in a target coordinate system TODO: if we decide to keep this proc, replace it by calling to for Coord1D on individual fields instead. Source   Edit  
func to(q: Quantity; kind: UnitKind; length = none(); scale = none()): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Source   Edit  
func toCentimeter(q: Quantity): Quantity {....raises: [ValueError], tags: [],
    forbids: [].}
returns the quantity converted to centimeter. This will fail if attempted to convert a non absolute unit! Source   Edit  
proc toData(q: Quantity; scale: Scale; length: Option[Quantity] = none()): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
Returns quantity q as a quantity in the given data scale, a ukData quantity. Source   Edit  
func toInch(q: Quantity): Quantity {....raises: [ValueError], tags: [], forbids: [].}
returns the quantity converted to inch. This will fail if attempted to convert a non absolute unit! Source   Edit  
proc toPoints(p: Coord1D; length: Option[Quantity] = none(); backend = none()): Coord1D {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
converts the given coordinate to point based absolute values Source   Edit  
func toPoints(q: Quantity; length: Option[Quantity] = none()): Quantity {.
    ...raises: [ValueError], tags: [], forbids: [].}
returns the quantity converted to Points. This will fail if attempted to convert a non absolute unit! Source   Edit  
proc toRelative(p: Coord): Coord {....raises: [ValueError, Exception, OSError,
    IOError, KeyError], tags: [ReadEnvEffect, ReadIOEffect, ExecIOEffect,
                               RootEffect, WriteIOEffect], forbids: [].}
converts the given coordinate to a relative coordinate Source   Edit  
proc toRelative(p: Coord1D; length: Option[Quantity] = none(); backend = none()): Coord1D {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
converts the given coordinate to a relative coordinate Source   Edit  
proc toRelative(q: Quantity; length: Option[Quantity] = none();
                scale: Option[Scale] = none()): Quantity {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
returns a quantity as a relative length (typically) in a given viewport Source   Edit  
func updateDataScale(view: Viewport) {....raises: [], tags: [], forbids: [].}
Updates the data scales of all children viewports of view and their objects recursively Note that if view contains many children or children with many objects this may potentially be quite expensive! Source   Edit  
func updateDataScale(view: Viewport; objs: var seq[GraphObject]) {....raises: [],
    tags: [], forbids: [].}
updates the data scales associated to the objs to the current view.(x|y)scale. This is important, because due to calculation of tick locations (and thus new range scale) the associated scales may be wrong. Potentially other objects may also have an associated scale (e.g. the user may want to define some location in scale coordinates), hence check for any Coord in the object. Source   Edit  
proc width(view: Viewport): Quantity {....raises: [ValueError, Exception],
                                       tags: [], forbids: [].}
returns the width of the Viewport in ukRelative NOTE: this procedure is a no-op, if the width is already stored as a ukRelative! Source   Edit  
proc xaxis(view: Viewport; width = 1.0; color = color(0.0, 0.0, 0.0)): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc xlabel(view: Viewport; label: string; font = defaultFont(); margin = 1.0;
            name = "xLabel"; isCustomMargin = false; isSecondary = false;
            rotate = none()): GraphObject {....raises: [ValueError, Exception],
    tags: [], forbids: [].}
margin assumed to be in cm! Source   Edit  
proc xlabel(view: Viewport; label: string; margin: Coord1D;
            font = defaultFont(); name = "xLabel"; isSecondary = false;
            rotate = none()): GraphObject {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
proc xticks(view: Viewport; numTicks: int = 10; tickLocs: seq[Coord] = @[];
            major = true; tickKind: TickKind = tkOneSide;
            style: Option[Style] = none(); updateScale = true;
            isSecondary = false): seq[GraphObject] {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
generates the ticks for the x axis. Note that this updates the data scale of all children and objects of the given viewport. In order for this to as inexpensive as possible make sure to call this rather before all objects have been added. Source   Edit  
proc yaxis(view: Viewport; width = 1.0; color = color(0.0, 0.0, 0.0)): GraphObject {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc ylabel(view: Viewport; label: string; font = defaultFont(); margin = 1.0;
            name = "yLabel"; isCustomMargin = false; isSecondary = false;
            rotate = none()): GraphObject {....raises: [ValueError, Exception],
    tags: [], forbids: [].}
Margin assumed to be in cm! Source   Edit  
proc ylabel(view: Viewport; label: string; margin: Coord1D;
            font = defaultFont(); name = "yLabel"; isSecondary = false;
            rotate = none()): GraphObject {.
    ...raises: [ValueError, Exception, OSError, IOError, KeyError], tags: [
    ReadEnvEffect, ReadIOEffect, ExecIOEffect, RootEffect, WriteIOEffect],
    forbids: [].}
Source   Edit  
proc yticks(view: Viewport; numTicks: int = 10; tickLocs: seq[Coord] = @[];
            major = true; tickKind: TickKind = tkOneSide;
            style: Option[Style] = none(); updateScale = true;
            isSecondary = false): seq[GraphObject] {.
    ...raises: [ValueError, Exception], tags: [], forbids: [].}
generates the ticks for the y axis. Note that this updates the data scale of all children and objects of the given viewport. In order for this to as inexpensive as possible make sure to call this rather before all objects have been added. Source   Edit  

Iterators

iterator items(view: Viewport): Viewport {....raises: [], tags: [], forbids: [].}
Source   Edit  
iterator mitems(view: var Viewport): var Viewport {....raises: [], tags: [],
    forbids: [].}
Source   Edit  

Templates

template c(view: Viewport; x, y: float; kind: UnitKind = ukRelative): Coord
Source   Edit  
template c(x, y: float; kind: UnitKind = ukRelative): Coord
Source   Edit  
template c1(at: float; kind: UnitKind = ukRelative; axKind: AxisKind = akX): Coord1D
Source   Edit  
template c1(view: Viewport; at: float; axKind: AxisKind;
            kind: UnitKind = ukPoint): Coord1D
Source   Edit  
template XAxisYPos(view: Option[Viewport] = none(); margin = 0.0;
                   isSecondary = false): untyped
Y position of the X axis. Source   Edit  
template YAxisXPos(view: Option[Viewport] = none(); margin = 0.0;
                   isSecondary = false): untyped
X position of the Y axis. Source   Edit