Class: ActiveCharts::LineChart

Inherits:
XYChart show all
Defined in:
lib/active_charts/line_chart.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

#line_labelsObject (readonly)

Returns the value of attribute line_labels.



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

def line_labels
  @line_labels
end

Instance Method Details

#chart_svg_tagObject



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

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

#dots_specsObject



29
30
31
32
33
34
35
# File 'lib/active_charts/line_chart.rb', line 29

def dots_specs
  (0..columns_count - 1).map do |col_index|
    collection.map.with_index do |row, row_index|
      dot_spec(row[col_index], row_index)
    end
  end
end

#line_label_tagsObject



23
24
25
26
27
# File 'lib/active_charts/line_chart.rb', line 23

def line_label_tags
  dots_specs.flatten.map do |dot| 
    tag.text(dot[:label], x: dot[:cx] + OFFSET, y: dot[:cy] - OFFSET, class: label_classes)
  end
end

#linesObject



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

def lines
  dots_specs.map.with_index do |line_dots, index|
    d = line_dots.map do |dot| 
      [dot[:cx], dot[:cy]].join(' ') 
    end
    
    tag.path('', d: 'M' + d.join(' L '), class: line_classes(index))
  end
end