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.
700 701 702 |
# File 'lib/numo/gnuplot.rb', line 700 def initialize(*items) @items = items end |
Class Method Details
.is_data(a) ⇒ Object
:nodoc: all
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/numo/gnuplot.rb', line 670 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 end if defined?(Numo::NArray) return true if a.kind_of?(Numo::NArray) end if defined?(::NArray) return true if a.kind_of?(::NArray) end if defined?(::NMatrix) return true if a.kind_of?(::NMatrix) end case a[a.size-1] # quick check for unknown data class when Numeric return true if a[0].kind_of?(Numeric) when String return true if a[0].kind_of?(String) end false rescue false end |
Instance Method Details
#<<(item) ⇒ Object
704 705 706 |
# File 'lib/numo/gnuplot.rb', line 704 def <<(item) @items << item end |
#cmd_str ⇒ Object
768 769 770 771 772 773 774 775 |
# File 'lib/numo/gnuplot.rb', line 768 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
777 778 779 780 781 782 783 784 |
# File 'lib/numo/gnuplot.rb', line 777 def data_str parse_items if @function nil else @data.data_str end end |
#empty? ⇒ Boolean
708 709 710 |
# File 'lib/numo/gnuplot.rb', line 708 def empty? @items.empty? end |
#parse_data(data) ⇒ Object
764 765 766 |
# File 'lib/numo/gnuplot.rb', line 764 def parse_data(data) parse_data_style(data) || PlotData.new(*data) end |
#parse_data_style(data) ⇒ Object
751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/numo/gnuplot.rb', line 751 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
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 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'lib/numo/gnuplot.rb', line 712 def parse_items if !@options if @items.empty? return elsif @items.first.kind_of?(String) || @items.first.kind_of?(Symbol) @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.quote(@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 |