Module: RailsPulse::ChartHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/rails_pulse/chart_helper.rb
Instance Method Summary collapse
- #area_chart_options ⇒ Object
- #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
-
#base_chart_options(units: nil, zoom: false) ⇒ Object
Base chart options shared across all chart types.
- #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
-
#render_stimulus_chart(data, type:, **options) ⇒ Object
Main chart rendering method - unified API for all chart types Uses Stimulus controller to handle chart initialization.
- #sparkline_chart_options ⇒ Object
Instance Method Details
#area_chart_options ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 112 def .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
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 59 def (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) = (units: units, zoom: zoom).deep_merge({ series: { itemStyle: { borderRadius: [ 5, 5, 5, 5 ] } } }) apply_tooltip_formatter(, tooltip_formatter) apply_xaxis_formatter(, xaxis_formatter) apply_zoom_configuration(, zoom, zoom_start, zoom_end, chart_data) end |
#base_chart_options(units: nil, zoom: false) ⇒ Object
Base chart options shared across all chart types
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 29 def (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: true } 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 73 def (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) = (units: units, zoom: zoom).deep_merge({ series: { smooth: true, lineStyle: { width: 3 }, symbol: "circle", symbolSize: 8 } }) apply_tooltip_formatter(, tooltip_formatter) apply_xaxis_formatter(, xaxis_formatter) apply_zoom_configuration(, zoom, zoom_start, zoom_end, chart_data) end |
#render_stimulus_chart(data, type:, **options) ⇒ Object
Main chart rendering method - unified API for all chart types Uses Stimulus controller to handle chart initialization
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 5 def render_stimulus_chart(data, type:, **) chart_id = [:id] || "rails-pulse-chart-#{SecureRandom.hex(8)}" height = [:height] || "400px" width = [:width] || "100%" theme = [:theme] || "railspulse" = [:options] || {} # Build data attributes for Stimulus stimulus_data = { controller: "rails-pulse--chart", rails_pulse__chart_type_value: type, rails_pulse__chart_data_value: data.to_json, rails_pulse__chart_options_value: .to_json, rails_pulse__chart_theme_value: theme } content_tag(:div, "", id: chart_id, style: "height: #{height}; width: #{width};", data: stimulus_data ) end |
#sparkline_chart_options ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/rails_pulse/chart_helper.rb', line 90 def # Compact sparkline columns that fill the canvas with no axes/labels/gaps .deep_merge({ series: { type: "bar", itemStyle: { borderRadius: [ 2, 2, 0, 0 ] }, barCategoryGap: "10%", barGap: "0%" }, yAxis: { show: false, splitLine: { show: false } }, xAxis: { type: "category", boundaryGap: true, axisLine: { show: false }, axisTick: { show: false }, splitLine: { show: false }, axisLabel: { show: false } }, grid: { left: 0, right: 0, top: 0, bottom: 0, containLabel: false, show: false } }) end |