Class: Numo::Gnuplot::PlotItem
- Inherits:
-
Object
- Object
- Numo::Gnuplot::PlotItem
- Defined in:
- lib/numo/gnuplot.rb
Direct Known Subclasses
Class Method Summary collapse
-
.is_data(a) ⇒ Object
:nodoc: all.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #cmd_str ⇒ Object
- #data_str ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(*items) ⇒ PlotItem
constructor
A new instance of PlotItem.
- #parse_data(data) ⇒ Object
- #parse_data_style(data) ⇒ Object
- #parse_items ⇒ Object
Constructor Details
#initialize(*items) ⇒ PlotItem
Returns a new instance of PlotItem.
687 688 689 |
# File 'lib/numo/gnuplot.rb', line 687 def initialize(*items) @items = items end |
Class Method Details
.is_data(a) ⇒ Object
:nodoc: all
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/numo/gnuplot.rb', line 668 def self.is_data(a) if a.kind_of? Array if a.last.kind_of?(Hash) return false else t = a.first.class t = Numeric if t < Numeric return a.all?{|e| e.kind_of?(t)} end elsif defined?(Numo::NArray) return true if a.kind_of?(Numo::NArray) elsif defined?(::NArray) return true if a.kind_of?(::NArray) elsif defined?(::NMatrix) return true if a.kind_of?(::NMatrix) end false end |
Instance Method Details
#<<(item) ⇒ Object
691 692 693 |
# File 'lib/numo/gnuplot.rb', line 691 def <<(item) @items << item end |
#cmd_str ⇒ Object
755 756 757 758 759 760 761 762 |
# File 'lib/numo/gnuplot.rb', line 755 def cmd_str parse_items if @function "%s %s" % [@function, OptArg.parse(*@options)] else "%s %s" % [@data.cmd_str, OptArg.parse(*@options)] end end |
#data_str ⇒ Object
764 765 766 767 768 769 770 771 |
# File 'lib/numo/gnuplot.rb', line 764 def data_str parse_items if @function nil else @data.data_str end end |
#empty? ⇒ Boolean
695 696 697 |
# File 'lib/numo/gnuplot.rb', line 695 def empty? @items.empty? end |
#parse_data(data) ⇒ Object
751 752 753 |
# File 'lib/numo/gnuplot.rb', line 751 def parse_data(data) parse_data_style(data) || PlotData.new(*data) end |
#parse_data_style(data) ⇒ Object
738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'lib/numo/gnuplot.rb', line 738 def parse_data_style(data) if @style re = /^#{@style}/ if re =~ "image" return ImageData.new(*data) elsif re =~ "rgbimage" return RgbImageData.new(*data) elsif re =~ "rgbalpha" return RgbAlphaData.new(*data) end end end |
#parse_items ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/numo/gnuplot.rb', line 699 def parse_items if !@options if @items.empty? return elsif @items.first.kind_of? String @function = @items.first @options = @items[1..-1] if (o=@items.last).kind_of? Hash if o.any?{|k,v| /^#{k}/ =~ "using"} # @function is data file @function = OptArg.squote(@function) end end else data = [] @options = [] @items.each do |x| if PlotItem.is_data(x) data << x else @options << x if x.kind_of? Hash x.each do |k,v| if /^#{k}/ =~ "with" @style = v; break; end end end end end if data.empty? @function = '' else @data = parse_data(data) end end end end |