lib/tty/pie.rb in tty-pie-0.3.0 vs lib/tty/pie.rb in tty-pie-0.4.0
- old
+ new
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require 'pastel'
-require 'tty-cursor'
+require "pastel"
+require "tty-cursor"
-require_relative 'pie/data_item'
-require_relative 'pie/version'
+require_relative "pie/data_item"
+require_relative "pie/version"
module TTY
class Pie
FULL_CIRCLE_DEGREES = 360
- POINT_SYMBOL = '•'
+ POINT_SYMBOL = "•"
LEGEND_LINE_SPACE = 1
LEGEND_LEFT_SPACE = 4
@@ -33,11 +33,11 @@
attr_reader :legend
# Create pie chart
#
# @example
- # data = [ { name: 'BTC', value: 5977, fill: '*' } ]
+ # data = [ { name: "BTC", value: 5977, fill: "*" } ]
# pie_chart = TTY::Pie.new(data: data, radius: 2)
#
# @param [Array[Hash]] data
# the data to display in each slice
# @param [Integer] top
@@ -118,11 +118,11 @@
# @return [String]
#
# @api public
def render
items = data_items
- return '' if items.empty?
+ return "" if items.empty?
angles = data_angles(items)
output = []
labels = items.map { |item| item.to_label(legend) }
label_vert_space = legend_line
@@ -133,11 +133,11 @@
(-radius..radius).each do |y|
width = (Math.sqrt(radius * radius - y * y) * aspect_ratio).round
width = width.zero? ? (radius / aspect_ratio).round : width
- output << ' ' * (center_x - width) if top.nil?
+ output << " " * (center_x - width) if top.nil?
(-width..width).each do |x|
angle = radian_to_degree(Math.atan2(x, y))
item = items[select_data_item(angle, angles)]
if !top.nil?
output << cursor.move_to(center_x + x, center_y + y)
@@ -153,10 +153,10 @@
if !top.nil?
output << cursor.move_to(center_x + aspect_ratio * radius + label_horiz_space, center_y + y)
end
if labels_range.include?(y)
if top.nil?
- output << ' ' * ((center_x - (left.to_i + width)) + label_horiz_space)
+ output << " " * ((center_x - (left.to_i + width)) + label_horiz_space)
end
output << labels[label_offset + y / label_vert_space]
end
end