Class: CTioga2::Graphics::Styles::BackgroundStyle
- Inherits:
-
BasicStyle
- Object
- BasicStyle
- CTioga2::Graphics::Styles::BackgroundStyle
- 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::AllStyles, CTioga2::Graphics::Styles::BasicStyle::OldAttrAccessor
Instance Method Summary collapse
-
#draw_background(t) ⇒ Object
Draws the background of the current plot.
- #draw_watermark(t) ⇒ Object
-
#initialize(location = nil, type = nil, label = nil) ⇒ BackgroundStyle
constructor
Creates a new AxisStyle object at the given location with the given style.
Methods inherited from BasicStyle
alias_for, attr_accessor, attribute_type, attribute_types, attributes, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #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 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 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.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 |