Class: Numo::Gnuplot::PlotItem

Inherits:
Object
  • Object
show all
Defined in:
lib/numo/gnuplot.rb

Direct Known Subclasses

SPlotItem

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*items) ⇒ PlotItem

Returns a new instance of PlotItem.



690
691
692
# File 'lib/numo/gnuplot.rb', line 690

def initialize(*items)
  @items = items
end

Class Method Details

.is_data(a) ⇒ Object

:nodoc: all



671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/numo/gnuplot.rb', line 671

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



694
695
696
# File 'lib/numo/gnuplot.rb', line 694

def <<(item)
  @items << item
end

#cmd_strObject



758
759
760
761
762
763
764
765
# File 'lib/numo/gnuplot.rb', line 758

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_strObject



767
768
769
770
771
772
773
774
# File 'lib/numo/gnuplot.rb', line 767

def data_str
  parse_items
  if @function
    nil
  else
    @data.data_str
  end
end

#empty?Boolean

Returns:

  • (Boolean)


698
699
700
# File 'lib/numo/gnuplot.rb', line 698

def empty?
  @items.empty?
end

#parse_data(data) ⇒ Object



754
755
756
# File 'lib/numo/gnuplot.rb', line 754

def parse_data(data)
  parse_data_style(data) || PlotData.new(*data)
end

#parse_data_style(data) ⇒ Object



741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/numo/gnuplot.rb', line 741

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_itemsObject



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
737
738
739
# File 'lib/numo/gnuplot.rb', line 702

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