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
3 changes: 1 addition & 2 deletions lib/text_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def size_config(key)

SIZE_CONFIG = {
y_axis_width: 1,
bar_margin: 3,
bar_margin: 1,
bar_width: 3,
reference_and_y_axis_margin: 1,
x_axis_height: 1,
reference_row_height: 1
}
Expand Down
3 changes: 1 addition & 2 deletions lib/text_chart/designer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ def draw_references
width = @size_calc.calculate_reference_width
number_of_references = references.size
ref_size = ref_start = ref_end = nil
margin_size = @text_chart.size_config(:reference_and_y_axis_margin)

number_of_references.times do |i|
ref_size = references[i].size

if ref_size == (width - margin_size)
if ref_size == width
ref_start = 0
ref_end = ref_size - 1
@chart_canvas[i][ref_start..ref_end] = references[i]
Expand Down
3 changes: 1 addition & 2 deletions lib/text_chart/size_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def calculate_reference_width
@reference_width ||=
begin
biggest_number_size = @text_chart.data.map(&:to_s).map(&:size).max
reference_margin = @text_chart.size_config(:reference_and_y_axis_margin)
biggest_number_size + reference_margin
biggest_number_size
end
end

Expand Down
168 changes: 84 additions & 84 deletions test/text_chart/designer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class TextChart::DesignerTest < Test::Unit::TestCase
This is a nice title
This is a nice subtitle



EXPECTED
end

Expand All @@ -29,47 +29,47 @@ class TextChart::DesignerTest < Test::Unit::TestCase
with_negative_number_result = with_negative_number.draw_axis.join

assert_equal no_sample_result, <<~END
0 |
----------
0|
------
END

assert_equal small_sample_result, <<~END
10 |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
----------------------------------------------------------------
10|
9|
8|
7|
6|
5|
4|
3|
2|
1|
------------------------------------------
END

assert_equal with_gaps_result, <<~END
10 |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
----------------------
10|
9|
8|
7|
6|
5|
4|
3|
2|
1|
--------------
END

assert_equal with_negative_number_result, <<~END
3 |
2 |
1 |
0 |
-1 |
-2 |
-3 |
----------------------------------------------
3|
2|
1|
0|
-1|
-2|
-3|
------------------------------
END
end

Expand All @@ -95,68 +95,68 @@ class TextChart::DesignerTest < Test::Unit::TestCase
negative_result = negative.draw_bars.join

assert_equal sorted_result, <<-END
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''###
'''''''''''''''''''''''''''''''''''''''''''''''''''### ###
'''''''''''''''''''''''''''''''''''''''''''''### ### ###
'''''''''''''''''''''''''''''''''''''''### ### ### ###
'''''''''''''''''''''''''''''''''### ### ### ### ###
'''''''''''''''''''''''''''### ### ### ### ### ###
'''''''''''''''''''''### ### ### ### ### ### ###
'''''''''''''''### ### ### ### ### ### ### ###
'''''''''### ### ### ### ### ### ### ### ###
'''### ### ### ### ### ### ### ### ### ###
'''''''''''''''''''''''''''''''''''''###
'''''''''''''''''''''''''''''''''### ###
'''''''''''''''''''''''''''''### ### ###
'''''''''''''''''''''''''### ### ### ###
'''''''''''''''''''''### ### ### ### ###
'''''''''''''''''### ### ### ### ### ###
'''''''''''''### ### ### ### ### ### ###
'''''''''### ### ### ### ### ### ### ###
'''''### ### ### ### ### ### ### ### ###
'### ### ### ### ### ### ### ### ### ###

END

assert_equal random_order_result, <<-END
'''''''''###
'''''''''###'''''''''''''''''''''''''''''''''''''''###
'''''''''###'''''''''''''''''''''''''''''''''### ###
'''''''''###'''### ### ###
'''''''''###'''###'''''''''''''''''''''''''''###'''###'''###
'''''''''###'''###'''### ### ### ###
'''''''''###'''###'''###'''''''''### ### ### ###
'''### ### ### ### ### ### ### ###
'''###'''###'''###'''###'''''''''###'''### ### ### ###
'''###'''###'''###'''###'''### ### ### ### ### ###
'''''###
'''''###'''''''''''''''''''''''''###
'''''###'''''''''''''''''''''### ###
'''''###'### ### ###
'''''###'###'''''''''''''''''###'###'###
'''''###'###'### ### ### ###
'''''###'###'###'''''### ### ### ###
'### ### ### ### ### ### ### ###
'###'###'###'###'''''###'### ### ### ###
'###'###'###'###'### ### ### ### ### ###

END

assert_equal with_zero_result, <<-END
'''''''''''''''''''''''''''''''''###
'''''''''''''''### ###
'''''''''''''''###'''''''''### ###
'''### ### ### ###
'''###'''### ### ### ###
'''###'''###'''###'''### ### ###
'''''''''''''''''''''###
'''''''''### ###
'''''''''###'''''### ###
'### ### ### ###
'###'### ### ### ###
'###'###'###'### ### ###

END

assert_equal gaps_result, <<-END
'''''''''''''''###
###
###
###
###
###
'''''''''''''''###'''''''''###
### ###
### ###
'''### ### ###
'''###'''### ### ###
'''###'''###'''###'''### ###
'''''''''###
###
###
###
###
###
'''''''''###'''''###
### ###
### ###
'### ### ###
'###'### ### ###
'###'###'###'### ###

END

assert_equal negative_result, <<-END
'''###
'''###'''''''''''''''''''''''''''''''''###
'''###'''''''''''''''''''''### ###
'''###'''''''''''''''''''''###'''### ###
'''###'''### ### ### ###
'''###'''###'''### ### ### ###
'''###'''###'''###'''### ### ### ###
'###
'###'''''''''''''''''''''###
'###'''''''''''''### ###
'###'''''''''''''###'### ###
'###'### ### ### ###
'###'###'### ### ### ###
'###'###'###'### ### ### ###

END
end
end
98 changes: 49 additions & 49 deletions test/text_chart/size_calculator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class TextChart::SizeCalculatorTest < Test::Unit::TestCase
big_sample_result = big_sample.calculate_reference_width
with_negative_number_result = with_negative_number.calculate_reference_width

assert_equal no_sample_result, 2
assert_equal small_sample_result, 3
assert_equal medium_sample_result, 4
assert_equal big_sample_result, 5
assert_equal with_negative_number_result, 4
assert_equal no_sample_result, 1
assert_equal small_sample_result, 2
assert_equal medium_sample_result, 3
assert_equal big_sample_result, 4
assert_equal with_negative_number_result, 3
end

test "#calculate_number_of_rows" do
Expand All @@ -31,22 +31,22 @@ class TextChart::SizeCalculatorTest < Test::Unit::TestCase
small_sample_result = small_sample.calculate_number_of_rows

# Example:
# 0 | 1
# ---------- 2
# 0| 1
# ------ 2
assert_equal no_sample_result, 2

# Example:
# 10 | 1
# 9 | 2
# 8 | 3
# 7 | 4
# 6 | 5
# 5 | 6
# 4 | 7
# 3 | 8
# 2 | 9
# 1 | 10
# ------- 11
# 10| 1
# 9| 2
# 8| 3
# 7| 4
# 6| 5
# 5| 6
# 4| 7
# 3| 8
# 2| 9
# 1| 10
# ------ 11
assert_equal small_sample_result, 11
end

Expand All @@ -58,20 +58,20 @@ class TextChart::SizeCalculatorTest < Test::Unit::TestCase
small_sample_result = small_sample.calculate_number_of_columns

# Example:
# 0 |
# ----------
# cccccccccccc = 12
assert_equal no_sample_result, 12
# 0|
# ------
# ccccccc = 7
assert_equal no_sample_result, 7

# Example:
# 10 |
# 10|
# .
# .
# .
# 2 | ### ### ### ### ### ### ### ### ### ###
# ---------------------------------------------------------------
# cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = 67
assert_equal small_sample_result, 67
# 2| ### ### ### ### ### ### ### ### ### ###
# ------------------------------------------
# cccccccccccccccccccccccccccccccccccccccccccc = 44
assert_equal small_sample_result, 44
end

test "#calculate_x_axis_size" do
Expand All @@ -82,20 +82,20 @@ class TextChart::SizeCalculatorTest < Test::Unit::TestCase
small_sample_result = small_sample.calculate_x_axis_size

# Example:
# 0 |
# ----------
# xxxxxxxxxx = 10
assert_equal no_sample_result, 10
# 0|
# ------
# cccccc = 6
assert_equal no_sample_result, 6

# Example:
# 10 |
# 10|
# .
# .
# .
# 2 | ### ### ### ### ### ### ### ### ### ###
# ----------------------------------------------------------------
# cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = 64
assert_equal small_sample_result, 64
# 2| ### ### ### ### ### ### ### ### ### ###
# ------------------------------------------
# cccccccccccccccccccccccccccccccccccccccccc = 42
assert_equal small_sample_result, 42
end

test "#calculate_y_axis_size" do
Expand All @@ -106,22 +106,22 @@ class TextChart::SizeCalculatorTest < Test::Unit::TestCase
small_sample_result = small_sample.calculate_y_axis_size

# Example:
# 0 | y = 1
# ----------
# 0| y = 1
# ------
assert_equal no_sample_result, 1

# Example:
# 10 | y
# 9 | y
# 8 | y
# 7 | y
# 6 | y
# 5 | y
# 4 | y
# 3 | y
# 2 | y
# 1 | y = 10
# ----------
# 10| y
# 9| y
# 8| y
# 7| y
# 6| y
# 5| y
# 4| y
# 3| y
# 2| y
# 1| y = 10
# ------
assert_equal small_sample_result, 10
end
end
Loading