Module: RailsPulse::ChartHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/rails_pulse/chart_helper.rb

Instance Method Summary collapse

Instance Method Details

#area_chart_optionsObject



79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/rails_pulse/chart_helper.rb', line 79

def area_chart_options
  base_chart_options.deep_merge({
    series: {
      smooth: true,
      lineStyle: { width: 3 },
      symbol: "roundRect",
      symbolSize: 8
    }
  })
end

#bar_chart_options(units: nil, zoom: false, chart_start: 0, chart_end: 100, xaxis_formatter: nil, tooltip_formatter: nil, zoom_start: nil, zoom_end: nil, chart_data: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/rails_pulse/chart_helper.rb', line 34

def bar_chart_options(units: nil, zoom: false, chart_start: 0, chart_end: 100, xaxis_formatter: nil, tooltip_formatter: nil, zoom_start: nil, zoom_end: nil, chart_data: nil)
  options = base_chart_options(units: units, zoom: zoom).deep_merge({
    series: {
      itemStyle: { borderRadius: [ 5, 5, 5, 5 ] }
    }
  })

  apply_tooltip_formatter(options, tooltip_formatter)
  apply_xaxis_formatter(options, xaxis_formatter)
  apply_zoom_configuration(options, zoom, zoom_start, zoom_end, chart_data)

  options
end

#base_chart_options(units: nil, zoom: false) ⇒ Object

Base chart options shared across all chart types



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/rails_pulse/chart_helper.rb', line 4

def base_chart_options(units: nil, zoom: false)
  {
    tooltip: {
      trigger: "axis",
      axisPointer: { type: "shadow" }
    },
    toolbox: {
      feature: { saveAsImage: { show: false } }
    },
    xAxis: {
      axisLine: { show: false },
      axisTick: { show: false }
    },
    yAxis: {
      splitArea: { show: false },
      axisLabel: {
        formatter: "{value} #{units}"
      }
    },
    grid: {
      left: "0",
      right: "2%",
      bottom: (zoom ? "60" : "0"),
      top: "10%",
      containLabel: true
    },
    animation: false
  }
end

#line_chart_options(units: nil, zoom: false, chart_start: 0, chart_end: 100, xaxis_formatter: nil, tooltip_formatter: nil, zoom_start: nil, zoom_end: nil, chart_data: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/rails_pulse/chart_helper.rb', line 48

def line_chart_options(units: nil, zoom: false, chart_start: 0, chart_end: 100, xaxis_formatter: nil, tooltip_formatter: nil, zoom_start: nil, zoom_end: nil, chart_data: nil)
  options = base_chart_options(units: units, zoom: zoom).deep_merge({
    series: {
      smooth: true,
      lineStyle: { width: 3 },
      symbol: "circle",
      symbolSize: 8
    }
  })

  apply_tooltip_formatter(options, tooltip_formatter)
  apply_xaxis_formatter(options, xaxis_formatter)
  apply_zoom_configuration(options, zoom, zoom_start, zoom_end, chart_data)

  options
end

#sparkline_chart_optionsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/rails_pulse/chart_helper.rb', line 65

def sparkline_chart_options
  base_chart_options.deep_merge({
    series: {
      type: "line",
      smooth: true,
      lineStyle: { width: 2 },
      symbol: "none"
    },
    yAxis: { show: false },
    xAxis: { splitLine: { show: false } },
    grid: { show: false }
  })
end