Class: Minichart::Base
- Inherits:
-
Victor::SVGBase
- Object
- Victor::SVGBase
- Minichart::Base
- Defined in:
- lib/minichart/base.rb
Overview
Base class for all Minichart classes
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.defaults ⇒ Object
For subclasses to define.
- .master_defaults ⇒ Object
- .options(update_hash = nil) ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
- #full_height ⇒ Object
- #full_width ⇒ Object
-
#initialize(data, user_options = {}) ⇒ Base
constructor
A new instance of Base.
- #setup_clip_path(id) ⇒ Object
- #viewbox ⇒ Object
Constructor Details
#initialize(data, user_options = {}) ⇒ Base
Returns a new instance of Base.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/minichart/base.rb', line 31 def initialize(data, = {}) @data = data @options = self.class..merge super viewBox: viewbox, style: [:style] element :rect, x: 0, y: 0, width: full_width, height: full_height, fill: [:background], stroke_width: 0 clip_path_id = IDGenerator.next setup_clip_path clip_path_id element :g, clip_path: "url(##{clip_path_id})" do build end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/minichart/base.rb', line 4 def data @data end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/minichart/base.rb', line 4 def @options end |
Class Method Details
.defaults ⇒ Object
For subclasses to define
20 21 22 |
# File 'lib/minichart/base.rb', line 20 def defaults {} end |
.master_defaults ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/minichart/base.rb', line 7 def master_defaults { background: 'white', height: 100, width: 300, stroke: 2, style: {}, color: '#66f', padding: 10, } end |
.options(update_hash = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/minichart/base.rb', line 24 def (update_hash = nil) @options ||= master_defaults.merge defaults @options.merge! update_hash if update_hash @options end |
Instance Method Details
#build ⇒ Object
68 69 70 |
# File 'lib/minichart/base.rb', line 68 def build raise NotImplementedError, "#build is not implemented" end |
#full_height ⇒ Object
60 61 62 |
# File 'lib/minichart/base.rb', line 60 def full_height [:height] + [:padding] * 2 end |
#full_width ⇒ Object
64 65 66 |
# File 'lib/minichart/base.rb', line 64 def full_width [:width] + [:padding] * 2 end |
#setup_clip_path(id) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/minichart/base.rb', line 48 def setup_clip_path(id) element :defs do element :clipPath, id: id do element :rect, width: full_width, height: full_height end end end |
#viewbox ⇒ Object
56 57 58 |
# File 'lib/minichart/base.rb', line 56 def viewbox "0 0 #{full_width} #{full_height}" end |