Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ jobs:
- name: Run tests
run: bundle exec rubocop

RBS:
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
matrix:
ruby-version: ['3.4']
imagemagick-version:
- { full: 7.1.1-33, major-minor: '7.1' }
name: Check RBS (Ruby ${{ matrix.ruby-version }}, ImageMagick ${{ matrix.imagemagick-version.major-minor }})
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Cache ImageMagick
uses: actions/cache@v4
with:
path: ./build-ImageMagick
key: v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
restore-keys: |
v1-linux-imagemagick-${{ matrix.imagemagick-version.full }}
- name: Install ImageMagick ${{ matrix.imagemagick-version.full }}
run: |
export IMAGEMAGICK_VERSION=${{ matrix.imagemagick-version.full }}
./before_install_linux.sh
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@master
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Install dependencies
run: bundle install --path=vendor/bundle --jobs 4 --retry 3
- name: Run tests
run: |
bundle exec rake rbs:update
git --no-pager diff --exit-code
bundle exec steep check

test-ruby:
runs-on: ubuntu-24.04
timeout-minutes: 20
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Layout/ClassStructure:
Layout/FirstMethodArgumentLineBreak:
Enabled: false

Layout/LeadingCommentSpace:
Enabled: false

Layout/LineLength:
Max: 150

Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ gem 'minitest-reporters'
gem 'rake'
gem 'simplecov'
gem 'yard', '~> 0.9.28'

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1') && !RUBY_PLATFORM.include?('java')
gem 'rbs-inline', '~> 0.11'
gem 'steep', '~> 1.10'
end
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ If you have made changes that involve updating the expected image, you need to u
$ bundle exec rake test:image:update
```

If you change the method, you need to update RBS signatures.

```
$ rake rbs:update
```

## Contributing

### Source
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ task default: :test

Rake::TestTask.new

namespace :rbs do
desc 'Update RBS signatures'
task :update do
sh 'bundle exec rbs-inline --output lib'
end
end

namespace :test do
desc 'Update expected image with output'
task :'image:update' do
Expand Down
13 changes: 13 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

D = Steep::Diagnostic

target :lib do
signature 'sig'

check 'lib'

library 'bigdecimal'

configure_code_diagnostics(D::Ruby.lenient)
end
2 changes: 1 addition & 1 deletion gruff.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.authors = ['Geoffrey Grosenbach', 'Uwe Kubosch']
s.description = 'Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.'
s.email = 'boss@topfunky.com'
s.files = `git ls-files`.split.grep_v(/^test|^docker|^before_install_linux.sh|^Rakefile/i)
s.files = `git ls-files`.split.grep_v(/^test|^docker|^before_install_linux.sh|^Rakefile|^Steepfile/i)
s.homepage = 'https://github.com/topfunky/gruff'
s.require_paths = %w[lib]
s.summary = 'Beautiful graphs for one or multiple datasets.'
Expand Down
4 changes: 3 additions & 1 deletion lib/gruff.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# rbs_inline: enabled

require 'rmagick'

require_relative 'gruff/patch/rmagick'
Expand All @@ -16,7 +18,7 @@
module Gruff
# @private
def self.libpath(path)
File.join(__dir__, 'gruff', path)
File.join(__dir__, 'gruff', path) # steep:ignore
end

autoload :BarConversion, Gruff.libpath('helper/bar_conversion')
Expand Down
4 changes: 3 additions & 1 deletion lib/gruff/accumulator_bar.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# rbs_inline: enabled

#
# Gruff::AccumulatorBar is a special bar graph that shows a
# single dataset as a set of stacked bars.
Expand All @@ -19,7 +21,7 @@ class Gruff::AccumulatorBar < Gruff::StackedBar
def setup_data
raise(Gruff::IncorrectNumberOfDatasetsException) unless store.length == 1

accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << (a.last + v.to_f) }
accum_array = store.data.first.points[0..-2].reduce([0]) { |a, v| a << (a.last + v.to_f) } # steep:ignore
data 'Accumulator', accum_array
set_colors
store.reverse!
Expand Down
6 changes: 4 additions & 2 deletions lib/gruff/area.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# rbs_inline: enabled

#
# Gruff::Area provides an area graph which displays graphically
# quantitative data.
Expand All @@ -15,10 +17,10 @@
#
class Gruff::Area < Gruff::Base
# Specifies the filling opacity in area graph. Default is +0.85+.
attr_writer :fill_opacity
attr_writer :fill_opacity #: Float | Integer

# Specifies the stroke width in line around area graph. Default is +2.0+.
attr_writer :stroke_width
attr_writer :stroke_width #: Float | Integer

private

Expand Down
27 changes: 18 additions & 9 deletions lib/gruff/bar.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# rbs_inline: enabled

require_relative 'helper/bar_mixin'

#
Expand All @@ -18,24 +20,24 @@
# g.write('bar.png')
#
class Gruff::Bar < Gruff::Base
include BarMixin
include Gruff::Base::BarMixin

# Spacing factor applied between bars.
attr_writer :bar_spacing
attr_writer :bar_spacing #: Float | Integer

# Spacing factor applied between a group of bars belonging to the same label.
attr_writer :group_spacing
attr_writer :group_spacing #: Float | Integer

# Set the number output format string or lambda.
# Default is +"%.2f"+.
attr_writer :label_formatting
attr_writer :label_formatting #: nil | String | Proc

# Output the values for the bars on a bar graph.
# Default is +false+.
attr_writer :show_labels_for_bar_values
attr_writer :show_labels_for_bar_values #: bool

# Prevent drawing of column labels below a bar graph. Default is +false+.
attr_writer :hide_labels
attr_writer :hide_labels #: bool

# Value to avoid completely overwriting the coordinate axis
AXIS_MARGIN = 0.5
Expand All @@ -47,10 +49,12 @@ class Gruff::Bar < Gruff::Base
# line with no x dimension).
#
# Default value is +0.9+.
#
# @rbs space_percent: Float | Integer
def spacing_factor=(space_percent)
raise ArgumentError, 'spacing_factor must be between 0.00 and 1.00' if (space_percent < 0) || (space_percent > 1)

@spacing_factor = (1 - space_percent)
@spacing_factor = (1.0 - space_percent)
end

private
Expand All @@ -73,14 +77,17 @@ def setup_drawing
super
end

# @rbs return: bool
def hide_labels?
@hide_labels
end

# @rbs return: bool
def hide_left_label_area?
@hide_line_markers && @y_axis_label.nil?
end

# @rbs return: bool
def hide_bottom_label_area?
hide_labels? && @x_axis_label.nil? && @legend_at_bottom == false
end
Expand All @@ -106,7 +113,7 @@ def draw_graph
@bar_spacing ||= @spacing_factor # space between the bars

bar_width = (@graph_width - calculate_spacing) / (column_count * store.length)
padding = (bar_width * (1 - @bar_spacing)) / 2.0
padding = (bar_width * (1.0 - @bar_spacing)) / 2.0

# Setup the BarConversion Object
conversion = Gruff::BarConversion.new(
Expand All @@ -117,7 +124,7 @@ def draw_graph
group_left_x = @graph_left

normalized_group_bars.each_with_index do |group_bars, group_index|
right_x = 0
right_x = 0.0
group_bars.each_with_index do |bar, index|
left_x = group_left_x + (bar_width * index) + padding
right_x = left_x + (bar_width * @bar_spacing)
Expand Down Expand Up @@ -146,10 +153,12 @@ def draw_graph
draw_label(@graph_right, column_count, Magick::NorthWestGravity) if @center_labels_over_point
end

# @rbs return: Float | Integer
def calculate_spacing
@group_spacing * (column_count - 1)
end

# @rbs return: Proc
def proc_text_metrics
->(text) { text_metrics(@marker_font, text) }
end
Expand Down
Loading