Class: GraphKit::AxisKit
- Inherits:
-
KitHash
show all
- Includes:
- Log
- Defined in:
- lib/graphkit.rb,
lib/graphkit/gnuplot.rb
Constant Summary
collapse
- AXES =
GraphKit::AXES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KitHash
from_hash, #inspect
Methods included from Kit
#check, #method_missing
Methods inherited from Hash
#modify
Constructor Details
#initialize(hash = {}) ⇒ AxisKit
attr_accessor :labels, :ranges, :has_legend, :units, :dimensions
700
701
702
703
704
705
706
|
# File 'lib/graphkit.rb', line 700
def initialize(hash = {})
super()
self.title = ""
self.units = ""
self.
absorb hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Kit
Class Method Details
.autocreate(hash) ⇒ Object
720
721
722
723
724
|
# File 'lib/graphkit.rb', line 720
def self.autocreate(hash)
new_kit = new(hash)
new_kit.label = "#{new_kit.title} (#{new_kit.units})"
new_kit
end
|
Instance Method Details
#check_integrity ⇒ Object
708
709
710
711
|
# File 'lib/graphkit.rb', line 708
def check_integrity
check(['units.class', [String]], ['scaling.class', [Float, NilClass]], ['label.class', [String, NilClass]], ['title.class', [String]])
check(['data.to_a.class', Array])
end
|
#data_for_gnuplot(rank) ⇒ Object
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
# File 'lib/graphkit/gnuplot.rb', line 323
def data_for_gnuplot(rank)
case rank
when 0, 1
return data
when Fixnum
if shape.size == 1
return SparseTensor.diagonal(rank, data)
else
return data
end
else
raise TypeError("Bad Rank")
end
end
|
#dup ⇒ Object
713
714
715
716
717
718
|
# File 'lib/graphkit.rb', line 713
def dup
new = self.class.new(self)
new.data = data.dup
new
end
|
#extend_using(other) ⇒ Object
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
# File 'lib/graphkit.rb', line 755
def extend_using(other)
raise TypeError.new("Can only extend axes if data have the same ranks: #{shape.size}, #{other.shape.size}") unless shape.size == other.shape.size
raise TypeError.new("Can only extend axes if data have the same class") unless data.class == other.data.class
case shape.size
when 1
desired_length = shape[0] + other.shape[0]
if data.methods.include? :connect
self.data = data.connect(other.data)
elsif data.methods.include? "+".to_sym
data += other
else
raise TypeError("Extending this type of data is currently not implemented.")
end
raise "Something went wrong: the length of the extended data #{shape[0]} is not the sum of the lengths of the two original pieces of data #{desired_length}." unless shape[0] == desired_length
else
raise TypeError("Extending data with this rank: #{shape.size} is currently not implemented.")
end
end
|
#shape ⇒ Object
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
# File 'lib/graphkit.rb', line 726
def shape
logf :shape
if data.methods.include? :shape
ans = data.shape
elsif data.methods.include? :size
ans = [data.size]
elsif data.methods.include? :dimensions
ans = data.dimensions
else
raise 'data does not implement size or shape or dimensions methods'
end
logfc :shape
return ans
end
|