Class: GuindillaGUI::Chart
- Defined in:
- lib/guindilla_gui/guindilla_classes.rb
Overview
—————————————————————————-#
Chart #
—————————————————————————-#
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Attributes inherited from Element
Attributes inherited from Guindilla
#active_id, #blocks, #elements, #inputs, #socket
Instance Method Summary collapse
-
#initialize(attributes, &block) ⇒ Chart
constructor
A new instance of Chart.
- #legend(legend_hash) ⇒ Object
-
#plot(plot_hash) ⇒ Object
initialize.
- #x_axis(x_hash) ⇒ Object
- #y_axis(y_hash) ⇒ Object
Methods inherited from Element
Methods inherited from Guindilla
#after, #alert, #align, #append, #attributes, #audio_out, #background, #border, #border_color, #border_radius, #border_width, #bullet_list, #button, #canvas, #chart, #checkbox, #circle, #color, #color_input, #container, #display, #every, #file_input, #font, #font_family, #font_size, #h_box, #h_rule, #heading, #height, #hide, #image, #justify, #line_break, #link, #margin, #move_to, #number_input, #on_click, #on_hover, #on_leave, #on_mouse_move, #opacity, #ordered_list, #padding, #para, #polygon, #radio_button, #range_slider, #rectangle, #rotate, #show, #size, #source, #square, #style, #sub_script, #sup_script, #text, #text_align, #text_input, #toggle, #transition, #triangle, #url_input, #v_box, #video_out, #web_frame, #width
Constructor Details
#initialize(attributes, &block) ⇒ Chart
Returns a new instance of Chart.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 334 def initialize(attributes, &block) title = attributes.delete(:title) attributes[:type] = 'scatter' unless attributes.has_key?(:type) @type = attributes.delete(:type) attributes[:showlegend] = true unless attributes.has_key?(:showlegend) showlegend = attributes.delete(:showlegend) div = container(attributes) @data = [] @x_axis = {} @y_axis = {} @legend = {} instance_eval &block if block data_string = "[" @data.each{|hash| data_string += to_plotly(hash) + ", "} data_string.delete_suffix!(", ") data_string += "]" layout_string = %Q~{title: "#{title}", showlegend: #{showlegend}, ~ layout_string += "xaxis: " + to_plotly(@x_axis) + ", " unless @x_axis.empty? layout_string += "yaxis: " + to_plotly(@y_axis) + ", " unless @y_axis.empty? layout_string += "legend: " + to_plotly(@legend) + ", " unless @legend.empty? layout_string.delete_suffix!(", ") layout_string += "}" send_js(%Q~ Plotly.newPlot(#{div.id}, #{data_string}, #{layout_string}); ~) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
332 333 334 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 332 def data @data end |
Instance Method Details
#legend(legend_hash) ⇒ Object
368 369 370 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 368 def legend(legend_hash) @legend = legend_hash end |
#plot(plot_hash) ⇒ Object
initialize
363 364 365 366 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 363 def plot(plot_hash) plot_hash[:type] = @type @data << plot_hash end |
#x_axis(x_hash) ⇒ Object
372 373 374 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 372 def x_axis(x_hash) @x_axis = x_hash end |
#y_axis(y_hash) ⇒ Object
376 377 378 |
# File 'lib/guindilla_gui/guindilla_classes.rb', line 376 def y_axis(y_hash) @y_axis = y_hash end |