Class: ApexCharts::Renderer
- Inherits:
-
Object
- Object
- ApexCharts::Renderer
- Defined in:
- lib/apex_charts/renderer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #css_class ⇒ Object
- #element_id ⇒ Object
- #height ⇒ Object
- #id_number ⇒ Object
-
#initialize(options) ⇒ Renderer
constructor
A new instance of Renderer.
- #style ⇒ Object
- #variable ⇒ Object
- #window_apex ⇒ Object
Constructor Details
#initialize(options) ⇒ Renderer
34 35 36 |
# File 'lib/apex_charts/renderer.rb', line 34 def initialize() = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/apex_charts/renderer.rb', line 32 def end |
Class Method Details
.render_default(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/apex_charts/renderer.rb', line 8 def render_default() renderer = new html = if renderer.id_number == '1' && !ApexCharts.config..empty? renderer.window_apex else '' end html + " <div id=\"\#{renderer.element_id}\" class=\"\#{renderer.css_class}\" style=\"\#{renderer.style}\"></div>\n <script type=\"text/javascript\">\n var \#{renderer.variable} = new ApexCharts(document.querySelector(\"#\#{renderer.element_id}\"), \#{substitute_function_object(renderer.options.to_json)});\n \#{renderer.variable}.render();\n </script>\n HTML\nend\n" |
.substitute_function_object(json) ⇒ Object
25 26 27 28 29 |
# File 'lib/apex_charts/renderer.rb', line 25 def substitute_function_object(json) json.gsub(%r[{"function":{"args":"(?<args>.*?)","body":"(?<body>.*?)"}}]) do "function(#{$~&.[](:args)}){#{$~&.[](:body)}}" end end |
Instance Method Details
#attributes ⇒ Object
38 39 40 |
# File 'lib/apex_charts/renderer.rb', line 38 def attributes @attributes ||= .delete(:div) { {} } end |
#css_class ⇒ Object
54 55 56 |
# File 'lib/apex_charts/renderer.rb', line 54 def css_class attributes.delete(:class) end |
#element_id ⇒ Object
42 43 44 |
# File 'lib/apex_charts/renderer.rb', line 42 def element_id @element_id ||= attributes.delete(:id) end |
#height ⇒ Object
58 59 60 |
# File 'lib/apex_charts/renderer.rb', line 58 def height "#{options[:chart][:height].to_i}px" end |
#id_number ⇒ Object
46 47 48 |
# File 'lib/apex_charts/renderer.rb', line 46 def id_number @id_number ||= element_id&.[](/\d+/) end |
#style ⇒ Object
62 63 64 |
# File 'lib/apex_charts/renderer.rb', line 62 def style "height: #{height}; #{attributes.delete(:style)}" end |
#variable ⇒ Object
50 51 52 |
# File 'lib/apex_charts/renderer.rb', line 50 def variable @variable ||= attributes.delete(:var) { "chart#{id_number}" } end |
#window_apex ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/apex_charts/renderer.rb', line 66 def window_apex " <script type=\"text/javascript\">\n window.Apex = \#{ApexCharts.config.default_options.to_json}\n </script>\n HTML\nend\n" |