Rework output API
Now you give the data at the creation of the object to render it later. So you need to create a new output object for every new set of data.
This commit is contained in:
parent
2bb29d9e8d
commit
66b2becebd
|
@ -52,8 +52,7 @@ module Rubella
|
|||
# @return binaryblob An output representation of the heatmap
|
||||
def process inpt
|
||||
weight = @weighting.new 10
|
||||
outpt = @output.new
|
||||
outpt.create weight.parse(inpt)
|
||||
@output.new(weight.parse(inpt)).render
|
||||
end
|
||||
|
||||
# Set the input type by the given name
|
||||
|
|
|
@ -23,10 +23,11 @@ module Rubella
|
|||
# Also sets the used ascii art theme to "shades_ascii". See the
|
||||
# used_symbols= for further information.
|
||||
#
|
||||
# @param data Rubella::Storage
|
||||
# @param field_size int Used chars for one value
|
||||
# @return Rubella::Output::ASCII
|
||||
#
|
||||
def initialize field_size = 1
|
||||
def initialize data, field_size = 1
|
||||
@symbols = Hash.new
|
||||
@symbols["shades"] =
|
||||
[" ", " ", "░", "░", "▒", "▒", "▓", "▓", "█", "█"]
|
||||
|
@ -38,7 +39,7 @@ module Rubella
|
|||
[" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
||||
|
||||
self.used_symbols = "shades_ascii"
|
||||
super field_size
|
||||
super data, field_size
|
||||
end
|
||||
|
||||
# Sets the used ascii theme by the given name.
|
||||
|
@ -61,14 +62,13 @@ module Rubella
|
|||
@symbols.keys.join(", ")
|
||||
end
|
||||
|
||||
# Creates an ascii art representation of the given storage data.
|
||||
# Creates an ascii art representation.
|
||||
#
|
||||
# @param storage Rubella::Storage
|
||||
# @return Rubella::Storage::ASCII
|
||||
# @return String
|
||||
#
|
||||
def create storage
|
||||
buckets = storage.data[0].length
|
||||
# columns = storage.data.length
|
||||
def render
|
||||
buckets = @data.data[0].length
|
||||
# columns = @data.data.length
|
||||
|
||||
# image size
|
||||
# x = columns*@field_size
|
||||
|
@ -78,7 +78,7 @@ module Rubella
|
|||
ascii_arr = []
|
||||
0.upto(buckets-1).each { |i| ascii_arr[i] = "" }
|
||||
|
||||
storage.data.each do |point|
|
||||
@data.data.each do |point|
|
||||
i = 0
|
||||
point.reverse.each do |part|
|
||||
part = (part*10).to_i
|
||||
|
@ -94,8 +94,7 @@ module Rubella
|
|||
end
|
||||
end
|
||||
|
||||
@data = ascii_arr.join("\n")
|
||||
self
|
||||
ascii_arr.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,28 +8,27 @@ module Rubella
|
|||
#
|
||||
class Base
|
||||
attr_accessor :field_size
|
||||
attr_reader :data
|
||||
|
||||
# Constructor
|
||||
# Gets the field size to store it local. It's the size of one value of
|
||||
# the later created visual representation. The unit depends on the kind
|
||||
# of representation.
|
||||
#
|
||||
# @param data Rubella::Storage
|
||||
# @param field_size int size of one value
|
||||
# @return Rubella::Output::Base
|
||||
#
|
||||
def initialize field_size
|
||||
def initialize data, field_size
|
||||
@data = data
|
||||
@field_size = field_size
|
||||
end
|
||||
|
||||
# Creates a visual representation of the data in the given storage and
|
||||
# stores this local.
|
||||
# Creates a visual representation.
|
||||
#
|
||||
# @param storage Rubella::Storage
|
||||
# @return Rubella::Output::Base
|
||||
# @return rendered data
|
||||
#
|
||||
def create storage
|
||||
raise NotImplementedError "Please override 'create' in your concrete "+
|
||||
def render
|
||||
raise NotImplementedError "Please override 'render' in your concrete "+
|
||||
"implementation"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,31 +15,31 @@ module Rubella
|
|||
# Constructor
|
||||
# Has a default field_size of 15 pixel.
|
||||
#
|
||||
# @param data Rubella::Storage
|
||||
# @param field_size int How many pixel one value has
|
||||
# @return Rubella::Output::Image
|
||||
#
|
||||
def initialize field_size = 15
|
||||
super field_size
|
||||
def initialize data, field_size = 15
|
||||
super data, field_size
|
||||
end
|
||||
|
||||
# Creates a pixel based graphic from the given storage data.
|
||||
# Creates a pixel based graphic.
|
||||
#
|
||||
# @param storage Rubella::Storage
|
||||
# @return Rubella::Output::Image
|
||||
# @return RMagick::Image
|
||||
#
|
||||
def create storage
|
||||
buckets = storage.data[0].length
|
||||
columns = storage.data.length
|
||||
def render
|
||||
buckets = @data.data[0].length
|
||||
columns = @data.data.length
|
||||
|
||||
# image size
|
||||
x = columns*@field_size
|
||||
y = buckets*@field_size
|
||||
|
||||
# start drawing the damn thing
|
||||
@data = Magick::Image.new(x, y) { self.background_color = "white" }
|
||||
image = Magick::Image.new(x, y) { self.background_color = "white" }
|
||||
|
||||
i = 0
|
||||
storage.data.each do |point|
|
||||
@data.data.each do |point|
|
||||
j = 0
|
||||
point.reverse.each do |part|
|
||||
# draw a red rectangle on the white background
|
||||
|
@ -55,13 +55,13 @@ module Rubella
|
|||
# Draw
|
||||
core.fill(Magick::Pixel.from_hsla(0, 255, l, 1).to_color)
|
||||
core.rectangle((i*@field_size), (j*@field_size), ((i+1)*@field_size), ((j+1)*@field_size))
|
||||
core.draw @data
|
||||
core.draw image
|
||||
j = j + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
self
|
||||
image
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue