numo-gnuplot 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/numo/gnuplot.rb +51 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39a3ebbe14ce683f9921fa70f40e60b398f76678
4
- data.tar.gz: c2508063acf8dca872ab6c53bd5ae075c379681f
3
+ metadata.gz: 6d5e544ba0f4909259490066ff280df9562cbc44
4
+ data.tar.gz: e640abea3b8753a94265fe4c9a1c9bce8eb6b0f5
5
5
  SHA512:
6
- metadata.gz: a5dee4a5e360d41ea5804845a76b081fa6f8e1c13bd134538a3b618861095b534cb5dad8d844be79b7dc0846703c9bba38c14bad20e65a748e9461531402098f
7
- data.tar.gz: 63e12b30cb0e739a6fc5cffb2a3a99300ff3160148be08f1e7c10929699d5c1ec17b0400baf75128137d4e2f0b9761a6a25ee92f83c34a48b6f87f4cc92f6b9a
6
+ metadata.gz: 8d16164e9871ee7a6b5f8749ed8b06ce83e07992a5ab450dd30350f0b2ca9d4b245ef6c843bdd5eb5582c73f9113cbfd752530e55f7eac025646535b0aaa09a9
7
+ data.tar.gz: d0bc21a42e7187fb5c1ba79a9cb1f3f1d7dbe8bfba42d4b4d8d26ffba5e503146de3179555778439a64eba34c155090db27ed4622a88e4d833fe907fa5b08e8b
data/lib/numo/gnuplot.rb CHANGED
@@ -11,7 +11,7 @@ module Numo
11
11
 
12
12
  class Gnuplot
13
13
 
14
- VERSION = "0.1.3"
14
+ VERSION = "0.1.4"
15
15
  POOL = []
16
16
  DATA_FORMAT = "%.5g"
17
17
 
@@ -120,7 +120,7 @@ class Gnuplot
120
120
  # text display option is disabled.
121
121
  # pause 10
122
122
  # pause 'mouse'
123
- # pause mouse:%w[keypress,button1,button2,button3,close,any]
123
+ # pause mouse:%w[keypress button1 button2 button3 close any]
124
124
  def pause(*args)
125
125
  send_cmd("pause #{OptsToS.new(*args)}").join.chomp
126
126
  nil
@@ -542,20 +542,65 @@ class Gnuplot
542
542
  s.pack("d*")
543
543
  end
544
544
  end
545
+
546
+ def self.array_shape(a)
547
+ if a.kind_of?(Array)
548
+ is_2d = true
549
+ is_1d = true
550
+ size_min = nil
551
+ a.each do |b|
552
+ if b.kind_of?(Array)
553
+ is_1d = false
554
+ if b.any?{|c| c.kind_of?(Array)}
555
+ is_2d = false
556
+ elsif size_min.nil? || b.size < size_min
557
+ size_min = b.size
558
+ end
559
+ else
560
+ is_2d = false
561
+ end
562
+ break if !is_1d && !is_2d
563
+ end
564
+ if is_1d
565
+ [a.size]
566
+ elsif is_2d
567
+ [a.size, size_min]
568
+ else
569
+ kernel_raise GnuplotError, "not suitable Array for data"
570
+ end
571
+ elsif a.respond_to?(:shape)
572
+ a.shape
573
+ else
574
+ kernel_raise GnuplotError, "not suitable type for data"
575
+ end
576
+ end
545
577
  end
546
578
 
547
579
  # @private
548
580
  class SPlotRecord < PlotData # :nodoc: all
549
- def initialize(*data)
550
- @shape = data.last.shape
551
- super
581
+
582
+ def initialize(x,y,z)
583
+ @text = false
584
+ @data = [x,y,z].map{|a| a.flatten}
585
+ @n = @data.map{|a| a.size}.min
586
+ shape = PlotData.array_shape(z)
587
+ if shape.size >= 2
588
+ n = shape[1]*shape[0]
589
+ if @n < n
590
+ kernel_raise GnuplotError, "data size mismatch"
591
+ end
592
+ @n = n
593
+ @record = "#{shape[1]},#{shape[0]}"
594
+ else
595
+ @record = "#{@n}"
596
+ end
552
597
  end
553
598
 
554
599
  def cmd_str
555
600
  if @text
556
601
  "'-'"
557
602
  else
558
- "'-' binary record=(#{@shape[1]},#{@shape[0]}) format='%float64' using 1:2:3"
603
+ "'-' binary record=(#{@record}) format='%float64' using 1:2:3"
559
604
  end
560
605
  end
561
606
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-gnuplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-12 00:00:00.000000000 Z
11
+ date: 2016-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler