From ae3f27fd499c728d28cadecd6276894b6746ce66 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 26 Sep 2018 20:07:57 +0200 Subject: Create own graph type RoomSchedule to get more what I want. Based heavily on the SVG::Graph::Schedule code in the svg-graph gem, adapted and simplified for my use. --- ramaskrik-program.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'ramaskrik-program.rb') diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb index c9044ef..3a84982 100644 --- a/ramaskrik-program.rb +++ b/ramaskrik-program.rb @@ -17,7 +17,7 @@ require 'date' require 'nokogiri' require 'open-uri' -require 'SVG/Graph/Schedule' +require 'room-schedule' class Movie attr_reader :title, :start_time, :end_time, :venue @@ -33,30 +33,23 @@ class Movie def to_s "#{title} #{start_time} - #{end_time}, #{venue}" end - - def triplet - [@title, @start_time.strftime("%d.%m.%Y %H:%M"), @end_time.strftime("%d.%m.%Y %H:%M")] - end end doc = Nokogiri::HTML(open("program.html")) ## open("https://ramaskrik.no/program/")) movies = doc.css(".kultur-type-movie").map { |movie| Movie.new(movie) } days = movies.group_by { |movie| movie.start_time.strftime("%A %d.%m.%Y") } days.each do |d, movies| - graph = SVG::Graph::Schedule.new({ + graph = SVG::Graph::RoomSchedule.new({ graph_title: d, show_graph_title: true, show_x_guidelines: true, width: 1024, - key: false, x_label_format: "%H:%M", timescale_divisions: "30 minutes", }) - venues = movies.group_by { |m| m.venue } - venues.each do |v, m| - data = m.flat_map { |m| m.triplet } - graph.add_data({ title: v, data: data }) + movies.group_by { |m| m.venue }.each do |title, data| + graph.add_data(title: title, data: data) end IO.write("#{d}-program.svg", graph.burn()) -- cgit v1.2.3