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.



427
428
429
# File 'lib/numo/gnuplot.rb', line 427

def initialize(*items)
  @items = items
end

Class Method Details

.is_data(a) ⇒ Object

:nodoc: all



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/numo/gnuplot.rb', line 408

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?(::NMatix)
  end
  false
end

Instance Method Details

#<<(item) ⇒ Object



431
432
433
# File 'lib/numo/gnuplot.rb', line 431

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

#cmd_strObject



471
472
473
474
475
476
477
478
# File 'lib/numo/gnuplot.rb', line 471

def cmd_str
  parse_items
  if @function
    "%s %s" % [@function, OptsToS.new(*@options)]
  else
    "%s %s" % [@data.cmd_str, OptsToS.new(*@options)]
  end
end

#data_strObject



480
481
482
483
484
485
486
487
# File 'lib/numo/gnuplot.rb', line 480

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

#empty?Boolean

Returns:

  • (Boolean)


435
436
437
# File 'lib/numo/gnuplot.rb', line 435

def empty?
  @items.empty?
end

#parse_data(data) ⇒ Object



467
468
469
# File 'lib/numo/gnuplot.rb', line 467

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

#parse_itemsObject



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/numo/gnuplot.rb', line 439

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 = "'#{@function}'"
        end
      end
    else
      data = []
      @options = []
      @items.each do |x|
        if PlotItem.is_data(x)
          data << x
        else
          @options << x
        end
      end
      @data = parse_data(data)
    end
  end
end