Class: GraphKit::AxisKit

Inherits:
KitHash show all
Includes:
Log
Defined in:
lib/graphkit.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



827
828
829
830
831
832
833
# File 'lib/graphkit.rb', line 827

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



847
848
849
850
851
# File 'lib/graphkit.rb', line 847

def self.autocreate(hash)
  new_kit = new(hash)
  new_kit.label = "#{new_kit.title} (#{new_kit.units})"
  new_kit
end

Instance Method Details

#check_integrityObject



835
836
837
838
# File 'lib/graphkit.rb', line 835

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

#dupObject



840
841
842
843
844
845
# File 'lib/graphkit.rb', line 840

def dup
#     puts 'i was called'
  new = self.class.new(self)
  new.data = data.dup
  new
end

#extend_using(other) ⇒ Object

end

Raises:

  • (TypeError)


882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/graphkit.rb', line 882

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

#shapeObject



853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'lib/graphkit.rb', line 853

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