Class: ActiveCharts::ScatterPlot

Inherits:
XYChart show all
Defined in:
lib/active_charts/scatter_plot.rb

Constant Summary

Constants inherited from XYChart

XYChart::OFFSET

Constants inherited from RectangularChart

RectangularChart::TOP_LEFT_OFFSET

Constants inherited from Chart

Chart::CSS_CLASSES, Chart::MARGIN

Instance Attribute Summary collapse

Attributes inherited from XYChart

#section_height, #section_width, #x_label_y, #x_labels, #x_max, #x_min, #x_ticks, #y_label_x, #y_labels, #y_max, #y_min, #y_ticks

Attributes inherited from RectangularChart

#grid_height, #grid_width, #svg_height, #svg_width

Attributes inherited from Chart

#collection, #columns_count, #data_formatters, #extra_css_classes, #label_height, #max_values, #rows_count, #series_labels, #title

Instance Method Summary collapse

Methods inherited from XYChart

#bottom_label_text_tags, #initialize, #side_label_text_tags

Methods inherited from RectangularChart

#grid_rect_tag, #initialize

Methods inherited from Chart

#initialize, #legend_list_tag, #to_html

Constructor Details

This class inherits a constructor from ActiveCharts::XYChart

Instance Attribute Details

#dot_labelsObject (readonly)

Returns the value of attribute dot_labels.



3
4
5
# File 'lib/active_charts/scatter_plot.rb', line 3

def dot_labels
  @dot_labels
end

Instance Method Details

#chart_svg_tagObject



5
6
7
8
9
10
11
# File 'lib/active_charts/scatter_plot.rb', line 5

def chart_svg_tag
  inner_html = [grid_rect_tag, ticks(x_ticks, y_ticks), dots, 
                side_label_text_tags, bottom_label_text_tags].flatten.join('
      ')
  
  tag.svg(inner_html.html_safe, svg_options)
end

#dotsObject



13
14
15
16
17
18
19
20
# File 'lib/active_charts/scatter_plot.rb', line 13

def dots
  whitelist = %w[cx cy class]
  
  dots_specs.flatten.map do |dot| 
    [%(<circle #{tag_options(dot, whitelist)} />),
     tag.text(dot[:label], x: dot[:cx] + OFFSET, y: dot[:cy] - OFFSET, class: label_classes)]
  end
end

#dots_specsObject



22
23
24
25
26
27
28
# File 'lib/active_charts/scatter_plot.rb', line 22

def dots_specs
  collection.map.with_index do |row, row_index|
    row.map.with_index do |cell, col_index|
      dot_spec(cell, row_index, col_index)
    end
  end
end