Class: Renalware::Pathology::SparklineComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Renalware::Pathology::SparklineComponent
- Defined in:
- app/components/renalware/pathology/sparkline_component.rb
Overview
Renders a pathology sparkline - a small graph of patient results for a particular OBX (observation_description) over time. TODO: Move the graph config into JS. Possibly use a stimulus controller
Constant Summary collapse
- CHART_OPTIONS =
{ library: { chart: { type: "area", margin: [0, 0, 0, 0], height: 20, width: 80, skipClone: true, style: { overflow: "visible" } }, credits: { enabled: false }, title: "", xAxis: { type: "datetime", tickPositions: [], labels: { enabled: false }, startOnTick: false, endOnTick: false, title: { text: nil } }, legend: { enabled: false }, yAxis: { tickPositions: [0], endOnTick: false, startOnTick: false, title: { text: nil }, min: 0, labels: { enabled: false } }, tooltip: { hideDelay: 0, outside: true, shared: true, xDateFormat: "%d-%b-%Y" }, plotOptions: { area: { fillColor: { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, stops: [ [0, "#eee"], [0.5, "#fff"] ] } }, series: { animation: false, lineWidth: 1, shadow: false, states: { hover: { lineWidth: 1 } }, marker: { radius: 1, states: { hover: { radius: 2 } } }, fillOpacity: 0.25 }, column: { negativeColor: "#910000", borderColor: "silver" } } } }.freeze
Instance Method Summary collapse
- #cache_key ⇒ Object
- #chart_data ⇒ Object
- #dom_id ⇒ Object
- #options ⇒ Object
-
#render? ⇒ Boolean
Because we cache the component html inside the view sidecar, we want to avoid implementing this method properly - ie checking if there anything to render - as that would involve querying the database, thus negating the befit of any caching.
Methods inherited from ApplicationComponent
Instance Method Details
#cache_key ⇒ Object
113 114 115 |
# File 'app/components/renalware/pathology/sparkline_component.rb', line 113 def cache_key "#{patient.cache_key}/sparkline/#{observation_description.id}" end |
#chart_data ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'app/components/renalware/pathology/sparkline_component.rb', line 103 def chart_data @chart_data ||= begin patient .observations .where(description_id: observation_description.id) .order(:observed_at) .pluck([:observed_at, :result]) end end |
#dom_id ⇒ Object
129 130 131 |
# File 'app/components/renalware/pathology/sparkline_component.rb', line 129 def dom_id @dom_id ||= ActionView::RecordIdentifier.dom_id(observation_description) end |
#options ⇒ Object
125 126 127 |
# File 'app/components/renalware/pathology/sparkline_component.rb', line 125 def CHART_OPTIONS end |
#render? ⇒ Boolean
Because we cache the component html inside the view sidecar, we want to avoid implementing this method properly - ie checking if there anything to render - as that would involve querying the database, thus negating the befit of any caching.
121 122 123 |
# File 'app/components/renalware/pathology/sparkline_component.rb', line 121 def render? true end |