Skip to content

Commit 57647a7

Browse files
committed
tidy up
1 parent 9d47ad2 commit 57647a7

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

external_library/java/grafica/default_plot.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12

23
require 'picrate'
34

@@ -14,24 +15,19 @@ def settings
1415
def setup
1516
sketch_title 'default plot'
1617
background(150)
17-
1818
# Prepare the points for the plot
1919
points = GPointsArray.new(POINTS)
20-
2120
POINTS.times do |i|
2221
points.add(i, 10 * noise(0.1 * i))
2322
end
24-
2523
# Create a new plot and set its position on the screen
2624
plot = GPlot.new(self)
2725
plot.set_pos(25, 25)
28-
2926
# Set the plot title and the axis labels
3027
plot.set_points(points)
31-
plot.getXAxis.setAxisLabelText("x axis")
32-
plot.getYAxis.setAxisLabelText("y axis")
33-
plot.setTitleText("A very simple example")
34-
28+
plot.getXAxis.set_axis_label_text('x axis')
29+
plot.getYAxis.set_axis_label_text('y axis')
30+
plot.set_title_text('A very simple example')
3531
# Draw it!
3632
plot.default_draw
3733
end

external_library/java/grafica/oktoberfest_example.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
# frozen_string_literal: true
12

23
require 'picrate'
34
require 'csv'
4-
5+
# Grafica Sketch
56
class Oktoberfest < Processing::App
6-
77
load_library :grafica
88
java_import 'grafica.GPlot'
99
java_import 'grafica.GPointsArray'
1010

11-
MONTH_NAMES = %w[January February March April May June July August September October November December]
12-
DAYS_PER_MONTH = [31,28,31,30,31,30,31,31,30,31,30,31]
13-
DAYS_PER_MONTH_LEAP_YEAR = [31,29,31,30,31,30,31,31,30,31,30,31]
14-
11+
MONTH_NAMES = %w[
12+
January February March April May June July August September October November
13+
December
14+
].freeze
15+
DAYS_PER_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].freeze
16+
DAYS_PER_MONTH_LEAP_YEAR = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
17+
.freeze
1518
attr_reader :plot, :points_oktoberfest, :points_elections
1619

1720
def settings
@@ -29,23 +32,27 @@ def setup
2932
@points_oktoberfest = GPointsArray.new
3033
@points_elections = GPointsArray.new
3134

32-
CSV.foreach(data_path('OktoberfestVSGermanElections.csv'), headers: true) do |row|
35+
CSV.foreach(
36+
data_path('OktoberfestVSGermanElections.csv'), headers: true
37+
) do |row|
3338
year = row['year'].to_i
3439
month = row['month'].to_i
3540
day = row['day'].to_i
3641
date = get_exact_date(year, month, day)
3742
oktoberfest_count = row['oktoberfest'].to_i
3843
elections_count = row['bundestagswahl'].to_i
39-
points_oktoberfest.add(date, oktoberfest_count, MONTH_NAMES[month])
40-
points_elections.add(date, elections_count, MONTH_NAMES[month])
44+
month_name = MONTH_NAMES[month]
45+
points_oktoberfest.add(date, oktoberfest_count, month_name)
46+
points_elections.add(date, elections_count, month_name)
4147
end
4248
# Create the plot
4349
@plot = GPlot.new(self)
4450
plot.set_dim(700, 300)
4551
plot.set_title_text('Oktoberfest vs. Bundestagwahl Google search history')
46-
plot.getXAxis.set_axis_label_text('Year')
52+
x_axis = plot.getXAxis
53+
x_axis.set_axis_label_text('Year')
4754
plot.getYAxis.set_axis_label_text('Google normalized searches')
48-
plot.getXAxis.setNTicks(10)
55+
x_axis.setNTicks(10)
4956
plot.set_points(points_oktoberfest)
5057
plot.set_line_color(color(100, 100, 100))
5158
plot.add_layer('German elections day', points_elections)
@@ -74,7 +81,8 @@ def draw
7481

7582
def get_exact_date(year, month, day)
7683
leap = (year % 4).zero? && !(year % 100).zero? || (year % 400).zero?
77-
return year + (month + (day - 1)/ DAYS_PER_MONTH[month]) / 12.0 unless leap
84+
return year + (month + (day - 1) / DAYS_PER_MONTH[month]) / 12.0 unless leap
85+
7886
year + (month + (day - 1) / DAYS_PER_MONTH_LEAP_YEAR[month]) / 12.0
7987
end
8088
end

0 commit comments

Comments
 (0)