Class: CTioga2::Graphics::Styles::BackgroundStyle

Inherits:
BasicStyle
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/background.rb

Overview

The style of the background of a plot. Handles:

  • uniform background colors (fine)

  • (text) watermark

  • pictures (in a distant future ?)

Constant Summary

Constants inherited from BasicStyle

CTioga2::Graphics::Styles::BasicStyle::OldAttrAccessor

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicStyle

attr_accessor, attributes, from_hash, #instance_variable_defined?, #set_from_hash, #to_hash, #update_from_other

Constructor Details

#initialize(location = nil, type = nil, label = nil) ⇒ BackgroundStyle

Creates a new AxisStyle object at the given location with the given style.



44
45
46
47
48
# File 'lib/ctioga2/graphics/styles/background.rb', line 44

def initialize(location = nil, type = nil, label = nil)
  @background_color = nil
  @watermark_style = MarkerStringStyle.new
  @watermark_style.color = [0.5,0.5,0.5]
end

Instance Attribute Details

#background_colorObject

The background color for a uniform fill.



32
33
34
# File 'lib/ctioga2/graphics/styles/background.rb', line 32

def background_color
  @background_color
end

#watermark_styleObject

A MarkerStringStyle object representing the style of the watermark.



40
41
42
# File 'lib/ctioga2/graphics/styles/background.rb', line 40

def watermark_style
  @watermark_style
end

#watermark_textObject

The text of the watermark, or nil if there should be no watermark.



36
37
38
# File 'lib/ctioga2/graphics/styles/background.rb', line 36

def watermark_text
  @watermark_text
end

Instance Method Details

#draw_background(t) ⇒ Object

Draws the background of the current plot. Fills up the current frame.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ctioga2/graphics/styles/background.rb', line 52

def draw_background(t)
  t.context do
    xl, yb, xr, yt = 
      t.bounds_left, t.bounds_bottom, t.bounds_right, t.bounds_top
    if @background_color
      t.fill_color = @background_color
      t.fill_frame
    end
    draw_watermark(t)
  end
end

#draw_watermark(t) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ctioga2/graphics/styles/background.rb', line 64

def draw_watermark(t)
  if @watermark_text
    x = t.convert_frame_to_figure_x(0.5)
    y = t.convert_frame_to_figure_y(0.5)
    
    delta_y = t.default_text_height_dy * @watermark_style.
      real_vertical_scale
    
    # We split lines on \\, just like in standard LaTeX
    lines = @watermark_text.split(/\s*\\\\\s*/)
    i = + (lines.size-1)/2.0
    for text in lines 
      @watermark_style.
        draw_string_marker(t, text, x, y + delta_y * i)
      i -= 1
    end
  end
end