Class MRPlot::GraphicContext
In: mrplot.rb
Parent: Object

GraphicContext is the base class for all backends. If you use it as context your plots will be printed to the console as commands. If you want to write your own backend you need to overwrite at least all functions starting with atom_. For optimisation it is recommend to overwrite the other draw methods too. With mrplot comes the RMagickContext which is a binding to the rmagick/imagemagick library.

Which styles are supported by a backend varies but you should support the following styles (and accept the classes as written here):

color (Color):The stroke color of an object (the fill color if there is no stroke)
fill_color (Color):The fill color of an object
line_width (Numeric) :The line/stroke width of an object

These styles are only used in atom_ methods which are handling with text

font (String):The font of a text
font_size (Numeric):The font size of a text
font_style (String):The font style of a text

The following styles are only used within the marker/arrowhead atoms

marker (Symbol):The marker type which will be used
marker_image (String) :Path to a marker image
arrow_head (Symbol) :The style of the arrowhead used

Which arrowheads/markers are supported is depending on the context you use.

Methods

Attributes

clip  [RW] 
windowspace  [RW] 

Public Class methods

Creates a new context

Public Instance methods

Draws an arrowhead at the position point with the align :xarrow or :yarrow

Draws a single line from point_start to point_end

Draws the outline of a rectangle with the dimensions of rect

Draws a filled rectangle with the dimensions of rect

Draws a marker at the position point

Draw a string at a given point. The style parameter depends on the context. Not every style parameter is supported by every context.

rel and rel_v are used to specify how the string is aligned to the given point

rel can be :left, :center, :right rel_v can be :top, :center, :bottom

The rotation parameter is a MRPHelpers::Rotation object which specifies a rotation around a point.

Get the size of a styled string

The size can include the descent!

Get the core context. This depends on the choosen graphics context. The MagickContext for example returns a draw object.

Used to draw multiple connected lines with one command

Can be overwritten for speed reasons. The standard implementation just loops over an array of points and calls atom_drawline(points[i-1], points[i], style)

Used to draw multiple lines in with one command

Can be overwritten for speed reasons.

Draw multiple markers at once

Does the same as transform but transforms from contextspace to windowspace

Draws a placeholder rect to the context

The method is only needed for debugging purposes

Draw a text centered within a rectangle

Transform a point from windowspace (which has a bottom, left = 0,0 coordinate system) to context space (top, left = 0,0). If your backend also supports a coordinate system like the windowspace you don’t need to call it.

[Validate]