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



851
852
853
854
855
856
857
# File 'lib/graphkit.rb', line 851

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



871
872
873
874
875
# File 'lib/graphkit.rb', line 871

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



859
860
861
862
# File 'lib/graphkit.rb', line 859

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



864
865
866
867
868
869
# File 'lib/graphkit.rb', line 864

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

#extend_using(other) ⇒ Object

end

Raises:

  • (TypeError)


906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'lib/graphkit.rb', line 906

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



877
878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/graphkit.rb', line 877

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