Class: Abqari::Visualizations
- Inherits:
-
Object
- Object
- Abqari::Visualizations
- Defined in:
- lib/abqari/visualizations.rb
Overview
D3-based data visualizations of your site's content. Off by default —
toggle in config/site.yml under visualizations:. When enabled, abqari
generates per-viz JSON data files and HTML pages at build time. The
viz pages load D3 (vendored at /assets/d3/d3.v7.min.js) and the
corresponding JSON, then render entirely client-side.
Three visualizations ship:
- tag-bubble: circle-pack of tags sized by post count
- tag-cooccurrence: chord diagram of tags that appear together
- topic-constellation: force graph of posts connected by shared tags
Each is independently config-toggleable. When all are off, no JSON is written, no pages are generated, D3 isn't pulled into the asset pipeline.
Constant Summary collapse
- VIZ_NAMES =
%w[tag-bubble tag-cooccurrence topic-constellation].freeze
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #enabled_visualizations ⇒ Object
-
#initialize(site) ⇒ Visualizations
constructor
A new instance of Visualizations.
-
#pages ⇒ Object
Generated VizPage instances — appended to Site's @generated_pages so they go through the normal render pipeline (post-process, minification, incremental check, etc.).
-
#write_data ⇒ Object
Writes the JSON data files.
Constructor Details
#initialize(site) ⇒ Visualizations
Returns a new instance of Visualizations.
23 24 25 |
# File 'lib/abqari/visualizations.rb', line 23 def initialize(site) @site = site end |
Instance Method Details
#enabled? ⇒ Boolean
27 28 29 |
# File 'lib/abqari/visualizations.rb', line 27 def enabled? enabled_visualizations.any? end |
#enabled_visualizations ⇒ Object
31 32 33 34 |
# File 'lib/abqari/visualizations.rb', line 31 def enabled_visualizations config = @site.config['visualizations'] || {} VIZ_NAMES.select { |name| config[name.tr('-', '_')] == true } end |
#pages ⇒ Object
Generated VizPage instances — appended to Site's @generated_pages so they go through the normal render pipeline (post-process, minification, incremental check, etc.).
39 40 41 |
# File 'lib/abqari/visualizations.rb', line 39 def pages enabled_visualizations.map { |name| VizPage.new(name, @site) } end |
#write_data ⇒ Object
Writes the JSON data files. Called from Site#build after pages render.
44 45 46 47 48 |
# File 'lib/abqari/visualizations.rb', line 44 def write_data return unless enabled? enabled_visualizations.each { |name| write_one(name) } end |