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.



640
641
642
# File 'lib/numo/gnuplot.rb', line 640

def initialize(*items)
  @items = items
end

Class Method Details

.is_data(a) ⇒ Object

:nodoc: all



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/numo/gnuplot.rb', line 621

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



644
645
646
# File 'lib/numo/gnuplot.rb', line 644

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

#cmd_strObject



688
689
690
691
692
693
694
695
# File 'lib/numo/gnuplot.rb', line 688

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



697
698
699
700
701
702
703
704
# File 'lib/numo/gnuplot.rb', line 697

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

#empty?Boolean

Returns:

  • (Boolean)


648
649
650
# File 'lib/numo/gnuplot.rb', line 648

def empty?
  @items.empty?
end

#parse_data(data) ⇒ Object



684
685
686
# File 'lib/numo/gnuplot.rb', line 684

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

#parse_itemsObject



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/numo/gnuplot.rb', line 652

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
        end
      end
      if data.empty?
        @function = ''
      else
        @data = parse_data(data)
      end
    end
  end
end